00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __Ogre_Volume_DualGridGenerator_H__ 00029 #define __Ogre_Volume_DualGridGenerator_H__ 00030 00031 #include <vector> 00032 00033 #include "OgreSceneManager.h" 00034 00035 #include "OgreVolumeOctreeNode.h" 00036 #include "OgreVolumePrerequisites.h" 00037 #include "OgreVolumeIsoSurface.h" 00038 00039 namespace Ogre { 00040 namespace Volume { 00041 00044 typedef struct _OgreVolumeExport DualCell 00045 { 00046 public: 00047 Vector3 mC0; 00048 Vector3 mC1; 00049 Vector3 mC2; 00050 Vector3 mC3; 00051 Vector3 mC4; 00052 Vector3 mC5; 00053 Vector3 mC6; 00054 Vector3 mC7; 00055 DualCell(const Vector3 &c0, const Vector3 &c1, const Vector3 &c2, const Vector3 &c3, const Vector3 &c4, const Vector3 &c5, const Vector3 &c6, const Vector3 &c7) : 00056 mC0(c0), mC1(c1), mC2(c2), mC3(c3), mC4(c4), mC5(c5), mC6(c6), mC7(c7) 00057 { 00058 } 00059 } DualCell; 00060 00063 typedef vector<DualCell>::type VecDualCell; 00064 00067 class _OgreVolumeExport DualGridGenerator : public UtilityAlloc 00068 { 00069 protected: 00070 00072 static size_t mDualGridI; 00073 00075 Entity* mDualGrid; 00076 00078 OctreeNode const* mRoot; 00079 00081 VecDualCell mDualCells; 00082 00084 bool mSaveDualCells; 00085 00087 IsoSurface *mIs; 00088 00090 MeshBuilder *mMb; 00091 00093 Real mMaxMSDistance; 00094 00096 Vector3 mTotalFrom; 00097 00099 Vector3 mTotalTo; 00100 00117 inline void addDualCell(const Vector3 &c0, const Vector3 &c1, const Vector3 &c2, const Vector3 &c3, const Vector3 &c4, const Vector3 &c5, const Vector3 &c6, const Vector3 &c7) 00118 { 00119 addDualCell(c0, c1, c2, c3, c4, c5, c6, c7, 0); 00120 } 00121 00142 inline void addDualCell(const Vector3 &c0, const Vector3 &c1, const Vector3 &c2, const Vector3 &c3, const Vector3 &c4, const Vector3 &c5, const Vector3 &c6, const Vector3 &c7, 00143 Vector4 *values) 00144 { 00145 00146 if (mSaveDualCells) 00147 { 00148 mDualCells.push_back(DualCell(c0, c1, c2, c3, c4, c5, c6, c7)); 00149 } 00150 00151 Vector3 corners[8]; 00152 corners[0] = c0; 00153 corners[1] = c1; 00154 corners[2] = c2; 00155 corners[3] = c3; 00156 corners[4] = c4; 00157 corners[5] = c5; 00158 corners[6] = c6; 00159 corners[7] = c7; 00160 mIs->addMarchingCubesTriangles(corners, values, mMb); 00161 Vector3 from = mRoot->getFrom(); 00162 Vector3 to = mRoot->getTo(); 00163 if (corners[0].z == from.z && corners[0].z != mTotalFrom.z) 00164 { 00165 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_BACK, mMaxMSDistance, mMb); 00166 } 00167 if (corners[2].z == to.z && corners[2].z != mTotalTo.z) 00168 { 00169 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_FRONT, mMaxMSDistance, mMb); 00170 } 00171 if (corners[0].x == from.x && corners[0].x != mTotalFrom.x) 00172 { 00173 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_LEFT, mMaxMSDistance, mMb); 00174 } 00175 if (corners[1].x == to.x && corners[1].x != mTotalTo.x) 00176 { 00177 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_RIGHT, mMaxMSDistance, mMb); 00178 } 00179 if (corners[5].y == to.y && corners[5].y != mTotalTo.y) 00180 { 00181 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_TOP, mMaxMSDistance, mMb); 00182 } 00183 if (corners[0].y == from.y && corners[0].y != mTotalFrom.y) 00184 { 00185 mIs->addMarchingSquaresTriangles(corners, values, IsoSurface::MS_CORNERS_BOTTOM, mMaxMSDistance, mMb); 00186 } 00187 } 00188 00189 /* Startpoint for the creation recursion. 00190 @param n 00191 The node to start with. 00192 */ 00193 void nodeProc(const OctreeNode *n); 00194 00195 /* faceProc with variing X and Y of the nodes, see the paper for faceProc(). 00196 Direction of parameters: Z+ (n0 and n3 for example of parent cell) 00197 @param n0 00198 The first node. 00199 @param n1 00200 The second node. 00201 */ 00202 void faceProcXY(const OctreeNode *n0, const OctreeNode *n1); 00203 00204 /* faceProc with variing Z and Y of the nodes, see the paper for faceProc(). 00205 Direction of parameters: X+ (n0 and n1 for example of parent cell) 00206 @param n0 00207 The first node. 00208 @param n1 00209 The second node. 00210 */ 00211 void faceProcZY(const OctreeNode *n0, const OctreeNode *n1); 00212 00213 /* faceProc with variing X and Z of the nodes, see the paper for faceProc(). 00214 Direction of parameters: Y- (n4 and n0 for example of parent cell) 00215 @param n0 00216 The first node. 00217 @param n1 00218 The second node. 00219 */ 00220 void faceProcXZ(const OctreeNode *n0, const OctreeNode *n1); 00221 00233 void edgeProcX(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3); 00234 00246 void edgeProcY(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3); 00247 00259 void edgeProcZ(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3); 00260 00261 /* vertProc of the nodes, see the paper for vertProc. Difference to the paper: The cells to the 00262 octree border are already created here and not with another traversion. 00263 @param n0 00264 The first node. 00265 @param n1 00266 The second node. 00267 @param n3 00268 The third node. 00269 @param n4 00270 The fourth node. 00271 @param n5 00272 The fifth node. 00273 @param n6 00274 The sixth node. 00275 @param n7 00276 The seventh node. 00277 */ 00278 void vertProc(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3, const OctreeNode *n4, const OctreeNode *n5, const OctreeNode *n6, const OctreeNode *n7); 00279 00280 /* Creates the bordercells. 00281 @param n0 00282 The first node. 00283 @param n1 00284 The second node. 00285 @param n3 00286 The third node. 00287 @param n4 00288 The fourth node. 00289 @param n5 00290 The fifth node. 00291 @param n6 00292 The sixth node. 00293 @param n7 00294 The seventh node. 00295 */ 00296 void createBorderCells(const OctreeNode *n0, const OctreeNode *n1, const OctreeNode *n2, const OctreeNode *n3, const OctreeNode *n4, const OctreeNode *n5, const OctreeNode *n6, const OctreeNode *n7); 00297 00298 public: 00299 00302 DualGridGenerator(void); 00303 00320 void generateDualGrid(const OctreeNode *root, IsoSurface *is, MeshBuilder *mb, Real maxMSDistance, const Vector3 &totalFrom, const Vector3 &totalTo, bool saveDualCells); 00321 00328 Entity* getDualGrid(SceneManager *sceneManager); 00329 00334 inline size_t getDualCellCount(void) const 00335 { 00336 return mDualCells.size(); 00337 } 00338 00345 inline DualCell getDualCell(size_t i) const 00346 { 00347 return mDualCells[i]; 00348 } 00349 }; 00350 } 00351 } 00352 00353 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48