<div class="gmail_quote">On Sun, Aug 7, 2011 at 11:36 PM, luoyx <span dir="ltr">&lt;<a href="mailto:luoyx08@gmail.com">luoyx08@gmail.com</a>&gt;</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&#39; color data and want to export them as a ply<br>
file using the plywriter.<br>
But the exported file don&#39;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&lt;vtkUnsignedCharArray&gt; color_array =<br>
vtkSmartPointer&lt;vtkUnsignedCharArray&gt;::New();<br>
   color_array-&gt;SetName(&quot;RGB&quot;);<br>
   color_array-&gt;SetNumberOfComponents(3);<br>
   color_array-&gt;SetNumberOfTuples(cloud-&gt;size());<br>
<br>
<br>
   for(vtkIdType j =0; j!= cloud-&gt;size(); ++j)<br>
           for(vtkIdType i = 0; i!=3; ++i)<br>
         {<br>
                 switch(i)<br>
                 {<br>
                 case 0:<br>
                         color_array-&gt;SetValue(j*3+i,cloud-&gt;points[j].r);<br>
                  break;<br>
<br>
                 case 1:<br>
                         color_array-&gt;SetValue(j*3+i,cloud-&gt;points[j].g);<br>
                  break;<br>
<br>
                 case 2:<br>
                         color_array-&gt;SetValue(j*3+i,cloud-&gt;points[j].b);<br>
                  break;<br>
                 }<br>
         }<br>
<br>
    //read data from a vtk file<br>
        vtkPolyDataReader *reader=vtkPolyDataReader::New();<br>
        reader-&gt;SetFileName(&quot;mesh.vtk&quot;);<br>
        vtkDataObject *vtkdata;<br>
        vtkdata=reader-&gt;GetOutputDataObject(0);<br>
<br>
<br>
<br>
  // Convert vtk file to ply(add color info)<br>
        vtkSmartPointer&lt;vtkPLYWriter&gt; writer=vtkSmartPointer&lt;vtkPLYWriter&gt;::New();<br>
        writer-&gt;SetInput(vtkdata);<br>
        writer-&gt;SetFileTypeToASCII();<br>
        writer-&gt;SetColorModeToDefault();<br>
        writer-&gt;SetArrayName(&quot;RGB&quot;);<br>
        writer-&gt;SetFileName(&quot;mesh.ply&quot;);<br>
        writer-&gt;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>