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

simplex_data.H

Go to the documentation of this file.
00001 /*****************************************************************
00002  * simplex_data.H
00003  *****************************************************************/
00004 #ifndef SIMPLEX_DATA_H_IS_INCLUDED
00005 #define SIMPLEX_DATA_H_IS_INCLUDED
00006 
00007 #include "net/rtti.H"
00008 #include "mlib/points.H"
00009 
00010 using namespace mlib;
00011 
00012 typedef unsigned int   uint;
00013 typedef unsigned short ushort;
00014 typedef unsigned char  uchar;
00015 
00016 class Bsimplex;
00017 /*****************************************************************
00018  * SimplexData:
00019  *
00020  *      Base class for data attached to a Bsimplex; a Bsimplex is a
00021  *      mesh element such as a vertex, edge, or face.
00022  *****************************************************************/
00023 class SimplexData;
00024 typedef const SimplexData CSimplexData;
00025 class SimplexData {
00026  public:
00027    //******** MANAGERS ********
00028 
00029    // Store the data on the simplex with a given "owner ID":
00030    void set(uint id, Bsimplex* s);
00031    void set(Cstr_ptr& str, Bsimplex* s) { set((uint)**str, s); }
00032 
00033    SimplexData(uint key, Bsimplex* s)     : _id(0), _simplex(0) { set(key, s);}
00034    SimplexData(Cstr_ptr& str, Bsimplex* s): _id(0), _simplex(0) { set(str, s);}
00035   
00036    virtual ~SimplexData();
00037 
00038    //******** RUN-TIME TYPE ID ********
00039    DEFINE_RTTI_METHODS_BASE("SimplexData", CSimplexData*);
00040 
00041    //******** ACCESSORS ********
00042    uint       id()                      const   { return _id; }
00043    Bsimplex*  simplex()                 const   { return _simplex; }
00044 
00045    //******** VIRTUAL METHODS ********
00046 
00047    // Notification that the simplex changed, meaning:
00048    //
00049    //   For a vertex: It moved.
00050    //
00051    //   For an edge or face:
00052    //      Its shape changed. I.e. one of its vertices moved.
00053    //
00054    virtual void notify_simplex_changed()  {}
00055 
00056    // Notification that the normal of the simplex changed, meaning:
00057    //
00058    //   For a face: One of its vertices moved.
00059    //
00060    //   For an edge or vertex:
00061    //      An adjacent face changed shape, or was added or removed.
00062    //
00063    virtual void notify_normal_changed()   {}
00064 
00065    // Notification that simplex was transformed -- i.e. the
00066    // simplex is a vertex and its location was changed by being
00067    // multiplied by the given Wtransf. This notification will
00068    // follow a call to notify_simplex_changed():
00069    virtual void notify_simplex_xformed(CWtransf&) {}
00070 
00071    // Notification that the simplex has been deleted:
00072    virtual void notify_simplex_deleted()  { _simplex = 0; delete this; }
00073 
00074    // Notification that the simplex was split, generating the
00075    // given simplex.  E.g., when an edge is split, it generates a
00076    // new vertex at the middle of the edge; the edge is redefined
00077    // to run from one of the original vertices to the new vertex,
00078    // and a new edge is generated running from the new vertex to
00079    // the other original vertex. So notify split will be called
00080    // twice, once with the new vertex and once with the new edge:
00081    virtual void notify_split(Bsimplex*)   {}
00082 
00083    // Notification that the simplex generated its subdiv elements:
00084    virtual void notify_subdiv_gen() {}
00085 
00086    // Query issued to data on edges and faces:
00087    // Does the data want to handle assigning the subdivision location?
00088    virtual bool handle_subdiv_calc()  { return false; }
00089 
00090  //*****************************************************************
00091  protected:
00092    uint      _id;       // unique ID of the owner of this data
00093    Bsimplex* _simplex;  // the simplex this is attached to.
00094 };
00095 
00096 /*****************************************************************
00097  * SimplexDataList:
00098  *
00099  *      Convenience class -- an array of SimplexData pointers.
00100  *      Can lookup a SimplexData item from its owner's unique ID,
00101  *      or "key."
00102  *****************************************************************/
00103 class SimplexDataList : public ARRAY<SimplexData*> {
00104  public:
00105    //******** MANAGERS ********
00106    SimplexDataList(int n=0) : ARRAY<SimplexData*>(n) {}
00107    ~SimplexDataList();
00108 
00109    //******** LOOKUP ********
00110    SimplexData* get_item(uint key) const {
00111       for (int k=0; k<_num; k++)
00112          if (_array[k]->id() == key)
00113             return _array[k];
00114       return 0;
00115    }
00116 
00117    //******** CONVENIENCE METHODS ********
00118    void notify_split(Bsimplex* new_simp) const {
00119       for (int k=0; k<_num; k++)
00120          _array[k]->notify_split(new_simp);
00121    }
00122    void notify_simplex_changed() const {
00123       for (int k=0; k<_num; k++)
00124          _array[k]->notify_simplex_changed();
00125    }
00126    void notify_normal_changed() const {
00127       for (int k=0; k<_num; k++)
00128          _array[k]->notify_normal_changed();
00129    }
00130    void notify_simplex_xformed(CWtransf& xf) const {
00131       for (int k=0; k<_num; k++)
00132          _array[k]->notify_simplex_xformed(xf);
00133    }
00134    void notify_simplex_deleted() const {
00135       for (int k=0; k<_num; k++)
00136          _array[k]->notify_simplex_deleted();
00137    }
00138    void notify_subdiv_gen() const {
00139       for (int k=0; k<_num; k++)
00140          _array[k]->notify_subdiv_gen();
00141    }
00142    bool  handle_subdiv_calc() {
00143       // They all get a chance...
00144       // return true if one or more take it:
00145       bool ret = false;
00146       for (int k=0; k<_num; k++)
00147          ret = _array[k]->handle_subdiv_calc() || ret;
00148       return ret;
00149    }
00150 };
00151 
00152 #endif // SIMPLEX_DATA_H_IS_INCLUDED
00153 
00154 // end of file simplex_data.H

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