BVH.hpp
Go to the documentation of this file.
1 
28 /*
29  * BVH.hpp
30  *
31  * @date 21.01.2018
32  * @author Johan M. von Behren <johan@vonbehren.eu>
33  */
34 
35 #pragma once
36 
37 #include <vector>
38 #include <memory>
39 
41 #include "lvr2/geometry/Normal.hpp"
42 
43 using std::unique_ptr;
44 using std::vector;
45 using std::pair;
46 
47 namespace lvr2
48 {
49 
60 template<typename BaseVecT>
61 class BVHTree
62 {
63 public:
64 
71  BVHTree(const vector<float>& vertices, const vector<uint32_t>& faces);
72 
76  BVHTree(
77  const floatArr vertices, size_t n_vertices,
78  const indexArray faces, size_t n_faces
79  );
80 
84  BVHTree(const MeshBufferPtr mesh);
85 
89  const vector<uint32_t>& getTriIndexList() const;
90 
94  const vector<float>& getLimits() const;
95 
106  const vector<uint32_t>& getIndexesOrTrilists() const;
107 
122  const vector<float>& getTrianglesIntersectionData() const;
123 
124 private:
125 
126  // Internal triangle representation
127  struct Triangle {
128 
129  Triangle();
130 
131  // indices in vertex array
132  // todo: not used?
133  uint32_t idx1;
134  uint32_t idx2;
135  uint32_t idx3;
136 
137  BaseVecT center;
139 
140  // intersection pre-computed cache
141  float d, d1, d2, d3;
143 
144  // todo: not used?
146  };
147 
148  // Internal AABB representation
149  struct AABB {
151 
152  // Triangles corresponding to this AABB
153  vector<size_t> triangles;
154  };
155 
156  // Abstract tree node
157  struct BVHNode {
159  virtual bool isLeaf() = 0;
160  };
161  using BVHNodePtr = unique_ptr<BVHNode>;
162 
163  // Inner tree node
164  struct BVHInner: BVHNode {
165 
166  // Left sub tree
168 
169  // Right sub tree
171  virtual bool isLeaf() { return false; }
172  };
173  using BVHInnerPtr = unique_ptr<BVHInner>;
174 
175  // Leaf tree node
176  struct BVHLeaf: BVHNode {
177 
178  // Triangles corresponding to this leaf node
179  vector<size_t> triangles;
180  virtual bool isLeaf() { return true; }
181  };
182  using BVHLeafPtr = unique_ptr<BVHLeaf>;
183 
184  // working variables for tree construction
186  vector<Triangle> m_triangles;
187 
188  // cache friendly data for the SIMD device
189  vector<uint32_t> m_triIndexList;
190  vector<float> m_limits;
191  vector<uint32_t> m_indexesOrTrilists;
193 
202  BVHNodePtr buildTree(const vector<float>& vertices, const vector<uint32_t>& faces);
203 
213  const floatArr vertices, size_t n_vertices,
214  const indexArray faces, size_t n_faces
215  );
216 
225  BVHNodePtr buildTreeRecursive(vector<AABB>& work, uint32_t depth = 0);
226 
230  void createCFTree();
231 
239  void createCFTreeRecursive(BVHNodePtr currentNode, uint32_t& idxBoxes);
240 
245 };
246 
247 } /* namespace lvr2 */
248 
249 #include "lvr2/geometry/BVH.tcc"
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
lvr2::BVHTree::BVHInner
Definition: BVH.hpp:164
lvr2::BVHTree::Triangle::e2
Normal< float > e2
Definition: BVH.hpp:142
lvr2::BVHTree::Triangle::e1
Normal< float > e1
Definition: BVH.hpp:142
lvr2::BVHTree::buildTreeRecursive
BVHNodePtr buildTreeRecursive(vector< AABB > &work, uint32_t depth=0)
Recursive method to build the tree.
lvr2::BVHTree::buildTree
BVHNodePtr buildTree(const vector< float > &vertices, const vector< uint32_t > &faces)
Builds the tree without it's cache friendly representation. Utilizes the buildTreeRecursive method.
lvr2::BVHTree::m_root
BVHNodePtr m_root
Definition: BVH.hpp:185
lvr2::BVHTree::BVHLeaf
Definition: BVH.hpp:176
lvr2::BVHTree::createCFTree
void createCFTree()
Creates the cache friendly representation of the tree. Needs the tree itself!
lvr2::BVHTree::m_trianglesIntersectionData
vector< float > m_trianglesIntersectionData
Definition: BVH.hpp:192
lvr2::indexArray
boost::shared_array< unsigned int > indexArray
Definition: DataStruct.hpp:128
lvr2::BVHTree< lvr2::BaseVector< float > >::BVHNodePtr
unique_ptr< BVHNode > BVHNodePtr
Definition: BVH.hpp:161
lvr2::BVHTree::m_indexesOrTrilists
vector< uint32_t > m_indexesOrTrilists
Definition: BVH.hpp:191
lvr2::BVHTree::m_triangles
vector< Triangle > m_triangles
Definition: BVH.hpp:186
lvr2::BVHTree::BVHInner::right
BVHNodePtr right
Definition: BVH.hpp:170
lvr2::BVHTree::Triangle::Triangle
Triangle()
lvr2::BVHTree< lvr2::BaseVector< float > >::BVHLeafPtr
unique_ptr< BVHLeaf > BVHLeafPtr
Definition: BVH.hpp:182
lvr2::BVHTree::BVHNode::isLeaf
virtual bool isLeaf()=0
lvr2::BVHTree::Triangle::d2
float d2
Definition: BVH.hpp:141
lvr2::BVHTree::AABB::triangles
vector< size_t > triangles
Definition: BVH.hpp:153
lvr2::BVHTree::Triangle::bb
BoundingBox< BaseVecT > bb
Definition: BVH.hpp:145
lvr2::BVHTree::AABB::bb
BoundingBox< BaseVecT > bb
Definition: BVH.hpp:150
lvr2::BVHTree::Triangle::idx1
uint32_t idx1
Definition: BVH.hpp:133
lvr2::BVHTree::BVHNode::bb
BoundingBox< BaseVecT > bb
Definition: BVH.hpp:158
lvr2::Normal< float >
lvr2::BVHTree::getTriIndexList
const vector< uint32_t > & getTriIndexList() const
lvr2::BVHTree::Triangle::d3
float d3
Definition: BVH.hpp:141
lvr2::BVHTree::Triangle::d1
float d1
Definition: BVH.hpp:141
lvr2::BVHTree::BVHTree
BVHTree(const vector< float > &vertices, const vector< uint32_t > &faces)
Constructs the tree itself and it's cache friendly representation.
lvr2::BVHTree::Triangle::idx2
uint32_t idx2
Definition: BVH.hpp:134
lvr2::BVHTree
Implementation of an Bounding Volume Hierarchy Tree used for ray casting.
Definition: BVH.hpp:61
lvr2::BVHTree::createCFTreeRecursive
void createCFTreeRecursive(BVHNodePtr currentNode, uint32_t &idxBoxes)
Recursive method for cache friendly tree creation.
lvr2::BVHTree::AABB
Definition: BVH.hpp:149
lvr2::BVHTree::BVHLeaf::triangles
vector< size_t > triangles
Definition: BVH.hpp:179
lvr2::BVHTree::getTrianglesIntersectionData
const vector< float > & getTrianglesIntersectionData() const
Returns precalculated values for the triangle intersection tests.
lvr2::BoundingBox
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
lvr2::BVHTree::BVHLeaf::isLeaf
virtual bool isLeaf()
Definition: BVH.hpp:180
lvr2::BVHTree::BVHNode
Definition: BVH.hpp:157
lvr2::BVHTree::m_limits
vector< float > m_limits
Definition: BVH.hpp:190
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::MeshBufferPtr
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
lvr2::BVHTree::getLimits
const vector< float > & getLimits() const
lvr2::BVHTree::Triangle::d
float d
Definition: BVH.hpp:141
lvr2::BVHTree::convertTrianglesIntersectionData
void convertTrianglesIntersectionData()
Converts the precalculated triangle intersection data to a SIMD friendly structure.
lvr2::BVHTree::BVHInner::isLeaf
virtual bool isLeaf()
Definition: BVH.hpp:171
lvr2::BVHTree::getIndexesOrTrilists
const vector< uint32_t > & getIndexesOrTrilists() const
lvr2::BVHTree::m_triIndexList
vector< uint32_t > m_triIndexList
Definition: BVH.hpp:189
mesh
HalfEdgeMesh< Vec > mesh
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:26
lvr2::BVHTree::Triangle::center
BaseVecT center
Definition: BVH.hpp:137
BoundingBox.hpp
lvr2::BVHTree::Triangle::e3
Normal< float > e3
Definition: BVH.hpp:142
lvr2::BVHTree< lvr2::BaseVector< float > >::BVHInnerPtr
unique_ptr< BVHInner > BVHInnerPtr
Definition: BVH.hpp:173
lvr2::BVHTree::Triangle
Definition: BVH.hpp:127
Normal.hpp
lvr2::BVHTree::Triangle::normal
Normal< float > normal
Definition: BVH.hpp:138
lvr2::BVHTree::BVHInner::left
BVHNodePtr left
Definition: BVH.hpp:167
lvr2::BVHTree::Triangle::idx3
uint32_t idx3
Definition: BVH.hpp:135


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:22