PointCloudLibrary / PointCloudLibrary/pcl
vtkPolyDataToPointCloud does not color cloud
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 4.7k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 6
Description
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;
int
main (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::Ptr cloud (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 ();
return 0;
}
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>
int
main (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);
return 0;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the vtkPolyDataToPointCloud entry point and run the provided C++ reproducer using the mesh-to-VTK conversion and PCLVisualizer checks. Trace how color and alpha are transferred into the PointXYZRGBA cloud; done means the converted cloud retains its source colors and displays correctly without the FIXME alpha workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100