![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsGridGenerator.hpp 00003 ******************************************************************************/ 00020 /****************************************************************************** 00021 SUKITTI PUNAK (07/22/2007) 00022 UPDATE (03/16/2010) 00023 ******************************************************************************/ 00024 #ifndef TAPs_GRID_GENERATOR_HPP 00025 #define TAPs_GRID_GENERATOR_HPP 00026 00027 #include "../Core/TAPsLib.hpp" 00028 #include "../OpenGLModel/TAPsModel.hpp" 00029 #include "../OpenGLModel/TAPsOpenGLModelList.hpp" 00030 00031 #include "../GeometricDataStructure/TAPsTetBarycentricCoordsForVertexRef.hpp" 00032 #include "../GeometricDataStructure/TAPsHexBarycentricCoordsForVertexRef.hpp" 00033 00034 // Grid layout (right-handed coordinates) 00035 // ^ y 00036 // | 00037 // | 00038 // 0-----> x x = column 00039 // / y = row 00040 // / z = depth 00041 // v z 00042 // 00043 // Where X := #columns-1, Y := #rows-1, and Z := #slices-1. 00044 // 00045 // O-------O-------O---------------O-------O 00046 // /| /| /| ... /| /| 00047 // / |(0,Y,0)| / | ... / |(X,Y,0)| 00048 // / | / | / | ... / | / | 00049 // / O---/---O---/---O-----------/---O---/---O 00050 // / | / | / | ... / | / /| 00051 // / | / | / | .../ | / / | 00052 // / |/ |/ | ../ |/ / | 00053 // / /-------/-------O-------/-------/---/---O 00054 // / /| / HIGHEST / POINT /| 00055 // O-------O-------O---------------O-------@ / / | 00056 // | | | ... | . | / / | 00057 // |(0,Y,Z)| | ... |(X,Y,Z)| / / | 00058 // | | | ... | . |/ / | 00059 // O-------O-------O---------------O-------O / | 00060 // | | | ... | . | / | 00061 // | | | ... | . | / | 00062 // | | | ... | . |/ | 00063 // O-------O-------O---------------O-------O | 00064 // | | . . | | 00065 // | O-------O-----.-O-------------|-O-------0 00066 // | /| | . | ... | | /| 00067 // | / |(0,0,0)| . | ... | |(X,0,0)| 00068 // | / | | . | ... | | / | 00069 // | / @-------O-----.-O-------------|-O---/---O 00070 // | LOWEST / POINT / ./ |/ / / 00071 // | / / / . | / / 00072 // | / / / /. /| / / 00073 // | / / / / . / | / / 00074 // |/ / / / . / |/ / 00075 // O-------O-------O---------------O-------O / 00076 // | / | / | / ... | / | / 00077 // |(0,0,Z)| / | / ... |(X,0,Z)| / 00078 // |/ |/ |/ ... |/ |/ 00079 // O-------O-------O---------------O-------O 00080 00081 //============================================================================= 00082 // DEFINES / CHOICES 00083 //============================================================================= 00084 //----------------------------------------------------------------------------- 00085 #define TAPs_GRID_GENERATOR_BY_SOFTWARE 00086 #define TAPs_GRID_GENERATOR_BY_HARDWARE 00087 //----------------------------------------------------------------------------- 00088 //============================================================================= 00089 00090 00091 #define TAPs_GRID_GENERATOR_ADD_BARYCENTRIC 00092 #ifdef TAPs_GRID_GENERATOR_ADD_BARYCENTRIC 00093 #endif//TAPs_GRID_GENERATOR_ADD_BARYCENTRIC 00094 00095 BEGIN_NAMESPACE_TAPs 00096 //============================================================================= 00097 // Forward Declaration 00098 //----------------------------------------------------------------------------- 00099 //----------------------------------------------------------------------------- 00100 //============================================================================= 00101 00102 //============================================================================= 00103 // Class GridGenerator 00104 //----------------------------------------------------------------------------- 00105 template <typename T, typename DATA> 00106 class GridGenerator { 00107 public: 00108 //--------------------------------------------------------------- 00110 GridGenerator ( 00111 OpenGL::Model<T> * pModel = NULL, 00112 bool useSoftware = false, 00113 bool genInversely = false, 00114 bool useDefaultIntpValue = false, 00115 //bool useDefaultIntpValue = true, //!< Use default global interpolation value 00116 T defaultIntpValue = 0.5 00117 ); 00119 ~GridGenerator (); 00120 //--------------------------------------------------------------- 00121 // Operation(s) 00122 bool RegenerateGrids (); 00123 bool GenerateGridsWithDimension ( 00124 T iGridWidth, T iGridHeight, T iGridDepth, 00125 Vector3<T> * lowPoint = NULL, 00126 Vector3<T> * highPoint = NULL 00127 ); 00128 bool GenerateGridsWithSize ( 00129 int iNumOfXSlices, int iNumOfYSlices, int iNumOfZSlices, 00130 Vector3<T> * lowPoint = NULL, 00131 Vector3<T> * highPoint = NULL 00132 ); 00133 00134 //* 00135 // DEBUG for Checking Marching Cubes Tables 00136 bool GenerateDefinedGrids2x2x2 ( 00137 unsigned char config = 1, 00138 int iNumOfXSlices = 2, int iNumOfYSlices = 2, int iNumOfZSlices = 2, 00139 Vector3<T> * lowPoint = NULL, 00140 Vector3<T> * highPoint = NULL 00141 ); // flags of cube's vertices 00142 //*/ 00143 00144 //--------------------------------------------------------------- 00145 // Grid Info Accessor(s) 00146 //inline Vector3<T> GetGridDimension () { return Vector3<T>( m_atGridDimension ) }; 00147 //inline Vector3<T> GetGridSize () { return Vector3<T>( m_atGridSize ) }; 00148 inline T GetGridDimensionX () const { return m_atGridDimension[0]; } 00149 inline T GetGridDimensionY () const { return m_atGridDimension[1]; } 00150 inline T GetGridDimensionZ () const { return m_atGridDimension[2]; } 00151 inline int GetGridSizeX () const { return m_auiGridSize[0]; } 00152 inline int GetGridSizeY () const { return m_auiGridSize[1]; } 00153 inline int GetGridSizeZ () const { return m_auiGridSize[2]; } 00154 inline Vector3<T> GetAABBMinPt () const { return Vector3<T>( m_tAABBMin ); } 00155 inline Vector3<T> GetAABBMaxPt () const { return Vector3<T>( m_tAABBMax ); } 00156 //------------- 00157 //inline void SetGridDimensionX ( T v ) { m_atGridDimension[0] = v; ... } 00158 //inline void SetGridDimensionY ( T v ) { m_atGridDimension[1] = v; ... } 00159 //inline void SetGridDimensionZ ( T v ) { m_atGridDimension[2] = v; ... } 00160 //inline void SetGridSizeX ( T v ) { m_auiGridSize[0] = v; ... } 00161 //inline void SetGridSizeY ( T v ) { m_auiGridSize[1] = v; ... } 00162 //inline void SetGridSizeZ ( T v ) { m_auiGridSize[2] = v; ... } 00163 //--------------------------------------------------------------- 00164 00165 //=============================================================== 00166 // Adjustable Parameters -- User Interaction 00167 //--------------------------------------------------------------- 00168 bool DoesGridGeneratorUseSoftware () const { return m_bUseSoftwareToGenGrid; } 00169 bool DoesGridGeneratorUseHardware () const { return !m_bUseSoftwareToGenGrid; } 00170 void SetGridGeneratorToUseSoftware () { m_bUseSoftwareToGenGrid = true; } 00171 void SetGridGeneratorToUseHardware () { m_bUseSoftwareToGenGrid = false; } 00172 //--------------------------------------------------------------- 00173 bool DoesGridGeneratorGenerateGridInversely () const { return m_bGenGridInversely; } 00174 bool DoesGridGeneratorGenerateGridNormally () const { return !m_bGenGridInversely; } 00175 void SetGridGeneratorToGenerateGridInversely () { m_bGenGridInversely = true; } 00176 void SetGridGeneratorToGenerateGridNormally () { m_bGenGridInversely = false; } 00177 //--------------------------------------------------------------- 00194 bool DoesGridGeneratorUseDefaultIntpVal () const { return m_bUseDefaultIntpVal; } 00195 bool DoesGridGeneratorUseMeshOffsetForIntpVal () const { return !m_bUseDefaultIntpVal; } 00196 void SetGridGeneratorUseDefaultIntpVal () { m_bUseDefaultIntpVal = true; } 00197 void SetGridGeneratorUseMeshOffsetForIntpVal () { m_bUseDefaultIntpVal = false; } 00198 void GetDefaultIntpVal () const { return m_tDefaultIntpVal; } 00199 void SetDefaultIntpVal ( T val ) { m_tDefaultIntpVal = val; } 00200 //--------------------------------------------------------------- 00201 //=============================================================== 00202 00203 //--------------------------------------------------------------- 00204 OpenGL::Model<T> * GetModelUseToGenGrid () const { return m_pModel; } 00205 void SetModelUseToGenGrid ( OpenGL::Model<T> * pModel ) { 00206 if ( m_pModel != pModel ) { 00207 DeleteGrids(); 00208 m_atGridDimension[0] = m_atGridDimension[1] = m_atGridDimension[2] = 0; 00209 m_auiGridSize[0] = m_auiGridSize[1] = m_auiGridSize[2] = 0; 00210 m_pModel = pModel; 00211 } 00212 } 00213 //--------------------------------------------------------------- 00214 void DeleteGrids (); // delete all grid info 00215 //--------------------------------------------------------------- 00216 inline bool IsGridGenerated () { return m_atVertexPosition != NULL; } 00217 //--------------------------------------------------------------- 00218 // For Vertex Flag 00219 static enum VertexFlag { 00220 UNSET = 0, 00221 OUTSIDE_MODEL, 00222 RIGHT_OUTSIDE_BOUNDARY, 00223 ON_BOUNDARY, 00224 RIGHT_INSIDE_BOUNDARY, 00225 INSIDE_MODEL, 00226 DUMMY 00227 }; 00228 //--------------------------------------------------------------- 00229 // Data Accessor(s) 00233 inline T **** const ReturnPtrToVertexPositionData () { return m_atVertexPosition; } 00234 inline T const **** const ReturnPtrToVertexPositionData () const { return m_atVertexPosition; } 00238 inline T **** const ReturnPtrToVertexNormalData () { return m_atVertexNormal; } 00239 inline T const **** const ReturnPtrToVertexNormalData () const { return m_atVertexNormal; } 00243 inline VertexFlag *** const ReturnPtrToVertexFlagData () { return m_abVertexFlag1; } 00244 inline VertexFlag const *** const ReturnPtrToVertexFlagData () const { return m_abVertexFlag1; } 00248 inline T **** const ReturnPtrToVertexInterpolationData () { return m_atVertexInterpolation; } 00249 inline T const **** const ReturnPtrToVertexInterpolationData () const { return m_atVertexInterpolation; } 00250 #ifdef TAPs_GRID_WITH_TWO_INTERPOLATIONS 00251 inline T **** const ReturnPtrToVertexInterpolationDataToo () { return m_atVertexInterpolationToo; } 00252 inline T const **** const ReturnPtrToVertexInterpolationDataToo () const { return m_atVertexInterpolationToo; } 00253 #endif 00254 //--------------------------------------------------------------- 00255 private: 00256 //=============================================================== 00257 // MEMBER FUNCTION(s) 00258 //--------------------------------------------------------------- 00259 void FindBoundingBoxDimension ( Vector3<T> * lowPoint, Vector3<T> * highPoint ); 00260 //----------------------------------------------------- 00261 00262 void GenerateGrids (); 00263 // 00264 void GenerateGridsForPosition (); 00265 void GenerateGridsForNormal (); 00266 void GenerateGridsForFlag1 (); 00267 void GenerateGridsForVertexInterpolation (); 00268 // 00269 void AllocateGridsForPosition (); 00270 void AllocateGridsForNormal (); 00271 void AllocateGridsForFlag1 (); 00272 void AllocateGridsForVertexInterpolation (); 00273 // 00274 void DeleteGridsForPosition (); 00275 void DeleteGridsForNormal (); 00276 void DeleteGridsForFlag1 (); 00277 void DeleteGridsForVertexInterpolation (); 00278 //----------------------------------------------------- 00279 // Sampling grid point values by Software 00280 #ifdef TAPs_GRID_GENERATOR_BY_SOFTWARE 00281 void SetGridPointsToInsideOutsideModelBoundary_SW (); 00282 void SetGridPointsToInsideOutsideModelBoundary_SW ( OpenGL::PolygonalModel<T> * pPModel ); // NOT IMPLEMENTED YET! 00283 void SetGridPointsToInsideOutsideModelBoundary_SW ( OpenGL::XPolygonalModel<T> * pXPModel ); 00284 void SetGridPointsToInsideOutsideModelBoundary_SW ( OpenGL::HalfEdgeModel<T> * pHEModel ); // NOT IMPLEMENTED YET! 00285 void SetAllGridPointsToInsideOutsideModel_SW (); 00286 #endif 00287 //----------------------------------------------------- 00288 // Sampling grid point values by Hardware (OpenGL) 00289 #ifdef TAPs_GRID_GENERATOR_BY_HARDWARE 00290 void SetAllGridPointsToInsideOutsideModel_HW (); 00291 void SetAllGridPointsToInsideOutsideModel_HW ( OpenGL::PolygonalModel<T> * pPModel ); // NOT IMPLEMENTED YET! 00292 void SetAllGridPointsToInsideOutsideModel_HW ( OpenGL::XPolygonalModel<T> * pXPModel ); 00293 void SetAllGridPointsToInsideOutsideModel_HW ( OpenGL::HalfEdgeModel<T> * pHEModel ); // NOT IMPLEMENTED YET! 00294 #endif 00295 00296 public: 00297 //=============================================================== 00298 // DEBUG BY DRAWING 00299 // Check SetGridPointsToInsideOutsideModelBoundary_SW ( OpenGL::XPolygonalModel<T> * pXPModel ) 00300 void DRAW_SetGridPointsToInsideOutsideModelBoundary_SW ( OpenGL::XPolygonalModel<T> * pXPModel ); 00301 //=============================================================== 00302 private: 00303 00304 //----------------------------------------------------- 00305 // Clear extra right outside points from the generated grid data 00306 void ClearExtraRightOutsidePoints (); 00307 //----------------------------------------------------- 00308 // Inverse Points -- Outside <--> Inside & Empty becomes Inside 00309 void InverseInsideOutside (); 00310 //----------------------------------------------------- 00311 // This one makes the grid generator uses the passed default value 00312 // for the global interpolation value. 00313 void SetVertexInterpolationData ( T tDefaultVal ); 00314 // 00315 // This one makes the grid generator uses either the (already set) 00316 // default value or uses randomly generated values for interpolation 00317 // values. 00318 void SetVertexInterpolationData (); 00319 void SetVertexInterpolationData ( OpenGL::PolygonalModel<T> * pPModel ); // NOT IMPLEMENTED YET! 00320 void SetVertexInterpolationData ( OpenGL::XPolygonalModel<T> * pXPModel ); 00321 void SetVertexInterpolationData ( OpenGL::HalfEdgeModel<T> * pHEModel ); // NOT IMPLEMENTED YET! 00322 //--------------------------------------------------------------- 00323 //=============================================================== 00324 // DATA MEMBERs 00325 //--------------------------------------------------------------- 00326 T m_tAABBMin[3]; // For Bounding Box 00327 T m_tAABBMax[3]; // For Bounding Box 00328 //------------------------------------------- 00329 00330 //------------------------------------------- 00331 T m_atGridDimension[3]; // width, height, depth of each cell 00332 int m_auiGridSize[3]; // number of cells in x, y, and z 00333 00334 //=============================================================== 00335 // Adjustable Parameters -- User Interaction 00336 //--------------------------------------------------------------- 00337 bool m_bUseSoftwareToGenGrid; // if set use SW, else use HW 00338 bool m_bGenGridInversely; // if set grid points are generated inversely 00339 // e.g. outside pts become inside pts 00340 00341 // Fop Marching Cubes Algorithm 00342 bool m_bUseDefaultIntpVal; // all vertices will have the same default interpolation value 00343 T m_tDefaultIntpVal; // default interpolation value for each vertex 00344 //--------------------------------------------------------------- 00345 //=============================================================== 00346 00347 //--------------------------------------------------------------- 00348 // Unmanaged Pointer(s) 00349 OpenGL::Model<T> * m_pModel; // pointer to a model 00350 //--------------------------------------------------------------- 00351 // Managed Pointer(s) 00352 //T *** tempData; // temp data 00353 //----------------------------------------------------- 00354 // Vertex Attributes 00358 T **** m_atVertexPosition; // vertex position 00359 T **** m_atVertexNormal; // vertex normal 00360 VertexFlag *** m_abVertexFlag1; // vertex flag1 00361 // See enum VertexFlag above 00371 T **** m_atVertexInterpolation; // interpolation value (pos) 00372 #ifdef TAPs_GRID_WITH_TWO_INTERPOLATIONS 00373 T **** m_atVertexInterpolationToo; // interpolation value (neg) 00374 #endif 00375 //--------------------------------------------------------------- 00376 00377 00378 //============================================================================= 00379 //----------------------------------------------------------------------------- 00380 // With OpenGL 00381 #if defined(__gl_h_) || defined(__GL_H__) 00382 public: 00383 //--------------------------------------------------------------- 00384 // DrawByOpenGL 00385 // GLenum drawStyle; GLU_FILL, GLU_LINE, GLU_SILHOUETTE, and GLU_POINT 00386 // Expensive Drawing, since it draws each particles using sphere. 00387 virtual void DrawByOpenGL ( T diameter = 1, GLenum drawStyle = GLU_FILL ); 00388 //--------------------------------------------------------------- 00389 virtual void DrawBoundingBoxByOpenGL ( 00390 Vector4<T> color = Vector4<T>( 0, 0, 1, 0.5 ) ); 00391 //--------------------------------------------------------------- 00392 virtual void DrawAsPointsByOpenGL ( 00393 Vector4<T> color = Vector4<T>( 0.77, 0.85, 0.75, 0.75 ) 00394 ); 00395 //--------------------------------------------------------------- 00396 virtual void DrawAsBoxesByOpenGL ( 00397 Vector4<T> color = Vector4<T>( 0.77, 0.85, 0.75, 0.75 ) 00398 ); 00399 //--------------------------------------------------------------- 00400 virtual void DrawAllOuterPointsByOpenGL ( 00401 Vector4<T> color = Vector4<T>( 1, 0, 0, 0.5 ) ); 00402 //--------------------------------------------------------------- 00403 virtual void DrawAllInnerPointsByOpenGL ( 00404 Vector4<T> color = Vector4<T>( 0, 1, 0, 0.5 ) ); 00405 //--------------------------------------------------------------- 00419 virtual void DrawAPlaneByOpenGL ( int drawDirection = 2, 00420 Vector4<T> color = Vector4<T>( 0, 1, 0, 0.5 ) ); 00421 00422 //--------------------------------------------------------------- 00423 static GLuint g_uiDisplayList; // for OpenGL drawing 00424 static GLenum g_eDrawStyle; // for OpenGL drawing 00425 #endif 00426 00427 00428 00429 00430 //============================================================================= 00431 #ifdef TAPs_GRID_GENERATOR_ADD_BARYCENTRIC 00432 //----------------------------------------------------------------------------- 00433 00434 /* 00435 //--------------------------- 00436 // FOR TETRAHEDRAL FEM 00437 //--------------------------- 00438 public: 00440 std::vector< TetBarycentricCoordsForVertexRef<T> > & GetTetBarycentricCoords () { return m_cTetBaryCoords; } 00441 00443 void RecordTetBarycentricCoordinates (); 00444 00446 inline void LocateTetGrid ( T x, T y, T z, unsigned int &i, unsigned int &j, unsigned int &k ); 00447 00449 void AnimateTet (); 00450 00451 protected: 00452 //------------------------------------------- 00453 // Barycentric Coordinates 00454 std::vector< TetBarycentricCoordsForVertexRef<T> > m_cTetBaryCoords; //!< tetrahedral barycentric coordinator 00455 00456 void RecordTetBarycentricCoordinates ( OpenGL::XPolygonalModel<T> * pXPModel ); 00457 void RecordTetBarycentricCoordinates ( OpenGL::HalfEdgeModel<T> * pHEModel ); 00458 private: 00459 //--------------------------- 00460 //*/ 00461 00462 //--------------------------- 00463 // FOR HEXAHEDRAL FEM 00464 //--------------------------- 00465 public: 00467 std::vector< HexBarycentricCoordsForVertexRef<T,DATA> > & GetHexBarycentricCoords () { return m_cHexBaryCoords; } 00468 00470 void RecordHexBarycentricCoordinates (); 00471 00473 inline void LocateHexGrid ( T x, T y, T z, unsigned int &i, unsigned int &j, unsigned int &k ); 00474 00476 void AnimateHex (); 00477 00478 protected: 00479 //------------------------------------------- 00480 // Barycentric Coordinates 00481 std::vector< HexBarycentricCoordsForVertexRef<T,DATA> > m_cHexBaryCoords; 00482 00483 void RecordHexBarycentricCoordinates ( OpenGL::XPolygonalModel<T> * pXPModel ); 00484 void RecordHexBarycentricCoordinates ( OpenGL::HalfEdgeModel<T> * pHEModel ); 00485 private: 00486 //--------------------------- 00487 00488 //----------------------------------------------------------------------------- 00489 #endif//TAPs_GRID_GENERATOR_ADD_BARYCENTRIC 00490 //============================================================================= 00491 00492 00493 00494 00495 //----------------------------------------------------------------------------- 00496 //============================================================================= 00497 }; // End Class GridGenerator 00498 //----------------------------------------------------------------------------- 00499 //============================================================================= 00500 END_NAMESPACE_TAPs 00501 //----------------------------------------------------------------------------- 00502 // Include definition if TAPs_USE_EXPORT is not defined 00503 //#if !defined( TAPs_USE_EXPORT ) 00504 #include "TAPsGridGenerator.cpp" 00505 //#endif 00506 //----------------------------------------------------------------------------- 00507 #endif 00508 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00509 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----