diff --git a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp index e615b11f779..fee53de0548 100644 --- a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp +++ b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp @@ -245,10 +245,11 @@ pcl::visualization::PCLVisualizer::convertPointCloudToVTKPolyData ( float *data = (static_cast (points->GetData ()))->GetPointer (0); // Set the points + vtkIdType ptr = 0; if (cloud->is_dense) { - for (vtkIdType i = 0; i < nr_points; ++i) - memcpy (&data[i * 3], &cloud->points[i].x, 12); // sizeof (float) * 3 + for (vtkIdType i = 0; i < nr_points; ++i, ptr += 3) + std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]); } else { @@ -261,7 +262,7 @@ pcl::visualization::PCLVisualizer::convertPointCloudToVTKPolyData ( !pcl_isfinite (cloud->points[i].z)) continue; - memcpy (&data[j * 3], &cloud->points[i].x, 12); // sizeof (float) * 3 + std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]); j++; } nr_points = j; @@ -600,7 +601,9 @@ pcl::visualization::PCLVisualizer::addSphere (const PointT ¢er, double radiu actor->GetProperty ()->SetRepresentationToSurface (); actor->GetProperty ()->SetInterpolationToFlat (); actor->GetProperty ()->SetColor (r, g, b); +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 actor->GetMapper ()->ImmediateModeRenderingOn (); +#endif actor->GetMapper ()->StaticOn (); actor->GetMapper ()->ScalarVisibilityOff (); actor->GetMapper ()->Update (); @@ -1531,7 +1534,9 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl double minmax[2]; minmax[0] = std::numeric_limits::min (); minmax[1] = std::numeric_limits::max (); +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 am_it->second.actor->GetMapper ()->ImmediateModeRenderingOff (); +#endif am_it->second.actor->GetMapper ()->SetScalarRange (minmax); // Update the mapper @@ -1567,7 +1572,9 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl double minmax[2]; minmax[0] = std::numeric_limits::min (); minmax[1] = std::numeric_limits::max (); +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 am_it->second.actor->GetMapper ()->ImmediateModeRenderingOff (); +#endif am_it->second.actor->GetMapper ()->SetScalarRange (minmax); // Update the mapper @@ -1605,12 +1612,12 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl // Get a pointer to the beginning of the data array float *data = (static_cast (points->GetData ()))->GetPointer (0); - int pts = 0; + vtkIdType pts = 0; // If the dataset is dense (no NaNs) if (cloud->is_dense) { for (vtkIdType i = 0; i < nr_points; ++i, pts += 3) - memcpy (&data[pts], &cloud->points[i].x, 12); // sizeof (float) * 3 + std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[pts]); } else { @@ -1620,8 +1627,7 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl // Check if the point is invalid if (!isFinite (cloud->points[i])) continue; - - memcpy (&data[pts], &cloud->points[i].x, 12); // sizeof (float) * 3 + std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[pts]); pts += 3; j++; } @@ -1642,8 +1648,9 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl scalars->GetRange (minmax); // Update the data polydata->GetPointData ()->SetScalars (scalars); - +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 am_it->second.actor->GetMapper ()->ImmediateModeRenderingOff (); +#endif am_it->second.actor->GetMapper ()->SetScalarRange (minmax); // Update the mapper @@ -1683,17 +1690,16 @@ pcl::visualization::PCLVisualizer::addPolygonMesh ( colors = vtkSmartPointer::New (); colors->SetNumberOfComponents (3); colors->SetName ("Colors"); - - pcl::RGB rgb_data; + uint32_t offset = fields[rgb_idx].offset; for (size_t i = 0; i < cloud->size (); ++i) { if (!isFinite (cloud->points[i])) continue; - memcpy (&rgb_data, reinterpret_cast (&cloud->points[i]) + fields[rgb_idx].offset, sizeof (pcl::RGB)); + const pcl::RGB* const rgb_data = reinterpret_cast(reinterpret_cast (&cloud->points[i]) + offset); unsigned char color[3]; - color[0] = rgb_data.r; - color[1] = rgb_data.g; - color[2] = rgb_data.b; + color[0] = rgb_data->r; + color[1] = rgb_data->g; + color[2] = rgb_data->b; colors->InsertNextTupleValue (color); } } @@ -1707,13 +1713,13 @@ pcl::visualization::PCLVisualizer::addPolygonMesh ( // Get a pointer to the beginning of the data array float *data = static_cast (points->GetData ())->GetPointer (0); - int ptr = 0; + vtkIdType ptr = 0; std::vector lookup; // If the dataset is dense (no NaNs) if (cloud->is_dense) { for (vtkIdType i = 0; i < nr_points; ++i, ptr += 3) - memcpy (&data[ptr], &cloud->points[i].x, sizeof (float) * 3); + std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]); } else { @@ -1726,7 +1732,7 @@ pcl::visualization::PCLVisualizer::addPolygonMesh ( continue; lookup[i] = static_cast (j); - memcpy (&data[ptr], &cloud->points[i].x, sizeof (float) * 3); + std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]); j++; ptr += 3; } @@ -1866,7 +1872,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( if (cloud->is_dense) { for (vtkIdType i = 0; i < nr_points; ++i, ptr += 3) - memcpy (&data[ptr], &cloud->points[i].x, sizeof (float) * 3); + std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]); } else { @@ -1879,7 +1885,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( continue; lookup [i] = static_cast (j); - memcpy (&data[ptr], &cloud->points[i].x, sizeof (float) * 3); + std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]); j++; ptr += 3; } @@ -1898,19 +1904,17 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( rgb_idx = pcl::getFieldIndex (*cloud, "rgba", fields); if (rgb_idx != -1 && colors) { - pcl::RGB rgb_data; int j = 0; + uint32_t offset = fields[rgb_idx].offset; for (size_t i = 0; i < cloud->size (); ++i) { if (!isFinite (cloud->points[i])) continue; - memcpy (&rgb_data, - reinterpret_cast (&cloud->points[i]) + fields[rgb_idx].offset, - sizeof (pcl::RGB)); + const pcl::RGB* const rgb_data = reinterpret_cast(reinterpret_cast (&cloud->points[i]) + offset); unsigned char color[3]; - color[0] = rgb_data.r; - color[1] = rgb_data.g; - color[2] = rgb_data.b; + color[0] = rgb_data->r; + color[1] = rgb_data->g; + color[2] = rgb_data->b; colors->SetTupleValue (j++, color); } } diff --git a/visualization/include/pcl/visualization/pcl_visualizer.h b/visualization/include/pcl/visualization/pcl_visualizer.h index 9b4be508898..b68b8ed1a01 100644 --- a/visualization/include/pcl/visualization/pcl_visualizer.h +++ b/visualization/include/pcl/visualization/pcl_visualizer.h @@ -103,7 +103,8 @@ namespace pcl */ PCLVisualizer (const std::string &name = "", const bool create_interactor = true); - /** \brief PCL Visualizer constructor. + /** \brief PCL Visualizer constructor. It looks through the passed argv arguments to find the "-cam *.cam" argument. + * If the search failed, the name for cam file is calculated with boost uuid. If there is no such file, camera is not initilalized. * \param[in] argc * \param[in] argv * \param[in] name the window name (empty by default) diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index 962ca703aee..d7fe0e9644a 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -1217,7 +1217,9 @@ pcl::visualization::PCLVisualizer::createActorFromVTKDataSet (const vtkSmartPoin mapper->ScalarVisibilityOn (); } } +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 mapper->ImmediateModeRenderingOff (); +#endif actor->SetNumberOfCloudPoints (int (std::max (1, data->GetNumberOfPoints () / 10))); actor->GetProperty ()->SetInterpolationToFlat (); @@ -1297,7 +1299,9 @@ pcl::visualization::PCLVisualizer::createActorFromVTKDataSet (const vtkSmartPoin mapper->ScalarVisibilityOn (); } } +#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2 mapper->ImmediateModeRenderingOff (); +#endif //actor->SetNumberOfCloudPoints (int (std::max (1, data->GetNumberOfPoints () / 10))); actor->GetProperty ()->SetInterpolationToFlat (); @@ -1668,7 +1672,7 @@ pcl::visualization::PCLVisualizer::setPointCloudSelected (const bool selected, c if (selected) { actor->GetProperty ()->EdgeVisibilityOn (); - actor->GetProperty ()->SetEdgeColor (1.0,0.0,0.0); + actor->GetProperty ()->SetEdgeColor (1.0, 0.0, 0.0); actor->Modified (); } else @@ -2097,7 +2101,7 @@ pcl::visualization::PCLVisualizer::getCameras (std::vectorGetNextItem ()) != NULL) { - cameras.push_back(Camera()); + cameras.push_back (Camera ()); cameras.back ().pos[0] = renderer->GetActiveCamera ()->GetPosition ()[0]; cameras.back ().pos[1] = renderer->GetActiveCamera ()->GetPosition ()[1]; cameras.back ().pos[2] = renderer->GetActiveCamera ()->GetPosition ()[2]; @@ -2458,7 +2462,7 @@ pcl::visualization::PCLVisualizer::addCube (float x_min, float x_max, vtkSmartPointer actor; createActorFromVTKDataSet (data, actor); actor->GetProperty ()->SetRepresentationToSurface (); - actor->GetProperty ()->SetColor (r,g,b); + actor->GetProperty ()->SetColor (r, g, b); addActorToRenderer (actor, viewport); // Save the pointer/ID pair to the global actor map @@ -2543,7 +2547,7 @@ pcl::visualization::PCLVisualizer::addModelFromPolyData ( #else trans_filter->SetInputData (polydata); #endif - trans_filter->Update(); + trans_filter->Update (); // Create an Actor vtkSmartPointer actor; @@ -3104,9 +3108,11 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (const pcl::PolygonMesh &poly_ pcl::fromPCLPointCloud2 (poly_mesh.cloud, *point_cloud); poly_points->SetNumberOfPoints (point_cloud->points.size ()); - size_t i; - for (i = 0; i < point_cloud->points.size (); ++i) - poly_points->InsertPoint (i, point_cloud->points[i].x, point_cloud->points[i].y, point_cloud->points[i].z); + for (size_t i = 0; i < point_cloud->points.size (); ++i) + { + const pcl::PointXYZ& p = point_cloud->points[i]; + poly_points->InsertPoint (i, p.x, p.y, p.z); + } bool has_color = false; vtkSmartPointer colors = vtkSmartPointer::New (); @@ -3116,34 +3122,34 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (const pcl::PolygonMesh &poly_ colors->SetNumberOfComponents (3); colors->SetName ("Colors"); pcl::PointCloud cloud; - pcl::fromPCLPointCloud2(poly_mesh.cloud, cloud); - for (i = 0; i < cloud.points.size (); ++i) + pcl::fromPCLPointCloud2 (poly_mesh.cloud, cloud); + for (size_t i = 0; i < cloud.points.size (); ++i) { - const unsigned char color[3] = {cloud.points[i].r, cloud.points[i].g, cloud.points[i].b}; - colors->InsertNextTupleValue(color); + const unsigned char color[3] = { cloud.points[i].r, cloud.points[i].g, cloud.points[i].b }; + colors->InsertNextTupleValue (color); } } - if (pcl::getFieldIndex(poly_mesh.cloud, "rgba") != -1) + if (pcl::getFieldIndex (poly_mesh.cloud, "rgba") != -1) { has_color = true; colors->SetNumberOfComponents (3); colors->SetName ("Colors"); pcl::PointCloud cloud; - pcl::fromPCLPointCloud2(poly_mesh.cloud, cloud); - for (i = 0; i < cloud.points.size (); ++i) + pcl::fromPCLPointCloud2 (poly_mesh.cloud, cloud); + for (size_t i = 0; i < cloud.points.size (); ++i) { - const unsigned char color[3] = {cloud.points[i].r, cloud.points[i].g, cloud.points[i].b}; - colors->InsertNextTupleValue(color); + const unsigned char color[3] = { cloud.points[i].r, cloud.points[i].g, cloud.points[i].b }; + colors->InsertNextTupleValue (color); } } vtkSmartPointer actor; - if (poly_mesh.polygons.size() > 1) + if (poly_mesh.polygons.size () > 1) { //create polys from polyMesh.polygons vtkSmartPointer cell_array = vtkSmartPointer::New (); - for (i = 0; i < poly_mesh.polygons.size (); i++) + for (size_t i = 0; i < poly_mesh.polygons.size (); i++) { size_t n_points (poly_mesh.polygons[i].vertices.size ()); cell_array->InsertNextCell (int (n_points)); @@ -3151,23 +3157,23 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (const pcl::PolygonMesh &poly_ cell_array->InsertCellPoint (poly_mesh.polygons[i].vertices[j]); } - vtkSmartPointer polydata = vtkSmartPointer::New(); -// polydata->SetStrips (cell_array); + vtkSmartPointer polydata = vtkSmartPointer::New (); + // polydata->SetStrips (cell_array); polydata->SetPolys (cell_array); polydata->SetPoints (poly_points); if (has_color) - polydata->GetPointData()->SetScalars(colors); + polydata->GetPointData ()->SetScalars (colors); createActorFromVTKDataSet (polydata, actor); } - else if (poly_mesh.polygons.size() == 1) + else if (poly_mesh.polygons.size () == 1) { vtkSmartPointer polygon = vtkSmartPointer::New (); size_t n_points = poly_mesh.polygons[0].vertices.size (); polygon->GetPointIds ()->SetNumberOfIds (n_points - 1); - for (size_t j=0; j < (n_points - 1); j++) + for (size_t j = 0; j < (n_points - 1); j++) polygon->GetPointIds ()->SetId (j, poly_mesh.polygons[0].vertices[j]); vtkSmartPointer poly_grid = vtkSmartPointer::New (); @@ -3180,7 +3186,7 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (const pcl::PolygonMesh &poly_ } else { - PCL_ERROR("PCLVisualizer::addPolygonMesh: No polygons\n"); + PCL_ERROR ("PCLVisualizer::addPolygonMesh: No polygons\n"); return false; } @@ -3205,7 +3211,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( const std::string &id) { - if (poly_mesh.polygons.empty()) + if (poly_mesh.polygons.empty ()) { pcl::console::print_error ("[updatePolygonMesh] No vertices given!\n"); return (false); @@ -3220,7 +3226,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( pcl::PointCloud::Ptr cloud (new pcl::PointCloud ()); pcl::fromPCLPointCloud2 (poly_mesh.cloud, *cloud); - std::vector verts(poly_mesh.polygons); // copy vector + std::vector verts (poly_mesh.polygons); // copy vector // Get the current poly data vtkSmartPointer polydata = static_cast(am_it->second.actor->GetMapper ())->GetInput (); @@ -3229,7 +3235,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( vtkSmartPointer cells = polydata->GetStrips (); if (!cells) return (false); - vtkSmartPointer points = polydata->GetPoints (); + vtkSmartPointer points = polydata->GetPoints (); // Copy the new point array in vtkIdType nr_points = cloud->points.size (); points->SetNumberOfPoints (nr_points); @@ -3243,7 +3249,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( if (cloud->is_dense) { for (vtkIdType i = 0; i < nr_points; ++i, ptr += 3) - memcpy (&data[ptr], &cloud->points[i].x, sizeof (float) * 3); + std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]); } else { @@ -3255,8 +3261,8 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( if (!isFinite (cloud->points[i])) continue; - lookup [i] = static_cast (j); - memcpy (&data[ptr], &cloud->points[i].x, sizeof (float) * 3); + lookup[i] = static_cast (j); + std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]); j++; ptr += 3; } @@ -3338,7 +3344,7 @@ pcl::visualization::PCLVisualizer::addPolylineFromPolygonMesh ( polyLine->GetPointIds()->SetNumberOfIds(polymesh.polygons[i].vertices.size()); for(unsigned int k = 0; k < polymesh.polygons[i].vertices.size(); k++) { - polyLine->GetPointIds()->SetId(k,polymesh.polygons[i].vertices[k]); + polyLine->GetPointIds ()->SetId (k, polymesh.polygons[i].vertices[k]); } cells->InsertNextCell (polyLine); @@ -3407,21 +3413,21 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, // total number of vertices std::size_t nb_vertices = 0; for (std::size_t i = 0; i < mesh.tex_polygons.size (); ++i) - nb_vertices+= mesh.tex_polygons[i].size (); + nb_vertices += mesh.tex_polygons[i].size (); // no vertices --> exit if (nb_vertices == 0) { - PCL_ERROR("[PCLVisualizer::addTextureMesh] No vertices found!\n"); + PCL_ERROR ("[PCLVisualizer::addTextureMesh] No vertices found!\n"); return (false); } // total number of coordinates std::size_t nb_coordinates = 0; for (std::size_t i = 0; i < mesh.tex_coordinates.size (); ++i) - nb_coordinates+= mesh.tex_coordinates[i].size (); + nb_coordinates += mesh.tex_coordinates[i].size (); // no texture coordinates --> exit if (nb_coordinates == 0) { - PCL_ERROR("[PCLVisualizer::addTextureMesh] No textures coordinates found!\n"); + PCL_ERROR ("[PCLVisualizer::addTextureMesh] No textures coordinates found!\n"); return (false); } @@ -3434,10 +3440,10 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, (pcl::getFieldIndex(mesh.cloud, "rgb") != -1)) { pcl::PointCloud cloud; - pcl::fromPCLPointCloud2(mesh.cloud, cloud); + pcl::fromPCLPointCloud2 (mesh.cloud, cloud); if (cloud.points.size () == 0) { - PCL_ERROR("[PCLVisualizer::addTextureMesh] Cloud is empty!\n"); + PCL_ERROR ("[PCLVisualizer::addTextureMesh] Cloud is empty!\n"); return (false); } convertToVtkMatrix (cloud.sensor_origin_, cloud.sensor_orientation_, transformation); @@ -3449,8 +3455,8 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, { const pcl::PointXYZRGB &p = cloud.points[i]; poly_points->InsertPoint (i, p.x, p.y, p.z); - const unsigned char color[3] = {p.r, p.g, p.b}; - colors->InsertNextTupleValue(color); + const unsigned char color[3] = { p.r, p.g, p.b }; + colors->InsertNextTupleValue (color); } } else @@ -3460,7 +3466,7 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, // no points --> exit if (cloud->points.size () == 0) { - PCL_ERROR("[PCLVisualizer::addTextureMesh] Cloud is empty!\n"); + PCL_ERROR ("[PCLVisualizer::addTextureMesh] Cloud is empty!\n"); return (false); } convertToVtkMatrix (cloud->sensor_origin_, cloud->sensor_orientation_, transformation); @@ -3485,11 +3491,11 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, } } - vtkSmartPointer polydata = vtkSmartPointer::New(); + vtkSmartPointer polydata = vtkSmartPointer::New (); polydata->SetPolys (polys); polydata->SetPoints (poly_points); if (has_color) - polydata->GetPointData()->SetScalars(colors); + polydata->GetPointData ()->SetScalars (colors); vtkSmartPointer mapper = vtkSmartPointer::New (); #if VTK_MAJOR_VERSION < 6 @@ -3534,7 +3540,7 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, std::string this_coordinates_name = ss.str (); coordinates->SetName (this_coordinates_name.c_str ()); - for (std::size_t t = 0 ; t < mesh.tex_coordinates.size (); ++t) + for (std::size_t t = 0; t < mesh.tex_coordinates.size (); ++t) if (t == tex_id) for (std::size_t tc = 0; tc < mesh.tex_coordinates[t].size (); ++tc) coordinates->InsertNextTuple2 (mesh.tex_coordinates[t][tc][0], @@ -3547,7 +3553,7 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, this_coordinates_name.c_str (), vtkDataObject::FIELD_ASSOCIATION_POINTS); polydata->GetPointData ()->AddArray (coordinates); - actor->GetProperty ()->SetTexture(tu, texture); + actor->GetProperty ()->SetTexture (tu, texture); ++tex_id; ++tu; } @@ -3574,7 +3580,7 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, coordinates->SetTuple2 (tc, uv[0], uv[1]); } coordinates->SetName ("TCoords"); - polydata->GetPointData ()->SetTCoords(coordinates); + polydata->GetPointData ()->SetTCoords (coordinates); // apply texture actor->SetTexture (texture); } // end of one texture @@ -3607,7 +3613,7 @@ pcl::visualization::PCLVisualizer::setRepresentationToSurfaceForAllActors () while ((actor = actors->GetNextActor ()) != NULL) { actor->GetProperty ()->SetRepresentationToSurface (); - actor->GetProperty ()->SetLighting(true); + actor->GetProperty ()->SetLighting (true); } } } @@ -3646,7 +3652,7 @@ pcl::visualization::PCLVisualizer::setRepresentationToWireframeForAllActors () while ((actor = actors->GetNextActor ()) != NULL) { actor->GetProperty ()->SetRepresentationToWireframe (); - actor->GetProperty ()->SetLighting(false); + actor->GetProperty ()->SetLighting (false); } } } @@ -3796,7 +3802,7 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere ( vtkSmartPointer cells_sphere = sphere->GetPolys (); cam_positions.resize (sphere->GetNumberOfPolys ()); - size_t i=0; + size_t i = 0; for (cells_sphere->InitTraversal (); cells_sphere->GetNextCell (npts_com, ptIds_com);) { sphere->GetPoint (ptIds_com[0], p1_com); @@ -4032,43 +4038,43 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere ( #else //THIS CAN BE USED WHEN VTK >= 5.4 IS REQUIRED... vtkVisibleCellSelector is deprecated from VTK5.4 vtkSmartPointer hardware_selector = vtkSmartPointer::New (); - hardware_selector->ClearBuffers(); - vtkSmartPointer hdw_selection = vtkSmartPointer::New (); - hardware_selector->SetRenderer (renderer); - hardware_selector->SetArea (0, 0, xres - 1, yres - 1); - hardware_selector->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_CELLS); - hdw_selection = hardware_selector->Select (); - if (!hdw_selection || !hdw_selection->GetNode (0) || !hdw_selection->GetNode (0)->GetSelectionList ()) - { - PCL_WARN ("[renderViewTesselatedSphere] Invalid selection, skipping!\n"); - continue; - } - - 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++) - { - int id_mesh = static_cast (ids->GetValue (sel_id)); - vtkCell * cell = polydata->GetCell (id_mesh); - vtkTriangle* triangle = dynamic_cast (cell); - if (!triangle) - { - PCL_WARN ("[renderViewTesselatedSphere] Invalid triangle %d, skipping!\n", id_mesh); - continue; - } - - double p0[3]; - double p1[3]; - double p2[3]; - triangle->GetPoints ()->GetPoint (0, p0); - triangle->GetPoints ()->GetPoint (1, p1); - triangle->GetPoints ()->GetPoint (2, p2); - area = vtkTriangle::TriangleArea (p0, p1, p2); - visible_area += area; - } + hardware_selector->ClearBuffers (); + vtkSmartPointer hdw_selection = vtkSmartPointer::New (); + hardware_selector->SetRenderer (renderer); + hardware_selector->SetArea (0, 0, xres - 1, yres - 1); + hardware_selector->SetFieldAssociation (vtkDataObject::FIELD_ASSOCIATION_CELLS); + hdw_selection = hardware_selector->Select (); + if (!hdw_selection || !hdw_selection->GetNode (0) || !hdw_selection->GetNode (0)->GetSelectionList ()) + { + PCL_WARN ("[renderViewTesselatedSphere] Invalid selection, skipping!\n"); + continue; + } + + 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++) + { + int id_mesh = static_cast (ids->GetValue (sel_id)); + vtkCell * cell = polydata->GetCell (id_mesh); + vtkTriangle* triangle = dynamic_cast (cell); + if (!triangle) + { + PCL_WARN ("[renderViewTesselatedSphere] Invalid triangle %d, skipping!\n", id_mesh); + continue; + } + + double p0[3]; + double p1[3]; + double p2[3]; + triangle->GetPoints ()->GetPoint (0, p0); + triangle->GetPoints ()->GetPoint (1, p1); + triangle->GetPoints ()->GetPoint (2, p2); + area = vtkTriangle::TriangleArea (p0, p1, p2); + visible_area += area; + } #endif enthropies.push_back (static_cast (visible_area / totalArea)); @@ -4136,7 +4142,7 @@ pcl::visualization::PCLVisualizer::renderView (int xres, int yres, pcl::PointClo { if (rens_->GetNumberOfItems () > 1) { - PCL_WARN("[renderView] Method will render only the first viewport\n"); + PCL_WARN ("[renderView] Method will render only the first viewport\n"); return; } @@ -4299,7 +4305,7 @@ pcl::visualization::PCLVisualizer::updateCells (vtkSmartPointer for (vtkIdType i = 0; i < nr_points; ++i, cell += 2) { *cell = 1; - *(cell+1) = i; + *(cell + 1) = i; } // Save the results in initcells @@ -4342,8 +4348,8 @@ pcl::visualization::PCLVisualizer::getTransformationMatrix ( Eigen::Matrix4f &transformation) { transformation.setIdentity (); - transformation.block<3,3>(0,0) = orientation.toRotationMatrix (); - transformation.block<3,1>(0,3) = origin.head (3); + transformation.block<3, 3> (0, 0) = orientation.toRotationMatrix (); + transformation.block<3, 1> (0, 3) = origin.head (3); } ////////////////////////////////////////////////////////////////////////////////////////////// @@ -4385,7 +4391,7 @@ pcl::visualization::PCLVisualizer::convertToEigenMatrix ( { for (int i = 0; i < 4; i++) for (int k = 0; k < 4; k++) - m (i,k) = static_cast (vtk_matrix->GetElement (i, k)); + m (i, k) = static_cast (vtk_matrix->GetElement (i, k)); } ////////////////////////////////////////////////////////////////////////////////////////////// @@ -4481,7 +4487,7 @@ pcl::visualization::PCLVisualizer::setWindowBorders (bool mode) if (win_) win_->SetBorders (mode); } - + ////////////////////////////////////////////////////////////////////////////////////////////// void pcl::visualization::PCLVisualizer::setPosition (int x, int y) @@ -4492,7 +4498,7 @@ pcl::visualization::PCLVisualizer::setPosition (int x, int y) win_->Render (); } } - + ////////////////////////////////////////////////////////////////////////////////////////////// void pcl::visualization::PCLVisualizer::setSize (int xw, int yw) @@ -4558,13 +4564,13 @@ pcl::visualization::PCLVisualizer::getGeometryHandlerIndex (const std::string &i bool pcl::visualization::PCLVisualizer::wasStopped () const { - if (interactor_ != NULL) + if (interactor_ != NULL) #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4)) return (interactor_->stopped); #else - return (stopped_); + return (stopped_); #endif - else + else return (true); } @@ -4572,11 +4578,11 @@ pcl::visualization::PCLVisualizer::wasStopped () const void pcl::visualization::PCLVisualizer::resetStoppedFlag () { - if (interactor_ != NULL) + if (interactor_ != NULL) #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4)) interactor_->stopped = false; #else - stopped_ = false; + stopped_ = false; #endif } @@ -4607,19 +4613,18 @@ pcl::visualization::PCLVisualizer::ExitMainLoopTimerCallback::Execute ( { if (event_id != vtkCommand::TimerEvent) return; - int timer_id = * static_cast (call_data); + int timer_id = *static_cast (call_data); //PCL_WARN ("[pcl::visualization::PCLVisualizer::ExitMainLoopTimerCallback] Timer %d called.\n", timer_id); if (timer_id != right_timer_id) return; // Stop vtk loop and send notification to app to wake it up - if (pcl_visualizer->interactor_) #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4)) - pcl_visualizer->interactor_->stopLoop (); + pcl_visualizer->interactor_->stopLoop (); #else - pcl_visualizer->interactor_->TerminateApp (); + pcl_visualizer->interactor_->TerminateApp (); #endif } - + ////////////////////////////////////////////////////////////////////////////////////////////// void pcl::visualization::PCLVisualizer::ExitCallback::Execute (