Biomechanical Joint Model
 Author: Anderson Maciel

blob.h

Go to the documentation of this file.
00001 #ifndef MC_BLOBBY_H
00002 #define MC_BLOBBY_H
00003 
00004 #include <LinAlg/linalg.h>
00005 #include <RayCasting/bbox.h>
00006 #include "private_marching_cubes.h"
00007 #include "primitive.h"
00008 #include <vector>
00009 #include <algorithm>
00010 
00011 //namespace MarchingCubes {
00012 
00013 //using namespace RayCasting;
00014 //using namespace std;
00015 
00016 class Quadric
00017 {
00018 public:   
00019    Quadric(HMAT M_, REAL a_=1, REAL b_=1, REAL c_=1) : a(a_), b(b_), c(c_), M(M_), T(inverse(M_)) 
00020    { init(); /*cout << "a,b,c = " << a << " "<< b << " "<< c << "\nT = " << T << endl;*/ };
00021    Quadric(const Quadric &q) : a(q.a), b(q.b), c(q.c), M(q.M), T(q.T) { init(); };
00022 
00023    virtual bool intersectedBy(Ray &ray, REAL root[]) const;
00024 
00025 protected:   
00026    void init() { a2 = a*a; b2 = b*b; c2 = c*c; };
00027 
00028 public:
00029    REAL a,b,c;    // semi-axis lengths
00030    REAL a2,b2,c2; // square of the coeffcients a,b,c
00031    HMAT T;        // homogeneous matrix from g.c.s. to l.c.s.
00032    HMAT M;        // homogeneous matrix from l.c.s to g.c.s. (i.e matrix of lcs expressed in gcs)
00033 };
00034 
00035 class Blob : public Quadric
00036 {
00037 public:
00038    // constructors
00039    Blob(HMAT M_, REAL a_=1, REAL b_=1, REAL c_=1, REAL w_=1) : Quadric(M_,a_,b_,c_), w(w_) {};
00040    virtual bool intersectedBy(Ray &ray, REAL root[]) const;
00041 
00042    REAL w;        // weight
00043 };
00044 
00045 class Sphere{
00046 public:
00047    Sphere(const VEC &centre, REAL thick=1, REAL stiff=1) :
00048       C(centre), ro(thick), k(stiff) { R = ro + (2.0/k); };
00049    Sphere(int FctId, const VEC &centre, REAL thick, REAL stiff)
00050        { C=centre; ro=thick; k=stiff; FId=FctId; R = ro + (2.0/k);};
00051    Sphere(const Sphere &s) : C(s.C), ro(s.ro), k(s.k), R(s.R), FId(s.FId) {};
00052    //  virtual bool intersectedBy(RayCasting::Ray &ray, REAL root[]) const;
00053    
00054 public:          
00055    // definition de la sphere:  
00056    VEC  C;       // center
00057    REAL ro;      // thickness
00058    REAL R;       // scope of influence
00059    REAL k;       // stiffness
00060 
00061    // Facet from which sphere has been created
00062    int FId;
00063  
00064 };
00065 
00066 class TrianglePrimitive{
00067  public:
00068   TrianglePrimitive(const VEC &V1, const VEC &V2, const VEC &V3, double *norm, REAL thick=1.0, REAL stiff=1.0)
00069     :P1(V1), P2(V2), P3(V3), n(norm), ro(thick), k(stiff) { R = ro + (2.0/k); };
00070   TrianglePrimitive(int FctId, const VEC &V1, const VEC &V2, const VEC &V3, double *norm, REAL thick, REAL stiff)
00071        { P1=V1; P2=V2; P3=V3; n=norm; ro=thick; k=stiff; FId=FctId; R = ro + (2.0/k);};
00072   TrianglePrimitive(const TrianglePrimitive &s) : P1(s.P1), P2(s.P2), P3(s.P3), n(s.n), ro(s.ro), k(s.k), R(s.R), FId(s.FId) {};
00073 
00074  public:
00075   VEC P1, P2, P3;  // triangle vertices
00076   double *n;       // triangle normal
00077   REAL ro;         // thickness
00078   REAL k;          // stiffness
00079   REAL R;          // scope of influence
00080   int FId;         // Facet from which sphere has been created
00081 };
00082 
00083 
00084 class Ellipsoids : public Primitive
00085 {
00086 public:
00087    Ellipsoids() : Primitive(), quadlist() {};
00088    void addQuadric(const Quadric &quad) { quadlist.push_back(quad); };
00089 
00090    virtual bool intersectedBy(Ray &ray) const;
00091    virtual REAL getDistance(const VEC &X) const;
00092    virtual BBox getBoundingBox();
00093    virtual void findIntersection(const VEC &P1, const VEC &P2, REAL valp1, REAL valp2, 
00094                                  VEC &P, VEC &N) const;
00095 protected:
00096    vector<Quadric> quadlist;
00097 };
00098 
00099 class Metaballs : public ImplicitPrimitive
00100 {
00101 public:
00102    Metaballs(REAL isolevel=0.5) : ImplicitPrimitive(isolevel), bloblist() {};
00103    void addBlob(const Blob &blob) { bloblist.push_back(blob); };
00104     
00105    virtual BBox getBoundingBox();
00106 
00107 protected:
00108     vector<Blob> bloblist;
00109 };
00110 
00111 // Metaballs represented as the spheres with Raquel's density function
00112 class MetaballsSphere : public ImplicitPrimitive{
00113  public:
00114   MetaballsSphere(REAL isolevel=1.0):ImplicitPrimitive(isolevel){};
00115   void addSphere(const Sphere &sph) { spherelist.push_back(sph); };
00116   
00117   virtual BBox getBoundingBox();
00118   vector<Sphere> spherelist;
00119  protected:
00120   virtual REAL   density(const VEC& U) const;
00121   virtual VEC    gradient(const VEC& U) const;
00122 };
00123 
00124 // Metaballs represented as the spheres with exponential density function
00125 class MetaballsSphere_exp : public MetaballsSphere{
00126 
00127  public:
00128   MetaballsSphere_exp(REAL isolevel=0.5,  REAL dist_coeff = 2):MetaballsSphere(isolevel),coeff(dist_coeff){};
00129 
00130  protected:
00131   virtual REAL  density(const VEC& U) const;
00132   virtual VEC   gradient(const VEC& U) const;
00133 
00134  private:
00135   REAL coeff;  
00136 };
00137 
00138 // Genralized metaballs built on the triagle as the geometric primitive with Raquel's density function
00139 class MetaballsTriangle : public ImplicitPrimitive{
00140  public:
00141   MetaballsTriangle(REAL isolevel=1.0):ImplicitPrimitive(isolevel){};
00142   void addTriangle(const TrianglePrimitive &trg) { trianglelist.push_back(trg); };
00143   
00144   virtual BBox getBoundingBox();
00145   vector<TrianglePrimitive> trianglelist;
00146   // protected:
00147   double  EuclidDistFromTriangle(const VEC &P1, const VEC &P2, const VEC &P3, const VEC &Pt, const double *Plane, VEC &N) const;
00148   virtual REAL   density(const VEC& U) const;
00149   virtual VEC    gradient(const VEC& U) const;
00150 };
00151 
00152 
00153 // Metaballs with Shen's density function
00154 class Metaballs_Shen : public Metaballs
00155 {
00156 public:
00157    Metaballs_Shen(REAL isolevel=0.5) : Metaballs(isolevel) {};   
00158    virtual bool intersectedBy(Ray &ray) const;
00159 
00160 protected:   
00161    virtual REAL  density(const VEC& U) const;
00162    virtual VEC   gradient(const VEC& U) const;
00163 };
00164 
00165 // metaballs with an exponential(-dist_coeff * distance^2) density function
00166 class Metaballs_exp : public Metaballs
00167 {
00168 public:
00169    Metaballs_exp(REAL isolevel=0.5, REAL dist_coeff = 2) : coeff(dist_coeff), 
00170       Metaballs(isolevel) {};
00171 
00172 protected:   
00173    virtual REAL  density(const VEC& U) const;
00174    virtual VEC   gradient(const VEC& U) const;
00175 
00176 private:
00177    REAL coeff;
00178 };
00179 
00180 //}
00181 
00182 #endif

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