Last active
August 29, 2015 14:24
-
-
Save deli4iled/c06ea4c112591ae6af65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cv::viz::Mesh load(InputArray pointCloud){ | |
vtkSmartPointer<vtkCloudMatSource> cloud_source = vtkSmartPointer<vtkCloudMatSource>::New(); | |
cloud_source->SetCloud(pointCloud); | |
vtkSmartPointer<vtkPolyData> polydata = cloud_source->GetOutput(); | |
Mesh mesh; | |
vtkSmartPointer<vtkCloudMatSink> sink = vtkSmartPointer<vtkCloudMatSink>::New(); | |
sink->SetOutput(mesh.cloud, mesh.colors, mesh.normals, mesh.tcoords); | |
sink->SetInputConnection(reader->GetOutputPort()); | |
sink->Write(); | |
// Now handle the polygons | |
vtkSmartPointer<vtkCellArray> polygons = polydata->GetPolys(); | |
mesh.polygons.create(1, polygons->GetSize(), CV_32SC1); | |
int* poly_ptr = mesh.polygons.ptr<int>(); | |
polygons->InitTraversal(); | |
vtkIdType nr_cell_points, *cell_points; | |
while (polygons->GetNextCell(nr_cell_points, cell_points)) | |
{ | |
*poly_ptr++ = nr_cell_points; | |
for (vtkIdType i = 0; i < nr_cell_points; ++i) | |
*poly_ptr++ = (int)cell_points[i]; | |
} | |
return mesh; | |
} | |
Mesh mesh = load(pointCloud); //pointCloud è restituita da reproject3d | |
//Costruzione finestra per visualizzazione | |
viz::Viz3d myWindow("Coordinate Frame"); | |
/// Add coordinate axes | |
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); | |
myWindow.setBackgroundColor(viz::Color::gray()); | |
myWindow.spin(); | |
//WMesh da mesh | |
viz::WMesh mesh_widget(mesh); | |
mesh_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); | |
myWindow.showWidget("point cloud", mesh_widget); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment