[vtkusers] how to export a ply file with color infomation

David Doria daviddoria at gmail.com
Mon Aug 8 08:49:11 EDT 2011


On Sun, Aug 7, 2011 at 11:36 PM, luoyx <luoyx08 at gmail.com> wrote:

> i have a vtk file and the points' color data and want to export them as a
> ply
> file using the plywriter.
> But the exported file don't contain the color infomation.Thanks for your
> help!
>
> my code is shown below:
>
>
>   // initial the color array (cloud is a pointcloud with XYZRGB data)
>   vtkSmartPointer<vtkUnsignedCharArray> color_array =
> vtkSmartPointer<vtkUnsignedCharArray>::New();
>   color_array->SetName("RGB");
>   color_array->SetNumberOfComponents(3);
>   color_array->SetNumberOfTuples(cloud->size());
>
>
>   for(vtkIdType j =0; j!= cloud->size(); ++j)
>           for(vtkIdType i = 0; i!=3; ++i)
>         {
>                 switch(i)
>                 {
>                 case 0:
>                         color_array->SetValue(j*3+i,cloud->points[j].r);
>                  break;
>
>                 case 1:
>                         color_array->SetValue(j*3+i,cloud->points[j].g);
>                  break;
>
>                 case 2:
>                         color_array->SetValue(j*3+i,cloud->points[j].b);
>                  break;
>                 }
>         }
>
>    //read data from a vtk file
>        vtkPolyDataReader *reader=vtkPolyDataReader::New();
>        reader->SetFileName("mesh.vtk");
>        vtkDataObject *vtkdata;
>        vtkdata=reader->GetOutputDataObject(0);
>
>
>
>  // Convert vtk file to ply(add color info)
>        vtkSmartPointer<vtkPLYWriter>
> writer=vtkSmartPointer<vtkPLYWriter>::New();
>        writer->SetInput(vtkdata);
>        writer->SetFileTypeToASCII();
>        writer->SetColorModeToDefault();
>        writer->SetArrayName("RGB");
>        writer->SetFileName("mesh.ply");
>        writer->Write();
>

Can you post a compilable example and the output file that is produced? I
would hard code something like this :
http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/TriangleColoredPoints as
the input.

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110808/72300d7a/attachment.htm>


More information about the vtkusers mailing list