00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _SO_BASE_CONVERTER_
00025 #define _SO_BASE_CONVERTER_
00026
00027 #ifdef _MSC_VER
00028 #pragma warning( push )
00029 #pragma warning(disable:4251)
00030 #endif
00031
00032
00033 #include <LDM/nodes/SoDataSet.h>
00034 #include <Inventor/STL/vector>
00035 #include <Inventor/SbBox.h>
00036 #include <Inventor/SbPList.h>
00037
00038 #include <Inventor/threads/SbThreadMutex.h>
00039
00040 #include <LDM/readers/SoLDMReader.h>
00041 #include <LDM/compressors/SoDataCompressor.h>
00042
00043 class SoLDMTopoOctree;
00044 class ScJob;
00045 class SoVolumeHistogram;
00046 class SiBitFile;
00047 class SoDataCompressInfo;
00048 class SoPerfCounterManager;
00049 class SoConverterParameters;
00050
00317 class SoConverter {
00318
00319 public:
00320
00324 virtual ~SoConverter();
00325
00329 enum ConverterError{
00331 CVT_FINISHED_WITH_WARNINGS = 1,
00333 CVT_NO_ERROR = 0,
00335 CVT_INPUT_PARAMS_PROBLEM = -1,
00337 CVT_FILE_EXT_UNKNOWN = -2,
00339 CVT_CANT_OPEN_INPUT_FILE = -3,
00341 CVT_CANT_CREATE_DATA_FILE = -4,
00343 CVT_CANT_CREATE_HEADER_FILE = -5,
00345 CVT_NOT_ENOUGH_DISK_SPACE = -6,
00347 CVT_CANT_READ_INPUT_FILE = -7,
00349 CVT_ABORTED = -9,
00351 CVT_NOT_INITIALIZED = -10,
00353 CVT_NO_NODE = -998,
00355 CVT_NO_LDM_LICENSE = -999
00356 };
00357
00366 int convert( SoConverterParameters* parameters = NULL);
00367
00373 void setXmlCallback( void (*xmlCB)( FILE*, void * userData ), void * userData );
00374
00375 #if 1 SoDEPRECATED
00381 int convert( int argc, char ** argv);
00382 SoDEPRECATED
00384 int convert( const SbStringList& arguments );
00385
00386 #endif
00388 private:
00389
00390 enum MessageType{
00391 INIT = 1,
00392 BUILD_SLAB,
00393 BUILD_LEVEL,
00394 CLEAR
00395 };
00396
00397 char* m_slabBuffer;
00398 SbVec3i32 m_slabBufferDim;
00399 int64_t m_subSliceSize;
00400
00401
00402 SoVolumeHistogram* m_stat;
00403 double m_min, m_max;
00404 std::vector<int64_t> m_numValues;
00405 std::vector<double> m_values;
00406
00407 int m_numTilesGenerated;
00408 float m_progress;
00409
00410 struct Stat{
00411 double value;
00412 int64_t numValues;
00413 };
00414
00415 void checkProgress();
00416
00417
00418
00419 int m_dataSize;
00420
00421
00422 ConverterError init();
00423
00424 char* allocateSlabBuffer(int& _numTilesOnYAxis, SbVec3i32& _slabBufferDim, int64_t& _subSliceSize);
00425 int buildSlab2Level(SbBox3i32& slabBox, char*& slabBufferPtr, void* parentTile, void** octantTile,SbVec3i32& slabBufferDim, int64_t subSliceSize, std::vector<int>& fileIDsBuilt);
00426 void buildLevel(std::vector<int>&, int, int fromFileID = -1, int toFileID = -1);
00427 int initializeFiles( int argc, char ** argv );
00428 int initializeFiles( SoConverterParameters* parameters );
00429
00430 int writeSubVolume( const SbBox3i32 & subVolume, const void * data, SbBool doLowerResolution = TRUE, SbBool doOverlappingTiles = TRUE );
00431 int writeTile( const SoLDMTileID & tileID, void * data );
00432
00433 int writeSubVolume( const SbBox3i32 & subVolume, SoBufferObject* data, SbBool doLowerResolution = TRUE, SbBool doOverlappingTiles = TRUE );
00434 int writeTile( const SoLDMTileID & tileID, SoBufferObject* data );
00435
00436 const SoLDMTopoOctree* getTopo() { return m_LDMTopo; };
00437 int finalizeFiles( int retCode = 0 );
00438 int buildLevels( int fromLevel, int numLevels );
00439
00440 void * m_fout;
00441 SoConverterParameters* getParameters();
00442 void updateFileCompletion(std::vector<int>& fileIDs);
00443
00444 std::vector<SoDataSet::DatumElement> m_datum;
00445 bool m_isDataFloat;
00446 bool m_isDataSigned;
00447 size_t m_tileSize;
00448 int m_numSigBits;
00449
00450 private: protected:
00451 SoVolumeReader* m_reader;
00452
00454 SoConverter();
00455
00457 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, void * data ) = 0;
00458
00459
00460 virtual SbBox3f getSize(int& error) = 0;
00461 virtual std::vector<SoDataSet::DatumElement> getDatum(int& error) = 0;
00462 virtual SbVec3i32 getDimension(int& error) = 0;
00463 virtual int getRange( double & rangeMin, double & rangeMax) = 0;
00464 virtual SoVolumeHistogram* getHistogram();
00465 virtual std::vector<SbVec2d>& getTileMinMax(int numTiles);
00466 virtual void closeInputFileHandles();
00467
00481 virtual void sampleTile ( const SbVec3i32& tileDim, int border, const void* const octantTile[8], const int octantExists[8], void* parentTile ) = 0;
00482 virtual void buildTile ( SbBox3i32& slabBox, SbVec3i32& slabBufferDim, void* slabBuffer, SbVec3i32& tileOrigin, void* tileBuffer );
00483 void buildTile ( const SbBox3i32& subVolume, const void* subVolumeBuffer, const SbBox3i32& tilePos, void* tileData, const SbBox3i32& intersection );
00484 virtual void outputHeader( FILE* ) {};
00485 virtual void outputTileBefore( int fileTileIndex, int dataSize, void *data, bool dataInverted );
00486 virtual void startConversion(){};
00487 virtual void endConversion(){};
00488
00489 virtual bool updateDataFile() { return true; }
00490 virtual int getSpecificOffset(bool aligned = true ) { return !aligned; }
00491 virtual SbString getOriginalFilename() const;
00492 virtual void setOriginalFileName(const SbString& originalFileName);
00493
00494
00496
00498 enum Abort {
00500 CVT_CONTINUE,
00502 CVT_ABORT
00503 };
00504
00508 enum SampleType
00509 {
00513 DECIMATION,
00517 AVERAGE
00518 };
00519
00527 virtual Abort progress( int numTilesGenerated, int numTilesToGenerate );
00528
00529 ConverterError buildHeader( const SbString&, bool conversionDone = false);
00530
00531 virtual void outputDataType(FILE* fout);
00532
00533 SbBox3f m_volumeSize;
00534
00535 void inputTile( int fileTileIndex, int dataSize, void *data, bool i = false );
00536 void printTime();
00537 int buildLevelMax();
00538 void outputTile( int fileTileIndex, int dataSize, void*, bool i = false );
00539
00540 void printCompressionInfos();
00541
00542 void (*m_xmlCB)( FILE*, void* );
00543 void *m_xmlCBUserData;
00544 SoLDMTopoOctree *m_LDMTopo;
00545
00546
00547 int64_t m_filesize;
00548 int64_t m_compressedFilesize;
00549 SbString m_fileCompletion;
00550 SbString m_fileCompletionName;
00551 SbString m_fileExt;
00552
00553
00554 int m_pid;
00555 int m_levelMax;
00556 bool m_thinDataSet;
00557 SbVec3i32 m_volumeDimension;
00558
00559
00560
00561 int m_numTilesToGenerate;
00562 bool m_abort;
00563 int getNumTileToGenerate(SbBox3i32& slabBox);
00564 SiBitFile* m_bitFile;
00565
00566
00567 SoDataCompressor *m_ldmCompressor;
00568 int64_t m_sizeOfTileIndex;
00569 char m_compressionType[256];
00570 SoDataCompressInfo* m_lastWrittenCompressInfo;
00571
00572
00573 bool m_fromInitializeFiles;
00574
00575
00576 void writeTileComplete(int fileID, bool writeHeader = false);
00577
00578
00579 void abortConversion();
00580
00581 void readSlab(SbBox3i32& slabBox, char*& slabBufferPtr,int64_t subSliceSize);
00582
00583
00584 SampleType m_sampleType;
00585
00586
00587
00588 static const char *m_dataTypeStr[];
00589 static const char *m_dataTypeXml[];
00590 int m_currentWordFormat;
00591
00592
00593 SoPerfCounterManager *m_perfManager;
00594 SoConverterParameters* m_parameters;
00595 SbString m_originalFileName;
00596
00597 virtual void adjustParameters() {};
00598 virtual void handleCustomTags(FILE*) {};
00599
00601 std::vector<SbVec2d> m_tileMinMax;
00602
00607 bool isFastUpdate();
00608
00609 SoConverter::ConverterError m_statusAdjustParameters;
00610
00611 private:
00612 bool m_userDefinedParameters;
00613 int64_t getCrc32(void* data, int dataSize, const SoDataCompressor::TileInfo& ti);
00614 void usage();
00615 template <typename T> void fillTile(void* ptrDst, int size, void* value );
00616
00617 template <typename T> void fillTileWithSingleValue(void* ptrDst, int size, T value );
00618
00620 SoConverter::ConverterError outputMinMaxInfos(FILE* fout);
00621
00623 void computeLowResMinMax(const SoLDMTileID& tileId);
00624
00625 bool m_bComplFileAlreadyExists;
00626
00628 void buildTileFast(int fileID, void* tileData, const SbVec3i32& tileOrigin);
00629
00630 static SbThreadMutex s_classMutex;
00631
00633 static bool s_doFastUpdate;
00634 };
00635
00636 inline void
00637 SoConverter::outputTileBefore( int , int , void *, bool )
00638 {
00639 }
00640
00641 inline SoConverterParameters*
00642 SoConverter::getParameters()
00643 {
00644 return m_parameters;
00645 }
00646
00647 inline SbString
00648 SoConverter::getOriginalFilename() const
00649 {
00650 return m_originalFileName;
00651 }
00652
00653 inline void
00654 SoConverter::setOriginalFileName(const SbString& originalFilename)
00655 {
00656 m_originalFileName = originalFilename;
00657 }
00658
00659 #ifdef _MSC_VER
00660 #pragma warning( pop )
00661 #endif
00662
00663 #endif //_SO_BASE_CONVERTER_
00664
00665
00666