Open Inventor Release 2024.1.0
 
Loading...
Searching...
No Matches
SoLDMReader.h
Go to the documentation of this file.
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 : VSG (MMM YYYY)
22**=======================================================================*/
23
24
25#ifndef _LDM_READER_
26#define _LDM_READER_
27
28#include <LDM/nodes/SoDataSet.h>
29#include <Inventor/STL/vector>
32#include <LDM/xml/SbXmlTag.h>
33
34#ifdef _MSC_VER
35#pragma warning( push )
36#pragma warning(disable:4251)
37#endif
38
39class TiXmlElement;
40class SbThreadMutex;
41class SiBitFile;
43class SoDataCompressInfo;
44
98{
100
101public:
105
135
138
143 virtual SbBox3f getSize();
154
160 //not used in vviz. used on resviz because the geom is not implicit anymore.
161 virtual SbBool getBbox(int fileId, SbBox3f& box);
162
167 //not used in vviz. used on resviz because the geom is not implicit anymore.
168 virtual SbBool getCenter(int fileId, SbVec3f& center);
169
174
178 void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, void * data );
179
195 virtual SoBufferObject* readTile(int index, const SbBox3i32& tilePosition);
196
207 virtual SbBool readXTraceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const SbVec2i32& tracePosition);
208
219 virtual SbBool readXSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
220
231 virtual SbBool readYSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
232
243 virtual SbBool readZSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
244
248 virtual SbBool getMinMax(int64_t & min, int64_t & max);
249
254 virtual SbBool getMinMax(double & min, double & max);
255
262 virtual SbBool getHistogram(std::vector<int64_t>& numVox);
263
268 virtual bool isLittleEndian();
269
276
284 virtual SbXmlTag getXmlTag( const char * tagName );
285
291
294
298 virtual int handleHeader(TiXmlElement *) {return LDM_NO_ERROR;} ;
299
303 virtual SbBool isThreadSafe() const;
304
306 virtual SbVec2d getTileMinMax( int index ) const;
307
308#if 1 SoDEPRECATED
314 virtual int getBorderFlag();
315
316#endif
318#if 1 SoDEPRECATED
351 virtual SbBool readTile(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
352
353#endif
355#if 1 SoDEPRECATED
362 virtual SbBool getMinMax(int & min, int & max);
363
364#endif
366 private:
367
372 virtual std::vector<SoDataSet::DatumElement> getDatumDescription();
373
377 int getNumBytesPerDatum();
378
379 virtual bool isLDMReader() { return true; }
380
381 virtual bool isVolumeMaskReader() { return false; }
382
389 virtual unsigned char* getHoleData();
390
391 SiBitFile* getFileCompletion();
392
393 SoLDMError getLastErr() { return m_lastError; };
394
395 //Return the default size of a tile (64x64x64)
396 static const SbVec3i32 &getDefaultTileDim() { return DEFAULT_TILE_DIM; }
397
402 SbBool getCell8to1() {
403 return m_cell8to1;
404 }
405
406#if 1 SoDEPRECATED
412 const SbVec2d& getMinMax(int fileId) const;
413SoDEPRECATED
418 bool hasPerTileMinMax() const;
419#endif
426 virtual double getUndefinedValue() const;
427
431 virtual double getDefaultValue() const;
432
436 virtual void* getSpecificHeader() { return NULL; }
437
441 virtual uint64_t getTileSizeFromFid(int fileId);
442
447 virtual void closeAllHandles();
448
453 virtual void restoreAllHandles();
454
459 virtual bool isDataSetBitSet();
460
465 virtual void setTileDimPow2Forced( bool flag );
466
470 virtual SbBool isDataConverted() const
471 { return TRUE; }
472
473 virtual void reloadTileMinMax();
474
478 virtual bool hasUndefValue();
479
483 virtual bool hasDefaultValue();
484
486 virtual SoType getCompressionType() const;
487
489 virtual size_t getCompressionLevel() const;
490
492 virtual bool useCRC32() const;
493
494 // Internal use only. Return true if reader has an histogram (check m_entries size).
495 virtual SbBool hasHistogram();
496
497 virtual void saveCustomsTags(FILE*) {}
498
502 void setHeaderDirty( bool headerDirty );
503
508 void setTileCachePolicy( SoLDMResourceParameters::TileCachePolicy tileCachePolicy );
509
510private:
512 virtual ~SoLDMReader();
513
514 SoLDMError m_lastError;
515 int m_makeFakeData;
516 int m_levelMax;
517
518 bool readXmlHeader(int& errorCode);
519
520 static const SbVec3i32 DEFAULT_TILE_DIM;
521 SbVec3i32 m_tileSize;
522 int m_border;
523 double m_defaultValue;
524
525 SbBool m_cell8to1;
526 int m_compression;
527 SbBox3f m_size;
528 SbVec3i32 m_dim;
529
530 unsigned char* m_hole;
531
532 //Compression
533 bool m_useCrc32;
534 SoType m_compressType;
535 size_t m_compressLevel;
536 size_t m_numTileInfos;
537 SoDataCompressInfo* m_compressInfos;
538
539 SbString m_alternateFileName;
540 SbString m_completionFileName;
541 SbString m_originalFile;
542
543 bool hasCompletionFile() const { return m_hasCompletionFile; }
544
545 size_t m_compressionIndexArraySize;
546 unsigned int *m_compressionIndexArray;
547
548 struct Descriptor {
549 FILE* file;
550 SiBitFile* completion;
551 SbThreadId_t threadID;
552 SoDataCompressor *compressor;
553 };
554 std::vector<Descriptor*> m_descriptors;
555 Descriptor* getDescriptor( SbThreadId_t id, bool forceBuffering = false );
556
557 SbThreadMutex* m_ldmFileMutex;
558
562 SbBool getFakeData(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
563
567 SbBool getFakeDataGeom(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
568
569 double getFakeValue( const SbBox3i32& tilePosition);
570
571 /* These three function have been added to handle specific header
572 * managed by specific reader
573 */
574
575 // Read the specific header from file
576 virtual void readSpecificHeader(FILE*) {}; // No name for parameter to avoid compilation warning
577 // parameter is the name of the file currently read
578
579 // Flag to determine if the specific header has already
580 // been read
581 virtual bool isSpecificHeaderRead() { return true; }
582
583 // get the specific offset from the specific header. This offset
584 // represent the amount of data added by specific reader at the beginning
585 // of the LDM file
586 virtual int getSpecificOffset(bool aligned = true) { return !aligned; }
587
588 void* m_xmlDoc;
589 void* m_xmlRoot;// a son can parse header from m_xmlRoot
590
591 bool m_littleEndian;
592 bool m_headerDirty;
593
594 void oldUncompress(FILE* dataFile, int64_t compressedSize, size_t tileSize, char* buffer);
595 void oldGetOffsetAndSize(int index, int64_t& compressedSize, int64_t& offset);
596
597 void uncompressTile(Descriptor* desc, int64_t compressedSize, size_t tileSize, char* buffer);
598 void getOffsetAndSize(Descriptor* compressor, int index, int64_t& compressedSize, int64_t& offset);
599 void checkCrc32(char* buffer, int tileIndex, size_t tileSize);
600
601private:
602 enum DebugBorderMode
603 {
604 NORMAL_BORDERS = 0,
605 MARK_BORDERS = 1,
606 ONLY_BORDERS = 2
607 };
608
609
610 void internalInit();
611
613 template<typename T> void getFakeDataNoise(void* buffer, const SbBox3i32& tilePosition);
614
616 void visibleBorder(unsigned char* buffer);
617
619 void readBorderOnly(unsigned char* buffer);
620
622 void readTileMinMax(TiXmlElement *s);
623
625 void extractUndefValue(TiXmlElement* element);
626
628 std::vector<SbVec2d> m_tileMinMax;
629
631 double m_undefValue;
632
634 bool m_hasUndefValue;
635
637 bool m_hasDefaultValue;
638
640 bool m_fakeDataNoise;
641 unsigned int m_fakeDataNumOctaves;
642 float m_fakeDataPersistence;
643
645 static DebugBorderMode s_debugBorders;
646
647 bool m_hasCompletionFile;
648 SbBool m_hasAlternateFile;
649
650 // Specific flag to handle bitset dataset
651 bool m_bIsBitSetDataSet;
652
654 bool m_forcePow2TileDim;
655
656 // Used only with a fake uniform reader
657 // return fake uniform value based on topoOctree and fileId
658 // Should return same value as getFakeValue( const SbBox3i32& tilePosition)
659 double getFakeValueBasedOnTopoOctree( const int fileId );
660
661 // Used only with a fake uniform reader
662 // TopoOctree only used by getFakeValueBasedOnTopoOctree
663 SoLDMTopoOctree m_topoOctree;
664
667
668 // Used to restore internal path after filename has been changed
669 // mainly used be edition
670 void resetInternalPath();
671};
672
673/*******************************************************************************/
674inline SbBool
676{
677 return FALSE;
678}
679
680inline SbBool
682{
683 return FALSE;
684}
685
686inline void
687SoLDMReader::getSubSlice( const SbBox2i32& , int , void *)
688{
689}
690
692inline SbBool
693SoLDMReader::getMinMax(int & , int & )
694{
695 return FALSE;
696}
697
698inline SbBool
699SoLDMReader::getMinMax(int64_t & , int64_t & )
700{
701 return FALSE;
702}
703
704inline
705SbBool SoLDMReader::getMinMax(double & , double & )
706{
707 return FALSE;
708}
709
710inline SbBool
711SoLDMReader::getHistogram(std::vector<int64_t>& )
712{
713 return FALSE;
714}
715
716inline SbBool
717SoLDMReader::hasHistogram()
718{
719 return FALSE;
720}
721
722inline void
723SoLDMReader::setHeaderDirty( bool headerDirty )
724{
725 m_headerDirty = headerDirty;
726}
727
728inline uint64_t
729SoLDMReader::getTileSizeFromFid(int)
730{
731 return 0;
732}
733
734inline void
735SoLDMReader::setTileDimPow2Forced( bool flag )
736{
737 m_forcePow2TileDim = flag;
738}
740
741#ifdef _MSC_VER
742#pragma warning( pop )
743#endif
744
745#endif
746
747
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
#define FALSE
Possible value of SbBool.
Definition SbBase.h:75
#define SO_FIELDCONTAINER_HEADER(className)
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:932
3D vector class.
Definition SbVec.h:1517
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> XML tag ...
Definition SbXmlTag.h:122
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Data com...
DataType
Supported data type.
Definition SoDataSet.h:604
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Base cla...
Definition SoLDMReader.h:98
virtual SbBool readXTraceInTile(int index, unsigned char *&buffer, const SbBox3i32 &tilePosition, const SbVec2i32 &tracePosition)
Read directly from the LDM data source, a trace inside a tile.
virtual SbBool getCenter(int fileId, SbVec3f &center)
Returns the center of the data associated with the specified file ID.
virtual SbBool getHistogram(std::vector< int64_t > &numVox)
Returns the distribution of data values, i.e., the number of voxels per data value.
virtual int handleHeader(TiXmlElement *)
Handle tags of LDM reader inheriting from this base class.
virtual SbBool getMinMax(int64_t &min, int64_t &max)
Returns the minimum and maximum data values.
virtual SbString getOriginalFilename() const
Returns original file name from which the data has been converted to LDM format if stored in file.
SoLDMError
LDM Reader error code.
@ LDM_XML_ROOT_START_TAG_NOT_FOUND
XML START Tag not found.
@ LDM_RD_FILE_NOT_FOUND_ERROR
file not found
@ LDM_RD_NO_ERROR
No error.
@ LDM_RD_UNSUPPORTED_DATA_TYPE_ERROR
Unsupported data file type.
@ LDM_RD_UNKNOWN_ERROR
Unknown error.
@ LDM_XML_PARSING_ERROR
XML parsing error.
@ LDM_ALTERNATE_FILE_NOT_FOUND
Alternate file not found.
@ LDM_NO_ERROR
no error
@ LDM_XML_ROOT_END_TAG_NOT_FOUND
XML END Tag not found.
@ LDM_FILE_NOT_FOUND
file not found
@ LDM_COMPLETION_FILE_NOT_FOUND
Completion file not found.
@ LDM_SIZE_TAG_MISSING
Size tag missing.
virtual SbVec3i32 getDimension()
Returns the dimension of the data.
virtual ReadError getDataChar(SbBox3f &size, SoDataSet::DataType &type, SbVec3i32 &dim) override
Gets the characteristics (file header) of the data volume.
virtual SoDEPRECATED int getBorderFlag()
Returns the border flag.
virtual SbBool getMinMax(double &min, double &max)
Returns the minimum and maximum data values (for float values).
virtual SbBool readYSliceInTile(int index, unsigned char *&buffer, const SbBox3i32 &tilePosition, const uint32_t &slicePosition)
Read directly from the LDM data source, an orthoslice on the Y axis inside a tile.
virtual bool isLittleEndian()
Returns whether the bytes of the data are stored in big or little endian order.
virtual SbBool getTileSize(SbVec3i32 &tile)
Returns the size of a data tile.
virtual SoVolumeReader::ReaderType getReaderType()
Returns the reader type.
virtual SbBool readXSliceInTile(int index, unsigned char *&buffer, const SbBox3i32 &tilePosition, const uint32_t &slicePosition)
Read directly from the LDM data source, an orthoslice on the X axis inside a tile.
virtual SbBool isThreadSafe() const
Return true as this reader is thread safe.
SoLDMReader()
Constructor.
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 SbVec2d getTileMinMax(int index) const
Returns the minimum and maximum data values for the given tile.
virtual SoDEPRECATED SbBool getMinMax(int &min, int &max)
Returns the minimum and maximum data values.
virtual SbBool readZSliceInTile(int index, unsigned char *&buffer, const SbBox3i32 &tilePosition, const uint32_t &slicePosition)
Read directly from the LDM data source, an orthoslice on the Z axis inside a tile.
virtual SoBufferObject * readTile(int index, const SbBox3i32 &tilePosition)
Given an index, reads a tile if the data is organized in tiles (for LDM).
virtual SbXmlTag getXmlTag(const char *tagName)
Gets the first occurrence of the XML element whose tag name is specified by tagName.
virtual SbBool getBbox(int fileId, SbBox3f &box)
Returns the bounding box of the data associated with the specified file ID.
void getSubSlice(const SbBox2i32 &subSlice, int sliceNumber, void *data)
Note: SoLDMReader does not implement this method.
virtual SbBox3f getSize()
Returns the bounding box of the total data in world coordinates.
virtual SoVolumeWriter * getConfiguredWriter()
Returns a volume writer that corresponds to this reader (same format, parameters,...
TileCachePolicy
Tile cache management policy.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Octree t...
Stores runtime type information.
Definition SoType.h:98
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Abstract...
virtual SoBufferObject * readTile(int index, const SbBox3i32 &tilePosition)
Given an index, reads a tile if the data is organized in tiles (for LDM).
virtual ReadError getDataChar(SbBox3f &size, SoDataSet::DataType &type, SbVec3i32 &dim)=0
Gets the characteristics (file header) of the data volume.
ReaderType
Available reader type.
@ LDM
Open Inventor LDM.
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.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Abstract...
int SbBool
Boolean type.
Definition SbBase.h:87
size_t size() const