Skip to content

Commit

Permalink
Merge pull request #744 from xiangxw/pcd_viewer_print_auto_restore_me…
Browse files Browse the repository at this point in the history
…ssage

Better message printing for pcd_viewer
  • Loading branch information
taketwo committed Jun 12, 2014
2 parents 82d0099 + 9b96530 commit a2be3ea
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
25 changes: 23 additions & 2 deletions visualization/include/pcl/visualization/pcl_visualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1602,11 +1602,29 @@ namespace pcl
loadCameraParameters (const std::string &file);

/** \brief Checks whether the camera parameters were manually loaded.
* \return True if valid "-cam" option is available in command line or a corresponding camera file is automatically loaded.
* \return True if valid "-cam" option is available in command line.
* \sa cameraFileLoaded ()
*/
bool
cameraParamsSet () const;

/** \brief Checks whether a camera file were automatically loaded.
* \return True if a valid camera file is automatically loaded.
* \note The camera file is saved by pressing "ctrl + s" during last run of the program
* and restored automatically when the program runs this time.
* \sa cameraParamsSet ()
*/
bool
cameraFileLoaded () const;

/** \brief Get camera file for camera parameter saving/restoring.
* \note This will be valid only when valid "-cam" option were available in command line
* or a saved camera file were automatically loaded.
* \sa cameraParamsSet (), cameraFileLoaded ()
*/
std::string
getCameraFile () const;

/** \brief Update camera parameters and render. */
void
updateCamera ();
Expand Down Expand Up @@ -1872,9 +1890,12 @@ namespace pcl
/** \brief Internal pointer to widget which contains a set of axes */
vtkSmartPointer<vtkOrientationMarkerWidget> axes_widget_;

/** \brief Boolean that holds whether or not the camera parameters were manually initialized*/
/** \brief Boolean that holds whether or not the camera parameters were manually initialized */
bool camera_set_;

/** \brief Boolean that holds whether or not a camera file were automatically loaded */
bool camera_file_loaded_;

/** \brief Boolean that holds whether or not to use the vtkVertexBufferObjectMapper*/
bool use_vbos_;

Expand Down
21 changes: 18 additions & 3 deletions visualization/src/pcl_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pcl::visualization::PCLVisualizer::PCLVisualizer (const std::string &name, const
, shape_actor_map_ (new ShapeActorMap)
, coordinate_actor_map_ (new CoordinateActorMap)
, camera_set_ ()
, camera_file_loaded_ (false)
{
// Create a Renderer
vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New ();
Expand Down Expand Up @@ -188,6 +189,7 @@ pcl::visualization::PCLVisualizer::PCLVisualizer (int &argc, char **argv, const
, shape_actor_map_ (new ShapeActorMap)
, coordinate_actor_map_ ()
, camera_set_ ()
, camera_file_loaded_ (false)
{
// Create a Renderer
vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New ();
Expand Down Expand Up @@ -240,8 +242,7 @@ pcl::visualization::PCLVisualizer::PCLVisualizer (int &argc, char **argv, const
{
if (boost::filesystem::exists (camera_file) && style_->loadCameraParameters (camera_file))
{
pcl::console::print_info ("\nRestore camera parameters from %s.\n", camera_file.c_str ());
camera_set_ = true;
camera_file_loaded_ = true;
}
else
{
Expand All @@ -250,7 +251,7 @@ pcl::visualization::PCLVisualizer::PCLVisualizer (int &argc, char **argv, const
}
}
// Set the window size as 1/2 of the screen size or the user given parameter
if (!camera_set_)
if (!camera_set_ && !camera_file_loaded_)
{
win_->SetSize (scr_size[0]/2, scr_size[1]/2);
win_->SetPosition (0, 0);
Expand Down Expand Up @@ -1746,6 +1747,20 @@ pcl::visualization::PCLVisualizer::cameraParamsSet () const
return (camera_set_);
}

/////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::PCLVisualizer::cameraFileLoaded () const
{
return (camera_file_loaded_);
}

/////////////////////////////////////////////////////////////////////////////////////////////
std::string
pcl::visualization::PCLVisualizer::getCameraFile () const
{
return (style_->getCameraFile ());
}

/////////////////////////////////////////////////////////////////////////////////////////////
void
pcl::visualization::PCLVisualizer::updateCamera ()
Expand Down
6 changes: 4 additions & 2 deletions visualization/tools/pcd_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ main (int argc, char** argv)
// Set whether or not we should be using the vtkVertexBufferObjectMapper
p->setUseVbos (use_vbos);

if (!p->cameraParamsSet ())
if (!p->cameraParamsSet () && !p->cameraFileLoaded ())
{
Eigen::Matrix3f rotation;
rotation = orientation;
Expand Down Expand Up @@ -631,14 +631,16 @@ main (int argc, char** argv)
p->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_OPACITY, opaque.at (i), cloud_name.str ());

// Reset camera viewpoint to center of cloud if camera parameters were not passed manually and this is the first loaded cloud
if (i == 0 && !p->cameraParamsSet ())
if (i == 0 && !p->cameraParamsSet () && !p->cameraFileLoaded ())
{
p->resetCameraViewpoint (cloud_name.str ());
p->resetCamera ();
}

print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%u", cloud->width * cloud->height); print_info (" points]\n");
print_info ("Available dimensions: "); print_value ("%s\n", pcl::getFieldsList (*cloud).c_str ());
if (p->cameraFileLoaded ())
print_info ("Camera parameters restored from %s.\n", p->getCameraFile ().c_str ());
}

if (!mview && p)
Expand Down

0 comments on commit a2be3ea

Please sign in to comment.