VTKFIG  0.20.20181114
Easy VTK based in situ visualization
vtkfigDataSet.cxx
Go to the documentation of this file.
1 #include <vtkRectilinearGridWriter.h>
2 #include <vtkUnstructuredGridWriter.h>
3 
4 #include "vtkfigDataSet.h"
5 #include "config.h"
6 
7 namespace vtkfig
8 {
9 
11 
12 
14  {
15  auto udata=vtkUnstructuredGrid::SafeDownCast(this->data);
16  auto rdata=vtkRectilinearGrid::SafeDownCast(this->data);
17  if (udata) return DataType::UnstructuredGrid;
18  if (rdata) return DataType::RectilinearGrid;
19  return DataType::NoType;
20  }
21 
22 
23  template<class DATA, class WRITER>
24  void DataSet::WriteVTK(vtkSmartPointer<DATA> data, const std::string fname, const std::string filetype )
25  {
26  auto writer=vtkSmartPointer<WRITER>::New();
27  if (filetype=="A")
28  writer->SetFileTypeToASCII();
29  else if (filetype=="B")
30  writer->SetFileTypeToBinary();
31  else
32  throw std::runtime_error("WriteVTK: wrong file type, choose \"A\" for ascii, \"B\" for binary\n");
33  writer->SetFileName(fname.c_str());
34  writer->SetInputData(data);
35  writer->Write();
36  }
37 
38 
39 
40  void DataSet::WriteVTK(std::string fname, const std::string filetype)
41  {
43  WriteVTK<vtkUnstructuredGrid,vtkUnstructuredGridWriter>(vtkUnstructuredGrid::SafeDownCast(data),fname, filetype);
45  WriteVTK<vtkRectilinearGrid,vtkRectilinearGridWriter>(vtkRectilinearGrid::SafeDownCast(data),fname,filetype);
46  }
47 
48 
49 }
DataType
Enum describing different possible data types.
DataSet()
Constructor.
DataType GetDataType()
Request the data type of the dataset.
vtkSmartPointer< vtkDataSet > data
void WriteVTK(const std::string fname, const std::string filetype)
Write dataset to disk in VTK format.