Biomechanical Joint Model
 Author: Anderson Maciel

bbox.h

Go to the documentation of this file.
00001 /*@#---------------------------------------------------------------------------
00002  PROJECT            : PHD THESIS
00003  MODULE             : PHYSICALLY-BASED DEFORMATION
00004 
00005  FILE               : bbox.h
00006  CREATION DATE      : Thu Dec  2 13:49:39 MET 1999
00007  CREATION AUTHOR(S) : aubel 
00008  ------------------------------------------------------------------------------
00009  KEYWORD(S)         : bounding box
00010  DEFINED TYPE(S)    : 
00011  RELATED TYPE(S)    : 
00012 
00013  FUNCTIONALITY      : Bounding Box class to avoid relying on Inventor's bboxes
00014  ------------------------------------------------------------------------------
00015  LANGAGE            : Ansi C++
00016  SYSTEM             : UNIX V 6.x / SGI
00017  GRAPHIC LIBRARY    : SGI  
00018  ------------------------------------------------------------------------------
00019  PROJECT DIRECTOR   : D. THALMANN
00020  LAB                : EPFL- LIG
00021  --------------------------------------------------------------------------#@*/
00022 #ifndef BBOX_H
00023 #define BBOX_H
00024 
00025 #include <LinAlg/linalg.h>
00026 #include "ray.h"
00027 #include <vector>
00028 
00029 //using namespace std;
00030 
00031 // a bounding box class that works both in 2D and in 3D (default=3D, see ctor)
00032 class BBox 
00033 {
00034 public:
00035    BBox(int ndim = dimspace) : n_(ndim), LL(ndim), UR(ndim) , empty(true) { assert(n_<4); };
00036    BBox(const BBox &bb) : LL(bb.LL), UR(bb.UR), n_(bb.n_), empty(bb.empty) { assert(n_<4);};
00037 
00038    BBox(const VEC &LowerLeft, const VEC &UpperRight): LL(LowerLeft), UR(UpperRight), 
00039       n_(LowerLeft.dim()), empty( VEC(UR-LL).norm2() < epsilon ) {};
00040 
00041    void extendBy(const VEC &X);
00042    void extendBy(const VECArray &X) { for (int i=0; i<X.size(); i++) extendBy(X[i]); };
00043    void extendBy(const BBox &bb);
00044 
00045    VEC getMin() const { return LL; };
00046    VEC getMax() const { return UR; };
00047    VEC getDim() const { return (UR - LL); };
00048    VEC getCenter() const { return 0.5*(LL+UR); };
00049 
00050    void makeEmpty() { empty=true; };
00051    bool isEmpty() const { return empty; };
00052 
00053    void scale(REAL factor);
00054    bool contains(const VEC &X) const { return (X >= LL && X <= UR); };
00055    bool strictlyContains(const VEC &X) const { return (X > LL && X < UR); };
00056 
00057    bool intersectedBy(const BBox &bb) const;
00058    bool intersectedBy(Ray &ray) const;
00059    bool intersectedBy(const VEC &V0, const VEC &V1, const VEC &V2) const;
00060 
00061 private:
00062    VEC LL, UR;
00063    int n_;
00064    bool empty;
00065 };
00066 
00067 class BBoxHierarchy
00068 {   
00069 public:
00070    BBoxHierarchy(const BBox &bbox, int recursion_level=0) : 
00071       bb(bbox), bboxlist(), triangles(), level(recursion_level) {};
00072 
00073    BBoxHierarchy(const VEC &LL, const VEC &UR, int recursion_level=0) : 
00074       bb(LL, UR), bboxlist(), triangles(), level(recursion_level) {};
00075 
00076    BBoxHierarchy(const BBoxHierarchy &bb_h) : 
00077       bb(bb_h.bb), bboxlist(bb_h.bboxlist), triangles(bb_h.triangles), level(bb_h.level) {};
00078 
00079    ~BBoxHierarchy();
00080 
00081    // tris = list of triangles (ONLY!) with no separator between 2 consecutive triangles
00082    void createHierarchy(const VECArray &coords, const vector<int> &tris, int num_tris_max,
00083                         int level=0);
00084 
00085    // return list (without duplicates) of triangles that might be hit by ray
00086    // trilist = indices (premultiplied by 3 = # vertices) into the triangles list 
00087    void getPotentialTriangles(Ray &ray, vector<int> &trilist) const;
00088 
00089    // read-only
00090    const BBox& getBBox() const { return bb; };
00091    int getNumTriangles() const { return triangles.size(); };
00092    const vector<int> &getTriangles() const { return triangles; };
00093 
00094    // return lowest-level  bounding box that contains X and at least m triangles
00095    // return NULL if it doesn't exist
00096    const BBoxHierarchy* getSmallestBBox(const VEC &X, int m=1) const; 
00097 private:
00098    BBox bb;
00099    vector<BBoxHierarchy*> bboxlist;
00100    vector<int> triangles;  // list of indices of triangles
00101    int level;
00102 };
00103 
00104 #endif
00105 
00106 

Generated on Thu Dec 1 10:13:32 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5