00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LDM_DATA_ACCESS_H
00024 #define LDM_DATA_ACCESS_H
00025
00026 #include <Inventor/SbLinear.h>
00027 #include <Inventor/SbBox.h>
00028 #include <LDM/SoLDMTileID.h>
00029
00030 #include <Inventor/STL/vector>
00031 #include <Inventor/STL/map>
00032
00033 #include <Inventor/devices/SoBufferObject.h>
00034 #include <Inventor/devices/SoCpuBufferObject.h>
00035
00036 #include <LDM/nodes/SoLDMResourceParameters.h>
00037
00038 #ifdef _MSC_VER
00039 #pragma warning( push )
00040 #pragma warning(disable:4251)
00041 #endif
00042
00043 class SoDataSet;
00044 class SoLDMMediator;
00045 class SoPerfCounter;
00046 class SoPerfCounterManager;
00047 class SoCpuBufferObject;
00048 class SbThread;
00049 class SbThreadBarrier;
00050 class SoLDMAlgorithms;
00051
00052
00247 class SoLDMDataAccess {
00248
00249 public:
00250
00256 SoLDMDataAccess();
00257
00261 virtual ~SoLDMDataAccess();
00262
00266 void setDataSet(SoDataSet* v);
00267
00271 inline SoDataSet* getDataSet();
00272
00274 enum ErrorValue
00275 {
00277 CORRECT,
00279 INCORRECT_RESOLUTION,
00281 INCORRECT_SUBVOLUME,
00283 INCORRECT_LINE,
00285 INCORRECT_POLYLINE,
00287 INCORRECT_PLANE,
00289 INCORRECT_POSITION,
00291 INCORRECT_COORDINATE,
00293 MEMORY_FULL,
00295 REQUEST_NOT_COMPLETED,
00297 REQUEST_NOT_FOUND,
00303 INCORRECT_BUFFER
00304 };
00305
00311 enum GetDataMode
00312 {
00314 CACHE,
00317 DIRECT,
00320 DIRECT_AND_PREFETCH
00321 };
00322
00332 struct DataInfoBox
00333 {
00337 ErrorValue errorFlag;
00339 int64_t bufferSize;
00343 SbVec3i32 bufferDimension;
00344 };
00345
00355 struct DataInfoTrace
00356 {
00360 ErrorValue errorFlag;
00362 int64_t bufferSize;
00365 int bufferDimension;
00366 };
00367
00377 struct DataInfoLine
00378 {
00382 ErrorValue errorFlag;
00384 int64_t bufferSize;
00386 int bufferDimension;
00388 SbVec3i32 lineCoord[2];
00389 };
00400 class DataInfoPolyLine
00401 {
00402 public:
00403
00405 DataInfoPolyLine(int numPoint);
00406 virtual ~DataInfoPolyLine();
00407
00409 DataInfoPolyLine(const DataInfoPolyLine& A);
00410 void operator=(const DataInfoPolyLine& A);
00411
00415 ErrorValue errorFlag;
00416
00418 int64_t bufferSize;
00419
00421 int numSegment;
00422
00425 int* segmentBufferDim;
00426
00429 int* segmentBufferSize;
00430
00436 SbVec3i32** segmentCoord;
00437
00438 private:
00439 private:
00440
00441 DataInfoPolyLine();
00442 void free();
00443 void commonConstructor();
00444 void allocate(int numPoint);
00445 };
00446
00456 struct DataInfoPlane
00457 {
00461 ErrorValue errorFlag;
00463 int64_t bufferSize;
00465 SbVec2i32 bufferDimension;
00470 int numPolygonPoints;
00472 SbVec3i32 polygonCoord[6];
00474 SbVec3i32 quadCoord[4];
00478 int uAxis;
00482 int vAxis;
00483 };
00484
00491 struct DataInfo
00492 {
00496 ErrorValue errorFlag;
00498 SoLDMTileID tileID;
00500 SbVec3i32 tileDimension;
00503 SbBox3i32 tilePosition;
00505 int64_t bufferSize;
00510 void* tileData;
00511 };
00512
00525 DataInfoBox getData(int resolution, const SbBox3i32& subVolume0, SoBufferObject* bufferObj = NULL);
00526
00539 DataInfoPlane getData(int resolution, const SbBox3i32& subVolume0, const SbPlane& plane,
00540 SoBufferObject* bufferObj = NULL);
00541
00554 DataInfoLine getData(int resolution, const SbBox3i32& subVolume0, const SbLine& line , SoBufferObject* bufferObj = NULL) ;
00555
00570 DataInfoTrace getData( int resolution, const SbBox3i32& subVolume, const SbVec2i32 coord,
00571 SoBufferObject* bufferObj = NULL);
00572
00585 void getData(DataInfoPolyLine& infoPolyline, int resolution, const SbBox3i32& subVolume, int numPoints,
00586 const SbVec3i32* polyline, SoBufferObject* bufferObj = NULL);
00587
00642 DataInfo getData(int resolution, const SbVec3i32& dataPosition);
00643
00649 void releaseData(SoLDMTileID tileID);
00650
00659 SbBool isTileUniform(int resolution, const SbVec3i32& dataPosition, double& uniformValue);
00660
00662
00664
00686 int requestData(int resolution, const SbBox3i32& box, SoBufferObject* bufferObj);
00687
00691 void getRequestedData(int requestId, DataInfoBox& infoBox);
00692
00712 int requestData(int resolution, const SbBox3i32& subVolume, const SbPlane& plane, SoBufferObject* bufferObj);
00713
00717 void getRequestedData(int requestId, DataInfoPlane& infoPlane);
00718
00738 int requestData(int resolution, const SbBox3i32& subVolume0, const SbLine& line , SoBufferObject* bufferObj);
00739
00743 void getRequestedData(int requestId, DataInfoLine& infoLine);
00744
00765 int requestData(int resolution, const SbBox3i32& subVolume, int numPoints, const SbVec3i32* polyline, SoBufferObject* bufferObj);
00766
00770 void getRequestedData(int requestId, DataInfoPolyLine& infoPolyline);
00771
00794 int requestData(int resolution, const SbBox3i32& subVolume0, const SbVec2i32& coord, SoBufferObject* bufferObj);
00795
00799 void getRequestedData(int requestId, DataInfoTrace& infoTrace);
00800
00807 virtual void endRequest(int requestId);
00808
00812 SbVec3f voxelToXYZ(const SbVec3i32 &dataPosition);
00813
00817 SbVec3i32 XYZToVoxel(const SbVec3f &dataPosition);
00818
00824 bool setGetDataMode (const GetDataMode getDataMode);
00825
00829 GetDataMode getGetDataMode();
00830
00831
00832 #if 1 SoDEPRECATED
00838 DataInfoBox getData(int resolution, const SbBox3i32& subVolume, void* buffer);
00839 SoDEPRECATED
00844 DataInfoPlane getData(int resolution, const SbBox3i32& subVolume, const SbPlane& plane,
00845 void* buffer);
00846 SoDEPRECATED
00851 DataInfoLine getData(int resolution, const SbBox3i32& subVolume, const SbLine& line , void* buffer);
00852 SoDEPRECATED
00857 DataInfoTrace getData(int resolution, const SbBox3i32& subVolume, const SbVec2i32 coord,
00858 void* buffer );
00859 SoDEPRECATED
00864 void getData(DataInfoPolyLine& infoPolyline, int resolution, const SbBox3i32& subVolume, int numPoints,
00865 const SbVec3i32* polyline, void* buffer);
00866 SoDEPRECATED
00871 int requestData(int resolution, const SbBox3i32& subVolume, void* buffer);
00872 SoDEPRECATED
00877 int requestData(int resolution, const SbBox3i32& subVolume, const SbPlane& plane, void* buffer);
00878 SoDEPRECATED
00883 int requestData(int resolution, const SbBox3i32& subVolume, const SbLine& line, void* buffer);
00884 SoDEPRECATED
00889 int requestData(int resolution, const SbBox3i32& subVolume, int numPoints, const SbVec3i32* polyline, void* buffer);
00890 SoDEPRECATED
00895 int requestData(int resolution, const SbBox3i32& subVolume, const SbVec2i32& coord, void* buffer);
00896
00897 #endif
00899 private:
00900
00901 void initPerfCounters();
00902 void resetPerfCounters();
00903 bool intersectWith(const SbBox3i32 &, const SbBox3i32 &, SbBox3i32 &);
00904 int intersectWith(const SbBox3i32 &, const SbPlane &, int, SbVec3i32 [], SbVec3i32 []) const;
00905 bool intersectWith(const SbBox3i32 &, const SbLine &, SbVec3i32 []) const;
00906 int getZaxis(const SbVec3f &) const;
00907 void copyData(unsigned short dataSetId, SoLDMTileID tile, SoBufferObject* tileBufferObj, int tileIndex);
00908 void copyData(unsigned short dataSetId, SoLDMTileID tile, SoBufferObject* tileBufferObj, int tileIndex, int requestId, bool canRelease=true);
00909 void requestNotCompleted(int requestId);
00910 std::vector<SoLDMTileID> getRequestedTiles(int requestId);
00911 SoDataSet* getRequestingDataSet(int requestId);
00912 bool isTileToPrefecth(const SoLDMTileID &tileId);
00913 void removeTileFromPrefetch(const SoLDMTileID &tileId);
00914 SbThreadBarrier* getDataAccessBarrier();
00915 SbThreadBarrier* getReaderThreadBarrier();
00916
00917
00918 enum CopyWhat{
00919 COPY_BOX,
00920 COPY_PLANE,
00921 COPY_LINE,
00922 COPY_SINGLE,
00923 COPY_TRACE
00924 };
00925
00926 CopyWhat getTypeOfCopy () { return m_copyInfo.copyWhat;};
00927
00928 private:
00929 int clipSegment(const SbVec3i32 &, const SbVec3i32 &, SbVec3i32 *, int, const SbVec3i32 &, const SbVec3i32 &) const;
00930
00931
00932 void checkBox(int& _max, int& _min, int volBox);
00933 SbBox3i32 getBox(SbVec3i32 p1, SbVec3i32 p2, SbBox3i32 volBox);
00934
00935
00936
00937 struct CopyInfo {
00938 public:
00939 CopyInfo()
00940 { reset(); }
00941
00942
00943 void reset()
00944 {
00945 destBufferObj = NULL;
00946 userCpuObj = NULL;
00947 vmin = SbVec3i32(0,0,0);
00948 vmax = SbVec3i32(0,0,0);
00949 tileDim = -1;
00950 dataSize = -1;
00951 subVolume.makeEmpty();
00952 resolution = -1;
00953 copyWhat = COPY_SINGLE;
00954 qmin = SbVec2i32(0,0);
00955 qmax = SbVec2i32(0,0);
00956 normal = SbVec3f(0,0,0);
00957 distance = -1;
00958 Zaxis = -1;
00959 voxelsToCopy = NULL;
00960
00961
00962 tiles.clear();
00963 tilesFromDisk.clear();
00964 tilesToPrefetch.clear();
00965 tilesInfos.clear();
00966 tilesIndex.clear();
00967 ldmDataAccess = NULL;
00968 dataSet = NULL;
00969 loadPolicy = SoLDMResourceParameters::NEVER;
00970 requestSize = -1;
00971 requestId = -1;
00972 shouldCallback = false;
00973 dataInfoPolyline = NULL;
00974 dataInfoLine = NULL;
00975 dataInfoPlane = NULL;
00976 dataInfoBox = NULL;
00977 dataInfoTrace = NULL;
00978 }
00979
00980 public:
00981 SoRef<SoBufferObject> destBufferObj;
00982 SoRef<SoCpuBufferObject> userCpuObj;
00983 SbVec3i32 vmin;
00984 SbVec3i32 vmax;
00985 int tileDim;
00986 int dataSize;
00987 SbBox3i32 subVolume;
00988 int resolution;
00989 CopyWhat copyWhat;
00990 SbVec2i32 qmin;
00991 SbVec2i32 qmax;
00992 SbVec3f normal;
00993 float distance;
00994 SbPlane plane;
00995 int Zaxis;
00996 SbVec2i32 bufDim;
00997 std::vector< std::vector<SbVec2i32> >* voxelsToCopy;
00998
00999 std::vector<SoLDMTileID> tiles;
01000 std::vector<SoLDMTileID> tilesFromDisk;
01001 std::vector<SoLDMTileID> tilesToPrefetch;
01002 std::map<int64_t, SbVec3i32> tilesInfos;
01003 std::map<int64_t, int> tilesIndex;
01004 SoLDMDataAccess* ldmDataAccess;
01005 SoDataSet* dataSet;
01006 SoLDMResourceParameters::LoadPolicy loadPolicy;
01007 int64_t requestSize;
01008 int requestId;
01009 bool shouldCallback;
01010 DataInfoPolyLine* dataInfoPolyline;
01011 DataInfoLine* dataInfoLine;
01012 DataInfoPlane* dataInfoPlane;
01013 DataInfoBox* dataInfoBox;
01014 DataInfoTrace* dataInfoTrace;
01015 } m_copyInfo;
01016
01017
01018 private:
01019 enum threadType
01020 { NONE = 0,
01021 PLANE,
01022 BOX,
01023 TRACES,
01024 LINE,
01025 POLYLINE
01026 };
01027
01031 SoLDMDataAccess& operator=(const SoLDMDataAccess& ldmDa);
01032 SoLDMDataAccess(const SoLDMDataAccess& );
01033
01034 SoDataSet *m_dataSet;
01035 SoLDMMediator *m_mediator;
01036
01037 std::map<int, CopyInfo> m_requests;
01038
01039
01040 bool getRequestInfo(int resolution, const SbBox3i32& subVolume0, SoBufferObject *bufferObj, DataInfoBox& info, CopyInfo& copyInfo);
01041
01042 bool getRequestInfo(int resolution, const SbBox3i32& subVolume0, const SbPlane& plane, SoBufferObject *bufferObj,
01043 SoLDMDataAccess::DataInfoPlane& info, SoLDMDataAccess::CopyInfo& copyInfo);
01044
01045 bool getRequestInfo(int resolution, const SbBox3i32& subVolume0, const SbLine& line, SoBufferObject *bufferObj,
01046 SoLDMDataAccess::DataInfoLine& info, SoLDMDataAccess::CopyInfo& copyInfo);
01047
01048 bool getRequestInfo(int resolution, const SbBox3i32& subVolume0, const SbVec2i32 coord, SoBufferObject *bufferObj,
01049 SoLDMDataAccess::DataInfoTrace& info, SoLDMDataAccess::CopyInfo& copyInfo);
01050
01051
01052 void copyData(unsigned short , SoLDMTileID tile, SoBufferObject* tileBufferObj, int tileIndex, SoLDMDataAccess::CopyInfo& copyInfo);
01053
01054 static void *readTraceFromDiskThreadRoutine(void* userData);
01055 static void *readSliceFromDiskThreadRoutine(void* userData);
01056 static void *readTilesFromDiskThreadRoutine(void* userData);
01057 void readSliceInTile(SoLDMDataAccess* dataAccess, int fileID, SbBox3i32& tilePos, int& sliceNumber, SoBufferObject* destBuffer );
01058 void buildPlane(SoLDMDataAccess* dataAccess, int firstAxis, int secondAxis, int sliceNumber);
01059 bool createThreadReadDisk(SoLDMDataAccess::threadType threadType);
01060 void updateTilesLists(SoLDMDataAccess::CopyInfo& copyInfo);
01061 void checkGetDataMode (const SoLDMDataAccess::CopyWhat copyWhat);
01062
01063 enum RequestState {
01064 NOT_FOUND,
01065 OK
01066 };
01067
01068 RequestState queryRequestState(int requestId);
01069
01070 int m_nextRequestId;
01071 int getNextRequestId();
01072
01073 SoPerfCounterManager* m_perf;
01074
01075
01076 SoPerfCounter* m_time_copy_data_trace;
01077 SoPerfCounter* m_time_copy_data_vol;
01078 SoPerfCounter* m_time_copy_data_plane;
01079
01080
01081 SoPerfCounter* m_time_tile_select_trace;
01082 SoPerfCounter* m_time_tile_select_vol;
01083 SoPerfCounter* m_time_tile_select_plane;
01084
01085 SoLDMAlgorithms* m_algorithms;
01086
01087 GetDataMode m_getDataMode;
01088
01089 SbThreadBarrier *m_readerBarrier;
01090 SbThreadBarrier *m_diskReadThreadBarrier;
01091 SbThread *m_diskReadThread;
01092 bool m_threadMustStop;
01093 threadType m_threadType;
01094
01095 static void checkBuffer(SoBufferObject* buffer);
01096
01097 private:
01098 CopyInfo& getCopyInfo();
01099 bool threadMustStop();
01100
01101 };
01102
01103
01104 inline SoDataSet*
01105 SoLDMDataAccess::getDataSet()
01106 {
01107 return m_dataSet;
01108 }
01109
01110 inline void
01111 SoLDMDataAccess::endRequest(int)
01112 {
01113 SoDebugError::post("SoLDMDataAccess::endRequest", "An asynchronous access has been made using first class SoLDMDataAccess. Please implement your own, overloading endRequest method.");
01114 }
01115
01116 inline SoLDMDataAccess::GetDataMode
01117 SoLDMDataAccess::getGetDataMode()
01118 {
01119 return m_getDataMode;
01120 }
01121
01122 inline SoLDMDataAccess::CopyInfo&
01123 SoLDMDataAccess::getCopyInfo()
01124 {
01125 return m_copyInfo;
01126 }
01127
01128 inline bool
01129 SoLDMDataAccess::threadMustStop()
01130 {
01131 return m_threadMustStop;
01132 }
01133
01134 inline SbThreadBarrier*
01135 SoLDMDataAccess::getDataAccessBarrier()
01136 {
01137 return m_readerBarrier;
01138 }
01139
01140 inline SbThreadBarrier*
01141 SoLDMDataAccess::getReaderThreadBarrier()
01142 {
01143 return m_diskReadThreadBarrier;
01144 }
01145
01146
01147 inline SoLDMDataAccess&
01148 SoLDMDataAccess::operator=(const SoLDMDataAccess& )
01149 {
01150 assert(0);
01151 return *this;
01152 }
01153
01154 #ifdef _MSC_VER
01155 #pragma warning( pop )
01156 #endif
01157
01158 #endif
01159
01160
01161