Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vtkPolyDataToPointCloud does not color cloud #1040

Open
VictorLamoine opened this issue Dec 11, 2014 · 1 comment
Open

vtkPolyDataToPointCloud does not color cloud #1040

VictorLamoine opened this issue Dec 11, 2014 · 1 comment

Comments

@VictorLamoine
Copy link
Contributor

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;
}
@stale
Copy link

stale bot commented May 19, 2020

Marking this as stale due to 30 days of inactivity. It will be closed in 7 days if no further activity occurs.

@stale stale bot added the status: stale label May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant