Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better message printing for pcd_viewer #744

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1866,9 +1884,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 @@ -122,6 +122,7 @@ pcl::visualization::PCLVisualizer::PCLVisualizer (const std::string &name, const
, shape_actor_map_ (new ShapeActorMap)
, coordinate_actor_map_ (new CoordinateActorMap)
, camera_set_ ()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @taketwo just a question about C++, does this line set camera_set_ to false or let camera_set_ uninitialized? Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camera_set_ will be set to false in this case. See this SO answer for details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. @taketwo

, camera_file_loaded_ (false)
{
// Create a Renderer
vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New ();
Expand Down Expand Up @@ -187,6 +188,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 @@ -239,8 +241,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 @@ -249,7 +250,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 @@ -1691,6 +1692,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