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;
00245 class SoVolumeReader : public SoFieldContainer
00246 {
00247 SO_FIELDCONTAINER_ABSTRACT_HEADER(SoVolumeReader);
00248
00249 public:
00250
00254 enum ReadError {
00258 RD_NO_ERROR,
00262 RD_FILE_NOT_FOUND_ERROR,
00266 RD_INVALID_DATA_ERROR,
00270 RD_UNSUPPORTED_DATA_TYPE_ERROR,
00275 RD_FILE_FORMAT_NOT_VALID_ERROR,
00279 RD_UNKNOWN_ERROR
00280 } ;
00281
00286 enum Axis {
00287 X,
00288 Y,
00289 Z
00290 };
00291
00296 SoVolumeReader();
00297
00312 virtual ReadError getDataChar( SbBox3f &size, SoDataSet::DataType &type, SbVec3i32 &dim )=0;
00313
00320 virtual SbBool setOutputDataType( SbBool doChange, SoDataSet::DataType outputType );
00321
00330 virtual SbBool setInputDataRange( SbBool doChange, double min, double max );
00331
00341 virtual int getNumSignificantBits() { return 0; };
00342
00356 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, void * data )=0;
00357
00390 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, SoBufferObject * bufferObject);
00391
00406 SbVec3i32 getNumVoxels( const SbVec3i32& realSize, const SbVec3i32& subsamplingLevel );
00407
00417 SbVec3i32 getSizeToAllocate( const SbVec3i32& realSize, const SbVec3i32& subsamplingLevel );
00418
00423 virtual int setFilename( const SbString& filename );
00424
00428 SbString getFilename() const;
00429
00430
00439 virtual SbBool isDataConverted() const;
00440
00446 virtual SbBool getTileSize(SbVec3i32& size);
00447
00464 virtual SoBufferObject* readTile(int index, const SbBox3i32& tilePosition);
00465
00476 virtual SbBool readXTraceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const SbVec2i32& tracePosition);
00477
00488 virtual SbBool readYSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00489
00500 virtual SbBool readZSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00501
00512 virtual SbBool readXSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00513
00520 virtual SbBool isThreadSafe() const;
00521
00526 virtual SbString getOriginalFilename() const
00527 { return SbString(""); }
00528
00538 virtual SbBool getMinMax(int64_t & min, int64_t & max);
00539
00549 virtual SbBool getMinMax(double & min, double & max);
00550
00554 virtual SbBool getHistogram(std::vector<int64_t>& numVox);
00555
00563 virtual SbBool setDirectCoordSysAutoDetection(SbBool autoValue);
00567 virtual SbBool getDirectCoordSysAutoDetection();
00568
00575 virtual SbBool setDirectCoorSys(SbBool directCoord);
00576
00580 virtual SbBool getDirectCoordSys();
00581
00611 virtual SbVec2d getTileMinMax( int fileId ) const;
00612
00616 enum ReaderType {
00618 NO_READER,
00620 AM,
00622 AVS,
00624 DICOM,
00626 GENERIC,
00628 LDM,
00630 MEMORY,
00632 RASTERSTACK,
00634 SEGY,
00636 VOL,
00638 VOX,
00640 TIFF
00641 };
00642
00646 virtual ReaderType getReaderType (){return NO_READER;};
00647
00713 virtual SoVolumeWriter* getConfiguredWriter();
00714
00718 enum CoordinateType {
00722 COORDINATES_UNIFORM = 0,
00726 COORDINATES_RECTILINEAR
00727 };
00728
00732 CoordinateType getCoordinateType();
00733
00737 const float * getRectilinearCoordinates(Axis axis) const;
00738
00742 void setRectilinearCoordinates(const float *x, const float *y, const float *z);
00743
00748 virtual SbBool isRGBA() const
00749 { return m_isRGBA; }
00750
00754 inline void setRGBA(const SbBool flag)
00755 { m_isRGBA = flag; }
00756
00765 virtual void closeAllHandles() {};
00766
00770 virtual void restoreAllHandles() {};
00771
00783 static SoVolumeReader* getAppropriateReader(const SbString& filename);
00784
00785 #if 1 SoDEPRECATED
00815 virtual SbBool readTile(int SO_UNUSED_PARAM(index), unsigned char*& SO_UNUSED_PARAM(buffer), const SbBox3i32& SO_UNUSED_PARAM(tilePosition)) { return FALSE; }
00816 SoDEPRECATED
00823 virtual SbBool readTile(int index, SoBufferObject *buffer, const SbBox3i32& tilePosition);
00824
00825 #endif
00827 #if 1 SoDEPRECATED
00833 virtual int getBorderFlag()
00834 {return -1;}
00835
00836 #endif
00838 #if 1 SoDEPRECATED
00845 virtual SbBool getMinMax(int& min, int& max);
00846
00847 #endif
00849 private:
00850
00851
00852
00853 virtual ReadError getDataChar( SbBox3f &size, std::vector<SoDataSet::DatumElement>& datum, SbVec3i32 &dim );
00854
00855 void lockFileMutex();
00856 void unlockFileMutex();
00857
00867 void convert( SoDataSet::DataType typeIn , SoBufferObject* bufferIn,
00868 SoDataSet::DataType typeOut, SoBufferObject* bufferOut, int size, SbBool shiftData = true);
00869
00870 void convertDataRange( bool doRange, double min, double max );
00871
00872 virtual int getNumBytesPerDatum();
00873
00874 virtual bool isLDMReader() { return false; }
00875 virtual bool isVolumeMaskReader() { return false; }
00876
00877 virtual bool hasDeadCell() { return false; }
00878
00879 virtual bool isDead(int i,int j,int k);
00880
00881 virtual uint8_t* getCellGridState() { return NULL; }
00882
00883 virtual int getNbCell() { return 0; }
00884
00885 virtual uint64_t getTileSizeFromFid(int fileId);
00886
00887
00891 bool hasPerTileMinMaxComputed() const;
00892
00893 #if 1 SoDEPRECATED
00896 void convert( SoDataSet::DataType typeIn , void* bufferIn,
00897 SoDataSet::DataType typeOut, void* bufferOut, int size, SbBool shiftData = true);
00898
00899 #endif
00901 private: protected:
00902
00930 static bool registerVolumeReaderExtension(const SbString& fileExtension, const SoType& readerType);
00931
00941 static bool unregisterVolumeReaderExtensions(const SoType& readerType);
00942
00946 virtual ~SoVolumeReader();
00947
00954 void *getBuffer(int64_t offset, unsigned int size);
00955
00956
00957
00962 int bytesToInt( unsigned char *ptr, int sizeBytes );
00963
00967 void swapBytes( int *intPtr, int sizeBytes );
00968
00973 void swapBytesN( void *buffer, int numElements, int numBytesPerElement );
00974
00978 SbBool isValidFloat( const float val );
00979
00983 int64_t fileSize();
00984
00985 #if 1 SoDEPRECATED
00988 SbBool m_dataConverted;
00989
00990 #endif
00992 //------------------------------------------------------------------------------
00993 #ifndef HIDDEN_FROM_DOC
00994 SbString m_filename;
00995
00996 #endif // HIDDEN_FROM_DOC
00997
00998
01004 static SbBox3f adjustFlatExtent(const SbString& fileName, const SbBox3f& extent, const SbVec3i32& dim);
01005
01006 private:
01007
01008
01009
01010 SbBool m_directCoordSysAutoDetect;
01011
01012
01013 SbBool m_directCoordSys;
01014
01015 std::vector<SoDataSet::DatumElement> m_datum;
01016 int m_bytesPerVoxel;
01017
01018 double m_rangeMin, m_rangeMax;
01019 bool m_doRange;
01020
01021
01022 SbBool m_headerRead;
01023
01024 CoordinateType m_coordinateType;
01025 std::vector<float> m_rectilinearCoordinates[3];
01026
01027 private:
01028 SbBool m_isRGBA;
01029 SbBool m_useFMM;
01030 void *m_filehandle;
01031 int m_filedesc;
01032 int64_t m_filesize;
01033 void *m_fmmdata;
01034 int64_t m_fmmoffset;
01035 unsigned int m_fmmsize;
01036
01037 void releasefmm();
01038 void bestmap(int64_t);
01039
01040 SbThreadMutex* m_fileMutex;
01041
01042
01043 typedef std::map<SbString,SoType> SoVolumeReaderExtensionAssociationMap;
01044 static SoVolumeReaderExtensionAssociationMap s_volumeReaderExtensionAssociation;
01045
01046
01047 template <typename TypeInt, typename TypeOut>
01048 void convert_range(int size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
01049
01050
01051 template <typename TypeOut>
01052 void convert_out(int size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
01053
01054
01055 template <typename TypeIn>
01056 void convert_in(int size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
01057
01058 };
01059
01060 inline SbBool
01061 SoVolumeReader::readXTraceInTile(int , unsigned char*& , const SbBox3i32& , const SbVec2i32& )
01062 {
01063 return FALSE;
01064 }
01065
01066 inline SbBool
01067 SoVolumeReader::readXSliceInTile(int , unsigned char*& , const SbBox3i32& , const uint32_t& )
01068 {
01069 return FALSE;
01070 }
01071
01072 inline SbBool
01073 SoVolumeReader::readYSliceInTile(int , unsigned char*& , const SbBox3i32& , const uint32_t& )
01074 {
01075 return FALSE;
01076 }
01077
01078 inline SbBool
01079 SoVolumeReader::getMinMax(int& , int& )
01080 {
01081 return FALSE;
01082 }
01083
01084 inline SbBool
01085 SoVolumeReader::getMinMax(int64_t &, int64_t &)
01086 {
01087 return FALSE;
01088 }
01089
01090 inline SbBool
01091 SoVolumeReader::getMinMax(double & , double & )
01092 {
01093 return FALSE;
01094 }
01095
01096 inline SbBool
01097 SoVolumeReader::getHistogram(std::vector<int64_t>&)
01098 {
01099 return FALSE;
01100 }
01101
01102 inline SbBool
01103 SoVolumeReader::setDirectCoordSysAutoDetection(SbBool)
01104 {
01105 return FALSE;
01106 }
01107
01108 inline SbBool
01109 SoVolumeReader::getDirectCoordSysAutoDetection()
01110 {
01111 return m_directCoordSysAutoDetect;
01112 }
01113
01114 inline SbBool
01115 SoVolumeReader::setDirectCoorSys(SbBool)
01116 {
01117 return FALSE;
01118 }
01119
01120 inline SbBool
01121 SoVolumeReader::getDirectCoordSys()
01122 {
01123 return m_directCoordSys;
01124 }
01125
01126 inline bool
01127 SoVolumeReader::isDead(int, int, int)
01128 {
01129 return false;
01130 }
01131
01132 inline uint64_t
01133 SoVolumeReader::getTileSizeFromFid(int)
01134 {
01135 return 0;
01136 }
01137
01138 #ifdef _MSC_VER
01139 #pragma warning( pop )
01140 #endif
01141
01142 #endif // _SO_VOLUME_READER_
01143
01144
01145