[vtkusers] Conversion from VRML into VTK format

Fabian Wanner fpw05 at doc.ic.ac.uk
Thu Jan 22 15:50:16 EST 2009


Hello Nour,

the main part of your code is exactly the same as mine, but there are a 
few differences.

1. I had problems with the vtkGeometryFilter, so instead of doing that I 
used the static SafeDownCast method of the vtkPolyData and passed in the 
vtkDataSet.

2. You are writing the PointData, which is only the texture information. 
If you want to write the actual coordinates, you should do something 
like this:
writer->WritePoints(vtkFile, polyData1->GetPoints());

For writing the polygon or line information use something similar to this:
writer->WriteCells(vtkFile, polyData1->GetPolys(), "POLYGONS");
The label has to be the one mentioned on this website 
http://www.cacr.caltech.edu/~slombey/asci/vtk/vtk_formats.simple.html 
<http://www.cacr.caltech.edu/%7Eslombey/asci/vtk/vtk_formats.simple.html> 
under DataSet Format -> Polygonal Data

3. Unfortunately the line "DATASET POLYDATA" is not written by the 
vtkPolyDataWriter. After writing the header you should add the line 
(this took me a long time to find out):
*vtkFile << "DATASET POLYDATA\n";
This is necessary for the vtkReader to understand what type of data can 
be found in the file.

I didn't test anything I mentioned here, but this is how it works for 
me, so I hope it does for you as well. Please let me know if there are 
any problems.
Fabian


Nour Mestiri wrote:
> Hi all vtk users,
> I have a VRML file and i want  to convert it into VTK files. I found a 
> code but i have some problems with it :
>  
> vtkVRMLImporter *imp1 = vtkVRMLImporter::New();
> imp1->SetFileName("C:/vrmlFile");
> imp1->Read();
> imp1->Update();
>  
> vtkDataSet *pDataset1;
> vtkActorCollection *actors1 = imp1->GetRenderer()->GetActors();
> actors1->InitTraversal();
> pDataset1 = actors1->GetNextActor()->GetMapper()->GetInput();
>    
> vtkGeometryFilter *geometryFilter1 = vtkGeometryFilter::New();
> geometryFilter1->SetInput(pDataset1);
>    
> vtkPolyData *polyData1 = vtkPolyData::New();
> polyData1 = geometryFilter1->GetOutput();
> polyData1->Update();
>  
> vtkDataSetWriter *writer1 = vtkDataSetWriter::New();
> writer1->SetInput(polyData1);
> writer1->SetFileName(OutputFile);
> writer1->SetFileTypeToASCII();
>    
> ostream *vtkFile1 = writer1->OpenVTKFile();
> writer1->WriteHeader(vtkFile);
> writer1->WritePointData(vtkFile, pDataset1);
> writer1->CloseVTKFile(vtkFile);
>  
> Can you tell me if that code makes the conversion from VRML to VTK format?
> If yes, can you specify me the extensions to add for "OutputFile" and 
> "vtkFile"?
>  
> Thank you sooooo much for your help.
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>   




More information about the vtkusers mailing list