HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BV_Tree.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: BV_Tree.h
7  *
8  */
9 
10 #ifndef __BV_Tree_h__
11 #define __BV_Tree_h__
12 
13 #include "BV_API.h"
14 #include <UT/UT_Matrix4.h>
15 #include <iosfwd>
16 
17 class UT_IStream;
18 class BV_Callback;
19 class BV_LeafIterator;
20 
21 /// Base class for bounding volume hierarchies. It's not really intended to
22 /// be an all-encompassing base class; it's more intended as a rough
23 /// template for other bounding volume classes to follow.
25 {
26 public:
27  enum BV_Status
28  {
30  /// Rotations are not allowed.
32  /// Tree B was an unsupported type.
34  /// Failed for some other reason.
35  BV_FAIL
36  };
37  BV_Tree();
38  virtual ~BV_Tree();
39  BV_Tree *clone() const
40  { return cloneSubclass(); }
41 
42  virtual const char *getType() const = 0;
43  virtual const BV_Tree
44  *castTo(const char *type) const;
45  virtual BV_Tree *castTo(const char *type);
46 
48  { return getMemoryUsageSubclass(); }
49  int getNumLeaves() const
50  { return getNumLeavesSubclass(); }
51 
52  /// If the "onlyStructure" flag is set, then the dimensions of the
53  /// boxes are not saved/loaded, only the structure of the tree.
54  // @{
55  void save(std::ostream &os, bool onlyStructure) const
56  { saveSubclass(os, onlyStructure); }
57  bool load(UT_IStream &is, bool onlyStructure)
58  { return loadSubclass(is, onlyStructure); }
59  // @}
60 
61 
62  /// Construct a volume hierarchy from the given primitives.
63  void build(BV_LeafIterator &leafIt)
64  { buildSubclass(leafIt); }
65  /// Update an existing volume hierarchy by updating the bounding box
66  /// sizes without changing the hierarchy structure.
68  { updateExtentsSubclass(leafIt); }
69  /// Find intersections of bounding volumes of this tree ("A") with tree B,
70  /// rotated by ra and rb and translated by ta and tb respectively. For
71  /// each intersection, call the callback with the leaves whose bounding
72  /// volumes overlap.
73  ///
74  /// The callback can return a "stop" status to stop testing for further
75  /// intersections.
76  ///
77  /// Note:
78  /// - Not all trees can deal with rotations.
79  /// e.g., an AABB tree can't, unless it expands all nodes to handle
80  /// the contents at any orientation.
81  /// - method may not succeed if treeb is a different type.
82  /// @{
83  /// Static boxes only!
85  const BV_Tree &treeb,
86  const UT_DMatrix4 &xforma,
87  const UT_DMatrix4 &xformb,
88  fpreal tol = 0.001F) const
89  {
90  return intersectSubclass(callback, treeb,
91  xforma, xforma,
92  xformb, xformb,
93  tol);
94  }
95  /// Static boxes only!
97  const BV_Tree &treeb,
98  fpreal tol = 0.001F) const
99  {
100  return intersectSubclass(callback, treeb,
101  UT_DMatrix4(1.f),
102  UT_DMatrix4(1.f),
103  UT_DMatrix4(1.f),
104  UT_DMatrix4(1.f),
105  tol);
106  }
107  /// Moving boxes only!
109  const BV_Tree &treeb,
110  const UT_DMatrix4 &startxforma,
111  const UT_DMatrix4 &startxformb,
112  const UT_DMatrix4 &endxforma,
113  const UT_DMatrix4 &endxformb,
114  fpreal tol = 0.001F) const
115  {
116  return intersectSubclass(callback, treeb,
117  startxforma,
118  startxformb,
119  endxforma,
120  endxformb,
121  tol);
122  }
123  /// Moving boxes only!
125  const BV_Tree &treeb,
126  const UT_DMatrix4 &xforma,
127  const UT_DMatrix4 &startxforma,
128  const UT_DMatrix4 &startxformb,
129  const UT_DMatrix4 &xformb,
130  const UT_DMatrix4 &endxforma,
131  const UT_DMatrix4 &endxformb,
132  fpreal tol = 0.001F) const
133  {
134  // TODO: test
135  return intersectSubclass(callback, treeb,
136  startxforma * xforma,
137  startxformb * xformb,
138  endxforma * xforma,
139  endxformb * xformb,
140  tol);
141  }
142 
143  /// @}
144 
145 protected:
146  BV_Tree(const BV_Tree &tree);
147 
148  virtual BV_Tree *cloneSubclass() const = 0;
149  virtual void buildSubclass(BV_LeafIterator &leafIt) = 0;
150  virtual int64 getMemoryUsageSubclass() const = 0;
151  virtual int getNumLeavesSubclass() const = 0;
152  virtual void saveSubclass(std::ostream &os, bool onlyStructure)const = 0;
153  virtual bool loadSubclass(UT_IStream &is, bool onlyStructure) = 0;
154  virtual void updateExtentsSubclass(BV_LeafIterator &leafIt) = 0;
155  virtual BV_Status intersectSubclass(BV_Callback &callback,
156  const BV_Tree &treeb,
157  const UT_DMatrix4 &startxforma,
158  const UT_DMatrix4 &startxformb,
159  const UT_DMatrix4 &endxforma,
160  const UT_DMatrix4 &endxformb,
161  fpreal tol) const = 0;
162 
163 private:
164  /// Disallowed.
165  BV_Tree &operator=(const BV_Tree &);
166 };
167 
168 #endif
UT_Matrix4T< double > UT_DMatrix4
BV_Status intersect(BV_Callback &callback, const BV_Tree &treeb, const UT_DMatrix4 &startxforma, const UT_DMatrix4 &startxformb, const UT_DMatrix4 &endxforma, const UT_DMatrix4 &endxformb, fpreal tol=0.001F) const
Moving boxes only!
Definition: BV_Tree.h:108
BV_Status intersect(BV_Callback &callback, const BV_Tree &treeb, const UT_DMatrix4 &xforma, const UT_DMatrix4 &startxforma, const UT_DMatrix4 &startxformb, const UT_DMatrix4 &xformb, const UT_DMatrix4 &endxforma, const UT_DMatrix4 &endxformb, fpreal tol=0.001F) const
Moving boxes only!
Definition: BV_Tree.h:124
Rotations are not allowed.
Definition: BV_Tree.h:31
BV_Tree * clone() const
Definition: BV_Tree.h:39
Callback for bounding volume hierarchy intersection operation.
Definition: BV_Callback.h:17
GLfloat f
Definition: glcorearb.h:1926
BV_Status intersect(BV_Callback &callback, const BV_Tree &treeb, const UT_DMatrix4 &xforma, const UT_DMatrix4 &xformb, fpreal tol=0.001F) const
Definition: BV_Tree.h:84
long long int64
Definition: SYS_Types.h:116
void build(BV_LeafIterator &leafIt)
Construct a volume hierarchy from the given primitives.
Definition: BV_Tree.h:63
BV_Status
Definition: BV_Tree.h:27
Tree B was an unsupported type.
Definition: BV_Tree.h:33
#define BV_API
Definition: BV_API.h:10
fpreal64 fpreal
Definition: SYS_Types.h:277
int64 getMemoryUsage() const
Definition: BV_Tree.h:47
BV_Status intersect(BV_Callback &callback, const BV_Tree &treeb, fpreal tol=0.001F) const
Static boxes only!
Definition: BV_Tree.h:96
void updateExtents(BV_LeafIterator &leafIt)
Definition: BV_Tree.h:67
bool load(UT_IStream &is, bool onlyStructure)
Definition: BV_Tree.h:57
type
Definition: core.h:1059
void save(std::ostream &os, bool onlyStructure) const
Definition: BV_Tree.h:55
int getNumLeaves() const
Definition: BV_Tree.h:49