Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoLDMTopoOctree.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : T. DUFOUR (May 2005)
22**=======================================================================*/
23
24#ifndef _SO_LDM_TOPO_OCTREE_
25#define _SO_LDM_TOPO_OCTREE_
26
27#include <Inventor/SbLinear.h>
28#include <Inventor/SbBox.h>
29#include <LDM/SoLDMTileID.h>
30
31class SoLDMOctreeNode;
32
33
34#ifdef _MSC_VER
35#pragma warning( push )
36#pragma warning(disable:4251)
37#endif
38
39// Note : this level will be never reached (at least this century!)
40#define LEVEL_MAX 20
41
86{
87
88public:
89
94
100 void init(const SbVec3i32& dimension, const SbVec3i32& tileDim, const int border = 0);
101
107 void init(const SbVec3i32& dimension, const int tileDim, const int border=0)
108 {
109 init(dimension, SbVec3i32(tileDim, tileDim, tileDim), border);
110 }
111
117 SbBox3i32 getTilePos( const SoLDMTileID& tileID )const;
118
138 SoLDMTileID getTileID( const SbVec3i32& cellPos, const int resolutionLevel )const;
139
145 int getNumFileIDs()const;
146
152 inline size_t getNumTileIDs()const;
153
157 inline int getFileID( const SoLDMTileID& tileID )const;
158
162 SoLDMTileID getTileID( const int fileID )const;
163
168 inline bool isEmpty() const
169 { return (m_numFileIDs<=0); }
170
176 int getLevelMax()const;
177
183 inline int level( const SoLDMTileID& id ) const;
184
190 int level( const LDM_TILE_ID_TYPE index ) const;
191
193 const SbVec3i32& getTileSize() const
194 {
195 return m_tileDim;
196 }
197
198private:
199
200
206 enum Location
207 {
208 LEFT = 0x01,
209 RIGHT = 0x02,
210 BOTTOM = 0x04,
211 TOP = 0x08,
212 FRONT = 0x10,
213 BACK = 0x20
214 };
216 int opposite(int locationMask) const;
217
243 static const int s_allLocations[26];
244
249
250 SbVec3i32 getTileOrigin( const LDM_TILE_ID_TYPE tileID )const;
251
252 LDM_TILE_ID_TYPE parent( const LDM_TILE_ID_TYPE index )const;
253 inline LDM_TILE_ID_TYPE children( const LDM_TILE_ID_TYPE index )const;
254
255 LDM_TILE_ID_TYPE getNumTilesAtDepth( const int level )const;
256 LDM_TILE_ID_TYPE getSumTilesAtDepth( const int level )const;
257
258 int getNumFileIDsAtDepth( const int level )const;
259 int getSumFileIDsAtDepth( const int level )const;
260 int sizeofTiles( const int numTile, int tileDim )const;
261
262 inline bool hasChildren(const SoLDMTileID& tileId) const;
263
265 const SbVec3i32& getTileDimAtLevel(int l) const
266 {
267 return m_tileDimAtLevel[l];
268 }
269
271 const SbVec3i32& getTileDimAtLevel(const SoLDMTileID& id) const;
272
276 inline bool isChildOf(const SoLDMTileID& parent,
277 const SoLDMTileID& child) const;
278
282 inline bool isInFamilyOf(const SoLDMTileID& parent, const SoLDMTileID& child) const;
283
284
286 SbVec3i32 getTileSpacePos( const LDM_TILE_ID_TYPE tileID , const int tileLevel ) const;
287
289 SoLDMTileID getTileSpaceID( const SbVec3i32& cellPos, const int level) const;
290
296 SoLDMTileID getNeighborTile(const SoLDMTileID& tileID, int locationMask) const;
297
298 SoLDMOctreeNode* operator [](const LDM_TILE_ID_TYPE tileID)const;
299 SoLDMOctreeNode* operator ()(const int fileID)const;
300
307 inline static void getOrderedOctant(int octantOrder[8], const SbVec3f & viewVector);
308
309 /* Allow the octree to use (or not) the optimisation made on thin volume */
310 void useThinOptim(bool useThinVolumeOptim);
311
317 inline int getMaxNumChildren() const
318 { return m_maxNumChildren; }
319
324 void commonInit( const SbVec3i32& dimension, const SbVec3i32& tileDim, const int border=0 );
325
326 const SbVec3i32& getVolumeDimensions() const
327 {
328 return m_dimension;
329 }
330
331private:
333 void fillTileDimAtLevel();
334
336 SbVec3i32 getTileOrigin( const LDM_TILE_ID_TYPE tileID, int tileLevel ) const;
337
342 int getFileIDReverseTable( const SoLDMTileID& tileID )const;
343
349 static float computeLevelMax(unsigned int maxDim, unsigned int tileDim,
350 unsigned int border);
351
352 static const int MAX_OCTREE_DEPTH;
353
354 // precomputed data
355 static const uint64_t s_numTilesAtDepth[LEVEL_MAX+1];
356 static const uint64_t s_sumTilesAtDepth[LEVEL_MAX+2];
357
358 // data depending on the volume dimension
359 SbVec3i32 m_dimension;
360 SbVec3i32 m_tileDim;
361 int m_border;
362 int m_levelMax;
363 int m_maxNumChildren;
364 LDM_TILE_ID_TYPE m_numTileIDs;
365 int m_numFileIDs;
366 SoLDMOctreeNode *m_tileIDs;
367 int* m_fileIDs;
368 int m_numFileIDsAtDepth[LEVEL_MAX+1];
369 int m_sumFileIDsAtDepth[LEVEL_MAX+1];
370 bool m_initIsDone;
372 static const unsigned int TDimension;
373
374 std::vector<SbVec3i32> m_tileDimAtLevel;
375
376 /* Indicate if the octree can use thin volume optimization */
377 bool m_useThinVolumeOptim;
378
379};
380
381/******************************************************************************/
382size_t
384{
385 return (size_t)(m_numTileIDs);
386}
387
388/******************************************************************************/
389bool
390SoLDMTopoOctree::hasChildren(const SoLDMTileID& tileId) const
391{
392 return children(tileId.getID()) < (LDM_TILE_ID_TYPE)getNumTileIDs() ;
393}
394
395/******************************************************************************/
396int
398{
399 return level(id.getID());
400}
401
402/******************************************************************************/
403bool
404SoLDMTopoOctree::isChildOf(const SoLDMTileID& parent, const SoLDMTileID& child) const
405{
406 if ( child.getID() >= m_numTileIDs )
407 return false;
408
409 LDM_TILE_ID_TYPE firstChild = children(parent.getID());
410 LDM_TILE_ID_TYPE childId = child.getID();
411 return childId >= firstChild && childId < firstChild+8;
412}
413
414/******************************************************************************/
415bool
416SoLDMTopoOctree::isInFamilyOf(const SoLDMTileID& _parent, const SoLDMTileID& child) const
417{
418 LDM_TILE_ID_TYPE childId = child.getID();
419 LDM_TILE_ID_TYPE parentId = _parent.getID();
420 if ( childId >= m_numTileIDs || childId < 0 )
421 return false;
422 else if ( childId == parentId)
423 return true;
424 else
425 {
426 LDM_TILE_ID_TYPE parentChildID = parent(childId);
427 if ( parentChildID == parentId )
428 return true;
429 else
430 return isInFamilyOf(_parent,parentChildID);
431 }
432 return false;
433}
434
435/******************************************************************************/
436int
438{
439 if ( tileID.getID()<0 || tileID.getID()>=m_numTileIDs)
440 return -1;
441
442 // if m_fileIDs exists, use it straight
443 if ( m_fileIDs )
444 return m_fileIDs[tileID.getID()] - 1;
445
446 return getFileIDReverseTable(tileID);
447}
448
449/******************************************************************************/
450LDM_TILE_ID_TYPE
451SoLDMTopoOctree::children( const LDM_TILE_ID_TYPE index )const
452{
453 return (index << TDimension) + 1;
454}
455
456/******************************************************************************/
457void
458SoLDMTopoOctree::getOrderedOctant(int octantOrder[8], const SbVec3f & viewVector)
459{
460 int bitMask = 0;
461 for ( int i = 0; i < 3; i++ )
462 bitMask |= (viewVector[i] < 0) << i;
463 for ( unsigned int i = 0; i < 8; i++ )
464 octantOrder[i] = i^bitMask;
465}
466
467#ifdef _MSC_VER
468#pragma warning( pop )
469#endif
470
471#endif /* _SO_LDM_TOPO_OCTREE_ */
472
473
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 3D box class.
Definition SbBox.h:96
3D vector class.
Definition SbVec.h:932
3D vector class.
Definition SbVec.h:1517
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Tile ID
Definition SoLDMTileID.h:63
LDM_TILE_ID_TYPE getID() const
Returns the tile ID.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Octree t...
const SbVec3i32 & getTileSize() const
Return the tilesize used to setup this octree.
int getFileID(const SoLDMTileID &tileID) const
Given a tileID, returns the corresponding fileID.
SoLDMTileID getTileID(const int fileID) const
Given a fileID, returns the corresponding tileID.
size_t getNumTileIDs() const
Returns the number of tileIDs in the complete (conceptual) octree.
SbBox3i32 getTilePos(const SoLDMTileID &tileID) const
Returns the bounding box, in voxel/cell coordinates, of the specified tile.
SoLDMTileID getTileID(const SbVec3i32 &cellPos, const int resolutionLevel) const
Given the position of a voxel in full resolution voxel coordinates (i,j,k) and a resolution level,...
bool isEmpty() const
Returns false if the octree is empty.
void init(const SbVec3i32 &dimension, const SbVec3i32 &tileDim, const int border=0)
Initialize with the properties of the data set.
int level(const LDM_TILE_ID_TYPE index) const
Returns the tile level of the given tile Id.
int getLevelMax() const
Returns the maximum level of the octree tile hierarchy.
int level(const SoLDMTileID &id) const
Returns the tile level of the given tile Id.
int getNumFileIDs() const
Returns the number of fileIDs in the volume.
SoLDMTopoOctree()
Constructor.
void init(const SbVec3i32 &dimension, const int tileDim, const int border=0)
Initialize with the properties of the data set.