[vtkusers] vtkXMLPolyDataReader/Writer problem

madz madaramh at gmail.com
Thu Nov 7 04:19:33 EST 2013


Hi,
I'm trying to write a polydata file which looks like the following
<http://vtk.1045678.n5.nabble.com/file/n5724345/write_file.png> ;
The code I'm using is;

std::string filename2 = "outputBPoly.vtp";
// Write file
vtkSmartPointer<vtkXMLPolyDataWriter> writer =  
    vtkSmartPointer<vtkXMLPolyDataWriter>::New();
	writer2->SetFileName(filename2.c_str());
#if VTK_MAJOR_VERSION <= 5
	writer->SetInput(polydata);
#else
	writer->SetInputData(polydata);
#endif
	writer->SetDataModeToAscii();
	writer->Write();


And I'm reading the file from a different application.
The code is;

  // Read all the data from the file
  vtkSmartPointer<vtkXMLPolyDataReader> reader =
    vtkSmartPointer<vtkXMLPolyDataReader>::New();
  reader->SetFileName(filename.c_str());
  reader->Update();
 
  // Visualize
  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(reader->GetOutputPort());
 
  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
 
  vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);
 
  renderer->AddActor(actor);
  renderer->SetBackground(1, 1, 1); 
 
  renderWindow->Render();
  renderWindowInteractor->Start();

 And the output looks like the following image.
<http://vtk.1045678.n5.nabble.com/file/n5724345/read.png> 
My question is, what happened to the different colours in the original
polydata. Why aren't they appearing in the new polydata. How do I remedy
this?

Thank you.





--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkXMLPolyDataReader-Writer-problem-tp5724345.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list