SemiDiscreteOT 1.0
Semi-Discrete Optimal Transport Library
Loading...
Searching...
No Matches
VtkHandler.h
Go to the documentation of this file.
1#ifndef VTK_HANDLER_HPP
2#define VTK_HANDLER_HPP
3
4#include <deal.II/base/function.h>
5#include <deal.II/base/point.h>
6#include <deal.II/dofs/dof_handler.h>
7#include <deal.II/lac/vector.h>
8
9#include <vtkSmartPointer.h>
10#include <vtkUnstructuredGrid.h>
11#include <vtkPointData.h>
12#include <vtkCellData.h>
13#include <vtkPointLocator.h>
14#include <vtkCellLocator.h>
15#include <vtkDoubleArray.h>
16
17#include <string>
18#include <memory>
19
20using namespace dealii;
21
32template <int dim, int spacedim = dim>
33class VTKHandler : public Function<spacedim>
34{
35public:
39 enum class DataLocation {
40 PointData,
42 };
43
51 VTKHandler(const std::string& filename,
52 const bool is_binary = false,
53 const double scaling_factor = 1.0);
54
59 void read_file();
60
68 void setup_field(const std::string& field_name,
70 const unsigned int component = 0);
71
81 virtual double value(const Point<spacedim>& p,
82 const unsigned int component = 0) const override;
83
88 vtkSmartPointer<vtkUnstructuredGrid> get_grid() const { return vtk_grid; }
89
94 vtkSmartPointer<vtkDataArray> get_field_data() const { return field_data; }
95
100 int get_num_components() const { return field_data ? field_data->GetNumberOfComponents() : 0; }
101
102private:
103 std::string filename;
106
107 vtkSmartPointer<vtkUnstructuredGrid> vtk_grid;
108 vtkSmartPointer<vtkDataArray> field_data;
109 vtkSmartPointer<vtkPointLocator> point_locator;
110 vtkSmartPointer<vtkCellLocator> cell_locator;
111
113 std::string field_name;
114 unsigned int selected_component;
115};
116
117#endif // VTK_HANDLER_HPP
A handler class for reading and interpolating data from VTK files.
Definition VtkHandler.h:34
int get_num_components() const
Returns the number of components in the selected field data.
Definition VtkHandler.h:100
double scaling_factor
Definition VtkHandler.h:105
DataLocation data_location
Definition VtkHandler.h:112
vtkSmartPointer< vtkDataArray > field_data
Definition VtkHandler.h:108
virtual double value(const Point< spacedim > &p, const unsigned int component=0) const override
Interpolates the value of the selected field at a given point.
vtkSmartPointer< vtkUnstructuredGrid > vtk_grid
Definition VtkHandler.h:107
void read_file()
Reads the VTK file and initializes the internal data structures.
Definition VtkHandler.cc:33
unsigned int selected_component
Definition VtkHandler.h:114
vtkSmartPointer< vtkUnstructuredGrid > get_grid() const
Returns the underlying VTK unstructured grid.
Definition VtkHandler.h:88
void setup_field(const std::string &field_name, const DataLocation data_location=DataLocation::PointData, const unsigned int component=0)
Sets up the field to be used for interpolation.
Definition VtkHandler.cc:94
vtkSmartPointer< vtkPointLocator > point_locator
Definition VtkHandler.h:109
std::string field_name
Definition VtkHandler.h:113
DataLocation
Enum to specify whether the data is associated with points or cells.
Definition VtkHandler.h:39
@ CellData
Data is associated with the cells of the grid.
@ PointData
Data is associated with the vertices of the grid.
vtkSmartPointer< vtkDataArray > get_field_data() const
Returns the data array for the selected field.
Definition VtkHandler.h:94
vtkSmartPointer< vtkCellLocator > cell_locator
Definition VtkHandler.h:110
bool is_binary
Definition VtkHandler.h:104
std::string filename
Definition VtkHandler.h:103