[vtkusers] Convert VRML to VTK ASCII format

Jose Soto sotoglzz at gmail.com
Tue Mar 8 13:41:26 EST 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160308/360f8a66/attachment.html>


More information about the vtkusers mailing list