[vtkusers] save the coordinate with the color of point

David Doria daviddoria at gmail.com
Tue Jun 12 19:10:50 EDT 2012


On Tue, Jun 12, 2012 at 7:00 PM, kaouther <boutara.kaouther at gmail.com> wrote:
> Hi all,
> how to save a 3D mesh in a file in the form [xyz RGB] for each point of the
> mesh
> my mesh in the PLY format
> thank you for your response

Your mesh is not in PLY format, right? Once you've read it in, it is
now a vtkPolyData.

I don't think there is a built in writer to write a plain text file in
that form, but you can easily do something like:

for(vtkIdType i = 0; i < polydata->GetNumberOfPoints(); ++i)
{
  double p[3];
  polydata->GetPoint(i, p);
  unsigned char color[3];
  vtkUnsignedCharArray::SafeDownCast(polydata->GetPointData()->GetArray("Color"))->GetTupleValue(i,
color); // This is the only step that might vary, based on how your
colors are attached to your mesh

  fout << p[0] << " " << p[1] << " " << p[2] << " " <<
static_cast<int>(color[0]) << " " << static_cast<int>(color[1]) << " "
<< static_cast<int>(color[2]) << std::endl;
}

David



More information about the vtkusers mailing list