OPC_AABBTree.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_AABBTREE_H__
21 #define __OPC_AABBTREE_H__
22 
23 #if (defined __x86_64) || (defined __aarch64__)
24 #define EXWORD uqword
25 #else
26 #define EXWORD udword
27 #endif
28 
29 #ifdef OPC_NO_NEG_VANILLA_TREE
30  #define IMPLEMENT_TREE(base_class, volume) \
32  public: \
33  /* Constructor / Destructor */ \
34  base_class(); \
35  ~base_class(); \
36  /* Data access */ \
37  inline_ const volume* Get##volume() const { return &mBV; } \
38  /* Clear the last bit */ \
39  inline_ const base_class* GetPos() const { return (const base_class*)(mPos&~1); } \
40  inline_ const base_class* GetNeg() const { const base_class* P = GetPos(); return P ? P+1 : null;} \
41  \
42  /* We don't need to test both nodes since we can't have one without the other */ \
43  inline_ bool IsLeaf() const { return !GetPos(); } \
44  \
45  /* Stats */ \
46  inline_ udword GetNodeSize() const { return SIZEOFOBJECT; } \
47  protected: \
48  /* Tree-independent data */ \
49  /* Following data always belong to the BV-tree, regardless of what the tree actually contains.*/ \
50  /* Whatever happens we need the two children and the enclosing volume.*/ \
51  volume mBV; /* Global bounding-volume enclosing all the node-related primitives */ \
52  EXWORD mPos; /* "Positive" & "Negative" children */
53 #else
54  #define IMPLEMENT_TREE(base_class, volume) \
56  public: \
57  /* Constructor / Destructor */ \
58  base_class(); \
59  ~base_class(); \
60  /* Data access */ \
61  inline_ const volume* Get##volume() const { return &mBV; } \
62  /* Clear the last bit */ \
63  inline_ const base_class* GetPos() const { return (const base_class*)(mPos&~1); } \
64  inline_ const base_class* GetNeg() const { return (const base_class*)(mNeg&~1); } \
65  \
66 /* inline_ bool IsLeaf() const { return (!GetPos() && !GetNeg()); } */ \
67  /* We don't need to test both nodes since we can't have one without the other */ \
68  inline_ bool IsLeaf() const { return !GetPos(); } \
69  \
70  /* Stats */ \
71  inline_ udword GetNodeSize() const { return SIZEOFOBJECT; } \
72  protected: \
73  /* Tree-independent data */ \
74  /* Following data always belong to the BV-tree, regardless of what the tree actually contains.*/ \
75  /* Whatever happens we need the two children and the enclosing volume.*/ \
76  volume mBV; /* Global bounding-volume enclosing all the node-related primitives */ \
77  EXWORD mPos; /* "Positive" child */ \
78  EXOWRD mNeg; /* "Negative" child */
79 #endif
80 
81  typedef void (*CullingCallback) (udword nb_primitives, udword* node_primitives, BOOL need_clipping, void* user_data);
82 
84  {
86  public:
87  // Data access
88  inline_ const udword* GetPrimitives() const { return mNodePrimitives; }
89  inline_ udword GetNbPrimitives() const { return mNbPrimitives; }
90 
91  protected:
92  // Tree-dependent data
95  // Internal methods
96  udword Split(udword axis, AABBTreeBuilder* builder);
97  bool Subdivide(AABBTreeBuilder* builder);
98  void _BuildHierarchy(AABBTreeBuilder* builder);
99  void _Refit(AABBTreeBuilder* builder);
100  };
101 
103 
110  typedef bool (*WalkingCallback) (const AABBTreeNode* current, udword depth, void* user_data);
112 
114  {
115  public:
116  // Constructor / Destructor
117  AABBTree();
118  ~AABBTree();
119  // Build
120  bool Build(AABBTreeBuilder* builder);
121  void Release();
122 
123  // Data access
124  inline_ const udword* GetIndices() const { return mIndices; }
125  inline_ udword GetNbNodes() const { return mTotalNbNodes; }
126 
127  // Infos
128  bool IsComplete() const;
129  // Stats
130  udword ComputeDepth() const;
131  udword GetUsedBytes() const;
132  udword Walk(WalkingCallback callback, void* user_data) const;
133 
134  bool Refit(AABBTreeBuilder* builder);
135  bool Refit2(AABBTreeBuilder* builder);
136  private:
139  // Stats
141  };
142 
143 #endif // __OPC_AABBTREE_H__
AABBTreeNode * mPool
Linear pool of nodes for complete trees. Null otherwise. [Opcode 1.3].
Definition: OPC_AABBTree.h:138
inline_ udword GetNbNodes() const
Catch the number of nodes.
Definition: OPC_AABBTree.h:125
inline_ udword GetNbPrimitives() const
Definition: OPC_AABBTree.h:89
#define IMPLEMENT_TREE(base_class, volume)
TO BE DOCUMENTED.
Definition: Opcode.h:32
void(* CullingCallback)(udword nb_primitives, udword *node_primitives, BOOL need_clipping, void *user_data)
Definition: OPC_AABBTree.h:81
udword * mNodePrimitives
Node-related primitives (shortcut to a position in mIndices below)
Definition: OPC_AABBTree.h:93
inline_ const udword * GetIndices() const
Catch the indices.
Definition: OPC_AABBTree.h:124
#define inline_
#define OPCODE_API
Definition: Opcode.h:68
int BOOL
Another boolean type.
Definition: IceTypes.h:102
udword mNbPrimitives
Number of primitives for this node.
Definition: OPC_AABBTree.h:94
udword mTotalNbNodes
Number of nodes in the tree.
Definition: OPC_AABBTree.h:140
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
udword * mIndices
Indices in the app list. Indices are reorganized during build (permutation).
Definition: OPC_AABBTree.h:137
Definition: IceAABB.h:267
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
inline_ const udword * GetPrimitives() const
Definition: OPC_AABBTree.h:88
bool(* WalkingCallback)(const AABBTreeNode *current, udword depth, void *user_data)
Definition: OPC_AABBTree.h:111


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:04