Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoLDMResourceManager.h
Go to the documentation of this file.
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 : J.HUMMEL (Dec 2002)
22** Modified by : T.DUFOUR (MMM yyyy)
23**=======================================================================*/
24#ifndef _SO_LDM_RESOURCE_MANAGER_
25#define _SO_LDM_RESOURCE_MANAGER_
26
27#ifdef _MSC_VER
28#pragma warning( push )
29#pragma warning(disable:4251)
30#endif
31
34#include <Inventor/SbVec.h>
35#include <Inventor/STL/vector>
36#include <LDM/SoLDMTopoOctree.h>
37#define MIN_RES_THRESHOLD 10000 //high number meaning not set
38
39class SoDataSet;
40
41// callback function prototypes
42typedef void SoLDMTexFrontCB (void *userData);
43
62{
63public:
68
73
74
75private:
76
77 enum LoadPolicy {
78 NO_USER_INTERACTION, // Only load when no user interaction
79 ALWAYS, // Always load
80 NEVER // Never. No loading happens anymore. Allows suspending loading process.
81 };
82
87 void invalidateData();
88
94 static void setMultiIO(SbBool on);
99 static SbBool getMultiIO();
100
101 static void setMonitoringAmount(int);
102 static int getMonitoringAmount();
103
107 SbVec3i32 getTileSize() const;
108
112 int getDataSize();
113
117 void setTexelSize( int texelSize );
118
122 int getTexelSize();
123
127 const SbVec3i32& getVolumeDim() const;
128
129#if 1 SoDEPRECATED
132 void setTex3LoadRate( int loadRate );
133SoDEPRECATED
135 int getTex3LoadRate();
136SoDEPRECATED
138 void setTex2LoadRate( int loadRate );
139SoDEPRECATED
141 int getTex2LoadRate();
142SoDEPRECATED
144 void setMinResolutionThreshold( int threshold = MIN_RES_THRESHOLD ); // don't unload above this threshold.
145SoDEPRECATED
147 int getMinResolutionThreshold();
148SoDEPRECATED
150 void setMaxResolutionThreshold( int threshold ); // don't load below this threshold.
151SoDEPRECATED
153 int getMaxResolutionThreshold();
154
155#endif
158#if 1 SoDEPRECATED
161 int getTileDimension();
162
163#endif
165#if 1 SoDEPRECATED
171 void setMaxMainMemory( int maxMainMemory );
172SoDEPRECATED
177 int getMaxMainMemory();
178SoDEPRECATED
180 void setMaxTexMemory( int maxTexMemoryMB );
181SoDEPRECATED
183 int getMaxTexMemory();
184SoDEPRECATED
189 int getMaxTilesInMainMem();
190SoDEPRECATED
192 int getMaxTilesInTexMem();
193#endif
195#if 1 SoDEPRECATED
205 void setTileHalfLife( float timeInSec );
206SoDEPRECATED
211 float getTileHalfLife();
212SoDEPRECATED
223 void setLoadPolicy( LoadPolicy loadPolicy );SoDEPRECATED
228 LoadPolicy getLoadPolicy();
229
230 /*
231 * Sets the time (in seconds) for which VViz does not load once a user
232 * stopped interaction
233 * Consulted only in NO_USER_INTERACTION mode
234 * Default is 0.3 seconds.
235 */SoDEPRECATED
237 void setMovingTimeOut( float );
238
239 /*
240 * gets the time for which VViz should not load once a user
241 * stopped interaction
242 */SoDEPRECATED
244 float getMovingTimeOut();
245SoDEPRECATED
251 static void setTex2VVizLoadRate( int loadRate );
252SoDEPRECATED
258 static int getTex2VVizLoadRate();
259SoDEPRECATED
265 static void setTex3VVizLoadRate( int loadRate );
266SoDEPRECATED
272 static int getTex3VVizLoadRate();
273SoDEPRECATED
280 static void setMaxVVizMainMemory( int maxMainMemoryMB ); // set/get the allowed main memory in MB
281SoDEPRECATED
288 static void setMaxVVizTexMemory( int maxTexMemoryMB );
289SoDEPRECATED
294 static int getMaxVVizMainMemory(); // for all the LDM datasets.
295SoDEPRECATED
300 static int getMaxVVizTexMemory();
301SoDEPRECATED
307 static void setNumIO( unsigned int numIO );
308SoDEPRECATED
314 static unsigned int getNumIO();
315SoDEPRECATED
322 static void setLoadNotificationRate( int rate );
323SoDEPRECATED
328 static int getLoadNotificationRate();
329
330#endif
332private:
333 float m_decreaseWeightFactor;
334 float getDecreaseWeightFactor() {return m_decreaseWeightFactor;};
335
339 void setTileSize( SbVec3i32 tileDim );
340
344 void setDataSize( int dataSize );
345
349 void setVolumeDim( const SbVec3i32& dim );
350
351 int getNumTileToTime();
352
353 /*
354 * Enum used to store wich resources has changed. Can be cumulative to
355 * represent several resources modification
356 * ie: GPU resources and CPU resource updated -> value =GPU_MEM_UPDATED | CPU_MEM_UPDATED
357 */
358 enum State
359 {
360 NO_UPDATE = 0x00,
361 CPU_MEM_UPDATED = 0x01, // cpu memory has been changed
362 GPU_MEM_UPDATED = 0x02, // gpu memory has been changed
363 GPU_2D_UPDATED = 0x04, // gpu 2d memory has been changed
364 LOADRATE_2D_UPDATED = 0x08, // LoadRate 2D has been changed
365 LOADRATE_3D_UPDATED = 0x10, // LoadRate 3D has been changed
366 LOAD_RATE_UPDATED = 0x20, // Load notification rate has been updated
367 UPDATE_ALL = 0xFF // Special value to include all previous state
368 };
369
370 // Update all is needed according to the given state
371 virtual void updateResources(unsigned short resourceState);
372
373 // Internal method
374 int getMaxMainMemoryInKB() const; // return amount of main memory in KB
375 int getMaxTexMemoryInKB() const; // return amount of tex memory in KB
376 int getMax2DTexMemoryInKB() const; // return amount of 2D tex memory in KB
377
378 /*
379 Those set of functions returns the sum of resources of all data sets registered
380 */
381 int getSumOfMaxTilesInTexMem();
382 int getSumOfTex3LoadRate();
383 int getSumOfMax2DTextures();
384 int getSumOfTex2LoadRate();
385 void getSumOfMemAndTileSize(uint64_t &memByte, int& tileSize);
386 void getSumOfNumTileInMem( uint64_t &maxTileInMem );
387
388 static void computeInternalCounters(const std::vector<SoLDMResourceManager*>& rsToUpdate);
389 static void shareSpareResources(const std::vector<SoLDMResourceManager*>& rsToUpdate,
390 size_t spareAmount, SoLDMResourceManager::State resourceType);
391
392 /* *
393 * Set of method to compute and allocate internally amount of resources for each dataset
394 * Each method works on a specific resources and determine how much of this resource can
395 * be spared between all dataset. The computation is based on global value for each resources,
396 * and the amount manually set by application
397 */
398 void allocateGPUResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
399 void allocateCPUResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
400 void allocateGPU2DResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
401 void allocateTex2LoadRate(const std::vector<SoLDMResourceManager*>& rsToUpdate);
402 void allocateTex3LoadRate(const std::vector<SoLDMResourceManager*>& rsToUpdate);
403
404 void setIdealTextFrontCb( SoLDMTexFrontCB *func, void* userData = NULL);
405 void idealTexFrontReached();
406 SoLDMTexFrontCB* m_callbackFunc;
407 void* m_userData;
408 SoDataSet* getDataSet() { return m_ds; };
409
413 static uint64_t getMaxVViz2DTexMemory();
414
418 static void setMaxVViz2DTexMemory(uint64_t maxMemory);
419
423 void setMax2DTexMemory(int max2DTexMemory);
424
428 int getMax2DTexMemory();
429
431 void enableTileBorders( bool enableTileBorders );
432
434 bool areTileBordersEnabled() const;
435
437 void setMinTilesToLoad( int minTilesToLoad );
438
440 int getMinTilesToLoad() const
441 {
442 return m_minTilesToLoad;
443 }
444
446 void setViewpointRefinement( SoLDMResourceParameters::ViewpointRefinementPolicy viewportRefinementPolicy );
447
449 bool getViewpointRefinement() const;
450
452 void setScreenResolutionCulling(SoLDMResourceParameters::ScreenResolutionCullingPolicy screenResolutionCullingPolicy);
453
455 bool getScreenResolutionCulling() const;
456
458 uint64_t getDataTileSizeInBytes() const;
459
461 uint64_t getTexTileSizeInBytes(bool is3DTile = false) const;
462
463private:
464
465 int m_minResThreshold; // minimum resolution required (0:1/1, 1:1/2, 2:1/4, ...), default is 100.
466 int m_maxResThreshold; // maximum resolution allowed (0:1/1, 1:1/2, 2:1/4, ...), default is 0.
467
468 bool m_tileBordersEnabled;
469 int m_minTilesToLoad;
470 SoLDMResourceParameters::ViewpointRefinementPolicy m_viewpointRefinementPolicy;
471 SoLDMResourceParameters::ScreenResolutionCullingPolicy m_screenResolutionCullingPolicy;
472
473 // TODO: these 2 methods should be removed while the following friend dependencies will be managed
475 friend class SoLDMMediator;
476
477 //static void updateMainMemParams( int mem, SoLDMResourceManager* exclude );
478 static void updateNumTilesInMainMem();
479
481 static void updateMaxMainMem();
482
484 static void updateSumMax2DTextures();
485
490 static const std::vector<SoLDMResourceManager*>& getRSToUpdate();
491
493 // texture memory controls (for SoVolumeRender, SoVolumeGeometry)
494 static int s_maxVVizTexMemoryKB; // amount in KB of texture memory allowed for all the LDM datasets, default is 0 KB.
495
496 int m_maxTexMemoryKB; // amount in KB of texture memory allowed for the corresponding dataset.
497 int m_max2DTexMemoryKB; // amount in KB of 2D texture memory allowed for the corresponding dataset.
498
499 int m_numTilesInTexMem; // num tiles allowed in texture memory = m_maxTexMemory / tileTexSize
500
501 static void updateNumTilesInTexMem();
502
504 static void updateMaxTexMem();
505
506 // Check that all dataSets parameters are consistent with global ones.
507 // If, for each dataSet, one parameter is not consistent with the global one, it
508 // is reset to -1 in these dataSets.
509 static void checkParametersConsistency(const std::vector<SoLDMResourceManager*>& rsToUpdate);
510
512 // texture 3 memory load rate controls (for SoVolumeRender, SoVolumeGeometry)
513 static int s_tex3VVizLoadRate; // num tiles allowed to load in tex mem per frame for all the LDM datasets, default is 1.
514 int m_tex3LoadRate; // num tiles allowed to load in tex mem per frame for the corresponding dataset.
515
516
517 // texture 2 memory controls (for SoOxxSlice, SoVolumeSkin)
518 static uint64_t s_maxVViz2DTexMemory; // 2D tiles memory allowed in texture memory for all LDM datasets, default is 64M ( ~5% of 1G ).
519
520 // texture 2 memory load rate controls (for SoOxxSlice, SoVolumeSkin)
521 static int s_tex2VVizLoadRate; // num tiles allowed to load in tex mem per frame for all the LDM datasets, default is 64.
522 int m_tex2LoadRate; // num tiles allowed to load in tex mem per frame for the corresponding dataset.
523
524
525
526 static int s_maxVVizMainMemoryKB; // amount in KB of main memory allowed for all the LDM datasets, default is 256 MB.
527 int m_maxMainMemoryKB; // amount in KB of main memory allowed for the corresponding dataset.
528
529 int m_numTilesInMainMem; // num tiles allowed in main memory = m_maxMainMemory / tileSize
530
531 static int s_loadNotificationRate;
532 static int s_memToLoad;
533
534 //number of IO:
535 static unsigned int s_numIO;
536 static SbBool s_isMultiIO;
537
538
539 SbVec3i32 m_tileDimension; // tile dimension, default is 64.
540 int m_dataSize; // data size in bytes (1,2 or 4), default is 1.
541 int m_texelSize; // texel size in bits, default is 8.
542 // =8 for 8 bits indexed 3D textures
543 // =32 for RGBA 3D textures
544 // =24 for 8 bits indexed 2D textures
545 // =96 for RGBA 2D textures
546 SbVec3i32 m_volDim; // dataset dimension
547
548
549
550 static std::vector<SoLDMResourceManager*> s_resourceManagers; // list of all ResourceManager's
551
552
553 // Internal octree needed to compute resources
554 SoLDMTopoOctree m_topoOctree;
555
556 // Adjust the CPU memory allocated per dataset by taking in account
557 // dataset that needs less memory
558 void adjustMemPerDataset(const std::vector<SoLDMResourceManager*>& rsToUpdate);
559
560 SoDataSet* m_ds;
561
562 // cache value before and after ajustMaxTilesInTexMem
563 int m_getSumOfMaxTilesInTexMemAdjusted;
564 int m_getSumOfMaxTilesInTexMem;
565
570 size_t m_maxNeededMemKB;
571
572 // List of resourceManager to take in account for
573 // resource sharing
574 static std::vector<SoLDMResourceManager*> s_rsToUpdate;
575
576 // Store the number of mask associated to each data set
577 static std::map<SoLDMMediator*, int> s_maskPerMediator;
578
579 // Store the number of volume data that are not volumeMask, by cumulating their datasize.
580 // For example dataset in float will count for 4, while a dataset in byte will count
581 // for one. This allow to ponderate properly the amount of resources to
582 // dataset, taking in account their datasize.
583 static size_t s_nbVolumeData;
584
585 // store the amount of GPU memory available for dataset not manually configured
586 // ie : ( s_MaxVVizTexMemory - ( Sum of memory of all datasets with #maxTexMem != -1 )) / ( number of datasets with #maxTexMem == -1 )
587 static size_t s_gpuMemPerDataSetKB;
588
589 // store the amount of CPU memory available for dataset not manually configured
590 // ie : ( s_MaxVVizMainMemory - ( Sum of memory of all dataset with #maxMainMem != -1 )) / ( number of datasets with #maxMainMem == -1 )
591 static size_t s_cpuMemPerDataSetKB;
592
593 // store the 2D tiles memory in texture (GPU) memory available for dataset not manually configured MB
594 // ie : (s_maxVViz2DTexMemory - ( Sum of memory of all dataset with #max2DTextures != -1 )) / ( number of datasets with #max2DTextures == -1 )
595 static uint64_t s_2DGpuTexMemoryPerDataSetMB;
596
597 // store the amount of 2D Load Rate available for dataset not manually configured
598 // ie : (s_tex2VVizLoadRate - ( Sum of 2DLoadRate of all dataset with #tex2LoadRate != -1 )) / ( number of datasets with #tex2LoadRate == -1 )
599 static size_t s_tex2LoadRatePerDataSet;
600
601 // store the amount of 3D Load Rate available for dataset not manually configured
602 // ie : (s_tex3VVizLoadRate - ( Sum of 3DLoadRate of all dataset with #tex3LoadRate != -1 )) / ( number of datasets with #tex3LoadRate == -1 )
603 static size_t s_tex3LoadRatePerDataSet;
604
605 // store the remainder amount of GPU Memory
606 static size_t s_spareGpuMemoryKB;
607
608 // store the remainder amount of CPU Memory
609 static size_t s_spareCpuMemoryKB;
610
611 // store the remainder amount of tex2 LoadRate
612 static size_t s_spareTex2LoadRate;
613
614 // store the remainder amount of tex3 LoadRate
615 static size_t s_spareTex3LoadRate;
616
617 // if true, prints MaxMain(MiB), Max2DTex(MiB), Max3DTex(MiB), Tex2LoadRate, Tex3LoadRate.
618 static bool s_debugResourceValues;
619
624 static SbThreadMutex s_globalResourcesMutex;
625};
626
627
628#ifdef _MSC_VER
629#pragma warning( pop )
630#endif
631
632#endif // _SO_LDM_RESOURCE_MANAGER_
633
634
#define SoEXTENDER_Documented
#define MIN_RES_THRESHOLD
void SoLDMTexFrontCB(void *userData)
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
3D vector class.
Definition SbVec.h:1517
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Data set...
Definition SoDataSet.h:139
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Large Da...
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Resource...
virtual ~SoLDMResourceManager()
Destructor.
SoLDMResourceManager(SoDataSet *ds)
Constructor.
ViewpointRefinementPolicy
Viewpoint refinement policies.
ScreenResolutionCullingPolicy
Screen resolution culling policies.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Octree t...
int SbBool
Boolean type.
Definition SbBase.h:87