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 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 SbBool m_HeaderRead;
00537
00538
00539 bool m_useCrc32;
00540 SoType m_compressType;
00541 size_t m_compressLevel;
00542 size_t m_numTileInfos;
00543 SoDataCompressInfo* m_compressInfos;
00544
00545 SbString m_alternateFileName;
00546 SbString m_completionFileName;
00547 SbString m_originalFile;
00548
00549 bool hasCompletionFile() const { return m_hasCompletionFile; }
00550
00551 size_t m_compressionIndexArraySize;
00552 unsigned int *m_compressionIndexArray;
00553
00554 struct Descriptor {
00555 FILE* file;
00556 SiBitFile* completion;
00557 SbThreadId_t threadID;
00558 SoDataCompressor *compressor;
00559 };
00560 std::vector<Descriptor*> m_descriptors;
00561 Descriptor* getDescriptor( SbThreadId_t id, bool forceBuffering = false );
00562
00563 SbThreadMutex* m_ldmFileMutex;
00564
00565 SbBool getFakeData(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
00566 SbBool getFakeDataGeom(int index, unsigned char*&buffer, const SbBox3i32& tilePosition);
00567 double getFakeValue( const SbBox3i32& tilePosition);
00568
00569
00570
00571
00572
00573
00574 virtual void readSpecificHeader(FILE*) {};
00575
00576
00577
00578
00579 virtual bool isSpecificHeaderRead() { return true; }
00580
00581
00582
00583
00584 virtual int getSpecificOffset(bool aligned = true) { return !aligned; }
00585
00586 void* m_xmlDoc;
00587 void* m_xmlRoot;
00588
00589 bool m_littleEndian;
00590 bool m_headerDirty;
00591
00592 void oldUncompress(FILE* dataFile, int64_t compressedSize, size_t tileSize, char* buffer);
00593 void oldGetOffsetAndSize(int index, int64_t& compressedSize, int64_t& offset);
00594
00595 void uncompressTile(Descriptor* desc, int64_t compressedSize, size_t tileSize, char* buffer);
00596 void getOffsetAndSize(Descriptor* compressor, int index, int64_t& compressedSize, int64_t& offset);
00597 void checkCrc32(char* buffer, int tileIndex, size_t tileSize);
00598
00599 private:
00600 enum DebugBorderMode
00601 {
00602 NORMAL_BORDERS = 0,
00603 MARK_BORDERS = 1,
00604 ONLY_BORDERS = 2
00605 };
00606
00607
00608 void internalInit();
00609
00611 template<typename T> void getFakeDataNoise(void* buffer, const SbBox3i32& tilePosition);
00612
00614 void visibleBorder(unsigned char* buffer);
00615
00617 void readBorderOnly(unsigned char* buffer);
00618
00620 void readTileMinMax(TiXmlElement *s);
00621
00623 void extractUndefValue(TiXmlElement* element);
00624
00626 std::vector<SbVec2d> m_tileMinMax;
00627
00629 double m_undefValue;
00630
00632 bool m_hasUndefValue;
00633
00635 bool m_hasDefaultValue;
00636
00638 bool m_fakeDataNoise;
00639 unsigned int m_fakeDataNumOctaves;
00640 float m_fakeDataPersistence;
00641
00643 static DebugBorderMode s_debugBorders;
00644
00645 bool m_hasCompletionFile;
00646 SbBool m_hasAlternateFile;
00647
00648
00649 bool m_bIsBitSetDataSet;
00650
00652 bool m_forcePow2TileDim;
00653
00655 SoLDMResourceParameters::TileCachePolicy m_tileCachePolicy;
00656
00657
00658
00659 void resetInternalPath();
00660 };
00661
00662
00663 inline SbBool
00664 SoLDMReader::getBbox(int , SbBox3f& )
00665 {
00666 return FALSE;
00667 }
00668
00669 inline SbBool
00670 SoLDMReader::getCenter(int , SbVec3f& )
00671 {
00672 return FALSE;
00673 }
00674
00675 inline void
00676 SoLDMReader::getSubSlice( const SbBox2i32& , int , void *)
00677 {
00678 }
00679
00680 #if 1
00681 inline SbBool
00682 SoLDMReader::getMinMax(int & , int & )
00683 {
00684 return FALSE;
00685 }
00686 #endif
00688 inline SbBool
00689 SoLDMReader::getMinMax(int64_t & , int64_t & )
00690 {
00691 return FALSE;
00692 }
00693
00694 inline
00695 SbBool SoLDMReader::getMinMax(double & , double & )
00696 {
00697 return FALSE;
00698 }
00699
00700 inline SbBool
00701 SoLDMReader::getHistogram(std::vector<int64_t>& )
00702 {
00703 return FALSE;
00704 }
00705
00706 inline SbBool
00707 SoLDMReader::hasHistogram()
00708 {
00709 return FALSE;
00710 }
00711
00712 inline void
00713 SoLDMReader::setHeaderDirty( bool headerDirty )
00714 {
00715 m_headerDirty = headerDirty;
00716 }
00717
00718 inline uint64_t
00719 SoLDMReader::getTileSizeFromFid(int)
00720 {
00721 return 0;
00722 }
00723
00724 inline void
00725 SoLDMReader::setTileDimPow2Forced( bool flag )
00726 {
00727 m_forcePow2TileDim = flag;
00728 }
00729
00730 #ifdef _MSC_VER
00731 #pragma warning( pop )
00732 #endif
00733
00734 #endif
00735
00736
00737