Skip to content

Commit

Permalink
beautification
Browse files Browse the repository at this point in the history
  • Loading branch information
aichim committed Mar 19, 2013
1 parent a2991a0 commit 0ae4bdc
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 96 deletions.
1 change: 0 additions & 1 deletion apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ if(build)
PCL_ADD_EXECUTABLE_OPT_BUNDLE(pcl_manual_registration ${SUBSYS_NAME} ${manual_registration_ui} ${manual_registration_moc} src/manual_registration/manual_registration.cpp)
target_link_libraries(pcl_manual_registration pcl_common pcl_io pcl_visualization pcl_segmentation pcl_features pcl_surface QVTK ${QT_LIBRARIES})

# Manual registration demo
QT4_WRAP_UI(pcd_video_player_ui src/pcd_video_player/pcd_video_player.ui)
QT4_WRAP_CPP(pcd_video_player_moc include/pcl/apps/pcd_video_player.h OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED)
PCL_ADD_EXECUTABLE_OPT_BUNDLE(pcl_pcd_video_player ${SUBSYS_NAME} ${pcd_video_player_ui} ${pcd_video_player_moc} src/pcd_video_player/pcd_video_player.cpp)
Expand Down
71 changes: 41 additions & 30 deletions apps/include/pcl/apps/pcd_video_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@

#include <pcl/registration/transformation_estimation_svd.h>

typedef pcl::PointXYZRGBA PointT;

#define CURRENT_VERSION 0.2

// Useful macros
Expand Down Expand Up @@ -97,7 +95,7 @@ class PCDVideoPlayer : public QMainWindow
{
Q_OBJECT
public:
typedef pcl::PointCloud<PointT> Cloud;
typedef pcl::PointCloud<pcl::PointXYZRGBA> Cloud;
typedef Cloud::Ptr CloudPtr;
typedef Cloud::ConstPtr CloudConstPtr;

Expand All @@ -106,50 +104,63 @@ class PCDVideoPlayer : public QMainWindow
~PCDVideoPlayer () {}

protected:
boost::shared_ptr<pcl::visualization::PCLVisualizer> vis_;
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_;
boost::shared_ptr<pcl::visualization::PCLVisualizer> vis_;
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_;

QMutex mtx_;
QMutex vis_mtx_;
Ui::MainWindow *ui_;
QTimer *vis_timer_;
QMutex mtx_;
QMutex vis_mtx_;
Ui::MainWindow *ui_;
QTimer *vis_timer_;

QString dir_;
QString dir_;

std::vector<std::string> pcd_files_;
std::vector<boost::filesystem::path> pcd_paths_;
std::vector<std::string> pcd_files_;
std::vector<boost::filesystem::path> pcd_paths_;

//QStringList pcd_files_;

unsigned int current_frame_; // The current displayed frame
unsigned int nr_of_frames_; // Store the number of loaded frames
/** \brief The current displayed frame */
unsigned int current_frame_;
/** \brief Store the number of loaded frames */
unsigned int nr_of_frames_;

bool cloud_present_; // Indicate that pointclouds were loaded
bool cloud_modified_; // Indicate that the timeoutSlot needs to reload the pointcloud
/** \brief Indicate that pointclouds were loaded */
bool cloud_present_;
/** \brief Indicate that the timeoutSlot needs to reload the pointcloud */
bool cloud_modified_;

bool play_mode_; // Indicate that files should play continiously
unsigned int speed_counter_; // In play mode only update if speed_counter_ == speed_value
unsigned int speed_value_; // Fixes the speed in steps of 5ms, default 5, gives 5+1 * 5ms = 30ms = 33,3 Hz playback speed
/** \brief Indicate that files should play continiously */
bool play_mode_;
/** \brief In play mode only update if speed_counter_ == speed_value */
unsigned int speed_counter_;
/** \brief Fixes the speed in steps of 5ms, default 5, gives 5+1 * 5ms = 30ms = 33,3 Hz playback speed */
unsigned int speed_value_;

public slots:
void
playButtonPressed();
playButtonPressed ()
{ play_mode_ = true; }

void
stopButtonPressed();
stopButtonPressed()
{ play_mode_ = false; }

void
backButtonPressed();
void
nextButtonPressed();
void
selectFolderButtonPressed();
backButtonPressed ();

void
nextButtonPressed ();

void
selectFolderButtonPressed ();

void
selectFilesButtonPressed();
selectFilesButtonPressed ();

void
indexSliderValueChanged(int value);
indexSliderValueChanged (int value);

private slots:
void
timeoutSlot();
timeoutSlot ();

};
121 changes: 56 additions & 65 deletions apps/src/pcd_video_player/pcd_video_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id: $
*
* @author: Koen Buys - KU Leuven
*/

//PCL
Expand Down Expand Up @@ -84,7 +81,7 @@ PCDVideoPlayer::PCDVideoPlayer ()
vis_timer_ = new QTimer (this);
vis_timer_->start (5);//5ms

connect (vis_timer_, SIGNAL (timeout ()), this, SLOT (timeoutSlot()));
connect (vis_timer_, SIGNAL (timeout ()), this, SLOT (timeoutSlot ()));

