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

Fix add/remove of 3D text without custom viewport #2110

Merged
merged 5 commits into from
Dec 5, 2017

Conversation

frozar
Copy link
Contributor

@frozar frozar commented Dec 1, 2017

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.

@SergioRAgostinho SergioRAgostinho added the needs: code review Specify why not closed/merged yet label Dec 3, 2017
@SergioRAgostinho
Copy link
Member

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

// Start the visualizer
pcl::visualization::PCLVisualizer p ("test_shapes");
int leftPort(0);
int rightPort(0);
p.createViewPort(0, 0, 0.5, 1, leftPort);
p.createViewPort(0.5, 0, 1, 1, rightPort);
p.setBackgroundColor (1, 1, 1);
p.addCoordinateSystem (1.0, "first");

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.

@SergioRAgostinho SergioRAgostinho added needs: author reply Specify why not closed/merged yet and removed needs: code review Specify why not closed/merged yet labels Dec 3, 2017
@frozar
Copy link
Contributor Author

frozar commented Dec 3, 2017

I'll do my best sempai 😼

@SergioRAgostinho SergioRAgostinho added needs: more work Specify why not closed/merged yet and removed needs: author reply Specify why not closed/merged yet labels Dec 3, 2017
@frozar frozar force-pushed the fix_text3d branch 3 times, most recently from 778e968 to f55d693 Compare December 4, 2017 19:21
@frozar
Copy link
Contributor Author

frozar commented Dec 4, 2017

⚠️ This PR ihas been rebase on top of the PR #2115

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
the value rens_->GetNumberOfItems(). If this value is equal to 1, there is no custom viewport. I let you check the code.

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 BUILD_TESTS.

@frozar frozar changed the title [TEXT3D] Break things (provocation) [VISU] Fix add/remove of 3D text without custom viewport Dec 4, 2017
@taketwo taketwo added needs: code review Specify why not closed/merged yet and removed needs: more work Specify why not closed/merged yet labels Dec 4, 2017
@SergioRAgostinho
Copy link
Member

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.

@SergioRAgostinho SergioRAgostinho added the needs: author reply Specify why not closed/merged yet label Dec 4, 2017
@frozar
Copy link
Contributor Author

frozar commented Dec 4, 2017

I give a try to the situation you describe, and I got something like this.
screenshot-1512426347

So you get left side (half on the screen) which correspond to the leftPort and on the left side, you will see a part of the first viewport (not custom)... On the picture you can notice that the coordinate system is displayed on every viewport but not the 3D text.

Question: what is the correct behavior? What is the specification of the different viewport: the default one vs the custom ones? In the situation you give, should we display the text everywhere, on every viewport?

It's not clear.

PS: I'll check the parenthesis soon.

Copy link
Member

@SergioRAgostinho SergioRAgostinho left a 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))
Copy link
Member

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

@@ -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))
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here

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 same.

@SergioRAgostinho SergioRAgostinho removed the needs: code review Specify why not closed/merged yet label Dec 5, 2017
@SergioRAgostinho
Copy link
Member

I updated the diff. It was looking weird.

@frozar
Copy link
Contributor Author

frozar commented Dec 5, 2017

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.

Copy link
Member

@SergioRAgostinho SergioRAgostinho left a 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);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, it's done.

@SergioRAgostinho SergioRAgostinho added status: ready to merge and removed needs: author reply Specify why not closed/merged yet labels Dec 5, 2017
@frozar
Copy link
Contributor Author

frozar commented Dec 5, 2017

If you would like any squash before merge, let me know.

@SergioRAgostinho
Copy link
Member

👍 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.

Copy link
Member

@SergioRAgostinho SergioRAgostinho left a 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 ();
Copy link
Member

@SergioRAgostinho SergioRAgostinho Dec 5, 2017

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.

Copy link
Contributor Author

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.

@frozar
Copy link
Contributor Author

frozar commented Dec 5, 2017

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 😉

@SergioRAgostinho SergioRAgostinho merged commit e5d5631 into PointCloudLibrary:master Dec 5, 2017
@SergioRAgostinho SergioRAgostinho mentioned this pull request Dec 5, 2017
@frozar frozar deleted the fix_text3d branch December 5, 2017 22:04
@taketwo taketwo changed the title [VISU] Fix add/remove of 3D text without custom viewport Fix add/remove of 3D text without custom viewport Sep 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants