View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

celltree.h
Go to the documentation of this file.
1#ifndef CELLTREE_H
2#define CELLTREE_H
3
4#include "export.h"
5#include "scalar.h"
6#include "index.h"
7#include "shm.h"
8#include "object.h"
9#include "vector.h"
10#include "geometry.h"
11#include "shmvector.h"
12
13namespace vistle {
14
15// a bounding volume hierarchy, cf. C. Garth and K. I. Joy:
16// “Fast, memory-efficient cell location in unstructured grids for visualization”,
17// IEEE Transactions on Visualization and Computer Graphics, vol. 16, no. 6, pp. 1541–1550, 2010.
18
19template<size_t IndexSize, int NumDimensions>
21
22typedef CelltreeNode<sizeof(Index), 1> CelltreeNode1;
23typedef CelltreeNode<sizeof(Index), 2> CelltreeNode2;
24typedef CelltreeNode<sizeof(Index), 3> CelltreeNode3;
25
29
30template<typename Scalar, typename Index, int NumDimensions = 3>
33
34public:
35 typedef Object Base;
36
38 typedef CelltreeNode<sizeof(Index), NumDimensions> Node;
39
41 public:
42 enum Order {
43 None = 0, //< none of the subnodes have to be visited
44 RightFirst = 1, //< right subnode has to be visited, should be visited first
45 RightSecond = 2, //< right subnode has to be visited, should be visited last
46 Left = 4, //< left subnode has to be visited
47 Right = RightFirst, //< right subnode has to be visited
48 LeftRight = Left | RightSecond, //< both subnodes have to be visited, preferably left first
49 RightLeft = Left | RightFirst, //< both subnodes have to be visited, preferably right first
50 };
51
53 bool checkBounds(const Scalar *min, const Scalar *max)
54 {
55 (void)min;
56 (void)max;
57 return true; // continue traversal
58 }
59
61 Order operator()(const Node &node)
62 {
63 (void)node;
64 return LeftRight;
65 }
66 };
67
70 public:
71 bool operator()(Index elem)
72 {
73 return true; // continue traversal
74 }
75 };
76
79 public:
80 bool operator()(Index elem, Vector *min, Vector *max)
81 {
82 return false; // couldn't compute bounds
83 }
84 };
85
86 Celltree(const Index numCells, const Meta &meta = Meta());
87
88 void init(const Vector *min, const Vector *max, const Vector &gmin, const Vector &gmax);
89 void refine(const Vector *min, const Vector *max, Index nodeIdx, const Vector &gmin, const Vector &gmax);
90 template<class BoundsFunctor>
91 bool validateTree(BoundsFunctor &func) const;
92
93 Scalar *min() { return &(d()->m_bounds)[0]; }
94 const Scalar *min() const { return &(d()->m_bounds)[0]; }
95 Scalar *max() { return &(d()->m_bounds)[NumDimensions]; }
96 const Scalar *max() const { return &(d()->m_bounds)[NumDimensions]; }
97 typename shm<Node>::array &nodes() { return *d()->m_nodes; }
98 const typename shm<Node>::array &nodes() const { return *d()->m_nodes; }
99 typename shm<Index>::array &cells() { return *d()->m_cells; }
100 const typename shm<Index>::array &cells() const { return *d()->m_cells; }
101
102 template<class InnerNodeFunctor, class ElementFunctor>
103 void traverse(InnerNodeFunctor &visitNode, ElementFunctor &visitElement) const
104 {
105 if (!visitNode.checkBounds(min(), max()))
106 return;
107 traverseNode(0, nodes().data(), cells().data(), visitNode, visitElement);
108 }
109
110private:
111 template<class BoundsFunctor>
112 bool validateNode(BoundsFunctor &func, Index nodenum, const Vector &min, const Vector &max) const;
113 template<class InnerNodeFunctor, class ElementFunctor>
114 bool traverseNode(Index curNode, const Node *nodes, const Index *cells, InnerNodeFunctor &visitNode,
115 ElementFunctor &visitElement) const
116 {
117 const Node &node = nodes[curNode];
118 if (node.isLeaf()) {
119 for (Index i = node.start; i < node.start + node.size; ++i) {
120 const Index cell = cells[i];
121 if (!visitElement(cell))
122 return false;
123 }
124 return true;
125 }
126
127 const typename VisitFunctor::Order order = visitNode(node);
128 assert(!((order & VisitFunctor::RightFirst) && (order & VisitFunctor::RightSecond)));
129 bool continueTraversal = true;
130 if (continueTraversal && (order & VisitFunctor::RightFirst)) {
131 continueTraversal = traverseNode(node.child + 1, nodes, cells, visitNode, visitElement);
132 }
133 if (continueTraversal && (order & VisitFunctor::Left)) {
134 continueTraversal = traverseNode(node.child, nodes, cells, visitNode, visitElement);
135 }
136 if (continueTraversal && (order & VisitFunctor::RightSecond)) {
137 continueTraversal = traverseNode(node.child + 1, nodes, cells, visitNode, visitElement);
138 }
139
140 return continueTraversal;
141 }
142
143 template<class Functor>
144 bool traverseNode(Index curNode, Functor &func) const;
145
146 V_DATA_BEGIN(Celltree);
147 Scalar m_bounds[NumDimensions * 2];
148 ShmVector<Index> m_cells;
149 ShmVector<Node> m_nodes;
150
151 static Data *create(const std::string &name = "", const Index numCells = 0, const Meta &m = Meta());
152 Data(const std::string &name = "", const Index numCells = 0, const Meta &m = Meta());
153 V_DATA_END(Celltree);
154};
155
157extern template class V_COREEXPORT Celltree<Scalar, Index, 1>;
158
160extern template class V_COREEXPORT Celltree<Scalar, Index, 2>;
161
163extern template class V_COREEXPORT Celltree<Scalar, Index, 3>;
164
165} // namespace vistle
166
167#include "celltreenode.h"
168
169namespace vistle {
170
171template<int Dim>
173public:
175 virtual bool hasCelltree() const = 0;
176 virtual typename Celltree::const_ptr getCelltree() const = 0;
177 virtual bool validateCelltree() const = 0;
178};
179
180} // namespace vistle
181#endif
182
183// include only where actually required
184//#include "celltree_impl.h"
Definition: celltree.h:172
virtual Celltree::const_ptr getCelltree() const =0
virtual bool validateCelltree() const =0
vistle::Celltree< Scalar, Index, Dim > Celltree
Definition: celltree.h:174
virtual bool hasCelltree() const =0
compute bounding box of a cell
Definition: celltree.h:78
bool operator()(Index elem, Vector *min, Vector *max)
Definition: celltree.h:80
return whether further cells have to be visited
Definition: celltree.h:69
bool operator()(Index elem)
Definition: celltree.h:71
Definition: celltree.h:40
Order
Definition: celltree.h:42
Order operator()(const Node &node)
return whether and in which order to visit children of a node
Definition: celltree.h:61
bool checkBounds(const Scalar *min, const Scalar *max)
check whether the celltree is within bounds min and max, otherwise no traversal
Definition: celltree.h:53
Definition: celltree.h:31
const shm< Index >::array & cells() const
Definition: celltree.h:100
shm< Index >::array & cells()
Definition: celltree.h:99
const shm< Node >::array & nodes() const
Definition: celltree.h:98
Scalar * min()
Definition: celltree.h:93
VistleScalarVector< NumDimensions >::type Vector
Definition: celltree.h:37
const Scalar * min() const
Definition: celltree.h:94
const Scalar * max() const
Definition: celltree.h:96
shm< Node >::array & nodes()
Definition: celltree.h:97
Object Base
Definition: celltree.h:35
Scalar * max()
Definition: celltree.h:95
void traverse(InnerNodeFunctor &visitNode, ElementFunctor &visitElement) const
Definition: celltree.h:103
Definition: geometry.h:23
Definition: objectmeta.h:16
Definition: object.h:58
std::shared_ptr< const Object > const_ptr
Definition: object.h:68
Definition: shm_array.h:19
#define V_COREEXPORT
Definition: export.h:9
static T min(T a, T b)
Definition: messages.cpp:28
Definition: allobjects.cpp:30
Celltree< Scalar, Index, 2 > Celltree2
Definition: celltree.h:159
Vector3 Vector
Definition: vector.h:36
float Scalar
Definition: scalar.h:14
Celltree< Scalar, Index, 3 > Celltree3
Definition: celltree.h:162
Eigen::Matrix< Scalar, d, 1 > type
Definition: vector.h:28
Celltree< Scalar, Index, 1 > Celltree1
Definition: celltree.h:156
uint32_t Index
Definition: index.h:13
Definition: celltree.h:20
#define V_DATA_BEGIN(ObjType)
Definition: object.h:474
#define V_DATA_END(ObjType)
Definition: object.h:481
#define V_OBJECT(ObjType)
declare a new Object type
Definition: object.h:381
#define V_DECLARE_SHMREF(T)
Definition: shm_reference.h:206