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

PCLVisualizer: save and restore camera information #703

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
81 changes: 80 additions & 1 deletion visualization/include/pcl/visualization/interactor_style.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ namespace pcl
* - g, G : display scale grid (on/off)
* - u, U : display lookup table (on/off)
* - r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]
* - CTRL + s, S : save camera parameters
* - CTRL + r, R : restore camera parameters
* - ALT + s, S : turn stereo mode on/off
* - ALT + f, F : switch between maximized window mode and original size
* - l, L : list all available geometric and color handlers for the current actor map
Expand All @@ -115,7 +117,7 @@ namespace pcl
max_win_height_ (), max_win_width_ (), grid_enabled_ (), grid_actor_ (), lut_enabled_ (),
lut_actor_ (), snapshot_writer_ (), wif_ (), mouse_signal_ (), keyboard_signal_ (),
point_picking_signal_ (), area_picking_signal_ (), stereo_anaglyph_mask_default_ (),
mouse_callback_ (), modifier_ ()
mouse_callback_ (), modifier_ (), camera_file_ (), camera_ (), camera_saved_ (), win_ ()
{}

/** \brief Empty destructor */
Expand Down Expand Up @@ -184,6 +186,56 @@ namespace pcl
void
saveScreenshot (const std::string &file);

/** \brief Save the camera parameters to disk, as a .cam file.
* \param[in] file the name of the .cam file
*/
bool
saveCameraParameters (const std::string &file);

/** \brief Get camera parameters and save them to a \ref pcl::visualization::Camera.
* \param[out] camera the name of the \ref pcl::visualization::Camera
*/
void
getCameraParameters (Camera &camera);

/** \brief Load camera parameters from a camera parameter file.
* \param[in] file the name of the camera parameter file
*/
bool
loadCameraParameters (const std::string &file);

/** \brief Set the camera parameters via an intrinsics and and extrinsics matrix
* \note This assumes that the pixels are square and that the center of the image is at the center of the sensor.
* \param[in] intrinsics the intrinsics that will be used to compute the VTK camera parameters
* \param[in] extrinsics the extrinsics that will be used to compute the VTK camera parameters
* \param[in] viewport the viewport to modify camera of (0 modifies all cameras)
*/
void
setCameraParameters (const Eigen::Matrix3f &intrinsics, const Eigen::Matrix4f &extrinsics, int viewport = 0);

/** \brief Set the camera parameters by given a full camera data structure.
* \param[in] camera camera structure containing all the camera parameters.
* \param[in] viewport the viewport to modify camera of (0 modifies all cameras)
*/
void
setCameraParameters (const Camera &camera, int viewport = 0);

/** \brief Set camera file for camera parameter saving/restoring.
* \param[in] file the name of the camera parameter file
*/
void
setCameraFile (const std::string file)
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to store the file name inside the interactor object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I think so. Keyboard events are handled in the interactor object and we need the file name in the interactor object. The file name is get/calculated from the command line input, so if no file name is stored, we have to store the command line input.

{
camera_file_ = file;
}

/** \brief Get camera file for camera parameter saving/restoring. */
std::string
getCameraFile () const
{
return (camera_file_);
}

/** \brief Change the default keyboard modified from ALT to a different special key.
* Allowed values are:
* - INTERACTOR_KB_MOD_ALT
Expand Down Expand Up @@ -284,6 +336,21 @@ namespace pcl
void
zoomOut ();

/** \brief Get camera parameters from a string vector.
* \param[in] camera A string vector:
* Clipping Range, Focal Point, Position, ViewUp, Distance, Field of View Y, Window Size, Window Pos.
* Values in each string are seperated by a ','
*/
bool
getCameraParameters (const std::vector<std::string> &camera);
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs more explanation, it's very unclear what this function is doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The strings in the vector are: Clipping Range, Focal Point, Position, ViewUp, Distance, Field of View Y, Window Size, Window Pos. Values in each string are seperated by a ','. I will add some comments to make it clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, the brief should be Get camera parameters from a string vector not for


/** \brief Set render window. */
void
setRenderWindow (const vtkSmartPointer<vtkRenderWindow> &win)
{
win_ = win;
}

/** \brief True if we're using red-blue colors for anaglyphic stereo, false if magenta-green. */
bool stereo_anaglyph_mask_default_;

Expand All @@ -293,7 +360,19 @@ namespace pcl
/** \brief The keyboard modifier to use. Default: Alt. */
InteractorKeyboardModifier modifier_;

/** \brief Camera file for camera parameter saving/restoring. */
std::string camera_file_;
/** \brief A \ref pcl::visualization::Camera for camera parameter saving/restoring. */
Camera camera_;
/** \brief A \ref pcl::visualization::Camera is saved or not. */
bool camera_saved_;
/** \brief The render window.
* Only used when interactor maybe not available
*/
vtkSmartPointer<vtkRenderWindow> win_;

friend class PointPickingCallback;
friend class PCLVisualizer;
};

/** \brief PCL histogram visualizer interactory style class.
Expand Down
29 changes: 28 additions & 1 deletion visualization/include/pcl/visualization/pcl_visualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,15 @@ namespace pcl
bool
getCameraParameters (int argc, char **argv);

/** \brief Checks whether the camera parameters were manually loaded from file.*/
/** \brief Load camera parameters from a camera parameters file.
* \param[in] file the name of the camera parameters file
*/
bool
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.
*/
bool
cameraParamsSet () const;

Expand Down Expand Up @@ -1689,6 +1697,18 @@ namespace pcl
void
saveScreenshot (const std::string &file);

/** \brief Save the camera parameters to disk, as a .cam file.
* \param[in] file the name of the .cam file
*/
void
saveCameraParameters (const std::string &file);

/** \brief Get camera parameters and save them to a pcl::visualization::Camera.
* \param[out] camera the name of the pcl::visualization::Camera
*/
void
getCameraParameters (Camera &camera);

/** \brief Return a pointer to the underlying VTK Render Window used. */
vtkSmartPointer<vtkRenderWindow>
getRenderWindow ()
Expand Down Expand Up @@ -2063,6 +2083,13 @@ namespace pcl
int
textureFromTexMaterial (const pcl::TexMaterial& tex_mat,
vtkTexture* vtk_tex) const;

/** \brief Get camera file for camera parameter saving/restoring from command line.
* Camera filename is calculated using sha1 value of all pathes of input .pcd files
* \return empty string if failed.
*/
std::string
getUniqueCameraFile (int argc, char **argv);

//There's no reason these conversion functions shouldn't be public and static so others can use them.
public:
Expand Down
Loading