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_RESOURCE_MANAGER_
00025 #define _SO_LDM_RESOURCE_MANAGER_
00026
00027 #ifdef _MSC_VER
00028 #pragma warning( push )
00029 #pragma warning(disable:4251)
00030 #endif
00031
00032 #include <LDM/SoLDMLargeDataManagement.h>
00033 #include <LDM/nodes/SoLDMResourceParameters.h>
00034 #include <Inventor/SbVec.h>
00035 #include <Inventor/STL/vector>
00036 #include <LDM/SoLDMTopoOctree.h>
00037 #define MIN_RES_THRESHOLD 10000 //high number meaning not set
00038
00039 class SoDataSet;
00040
00041
00042 typedef void SoLDMTexFrontCB (void *userData);
00043
00061 SoEXTENDER_Documented class SoLDMResourceManager : public SoLDMLargeDataManagement
00062 {
00063 public:
00067 SoLDMResourceManager(SoDataSet* ds);
00068
00072 virtual ~SoLDMResourceManager();
00073
00074
00075 private:
00076
00077 enum LoadPolicy {
00078 NO_USER_INTERACTION,
00079 ALWAYS,
00080 NEVER
00081 };
00082
00087 void invalidateData();
00088
00094 static void setMultiIO(SbBool on);
00099 static SbBool getMultiIO();
00100
00101 static void setMonitoringAmount(int);
00102 static int getMonitoringAmount();
00103
00107 SbVec3i32 getTileSize() const;
00108
00112 int getDataSize();
00113
00117 void setTexelSize( int texelSize );
00118
00122 int getTexelSize();
00123
00127 SbVec3i32 getVolumeDim();
00128
00129 #if 1 SoDEPRECATED
00132 void setTex3LoadRate( int loadRate );
00133 SoDEPRECATED
00135 int getTex3LoadRate();
00136 SoDEPRECATED
00138 void setTex2LoadRate( int loadRate );
00139 SoDEPRECATED
00141 int getTex2LoadRate();
00142 SoDEPRECATED
00144 void setMinResolutionThreshold( int threshold = MIN_RES_THRESHOLD );
00145 SoDEPRECATED
00147 int getMinResolutionThreshold();
00148 SoDEPRECATED
00150 void setMaxResolutionThreshold( int threshold );
00151 SoDEPRECATED
00153 int getMaxResolutionThreshold();
00154
00155 #endif
00158 #if 1 SoDEPRECATED
00161 int getTileDimension();
00162
00163 #endif
00165 #if 1 SoDEPRECATED
00171 void setMaxMainMemory( int maxMainMemory );
00172 SoDEPRECATED
00177 int getMaxMainMemory();
00178 SoDEPRECATED
00180 void setMaxTexMemory( int maxTexMemoryMB );
00181 SoDEPRECATED
00183 int getMaxTexMemory();
00184 SoDEPRECATED
00189 int getMaxTilesInMainMem();
00190 SoDEPRECATED
00192 int getMaxTilesInTexMem();
00193 #endif
00195 #if 1 SoDEPRECATED
00205 void setTileHalfLife( float timeInSec );
00206 SoDEPRECATED
00211 float getTileHalfLife();
00212 SoDEPRECATED
00223 void setLoadPolicy( LoadPolicy loadPolicy );SoDEPRECATED
00228 LoadPolicy getLoadPolicy();
00229
00230
00231
00232
00233
00234
00235 SoDEPRECATED
00237 void setMovingTimeOut( float );
00238
00239
00240
00241
00242 SoDEPRECATED
00244 float getMovingTimeOut();
00245 SoDEPRECATED
00251 static void setTex2VVizLoadRate( int loadRate );
00252 SoDEPRECATED
00258 static int getTex2VVizLoadRate();
00259 SoDEPRECATED
00265 static void setTex3VVizLoadRate( int loadRate );
00266 SoDEPRECATED
00272 static int getTex3VVizLoadRate();
00273 SoDEPRECATED
00280 static void setMaxVVizMainMemory( int maxMainMemoryMB );
00281 SoDEPRECATED
00288 static void setMaxVVizTexMemory( int maxTexMemoryMB );
00289 SoDEPRECATED
00294 static int getMaxVVizMainMemory();
00295 SoDEPRECATED
00300 static int getMaxVVizTexMemory();
00301 SoDEPRECATED
00307 static void setNumIO( unsigned int numIO );
00308 SoDEPRECATED
00314 static unsigned int getNumIO();
00315 SoDEPRECATED
00322 static void setLoadNotificationRate( int rate );
00323 SoDEPRECATED
00328 static int getLoadNotificationRate();
00329
00330 #endif
00332 private:
00333 float m_decreaseWeightFactor;
00334 float getDecreaseWeightFactor() {return m_decreaseWeightFactor;};
00335
00339 void setTileSize( SbVec3i32 tileDim );
00340
00344 void setDataSize( int dataSize );
00345
00349 void setVolumeDim( const SbVec3i32& dim );
00350
00351 int getNumTileToTime();
00352
00353
00354
00355
00356
00357
00358 enum State
00359 {
00360 NO_UPDATE = 0x00,
00361 CPU_MEM_UPDATED = 0x01,
00362 GPU_MEM_UPDATED = 0x02,
00363 GPU_2D_UPDATED = 0x04,
00364 LOADRATE_2D_UPDATED = 0x08,
00365 LOADRATE_3D_UPDATED = 0x10,
00366 LOAD_RATE_UPDATED = 0x20,
00367 UPDATE_ALL = 0xFF
00368 };
00369
00370
00371 virtual void updateResources(unsigned short resourceState);
00372
00373
00374 int getMaxMainMemoryInKB() const;
00375 int getMaxTexMemoryInKB() const;
00376
00377
00378
00379
00380 int getSumOfMaxTilesInTexMem();
00381 int getSumOfTex3LoadRate();
00382 int getSumOfMax2DTextures();
00383 int getSumOfTex2LoadRate();
00384 void getSumOfMemAndTileSize(uint64_t &memByte, int& tileSize);
00385 void getSumOfNumTileInMem( uint64_t &maxTileInMem );
00386
00387 static void computeInternalCounters(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00388 static void shareSpareResources(const std::vector<SoLDMResourceManager*>& rsToUpdate,
00389 size_t spareAmount, SoLDMResourceManager::State resourceType);
00390
00391
00392
00393
00394
00395
00396
00397 void allocateGPUResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00398 void allocateCPUResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00399 void allocateGPU2DResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00400 void allocateTex2LoadRate(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00401 void allocateTex3LoadRate(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00402
00403 void setIdealTextFrontCb( SoLDMTexFrontCB *func, void* userData = NULL);
00404 void idealTexFrontReached();
00405 SoLDMTexFrontCB* m_callbackFunc;
00406 void* m_userData;
00407 SoDataSet* getDataSet() { return m_ds; };
00408
00412 static uint64_t getMaxVViz2DTexMemory();
00413
00417 static void setMaxVViz2DTexMemory(uint64_t maxMemory);
00418
00422 void setMax2DTexMemory(int max2DTexMemory);
00423
00427 int getMax2DTexMemory();
00428
00430 void enableTileBorders( bool enableTileBorders );
00431
00433 bool areTileBordersEnabled() const
00434 {
00435 return m_tileBordersEnabled;
00436 }
00437
00439 void setMinTilesToLoad( int minTilesToLoad );
00440
00442 int getMinTilesToLoad() const
00443 {
00444 return m_minTilesToLoad;
00445 }
00446
00448 void setViewpointRefinement( SoLDMResourceParameters::ViewpointRefinementPolicy viewportRefinementPolicy );
00449
00451 bool getViewpointRefinement() const;
00452
00454 void setScreenResolutionCulling(SoLDMResourceParameters::ScreenResolutionCullingPolicy screenResolutionCullingPolicy);
00455
00457 bool getScreenResolutionCulling() const;
00458
00459 private:
00460
00461 int m_minResThreshold;
00462 int m_maxResThreshold;
00463
00464 bool m_tileBordersEnabled;
00465 int m_minTilesToLoad;
00466 SoLDMResourceParameters::ViewpointRefinementPolicy m_viewpointRefinementPolicy;
00467 SoLDMResourceParameters::ScreenResolutionCullingPolicy m_screenResolutionCullingPolicy;
00468
00469
00470 friend class SoLDMMultiIOTileManager;
00471 friend class SoLDMMediator;
00472
00473
00474 static void updateNumTilesInMainMem();
00475
00477 static void updateMaxMainMem();
00478
00480 static void updateSumMax2DTextures();
00481
00486 static const std::vector<SoLDMResourceManager*>& getRSToUpdate();
00487
00489
00490 static int s_maxVVizTexMemoryKB;
00491
00492 int m_maxTexMemoryKB;
00493
00494 int m_numTilesInTexMem;
00495
00496 static void updateNumTilesInTexMem();
00497
00499 static void updateMaxTexMem();
00500
00501
00502
00503
00504 static void checkParametersConsistency(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00505
00507
00508 static int s_tex3VVizLoadRate;
00509 int m_tex3LoadRate;
00510
00511
00512
00513 static uint64_t s_maxVViz2DTexMemory;
00514 uint64_t m_num2DTextures;
00515
00516
00517 static int s_tex2VVizLoadRate;
00518 int m_tex2LoadRate;
00519
00520
00521
00522 static int s_maxVVizMainMemoryKB;
00523 int m_maxMainMemoryKB;
00524
00525 int m_numTilesInMainMem;
00526
00527 static int s_loadNotificationRate;
00528 static int s_memToLoad;
00529
00530
00531 static unsigned int s_numIO;
00532 static SbBool s_isMultiIO;
00533
00534
00535 SbVec3i32 m_tileDimension;
00536 int m_dataSize;
00537 int m_texelSize;
00538
00539
00540
00541
00542 SbVec3i32 m_volDim;
00543
00544
00545
00546 static std::vector<SoLDMResourceManager*> s_resourceManagers;
00547
00548
00549
00550 SoLDMTopoOctree m_topoOctree;
00551
00552 float getDataTileSizeInKB();
00553 float getTexTileSizeInByte(bool is3DTile = false);
00554
00555
00556
00557 void adjustMemPerDataset(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00558
00559 SoDataSet* m_ds;
00560
00561
00562 int m_getSumOfMaxTilesInTexMemAdjusted;
00563 int m_getSumOfMaxTilesInTexMem;
00564
00569 size_t m_maxNeededMemKB;
00570
00571
00572
00573 static std::vector<SoLDMResourceManager*> s_rsToUpdate;
00574
00575
00576 static std::map<SoLDMMediator*, int> s_maskPerMediator;
00577
00578
00579
00580
00581
00582 static size_t s_nbVolumeData;
00583
00584
00585
00586 static size_t s_gpuMemPerDataSetKB;
00587
00588
00589
00590 static size_t s_cpuMemPerDataSetKB;
00591
00592
00593
00594 static uint64_t s_2DGpuTexMemoryPerDataSetMB;
00595
00596
00597
00598 static size_t s_tex2LoadRatePerDataSet;
00599
00600
00601
00602 static size_t s_tex3LoadRatePerDataSet;
00603
00604
00605 static size_t s_spareGpuMemoryKB;
00606
00607
00608 static size_t s_spareCpuMemoryKB;
00609
00610
00611 static size_t s_spareTex2LoadRate;
00612
00613
00614 static size_t s_spareTex3LoadRate;
00615
00616
00617 static bool s_debugResourceValues;
00618
00623 static SbThreadMutex s_globalResourcesMutex;
00624 };
00625
00626
00627 #ifdef _MSC_VER
00628 #pragma warning( pop )
00629 #endif
00630
00631 #endif // _SO_LDM_RESOURCE_MANAGER_
00632
00633
00634