void addSupervoxelConnectionsToViewer(pcl::PointXYZRGBA &supervoxel_center, pcl::PointCloud< pcl::PointXYZRGBA> &adjacent_supervoxel_centers, std::string supervoxel_name, pcl::visualization::PCLVisualizer &viewer) { vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New(); vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New(); // Setup colors unsigned char red[3] = {255, 0, 0}; unsigned char green[3] = {0, 255, 0}; unsigned char blue[3] = {0, 0, 255}; vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New(); colors->SetNumberOfComponents(3); colors->SetName("Colors"); colors->InsertNextTupleValue(red); colors->InsertNextTupleValue(green); colors->InsertNextTupleValue(blue); //Iterate through all adjacent points, and add a center point to adjacent point pair pcl::PointCloud< pcl::PointXYZRGBA>::iterator adjacent_itr = adjacent_supervoxel_centers.begin(); for(; adjacent_itr != adjacent_supervoxel_centers.end(); ++adjacent_itr) { points->InsertNextPoint(supervoxel_center.data); points->InsertNextPoint(adjacent_itr->data); } // Create a polydata to store everything in vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New(); // Add the points to the dataset polyData->SetPoints(points); polyLine->GetPointIds()->SetNumberOfIds(points->GetNumberOfPoints()); for(unsigned int i = 0; i < points->GetNumberOfPoints(); i++) { polyLine->GetPointIds()->SetId(i, i); } cells->InsertNextCell(polyLine); // Add the lines to the dataset polyData->SetLines(cells); // polyData->GetPointData()->SetScalars(colors); viewer.addModelFromPolyData(polyData, supervoxel_name); }