ui_ = new Ui::MainWindow;
ui_->setupUi (this);
Expand All @@ -102,49 +99,37 @@ PCDVideoPlayer::PCDVideoPlayer ()
ui_->qvtkWidget->update ();

// Connect all buttons
connect (ui_->playButton, SIGNAL(clicked()), this, SLOT(playButtonPressed()));
connect (ui_->stopButton, SIGNAL(clicked()), this, SLOT(stopButtonPressed()));
connect (ui_->backButton, SIGNAL(clicked()), this, SLOT(backButtonPressed()));
connect (ui_->nextButton, SIGNAL(clicked()), this, SLOT(nextButtonPressed()));
connect (ui_->playButton, SIGNAL (clicked ()), this, SLOT (playButtonPressed ()));
connect (ui_->stopButton, SIGNAL (clicked ()), this, SLOT (stopButtonPressed ()));
connect (ui_->backButton, SIGNAL (clicked ()), this, SLOT (backButtonPressed ()));
connect (ui_->nextButton, SIGNAL (clicked ()), this, SLOT (nextButtonPressed ()));

connect (ui_->selectFolderButton, SIGNAL(clicked()), this, SLOT(selectFolderButtonPressed()));
connect (ui_->selectFilesButton, SIGNAL(clicked()), this, SLOT(selectFilesButtonPressed()));
connect (ui_->selectFolderButton, SIGNAL (clicked ()), this, SLOT (selectFolderButtonPressed ()));
connect (ui_->selectFilesButton, SIGNAL (clicked ()), this, SLOT (selectFilesButtonPressed ()));

connect (ui_->indexSlider, SIGNAL(valueChanged(int)), this, SLOT(indexSliderValueChanged(int)));
}

void
PCDVideoPlayer::playButtonPressed()
{
play_mode_ = true;
connect (ui_->indexSlider, SIGNAL (valueChanged (int)), this, SLOT (indexSliderValueChanged (int)));
}

void
PCDVideoPlayer::stopButtonPressed()
{
play_mode_= false;
}

void
PCDVideoPlayer::backButtonPressed()
PCDVideoPlayer::backButtonPressed ()
{
if(current_frame_ == 0) // Allready in the beginning
{
PCL_DEBUG ("[PCDVideoPlayer::nextButtonPressed] : reached the end\n");
current_frame_ = nr_of_frames_-1; // reset to end
current_frame_ = nr_of_frames_ - 1; // reset to end
}
else
{
current_frame_--;
cloud_modified_ = true;
ui_->indexSlider->setSliderPosition(current_frame_); // Update the slider position
ui_->indexSlider->setSliderPosition (current_frame_); // Update the slider position
}
}

