-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Fix add/remove of 3D text without custom viewport #2110
Conversation
This doesn't fix the problem properly so it don't think it is a good idea to merge it like this. I overlooked your case when one doesn't invoke createViewport explicitly. I worked things with this use case in mind pcl/visualization/test/test_shapes_multiport.cpp Lines 22 to 29 in 3d5d915
What your changes tell me is that a default viewport is always created and that in my test example, this original viewport was overlaid with two other. What this means is that when the specified viewport id is 0, that first rendering element cannot be ignored, it needs to be checked and the corresponding shape added/deleted. The bug fix should address that. I can fix this after I'm done with the octree begin/end iterators unit tests. Alternatively, you can also change the current PR to implement the logic I just described. |
I'll do my best sempai 😼 |
778e968
to
f55d693
Compare
The work is done, ready to get a review. The solution I bring here is not really elegant but it works. I during the add or remove of a 3D text, I check if there is any custom viewport thanks to I also add 2 simple tests to check the right behavior of the visualiser, without and with custom viewports. To compile them, I use the following command line (enable only what is necessary): cmake -DPCL_ONLY_CORE_POINT_TYPES=ON -DPCL_NO_PRECOMPILE=ON -DBUILD_tools=OFF -DBUILD_examples=OFF -DBUILD_apps=OFF -DBUILD_2d=OFF -DBUILD_features=OFF -DBUILD_filters=OFF -DBUILD_outofcore=OFF -DBUILD_people=OFF -DBUILD_recognition=OFF -DBUILD_registration=OFF -DBUILD_sample_consensus=OFF -DBUILD_ml=OFF -DBUILD_stereo=OFF -DBUILD_surface=OFF -DBUILD_geometry=ON -DBUILD_io=ON -DBUILD_kdtree=ON -DBUILD_octree=ON -DBUILD_search=ON -DBUILD_visualization=ON -DBUILD_global_tests=ON -DBUILD_tests_common=OFF -DBUILD_tests_geometry=OFF -DBUILD_tests_io=OFF -DBUILD_tests_kdtree=OFF -DBUILD_tests_octree=OFF -DBUILD_tests_search=OFF -DBUILD_tests_surface=OFF -DBUILD_tests_segmentation=OFF -DBUILD_tests_features=OFF -DBUILD_tests_filters=OFF -DBUILD_tests_keypoints=OFF -DBUILD_tests_people=OFF -DBUILD_tests_outofcore=OFF -DBUILD_tests_recognition=OFF -DBUILD_tests_registration=OFF -DBUILD_tests_segmentation=OFF -DBUILD_tests_sample_consensus=OFF -DBUILD_tests_visualization=ON -DBUILD_TESTS=ON -DGTEST_INCLUDE_DIR=/home/frozar/soft/googletest/googletest/include -DGTEST_SRC_DIR=/home/frozar/soft/googletest/googletest -DCMAKE_BUILD_TYPE=Debug .. To run the test cases: make -j8 demo_text_simple && ./bin/demo_text_simple
make -j8 demo_text_simple_multiport && ./bin/demo_text_simple_multiport PS: I let some line of "visualization/test/CMakeLists.txt" uncomment because the compilation of these programs are protected by the CMake variable |
What happens if I do something like pcl::visualization::PCLVisualizer viz ("Visualizator");
int leftPort (0);
viz.createViewPort (0, 0, 0.5, 1, leftPort);
[code to add shapes etc...] Does the original viewport appear behind the new viewport? PS: There's some parenthesis spacing issues you might want to have a look in your added test files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try just applying the following changes.
diff --git a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
index 41805a0..c504116 100644
--- a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
+++ b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
@@ -674,8 +674,7 @@ pcl::visualization::PCLVisualizer::addText3D (
// check all or an individual viewport for a similar id
rens_->InitTraversal ();
- rens_->GetNextItem (); //discard first because it's not a renderer for the viewps
- for (size_t i = std::max (viewport, 1); rens_->GetNextItem () != NULL; ++i)
+ for (size_t i = viewport; rens_->GetNextItem () != NULL; ++i)
{
const std::string uid = tid + std::string (i, '*');
if (contains (uid))
@@ -700,8 +699,8 @@ pcl::visualization::PCLVisualizer::addText3D (
// Since each follower may follow a different camera, we need different followers
rens_->InitTraversal ();
- vtkRenderer* renderer = rens_->GetNextItem (); //discard first because it's not a renderer for the viewps
- int i = 1;
+ vtkRenderer* renderer;
+ int i = 0;
while ((renderer = rens_->GetNextItem ()) != NULL)
{
// Should we add the actor to all renderers or just to i-nth renderer?
@@ -753,8 +752,7 @@ pcl::visualization::PCLVisualizer::addText3D (
// check all or an individual viewport for a similar id
rens_->InitTraversal ();
- rens_->GetNextItem (); //discard first because it's not a renderer for the viewps
- for (size_t i = std::max (viewport, 1); rens_->GetNextItem () != NULL; ++i)
+ for (size_t i = viewport; rens_->GetNextItem () != NULL; ++i)
{
const std::string uid = tid + std::string (i, '*');
if (contains (uid))
@@ -786,8 +784,7 @@ pcl::visualization::PCLVisualizer::addText3D (
// Save the pointer/ID pair to the global actor map. If we are saving multiple vtkFollowers
rens_->InitTraversal ();
- rens_->GetNextItem (); //discard first because it's not a renderer for the viewps
- int i = 1;
+ int i = 0;
for ( vtkRenderer* renderer = rens_->GetNextItem ();
renderer != NULL;
renderer = rens_->GetNextItem (), ++i)
and for the removeText3D
diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp
index 5ba1fdb..e390ba6 100644
--- a/visualization/src/pcl_visualizer.cpp
+++ b/visualization/src/pcl_visualizer.cpp
@@ -901,8 +901,7 @@ pcl::visualization::PCLVisualizer::removeText3D (const std::string &id, int view
// check all or an individual viewport for a similar id
rens_->InitTraversal ();
- rens_->GetNextItem (); //discard first because it's not a renderer for the viewps
- for (size_t i = std::max (viewport, 1); rens_->GetNextItem () != NULL; ++i)
+ for (size_t i = viewport; rens_->GetNextItem () != NULL; ++i)
{
const std::string uid = id + std::string (i, '*');
ShapeActorMap::iterator am_it = shape_actor_map_->find (uid);
@@ -672,23 +672,45 @@ pcl::visualization::PCLVisualizer::addText3D ( | |||
if (viewport < 0) | |||
return false; | |||
|
|||
// check all or an individual viewport for a similar id | |||
// If there is no custom viewport and the viewport number is not 0, exit | |||
if ((rens_->GetNumberOfItems () == 1) && (1 <= viewport)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't
if (viewport => rens_->GetNumberOfItems ())
be generic for all cases and actually accomplish the same ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
visualization/src/pcl_visualizer.cpp
Outdated
@@ -899,36 +899,64 @@ pcl::visualization::PCLVisualizer::removeText3D (const std::string &id, int view | |||
|
|||
bool success = true; | |||
|
|||
// If there is no custom viewport and the viewport number is not 0, exit | |||
if ((rens_->GetNumberOfItems () == 1) && (1 <= viewport)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same.
I updated the diff. It was looking weird. |
Ok, here I removed what I'd done, I applied the patches from @SergioRAgostinho and cherry-pick my previous commits about adding test. I check the result of this branch with the two new tests and it seems to work well. A review should be done again I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thanks
viz.createViewPort(0, 0, 0.5, 1, leftPort); | ||
viz.createViewPort(0.5, 0, 1, 1, rightPort); | ||
|
||
viz.addCoordinateSystem(1.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space before the parenthesis from line 9 to 15.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it's done.
If you would like any squash before merge, let me know. |
👍 in theory I'll do it from github. If we need something more specific I'll let you know. I'm just gonna wait for CI tests to complete and check if we didn't output any new warnings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for bringing this up. I just realized that addText3D
and removeText3D
actually return boolean flags whether or not the calls were successful, so we can actually write proper unit tests, with gtest. We can address this in another PR, if you prefer.
|
||
viz.addText3D ("Following text", pcl::PointXYZ(0.0, 0.0, 0.0), | ||
1.0, 1.0, 0.0, 0.0, "id_following"); | ||
viz.spin (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a blocking call which continuously runs the main loop? Shouldn't spinOnce
be used instead? This comment is applicable for all the other calls to spin
you do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact I was inspired by other tests from this directory, and the behavior is good. Blocking spin()
method is correct. If you run the test, it allow you to see the effect of the different add/remove of text step by step. To pass to the next step, you just have to press "Q".
If I change it with spinOnce()
, I will not be able to even see the window: it will open and close instantly.
As it is functionnal right now (and it allows me to work on my "real" project), I would like to do it in another pull request 😉 |
This PR in relative to issue #2109.
The tiny changes I had enable to display text3D when you don't use any viewport.
I am sure the deletions break the internal logic of the visualizer and I need helps to fix/understand it.