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
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
31 changes: 23 additions & 8 deletions visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,18 @@ pcl::visualization::PCLVisualizer::addText3D (
if (viewport < 0)
return false;

// If there is no custom viewport and the viewport number is not 0, exit
if (rens_->GetNumberOfItems () <= viewport)
{
PCL_ERROR ("[addText3D] The viewport [%d] doesn't exist (id <%s>)! ",
viewport,
tid.c_str ());
return false;
}

// 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))
Expand All @@ -700,8 +708,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?
Expand Down Expand Up @@ -751,10 +759,18 @@ pcl::visualization::PCLVisualizer::addText3D (
if (viewport < 0)
return false;

// If there is no custom viewport and the viewport number is not 0, exit
if (rens_->GetNumberOfItems () <= viewport)
{
PCL_ERROR ("[addText3D] The viewport [%d] doesn't exist (id <%s>)! ",
viewport,
tid.c_str ());
return false;
}

// 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))
Expand Down Expand Up @@ -786,8 +802,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)
Expand Down
12 changes: 10 additions & 2 deletions visualization/src/pcl_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,18 @@ 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 () <= viewport)
{
PCL_ERROR ("[addText3D] The viewport [%d] doesn't exist (id <%s>)! ",
viewport,
id.c_str ());
return false;
}

// 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);
Expand Down
14 changes: 10 additions & 4 deletions visualization/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
#target_link_libraries(test_geometry pcl_common pcl_features pcl_filters pcl_io pcl_kdtree pcl_visualization)
#add_test(vis_test_geometry test_geometry)

#add_executable(demo_shapes test_shapes.cpp)
#target_link_libraries(demo_shapes pcl_common pcl_io pcl_kdtree pcl_visualization)
add_executable(demo_shapes test_shapes.cpp)
target_link_libraries(demo_shapes pcl_common pcl_io pcl_kdtree pcl_visualization)

#add_executable(demo_shapes_multiport test_shapes_multiport.cpp)
#target_link_libraries(demo_shapes_multiport pcl_common pcl_io pcl_kdtree pcl_visualization)
add_executable(demo_shapes_multiport test_shapes_multiport.cpp)
target_link_libraries(demo_shapes_multiport pcl_common pcl_io pcl_kdtree pcl_visualization)

add_executable(demo_text_simple text_simple.cpp)
target_link_libraries(demo_text_simple pcl_common pcl_visualization)

add_executable(demo_text_simple_multiport text_simple_multiport.cpp)
target_link_libraries(demo_text_simple_multiport pcl_common pcl_visualization)
24 changes: 24 additions & 0 deletions visualization/test/text_simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <pcl/point_types.h>

#include <pcl/visualization/pcl_visualizer.h>

int
main (int argc, char** argv)
{
pcl::visualization::PCLVisualizer viz ("Visualizator");
viz.addCoordinateSystem (1.0);

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.

double orientation[3] = {0., 0., 0.};
viz.addText3D ("Fixed text", pcl::PointXYZ(0.0, 0.0, 0.0), orientation,
1.0, 0.0, 1.0, 0.0, "id_fixed");
viz.spin ();
viz.removeText3D ("id_following");
viz.spin ();
viz.removeText3D ("id_fixed");
viz.spin ();

return (0);
}
30 changes: 30 additions & 0 deletions visualization/test/text_simple_multiport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <pcl/point_types.h>

#include <pcl/visualization/pcl_visualizer.h>

int
main (int argc, char** argv)
{
pcl::visualization::PCLVisualizer viz ("Visualizator");
int leftPort (0);
int rightPort (0);

viz.createViewPort (0, 0, 0.5, 1, leftPort);
viz.createViewPort (0.5, 0, 1, 1, rightPort);

viz.addCoordinateSystem (1.0);

viz.addText3D ("Following text", pcl::PointXYZ(0.0, 0.0, 0.0),
1.0, 1.0, 0.0, 0.0, "id_following", leftPort);
viz.spin ();
double orientation[3] = {0., 0., 0.};
viz.addText3D ("Fixed text", pcl::PointXYZ(0.0, 0.0, 0.0), orientation,
1.0, 0.0, 1.0, 0.0, "id_fixed", rightPort);
viz.spin ();
viz.removeText3D ("id_following", leftPort);
viz.spin ();
viz.removeText3D ("id_fixed", rightPort);
viz.spin ();

return (0);
}