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

Conversation

xiangxw
Copy link
Contributor

@xiangxw xiangxw commented May 27, 2014

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.

@xiangxw
Copy link
Contributor Author

xiangxw commented May 27, 2014

Origin camera:
pcd viewer_001
Change camera and press ctrl + s to save the camera information:
pcd viewer_002
Restarted:
pcd viewer_003

@taketwo
Copy link
Member

taketwo commented May 27, 2014

I think this is a very useful contribution, thanks! I have a few comments though:

  • In PCLVisualizer we already have functions to save/load camera parameters. Would be nice to reuse them to make sure that the file format is consistent.
  • I am not sure if ".screenshot-%s.cam" is a good filename. Why screenshot? Why hidden?
  • What about providing another shortcut to load camera information on demand? For example, the user might open the scene, play around selecting a good view, save it, then move the camera around even more in an attempt to find a better view. Then he decides that the first saved view was better, and reloads it.

@xiangxw
Copy link
Contributor Author

xiangxw commented May 27, 2014

hi, @taketwo

  • I can't find any public functions in PCLVisualizer to save/load camera parameters. My code is copyed from interactor_style.cpp, there is no public api there. Is it ok to add this extension to PCLVisualizer so that every PCLVisualizer has this ability?
  • There may be multiple .pcd files for pcl_viewer to view so we name the .cam file with sha1(not pathes of the .pcd files. And sha1 filename is hard to understand, so we make it hidden. Users do not need to see the .cam file.
  • Good idea. I will do that.

Question: If I add this to PCLVisualizer, path of .pcd files are not available so sha1 can be calculated. Any idea about how to calculate sha1 value of pointclouds? Thanks.

@taketwo
Copy link
Member

taketwo commented May 27, 2014

  • The ultimate goal should be to have a single implementation of saving/loading so that different clients can call it. If this could be put in PCLVisualizer, then why not.
  • I very much like the idea with SHA1, and you are right that the names are a bit unreadable. But still, why putting "screenshot" inside the name?
  • What shortcuts do you think it makes sense to assign to saving/loading?

Question: If I add this to PCLVisualizer, path of .pcd files are not available so sha1 can be calculated.

I would rather have save/load functions that take a filename. It's up to the client (pcl_viewer in our case) how it constructs this name.

@xiangxw
Copy link
Contributor Author

xiangxw commented May 27, 2014

hi, @taketwo

  • I will put this in PCLVisualizer.
  • "screenshot" is from interactor_style.cpp and I will remove it, with ".%s.cam" remaining.
  • How about ctrl+s for saving and ctrl+r for restoring?

PCLVisualizer will read "-cam" option and filenames from command arguments, and I will pass sha1 value of .pcd paths to PCLVisualizerInteractorStyle which is attached to the PCLVisualizer

@taketwo
Copy link
Member

taketwo commented May 27, 2014

How about ctrl+s for saving and ctrl+r for restoring?

+1

PCLVisualizer will read "-cam" option and filenames from command arguments

I am not sure I understand what you mean here.

@xiangxw
Copy link
Contributor Author

xiangxw commented May 27, 2014

@taketwo Sorry for my english.
I mean I will modify constructor:

 PCLVisualizer (int &argc, char **argv, const std::string &name="", PCLVisualizerInteractorStyle *style=PCLVisualizerInteractorStyle::New(), const bool create_interactor=true)

to calculate sha1 value and pass it to PCLVisualizerInteractorStyle. If "-cam" option are valid, camera information will save/restore using the specified .cam file

@taketwo
Copy link
Member

taketwo commented May 27, 2014

What about the following use-case. I have a program that uses PCLVisualizer to display some point clouds that it creates at runtime. This means that when it instantiates PCLVisualizer, it does not pass any filenames to it. Rather the point clouds are added programmatically later on. How saving/loading of camera parameters may be organized in this case?

@xiangxw
Copy link
Contributor Author

xiangxw commented May 27, 2014

@taketwo
In this case, camera information will be written to memory, not .cam file. Camera information can be restored using the information from memory, but can't be restored when program restarts,

@taketwo
Copy link
Member

taketwo commented May 27, 2014

Why this restriction? Wouldn't it make sense to have PCLVisualizer::saveCameraParameters (const std::string& filename) so that we can store the viewpoint to an arbitrary file?

@xiangxw
Copy link
Contributor Author

xiangxw commented May 27, 2014

Great @taketwo I will do that

@xiangxw xiangxw changed the title pcl_viewer: save and restore camera information PCLVisualizer: save and restore camera information May 29, 2014
@xiangxw
Copy link
Contributor Author

xiangxw commented May 29, 2014

Tested cases:

  • Test case 1: single input .pcd file.

    ./bin/pcl_viewer kitchen_small_1_1.pcd

  • Test case 2: multiple input .pcd files.

    ./bin/pcl_viewer kitchen_small_1_1.pcd kitchen_small_1_2.pcd

  • Test case 3: with "-cam" option.

    ./bin/pcl_viewer kitchen_small_1_1.pcd kitchen_small_1_2.pcd -cam 14.2608,2660.28/0,0,1/985.715,-401.162,909.226/0.288812,0.951412,0.106784/0.8575/960,540/603,242

  • Test case 4: with "-cam" option(camera file).

    ./bin/pcl_viewer kitchen_small_1_1.pcd kitchen_small_1_2.pcd -cam .efe7509f521e5435dc6008d38d927fd321ad30a0.cam

  • Test case 5: restart program(camera file saved will be automatically loaded).

@xiangxw
Copy link
Contributor Author

xiangxw commented May 30, 2014

Hi, @taketwo Is it ok to merge?

@taketwo
Copy link
Member

taketwo commented May 30, 2014

@xiangxw I skimmed through the code already and have a couple of questions. But in order to formulate them properly I would need some more time to dig in and read carefully. Unfortunately I'm quite busy with other things at the moment. I will come back to your PR as soon as possible. Sorry.

@xiangxw
Copy link
Contributor Author

xiangxw commented May 30, 2014

@taketwo ok, thanks.

* \param[out] camera the name of the \ref pcl::visualization::Camera
*/
void
saveCameraParameters (Camera &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 "save" is not a correct verb here. It has connotations with persistence and disk I/O. Rather, here the current camera parameters are retrieved into a variable. I would definitely call this getCameraParameters().

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, you are right.

@xiangxw
Copy link
Contributor Author

xiangxw commented Jun 3, 2014

Hi @taketwo I have modified the code. Thanks.

@taketwo
Copy link
Member

taketwo commented Jun 7, 2014

Looks good to me now, though I have one question. How is this going to behave in the following situation? Suppose the user provided -cam option when starting viewer. Camera parameters will be loaded from the specified file. But later on, when saving and restoring with 'Ctrl-S'/'Ctrl-R', will the parameters be saved/loaded to that same file? I think it would make sense if it was so. The user kind of suggesting that he wants to work with some particular camera file, not a "random" one.

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.
@xiangxw
Copy link
Contributor Author

xiangxw commented Jun 8, 2014

hi @taketwo

  • When -cam is provided with a camera file, the camera parameters will be saved to/loaded from that same file.
  • When -cam is provided with camera parameters, the camera parameters will be saved to/loaded from memory.

@taketwo
Copy link
Member

taketwo commented Jun 8, 2014

Great, that is exactly the behavior I was thinking about.

So everything is fine from my viewpoint. @jspricke?

jspricke added a commit that referenced this pull request Jun 8, 2014
PCLVisualizer: save and restore camera information
@jspricke jspricke merged commit 135d66b into PointCloudLibrary:master Jun 8, 2014
xiangxw added a commit to xiangxw/pcl that referenced this pull request Jun 12, 2014
Segmentation fault when "r" is pressed in PCLVisualizer.
The previous pull request PointCloudLibrary#703 does not handle the "r" keyboard event
correctly and pass the event to vtkInteractorStyleRubberBandPick,
which enables rubber-band selection mode when 'r' is pressed.
xiangxw added a commit to xiangxw/pcl that referenced this pull request Jun 12, 2014
Segmentation fault when "r" is pressed in PCLVisualizer.
The previous pull request PointCloudLibrary#703 does not handle the "r" keyboard event
correctly and pass the event to vtkInteractorStyleRubberBandPick,
which enables rubber-band selection mode when 'r' is pressed.
@xiangxw xiangxw deleted the pcl_viewer_remember_camera_position branch June 12, 2014 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants