OPC_TreeBuilders.h
Go to the documentation of this file.
1 /*
3  * OPCODE - Optimized Collision Detection
4  * Copyright (C) 2001 Pierre Terdiman
5  * Homepage: http://www.codercorner.com/Opcode.htm
6  */
8 
10 
16 
19 // Include Guard
20 #ifndef __OPC_TREEBUILDERS_H__
21 #define __OPC_TREEBUILDERS_H__
22 
25  {
26  // Primitive split
27  SPLIT_LARGEST_AXIS = (1<<0),
29  SPLIT_BEST_AXIS = (1<<2),
30  SPLIT_BALANCED = (1<<3),
31  SPLIT_FIFTY = (1<<4),
32  // Node split
33  SPLIT_GEOM_CENTER = (1<<5),
34  //
35  SPLIT_FORCE_DWORD = 0x7fffffff
36  };
37 
40  {
41  inline_ BuildSettings() : mLimit(1), mRules(SPLIT_FORCE_DWORD) {}
42 
45  };
46 
48  {
49  public:
52  mNbPrimitives(0),
53  mNodeBase(null),
54  mCount(0),
55  mNbInvalidSplits(0) {}
57  virtual ~AABBTreeBuilder() {}
58 
60 
67  virtual bool ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box) const = 0;
69 
71 
77  virtual float GetSplittingValue(udword index, udword axis) const = 0;
79 
81 
89  virtual float GetSplittingValue(const udword* primitives, udword nb_prims, const AABB& global_box, udword axis) const
91  {
92  // Default split value = middle of the axis (using only the box)
93  return global_box.GetCenter(axis);
94  }
95 
97 
104  virtual BOOL ValidateSubdivision(const udword* primitives, udword nb_prims, const AABB& global_box)
106  {
107  // Check the user-defined limit
108  if(nb_prims<=mSettings.mLimit) return FALSE;
109 
110  return TRUE;
111  }
112 
115  void* mNodeBase;
116  // Stats
117  inline_ void SetCount(udword nb) { mCount=nb; }
118  inline_ void IncreaseCount(udword nb) { mCount+=nb; }
119  inline_ udword GetCount() const { return mCount; }
120  inline_ void SetNbInvalidSplits(udword nb) { mNbInvalidSplits=nb; }
121  inline_ void IncreaseNbInvalidSplits() { mNbInvalidSplits++; }
122  inline_ udword GetNbInvalidSplits() const { return mNbInvalidSplits; }
123 
124  private:
127  };
128 
130  {
131  public:
133  AABBTreeOfVerticesBuilder() : mVertexArray(null) {}
136 
137  override(AABBTreeBuilder) bool ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box) const;
138  override(AABBTreeBuilder) float GetSplittingValue(udword index, udword axis) const;
139  override(AABBTreeBuilder) float GetSplittingValue(const udword* primitives, udword nb_prims, const AABB& global_box, udword axis) const;
140 
142  };
143 
145  {
146  public:
148  AABBTreeOfAABBsBuilder() : mAABBArray(null) {}
151 
152  override(AABBTreeBuilder) bool ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box) const;
153  override(AABBTreeBuilder) float GetSplittingValue(udword index, udword axis) const;
154 
155  const AABB* mAABBArray;
156  };
157 
159  {
160  public:
165 
166  override(AABBTreeBuilder) bool ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box) const;
167  override(AABBTreeBuilder) float GetSplittingValue(udword index, udword axis) const;
168  override(AABBTreeBuilder) float GetSplittingValue(const udword* primitives, udword nb_prims, const AABB& global_box, udword axis) const;
169 
171  };
172 
173 #endif // __OPC_TREEBUILDERS_H__
AABBTreeOfVerticesBuilder()
Constructor.
AABBTreeOfAABBsBuilder()
Constructor.
inline_ BuildSettings()
#define FALSE
Definition: OPC_IceHook.h:9
#define null
our own NULL pointer
Definition: IceTypes.h:57
Split at geometric center (else split in the middle)
inline_ void SetCount(udword nb)
Splatter primitive centers (QuickCD-style)
#define TRUE
Definition: OPC_IceHook.h:13
#define inline_
inline_ void IncreaseNbInvalidSplits()
virtual ~AABBTreeOfAABBsBuilder()
Destructor.
virtual ~AABBTreeOfTrianglesBuilder()
Destructor.
Definition: IcePoint.h:25
inline_ void SetNbInvalidSplits(udword nb)
virtual ~AABBTreeOfVerticesBuilder()
Destructor.
udword mNbPrimitives
Total number of primitives.
#define OPCODE_API
Definition: Opcode.h:68
const Point * mVertexArray
Shortcut to an app-controlled array of vertices.
void * mNodeBase
Address of node pool [Opcode 1.3].
int BOOL
Another boolean type.
Definition: IceTypes.h:102
virtual float GetSplittingValue(udword index, udword axis) const =0
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
const AABB * mAABBArray
Shortcut to an app-controlled array of AABBs.
inline_ void IncreaseCount(udword nb)
list index
Definition: IceAABB.h:267
Simple wrapper around build-related settings [Opcode 1.3].
udword mLimit
Limit number of primitives / node. If limit is 1, build a complete tree (2*N-1 nodes) ...
AABBTreeBuilder()
Constructor.
virtual bool ComputeGlobalBox(const udword *primitives, udword nb_prims, AABB &global_box) const =0
inline_ void GetCenter(Point &center) const
Get box center.
Definition: IceAABB.h:353
const MeshInterface * mIMesh
Shortcut to an app-controlled mesh interface.
inline_ udword GetNbInvalidSplits() const
udword mRules
Building/Splitting rules (a combination of SplittingRules flags)
Arbitrary 50-50 split.
SplittingRules
Tree splitting rules.
BuildSettings mSettings
Splitting rules & split limit [Opcode 1.3].
Try largest axis, then second, then last.
udword mNbInvalidSplits
Stats: number of invalid splits.
AABBTreeOfTrianglesBuilder()
Constructor.
virtual ~AABBTreeBuilder()
Destructor.
Try to keep a well-balanced tree.
udword mCount
Stats: number of nodes created.
Split along the largest axis.
inline_ udword GetCount() const


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:24