[vtkusers] Convert VRML to VTK ASCII format

David E DeMarle dave.demarle at kitware.com
Tue Mar 8 16:08:46 EST 2016


This also looks fishy.

> ostream *vtkFile = writer->OpenVTKFile();
> writer->SetHeader("vtkFile");
> writer->WriteHeader(vtkFile);
> *vtkFile << "DATASET POLYDATA\n";
> writer->WritePoints(vtkFile, polyData->GetPoints());
> writer->WriteCells(vtkFile, polyData->GetPolys(), "POLYGONS");
> writer->CloseVTKFile(vtkFile);


You shouldn't have to do the low level bits, instead just let the class to
the work like so:
writer->SetInputData(polyData);
writer->Write();

hah
David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909

On Tue, Mar 8, 2016 at 3:20 PM, Cory Quammen <cory.quammen at kitware.com>
wrote:

> You can't do this:
>
> strcat(vrmlFileName, ".vtk");
>
> You can do this:
>
> vrmlFileName.append(".vtk");
>
> HTH,
> Cory
>
> On Tue, Mar 8, 2016 at 12:41 PM, Jose Soto <sotoglzz at gmail.com> wrote:
> >
> > Dears vtk users:
> >
> > I'm trying to convert a VRML file to a vtk ASCII format using this code
> from
> > this  vtk topic:
> >
> http://vtk.1045678.n5.nabble.com/Conversion-from-VRML-into-VTK-format-td1243521.html#a1243526
> > , here's the code:
> >
> > #include <vtkVRMLImporter.h>
> > #include <vtkDataSet.h>
> > #include <vtkActorCollection.h>
> > #include <vtkPolyData.h>
> > #include <vtkPolyDataWriter.h>
> > #include <vtkRenderer.h>
> > #include <vtkMapper.h>
> >
> > int main (int argc, char *argv[]) {
> >
> > std::string Fichier = argv[1];
> > std::string vrmlFileName = argv[2];
> >
> > vtkVRMLImporter *imp = vtkVRMLImporter::New();
> > imp->SetFileName(Fichier.c_str());
> > imp->Read();
> > imp->Update();
> > vtkDataSet *pDataset;
> > vtkActorCollection *actors = imp->GetRenderer()->GetActors();
> > actors->InitTraversal();
> > pDataset = actors->GetNextActor()->GetMapper()->GetInput();
> >
> > vtkPolyData *polyData = vtkPolyData::SafeDownCast(pDataset);
> > polyData->Update();
> >
> > vtkPolyDataWriter *writer = vtkPolyDataWriter::New();
> > strcat(vrmlFileName, ".vtk");
> > writer->SetFileName(vrmlFileName);
> > writer->SetFileTypeToASCII();
> >
> > ostream *vtkFile = writer->OpenVTKFile();
> > writer->SetHeader("vtkFile");
> > writer->WriteHeader(vtkFile);
> > *vtkFile << "DATASET POLYDATA\n";
> > writer->WritePoints(vtkFile, polyData->GetPoints());
> > writer->WriteCells(vtkFile, polyData->GetPolys(), "POLYGONS");
> > writer->CloseVTKFile(vtkFile);
> >
> > return EXIT_SUCCESS;
> >
> > }
> >
> > When I'm trying to compile it I get the following errror
> >
> > [100%] Building CXX object CMakeFiles/VRML.dir/VRML.cxx.o
> > /home/trinidad/VRMLConv/VRML.cxx: In function ‘int main(int, const
> char**)’:
> > /home/trinidad/VRMLConv/VRML.cxx:28:28: error: cannot convert
> ‘std::string
> > {aka std::basic_string<char>}’ to ‘char*’ for argument ‘1’ to ‘char*
> > strcat(char*, const char*)’
> >  strcat(vrmlFileName, ".vtk");
> >
> > Can someone give me a little help please??
> > Thanks, in advance
> > José Soto
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the VTK FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> >
> > Search the list archives at: http://markmail.org/search/?q=vtkusers
> >
> > Follow this link to subscribe/unsubscribe:
> > http://public.kitware.com/mailman/listinfo/vtkusers
> >
>
>
>
> --
> Cory Quammen
> R&D Engineer
> Kitware, Inc.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160308/51ce305b/attachment.html>


More information about the vtkusers mailing list