DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
utlVTK.h
Go to the documentation of this file.
1 
11 #ifndef __utlVTK_h
12 #define __utlVTK_h
13 
14 #include <vtkSmartPointer.h>
15 #include <vtkPolyData.h>
16 #include <vtkPolyDataWriter.h>
17 #include <vtkXMLPolyDataWriter.h>
18 #include <vtkPLYWriter.h>
19 #include <vtkSTLWriter.h>
20 #include <vtkXMLUnstructuredGridWriter.h>
21 #include <vtkXMLImageDataWriter.h>
22 #include <vtkXMLStructuredGridWriter.h>
23 #include <vtkXMLRectilinearGridWriter.h>
24 
25 #include "utlVTKMacro.h"
26 #include "utlCore.h"
27 
28 namespace utl
29 {
30 
31 template <typename WriterType>
32 inline void
33 WriteVTK(vtkPolyData* mesh, const std::string& filename)
34 {
35  vtkSmartPointer< WriterType > writer = vtkSmartPointer< WriterType >::New();
36  writer->SetInputData(mesh);
37  writer->SetFileName(filename.c_str());
38  writer->Write();
39 }
40 
41 
42 
44 inline void
45 WriteVtkPolyData ( vtkPolyData* mesh, const std::string& filename)
46 {
47  std::string fileNoExt, ext;
48  utl::GetFileExtension(filename, ext, fileNoExt);
49  std::cout << "Writing polydata to " << filename << std::endl;
50  if (ext=="vtk")
51  WriteVTK<vtkPolyDataWriter>(mesh, filename);
52  else if (ext=="vtp")
53  WriteVTK<vtkXMLPolyDataWriter>(mesh, filename);
54  else if (ext=="ply")
55  WriteVTK<vtkPLYWriter>(mesh, filename);
56  else if (ext=="stl")
57  WriteVTK<vtkSTLWriter>(mesh, filename);
58  else if (ext=="vtu")
59  WriteVTK<vtkXMLUnstructuredGridWriter>(mesh, filename);
60  else if (ext=="vti")
61  WriteVTK<vtkXMLImageDataWriter>(mesh, filename);
62  else if (ext=="vts")
63  WriteVTK<vtkXMLStructuredGridWriter>(mesh, filename);
64  else if (ext=="vtr")
65  WriteVTK<vtkXMLRectilinearGridWriter>(mesh, filename);
66  else
67  WriteVTK<vtkPolyDataWriter>(mesh, filename);
68 }
69 
70 }
71 
72 
73 #endif
void WriteVTK(vtkPolyData *mesh, const std::string &filename)
Definition: utlVTK.h:33
Definition: utl.h:90
Created "02-18-2015.
void GetFileExtension(const std::string &fileNameAbsolute, std::string &ext, std::string &fileNoExt)
Definition: utlCore.h:559
void WriteVtkPolyData(vtkPolyData *mesh, const std::string &filename)
Definition: utlVTK.h:45