Skip to content

Commit

Permalink
Merge pull request #1245 from VictorLamoine/visualizer_vtk_fixes
Browse files Browse the repository at this point in the history
Check that vtk SafeDownCast worked
  • Loading branch information
taketwo committed Jun 9, 2015
2 parents a08f964 + 47339f5 commit 646c4dd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,16 @@ pcl::visualization::PCLVisualizer::updateSphere (const PointT &center, double ra
// Get the actor pointer
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second);
if (!actor)
return (false);
#if VTK_MAJOR_VERSION < 6
vtkAlgorithm *algo = actor->GetMapper ()->GetInput ()->GetProducerPort ()->GetProducer ();
#else
vtkAlgorithm *algo = actor->GetMapper ()->GetInputAlgorithm ();
#endif
vtkSphereSource *src = vtkSphereSource::SafeDownCast (algo);
if (!src)
return (false);

src->SetCenter (double (center.x), double (center.y), double (center.z));
src->SetRadius (radius);
Expand Down Expand Up @@ -1170,6 +1174,8 @@ pcl::visualization::PCLVisualizer::addCorrespondences (
else
{
vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast (am_it->second);
if (!actor)
return (false);
// Update the mapper
#if VTK_MAJOR_VERSION < 6
reinterpret_cast<vtkPolyDataMapper*>(actor->GetMapper ())->SetInput (line_data);
Expand Down Expand Up @@ -1764,6 +1770,8 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh (

// Update colors
vtkUnsignedCharArray* colors = vtkUnsignedCharArray::SafeDownCast (polydata->GetPointData ()->GetScalars ());
if (!colors)
return (false);
int rgb_idx = -1;
std::vector<pcl::PCLPointField> fields;
rgb_idx = pcl::getFieldIndex (*cloud, "rgb", fields);
Expand Down
37 changes: 33 additions & 4 deletions visualization/src/pcl_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ namespace
int
getDefaultScalarInterpolationForDataSet (vtkDataSet* data)
{
vtkPolyData* polyData = vtkPolyData::SafeDownCast (data);
vtkPolyData* polyData = vtkPolyData::SafeDownCast (data); // Check that polyData != NULL in case of segfault
return (polyData && polyData->GetNumberOfCells () != polyData->GetNumberOfVerts ());
}

Expand Down Expand Up @@ -1271,6 +1271,8 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties (
}
// Get the actor pointer
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor);
if (!actor)
return (false);

switch (property)
{
Expand Down Expand Up @@ -1301,6 +1303,8 @@ pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (int propert
return (false);
// Get the actor pointer
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor);
if (!actor)
return (false);

switch (property)
{
Expand Down Expand Up @@ -1346,6 +1350,8 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties (
}
// Get the actor pointer
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor);
if (!actor)
return (false);

switch (property)
{
Expand Down Expand Up @@ -1401,6 +1407,8 @@ pcl::visualization::PCLVisualizer::setPointCloudSelected (const bool selected, c
}
// Get the actor pointer
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor);
if (!actor)
return (false);

if (selected)
{
Expand Down Expand Up @@ -1432,6 +1440,8 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties (
}
// Get the actor pointer
vtkActor* actor = vtkActor::SafeDownCast (am_it->second);
if (!actor)
return (false);

switch (property)
{
Expand Down Expand Up @@ -1477,6 +1487,8 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties (
}
// Get the actor pointer
vtkActor* actor = vtkActor::SafeDownCast (am_it->second);
if (!actor)
return (false);

switch (property)
{
Expand All @@ -1501,6 +1513,8 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties (
case PCL_VISUALIZER_FONT_SIZE:
{
vtkTextActor* text_actor = vtkTextActor::SafeDownCast (am_it->second);
if (!text_actor)
return (false);
vtkSmartPointer<vtkTextProperty> tprop = text_actor->GetTextProperty ();
tprop->SetFontSize (int (value));
text_actor->Modified ();
Expand Down Expand Up @@ -1710,6 +1724,9 @@ pcl::visualization::PCLVisualizer::updateShapePose (const std::string &id, const
else
actor = vtkLODActor::SafeDownCast (am_it->second);

if (!actor)
return (false);

vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New ();

convertToVtkMatrix (pose.matrix (), matrix);
Expand All @@ -1733,6 +1750,9 @@ pcl::visualization::PCLVisualizer::updateCoordinateSystemPose (const std::string
else
actor = vtkLODActor::SafeDownCast (am_it->second);

if (!actor)
return (false);

vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New ();

convertToVtkMatrix (pose.matrix (), matrix);
Expand Down Expand Up @@ -2664,11 +2684,12 @@ pcl::visualization::PCLVisualizer::updateText (const std::string &text, int xpos

// Retrieve the Actor
vtkTextActor* actor = vtkTextActor::SafeDownCast (am_it->second);
if (!actor)
return (false);

actor->SetPosition (xpos, ypos);
actor->SetInput (text.c_str ());

actor->Modified ();

return (true);
}

Expand All @@ -2689,6 +2710,8 @@ pcl::visualization::PCLVisualizer::updateText (const std::string &text, int xpos

// Create the Actor
vtkTextActor* actor = vtkTextActor::SafeDownCast (am_it->second);
if (!actor)
return (false);
actor->SetPosition (xpos, ypos);
actor->SetInput (text.c_str ());

Expand Down Expand Up @@ -2716,6 +2739,8 @@ pcl::visualization::PCLVisualizer::updateText (const std::string &text, int xpos

// Retrieve the Actor
vtkTextActor *actor = vtkTextActor::SafeDownCast (am_it->second);
if (!actor)
return (false);

actor->SetPosition (xpos, ypos);
actor->SetInput (text.c_str ());
Expand Down Expand Up @@ -3210,6 +3235,8 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh,

vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New ();
vtkOpenGLHardwareSupport* hardware = vtkOpenGLRenderWindow::SafeDownCast (win_)->GetHardwareSupport ();
if (!hardware)
return (false);
bool supported = hardware->GetSupportsMultiTexturing ();
// Check if hardware support multi texture
std::size_t texture_units (hardware->GetNumberOfFixedTextureUnits ());
Expand Down Expand Up @@ -3745,8 +3772,10 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere (
continue;
}

vtkSmartPointer<vtkIdTypeArray> ids = vtkSmartPointer<vtkIdTypeArray>::New ();
vtkSmartPointer<vtkIdTypeArray> ids;
ids = vtkIdTypeArray::SafeDownCast(hdw_selection->GetNode(0)->GetSelectionList());
if (!ids)
return;
double visible_area = 0;
for (int sel_id = 0; sel_id < (ids->GetNumberOfTuples ()); sel_id++)
{
Expand Down

0 comments on commit 646c4dd

Please sign in to comment.