Simbody  3.4 (development)
OBBTree.h
Go to the documentation of this file.
00001 #ifndef SimTK_SIMMATH_OBB_TREE_H_
00002 #define SimTK_SIMMATH_OBB_TREE_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                        Simbody(tm): SimTKmath                              *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK biosimulation toolkit originating from           *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody.  *
00011  *                                                                            *
00012  * Portions copyright (c) 2011-12 Stanford University and the Authors.        *
00013  * Authors: Michael Sherman                                                   *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Licensed under the Apache License, Version 2.0 (the "License"); you may    *
00017  * not use this file except in compliance with the License. You may obtain a  *
00018  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0.         *
00019  *                                                                            *
00020  * Unless required by applicable law or agreed to in writing, software        *
00021  * distributed under the License is distributed on an "AS IS" BASIS,          *
00022  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
00023  * See the License for the specific language governing permissions and        *
00024  * limitations under the License.                                             *
00025  * -------------------------------------------------------------------------- */
00026 
00030 #include "SimTKcommon.h"
00031 #include "simmath/internal/common.h"
00032 #include "simmath/internal/Geo.h"
00033 #include "simmath/internal/Geo_Box.h"
00034 #include "simmath/internal/Geo_BicubicBezierPatch.h"
00035 
00036 #include <cassert>
00037 
00038 namespace SimTK {
00039 
00040 //==============================================================================
00041 //                               OBB LEAF
00042 //==============================================================================
00044 class OBBLeaf {
00045 public:
00046     virtual ~OBBLeaf() {}
00047 };
00048 
00049 //==============================================================================
00050 //                               OBB NODE
00051 //==============================================================================
00053 class SimTK_SIMMATH_EXPORT OBBNode {
00054 public:
00055     OBBNode() : contents(0) {clear();}
00056     ~OBBNode() {clear();}
00057 
00058     void clear() {
00059         delete contents; contents=0;
00060         x0=y0=nx=ny=-1;
00061         children.clear();
00062     }
00063 
00064     bool isLeaf() const {return children.empty();}
00065     int getNumChildren() const {return (int)children.size();}
00066     const OBBNode& getChild(int i) const {return children[i];}
00067     OBBNode& updChild(int i) {return children[i];}
00068 
00069     // A box enclosing the contents.
00070     Geo::OrientedBox    box;
00071     int                 depth;  // 0 is root
00072     int                 height; // a leaf is 0, node is max of children+1
00073 
00074     // A cone enclosing the entire range of normals.
00075     UnitVec3            normal; // central normal
00076     Real                coneHalfAngle;  // 0<=a<=pi, pi/2 makes a halfspace
00077 
00078     // An arbitrary point on the contained surface, used in 
00079     // distance queries where distance to box is min distance, distance
00080     // to point is max distance.
00081     Vec3                pointOnSurface;
00082 
00083     int                 x0,y0; // Range of patches in this node
00084     int                 nx,ny;
00085 
00086     Array_<OBBNode>     children;
00087 
00088     // If no children, leaf contents:
00089     OBBLeaf*            contents; // non-null only for leaf (NOT USED YET)
00090     Vec2                centerUW; // (u,w) parameters of patch center
00091     Vec2                dims;     // half-u, half-w sizes
00092     Geo::BicubicBezierPatch patch; // TODO: no need to keep this around
00093 };
00094 
00095 
00096 //==============================================================================
00097 //                               OBB TREE
00098 //==============================================================================
00100 class SimTK_SIMMATH_EXPORT OBBTree {
00101 public:
00102     const OBBNode& getRoot() const {return root;}
00103     OBBNode& updRoot() {return root;}
00104 private:
00105     OBBNode root;
00106 };
00107 
00108 
00109 
00110 } // namespace SimTK
00111 
00112 #endif // SimTK_SIMMATH_OBB_TREE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines