<div class="gmail_quote">On Sun, Aug 7, 2011 at 11:36 PM, luoyx <span dir="ltr"><<a href="mailto:luoyx08@gmail.com">luoyx08@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
i have a vtk file and the points' color data and want to export them as a ply<br>
file using the plywriter.<br>
But the exported file don't contain the color infomation.Thanks for your<br>
help!<br>
<br>
my code is shown below:<br>
<br>
<br>
// initial the color array (cloud is a pointcloud with XYZRGB data)<br>
vtkSmartPointer<vtkUnsignedCharArray> color_array =<br>
vtkSmartPointer<vtkUnsignedCharArray>::New();<br>
color_array->SetName("RGB");<br>
color_array->SetNumberOfComponents(3);<br>
color_array->SetNumberOfTuples(cloud->size());<br>
<br>
<br>
for(vtkIdType j =0; j!= cloud->size(); ++j)<br>
for(vtkIdType i = 0; i!=3; ++i)<br>
{<br>
switch(i)<br>
{<br>
case 0:<br>
color_array->SetValue(j*3+i,cloud->points[j].r);<br>
break;<br>
<br>
case 1:<br>
color_array->SetValue(j*3+i,cloud->points[j].g);<br>
break;<br>
<br>
case 2:<br>
color_array->SetValue(j*3+i,cloud->points[j].b);<br>
break;<br>
}<br>
}<br>
<br>
//read data from a vtk file<br>
vtkPolyDataReader *reader=vtkPolyDataReader::New();<br>
reader->SetFileName("mesh.vtk");<br>
vtkDataObject *vtkdata;<br>
vtkdata=reader->GetOutputDataObject(0);<br>
<br>
<br>
<br>
// Convert vtk file to ply(add color info)<br>
vtkSmartPointer<vtkPLYWriter> writer=vtkSmartPointer<vtkPLYWriter>::New();<br>
writer->SetInput(vtkdata);<br>
writer->SetFileTypeToASCII();<br>
writer->SetColorModeToDefault();<br>
writer->SetArrayName("RGB");<br>
writer->SetFileName("mesh.ply");<br>
writer->Write();<br></blockquote><div><br></div>Can you post a compilable example and the output file that is produced? I would hard code something like this : <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/TriangleColoredPoints">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/TriangleColoredPoints</a> as the input.<br clear="all">
<br><div>David </div></div>