VedaLibDemo/MarchinCubeSpace.h

00001 #ifndef COM_M4NKIND_MarchinCubeSpace_H
00002 #define COM_M4NKIND_MarchinCubeSpace_H
00003 
00004 #include "BaseObject.h"
00005 #include "PackLong_WithLimits.h"
00006 /*!
00007     \class  MarchinCubeSpace
00008     \ingroup    BaseObjectInherited_VedaLibDemo
00009     \brief  Define a Space Matrix Grid used by Object3DMarchCube to generate objects
00010             using a marching cube algorythm.
00011 
00012 */
00013 
00014 class MarchinCubeSpace : public BaseObject
00015 {
00016 /*==================================================================
00017                                 PUBLIC
00018 ==================================================================*/
00019 public:
00020     /*!
00021         \brief  Constructor. There should only be members initialisation there.
00022     */
00023     MarchinCubeSpace(void);
00024 
00025     /*!
00026         \brief  Class Inheritance Descriptors. Also forces a destructor. See BASEOBJECT_DECLARE_... in .cpp
00027     */
00028     BASEOBJECT_DEFINE_CLASS(MarchinCubeSpace);
00029 
00030     // note for PPC implementation floats must be 4-aligned.
00031     //! \struct MarchCubeIndex
00032     //! \brief hold the creation of vertex on edges in pass2, and is read in pass3 at polygon creation.
00033     typedef struct { // DONT MODIFY MEMBER ORDER ! DONT ADD VIRTUAL METHODS !!
00034         unsigned short  m_vx;    // vertex index of the one created on branch going X,
00035         unsigned short  m_vy;    // vertex index of the one created on branch Y
00036         unsigned short  m_vz;    // vertex index of the one created on branch Z.
00037     } MarchCubeIndex;
00038     // this must correspond to marchcube struct members offsets:
00039     static const unsigned int ofs_x=0;
00040     static const unsigned int ofs_y=sizeof(unsigned short);
00041     static const unsigned int ofs_z=sizeof(unsigned short)*2;
00042 
00043     // this is an extra value for space vertex set in pass1. can be used a way or another.
00044     // by using a 4 byte union, one alloc can be used a way or another.
00045     typedef unsigned char  tchar4[4];
00046 
00047         //
00048     typedef union {
00049         unsigned int    u_WholeBitField;    // can be used to be set to 0 or 0xffffffff.
00050         tchar4          u_RGBA;     // Color
00051     } MarchCubeExtraValue;
00052 
00053 
00054     /*!
00055         \brief  Access to the cube table:
00056         \return the cube table
00057     */
00058     inline MarchCubeIndex   *GetCubeTable_Index(){ return m_pCubeTable_Index ; };
00059     /*!
00060         \brief  Access to the cube table: inside/outside flag bits.
00061         \return the cube table
00062     */
00063     inline unsigned char    *GetCubeTable_Flags(){ return m_pCubeTable_Flags ; };
00064     /*!
00065         \brief  Access to the cube table: scalar values at corners.
00066         \return the cube table
00067     */
00068     inline float        *GetCubeTable_Values(){ return m_pCubeTable_Values ; };
00069     /*!
00070         \brief  Access to the cube table: Extra values at corners. cf MarchCubeExtraValue.
00071         \return the cube table
00072     */
00073     inline MarchCubeExtraValue *GetCubeTable_ExtraValues(){ return m_pCubeTable_ExtraValue ; };
00074     /*!
00075         \brief  Access to the cube table:  date when the cube was last processed.
00076                 It prevent a "clean pass" on the whole cubespace at the beginning.
00077                 note: each date is in special "pass" values. one pass date in unique to 
00078                 a whole space calculation AND pass.
00079         \return the cube table
00080     */
00081     inline unsigned int     *GetCubeTable_CheckDate(){ return m_pCubeTable_CheckDate ; };
00082 
00083     /*!
00084         \brief  Access to the poly Index Table for this cube dimensions:
00085         \return the cube poly Index Table.
00086     */
00087     inline const unsigned int   *GetPolyIndexTable(){ return m_polyIndexTable ; };
00088     /*!
00089         \brief  Access to the number of SUBDIVISIONS in the X axis. (number of cell is +1)
00090         \return  the total number of SUBDIVISIONS in the X axis
00091     */
00092     inline unsigned int GetLengthX(){ return mSer_LengthX.Get() ; };
00093     /*!
00094         \brief  Access to the number of SUBDIVISIONS in the X axis. (number of cell is +1)
00095         \return  the total number of SUBDIVISIONS in the X axis
00096     */
00097     inline unsigned int GetLengthY(){ return mSer_LengthY.Get() ; };
00098     /*!
00099         \brief  Access to the number of SUBDIVISIONS in the X axis. (number of cell is +1)
00100         \return  the total number of SUBDIVISIONS in the X axis
00101     */
00102     inline unsigned int GetLengthZ(){ return mSer_LengthZ.Get() ; };
00103     /*!
00104         \brief  Get 3 new checkdate number for the 3 passes. Statement: no checkdate on the cube got
00105                 one of these 3 new values.
00106             0->pass1
00107             1->8 pass2, with edgecheck on low bytes.
00108             9->16 pass3,...
00109         \return a new checkdate.
00110     */
00111     inline unsigned int GetNextCheckDate(){ m_CheckDate+=17; return m_CheckDate;  };
00112     
00113 /*==================================================================
00114                                 PROTECTED
00115 ==================================================================*/
00116 protected:
00117 
00118     //! number of cube in the X axis
00119     PackLong_WithLimits     mSer_LengthX;
00120 
00121     //! number of cube in the Y axis
00122     PackLong_WithLimits     mSer_LengthY;
00123 
00124     //! number of cube in the Z axis
00125     PackLong_WithLimits     mSer_LengthZ;
00126 
00127     //!we do one alloc and we align some of the table inside:
00128     unsigned char           *m_pMainTableAlloc;
00129     //! the current checkdate. 0 when object is new.
00130     unsigned int            m_CheckDate;
00131 
00132     //! the vertex created index of the 3 edges:
00133     MarchCubeIndex          *m_pCubeTable_Index;
00134     //! the byte per cube flags:  0 means out, 1 means in.
00135     unsigned char           *m_pCubeTable_Flags;
00136     //! the space scalar values:
00137     float                   *m_pCubeTable_Values;
00138     //! the date of the last frame this cube was processed, for windowing.
00139     unsigned int            *m_pCubeTable_CheckDate;
00140     //! an extra value by space vertex. see union MarchCubeExtraValue.
00141     MarchCubeExtraValue     *m_pCubeTable_ExtraValue;
00142     //! the polygon table for each 256 cube configurations, with good edges offset for this CubeSpace.
00143     unsigned int            *m_polyIndexTable;
00144 
00145     /*!
00146         \brief  Method that really build the object using the serializable parameters.
00147                 Close() should close everything opened by CreateInternal().
00148     */
00149     virtual bool CreateInternal(void);
00150 
00151 #ifdef _ENGINE_EDITABLE_
00152     /*!
00153         \brief  that closes everything. Still, the object exist and can be rebuild the same using Create()
00154     */
00155     virtual void    CloseInternal(void);
00156 #endif
00157 
00158     bool    PreGenerateTriangleTables( void );
00159 
00160 };
00161 
00162 #endif

      /\/\        4         N         k         !         N         D
                      _______  _ __ ___  _____            ___ _ _  ____
     ___________  __//___   /________  |/    / ___________\_______/    \
    /   _   _   \/   _     /    _   /      _/_/____/    _       __     /
   /    /   /       /     /    /    \      \/     /    /    \   \     /
  \\___/___/___/    ¯    _____/_____/       ______\___/_____/\________\\
               \________/_ ___ __ l____\      /elD!  
                 http://www.m4nkind.com \____/