View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

grid.h
Go to the documentation of this file.
1#ifndef VISTLE_GRID_H
2#define VISTLE_GRID_H
3
4#include "object.h"
5#include "vector.h"
6#include "database.h"
7#include "geometry.h"
8#include "export.h"
9
10//#define INTERPOL_DEBUG
11
12namespace vistle {
13
15public:
17 NoFlags = 0,
18 AcceptGhost = 1,
19 ForceCelltree = 2,
20 NoCelltree = 4,
21 };
22
23 virtual bool isGhostCell(Index elem) const = 0;
24 virtual Index findCell(const Vector &point, Index hint = InvalidIndex, int flags = NoFlags) const = 0;
25 virtual bool inside(Index elem, const Vector &point) const = 0;
26 virtual std::pair<Vector, Vector> cellBounds(Index elem) const = 0;
27 virtual Vector cellCenter(Index elem) const = 0; //< a point inside the convex hull of the cell
28 virtual Scalar cellDiameter(Index elem) const = 0; //< approximate diameter of cell
29 virtual Scalar exitDistance(Index elem, const Vector &point, const Vector &dir) const = 0;
30 virtual std::vector<Index> getNeighborElements(Index elem)
31 const = 0;
32
34 std::vector<Scalar> weights;
35 std::vector<Index> indices;
36
37 public:
39 Interpolator(std::vector<Scalar> &weights, std::vector<Index> &indices)
40 : weights(std::move(weights)), indices(std::move(indices))
41 {
42#ifndef NDEBUG
43 check();
44#endif
45 }
46
47 Scalar operator()(const Scalar *field) const
48 {
49 Scalar ret(0);
50 for (size_t i = 0; i < weights.size(); ++i)
51 ret += field[indices[i]] * weights[i];
52 return ret;
53 }
54
55 Vector3 operator()(const Scalar *f0, const Scalar *f1, const Scalar *f2) const
56 {
57 Vector3 ret(0, 0, 0);
58 for (size_t i = 0; i < weights.size(); ++i) {
59 const Index ind(indices[i]);
60 const Scalar w(weights[i]);
61 ret += Vector3(f0[ind], f1[ind], f2[ind]) * w;
62 }
63 return ret;
64 }
65
66 bool check() const;
67 };
68
69 DEFINE_ENUM_WITH_STRING_CONVERSIONS(InterpolationMode, (First) // value of first vertex
70 (Mean) // mean value of all vertices
71 (Nearest) // value of nearest vertex
72 (Linear) // barycentric/multilinear interpolation
73 );
74
75 virtual Interpolator getInterpolator(Index elem, const Vector &point, DataBase::Mapping mapping = DataBase::Vertex,
76 InterpolationMode mode = Linear) const = 0;
77 Interpolator getInterpolator(const Vector &point, DataBase::Mapping mapping = DataBase::Vertex,
78 InterpolationMode mode = Linear) const
79 {
80 const Index elem = findCell(point);
81 if (elem == InvalidIndex) {
82 return Interpolator();
83 }
84 return getInterpolator(elem, point, mapping, mode);
85 }
86};
87
88} // namespace vistle
89#endif
Definition: geometry.h:23
return at least those elements sharing faces with elem, but might also contain those just sharing ver...
Definition: grid.h:33
Scalar operator()(const Scalar *field) const
Definition: grid.h:47
Vector3 operator()(const Scalar *f0, const Scalar *f1, const Scalar *f2) const
Definition: grid.h:55
Interpolator(std::vector< Scalar > &weights, std::vector< Index > &indices)
Definition: grid.h:39
Interpolator()
Definition: grid.h:38
Definition: grid.h:14
Interpolator getInterpolator(const Vector &point, DataBase::Mapping mapping=DataBase::Vertex, InterpolationMode mode=Linear) const
Definition: grid.h:77
virtual Index findCell(const Vector &point, Index hint=InvalidIndex, int flags=NoFlags) const =0
virtual Scalar exitDistance(Index elem, const Vector &point, const Vector &dir) const =0
virtual bool isGhostCell(Index elem) const =0
FindCellFlags
Definition: grid.h:16
virtual bool inside(Index elem, const Vector &point) const =0
virtual Vector cellCenter(Index elem) const =0
DEFINE_ENUM_WITH_STRING_CONVERSIONS(InterpolationMode,(First)(Mean)(Nearest)(Linear))
virtual Interpolator getInterpolator(Index elem, const Vector &point, DataBase::Mapping mapping=DataBase::Vertex, InterpolationMode mode=Linear) const =0
virtual std::pair< Vector, Vector > cellBounds(Index elem) const =0
virtual std::vector< Index > getNeighborElements(Index elem) const =0
virtual Scalar cellDiameter(Index elem) const =0
#define V_COREEXPORT
Definition: export.h:9
Definition: allobjects.cpp:30
Eigen::Matrix< Scalar, 3, 1 > Vector3
Definition: vector.h:33
Vector3 Vector
Definition: vector.h:36
const Index InvalidIndex
Definition: index.h:17
float Scalar
Definition: scalar.h:14
uint32_t Index
Definition: index.h:13