void
PCDVideoPlayer::nextButtonPressed()
PCDVideoPlayer::nextButtonPressed ()
{
if(current_frame_ == (nr_of_frames_-1)) // Reached the end
if (current_frame_ == (nr_of_frames_ - 1)) // Reached the end
{
PCL_DEBUG ("[PCDVideoPlayer::nextButtonPressed] : reached the end\n");
current_frame_ = 0; // reset to beginning
Expand All @@ -153,26 +138,29 @@ PCDVideoPlayer::nextButtonPressed()
{
current_frame_++;
cloud_modified_ = true;
ui_->indexSlider->setSliderPosition(current_frame_); // Update the slider position
ui_->indexSlider->setSliderPosition (current_frame_); // Update the slider position
}
}

void
PCDVideoPlayer::selectFolderButtonPressed()
PCDVideoPlayer::selectFolderButtonPressed ()
{
pcd_files_.clear(); // Clear the std::vector
pcd_paths_.clear(); // Clear the boost filesystem paths
pcd_files_.clear (); // Clear the std::vector
pcd_paths_.clear (); // Clear the boost filesystem paths

dir_ = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
dir_ = QFileDialog::getExistingDirectory (this,
tr("Open Directory"),
"/home",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);

boost::filesystem::directory_iterator end_itr;

if(boost::filesystem::is_directory(dir_.toStdString()))
if (boost::filesystem::is_directory (dir_.toStdString ()))
{
for (boost::filesystem::directory_iterator itr(dir_.toStdString()); itr != end_itr; ++itr)
for (boost::filesystem::directory_iterator itr (dir_.toStdString ()); itr != end_itr; ++itr)
{
std::string ext = itr->path().extension().string();
if(ext.compare(".pcd") == 0)
std::string ext = itr->path ().extension ().string ();
if (ext.compare (".pcd") == 0)
{
pcd_files_.push_back (itr->path ().string ());
pcd_paths_.push_back (itr->path ());
Expand All @@ -189,20 +177,20 @@ PCDVideoPlayer::selectFolderButtonPressed()
PCL_ERROR("Path is not a directory\n");
exit(-1);
}
nr_of_frames_ = pcd_files_.size();
nr_of_frames_ = pcd_files_.size ();
PCL_DEBUG ("[PCDVideoPlayer::selectFolderButtonPressed] : found %d files\n", nr_of_frames_ );

if(nr_of_frames_ == 0)
if (nr_of_frames_ == 0)
{
PCL_ERROR("Please select valid pcd folder\n");
PCL_ERROR ("Please select valid pcd folder\n");
cloud_present_ = false;
return;
}
else
{
// Reset the Slider
ui_->indexSlider->setValue(0); // set cursor back in the beginning
ui_->indexSlider->setRange(0,nr_of_frames_-1); // rescale the slider
ui_->indexSlider->setValue (0); // set cursor back in the beginning
ui_->indexSlider->setRange (0, nr_of_frames_ - 1); // rescale the slider

current_frame_ = 0;

Expand All @@ -212,33 +200,36 @@ PCDVideoPlayer::selectFolderButtonPressed()
}

void
PCDVideoPlayer::selectFilesButtonPressed()
PCDVideoPlayer::selectFilesButtonPressed ()
{
pcd_files_.clear(); // Clear the std::vector
pcd_paths_.clear(); // Clear the boost filesystem paths
pcd_files_.clear (); // Clear the std::vector
pcd_paths_.clear (); // Clear the boost filesystem paths

QStringList qt_pcd_files = QFileDialog::getOpenFileNames(this, "Select one or more PCD files to open", "/home", "PointClouds (*.pcd)");
nr_of_frames_ = qt_pcd_files.size();
std::cout << "[PCDVideoPlayer::selectFilesButtonPressed] : selected " << nr_of_frames_ << " files" << std::endl;
QStringList qt_pcd_files = QFileDialog::getOpenFileNames (this,
"Select one or more PCD files to open",
"/home",
"PointClouds (*.pcd)");
nr_of_frames_ = qt_pcd_files.size ();
PCL_INFO ("[PCDVideoPlayer::selectFilesButtonPressed] : selected %ld files\n", nr_of_frames_);

if(nr_of_frames_ == 0)
if (nr_of_frames_ == 0)
{
PCL_ERROR("Please select valid pcd files\n");
PCL_ERROR ("Please select valid pcd files\n");
cloud_present_ = false;
return;
}
else
{
for(int i = 0; i < qt_pcd_files.size(); i++)
for(int i = 0; i < qt_pcd_files.size (); i++)
{
pcd_files_.push_back(qt_pcd_files.at(i).toStdString());
pcd_files_.push_back (qt_pcd_files.at (i).toStdString ());
}

current_frame_ = 0;

// Reset the Slider
ui_->indexSlider->setValue(0); // set cursor back in the beginning
ui_->indexSlider->setRange(0,nr_of_frames_-1); // rescale the slider
ui_->indexSlider->setValue (0); // set cursor back in the beginning
ui_->indexSlider->setRange (0, nr_of_frames_ - 1); // rescale the slider

cloud_present_ = true;
cloud_modified_ = true;
Expand All @@ -248,19 +239,19 @@ PCDVideoPlayer::selectFilesButtonPressed()
void
PCDVideoPlayer::timeoutSlot ()
{
if(play_mode_)
if (play_mode_)
{
if(speed_counter_ == speed_value_)
if (speed_counter_ == speed_value_)
{
if(current_frame_ == (nr_of_frames_-1)) // Reached the end
if (current_frame_ == (nr_of_frames_-1)) // Reached the end
{
current_frame_ = 0; // reset to beginning
}
else
{
current_frame_++;
cloud_modified_ = true;
ui_->indexSlider->setSliderPosition(current_frame_); // Update the slider position
ui_->indexSlider->setSliderPosition (current_frame_); // Update the slider position
}
}
else
Expand All @@ -269,25 +260,25 @@ PCDVideoPlayer::timeoutSlot ()
}
}

if(cloud_present_ && cloud_modified_)
if (cloud_present_ && cloud_modified_)
{
if (pcl::io::loadPCDFile<pcl::PointXYZRGBA> (pcd_files_[current_frame_], *cloud_) == -1) //* load the file
{
PCL_ERROR ("[PCDVideoPlayer::timeoutSlot] : Couldn't read file %s\n");
}

if(!vis_->updatePointCloud(cloud_, "cloud_"))
if (!vis_->updatePointCloud(cloud_, "cloud_"))
{
vis_->addPointCloud (cloud_, "cloud_");
vis_->resetCameraViewpoint("cloud_");
}
cloud_modified_ = false;
}
ui_->qvtkWidget->update();
ui_->qvtkWidget->update ();
}

void
PCDVideoPlayer::indexSliderValueChanged(int value)
PCDVideoPlayer::indexSliderValueChanged (int value)
{
PCL_DEBUG ("[PCDVideoPlayer::indexSliderValueChanged] : (I) : value %d\n", value);
current_frame_ = value;
Expand All @@ -311,11 +302,11 @@ print_usage ()
int
main (int argc, char** argv)
{
QApplication app(argc, argv);
QApplication app (argc, argv);

PCDVideoPlayer VideoPlayer;

VideoPlayer.show();
VideoPlayer.show ();

return (app.exec());
return (app.exec ());
}

0 comments on commit 0ae4bdc

Please sign in to comment.