Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoVolumeReader.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : P. ESTRADE (Mar 2000)
22**=======================================================================*/
23#ifndef _SO_VOLUME_READER_
24#define _SO_VOLUME_READER_
25
26#ifdef _MSC_VER
27#pragma warning( push )
28#pragma warning(disable:4251)
29#endif
30
31#include <Inventor/nodes/SoNode.h>
32#include <Inventor/SoPreferences.h>
33#include <LDM/nodes/SoDataSet.h>
34
35#include <Inventor/STL/vector>
36#include <Inventor/STL/map>
37
38class SbThreadMutex;
39class SoVolumeWriter;
253{
254 SO_FIELDCONTAINER_ABSTRACT_HEADER(SoVolumeReader);
255
256 public:
257
288
293 enum Axis {
296 Z
297 };
298
304
320
327 virtual SbBool setOutputDataType( SbBool doChange, SoDataSet::DataType outputType );
328
337 virtual SbBool setInputDataRange( SbBool doChange, double min, double max );
338
348 virtual int getNumSignificantBits() { return 0; };
349
365 virtual void getSubSlice(const SbBox2i32& subSlice, int sliceNumber, void* data);
366
399 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, SoBufferObject * dataBuffer);
400
415 SbVec3i32 getNumVoxels( const SbVec3i32& realSize, const SbVec3i32& subsamplingLevel );
416
426 SbVec3i32 getSizeToAllocate( const SbVec3i32& realSize, const SbVec3i32& subsamplingLevel );
427
432 virtual int setFilename( const SbString& filename );
433
438
439 //------------ for LDM -----------------//
449 virtual SbBool isDataConverted() const;
450
451 virtual void reloadTileMinMax() {};
452
459
480 virtual SoBufferObject* readTile(int index, const SbBox3i32& tilePosition);
481
495 virtual SbBool readXTraceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const SbVec2i32& tracePosition);
496
510 virtual SbBool readYSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
511
525 virtual SbBool readZSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
526
540 virtual SbBool readXSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
541
549 virtual SbBool isThreadSafe() const;
550
554 virtual SbBool isIgnoredFile() const;
555
561 { return SbString(""); }
562
572 virtual SbBool getMinMax(int64_t & min, int64_t & max);
573
583 virtual SbBool getMinMax(double & min, double & max);
584
590 virtual SbBool getHistogram(std::vector<int64_t>& numVox);
591
604
611 virtual SbBool setDirectCoorSys(SbBool directCoord);
612
616 virtual SbBool getDirectCoordSys();
617
657 virtual SbVec2d getTileMinMax( int index ) const;
658
690
695
762
776
781
788 const float * getRectilinearCoordinates(Axis axis) const;
789
793 void setRectilinearCoordinates(const float *x, const float *y, const float *z);
794
800 virtual SbBool isRGBA() const
801 { return m_isRGBA; }
802
807 inline void setRGBA(const SbBool flag)
808 { m_isRGBA = flag; }
809
818 virtual void closeAllHandles() {};
819
823 virtual void restoreAllHandles() {};
824
837
838#if 1 SoDEPRECATED
871 virtual SbBool readTile(int SO_UNUSED_PARAM(index), unsigned char*& SO_UNUSED_PARAM(buffer), const SbBox3i32& SO_UNUSED_PARAM(tilePosition)) { return FALSE; }
872SoDEPRECATED
879 virtual SbBool readTile(int index, SoBufferObject *buffer, const SbBox3i32& tilePosition);
880
881#endif
883#if 1 SoDEPRECATED
889 virtual int getBorderFlag()
890 {return -1;}
891
892#endif
894#if 1 SoDEPRECATED
901 virtual SbBool getMinMax(int& min, int& max);
902
903#endif
905private:
906 //for volume having a series of data per datum
907 //used by ReservoirViz. The converter asks the eclipse reader for the datum.
908 //not used in vviz which uses getDataChar(...type...). (must keep for compatibility reasons).
909 virtual ReadError getDataChar( SbBox3f &size, std::vector<SoDataSet::DatumElement>& datum, SbVec3i32 &dim );
910
911 void lockFileMutex();
912 void unlockFileMutex();
913
923 void convert( SoDataSet::DataType typeIn , SoBufferObject* bufferIn,
924 SoDataSet::DataType typeOut, SoBufferObject* bufferOut, size_t size, SbBool shiftData = true);
925
926 void convertDataRange( bool doRange, double min, double max );
927
928 virtual int getNumBytesPerDatum();
929
930 // number of bytes in a voxel
931 // uses DataType if getNumBytesPerDatum() returns 0
932 int getDataSize();
933
934 virtual bool isLDMReader() { return false; }
935 virtual bool isVolumeMaskReader() { return false; }
936
937 virtual bool hasDeadCell() { return false; }
938
939 virtual bool isDead(int i,int j,int k);
940
941 virtual uint8_t* getCellGridState() { return NULL; }
942
943 virtual int getNbCell() { return 0; }
944
945 virtual uint64_t getTileSizeFromFid(int fileId);// Virtual method, only used
946 // by resviz for now
947
951 bool hasPerTileMinMaxComputed();
952
953#if 1 SoDEPRECATED
956 void convert( SoDataSet::DataType typeIn , void* bufferIn,
957 SoDataSet::DataType typeOut, void* bufferOut, size_t size, SbBool shiftData = true);
958
959#endif
965 virtual SoVolumeReader* getInternalReader() const
966 {
967 return const_cast<SoVolumeReader*>(this);
968 }
969
970 private: protected:
999 static bool registerVolumeReaderExtension(const SbString& fileExtension, const SoType& readerType);
1000
1010 static bool unregisterVolumeReaderExtensions(const SoType& readerType);
1011
1016
1025 void *getBuffer(int64_t offset, unsigned int size);
1026
1027 // Convenient methods
1028
1035 static int bytesToInt(const unsigned char* ptr, int sizeBytes);
1036
1042 static void swapBytes( int *intPtr, int sizeBytes );
1043
1050 static void swapBytesN( void *buffer, int numElements, int numBytesPerElement );
1051
1055 static SbBool isValidFloat( const float val );
1056
1060 int64_t fileSize();
1061
1062#if 1 SoDEPRECATED
1066
1067#endif
1069 //------------------------------------------------------------------------------
1070#ifndef HIDDEN_FROM_DOC
1071 SbString m_filename;
1072
1073#endif // HIDDEN_FROM_DOC
1074
1075
1081 static SbBox3f adjustFlatExtent(const SbString& fileName, const SbBox3f& extent, const SbVec3i32& dim);
1082
1083private:
1084
1085 //if true, try to detect automatically whether the coord sys is diret or not.
1086 //default is true
1087 SbBool m_directCoordSysAutoDetect;
1088 //has the data been stored using a direct coordinate system?
1089 //default is true
1090 SbBool m_directCoordSys;
1091
1092 std::vector<SoDataSet::DatumElement> m_datum;
1093 int m_bytesPerVoxel;
1094
1095 double m_rangeMin, m_rangeMax;
1096 bool m_doRange;
1097
1098 //True if header has already been read
1099 SbBool m_headerRead;
1100
1101 CoordinateType m_coordinateType;
1102 std::vector<float> m_rectilinearCoordinates[3];
1103
1104 SbBool m_ignoredFile;
1105
1106SoINTERNAL private:
1107 // Used to guard the buffer obtained by calling getBuffer()
1108 SbThreadMutex* m_fmmMutex;
1109
1110private:
1111 SbBool m_isRGBA;
1112 SbBool m_useFMM;
1113 void *m_filehandle;
1114 int m_filedesc;
1115 int64_t m_filesize;
1116 void *m_fmmdata;
1117 int64_t m_fmmoffset;
1118 unsigned int m_fmmsize;
1119 bool m_hasPerTileMinMaxComputed;
1120
1121 void releasefmm();
1122 void bestmap(int64_t);
1123
1124 SbThreadMutex* m_fileMutex;
1125
1126 // keep a map of readerType <-> extension association
1127 typedef std::map<SbString,SoType> SoVolumeReaderExtensionAssociationMap;
1128 static SoVolumeReaderExtensionAssociationMap s_volumeReaderExtensionAssociation;
1129
1130 // Convert range from input type to given TypeOut type.
1131 template <typename TypeInt, typename TypeOut>
1132 void convert_range(size_t size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
1133
1134 // Convert float input type to any supported type
1135 template <typename TypeOut>
1136 void convert_out(size_t size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
1137
1138 // Convert any input type to float output
1139 template <typename TypeIn>
1140 void convert_in(size_t size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
1141
1142};
1143
1144inline SbBool
1145SoVolumeReader::readXTraceInTile(int , unsigned char*& , const SbBox3i32& , const SbVec2i32& )
1146{
1147 return FALSE;
1148}
1149
1150inline SbBool
1151SoVolumeReader::readXSliceInTile(int , unsigned char*& , const SbBox3i32& , const uint32_t& )
1152{
1153 return FALSE;
1154}
1155
1156inline SbBool
1157SoVolumeReader::readYSliceInTile(int , unsigned char*& , const SbBox3i32& , const uint32_t& )
1158{
1159 return FALSE;
1160}
1161
1162inline SbBool
1164{
1165 return FALSE;
1166}
1167
1168inline SbBool
1169SoVolumeReader::getMinMax(int64_t &, int64_t &)
1170{
1171 return FALSE;
1172}
1173
1174inline SbBool
1176{
1177 return m_ignoredFile;
1178}
1179
1180inline SbBool
1181SoVolumeReader::getMinMax(double & , double & )
1182{
1183 return FALSE;
1184}
1185
1186inline SbBool
1187SoVolumeReader::getHistogram(std::vector<int64_t>&)
1188{
1189 return FALSE;
1190}
1191
1192inline SbBool
1197
1198inline SbBool
1200{
1201 return m_directCoordSysAutoDetect;
1202}
1203
1204inline SbBool
1206{
1207 return FALSE;
1208}
1209
1210inline SbBool
1212{
1213 return m_directCoordSys;
1214}
1215
1216inline bool
1217SoVolumeReader::isDead(int, int, int)
1218{
1219 return false;
1220}
1221
1222inline uint64_t
1223SoVolumeReader::getTileSizeFromFid(int)
1224{
1225 return 0;
1226}
1227
1228#ifdef _MSC_VER
1229#pragma warning( pop )
1230#endif
1231
1232#endif // _SO_VOLUME_READER_
1233
1234
2D box class.
Definition SbBox.h:2383
3D box class.
Definition SbBox.h:649
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 3D box class.
Definition SbBox.h:96
Class for smart character strings.
Definition SbString.h:202
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 2D vector class ...
Definition SbVec.h:314
2D vector class.
Definition SbVec.h:517
3D vector class.
Definition SbVec.h:1517
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
DataType
Supported data type.
Definition SoDataSet.h:624
Abstract base class for objects that contain fields.
Stores runtime type information.
Definition SoType.h:98
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Abstract...
static void swapBytes(int *intPtr, int sizeBytes)
Utility method to convert an integer into the correct architecture (little/big endian).
static void swapBytesN(void *buffer, int numElements, int numBytesPerElement)
Utility method to swap bytes of each element of an array of numElements elements.
virtual SbString getOriginalFilename() const
Returns original file name from which the data has been converted to LDM format if stored in file.
static SbBox3f adjustFlatExtent(const SbString &fileName, const SbBox3f &extent, const SbVec3i32 &dim)
VolumeViz doesn't handles empty extent (for ex.
virtual SoDEPRECATED SbBool readTile(int index, unsigned char *&buffer, const SbBox3i32 &tilePosition)
Given an index, reads a tile if the data is organized in tiles (for LDM).
virtual void reloadTileMinMax()
SoDEPRECATED SbBool m_dataConverted
SoVolumeReader()
Constructor.
static bool unregisterVolumeReaderExtensions(const SoType &readerType)
Unregister all filename extensions associated with the specified SoVolumeReader class.
virtual SbBool isRGBA() const
Returns TRUE if the data set contains RGBA color values.
virtual SoVolumeReader::ReaderType getReaderType()
Returns the reader type.
virtual SoBufferObject * readTile(int index, const SbBox3i32 &tilePosition)
Given an index, reads a tile if the data is organized in tiles (for LDM).
void setRectilinearCoordinates(const float *x, const float *y, const float *z)
Sets rectilinear coordinates for the data set.
virtual int setFilename(const SbString &filename)
Specifies the path of the file.
const float * getRectilinearCoordinates(Axis axis) const
Returns the coordinates for the specified axis.
virtual SbBool setDirectCoorSys(SbBool directCoord)
Specify if the coordinate system used is direct or not.
virtual SbBool getHistogram(std::vector< int64_t > &numVox)
Returns histogram if available.
void setRGBA(const SbBool flag)
Specifies if data must be considered as RGBA.
virtual SbBool setInputDataRange(SbBool doChange, double min, double max)
Requests that the input be converted from the specified range to the range depending on the output da...
virtual SbBool isDataConverted() const
Returns TRUE if the data is already organized in tiles for the LDM module.
Axis
Which axis to handle.
static int bytesToInt(const unsigned char *ptr, int sizeBytes)
Utility method that returns an integer from sizeBytes bytes starting at address ptr.
int64_t fileSize()
Returns the size of the file when file I/O is handled by this class.
virtual SoDEPRECATED int getBorderFlag()
Returns border (overlap) value if stored in file.
virtual void restoreAllHandles()
Restore resources that were closed by closeAllHandles().
SbVec3i32 getSizeToAllocate(const SbVec3i32 &realSize, const SbVec3i32 &subsamplingLevel)
Utility function provided by SoVolumeReader for subclass readers to call.
virtual SbBool setOutputDataType(SbBool doChange, SoDataSet::DataType outputType)
Sets the output data type.
static SoVolumeReader * getAppropriateReader(const SbString &filename)
Returns a preconfigured SoVolumeReader instance that can be used to load the given file (based on the...
virtual SbBool readXSliceInTile(int index, unsigned char *&buffer, const SbBox3i32 &tilePosition, const uint32_t &slicePosition)
Read directly from the data source, an orthoslice on the X axis (Zaxis == 0) inside a tile.
virtual SbBool getTileSize(SbVec3i32 &size)
Returns tile dimensions in voxels when using data stored in tiles.
virtual SbBool readYSliceInTile(int index, unsigned char *&buffer, const SbBox3i32 &tilePosition, const uint32_t &slicePosition)
Read directly from the data source, an orthoslice on the Y axis (Zaxis == 1) inside a tile.
CoordinateType
Coordinate type used by this data set.
@ COORDINATES_UNIFORM
Uniform grid spacing along each axis.
@ COORDINATES_RECTILINEAR
Grid spacing defined by x, y, z values.
virtual SbBool getDirectCoordSys()
Return whether the coordinate system used is direct or not.
virtual SbBool isThreadSafe() const
Should return TRUE if the reader is thread safe.
SbString getFilename() const
Returns the path of the file.
virtual SbVec2d getTileMinMax(int index) const
Returns the minimum and maximum data values for the given tile.
virtual SbBool setDirectCoordSysAutoDetection(SbBool autoValue)
Sets whether or not the reader should automatically try to detect if the coordinate system used is di...
virtual ReadError getDataChar(SbBox3f &size, SoDataSet::DataType &type, SbVec3i32 &dim)=0
Gets the characteristics (file header) of the data volume.
virtual int getNumSignificantBits()
This method is optional.
virtual SoDEPRECATED SbBool readTile(int index, SoBufferObject *buffer, const SbBox3i32 &tilePosition)
Same as readTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition) but using an SoBuf...
virtual void closeAllHandles()
Close all resources that are locked by the reader.
virtual ~SoVolumeReader()
Destructor.
virtual SbBool readZSliceInTile(int index, unsigned char *&buffer, const SbBox3i32 &tilePosition, const uint32_t &slicePosition)
Read directly from the data source, an orthoslice on the Z axis (Zaxis == 2) inside a tile.
SbVec3i32 getNumVoxels(const SbVec3i32 &realSize, const SbVec3i32 &subsamplingLevel)
Utility function provided by SoVolumeReader for subclass readers to call.
ReaderType
Available reader type.
@ LDM
Open Inventor LDM.
@ RASTERSTACK
Raster Stack.
@ MEMORY
In memory.
@ NO_READER
Unknown.
virtual SbBool getMinMax(int64_t &min, int64_t &max)
Returns min and max for integer data type, if available.
static bool registerVolumeReaderExtension(const SbString &fileExtension, const SoType &readerType)
Register an SoVolumeReader class to handle a file extension.
virtual SbBool readXTraceInTile(int index, unsigned char *&buffer, const SbBox3i32 &tilePosition, const SbVec2i32 &tracePosition)
Read directly from the data source, a trace inside a tile.
virtual SbBool getDirectCoordSysAutoDetection()
Return automatic detection value.
virtual SbBool isIgnoredFile() const
Should return TRUE if at least one file has been ignored during reading.
virtual SoVolumeWriter * getConfiguredWriter()
Returns a volume writer that corresponds to this reader (same format, parameters,...
static SbBool isValidFloat(const float val)
Utility method to check if value is a valid IEEE 754 floating point number.
CoordinateType getCoordinateType()
Returns coordinate type used by the data set.
virtual void getSubSlice(const SbBox2i32 &subSlice, int sliceNumber, SoBufferObject *dataBuffer)
Same as getSubSlice( const SbBox2i32& subSlice, int sliceNumber, void * data ) but using an SoBufferO...
void * getBuffer(int64_t offset, unsigned int size)
Returns a pointer to a buffer of size bytes corresponding to a part of the file at offset bytes f...
virtual void getSubSlice(const SbBox2i32 &subSlice, int sliceNumber, void *data)
Must copy the rectangular part defined by subSlice of the XY slice sliceNumber to the memory refe...
ReadError
Read error.
@ RD_UNSUPPORTED_DATA_TYPE_ERROR
Unsupported data type (but the data is valid).
@ RD_INVALID_DATA_ERROR
Invalid data.
@ RD_FILE_NOT_FOUND_ERROR
The data file is not found.
@ RD_NO_ERROR
No error.
@ RD_UNKNOWN_ERROR
Unknown error.
@ RD_FILE_FORMAT_NOT_VALID_ERROR
Some error were detected in the file making it impossible to read.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Abstract...
int SbBool
Boolean type.
Definition SbBase.h:87