00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _LDM_READER_
00026 #define _LDM_READER_
00027
00028 #include <LDM/nodes/SoDataSet.h>
00029 #include <Inventor/STL/vector>
00030 #include <Inventor/threads/SbThread.h>
00031 #include <LDM/readers/SoVolumeReader.h>
00032 #include <LDM/xml/SbXmlTag.h>
00033
00034 #ifdef _MSC_VER
00035 #pragma warning( push )
00036 #pragma warning(disable:4251)
00037 #endif
00038
00039 class TiXmlElement;
00040 class SbThreadMutex;
00041 class SiBitFile;
00042 class SoDataCompressor;
00043 class SoDataCompressInfo;
00044
00098
00099 class SoLDMReader : public SoVolumeReader
00100 {
00101 SO_FIELDCONTAINER_HEADER(SoLDMReader);
00102
00103 public:
00104 using SoVolumeReader::getDataChar;
00105 using SoVolumeReader::getSubSlice;
00106 using SoVolumeReader::readTile;
00107
00111 enum SoLDMError{
00113 LDM_NO_ERROR,
00115 LDM_FILE_NOT_FOUND,
00117 LDM_XML_ROOT_START_TAG_NOT_FOUND,
00119 LDM_XML_ROOT_END_TAG_NOT_FOUND,
00121 LDM_ALTERNATE_FILE_NOT_FOUND,
00123 LDM_XML_PARSING_ERROR,
00125 LDM_SIZE_TAG_MISSING,
00127 LDM_COMPLETION_FILE_NOT_FOUND,
00129 LDM_RD_NO_ERROR,
00131 LDM_RD_FILE_NOT_FOUND_ERROR,
00133 LDM_RD_UNSUPPORTED_DATA_TYPE_ERROR,
00135 LDM_RD_UNKNOWN_ERROR
00136 } ;
00137
00139 SoLDMReader();
00140
00145 virtual SbBox3f getSize();
00150 virtual SbVec3i32 getDimension();
00155 virtual SbBool getTileSize(SbVec3i32& tile);
00156
00162
00163 virtual SbBool getBbox(int fileId, SbBox3f& box);
00164
00169
00170 virtual SbBool getCenter(int fileId, SbVec3f& center);
00171
00178 virtual ReadError getDataChar( SbBox3f &size, SoDataSet::DataType &type, SbVec3i32 &dim );
00179
00183 void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, void * data );
00184
00200 virtual SoBufferObject* readTile(int index, const SbBox3i32& tilePosition);
00201
00212 virtual SbBool readXTraceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const SbVec2i32& tracePosition);
00213
00224 virtual SbBool readXSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00225
00236 virtual SbBool readYSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00237
00248 virtual SbBool readZSliceInTile(int index, unsigned char*& buffer, const SbBox3i32& tilePosition, const uint32_t& slicePosition );
00249
00253 virtual SbBool getMinMax(int64_t & min, int64_t & max);
00254
00259 virtual SbBool getMinMax(double & min, double & max);
00260
00267 virtual SbBool getHistogram(std::vector<int64_t>& numVox);
00268
00273 virtual bool isLittleEndian();
00274
00280 virtual SbString getOriginalFilename() const;
00281
00289 virtual SbXmlTag getXmlTag( const char * tagName );
00290
00295 virtual ReaderType getReaderType (){return LDM;};
00296
00298 virtual SoVolumeWriter* getConfiguredWriter();
00299
00303 virtual int handleHeader(TiXmlElement *) {return LDM_NO_ERROR;} ;
00304
00308 virtual SbBool isThreadSafe() const;
00309
00311 virtual SbVec2d getTileMinMax( int fileId ) const;
00312
00313 #if 1 SoDEPRECATED
00319 virtual SbBool getTileSize(SbVec3s& size);
00320
00321 #endif
00323 #if 1 SoDEPRECATED
00329 virtual int getBorderFlag();
00330
00331 #endif
00333 #if 1 SoDEPRECATED
00366 virtual SbBool readTile(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
00367
00368 #endif
00370 #if 1 SoDEPRECATED
00377 virtual SbBool getMinMax(int & min, int & max);
00378
00379 #endif
00381 private:
00382
00387 virtual std::vector<SoDataSet::DatumElement> getDatumDescription();
00388
00392 int getNumBytesPerDatum();
00393
00394 virtual bool isLDMReader() { return true; }
00395
00396 virtual bool isVolumeMaskReader() { return false; }
00397
00404 virtual unsigned char* getHoleData();
00405
00406 SiBitFile* getFileCompletion();
00407
00408 SoLDMError getLastErr() { return m_lastError; };
00409
00410
00411 static const SbVec3i32 &getDefaultTileDim() { return DEFAULT_TILE_DIM; }
00412
00417 SbBool getCell8to1() {
00418 return m_cell8to1;
00419 }
00420
00421 #if 1 SoDEPRECATED
00427 const SbVec2d& getMinMax(int fileId) const;
00428 SoDEPRECATED
00433 bool hasPerTileMinMax() const;
00434 #endif
00441 virtual double getUndefinedValue() const;
00442
00446 virtual double getDefaultValue() const;
00447
00451 virtual void* getSpecificHeader() { return NULL; }
00452
00456 virtual uint64_t getTileSizeFromFid(int fileId);
00457
00462 virtual void closeAllHandles();
00463
00468 virtual void restoreAllHandles();
00469
00474 virtual bool isDataSetBitSet();
00475
00480 virtual void setTileDimPow2Forced( bool flag );
00481
00485 virtual SbBool isDataConverted() const
00486 { return TRUE; }
00487
00488 virtual void reloadTileMinMax();
00489
00493 virtual bool hasUndefValue();
00494
00498 virtual bool hasDefaultValue();
00499
00501 virtual SoType getCompressionType() const;
00502
00504 virtual size_t getCompressionLevel() const;
00505
00507 virtual bool useCRC32() const;
00508
00509
00510 virtual SbBool hasHistogram();
00511
00512 virtual void saveCustomsTags(FILE*) {}
00513
00517 void setHeaderDirty( bool headerDirty );
00518
00519 private:
00521 virtual ~SoLDMReader();
00522
00523 SoLDMError m_lastError;
00524 int m_makeFakeData;
00525 int m_levelMax;
00526
00527 bool readXmlHeader(int& errorCode);
00528
00529 static const SbVec3i32 DEFAULT_TILE_DIM;
00530 SbVec3i32 m_tileSize;
00531 int m_border;
00532 double m_defaultValue;
00533
00534 SbBool m_cell8to1;
00535 int m_compression;
00536 SbBox3f m_size;
00537 SbVec3i32 m_dim;
00538
00539 unsigned char* m_hole;
00540 SbBool m_HeaderRead;
00541
00542
00543 bool m_useCrc32;
00544 SoType m_compressType;
00545 size_t m_compressLevel;
00546 size_t m_numTileInfos;
00547 SoDataCompressInfo* m_compressInfos;
00548
00549
00550 SbBool m_ldmUseInMemCompression;
00551
00552 SbString m_alternateFileName;
00553 SbString m_completionFileName;
00554 SbString m_originalFile;
00555
00556 bool hasCompletionFile() const { return m_hasCompletionFile; }
00557
00558 size_t m_compressionIndexArraySize;
00559 unsigned int *m_compressionIndexArray;
00560
00561 struct Descriptor {
00562 FILE* file;
00563 SiBitFile* completion;
00564 SbThreadId_t threadID;
00565 SoDataCompressor *compressor;
00566 };
00567 std::vector<Descriptor*> m_descriptors;
00568 Descriptor* getDescriptor( SbThreadId_t id, bool forceBuffering = false );
00569
00570 SbThreadMutex* m_ldmFileMutex;
00571
00572 SbBool getFakeData(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
00573 SbBool getFakeDataGeom(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
00574 double getFakeValue( const SbBox3i32& tilePosition);
00575
00576
00577
00578
00579
00580
00581 virtual void readSpecificHeader(FILE*) {};
00582
00583
00584
00585
00586 virtual bool isSpecificHeaderRead() { return true; }
00587
00588
00589
00590
00591 virtual int getSpecificOffset(bool aligned = true) { return !aligned; }
00592
00593 void* m_xmlDoc;
00594 void* m_xmlRoot;
00595
00596 bool m_littleEndian;
00597 bool m_headerDirty;
00598
00599 void oldUncompress(FILE* dataFile, int64_t compressedSize, size_t tileSize, char* buffer);
00600 void oldGetOffsetAndSize(int index, int64_t& compressedSize, int64_t& offset);
00601
00602 void uncompressTile(Descriptor* desc, int64_t compressedSize, size_t tileSize, char* buffer);
00603 void getOffsetAndSize(Descriptor* compressor, int index, int64_t& compressedSize, int64_t& offset);
00604 void checkCrc32(char* buffer, int tileIndex, size_t tileSize);
00605
00606 private:
00607 enum DebugBorderMode
00608 {
00609 NORMAL_BORDERS = 0,
00610 MARK_BORDERS = 1,
00611 ONLY_BORDERS = 2
00612 };
00613
00614
00615 void internalInit();
00616
00618 template<typename T> void getFakeDataNoise(void* buffer, const SbBox3i32& tilePosition);
00619
00621 void visibleBorder(unsigned char* buffer);
00622
00624 void readBorderOnly(unsigned char* buffer);
00625
00627 void readTileMinMax(TiXmlElement *s);
00628
00630 void extractUndefValue(TiXmlElement* element);
00631
00633 std::vector<SbVec2d> m_tileMinMax;
00634
00636 double m_undefValue;
00637
00639 bool m_hasUndefValue;
00640
00642 bool m_hasDefaultValue;
00643
00645 bool m_fakeDataNoise;
00646 unsigned int m_fakeDataNumOctaves;
00647 float m_fakeDataPersistence;
00648
00650 static DebugBorderMode s_debugBorders;
00651
00652 bool m_hasCompletionFile;
00653 SbBool m_hasAlternateFile;
00654
00655
00656 bool m_bIsBitSetDataSet;
00657
00659 bool m_forcePow2TileDim;
00660
00661
00662
00663 void resetInternalPath();
00664 };
00665
00666
00667 inline SbBool
00668 SoLDMReader::getBbox(int , SbBox3f& )
00669 {
00670 return FALSE;
00671 }
00672
00673 inline SbBool
00674 SoLDMReader::getCenter(int , SbVec3f& )
00675 {
00676 return FALSE;
00677 }
00678
00679 inline void
00680 SoLDMReader::getSubSlice( const SbBox2i32& , int , void *)
00681 {
00682 }
00683
00684 #if 1
00685 inline SbBool
00686 SoLDMReader::getMinMax(int & , int & )
00687 {
00688 return FALSE;
00689 }
00690 #endif
00692 inline SbBool
00693 SoLDMReader::getMinMax(int64_t & , int64_t & )
00694 {
00695 return FALSE;
00696 }
00697
00698 inline
00699 SbBool SoLDMReader::getMinMax(double & , double & )
00700 {
00701 return FALSE;
00702 }
00703
00704 inline SbBool
00705 SoLDMReader::getHistogram(std::vector<int64_t>& )
00706 {
00707 return FALSE;
00708 }
00709
00710 inline SbBool
00711 SoLDMReader::hasHistogram()
00712 {
00713 return FALSE;
00714 }
00715
00716 inline void
00717 SoLDMReader::setHeaderDirty( bool headerDirty )
00718 {
00719 m_headerDirty = headerDirty;
00720 }
00721
00722 inline uint64_t
00723 SoLDMReader::getTileSizeFromFid(int)
00724 {
00725 return 0;
00726 }
00727
00728 inline void
00729 SoLDMReader::setTileDimPow2Forced( bool flag )
00730 {
00731 m_forcePow2TileDim = flag;
00732 }
00733
00734 #ifdef _MSC_VER
00735 #pragma warning( pop )
00736 #endif
00737
00738 #endif
00739
00740
00741