Bullet Collision Detection & Physics Library: btGImpactQuantizedBvh.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btGImpactQuantizedBvh.h
Go to the documentation of this file.
1#ifndef GIM_QUANTIZED_SET_H_INCLUDED
2#define GIM_QUANTIZED_SET_H_INCLUDED
3
7/*
8This source file is part of GIMPACT Library.
9
10For the latest info, see http://gimpact.sourceforge.net/
11
12Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
13email: projectileman@yahoo.com
14
15
16This software is provided 'as-is', without any express or implied warranty.
17In no event will the authors be held liable for any damages arising from the use of this software.
18Permission is granted to anyone to use this software for any purpose,
19including commercial applications, and to alter it and redistribute it freely,
20subject to the following restrictions:
21
221. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
232. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
243. This notice may not be removed or altered from any source distribution.
25*/
26
27#include "btGImpactBvh.h"
28#include "btQuantization.h"
29#include "btGImpactQuantizedBvhStructs.h"
30
31 class GIM_QUANTIZED_BVH_NODE_ARRAY : public btAlignedObjectArray<BT_QUANTIZED_BVH_NODE>
32{
33};
34
36 class btQuantizedBvhTree
37{
38protected:
39 int m_num_nodes;
40 GIM_QUANTIZED_BVH_NODE_ARRAY m_node_array;
41 btAABB m_global_bound;
42 btVector3 m_bvhQuantization;
43
44protected:
45 void calc_quantization(GIM_BVH_DATA_ARRAY& primitive_boxes, btScalar boundMargin = btScalar(1.0));
46
47 int _sort_and_calc_splitting_index(
48 GIM_BVH_DATA_ARRAY& primitive_boxes,
49 int startIndex, int endIndex, int splitAxis);
50
51 int _calc_splitting_axis(GIM_BVH_DATA_ARRAY& primitive_boxes, int startIndex, int endIndex);
52
53 void _build_sub_tree(GIM_BVH_DATA_ARRAY& primitive_boxes, int startIndex, int endIndex);
54
55public:
56 btQuantizedBvhTree()
57 {
58 m_num_nodes = 0;
59 }
60
63 void build_tree(GIM_BVH_DATA_ARRAY& primitive_boxes);
64
65 SIMD_FORCE_INLINE void quantizePoint(
66 unsigned short* quantizedpoint, const btVector3& point) const
67 {
68 bt_quantize_clamp(quantizedpoint, point, m_global_bound.m_min, m_global_bound.m_max, m_bvhQuantization);
69 }
70
71 SIMD_FORCE_INLINE bool testQuantizedBoxOverlapp(
72 int node_index,
73 unsigned short* quantizedMin, unsigned short* quantizedMax) const
74 {
75 return m_node_array[node_index].testQuantizedBoxOverlapp(quantizedMin, quantizedMax);
76 }
77
78 SIMD_FORCE_INLINE void clearNodes()
79 {
80 m_node_array.clear();
81 m_num_nodes = 0;
82 }
83
85 SIMD_FORCE_INLINE int getNodeCount() const
86 {
87 return m_num_nodes;
88 }
89
91 SIMD_FORCE_INLINE bool isLeafNode(int nodeindex) const
92 {
93 return m_node_array[nodeindex].isLeafNode();
94 }
95
96 SIMD_FORCE_INLINE int getNodeData(int nodeindex) const
97 {
98 return m_node_array[nodeindex].getDataIndex();
99 }
100
101 SIMD_FORCE_INLINE void getNodeBound(int nodeindex, btAABB& bound) const
102 {
103 bound.m_min = bt_unquantize(
104 m_node_array[nodeindex].m_quantizedAabbMin,
105 m_global_bound.m_min, m_bvhQuantization);
106
107 bound.m_max = bt_unquantize(
108 m_node_array[nodeindex].m_quantizedAabbMax,
109 m_global_bound.m_min, m_bvhQuantization);
110 }
111
112 SIMD_FORCE_INLINE void setNodeBound(int nodeindex, const btAABB& bound)
113 {
114 bt_quantize_clamp(m_node_array[nodeindex].m_quantizedAabbMin,
115 bound.m_min,
116 m_global_bound.m_min,
117 m_global_bound.m_max,
118 m_bvhQuantization);
119
120 bt_quantize_clamp(m_node_array[nodeindex].m_quantizedAabbMax,
121 bound.m_max,
122 m_global_bound.m_min,
123 m_global_bound.m_max,
124 m_bvhQuantization);
125 }
126
127 SIMD_FORCE_INLINE int getLeftNode(int nodeindex) const
128 {
129 return nodeindex + 1;
130 }
131
132 SIMD_FORCE_INLINE int getRightNode(int nodeindex) const
133 {
134 if (m_node_array[nodeindex + 1].isLeafNode()) return nodeindex + 2;
135 return nodeindex + 1 + m_node_array[nodeindex + 1].getEscapeIndex();
136 }
137
138 SIMD_FORCE_INLINE int getEscapeNodeIndex(int nodeindex) const
139 {
140 return m_node_array[nodeindex].getEscapeIndex();
141 }
142
143 SIMD_FORCE_INLINE const BT_QUANTIZED_BVH_NODE* get_node_pointer(int index = 0) const
144 {
145 return &m_node_array[index];
146 }
147
149};
150
152
156 class btGImpactQuantizedBvh
157{
158protected:
159 btQuantizedBvhTree m_box_tree;
160 btPrimitiveManagerBase* m_primitive_manager;
161
162protected:
163 //stackless refit
164 void refit();
165
166public:
168 btGImpactQuantizedBvh()
169 {
170 m_primitive_manager = NULL;
171 }
172
174 btGImpactQuantizedBvh(btPrimitiveManagerBase* primitive_manager)
175 {
176 m_primitive_manager = primitive_manager;
177 }
178
179 SIMD_FORCE_INLINE btAABB getGlobalBox() const
180 {
181 btAABB totalbox;
182 getNodeBound(0, totalbox);
183 return totalbox;
184 }
185
186 SIMD_FORCE_INLINE void setPrimitiveManager(btPrimitiveManagerBase* primitive_manager)
187 {
188 m_primitive_manager = primitive_manager;
189 }
190
191 SIMD_FORCE_INLINE btPrimitiveManagerBase* getPrimitiveManager() const
192 {
193 return m_primitive_manager;
194 }
195
198
200 SIMD_FORCE_INLINE void update()
201 {
202 refit();
203 }
204
206 void buildSet();
207
209 bool boxQuery(const btAABB& box, btAlignedObjectArray<int>& collided_results) const;
210
212 SIMD_FORCE_INLINE bool boxQueryTrans(const btAABB& box,
213 const btTransform& transform, btAlignedObjectArray<int>& collided_results) const
214 {
215 btAABB transbox = box;
216 transbox.appy_transform(transform);
217 return boxQuery(transbox, collided_results);
218 }
219
221 bool rayQuery(
222 const btVector3& ray_dir, const btVector3& ray_origin,
223 btAlignedObjectArray<int>& collided_results) const;
224
226 SIMD_FORCE_INLINE bool hasHierarchy() const
227 {
228 return true;
229 }
230
232 SIMD_FORCE_INLINE bool isTrimesh() const
233 {
234 return m_primitive_manager->is_trimesh();
235 }
236
238 SIMD_FORCE_INLINE int getNodeCount() const
239 {
240 return m_box_tree.getNodeCount();
241 }
242
244 SIMD_FORCE_INLINE bool isLeafNode(int nodeindex) const
245 {
246 return m_box_tree.isLeafNode(nodeindex);
247 }
248
249 SIMD_FORCE_INLINE int getNodeData(int nodeindex) const
250 {
251 return m_box_tree.getNodeData(nodeindex);
252 }
253
254 SIMD_FORCE_INLINE void getNodeBound(int nodeindex, btAABB& bound) const
255 {
256 m_box_tree.getNodeBound(nodeindex, bound);
257 }
258
259 SIMD_FORCE_INLINE void setNodeBound(int nodeindex, const btAABB& bound)
260 {
261 m_box_tree.setNodeBound(nodeindex, bound);
262 }
263
264 SIMD_FORCE_INLINE int getLeftNode(int nodeindex) const
265 {
266 return m_box_tree.getLeftNode(nodeindex);
267 }
268
269 SIMD_FORCE_INLINE int getRightNode(int nodeindex) const
270 {
271 return m_box_tree.getRightNode(nodeindex);
272 }
273
274 SIMD_FORCE_INLINE int getEscapeNodeIndex(int nodeindex) const
275 {
276 return m_box_tree.getEscapeNodeIndex(nodeindex);
277 }
278
279 SIMD_FORCE_INLINE void getNodeTriangle(int nodeindex, btPrimitiveTriangle& triangle) const
280 {
281 m_primitive_manager->get_primitive_triangle(getNodeData(nodeindex), triangle);
282 }
283
284 SIMD_FORCE_INLINE const BT_QUANTIZED_BVH_NODE* get_node_pointer(int index = 0) const
285 {
286 return m_box_tree.get_node_pointer(index);
287 }
288
289#ifdef TRI_COLLISION_PROFILING
290 static float getAverageTreeCollisionTime();
291#endif //TRI_COLLISION_PROFILING
292
293 static void find_collision(const btGImpactQuantizedBvh* boxset1, const btTransform& trans1,
294 const btGImpactQuantizedBvh* boxset2, const btTransform& trans2,
295 btPairSet& collision_pairs);
296};
297
298#endif // GIM_BOXPRUNING_H_INCLUDED
btGImpactBvh.h
btGImpactQuantizedBvhStructs.h
btQuantization.h
bt_quantize_clamp
void bt_quantize_clamp(unsigned short *out, const btVector3 &point, const btVector3 &min_bound, const btVector3 &max_bound, const btVector3 &bvhQuantization)
Definition: btQuantization.h:48
bt_unquantize
btVector3 bt_unquantize(const unsigned short *vecIn, const btVector3 &offset, const btVector3 &bvhQuantization)
Definition: btQuantization.h:65
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:98
GIM_BVH_DATA_ARRAY
Definition: btGImpactBvh.h:53
GIM_QUANTIZED_BVH_NODE_ARRAY
Definition: btGImpactQuantizedBvh.h:32
btAABB
Axis aligned box.
Definition: btBoxCollision.h:216
btAABB::m_min
btVector3 m_min
Definition: btBoxCollision.h:218
btAABB::m_max
btVector3 m_max
Definition: btBoxCollision.h:219
btAABB::appy_transform
void appy_transform(const btTransform &trans)
Apply a transform to an AABB.
Definition: btBoxCollision.h:354
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:46
btAlignedObjectArray::clear
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0),...
Definition: btAlignedObjectArray.h:176
btGImpactQuantizedBvh
Structure for containing Boxes.
Definition: btGImpactQuantizedBvh.h:157
btGImpactQuantizedBvh::getNodeData
int getNodeData(int nodeindex) const
Definition: btGImpactQuantizedBvh.h:249
btGImpactQuantizedBvh::boxQueryTrans
bool boxQueryTrans(const btAABB &box, const btTransform &transform, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
Definition: btGImpactQuantizedBvh.h:212
btGImpactQuantizedBvh::rayQuery
bool rayQuery(const btVector3 &ray_dir, const btVector3 &ray_origin, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
Definition: btGImpactQuantizedBvh.cpp:327
btGImpactQuantizedBvh::m_primitive_manager
btPrimitiveManagerBase * m_primitive_manager
Definition: btGImpactQuantizedBvh.h:160
btGImpactQuantizedBvh::getPrimitiveManager
btPrimitiveManagerBase * getPrimitiveManager() const
Definition: btGImpactQuantizedBvh.h:191
btGImpactQuantizedBvh::buildSet
void buildSet()
this rebuild the entire set
Definition: btGImpactQuantizedBvh.cpp:270
btGImpactQuantizedBvh::btGImpactQuantizedBvh
btGImpactQuantizedBvh()
this constructor doesn't build the tree. you must call buildSet
Definition: btGImpactQuantizedBvh.h:168
btGImpactQuantizedBvh::boxQuery
bool boxQuery(const btAABB &box, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
Definition: btGImpactQuantizedBvh.cpp:286
btGImpactQuantizedBvh::isLeafNode
bool isLeafNode(int nodeindex) const
tells if the node is a leaf
Definition: btGImpactQuantizedBvh.h:244
btGImpactQuantizedBvh::btGImpactQuantizedBvh
btGImpactQuantizedBvh(btPrimitiveManagerBase *primitive_manager)
this constructor doesn't build the tree. you must call buildSet
Definition: btGImpactQuantizedBvh.h:174
btGImpactQuantizedBvh::getNodeTriangle
void getNodeTriangle(int nodeindex, btPrimitiveTriangle &triangle) const
Definition: btGImpactQuantizedBvh.h:279
btGImpactQuantizedBvh::m_box_tree
btQuantizedBvhTree m_box_tree
Definition: btGImpactQuantizedBvh.h:159
btGImpactQuantizedBvh::setNodeBound
void setNodeBound(int nodeindex, const btAABB &bound)
Definition: btGImpactQuantizedBvh.h:259
btGImpactQuantizedBvh::refit
void refit()
Definition: btGImpactQuantizedBvh.cpp:230
btGImpactQuantizedBvh::getNodeCount
int getNodeCount() const
node count
Definition: btGImpactQuantizedBvh.h:238
btGImpactQuantizedBvh::getRightNode
int getRightNode(int nodeindex) const
Definition: btGImpactQuantizedBvh.h:269
btGImpactQuantizedBvh::update
void update()
node manager prototype functions
Definition: btGImpactQuantizedBvh.h:200
btGImpactQuantizedBvh::setPrimitiveManager
void setPrimitiveManager(btPrimitiveManagerBase *primitive_manager)
Definition: btGImpactQuantizedBvh.h:186
btGImpactQuantizedBvh::get_node_pointer
const BT_QUANTIZED_BVH_NODE * get_node_pointer(int index=0) const
Definition: btGImpactQuantizedBvh.h:284
btGImpactQuantizedBvh::getEscapeNodeIndex
int getEscapeNodeIndex(int nodeindex) const
Definition: btGImpactQuantizedBvh.h:274
btGImpactQuantizedBvh::getGlobalBox
btAABB getGlobalBox() const
Definition: btGImpactQuantizedBvh.h:179
btGImpactQuantizedBvh::isTrimesh
bool isTrimesh() const
tells if this set is a trimesh
Definition: btGImpactQuantizedBvh.h:232
btGImpactQuantizedBvh::getNodeBound
void getNodeBound(int nodeindex, btAABB &bound) const
Definition: btGImpactQuantizedBvh.h:254
btGImpactQuantizedBvh::getLeftNode
int getLeftNode(int nodeindex) const
Definition: btGImpactQuantizedBvh.h:264
btGImpactQuantizedBvh::find_collision
static void find_collision(const btGImpactQuantizedBvh *boxset1, const btTransform &trans1, const btGImpactQuantizedBvh *boxset2, const btTransform &trans2, btPairSet &collision_pairs)
Definition: btGImpactQuantizedBvh.cpp:466
btGImpactQuantizedBvh::hasHierarchy
bool hasHierarchy() const
tells if this set has hierarcht
Definition: btGImpactQuantizedBvh.h:226
btPairSet
A pairset array.
Definition: btGImpactBvh.h:35
btPrimitiveManagerBase
Prototype Base class for primitive classification.
Definition: btGImpactBvh.h:150
btPrimitiveManagerBase::get_primitive_triangle
virtual void get_primitive_triangle(int prim_index, btPrimitiveTriangle &triangle) const =0
retrieves only the points of the triangle, and the collision margin
btPrimitiveManagerBase::is_trimesh
virtual bool is_trimesh() const =0
determines if this manager consist on only triangles, which special case will be optimized
btPrimitiveTriangle
Definition: btTriangleShapeEx.h:70
btQuantizedBvhTree
Basic Box tree structure.
Definition: btGImpactQuantizedBvh.h:37
btQuantizedBvhTree::setNodeBound
void setNodeBound(int nodeindex, const btAABB &bound)
Definition: btGImpactQuantizedBvh.h:112
btQuantizedBvhTree::get_node_pointer
const BT_QUANTIZED_BVH_NODE * get_node_pointer(int index=0) const
Definition: btGImpactQuantizedBvh.h:143
btQuantizedBvhTree::m_bvhQuantization
btVector3 m_bvhQuantization
Definition: btGImpactQuantizedBvh.h:42
btQuantizedBvhTree::getNodeBound
void getNodeBound(int nodeindex, btAABB &bound) const
Definition: btGImpactQuantizedBvh.h:101
btQuantizedBvhTree::m_global_bound
btAABB m_global_bound
Definition: btGImpactQuantizedBvh.h:41
btQuantizedBvhTree::getRightNode
int getRightNode(int nodeindex) const
Definition: btGImpactQuantizedBvh.h:132
btQuantizedBvhTree::isLeafNode
bool isLeafNode(int nodeindex) const
tells if the node is a leaf
Definition: btGImpactQuantizedBvh.h:91
btQuantizedBvhTree::_build_sub_tree
void _build_sub_tree(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)
Definition: btGImpactQuantizedBvh.cpp:169
btQuantizedBvhTree::quantizePoint
void quantizePoint(unsigned short *quantizedpoint, const btVector3 &point) const
Definition: btGImpactQuantizedBvh.h:65
btQuantizedBvhTree::getNodeCount
int getNodeCount() const
node count
Definition: btGImpactQuantizedBvh.h:85
btQuantizedBvhTree::calc_quantization
void calc_quantization(GIM_BVH_DATA_ARRAY &primitive_boxes, btScalar boundMargin=btScalar(1.0))
Definition: btGImpactQuantizedBvh.cpp:65
btQuantizedBvhTree::build_tree
void build_tree(GIM_BVH_DATA_ARRAY &primitive_boxes)
prototype functions for box tree management
Definition: btGImpactQuantizedBvh.cpp:216
btQuantizedBvhTree::m_num_nodes
int m_num_nodes
Definition: btGImpactQuantizedBvh.h:39
btQuantizedBvhTree::getEscapeNodeIndex
int getEscapeNodeIndex(int nodeindex) const
Definition: btGImpactQuantizedBvh.h:138
btQuantizedBvhTree::m_node_array
GIM_QUANTIZED_BVH_NODE_ARRAY m_node_array
Definition: btGImpactQuantizedBvh.h:40
btQuantizedBvhTree::_sort_and_calc_splitting_index
int _sort_and_calc_splitting_index(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex, int splitAxis)
Definition: btGImpactQuantizedBvh.cpp:111
btQuantizedBvhTree::getNodeData
int getNodeData(int nodeindex) const
Definition: btGImpactQuantizedBvh.h:96
btQuantizedBvhTree::_calc_splitting_axis
int _calc_splitting_axis(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)
Definition: btGImpactQuantizedBvh.cpp:81
btQuantizedBvhTree::btQuantizedBvhTree
btQuantizedBvhTree()
Definition: btGImpactQuantizedBvh.h:56
btQuantizedBvhTree::testQuantizedBoxOverlapp
bool testQuantizedBoxOverlapp(int node_index, unsigned short *quantizedMin, unsigned short *quantizedMax) const
Definition: btGImpactQuantizedBvh.h:71
btQuantizedBvhTree::clearNodes
void clearNodes()
Definition: btGImpactQuantizedBvh.h:78
btQuantizedBvhTree::getLeftNode
int getLeftNode(int nodeindex) const
Definition: btGImpactQuantizedBvh.h:127
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
BT_QUANTIZED_BVH_NODE
btQuantizedBvhNode is a compressed aabb node, 16 bytes.
Definition: btGImpactQuantizedBvhStructs.h:34