[vtkusers] Conversion from VRML into VTK format

Amy Squillacote ahs at cfdrc.com
Thu Jan 29 09:41:08 EST 2009


Hi Nour,

Perhaps I'm missing something, but why not just call Write() on the 
vtkPolyDataWriter() after the line "writer->SetFileTypeToASCII();"? What 
happens if you do that (call writer->Write();) instead of your last 
section of code (i.e., from "ostream *vtkFile = writer->OpenVTKFile();" 
to the end of the code you posted?

- Amy

Nour Mestiri wrote:
> Hey Fabian,
> Thank you one more time for your helpful answer.
> I did what you told me, but i always have problems. I post you my new 
> code and please try to tell me what is wrong on it.
> Can you also telle me how to use the "SafeDownCast" method for the 
> "GeometryFilter"?
>  
> vtkVRMLImporter *imp = vtkVRMLImporter::New();
> imp->SetFileName(Fichier);
> 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();
>  
> vtkPolyDataWriter *writer = vtkPolyDataWriter::New();
> strcat(vrmlFileName,".vtk");
> writer->SetFileName(vrmlFileName);
> writer->SetFileTypeToASCII();
>  
> ostream *vtkFile = writer->OpenVTKFile();
> *vtkFile << "DATASET POLYDATA\n";
> writer->SetHeader("vtkFile");
> writer->WriteCells(vtkFile, polyData->GetPolys(), "POLYGONS");
> writer->CloseVTKFile(vtkFile);
>  
> 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
>     >   
>
>               
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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
>   

-- 
Amy Squillacote                    Phone: (256) 726-4839
Sr. Computer Scientist             Fax: (256) 726-4806
CFD Research Corporation           Web: http://www.cfdrc.com
215 Wynn Drive, Suite 501
Huntsville, AL  35805





More information about the vtkusers mailing list