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 SoVolumeReader::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 SoVolumeReader::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 index ) const;
00312
00313 #if 1 SoDEPRECATED
00319 virtual int getBorderFlag();
00320
00321 #endif
00323 #if 1 SoDEPRECATED
00356 virtual SbBool readTile(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
00357
00358 #endif
00360 #if 1 SoDEPRECATED
00367 virtual SbBool getMinMax(int & min, int & max);
00368
00369 #endif
00371 private:
00372
00377 virtual std::vector<SoDataSet::DatumElement> getDatumDescription();
00378
00382 int getNumBytesPerDatum();
00383
00384 virtual bool isLDMReader() { return true; }
00385
00386 virtual bool isVolumeMaskReader() { return false; }
00387
00394 virtual unsigned char* getHoleData();
00395
00396 SiBitFile* getFileCompletion();
00397
00398 SoLDMError getLastErr() { return m_lastError; };
00399
00400
00401 static const SbVec3i32 &getDefaultTileDim() { return DEFAULT_TILE_DIM; }
00402
00407 SbBool getCell8to1() {
00408 return m_cell8to1;
00409 }
00410
00411 #if 1 SoDEPRECATED
00417 const SbVec2d& getMinMax(int fileId) const;
00418 SoDEPRECATED
00423 bool hasPerTileMinMax() const;
00424 #endif
00431 virtual double getUndefinedValue() const;
00432
00436 virtual double getDefaultValue() const;
00437
00441 virtual void* getSpecificHeader() { return NULL; }
00442
00446 virtual uint64_t getTileSizeFromFid(int fileId);
00447
00452 virtual void closeAllHandles();
00453
00458 virtual void restoreAllHandles();
00459
00464 virtual bool isDataSetBitSet();
00465
00470 virtual void setTileDimPow2Forced( bool flag );
00471
00475 virtual SbBool isDataConverted() const
00476 { return TRUE; }
00477
00478 virtual void reloadTileMinMax();
00479
00483 virtual bool hasUndefValue();
00484
00488 virtual bool hasDefaultValue();
00489
00491 virtual SoType getCompressionType() const;
00492
00494 virtual size_t getCompressionLevel() const;
00495
00497 virtual bool useCRC32() const;
00498
00499
00500 virtual SbBool hasHistogram();
00501
00502 virtual void saveCustomsTags(FILE*) {}
00503
00507 void setHeaderDirty( bool headerDirty );
00508
00513 void setTileCachePolicy( SoLDMResourceParameters::TileCachePolicy tileCachePolicy );
00514
00515 private:
00517 virtual ~SoLDMReader();
00518
00519 SoLDMError m_lastError;
00520 int m_makeFakeData;
00521 int m_levelMax;
00522
00523 bool readXmlHeader(int& errorCode);
00524
00525 static const SbVec3i32 DEFAULT_TILE_DIM;
00526 SbVec3i32 m_tileSize;
00527 int m_border;
00528 double m_defaultValue;
00529
00530 SbBool m_cell8to1;
00531 int m_compression;
00532 SbBox3f m_size;
00533 SbVec3i32 m_dim;
00534
00535 unsigned char* m_hole;
00536
00537
00538 bool m_useCrc32;
00539 SoType m_compressType;
00540 size_t m_compressLevel;
00541 size_t m_numTileInfos;
00542 SoDataCompressInfo* m_compressInfos;
00543
00544 SbString m_alternateFileName;
00545 SbString m_completionFileName;
00546 SbString m_originalFile;
00547
00548 bool hasCompletionFile() const { return m_hasCompletionFile; }
00549
00550 size_t m_compressionIndexArraySize;
00551 unsigned int *m_compressionIndexArray;
00552
00553 struct Descriptor {
00554 FILE* file;
00555 SiBitFile* completion;
00556 SbThreadId_t threadID;
00557 SoDataCompressor *compressor;
00558 };
00559 std::vector<Descriptor*> m_descriptors;
00560 Descriptor* getDescriptor( SbThreadId_t id, bool forceBuffering = false );
00561
00562 SbThreadMutex* m_ldmFileMutex;
00563
00564 SbBool getFakeData(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
00565 SbBool getFakeDataGeom(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
00566 double getFakeValue( const SbBox3i32& tilePosition);
00567
00568
00569
00570
00571
00572
00573 virtual void readSpecificHeader(FILE*) {};
00574
00575
00576
00577
00578 virtual bool isSpecificHeaderRead() { return true; }
00579
00580
00581
00582
00583 virtual int getSpecificOffset(bool aligned = true) { return !aligned; }
00584
00585 void* m_xmlDoc;
00586 void* m_xmlRoot;
00587
00588 bool m_littleEndian;
00589 bool m_headerDirty;
00590
00591 void oldUncompress(FILE* dataFile, int64_t compressedSize, size_t tileSize, char* buffer);
00592 void oldGetOffsetAndSize(int index, int64_t& compressedSize, int64_t& offset);
00593
00594 void uncompressTile(Descriptor* desc, int64_t compressedSize, size_t tileSize, char* buffer);
00595 void getOffsetAndSize(Descriptor* compressor, int index, int64_t& compressedSize, int64_t& offset);
00596 void checkCrc32(char* buffer, int tileIndex, size_t tileSize);
00597
00598 private:
00599 enum DebugBorderMode
00600 {
00601 NORMAL_BORDERS = 0,
00602 MARK_BORDERS = 1,
00603 ONLY_BORDERS = 2
00604 };
00605
00606
00607 void internalInit();
00608
00610 template<typename T> void getFakeDataNoise(void* buffer, const SbBox3i32& tilePosition);
00611
00613 void visibleBorder(unsigned char* buffer);
00614
00616 void readBorderOnly(unsigned char* buffer);
00617
00619 void readTileMinMax(TiXmlElement *s);
00620
00622 void extractUndefValue(TiXmlElement* element);
00623
00625 std::vector<SbVec2d> m_tileMinMax;
00626
00628 double m_undefValue;
00629
00631 bool m_hasUndefValue;
00632
00634 bool m_hasDefaultValue;
00635
00637 bool m_fakeDataNoise;
00638 unsigned int m_fakeDataNumOctaves;
00639 float m_fakeDataPersistence;
00640
00642 static DebugBorderMode s_debugBorders;
00643
00644 bool m_hasCompletionFile;
00645 SbBool m_hasAlternateFile;
00646
00647
00648 bool m_bIsBitSetDataSet;
00649
00651 bool m_forcePow2TileDim;
00652
00653
00654
00655
00656 double getFakeValueBasedOnTopoOctree( const int fileId );
00657
00658
00659
00660 SoLDMTopoOctree m_topoOctree;
00661
00663 SoLDMResourceParameters::TileCachePolicy m_tileCachePolicy;
00664
00665
00666
00667 void resetInternalPath();
00668 };
00669
00670
00671 inline SbBool
00672 SoLDMReader::getBbox(int , SbBox3f& )
00673 {
00674 return FALSE;
00675 }
00676
00677 inline SbBool
00678 SoLDMReader::getCenter(int , SbVec3f& )
00679 {
00680 return FALSE;
00681 }
00682
00683 inline void
00684 SoLDMReader::getSubSlice( const SbBox2i32& , int , void *)
00685 {
00686 }
00687
00688 #if 1
00689 inline SbBool
00690 SoLDMReader::getMinMax(int & , int & )
00691 {
00692 return FALSE;
00693 }
00694 #endif
00696 inline SbBool
00697 SoLDMReader::getMinMax(int64_t & , int64_t & )
00698 {
00699 return FALSE;
00700 }
00701
00702 inline
00703 SbBool SoLDMReader::getMinMax(double & , double & )
00704 {
00705 return FALSE;
00706 }
00707
00708 inline SbBool
00709 SoLDMReader::getHistogram(std::vector<int64_t>& )
00710 {
00711 return FALSE;
00712 }
00713
00714 inline SbBool
00715 SoLDMReader::hasHistogram()
00716 {
00717 return FALSE;
00718 }
00719
00720 inline void
00721 SoLDMReader::setHeaderDirty( bool headerDirty )
00722 {
00723 m_headerDirty = headerDirty;
00724 }
00725
00726 inline uint64_t
00727 SoLDMReader::getTileSizeFromFid(int)
00728 {
00729 return 0;
00730 }
00731
00732 inline void
00733 SoLDMReader::setTileDimPow2Forced( bool flag )
00734 {
00735 m_forcePow2TileDim = flag;
00736 }
00737
00738 #ifdef _MSC_VER
00739 #pragma warning( pop )
00740 #endif
00741
00742 #endif
00743
00744
00745