00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _SO_LDM_TOPO_OCTREE_
00025 #define _SO_LDM_TOPO_OCTREE_
00026
00027 #include <Inventor/SbLinear.h>
00028 #include <Inventor/SbBox.h>
00029 #include <LDM/SoLDMTileID.h>
00030
00031 class SoLDMOctreeNode;
00032
00033
00034 #ifdef _MSC_VER
00035 #pragma warning( push )
00036 #pragma warning(disable:4251)
00037 #endif
00038
00039
00040 #define LEVEL_MAX 20
00041
00085 class SoLDMTopoOctree
00086 {
00087
00088 public:
00089
00093 SoLDMTopoOctree();
00094
00100 void init( const SbVec3i32& dimension, const int tileDim, const int border=0 );
00101
00107 SbBox3i32 getTilePos( const SoLDMTileID& tileID )const;
00108
00128 SoLDMTileID getTileID( const SbVec3i32& cellPos, const int resolutionLevel )const;
00129
00135 int getNumFileIDs()const;
00136
00142 inline size_t getNumTileIDs()const;
00143
00147 inline int getFileID( const SoLDMTileID& tileID )const;
00148
00152 SoLDMTileID getTileID( const int fileID )const;
00153
00158 inline bool isEmpty() const
00159 { return (m_numFileIDs<=0); }
00160
00166 int getLevelMax()const;
00167
00173 inline int level( const SoLDMTileID& id ) const;
00174
00180 int level( const LDM_TILE_ID_TYPE index ) const;
00181
00183 SbVec3i32 getTileSize() const
00184 { return m_tileDim; }
00185
00186 private:
00187
00188
00194 enum Location
00195 {
00196 LEFT = 0x01,
00197 RIGHT = 0x02,
00198 BOTTOM = 0x04,
00199 TOP = 0x08,
00200 FRONT = 0x10,
00201 BACK = 0x20
00202 };
00204 int opposite(int locationMask) const;
00205
00231 static const int s_allLocations[26];
00232
00236 ~SoLDMTopoOctree();
00237
00238 SbVec3i32 getTileOrigin( const LDM_TILE_ID_TYPE tileID )const;
00239
00240 LDM_TILE_ID_TYPE parent( const LDM_TILE_ID_TYPE index )const;
00241 inline LDM_TILE_ID_TYPE children( const LDM_TILE_ID_TYPE index )const;
00242
00243 LDM_TILE_ID_TYPE getNumTilesAtDepth( const int level )const;
00244 LDM_TILE_ID_TYPE getSumTilesAtDepth( const int level )const;
00245
00246 int getNumFileIDsAtDepth( const int level )const;
00247 int getSumFileIDsAtDepth( const int level )const;
00248 int sizeofTiles( const int numTile )const;
00249
00250 inline bool hasChildren(const SoLDMTileID& tileId) const;
00251
00253 inline const SbVec3i32& getTileDimAtLevel(int l) const;
00254
00256 SbVec3i32 getTileDimAtLevel(const SoLDMTileID& id) const;
00257
00261 inline bool isChildOf(const SoLDMTileID& parent,
00262 const SoLDMTileID& child) const;
00263
00267 inline bool isInFamilyOf(const SoLDMTileID& parent, const SoLDMTileID& child) const;
00268
00269
00271 SbVec3i32 getTileSpacePos( const LDM_TILE_ID_TYPE tileID , const int tileLevel ) const;
00272
00274 SoLDMTileID getTileSpaceID( const SbVec3i32& cellPos, const int level) const;
00275
00281 SoLDMTileID getNeighborTile(const SoLDMTileID& tileID, int locationMask) const;
00282
00283 SoLDMOctreeNode* operator [](const LDM_TILE_ID_TYPE tileID)const;
00284 SoLDMOctreeNode* operator ()(const int fileID)const;
00285
00292 inline static void getOrderedOctant(int octantOrder[8], const SbVec3f & viewVector);
00293
00294
00295 void useThinOptim(bool useThinVolumeOptim);
00296
00302 inline int getMaxNumChildren() const
00303 { return m_maxNumChildren; }
00304
00309 void commonInit( const SbVec3i32& dimension, const int tileDim, const int border=0 );
00310
00311 private:
00313 void fillTileDimAtLevel();
00314
00316 SbVec3i32 getTileOrigin( const LDM_TILE_ID_TYPE tileID, int tileLevel ) const;
00317
00322 int getFileIDReverseTable( const SoLDMTileID& tileID )const;
00323
00329 static float computeLevelMax(unsigned int maxDim, unsigned int tileDim,
00330 unsigned int border);
00331
00332 static const int MAX_OCTREE_DEPTH;
00333
00334
00335 static const uint64_t s_numTilesAtDepth[LEVEL_MAX+1];
00336 static const uint64_t s_sumTilesAtDepth[LEVEL_MAX+2];
00337
00338
00339 SbVec3i32 m_dimension;
00340 SbVec3i32 m_tileDim;
00341 int m_border;
00342 int m_levelMax;
00343 int m_maxNumChildren;
00344 LDM_TILE_ID_TYPE m_numTileIDs;
00345 int m_numFileIDs;
00346 SoLDMOctreeNode *m_tileIDs;
00347 int* m_fileIDs;
00348 int m_numFileIDsAtDepth[LEVEL_MAX+1];
00349 int m_sumFileIDsAtDepth[LEVEL_MAX+1];
00350 bool m_initIsDone;
00352 static const unsigned int TDimension;
00353
00354 std::vector<SbVec3i32> m_tileDimAtLevel;
00355
00356
00357 bool m_useThinVolumeOptim;
00358
00359 };
00360
00361
00362 size_t
00363 SoLDMTopoOctree::getNumTileIDs() const
00364 {
00365 return (size_t)(m_numTileIDs);
00366 }
00367
00368
00369 bool
00370 SoLDMTopoOctree::hasChildren(const SoLDMTileID& tileId) const
00371 {
00372 return children(tileId.getID()) < (LDM_TILE_ID_TYPE)getNumTileIDs() ;
00373 }
00374
00375
00376 int
00377 SoLDMTopoOctree::level(const SoLDMTileID& id) const
00378 {
00379 return level(id.getID());
00380 }
00381
00382
00383 bool
00384 SoLDMTopoOctree::isChildOf(const SoLDMTileID& parent, const SoLDMTileID& child) const
00385 {
00386 if ( child.getID() >= m_numTileIDs )
00387 return false;
00388
00389 LDM_TILE_ID_TYPE firstChild = children(parent.getID());
00390 LDM_TILE_ID_TYPE childId = child.getID();
00391 return childId >= firstChild && childId < firstChild+8;
00392 }
00393
00394
00395 bool
00396 SoLDMTopoOctree::isInFamilyOf(const SoLDMTileID& _parent, const SoLDMTileID& child) const
00397 {
00398 LDM_TILE_ID_TYPE childId = child.getID();
00399 LDM_TILE_ID_TYPE parentId = _parent.getID();
00400 if ( childId >= m_numTileIDs || childId < 0 )
00401 return false;
00402 else if ( childId == parentId)
00403 return true;
00404 else
00405 {
00406 LDM_TILE_ID_TYPE parentChildID = parent(childId);
00407 if ( parentChildID == parentId )
00408 return true;
00409 else
00410 return isInFamilyOf(_parent,parentChildID);
00411 }
00412 return false;
00413 }
00414
00415
00416 int
00417 SoLDMTopoOctree::getFileID( const SoLDMTileID& tileID )const
00418 {
00419 if ( tileID.getID()<0 || tileID.getID()>=m_numTileIDs)
00420 return -1;
00421
00422
00423 if ( m_fileIDs )
00424 return m_fileIDs[tileID.getID()] - 1;
00425
00426 return getFileIDReverseTable(tileID);
00427 }
00428
00429
00430 LDM_TILE_ID_TYPE
00431 SoLDMTopoOctree::children( const LDM_TILE_ID_TYPE index )const
00432 {
00433 return (index << TDimension) + 1;
00434 }
00435
00436
00437 void
00438 SoLDMTopoOctree::getOrderedOctant(int octantOrder[8], const SbVec3f & viewVector)
00439 {
00440 int bitMask = 0;
00441 for ( int i = 0; i < 3; i++ )
00442 bitMask |= (viewVector[i] < 0) << i;
00443 for ( unsigned int i = 0; i < 8; i++ )
00444 octantOrder[i] = i^bitMask;
00445 }
00446
00447 #ifdef _MSC_VER
00448 #pragma warning( pop )
00449 #endif
00450
00451 #endif
00452
00453
00454