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 <Inventor/SbVec.h>
00034 #include <Inventor/STL/vector>
00035 #include <LDM/SoLDMTopoOctree.h>
00036 #define MIN_RES_THRESHOLD 10000 //high number meaning not set
00037
00038 class SoDataSet;
00039
00040
00041 typedef void SoLDMTexFrontCB (void *userData);
00042
00069 SoEXTENDER_Documented class SoLDMResourceManager : public SoLDMLargeDataManagement
00070 {
00071 public:
00075 SoLDMResourceManager(SoDataSet* ds);
00076
00080 virtual ~SoLDMResourceManager();
00081
00082 private:
00086 void setTileSize( SbVec3i32 tileDim );
00087
00091 SbVec3i32 getTileSize() const;
00092
00096 void setDataSize( int dataSize );
00100 int getDataSize();
00104 void setTexelSize( int texelSize );
00108 int getTexelSize();
00112 void setVolumeDim( const SbVec3i32& dim );
00116 SbVec3i32 getVolumeDim();
00122 void fixParams( SbBool flag);
00126 SbBool isParamsFixed();
00127
00128
00130
00131 enum LoadPolicy {
00132 NO_USER_INTERACTION,
00133 ALWAYS,
00134 NEVER
00135 };
00136
00137 static void setMonitoringAmount(int);
00138 static int getMonitoringAmount();
00139
00145 static void setMultiIO(SbBool on);
00150 static SbBool getMultiIO();
00151
00156 void invalidateData();
00157
00163 static void setMaxVViz2DTextures(int numTextures);
00164
00168 static int getMaxVViz2DTextures();
00169
00170
00171 #if 1 SoDEPRECATED
00174 int getTileDimension();
00175 SoDEPRECATED
00177 void setTileSize(int dim);
00178 SoDEPRECATED
00183 void setOverlapping(int) {};
00184 SoDEPRECATED
00189 inline int getOverlapping() { return 0; }
00190 SoDEPRECATED
00192 void setVolumeDim(const SbVec3s& dim)
00193 {
00194 SbVec3i32 dimI32(dim[0], dim[1], dim[2]);
00195 setVolumeDim(dimI32);
00196 }
00197 #endif
00199 #if 1 SoDEPRECATED
00206 static void setTex2VVizLoadRate( int loadRate );
00207 SoDEPRECATED
00213 static int getTex2VVizLoadRate();
00214 SoDEPRECATED
00220 static void setTex3VVizLoadRate( int loadRate );
00221 SoDEPRECATED
00227 static int getTex3VVizLoadRate();
00228 SoDEPRECATED
00235 static void setMaxVVizMainMemory( int maxMainMemoryMB );
00236 SoDEPRECATED
00243 static void setMaxVVizTexMemory( int maxTexMemoryMB );
00244 SoDEPRECATED
00249 static int getMaxVVizMainMemory();
00250 SoDEPRECATED
00255 static int getMaxVVizTexMemory();
00256 SoDEPRECATED
00262 static void setNumIO( unsigned int numIO );
00263 SoDEPRECATED
00269 static unsigned int getNumIO();
00270 SoDEPRECATED
00277 static void setLoadNotificationRate( int rate );
00278 SoDEPRECATED
00283 static int getLoadNotificationRate();
00284 SoDEPRECATED
00295 void setLoadPolicy( LoadPolicy loadPolicy );
00296 SoDEPRECATED
00301 LoadPolicy getLoadPolicy();
00302
00303
00304
00305
00306
00307
00308 SoDEPRECATED
00310 void setMovingTimeOut( float );
00311
00312
00313
00314
00315 SoDEPRECATED
00317 float getMovingTimeOut();
00318 SoDEPRECATED
00327 void setTileHalfLife( float timeInSec );
00328 SoDEPRECATED
00333 float getTileHalfLife();
00334
00335 #endif
00337 #if 1 SoDEPRECATED
00343 void setMaxMainMemory( int maxMainMemory );
00344 SoDEPRECATED
00349 int getMaxMainMemory();
00350 SoDEPRECATED
00355 void setMaxTilesInMainMem( int numTiles );
00356 SoDEPRECATED
00361 int getMaxTilesInMainMem();
00362 SoDEPRECATED
00364 void setMaxTexMemory( int maxTexMemoryMB );
00365 SoDEPRECATED
00367 int getMaxTexMemory();
00368 SoDEPRECATED
00370 void setMaxTilesInTexMem( int numTiles );
00371 SoDEPRECATED
00373 int getMaxTilesInTexMem();
00374
00375 #endif
00377 #if 1 SoDEPRECATED
00380 void setTex3LoadRate( int loadRate );
00381 SoDEPRECATED
00383 int getTex3LoadRate();
00384 SoDEPRECATED
00386 void setMax2DTextures(int numTextures);
00387 SoDEPRECATED
00389 int getMax2DTextures();
00390 SoDEPRECATED
00392 void setTex2LoadRate(int loadRate);
00393 SoDEPRECATED
00395 int getTex2LoadRate();
00396
00397 SoDEPRECATED
00399 void setMinResolutionThreshold(int threshold = MIN_RES_THRESHOLD);
00400 SoDEPRECATED
00402 int getMinResolutionThreshold();
00403 SoDEPRECATED
00405 void setMaxResolutionThreshold(int threshold);
00406 SoDEPRECATED
00408 int getMaxResolutionThreshold();
00409 #endif
00411 private:
00412
00413 float m_decreaseWeightFactor;
00414 float m_tileHalfLife;
00415 float getDecreaseWeightFactor() { return m_decreaseWeightFactor; };
00416
00417 #if 1 SoDEPRECATED
00424 static void setMaxVVizNumTriangles(int numTriangles);
00425 SoDEPRECATED
00430 static int getMaxVVizNumTriangles();
00431 SoDEPRECATED
00434 void setMaxNumTriangles(int numTriangles);
00435 #endif
00440 inline void setDataSet(SoDataSet* ds);
00441
00442 int getNumTileToTime();
00443
00444
00445
00446
00447
00448
00449 enum State
00450 {
00451 NO_UPDATE = 0x00,
00452 CPU_MEM_UPDATED = 0x01,
00453 GPU_MEM_UPDATED = 0x02,
00454 GPU_2D_UPDATED = 0x04,
00455 LOADRATE_2D_UPDATED = 0x08,
00456 LOADRATE_3D_UPDATED = 0x10,
00457 MAX_TRIANGLES_UPDATED = 0x20,
00458 LOAD_RATE_UPDATED = 0x40,
00459 UPDATE_ALL = 0xFF
00460 };
00461
00462
00463 virtual void updateResources(unsigned short resourceState);
00464
00465
00466 int getMaxMainMemoryInKB() const;
00467 int getMaxTexMemoryInKB() const;
00468
00469
00470
00471
00472 int getSumOfMaxTilesInTexMem();
00473 int getSumOfTex3LoadRate();
00474 int getSumOfMax2DTextures();
00475 int getSumOfTex2LoadRate();
00476 void getSumOfMemAndTileSize(uint64_t &memByte, int& tileSize);
00477 void getSumOfNumTileInMem( uint64_t &maxTileInMem );
00478 unsigned int getSumOfMaxNumTriangles();
00479 int getMaxNumTriangles();
00480
00481 static void computeInternalCounters(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00482 static void shareSpareResources(const std::vector<SoLDMResourceManager*>& rsToUpdate,
00483 size_t spareAmount, SoLDMResourceManager::State resourceType);
00484
00485
00486
00487
00488
00489
00490
00491 void allocateGPUResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00492 void allocateCPUResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00493 void allocateGPU2DResources(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00494 void allocateTex2LoadRate(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00495 void allocateTex3LoadRate(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00496 void allocateMaxTriangles(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00497
00498 void setIdealTextFrontCb( SoLDMTexFrontCB *func, void* userData = NULL);
00499 void idealTexFrontReached();
00500 SoLDMTexFrontCB* m_callbackFunc;
00501 void* m_userData;
00502 SoDataSet* getDataSet() { return m_ds; };
00503 bool checkMaxTile() { return m_checkMaxTile; };
00504
00508 static uint64_t getMaxVViz2DTexMemory();
00509
00513 static void setMaxVViz2DTexMemory(uint64_t maxMemory);
00514
00518 void setMax2DTexMemory(int max2DTexMemory);
00519
00523 int getMax2DTexMemory();
00524
00525
00526
00527 private:
00528
00529 static std::vector<SoLDMResourceManager*> s_resourceManagers;
00530
00531 LoadPolicy m_loadPolicy;
00532 float m_movingTimeOut;
00533
00534
00535 static int s_loadNotificationRate;
00536 static int s_memToLoad;
00537
00538
00539 static unsigned int s_numIO;
00540 static SbBool s_isMultiIO;
00541
00543
00544 SbVec3i32 m_tileDimension;
00545 int m_dataSize;
00546 int m_texelSize;
00547
00548
00549
00550
00551 SbVec3i32 m_volDim;
00552 SbBool m_isParamsFixed;
00553
00555
00556 static int s_maxVVizMainMemoryKB;
00557 int m_maxMainMemoryKB;
00558
00559 int m_numTilesInMainMem;
00560
00561
00562 static void updateNumTilesInMainMem();
00563
00565 static void updateMaxMainMem();
00566
00568 static void updateSumMax2DTextures();
00569
00574 static const std::vector<SoLDMResourceManager*>& getRSToUpdate();
00575
00577
00578 static int s_maxVVizTexMemoryKB;
00579
00580 int m_maxTexMemoryKB;
00581
00582 int m_numTilesInTexMem;
00583
00584 static void updateNumTilesInTexMem();
00585
00587 static void updateMaxTexMem();
00588
00589
00590
00591
00592 static void checkParametersConsistency(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00593
00595
00596 static int s_tex3VVizLoadRate;
00597 int m_tex3LoadRate;
00598
00599
00601
00602 static uint64_t s_sumMaxVViz2DTexMemory;
00603 static uint64_t s_maxVViz2DTexMemory;
00604 uint64_t m_num2DTextures;
00605
00607
00608 static int s_tex2VVizLoadRate;
00609 int m_tex2LoadRate;
00610
00612
00613 int m_minResThreshold;
00614 int m_maxResThreshold;
00615
00616
00617 SoLDMTopoOctree m_topoOctree;
00618
00619 float getDataTileSizeInKB();
00620 float getTexTileSizeInByte(bool is3DTile = false);
00621
00622
00623
00624 void adjustMemPerDataset(const std::vector<SoLDMResourceManager*>& rsToUpdate);
00625
00626 SoDataSet* m_ds;
00627
00629 static int s_maxVVizNumTriangles;
00630
00632 static int s_sumMaxVVizNumTriangles;
00633
00635 int m_maxNumTriangles;
00636
00641 bool m_checkMaxTile;
00642
00643
00644 int m_getSumOfMaxTilesInTexMemAdjusted;
00645 int m_getSumOfMaxTilesInTexMem;
00646
00651 size_t m_maxNeededMemKB;
00652
00653
00654
00655 static std::vector<SoLDMResourceManager*> s_rsToUpdate;
00656
00657
00658 static std::map<SoLDMMediator*, int> s_maskPerMediator;
00659
00660
00661
00662
00663
00664 static size_t s_nbVolumeData;
00665
00666
00667
00668 static size_t s_gpuMemPerDataSetKB;
00669
00670
00671
00672 static size_t s_cpuMemPerDataSetKB;
00673
00674
00675
00676 static uint64_t s_2DGpuTexMemoryPerDataSetMB;
00677
00678
00679
00680 static size_t s_tex2LoadRatePerDataSet;
00681
00682
00683
00684 static size_t s_tex3LoadRatePerDataSet;
00685
00686
00687
00688 static size_t s_maxNumTrianglesPerDataSet;
00689
00690
00691 static size_t s_spareGpuMemoryKB;
00692
00693
00694 static size_t s_spareCpuMemoryKB;
00695
00696
00697 static size_t s_spareTex2LoadRate;
00698
00699
00700 static size_t s_spareTex3LoadRate;
00701
00702
00703 static size_t s_spareMaxNumTriangles;
00704
00705
00706 static bool s_debugResourceValues;
00707
00712 static SbThreadMutex s_globalResourcesMutex;
00713 };
00714
00715
00716 void
00717 SoLDMResourceManager::setDataSet(SoDataSet* ds)
00718 {
00719 m_ds = ds;
00720 }
00721
00722
00723 #ifdef _MSC_VER
00724 #pragma warning( pop )
00725 #endif
00726
00727 #endif // _SO_LDM_RESOURCE_MANAGER_
00728
00729
00730