00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _SO_VOLUME_READER_
00024 #define _SO_VOLUME_READER_
00025
00026 #ifdef _MSC_VER
00027 #pragma warning( push )
00028 #pragma warning(disable:4251)
00029 #endif
00030
00031 #include <Inventor/nodes/SoNode.h>
00032 #include <Inventor/SoPreferences.h>
00033 #include <LDM/nodes/SoDataSet.h>
00034
00035 #include <Inventor/STL/vector>
00036 #include <Inventor/STL/map>
00037
00038 class SbThreadMutex;
00039 class SoVolumeWriter;
00242 class SoVolumeReader : public SoFieldContainer
00243 {
00244 SO_FIELDCONTAINER_ABSTRACT_HEADER(SoVolumeReader);
00245
00246 public:
00247
00251 enum ReadError {
00255 RD_NO_ERROR,
00259 RD_FILE_NOT_FOUND_ERROR,
00263 RD_INVALID_DATA_ERROR,
00267 RD_UNSUPPORTED_DATA_TYPE_ERROR,
00272 RD_FILE_FORMAT_NOT_VALID_ERROR,
00276 RD_UNKNOWN_ERROR
00277 } ;
00278
00283 enum Axis {
00284 X,
00285 Y,
00286 Z
00287 };
00288
00293 SoVolumeReader();
00294
00309 virtual ReadError getDataChar( SbBox3f &size, SoDataSet::DataType &type, SbVec3i32 &dim )=0;
00310
00317 virtual SbBool setOutputDataType( SbBool doChange, SoDataSet::DataType outputType );
00318
00327 virtual SbBool setInputDataRange( SbBool doChange, double min, double max );
00328
00338 virtual int getNumSignificantBits() { return 0; };
00339
00353 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, void * data )=0;
00354
00387 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, SoBufferObject * dataBuffer);
00388
00392 enum CopyPolicy
00393 {
00395 COPY,
00397 NO_COPY,
00399 NO_COPY_AND_DELETE
00400 };
00401
00416 SbVec3i32 getNumVoxels( const SbVec3i32& realSize, const SbVec3i32& subsamplingLevel );
00417
00427 SbVec3i32 getSizeToAllocate( const SbVec3i32& realSize, const SbVec3i32& subsamplingLevel );
00428
00433 virtual int setFilename( const SbString& filename );
00434
00438 SbString getFilename() const;
00439
00440
00449 virtual SbBool isDataConverted() const;
00450
00456 virtual SbBool getTileSize(SbVec3i32& size);
00457
00474 virtual SoBufferObject* readTile(int index, const SbBox3i32& tilePosition);
00475
00486 virtual SbBool readXTraceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const SbVec2i32& tracePosition);
00487
00498 virtual SbBool readYSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00499
00510 virtual SbBool readZSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00511
00522 virtual SbBool readXSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00523
00530 virtual SbBool isThreadSafe() const;
00531
00535 virtual SbBool isIgnoredFile() const;
00536
00540 inline int getNumSubsampledTiles()
00541 {return m_numSubsampledTiles;};
00542
00547 virtual SbString getOriginalFilename() const
00548 { return SbString(""); }
00549
00554 virtual SbBool getMinMax(int64_t & min, int64_t & max);
00555
00560 virtual SbBool getMinMax(double & min, double & max);
00561
00565 virtual SbBool getHistogram(std::vector<int64_t>& numVox);
00566
00574 virtual SbBool setDirectCoordSysAutoDetection(SbBool autoValue);
00578 virtual SbBool getDirectCoordSysAutoDetection();
00579
00586 virtual SbBool setDirectCoorSys(SbBool directCoord);
00587
00591 virtual SbBool getDirectCoordSys();
00592
00612 virtual SbVec2d getTileMinMax( int fileId ) const;
00613
00617 enum ReaderType {
00619 NO_READER,
00621 AM,
00623 AVS,
00625 DICOM,
00627 GENERIC,
00629 LDM,
00631 MEMORY,
00633 RASTERSTACK,
00635 SEGY,
00637 VOL,
00639 VOX,
00641 TIFF
00642 };
00643
00647 virtual ReaderType getReaderType (){return NO_READER;};
00648
00714 virtual SoVolumeWriter* getConfiguredWriter();
00715
00719 enum CoordinateType {
00723 COORDINATES_UNIFORM = 0,
00727 COORDINATES_RECTILINEAR
00728 };
00729
00733 CoordinateType getCoordinateType();
00734
00738 const float * getRectilinearCoordinates(Axis axis) const;
00739
00743 void setRectilinearCoordinates(const float *x, const float *y, const float *z);
00744
00749 virtual SbBool isRGBA() const
00750 { return m_isRGBA; }
00751
00755 inline void setRGBA(const SbBool flag)
00756 { m_isRGBA = flag; }
00757
00766 virtual void closeAllHandles() {};
00767
00771 virtual void restoreAllHandles() {};
00772
00784 static SoVolumeReader* getAppropriateReader(const SbString& filename);
00785
00786 #if 1 SoDEPRECATED
00789 virtual SbBool getSubVolume( const SbBox3i32& subVolume, void * data );
00790 SoDEPRECATED
00795 virtual SbBool getTileSize(SbVec3s& size)
00796 {
00797 SbVec3i32 sizeI32;
00798 SbBool rc = getTileSize( sizeI32 );
00799 size.setValue( (short)sizeI32[0], (short)sizeI32[1], (short)sizeI32[2] );
00800 return rc;
00801 };
00802 SoDEPRECATED
00804 virtual void getDataChar( SbBox3f &size, SoDataSet::DataType &type, SbVec3s &dim )
00805 {
00806 SbVec3i32 dimI32;
00807 getDataChar( size, type, dimI32 );
00808 dim.setValue( (short)dimI32[0], (short)dimI32[1], (short)dimI32[2] );
00809 };
00810 SoDEPRECATED
00812 SbVec3s getNumVoxels( const SbVec3s& realSize, const SbVec3s& subsamplingLevel )
00813 {
00814 SbVec3i32 realSizeI32( realSize[0], realSize[1], realSize[2] );
00815 SbVec3i32 subsamplingLevelI32( subsamplingLevel[0], subsamplingLevel[1], subsamplingLevel[2] );
00816 SbVec3i32 numVoxels = getNumVoxels( realSizeI32, subsamplingLevelI32 );
00817 return SbVec3s( (short)numVoxels[0], (short)numVoxels[1], (short)numVoxels[2] );
00818 };
00819 SoDEPRECATED
00821 SbVec3s getSizeToAllocate( const SbVec3s& realSize, const SbVec3s& subsamplingLevel )
00822 {
00823 SbVec3i32 realSizeI32( realSize[0], realSize[1], realSize[2] );
00824 SbVec3i32 subsamplingLevelI32( subsamplingLevel[0], subsamplingLevel[1], subsamplingLevel[2] );
00825 SbVec3i32 size = getSizeToAllocate( realSizeI32, subsamplingLevelI32 );
00826 return SbVec3s( (short)size[0], (short)size[1], (short)size[2] );
00827 };
00828 SoDEPRECATED
00830 virtual void getSubSlice( const SbBox2s& subSlice, int sliceNumber, void * data )
00831 {
00832 SbBox2i32 subSliceI32( subSlice.getMin()[0], subSlice.getMin()[1], subSlice.getMax()[0], subSlice.getMax()[1] );
00833 getSubSlice( subSliceI32, sliceNumber, data );
00834 };
00835 SoDEPRECATED
00837 virtual SbBool getSubVolume( const SbBox3s& subVolume, void * data );
00838 SoDEPRECATED
00840 virtual SbBool getSubVolume( const SbBox3s& subVolume, const SbVec3s& aSL, void *& data );
00841 SoDEPRECATED
00843 virtual SbBool getSubVolumeInfo( const SbBox3s& subVolume, const SbVec3s& rSL, SbVec3s& aSL, SoVolumeReader::CopyPolicy& policy);
00844 SoDEPRECATED
00846 virtual SbBool readTile( int index, unsigned char*&buffer, const SbBox3s& tilePosition );
00847
00848 #endif
00850 #if 1 SoDEPRECATED
00853 virtual void getNextSlice( int SO_UNUSED_PARAM(sliceNumber), void * SO_UNUSED_PARAM(data) ) {};
00854 SoDEPRECATED
00856 virtual void skipSlice( int SO_UNUSED_PARAM(numSlices) ) {};
00857 SoDEPRECATED
00859 virtual void end( ) {};
00860
00861 #endif
00863 #if 1 SoDEPRECATED
00893 virtual SbBool readTile(int SO_UNUSED_PARAM(index), unsigned char*& SO_UNUSED_PARAM(buffer), const SbBox3i32& SO_UNUSED_PARAM(tilePosition)) { return FALSE; }
00894 SoDEPRECATED
00901 virtual SbBool readTile(int index, SoBufferObject *buffer, const SbBox3i32& tilePosition);
00902
00903 #endif
00905 #if 1 SoDEPRECATED
00919 inline int getNumTimeSteps()
00920 { return 1; };
00921 SoDEPRECATED
00931 void setCurrentTimeStep( int )
00932 { };
00933 SoDEPRECATED
00941 inline int getCurrentTimeStep() const
00942 { return 0;}
00943 SoDEPRECATED
00948 virtual SbBool getSubVolumeInfo(
00949 const SbBox3i32& subVolume,
00950 const SbVec3i32& requestedSubsampleLevel,
00951 SbVec3i32& actualSubsampleLevel,
00952 SoVolumeReader::CopyPolicy& policy
00953 );
00954 SoDEPRECATED
00956 virtual SbBool getSubVolume(
00957 const SbBox3i32& subVolume,
00958 const SbVec3i32& actualSubsampleLevel,
00959 void *& data
00960 );
00961 SoDEPRECATED
00966 virtual int getBorderFlag()
00967 {return -1;}
00968
00969 #endif
00971 #if 1 SoDEPRECATED
00978 virtual SbBool getMinMax(int& min, int& max);
00979
00980 #endif
00982 private:
00983
00984
00985
00986 virtual ReadError getDataChar( SbBox3f &size, std::vector<SoDataSet::DatumElement>& datum, SbVec3i32 &dim );
00987
00988 void lockFileMutex();
00989 void unlockFileMutex();
00990 void setNumSubsampledTiles(int num){m_numSubsampledTiles = num;};
01000 void convert( SoDataSet::DataType typeIn , SoBufferObject* bufferIn,
01001 SoDataSet::DataType typeOut, SoBufferObject* bufferOut, int size, SbBool shiftData = true);
01002
01003 void convertDataRange( bool doRange, double min, double max );
01004
01005 virtual int getNumBytesPerDatum();
01006
01007 virtual bool isLDMReader() { return false; }
01008 virtual bool isVolumeMaskReader() { return false; }
01009
01010 virtual bool hasDeadCell() { return false; }
01011
01012 virtual bool isDead(int i,int j,int k);
01013
01014 virtual uint8_t* getCellGridState() { return NULL; }
01015
01016 virtual int getNbCell() { return 0; }
01017
01018 virtual uint64_t getTileSizeFromFid(int fileId);
01019
01020
01024 bool hasPerTileMinMaxComputed() const;
01025
01026 #if 1 SoDEPRECATED
01029 void convert( SoDataSet::DataType typeIn , void* bufferIn,
01030 SoDataSet::DataType typeOut, void* bufferOut, int size, SbBool shiftData = true);
01031
01032 #endif
01034 private: protected:
01035
01063 static bool registerVolumeReaderExtension(const SbString& fileExtension, const SoType& readerType);
01064
01074 static bool unregisterVolumeReaderExtensions(const SoType& readerType);
01075
01079 virtual ~SoVolumeReader();
01080
01087 void *getBuffer(int64_t offset, unsigned int size);
01088
01089
01090
01095 int bytesToInt( unsigned char *ptr, int sizeBytes );
01096
01100 void swapBytes( int *intPtr, int sizeBytes );
01101
01106 void swapBytesN( void *buffer, int numElements, int numBytesPerElement );
01107
01111 SbBool isValidFloat( const float val );
01112
01116 int64_t fileSize();
01117
01118 #if 1 SoDEPRECATED
01121 SbBool m_dataConverted;
01122
01123 #endif
01125 //------------------------------------------------------------------------------
01126 #ifndef HIDDEN_FROM_DOC
01127 SbString m_filename;
01128
01129 #endif // HIDDEN_FROM_DOC
01130
01131
01137 static SbBox3f adjustFlatExtent(const SbString& fileName, const SbBox3f& extent, const SbVec3i32& dim);
01138
01139 private:
01140
01141
01142
01143 SbBool m_directCoordSysAutoDetect;
01144
01145
01146 SbBool m_directCoordSys;
01147
01148 std::vector<SoDataSet::DatumElement> m_datum;
01149 int m_bytesPerVoxel;
01150
01151 double m_rangeMin, m_rangeMax;
01152 bool m_doRange;
01153
01154
01155 SbBool m_headerRead;
01156
01157 CoordinateType m_coordinateType;
01158 std::vector<float> m_rectilinearCoordinates[3];
01159
01160 SbBool m_ignoredFile;
01161
01162 private:
01163 SbBool m_isRGBA;
01164 int m_numSubsampledTiles;
01165 SbBool m_useFMM;
01166 void *m_filehandle;
01167 int m_filedesc;
01168 int64_t m_filesize;
01169 void *m_fmmdata;
01170 int64_t m_fmmoffset;
01171 unsigned int m_fmmsize;
01172
01173 void releasefmm();
01174 void bestmap(int64_t);
01175
01176 SbThreadMutex* m_fileMutex;
01177
01178
01179 typedef std::map<SbString,SoType> SoVolumeReaderExtensionAssociationMap;
01180 static SoVolumeReaderExtensionAssociationMap s_volumeReaderExtensionAssociation;
01181
01182
01183 template <typename TypeInt, typename TypeOut>
01184 void convert_range(int size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
01185
01186
01187 template <typename TypeOut>
01188 void convert_out(int size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
01189
01190
01191 template <typename TypeIn>
01192 void convert_in(int size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
01193
01194 };
01195
01196 inline SbBool
01197 SoVolumeReader::readXTraceInTile(int , unsigned char*& , const SbBox3i32& , const SbVec2i32& )
01198 {
01199 return FALSE;
01200 }
01201
01202 inline SbBool
01203 SoVolumeReader::readXSliceInTile(int , unsigned char*& , const SbBox3i32& , const uint32_t& )
01204 {
01205 return FALSE;
01206 }
01207
01208 inline SbBool
01209 SoVolumeReader::readYSliceInTile(int , unsigned char*& , const SbBox3i32& , const uint32_t& )
01210 {
01211 return FALSE;
01212 }
01213
01214 inline SbBool
01215 SoVolumeReader::getMinMax(int& , int& )
01216 {
01217 return FALSE;
01218 }
01219
01220 inline SbBool
01221 SoVolumeReader::getMinMax(int64_t &, int64_t &)
01222 {
01223 return FALSE;
01224 }
01225
01226 inline SbBool
01227 SoVolumeReader::isIgnoredFile() const
01228 {
01229 return m_ignoredFile;
01230 }
01231
01232 inline SbBool
01233 SoVolumeReader::getMinMax(double & , double & )
01234 {
01235 return FALSE;
01236 }
01237
01238 inline SbBool
01239 SoVolumeReader::getHistogram(std::vector<int64_t>&)
01240 {
01241 return FALSE;
01242 }
01243
01244 inline SbBool
01245 SoVolumeReader::setDirectCoordSysAutoDetection(SbBool)
01246 {
01247 return FALSE;
01248 }
01249
01250 inline SbBool
01251 SoVolumeReader::getDirectCoordSysAutoDetection()
01252 {
01253 return m_directCoordSysAutoDetect;
01254 }
01255
01256 inline SbBool
01257 SoVolumeReader::setDirectCoorSys(SbBool)
01258 {
01259 return FALSE;
01260 }
01261
01262 inline SbBool
01263 SoVolumeReader::getDirectCoordSys()
01264 {
01265 return m_directCoordSys;
01266 }
01267
01268 inline bool
01269 SoVolumeReader::isDead(int, int, int)
01270 {
01271 return false;
01272 }
01273
01274 inline uint64_t
01275 SoVolumeReader::getTileSizeFromFid(int)
01276 {
01277 return 0;
01278 }
01279
01280 #ifdef _MSC_VER
01281 #pragma warning( pop )
01282 #endif
01283
01284 #endif // _SO_VOLUME_READER_
01285
01286
01287