From 47339f5b7cb818da95ca40acb1d06cd8b2f0c06b Mon Sep 17 00:00:00 2001 From: Victor Lamoine Date: Thu, 21 May 2015 16:28:38 +0200 Subject: [PATCH] Check that vtk SafeDownCast worked --- .../pcl/visualization/impl/pcl_visualizer.hpp | 8 ++++ visualization/src/pcl_visualizer.cpp | 37 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp index be42398bc8c..035b17b1a09 100644 --- a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp +++ b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp @@ -620,12 +620,16 @@ pcl::visualization::PCLVisualizer::updateSphere (const PointT ¢er, 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); @@ -1170,6 +1174,8 @@ pcl::visualization::PCLVisualizer::addCorrespondences ( else { vtkSmartPointer actor = vtkLODActor::SafeDownCast (am_it->second); + if (!actor) + return (false); // Update the mapper #if VTK_MAJOR_VERSION < 6 reinterpret_cast(actor->GetMapper ())->SetInput (line_data); @@ -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 fields; rgb_idx = pcl::getFieldIndex (*cloud, "rgb", fields); diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index 52d80e4740c..e9edcffcafb 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -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 ()); } @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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 tprop = text_actor->GetTextProperty (); tprop->SetFontSize (int (value)); text_actor->Modified (); @@ -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 matrix = vtkSmartPointer::New (); convertToVtkMatrix (pose.matrix (), matrix); @@ -1733,6 +1750,9 @@ pcl::visualization::PCLVisualizer::updateCoordinateSystemPose (const std::string else actor = vtkLODActor::SafeDownCast (am_it->second); + if (!actor) + return (false); + vtkSmartPointer matrix = vtkSmartPointer::New (); convertToVtkMatrix (pose.matrix (), matrix); @@ -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); } @@ -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 ()); @@ -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 ()); @@ -3210,6 +3235,8 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, vtkSmartPointer actor = vtkSmartPointer::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 ()); @@ -3745,8 +3772,10 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere ( continue; } - vtkSmartPointer ids = vtkSmartPointer::New (); + vtkSmartPointer 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++) {