HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GU_PrimRTree.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GU_PrimRTree.h
7  *
8  * COMMENTS: Convenience wrapper for RTree used with GA Primitives
9  *
10  */
11 
12 #pragma once
13 
14 #include "GU_API.h"
15 #include <GEO/GEO_Detail.h>
16 #include <UT/UT_Array.h>
17 #include <UT/UT_RTree.h>
18 #include <utility>
19 
21 {
22 
23 public:
24  /// Construct an RTree of primiotives in the given group.
25  /// padding is relative to the bounding box radius of each box in the rtree
26  /// to ensure there is always enough precision to represent a non-zero
27  /// padding even for large models
28  explicit GU_PrimRTree(
29  const GEO_Detail& gdp,
30  const GA_PrimitiveGroup *prim_grp = 0,
31  fpreal relative_padding = SYS_FTOLERANCE_D,
32  fpreal absolute_padding = 0);
33 
34  explicit GU_PrimRTree(
35  const GEO_Detail& gdp,
36  const GA_Range& prim_range,
37  fpreal relative_padding = SYS_FTOLERANCE_D,
38  fpreal absolute_padding = 0);
39 
40  /// Returns the bounding box of this tree
41  UT_Box boundingBox() const;
42 
43  // WARNING: These two functions are non re-entrant, please use the following
44  // functions to get thread safe behaviour
45  void getIntersectingPrimOffsetsUnsafe(
46  const UT_Box &query_box,
47  GA_OffsetArray &intersecting_prims) const;
48  void getIntersectingPrimIndicesUnsafe(
49  const UT_Box &query_box,
50  GA_IndexArray &intersecting_prims) const;
51 
52  void getIntersectingPrimOffsets(
53  const UT_Box &query_box,
54  UT_IntArray &box_set,
55  GA_OffsetArray &intersecting_prims) const;
56  void getIntersectingPrimIndices(
57  const UT_Box &query_box,
58  UT_IntArray &box_set,
59  GA_IndexArray &intersecting_prims) const;
60  void getIntersectingBoxIndices(
61  const UT_Box &query_box,
62  UT_IntArray &box_set) const;
63 
64  static UT_Box getPrimBoundingBox(
65  const GEO_Detail& gdp,
66  GA_Offset prim_off,
67  fpreal relative_padding = SYS_FTOLERANCE_D,
68  fpreal absolute_padding = 0);
69 
70  /// Returns the bounding box of a given segment with some padding.
71  /// This method is exposed for convenience
72  static UT_Box getSegmentBoundingBox(
73  const UT_Vector3F& a,
74  const UT_Vector3F& b,
75  fpreal relative_padding = SYS_FTOLERANCE_D,
76  fpreal absolute_padding = 0);
77 
78  /// Returns the bounding box of a given segment with some padding.
79  /// This method is exposed for convenience
80  static UT_Box getTriangleBoundingBox(
81  const UT_Vector3F& a,
82  const UT_Vector3F& b,
83  const UT_Vector3F& c,
84  fpreal relative_padding = SYS_FTOLERANCE_D,
85  fpreal absolute_padding = 0);
86 
87  // Permissive member accessors. These are exposed for inspection
88  const UT_RTree& getTree() const { return myTree; }
89  const UT_RTreeBoxAssignment& getBoxAssignment() const { return myBoxAssignment; }
90  const UT_Array<UT_Box>& getBoxArray() const { return myBoxes.getBoxArray(); }
91  const GA_OffsetArray& getBoxOffsetMap() const { return myBoxes.getBoxOffsetMap(); }
92  const UT_Box& getBox(GA_Size i) const { return myBoxes.getBox(i); }
93  GA_Offset boxOffset(GA_Size i) const { return myBoxes.boxOffset(i); }
94  GA_Index boxIndex(GA_Size i) const { return myBoxes.boxIndex(i); }
95 
97  {
98  public:
100  explicit PrimBoundingBoxes(const GEO_Detail& gdp,
101  const GA_PrimitiveGroup *grp,
102  fpreal relative_padding = SYS_FTOLERANCE_D,
103  fpreal absolute_padding = 0);
104  explicit PrimBoundingBoxes(const GEO_Detail& gdp,
105  const GA_Range& prim_range,
106  fpreal relative_padding = SYS_FTOLERANCE_D,
107  fpreal absolute_padding = 0);
108 
109  void build(const GEO_Detail& gdp,
110  const GA_PrimitiveGroup *grp,
111  fpreal relative_padding = SYS_FTOLERANCE_D,
112  fpreal absolute_padding = 0);
113  void build(const GEO_Detail& gdp,
114  const GA_Range& prim_range,
115  fpreal relative_padding = SYS_FTOLERANCE_D,
116  fpreal absolute_padding = 0);
117 
118  const UT_Array<UT_Box>& getBoxArray() const { return myBoxArray; }
119  const GA_OffsetArray& getBoxOffsetMap() const { return myOffsetArray; }
120  const UT_Box& getBox(GA_Size i) const { return myBoxArray[i]; }
121  GA_Offset boxOffset(GA_Size i) const { return myOffsetArray[i]; }
123  {
124  return myPrimitiveMap ? myPrimitiveMap->indexFromOffset(boxOffset(i)) : GA_INVALID_INDEX;
125  }
126 
127  private:
128  GA_OffsetArray myOffsetArray;
129  UT_Array<UT_Box> myBoxArray;
130  const GA_IndexMap* myPrimitiveMap;
131  };
132 
133 private:
134  mutable UT_IntArray myBoxSet; // working box set
135 
136  // WARNING: Don't change the order of these since construction of myTree
137  // depends on myBoxes
138  PrimBoundingBoxes myBoxes;
139  UT_RTree myTree;
140  UT_RTreeBoxAssignment myBoxAssignment;
141 
142  // Disallow as in UT_RTree
143  GU_PrimRTree();
144  GU_PrimRTree(const GU_PrimRTree&);
145  GU_PrimRTree& operator=(const GU_PrimRTree&);
146 };
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
GA_Index boxIndex(GA_Size i) const
Definition: GU_PrimRTree.h:122
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GA_Offset boxOffset(GA_Size i) const
Definition: GU_PrimRTree.h:121
const GA_OffsetArray & getBoxOffsetMap() const
Definition: GU_PrimRTree.h:91
#define SYS_FTOLERANCE_D
Definition: SYS_Types.h:203
const UT_Box & getBox(GA_Size i) const
Definition: GU_PrimRTree.h:92
png_uint_32 i
Definition: png.h:2877
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:617
GA_Index boxIndex(GA_Size i) const
Definition: GU_PrimRTree.h:94
const UT_RTreeBoxAssignment & getBoxAssignment() const
Definition: GU_PrimRTree.h:89
#define GU_API
Definition: GU_API.h:11
const GA_OffsetArray & getBoxOffsetMap() const
Definition: GU_PrimRTree.h:119
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
const UT_RTree & getTree() const
Definition: GU_PrimRTree.h:88
const UT_Array< UT_Box > & getBoxArray() const
Definition: GU_PrimRTree.h:118
double fpreal
Definition: SYS_Types.h:269
GA_Offset boxOffset(GA_Size i) const
Definition: GU_PrimRTree.h:93
#define GA_INVALID_INDEX
Definition: GA_Types.h:653
const UT_Array< UT_Box > & getBoxArray() const
Definition: GU_PrimRTree.h:90
const UT_Box & getBox(GA_Size i) const
Definition: GU_PrimRTree.h:120