Simbody  3.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OBBTree.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMMATH_OBB_TREE_H_
2 #define SimTK_SIMMATH_OBB_TREE_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKmath *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2011-12 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
30 #include "SimTKcommon.h"
32 #include "simmath/internal/Geo.h"
35 
36 #include <cassert>
37 
38 namespace SimTK {
39 
40 //==============================================================================
41 // OBB LEAF
42 //==============================================================================
44 class OBBLeaf {
45 public:
46  virtual ~OBBLeaf() {}
47 };
48 
49 //==============================================================================
50 // OBB NODE
51 //==============================================================================
54 public:
55  OBBNode() : contents(0) {clear();}
56  ~OBBNode() {clear();}
57 
58  void clear() {
59  delete contents; contents=0;
60  x0=y0=nx=ny=-1;
61  children.clear();
62  }
63 
64  bool isLeaf() const {return children.empty();}
65  int getNumChildren() const {return (int)children.size();}
66  const OBBNode& getChild(int i) const {return children[i];}
67  OBBNode& updChild(int i) {return children[i];}
68 
69  // A box enclosing the contents.
71  int depth; // 0 is root
72  int height; // a leaf is 0, node is max of children+1
73 
74  // A cone enclosing the entire range of normals.
75  UnitVec3 normal; // central normal
76  Real coneHalfAngle; // 0<=a<=pi, pi/2 makes a halfspace
77 
78  // An arbitrary point on the contained surface, used in
79  // distance queries where distance to box is min distance, distance
80  // to point is max distance.
82 
83  int x0,y0; // Range of patches in this node
84  int nx,ny;
85 
87 
88  // If no children, leaf contents:
89  OBBLeaf* contents; // non-null only for leaf (NOT USED YET)
90  Vec2 centerUW; // (u,w) parameters of patch center
91  Vec2 dims; // half-u, half-w sizes
92  Geo::BicubicBezierPatch patch; // TODO: no need to keep this around
93 };
94 
95 
96 //==============================================================================
97 // OBB TREE
98 //==============================================================================
101 public:
102  const OBBNode& getRoot() const {return root;}
103  OBBNode& updRoot() {return root;}
104 private:
105  OBBNode root;
106 };
107 
108 
109 
110 } // namespace SimTK
111 
112 #endif // SimTK_SIMMATH_OBB_TREE_H_