[vtkusers] Conversion from VRML into VTK format

Fabian Wanner fpw05 at doc.ic.ac.uk
Wed Jan 28 15:52:16 EST 2009


Hey,

the extension of OutputFile should be '.vtk', which I store in a char*.
The vtkFile is actually not a file, but is an output stream created 
through the vtkPolyDataWriter using the OpenVTKFile() function. If you 
set the FileName, FileType and Header before you create that vtkFile 
this should work.
The Header I put in there is the default header, so the SetHeader line 
is actually unnecessary unless you change it. It works for me with the 
default.

Here is an example:

    vtkPolyDataWriter* writer = vtkPolyDataWriter::New();

    writer->SetFileName(outputFile);
    writer->SetFileTypeToASCII();
    writer->SetHeader("vtk output");
    ostream* vtkFile = writer->OpenVTKFile();

After this you can then do your calls like writer->WriteHeader(vtkFile);

Regards
Fabian



Nour Mestiri wrote:
> Thank you Fabian forr your help.
> Can you please, help me more and tell me what should i use as 
> extensions for the files "OutputFile" and "vtkFile"?
> I have this problem when i write this :
> writer->WriteHeader("C:/vtkFile.vtk");
>  
> And i don't know the type of "OutputFile" in this line:
> writer->SetFileName("C:/OutputFile");
>  
> I have to know what type of files should "OutputFile" and "vtkFile" be!!!
> Thank you sooo much
>
>
> --- En date de : *Jeu 22.1.09, Fabian Wanner /<fpw05 at doc.ic.ac.uk>/* a 
> écrit :
>
>     De: Fabian Wanner <fpw05 at doc.ic.ac.uk>
>     Objet: Re: [vtkusers] Conversion from VRML into VTK format
>     À: nourmestiri at yahoo.fr
>     Cc: "vtk" <vtkusers at vtk.org>
>     Date: Jeudi 22 Janvier 2009, 20h50
>
>     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