Open Inventor Release 2025.2.2
 
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-2025 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;
252class SoVolumeReader : public SoFieldContainer
253{
254 SO_FIELDCONTAINER_ABSTRACT_HEADER(SoVolumeReader);
255
256 public:
257
288
293 enum Axis {
297 };
298
304
305#ifndef HIDDEN_FROM_DOC
312 SoSFBool isRetilingSupported;
313#endif
314
330
337 virtual SbBool setOutputDataType( SbBool doChange, SoDataSet::DataType outputType );
338
347 virtual SbBool setInputDataRange( SbBool doChange, double min, double max );
348
358 virtual int getNumSignificantBits() { return 0; };
359
375 virtual void getSubSlice(const SbBox2i32& subSlice, int sliceNumber, void* data);
376
409 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, SoBufferObject * dataBuffer);
410
425 SbVec3i32 getNumVoxels( const SbVec3i32& realSize, const SbVec3i32& subsamplingLevel );
426
436 SbVec3i32 getSizeToAllocate( const SbVec3i32& realSize, const SbVec3i32& subsamplingLevel );
437
442 virtual int setFilename( const SbString& filename );
443
448
449 //------------ for LDM -----------------//
459 virtual SbBool isDataConverted() const;
460
461 virtual void reloadTileMinMax() {};
462
469
490 virtual SoBufferObject* readTile(int index, const SbBox3i32& tilePosition);
491
505 virtual SbBool readXTraceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const SbVec2i32& tracePosition);
506
520 virtual SbBool readYSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
521
535 virtual SbBool readZSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
536
550 virtual SbBool readXSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
551
559 virtual SbBool isThreadSafe() const;
560
564 virtual SbBool isIgnoredFile() const;
565
571 { return SbString(""); }
572
582 virtual SbBool getMinMax(int64_t & min, int64_t & max);
583
593 virtual SbBool getMinMax(double & min, double & max);
594
600 virtual SbBool getHistogram(std::vector<int64_t>& numVox);
601
614
621 virtual SbBool setDirectCoorSys(SbBool directCoord);
622
626 virtual SbBool getDirectCoordSys();
627
667 virtual SbVec2d getTileMinMax( int index ) const;
668
700
705
772
786
791
798 const float * getRectilinearCoordinates(Axis axis) const;
799
803 void setRectilinearCoordinates(const float *x, const float *y, const float *z);
804
810 virtual SbBool isRGBA() const
811 { return m_isRGBA; }
812
817 inline void setRGBA(const SbBool flag)
818 { m_isRGBA = flag; }
819
828 virtual void closeAllHandles() {};
829
833 virtual void restoreAllHandles() {};
834
847
848#if 1
849SoDEPRECATED
881 virtual SbBool readTile(int SO_UNUSED_PARAM(index), unsigned char*& SO_UNUSED_PARAM(buffer), const SbBox3i32& SO_UNUSED_PARAM(tilePosition)) { return FALSE; }
882SoDEPRECATED
889 virtual SbBool readTile(int index, SoBufferObject *buffer, const SbBox3i32& tilePosition);
890
891#endif
892
893#if 1
894SoDEPRECATED
899 virtual int getBorderFlag()
900 {return -1;}
901
902#endif
903
904#if 1
905SoDEPRECATED
911 virtual SbBool getMinMax(int& min, int& max);
912
913#endif
914
915private:
916 //for volume having a series of data per datum
917 //used by ReservoirViz. The converter asks the eclipse reader for the datum.
918 //not used in vviz which uses getDataChar(...type...). (must keep for compatibility reasons).
919 virtual ReadError getDataChar( SbBox3f &size, std::vector<SoDataSet::DatumElement>& datum, SbVec3i32 &dim );
920
921 void lockFileMutex();
922 void unlockFileMutex();
923
933 void convert( SoDataSet::DataType typeIn , SoBufferObject* bufferIn,
934 SoDataSet::DataType typeOut, SoBufferObject* bufferOut, size_t size, SbBool shiftData = true);
935
936 void convertDataRange( bool doRange, double min, double max );
937
938 virtual int getNumBytesPerDatum();
939
940 // number of bytes in a voxel
941 // uses DataType if getNumBytesPerDatum() returns 0
942 int getDataSize();
943
944 virtual bool isLDMReader() { return false; }
945 virtual bool isVolumeMaskReader() { return false; }
946
947 virtual bool hasDeadCell() { return false; }
948
949 virtual bool isDead(int i,int j,int k);
950
951 virtual uint8_t* getCellGridState() { return NULL; }
952
953 virtual int getNbCell() { return 0; }
954
955 virtual uint64_t getTileSizeFromFid(int fileId);// Virtual method, only used
956 // by resviz for now
957
961 bool hasPerTileMinMaxComputed();
962
963#if 1
964SoDEPRECATED
966 void convert( SoDataSet::DataType typeIn , void* bufferIn,
967 SoDataSet::DataType typeOut, void* bufferOut, size_t size, SbBool shiftData = true);
968
969#endif
970
975 virtual SoVolumeReader* getInternalReader() const
976 {
977 return const_cast<SoVolumeReader*>(this);
978 }
979
980 private: protected:
1009 static bool registerVolumeReaderExtension(const SbString& fileExtension, const SoType& readerType);
1010
1020 static bool unregisterVolumeReaderExtensions(const SoType& readerType);
1021
1026
1035 void *getBuffer(int64_t offset, unsigned int size);
1036
1037 // Convenient methods
1038
1045 static int bytesToInt(const unsigned char* ptr, int sizeBytes);
1046
1052 static void swapBytes( int *intPtr, int sizeBytes );
1053
1060 static void swapBytesN( void *buffer, int numElements, int numBytesPerElement );
1061
1065 static SbBool isValidFloat( const float val );
1066
1070 int64_t fileSize();
1071
1072#if 1
1073SoDEPRECATED
1076
1077#endif
1078
1079 //------------------------------------------------------------------------------
1080#ifndef HIDDEN_FROM_DOC
1081 SbString m_filename;
1082
1083#endif // HIDDEN_FROM_DOC
1084
1085
1091 static SbBox3f adjustFlatExtent(const SbString& fileName, const SbBox3f& extent, const SbVec3i32& dim);
1092
1093private:
1094
1095 //if true, try to detect automatically whether the coord sys is diret or not.
1096 //default is true
1097 SbBool m_directCoordSysAutoDetect;
1098 //has the data been stored using a direct coordinate system?
1099 //default is true
1100 SbBool m_directCoordSys;
1101
1102 std::vector<SoDataSet::DatumElement> m_datum;
1103 int m_bytesPerVoxel;
1104
1105 double m_rangeMin, m_rangeMax;
1106 bool m_doRange;
1107
1108 //True if header has already been read
1109 SbBool m_headerRead;
1110
1111 CoordinateType m_coordinateType;
1112 std::vector<float> m_rectilinearCoordinates[3];
1113
1114 SbBool m_ignoredFile;
1115
1116SoINTERNAL private:
1117 // Used to guard the buffer obtained by calling getBuffer()
1118 SbThreadMutex* m_fmmMutex;
1119
1120private:
1121 SbBool m_isRGBA;
1122 SbBool m_useFMM;
1123 void *m_filehandle;
1124 int m_filedesc;
1125 int64_t m_filesize;
1126 void *m_fmmdata;
1127 int64_t m_fmmoffset;
1128 unsigned int m_fmmsize;
1129 bool m_hasPerTileMinMaxComputed;
1130
1131 void releasefmm();
1132 void bestmap(int64_t);
1133
1134 SbThreadMutex* m_fileMutex;
1135
1136 // keep a map of readerType <-> extension association
1137 typedef std::map<SbString,SoType> SoVolumeReaderExtensionAssociationMap;
1138 static SoVolumeReaderExtensionAssociationMap s_volumeReaderExtensionAssociation;
1139
1140 // Convert range from input type to given TypeOut type.
1141 template <typename TypeInt, typename TypeOut>
1142 void convert_range(size_t size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
1143
1144 // Convert float input type to any supported type
1145 template <typename TypeOut>
1146 void convert_out(size_t size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
1147
1148 // Convert any input type to float output
1149 template <typename TypeIn>
1150 void convert_in(size_t size, void* bufferIn, void* bufferOut, int64_t outMin, int64_t outMax);
1151
1152};
1153
1154inline SbBool
1155SoVolumeReader::readXTraceInTile(int , unsigned char*& , const SbBox3i32& , const SbVec2i32& )
1156{
1157 return FALSE;
1158}
1159
1160inline SbBool
1161SoVolumeReader::readXSliceInTile(int , unsigned char*& , const SbBox3i32& , const uint32_t& )
1162{
1163 return FALSE;
1164}
1165
1166inline SbBool
1167SoVolumeReader::readYSliceInTile(int , unsigned char*& , const SbBox3i32& , const uint32_t& )
1168{
1169 return FALSE;
1170}
1171
1172inline SbBool
1174{
1175 return FALSE;
1176}
1177
1178inline SbBool
1179SoVolumeReader::getMinMax(int64_t &, int64_t &)
1180{
1181 return FALSE;
1182}
1183
1184inline SbBool
1186{
1187 return m_ignoredFile;
1188}
1189
1190inline SbBool
1191SoVolumeReader::getMinMax(double & , double & )
1192{
1193 return FALSE;
1194}
1195
1196inline SbBool
1197SoVolumeReader::getHistogram(std::vector<int64_t>&)
1198{
1199 return FALSE;
1200}
1201
1202inline SbBool
1207
1208inline SbBool
1210{
1211 return m_directCoordSysAutoDetect;
1212}
1213
1214inline SbBool
1216{
1217 return FALSE;
1218}
1219
1220inline SbBool
1222{
1223 return m_directCoordSys;
1224}
1225
1226inline bool
1227SoVolumeReader::isDead(int, int, int)
1228{
1229 return false;
1230}
1231
1232inline uint64_t
1233SoVolumeReader::getTileSizeFromFid(int)
1234{
1235 return 0;
1236}
1237
1238#ifdef _MSC_VER
1239#pragma warning( pop )
1240#endif
1241
1242#endif // _SO_VOLUME_READER_
1243
1244
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:669
Field containing a single Boolean value.
Definition SoSFBool.h:79
Stores runtime type information.
Definition SoType.h:98
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