[vtkusers] file format conversion (XML <-> simple legacy format)

Martin Baumann mailsgetlost at web.de
Sun May 21 10:48:01 EDT 2006


Hi,

I am writing a converter that converts vtk simple legacy file format to 
xml and back.

1) Convert legacy file to XML file.
2) Convert new XML file back to legacy file.

Thereafter the legacy files (file_org.vtk and file_new.vtk) should 
contain same data.
file_org.vtk contained Data1, Data2 and Data3
file_new.vtk only contains Data1. Data2 and Data3 no more exist.

My code:

  // read Legacy-Format
  vtkUnstructuredGridReader* _grid_reader = 
vtkUnstructuredGridReader::New();
  _grid_reader->SetFileName("file_org.vtk");
  _grid_reader->Update();


  // write XML file
  vtkXMLUnstructuredGridWriter* _xml_grid_writer  = 
vtkXMLUnstructuredGridWriter::New();
  _xml_grid_writer->SetFileName("file.xml");
  _xml_grid_writer->SetInput(_grid_reader->GetOutput());
  _xml_grid_writer->Write();


  // read XML file
  vtkXMLUnstructuredGridReader* _xml_grid_reader  = 
vtkXMLUnstructuredGridReader::New();
  _xml_grid_reader->SetFileName("file.xml");
  _xml_grid_reader->Update();


  // write Legacy-Format variables
  vtkUnstructuredGridWriter* _grid_writer  = 
vtkUnstructuredGridWriter::New();
  _grid_writer->SetFileName("file_new.vtk");
  _grid_writer->SetInput(_xml_grid_reader->GetOutput());
  _grid_writer->Write();


Can anyone give me a hint what to do?

How can I see how many scalars and vectors are contained in the xml file?
For the simple legacy file it do the following:

  cout << "From Simple-Legacy file:" << endl;
  cout << "#Points : " << _grid_reader->GetOutput()->GetNumberOfPoints() 
<< endl;
  cout << "#Scalars: " << _grid_reader->GetNumberOfScalarsInFile() << endl;
  cout << "#Vectors: " << _grid_reader->GetNumberOfVectorsInFile() << endl;

vtkXMLUnstructuredGridReader does not have such functions expect the 
GetOutput()->GetNumberOfPoints() .



Thanks, M.B.



More information about the vtkusers mailing list