[vtkusers] VRML file to VTK file

Fabian Wanner fpw05 at doc.ic.ac.uk
Sat Jan 17 10:59:31 EST 2009


Hello,

I am new to VTK and experience the following problem. I am reading a 
VRML file and want to convert that into a VTK file, that can be opened 
by Paraview. Currently I get a VTK file, but unfortunately it cannot be 
opened by Paraview, as it does not seem to know what type of VTK file it 
is.

Here is my code, where the beginning is very similar to that in 
http://public.kitware.com/pipermail/vtkusers/2004-April/073172.html I 
also followed the suggestion with the Geometry Filter, but could not get 
it to work.

   vtkVRMLImporter* imp = vtkVRMLImporter::New();
   imp->SetFileName(sourceFileName);
   imp->Read();
   imp->Update();
     vtkDataSet *pDataset;
     vtkActorCollection *actors = imp->GetRenderer()->GetActors();
   actors->InitTraversal();
   pDataset = actors->GetNextActor()->GetMapper()->GetInput();
     vtkGeometryFilter* geometryFilter = vtkGeometryFilter::New();
   geometryFilter->SetInput(pDataset);
     vtkPolyData* polyData = vtkPolyData::New();
   polyData = geometryFilter->GetOutput();
   polyData->Update();

   // Here I tried the DataSetWriter and the PolyDataWriter, but I got 
the same results.
   vtkDataSetWriter* writer = vtkDataSetWriter::New();
   //vtkPolyDataWriter* writer = vtkPolyDataWriter::New();

   writer->SetInput(polyData);
   writer->SetFileName(outputFileName);
   writer->SetFileTypeToASCII();
     ostream* vtkFile = writer->OpenVTKFile();
   writer->WriteHeader(vtkFile);
   writer->WritePointData(vtkFile, pDataset);
   writer->CloseVTKFile(vtkFile);

Some information about the VRML file: It uses VRML 2.0 and contains the 
coordinates, texture coordinates, texture coordinate indeces and 
coordinate indeces, as well as some general information about the 
appearance. The output VTK file contains the numbers 1 to the number of 
vertices and a lot of numbers between 0 and 1. It seems like some values 
joining the vertices to faces are missing.

Any help would be greatly appreciated.
Thanks in advance
Fabian




More information about the vtkusers mailing list