40 #include <vtkPolyDataWriter.h>
41 #include <vtkPolyData.h>
42 #include <vtkPoints.h>
43 #include <vtkCellArray.h>
55 "Writes a VTK file.");
71 cout <<
"OutputVtk: Writing file..." << endl;
74 vtkPolyData *vtkMesh = vtkPolyData::New();
75 vtkPoints *vtkPoints = vtkPoints::New();
76 vtkCellArray *vtkPolys = vtkCellArray::New();
80 std::set<NodeSharedPtr> tmp(
81 m_mesh->m_vertexSet.begin(),
82 m_mesh->m_vertexSet.end());
84 for (it = tmp.begin(); it != tmp.end(); ++it)
87 vtkPoints->InsertPoint(n->m_id, n->m_x, n->m_y, n->m_z);
91 vector<ElementSharedPtr> &elmt =
93 for(
int i = 0; i < elmt.size(); ++i)
95 int vertexCount = elmt[i]->GetVertexCount();
96 for (
int j = 0; j < vertexCount; ++j)
98 p[j] = elmt[i]->GetVertex(j)->m_id;
100 vtkPolys->InsertNextCell(vertexCount, &p[0]);
103 vtkMesh->SetPoints(vtkPoints);
104 vtkMesh->SetPolys(vtkPolys);
107 vtkPolyDataWriter *vtkMeshWriter = vtkPolyDataWriter::New();
108 vtkMeshWriter->SetFileName(
m_config[
"outfile"].as<string>().c_str());
109 #if VTK_MAJOR_VERSION <= 5
110 vtkMeshWriter->SetInput(vtkMesh);
112 vtkMeshWriter->SetInputData(vtkMesh);
114 vtkMeshWriter->Update();