Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

simplex_frame.H

Go to the documentation of this file.
00001 /*****************************************************************
00002  * simplex_frame.H
00003  *****************************************************************/
00004 #ifndef SIMPLEX_FRAME_H_IS_INCLUDED
00005 #define SIMPLEX_FRAME_H_IS_INCLUDED
00006 
00007 #include "map3d/coord_frame.H"
00008 #include "bvert.H"
00009 
00010 /*****************************************************************
00011  * SimplexFrame:
00012  *
00013  *
00014  *   A CoordFrame associated with a Bsimplex. Origin is
00015  *   associated with the simplex (e.g. the position of a
00016  *   vertex, or midpoint of an edge), and vectors t and n
00017  *   are provided.
00018  *
00019  *****************************************************************/
00020 class SimplexFrame : public SimplexData, public CoordFrame {
00021  public:
00022 
00023    //******** MANAGERS ********
00024 
00025    SimplexFrame(uint key, Bsimplex* s, CWvec& t, mlib::CWvec& n) :
00026       SimplexData(key, s),
00027       _dirty(1) { set_(t,n); }
00028 
00029    //******** RUN-TIME TYPE ID ********
00030 
00031    DEFINE_RTTI_METHODS3("SimplexFrame", SimplexFrame*, SimplexData, CSimplexData*);
00032 
00033    //******** VIRTUAL METHODS ********
00034 
00035    // public method for setting the vectors:
00036    virtual void set(CWvec& t, mlib::CWvec& n) {
00037       set_(t,n);        // call internal set() method
00038       changed();        // then notify observers
00039    }
00040    virtual void apply_xform(CWtransf& xf) {
00041       // Transform t and n but not o, which is tied to the vertex.
00042       set_(xf*_t, xf*_n);
00043       changed(); // in any case observers can be told
00044    }
00045 
00046    //******** CoordFrame VIRTUAL METHODS ********
00047 
00048    // Subclasses must implement virtual Wpt o();
00049 
00050    virtual Wvec      t() { update(); return _t; }
00051    virtual Wvec      n() { update(); return _n; }
00052    virtual Wtransf  xf() { update(); return _xf; }
00053    virtual Wtransf inv() { update(); return _inverse; }
00054 
00055    virtual void changed() {
00056       _dirty = true;
00057       CoordFrame::changed();
00058    }
00059 
00060    //******** SimplexData NOTIFICATION METHODS ********
00061 
00062    virtual void notify_simplex_changed()                { changed(); }
00063    virtual void notify_simplex_xformed(CWtransf& /* xf */) {
00064       // XXX - what to do really?
00065       // apply_xform(xf);
00066    }
00067    virtual void notify_simplex_deleted() {
00068       _observers.notify_frame_deleted(this); 
00069       SimplexData::notify_simplex_deleted(); // deletes this
00070    }
00071 
00072    // Prevents warnings:
00073    void set(uint id, Bsimplex* s)       { SimplexData::set(id, s); }
00074    void set(Cstr_ptr& str, Bsimplex* s) { SimplexData::set(str, s); }
00075 
00076  //*******************************************************
00077  // PROTECTED
00078  //*******************************************************
00079  protected:
00080    Wvec                 _t;             // "tangent" direction
00081    Wvec                 _n;             // "normal" direction
00082    Wtransf              _xf;            // mapping from local to world
00083    Wtransf              _inverse;       // mapping from world to local
00084    bool                 _dirty;         // needs to be recomputed
00085 
00086    //******** INTERNAL METHODS ********
00087 
00088    // internal set() method not for public use:
00089    void set_(CWvec& t, mlib::CWvec& n) {
00090       // enforce policy that vectors must be orthonormal.
00091       // if caller passes in zero-length or parallel vectors
00092       // the frame will be degenerate.
00093       _t = t.normalized();       // preference to t
00094       _n = n.orthogonalized(_t).normalized();
00095    }
00096 
00097    virtual void recompute() {
00098       // subclasses may do more...
00099       // but whatever they do, they should
00100       // clear the _dirty flag
00101       _dirty   = 0; // need this before calling next line...
00102       _xf      = Wtransf(o(), t(), b(), n());
00103       _inverse = _xf.inverse();      // 'true' means it is rigid motion
00104    }
00105 
00106    void update() const {
00107       if (_dirty)
00108          ((SimplexFrame*)this)->recompute();
00109    }
00110 };
00111 typedef const SimplexFrame CSimplexFrame;
00112 
00113 #endif // SIMPLEX_FRAME_H_IS_INCLUDED
00114 
00115 // end of file simplex_frame.H

Generated on Mon Sep 18 11:39:33 2006 for jot by  doxygen 1.4.4