You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function vtkPolyDataToPointCloud allows the user to convert a mesh to a colored point cloud; but the color information is not correctly handled. The result is a black point cloud.
Test code
#include<iostream>
#include<pcl/common/common.h>
#include<pcl/io/vtk_lib_io.h>
#include<pcl/io/vtk_io.h>
#include<pcl/io/ply_io.h>
#include<pcl/visualization/pcl_visualizer.h>
#include<vtkPolyDataReader.h>typedef pcl::PointXYZRGBA PointT;
typedef pcl::PointCloud<PointT> PointCloudT;
intmain (int argc,
char** argv)
{
if (argc != 3)
{
PCL_ERROR("Usage: %s input.ply output.ply", argv[0]);
return -1;
}
pcl::PolygonMesh mesh;
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New ();
PointCloudT::Ptrcloud (new PointCloudT);
pcl::visualization::PCLVisualizer viewer ("PCL visualizer");
if (pcl::io::loadPolygonFilePLY (argv[1], mesh) < 0)
return -1;
pcl::io::mesh2vtk (mesh, polydata);
viewer.addPolygonMesh (mesh, "mesh");
//viewer.addModelFromPolyData(polydata, "mesh");
viewer.spin ();
viewer.removeShape ("mesh");
pcl::io::vtkPolyDataToPointCloud (polydata, *cloud);
// FIXME: Alpha is set to 0 (or not set at all)for (size_t i = 0; i < cloud->size (); ++i)
cloud->points[i].a = 255;
for (size_t i = 0; i < cloud->size () / 100; ++i)
std::cout << cloud->points[i] << std::endl;
viewer.addPointCloud (cloud);
viewer.setBackgroundColor (0.2, 0.2, 0.2);
viewer.spin ();
return0;
}
Result is a black cloud (alpha = 0) without the FIXME comment.
#include<iostream>
#include<pcl/common/common.h>
#include<pcl/io/vtk_lib_io.h>
#include<pcl/io/vtk_io.h>
#include<vtkPolyDataReader.h>
#include<pcl/visualization/pcl_visualizer.h>intmain (int argc,
char** argv)
{
pcl::visualization::PCLVisualizer viewer ("PCL visualizer");
pcl::PolygonMesh mesh;
pcl::io::loadPolygonFilePLY(argv[1], mesh);
viewer.addPolygonMesh(mesh);
viewer.setBackgroundColor(0.2, 0.2, 0.2);
while (!viewer.wasStopped())
viewer.spinOnce();
pcl::io::saveVTKFile("/home/victor/temp.vtk", mesh);
vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
reader->SetFileName("/home/vitemp.vtk");
reader->Update();
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
viewer.addModelFromPolyData(polydata); // To check that the conversion until here is fine
pcl::PointCloud<pcl::PointXYZRGBA> cloud;
pcl::io::vtkPolyDataToPointCloud(polydata, cloud);
std::cerr << "Cloud:\n" << cloud << std::endl;
pcl::PCDWriter pcdwriter;
pcdwriter.write<pcl::PointXYZRGBA>(argv[2], cloud);
return0;
}
The text was updated successfully, but these errors were encountered:
The function
vtkPolyDataToPointCloud
allows the user to convert a mesh to a colored point cloud; but the color information is not correctly handled. The result is a black point cloud.Test code
Result is a black cloud (alpha = 0) without the
FIXME
comment.The text was updated successfully, but these errors were encountered: