arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Volytope.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     9-20-02
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2002 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 //Volytope.h
00019 
00020 // Container class for a convex polytope, which is the basic
00021 //  primitive for volume rendering
00022 
00023 #ifndef __VOLYTOPE_DOT_H
00024 #define __VOLYTOPE_DOT_H
00025 
00026 #include <mathGutz.h>
00027 #include <arrayGutz.h>
00028 #include <list>
00029 #include <vector>
00030 #include <textureGlift.h>
00031 #include <smartptr.h>
00032 #include <volume/VolField.h>
00033 #include <simBase/simBase.h>
00034 
00035 
00036 
00037 ////////////////////////////////////////////////////////////////////////////////
00038 /// Volytope
00039 ////////////////////////////////////////////////////////////////////////////////
00040 
00041 class Volytope : 
00042    public gutz::Counted, 
00043    public SimBase 
00044 {
00045 public:
00046    /////////////////////////////////////////
00047    /// this is to make this flexible, but
00048    /// not a template: change these to change whole class
00049    typedef gutz::vec3f      V_TYPE;   /// Vertex type
00050    typedef gutz::vec3f      TC_TYPE;  /// Texture Coordinate type
00051    typedef glift::SingleTex TX_TYPE;  /// Texture type
00052    typedef gutz::vec2i      E_TYPE;   /// Edge type
00053    /////////////////////////////////////////
00054 
00055    Volytope(unsigned int nElements = 5000, 
00056       unsigned int nTcoords = 1,
00057       unsigned int nPrims = 1000);
00058 
00059    virtual ~Volytope();
00060 
00061    Volytope(const Volytope &v) { Volytope::operator =(v); }
00062    void operator=(const Volytope &v);
00063 
00064    ////////////////////////////////////////////////////////////////////
00065    /// set some data, load a field into the volytope
00066    virtual void loadField(VolFieldSP f, unsigned int brickNum=0) = 0;
00067 
00068    /////////////////////////////////////////////
00069    typedef gutz::arrayWrap1<V_TYPE>  VA_RTYPE; // return type for verts array
00070    typedef gutz::arrayOwn1<V_TYPE>   VA_ITYPE; // internal vertex array type
00071    typedef gutz::arrayWrap1<TC_TYPE> TA_RTYPE; // return type for TCoord array
00072    typedef gutz::arrayOwn1<TC_TYPE>  TA_ITYPE; // internal TCoord array type
00073    typedef gutz::arrayWrap1<E_TYPE>  EA_RTYPE; // return type for edge array 
00074    typedef gutz::arrayOwn1<E_TYPE>   EA_ITYPE; // internal edge array type
00075    /////////////////////////////////////////////
00076 
00077    virtual void setData(VA_RTYPE   *verts,
00078       TA_RTYPE   *tcoords,
00079       EA_RTYPE   *edges);
00080 
00081 
00082    /// Generate Verts
00083    virtual VA_RTYPE  genVerts(int nVerts);
00084    /// get verts
00085    const VA_RTYPE    getVerts() const   {return VA_RTYPE(*_verts);} 
00086    VA_RTYPE          getVerts()         {return VA_RTYPE(*_verts);}
00087 
00088 
00089    /// number of texture coordinates must match the
00090    /// number of verticies, thus "tNum" is the
00091    /// texture number, not the number of coordinates
00092    virtual TA_RTYPE  genTcoords(int tNum = 0);       
00093    /// get tcoords
00094    const TA_RTYPE    getTcoords(unsigned int tNum = 0) const; 
00095    TA_RTYPE          getTcoords(unsigned int tNum = 0);       
00096 
00097    /// Generate edges
00098    virtual EA_RTYPE  genEdges(int nEdges);      
00099    /// get edges
00100    const EA_RTYPE    getEdges() const   {return EA_RTYPE(*_edges);}
00101    EA_RTYPE          getEdges()         {return EA_RTYPE(*_edges);}
00102 
00103    ////////////////////////////////////////////////////////////////////
00104    /// texture info
00105    int                               numTextures()      {return _textures.size();}
00106    std::vector< gutz::SmartPtr<TX_TYPE> >  getTextures()      {return _textures;}
00107    gutz::SmartPtr<TX_TYPE>                 getTexture(int i)  {if(_textures[i]) return _textures[i]; return 0;}
00108    gutz::SmartPtr<TX_TYPE>                 removeTexture(int i);
00109    void                              clearTextures();
00110    void                              addTexture(glift::SingleTex *tex);
00111 
00112    ////////////////////////////////////////////////////////////////////
00113    /// get the volume matrix
00114    gutz::mat4f     getMatrix() const        {return _xform;}
00115    void            setMatrix(gutz::mat4f m) {_xform = m;}
00116 
00117    ////////////////////////////////////////////////////////////////////
00118    /// bounding box
00119    /// update bounding box and center
00120    virtual void        setSizes();
00121    virtual gutz::vec3f getBoxMax() const {return _max;}
00122    virtual gutz::vec3f getBoxMin() const {return _min;}
00123    gutz::vec3f         getCenter() const {return _center;}
00124 
00125    ////////////////////////////////////////////////////////////////////
00126    /// Transformations 
00127    virtual void scale(gutz::vec3f scale);
00128    virtual void translate(gutz::vec3f trans);
00129 
00130    ////////////////////////////////////////////////////////////////////
00131    /// sorting utilities
00132    /// sets the PointDist to the distance from the point to the 
00133    /// nearest vertex of the volytope.  getPointDist() is designed to
00134    /// be a very fast call for sorting purposes
00135    void  setPointDist(gutz::vec3f pt);
00136    float getPointDist() const { return _dist; }
00137 
00138 protected:
00139    Volytope(std::string name):SimBase(),_edges(0),_verts(0){}
00140 
00141    /// save volytope information into a nrro object
00142    virtual void writeState(NrroSP n) {derr("writeState(), function not implemented");}
00143    virtual void readState(NrroSP n)  {derr("readState(), function not implemented");}
00144 
00145    EA_ITYPE *_edges;
00146    VA_ITYPE *_verts;
00147    std::vector<TA_ITYPE*> _tcoords;
00148 
00149    std::vector< gutz::SmartPtr<TX_TYPE> > _textures;
00150 
00151    gutz::mat4f                    _xform;
00152    gutz::vec3f                    _center;
00153    gutz::vec3f                    _min;
00154    gutz::vec3f                    _max;
00155    float                          _dist;
00156 };
00157 
00158 typedef gutz::SmartPtr<Volytope> VolytopeSP;
00159 
00160 ////////////////////////////////////////////////////////////////////////////////
00161 ////////////////////////////////////////////////////////////////////////////////
00162 ////////////////////////////////////////////////////////////////////////////////
00163 ////////////////////////////////////////////////////////////////////////////////
00164 /// VolytopeVec
00165 ////////////////////////////////////////////////////////////////////////////////
00166 ////////////////////////////////////////////////////////////////////////////////
00167 ////////////////////////////////////////////////////////////////////////////////
00168 ////////////////////////////////////////////////////////////////////////////////
00169 
00170 class VolytopeVec : 
00171    public std::vector<VolytopeSP>, //< is a Vector
00172    public SimBase
00173 {
00174 public:
00175    VolytopeVec():SimBase(),_scale(1.0f,1.0f,1.0f) {}
00176    virtual ~VolytopeVec(){}
00177    /// using default copy and assignment operators
00178 
00179    ///////////////////////////////////////////////////
00180    ///@name Volytope management
00181    ///@{
00182    void          setVoly(VolytopeSP v, int i=0) {operator[](i) = v; }
00183    VolytopeSP    getVoly(int i=0) const         {return operator[](i);}
00184    void          addVoly(VolytopeSP &v)         {push_back(v);}
00185    ///@}
00186 
00187    ///////////////////////////////////////////////////
00188    ///@name Fields
00189    ///@{
00190    void          setField(VolFieldSP f);
00191    ///@}
00192 
00193    ///////////////////////////////////////////////////
00194    ///@name bounding boxes and sizes
00195    ///@{
00196    gutz::vec3f   getBoxMax() const;
00197    gutz::vec3f   getBoxMin() const;
00198    gutz::vec3f   getSize()             {return getBoxMax() - getBoxMin();}
00199    /// sets the maximum dimension to "size"
00200    void          setSize(float size);
00201    /// the scaling that returns the volytopes to their orginal size
00202    /// if you resized the volytopes this is the scale vector that undoes it.
00203    gutz::vec3f   getScale() const { return _scale; }
00204    ///@}
00205 
00206    ////////////////////////////////////////////////////
00207    ///@name transformations
00208    ///@{
00209    void          scale(gutz::vec3f scl);
00210    void          translate(gutz::vec3f trans);
00211    ///@}
00212 
00213    /// center the volytopes around their center of mass
00214    void          center();
00215 
00216    ////////////////////////////////////////////////////
00217    /// Sorting
00218    /// distance from a point, this only works if your
00219    /// volytopes are uniformly subdivided cubes
00220    VolytopeVec sortFromPoint(gutz::vec3f pt);
00221 
00222    ////////////////////////////////////////////////////
00223    /// get the center of all volytopes in this collection
00224    gutz::vec3f getCenter() const
00225    {
00226       gutz::vec3f min = getBoxMin();
00227       return min + (getBoxMax() - getBoxMin())/2.0f;
00228    }
00229 
00230 protected:
00231 
00232    gutz::vec3f _scale;
00233 };
00234 
00235 typedef VolytopeVec::iterator VolytopeVecIter;
00236 typedef VolytopeVec::reverse_iterator VolytopeVecRIter;
00237 
00238 #endif
00239 

Send questions, comments, and bug reports to:
jmk