Skip to content

Commit

Permalink
PCLVisualizer: save and restore camera information
Browse files Browse the repository at this point in the history
Press ctrl + s to save camera parameters and ctrl + r to restore the
saved camera parameters.

If a camera file is specified with "-cam" option or pcd file(s) is(are)
available in the command line, the camera parameters will be written to
the corresponding file and can be restored later from that file.
In this case, PCLVisualizer will restore camera parameters automatically
from the corresponding file when the pragram restarts with the same
command line input.
  • Loading branch information
xiangxw committed Jun 8, 2014
1 parent 512ff6e commit dc0f358
Show file tree
Hide file tree
Showing 5 changed files with 533 additions and 205 deletions.
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)
{
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);

/** \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

0 comments on commit dc0f358

Please sign in to comment.