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

luoyx luoyx08 at gmail.com
Sun Aug 7 23:36:35 EDT 2011


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();
 

--
View this message in context: http://vtk.1045678.n5.nabble.com/how-to-export-a-ply-file-with-color-infomation-tp4676437p4676437.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list