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;
00252 class SoVolumeReader : public SoFieldContainer
00253 {
00254 SO_FIELDCONTAINER_ABSTRACT_HEADER(SoVolumeReader);
00255
00256 public:
00257
00261 enum ReadError {
00265 RD_NO_ERROR,
00269 RD_FILE_NOT_FOUND_ERROR,
00273 RD_INVALID_DATA_ERROR,
00277 RD_UNSUPPORTED_DATA_TYPE_ERROR,
00282 RD_FILE_FORMAT_NOT_VALID_ERROR,
00286 RD_UNKNOWN_ERROR
00287 } ;
00288
00293 enum Axis {
00294 X,
00295 Y,
00296 Z
00297 };
00298
00303 SoVolumeReader();
00304
00319 virtual SoVolumeReader::ReadError getDataChar( SbBox3f &size, SoDataSet::DataType &type, SbVec3i32 &dim )=0;
00320
00327 virtual SbBool setOutputDataType( SbBool doChange, SoDataSet::DataType outputType );
00328
00337 virtual SbBool setInputDataRange( SbBool doChange, double min, double max );
00338
00348 virtual int getNumSignificantBits() { return 0; };
00349
00362 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, void * data )=0;
00363
00396 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, SoBufferObject * dataBuffer);
00397
00412 SbVec3i32 getNumVoxels( const SbVec3i32& realSize, const SbVec3i32& subsamplingLevel );
00413
00423 SbVec3i32 getSizeToAllocate( const SbVec3i32& realSize, const SbVec3i32& subsamplingLevel );
00424
00429 virtual int setFilename( const SbString& filename );
00430
00434 SbString getFilename() const;
00435
00436
00445 virtual SbBool isDataConverted() const;
00446
00447 virtual void reloadTileMinMax() {};
00448
00454 virtual SbBool getTileSize(SbVec3i32& size);
00455
00476 virtual SoBufferObject* readTile(int index, const SbBox3i32& tilePosition);
00477
00488 virtual SbBool readXTraceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const SbVec2i32& tracePosition);
00489
00500 virtual SbBool readYSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00501
00512 virtual SbBool readZSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00513
00524 virtual SbBool readXSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00525
00532 virtual SbBool isThreadSafe() const;
00533
00537 virtual SbBool isIgnoredFile() const;
00538
00543 virtual SbString getOriginalFilename() const
00544 { return SbString(""); }
00545
00555 virtual SbBool getMinMax(int64_t & min, int64_t & max);
00556
00566 virtual SbBool getMinMax(double & min, double & max);
00567
00571 virtual SbBool getHistogram(std::vector<int64_t>& numVox);
00572
00580 virtual SbBool setDirectCoordSysAutoDetection(SbBool autoValue);
00584 virtual SbBool getDirectCoordSysAutoDetection();
00585
00592 virtual SbBool setDirectCoorSys(SbBool directCoord);
00593
00597 virtual SbBool getDirectCoordSys();
00598
00638 virtual SbVec2d getTileMinMax( int index ) const;
00639
00643 enum ReaderType {
00645 NO_READER,
00647 AM,
00649 AVS,
00651 DICOM,
00653 GENERIC,
00655 LDM,
00657 MEMORY,
00659 RASTERSTACK,
00661 SEGY,
00663 VOL,
00665 VOX,
00667 TIFF,
00669 MRC
00670 };
00671
00675 virtual SoVolumeReader::ReaderType getReaderType (){return NO_READER;};
00676
00742 virtual SoVolumeWriter* getConfiguredWriter();
00743
00747 enum CoordinateType {
00751 COORDINATES_UNIFORM = 0,
00755 COORDINATES_RECTILINEAR
00756 };
00757
00761 CoordinateType getCoordinateType();
00762
00766 const float * getRectilinearCoordinates(Axis axis) const;
00767
00771 void setRectilinearCoordinates(const float *x, const float *y, const float *z);
00772
00777 virtual SbBool isRGBA() const
00778 { return m_isRGBA; }
00779
00783 inline void setRGBA(const SbBool flag)
00784 { m_isRGBA = flag; }
00785
00794 virtual void closeAllHandles() {};
00795
00799 virtual void restoreAllHandles() {};
00800
00812 static SoVolumeReader* getAppropriateReader(const SbString& filename);
00813
00814 #if 1 SoDEPRECATED
00844 virtual SbBool readTile(int SO_UNUSED_PARAM(index), unsigned char*& SO_UNUSED_PARAM(buffer), const SbBox3i32& SO_UNUSED_PARAM(tilePosition)) { return FALSE; }
00845 SoDEPRECATED
00852 virtual SbBool readTile(int index, SoBufferObject *buffer, const SbBox3i32& tilePosition);
00853
00854 #endif
00856 #if 1 SoDEPRECATED
00862 virtual int getBorderFlag()
00863 {return -1;}
00864
00865 #endif
00867 #if 1 SoDEPRECATED
00874 virtual SbBool getMinMax(int& min, int& max);
00875
00876 #endif
00878 private:
00879
00880
00881
00882 virtual SoVolumeReader::ReadError getDataChar( SbBox3f &size, std::vector<SoDataSet::DatumElement>& datum, SbVec3i32 &dim );
00883
00884 void lockFileMutex();
00885 void unlockFileMutex();
00886
00896 void convert( SoDataSet::DataType typeIn , SoBufferObject* bufferIn,
00897 SoDataSet::DataType typeOut, SoBufferObject* bufferOut, int size, SbBool shiftData = true);
00898
00899 void convertDataRange( bool doRange, double min, double max );
00900
00901 virtual int getNumBytesPerDatum();
00902
00903 virtual bool isLDMReader() { return false; }
00904 virtual bool isVolumeMaskReader() { return false; }
00905
00906 virtual bool hasDeadCell() { return false; }
00907
00908 virtual bool isDead(int i,int j,int k);
00909
00910 virtual uint8_t* getCellGridState() { return NULL; }
00911
00912 virtual int getNbCell() { return 0; }
00913
00914 virtual uint64_t getTileSizeFromFid(int fileId);
00915
00916
00920 bool hasPerTileMinMaxComputed();
00921
00922 #if 1 SoDEPRECATED
00925 void convert( SoDataSet::DataType typeIn , void* bufferIn,
00926 SoDataSet::DataType typeOut, void* bufferOut, int size, SbBool shiftData = true);
00927
00928 #endif
00930 private: protected:
00931
00959 static bool registerVolumeReaderExtension(const SbString& fileExtension, const SoType& readerType);
00960
00970 static bool unregisterVolumeReaderExtensions(const SoType& readerType);
00971
00975 virtual ~SoVolumeReader();
00976
00983 void *getBuffer(int64_t offset, unsigned int size);
00984
00985
00986
00991 int bytesToInt( unsigned char *ptr, int sizeBytes );
00992
00996 void swapBytes( int *intPtr, int sizeBytes );
00997
01002 void swapBytesN( void *buffer, int numElements, int numBytesPerElement );
01003
01007 SbBool isValidFloat( const float val );
01008
01012 int64_t fileSize();
01013
01014 #if 1 SoDEPRECATED
01017 SbBool m_dataConverted;
01018
01019 #endif
01021 //------------------------------------------------------------------------------
01022 #ifndef HIDDEN_FROM_DOC
01023 SbString m_filename;
01024
01025 #endif // HIDDEN_FROM_DOC
01026
01027
01033 static SbBox3f adjustFlatExtent(const SbString& fileName, const SbBox3f& extent, const SbVec3i32& dim);
01034
01035 private:
01036
01037
01038
01039 SbBool m_directCoordSysAutoDetect;
01040
01041
01042 SbBool m_directCoordSys;
01043
01044 std::vector<SoDataSet::DatumElement> m_datum;
01045 int m_bytesPerVoxel;
01046
01047 double m_rangeMin, m_rangeMax;
01048 bool m_doRange;
01049
01050
01051 SbBool m_headerRead;
01052
01053 CoordinateType m_coordinateType;
01054 std::vector<float> m_rectilinearCoordinates[3];
01055
01056 SbBool m_ignoredFile;
01057
01058 SoINTERNAL private:
01059
01060 SbThreadMutex* m_fmmMutex;
01061
01062 private:
01063 SbBool m_isRGBA;
01064 SbBool m_useFMM;
01065 void *m_filehandle;
01066 int m_filedesc;
01067 int64_t m_filesize;
01068 void *m_fmmdata;
01069 int64_t m_fmmoffset;
01070 unsigned int m_fmmsize;
01071 bool m_hasPerTileMinMaxComputed;
01072
01073 void releasefmm();
01074 void bestmap(int64_t);
01075
01076 SbThreadMutex* m_fileMutex;
01077
01078
01079 typedef std::map<SbString,SoType> SoVolumeReaderExtensionAssociationMap;
01080 static SoVolumeReaderExtensionAssociationMap s_volumeReaderExtensionAssociation;
01081
01082
01083 template <typename TypeInt, typename TypeOut>
01084 void convert_range(int size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
01085
01086
01087 template <typename TypeOut>
01088 void convert_out(int size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
01089
01090
01091 template <typename TypeIn>
01092 void convert_in(int size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
01093
01094 };
01095
01096 inline SbBool
01097 SoVolumeReader::readXTraceInTile(int , unsigned char*& , const SbBox3i32& , const SbVec2i32& )
01098 {
01099 return FALSE;
01100 }
01101
01102 inline SbBool
01103 SoVolumeReader::readXSliceInTile(int , unsigned char*& , const SbBox3i32& , const uint32_t& )
01104 {
01105 return FALSE;
01106 }
01107
01108 inline SbBool
01109 SoVolumeReader::readYSliceInTile(int , unsigned char*& , const SbBox3i32& , const uint32_t& )
01110 {
01111 return FALSE;
01112 }
01113
01114 inline SbBool
01115 SoVolumeReader::getMinMax(int& , int& )
01116 {
01117 return FALSE;
01118 }
01119
01120 inline SbBool
01121 SoVolumeReader::getMinMax(int64_t &, int64_t &)
01122 {
01123 return FALSE;
01124 }
01125
01126 inline SbBool
01127 SoVolumeReader::isIgnoredFile() const
01128 {
01129 return m_ignoredFile;
01130 }
01131
01132 inline SbBool
01133 SoVolumeReader::getMinMax(double & , double & )
01134 {
01135 return FALSE;
01136 }
01137
01138 inline SbBool
01139 SoVolumeReader::getHistogram(std::vector<int64_t>&)
01140 {
01141 return FALSE;
01142 }
01143
01144 inline SbBool
01145 SoVolumeReader::setDirectCoordSysAutoDetection(SbBool)
01146 {
01147 return FALSE;
01148 }
01149
01150 inline SbBool
01151 SoVolumeReader::getDirectCoordSysAutoDetection()
01152 {
01153 return m_directCoordSysAutoDetect;
01154 }
01155
01156 inline SbBool
01157 SoVolumeReader::setDirectCoorSys(SbBool)
01158 {
01159 return FALSE;
01160 }
01161
01162 inline SbBool
01163 SoVolumeReader::getDirectCoordSys()
01164 {
01165 return m_directCoordSys;
01166 }
01167
01168 inline bool
01169 SoVolumeReader::isDead(int, int, int)
01170 {
01171 return false;
01172 }
01173
01174 inline uint64_t
01175 SoVolumeReader::getTileSizeFromFid(int)
01176 {
01177 return 0;
01178 }
01179
01180 #ifdef _MSC_VER
01181 #pragma warning( pop )
01182 #endif
01183
01184 #endif // _SO_VOLUME_READER_
01185
01186
01187