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 SoDEPRECATED
00392 void listenToServer(int argc, char** argv);
00393
00394 #endif
00396 private:
00397
00398 enum MessageType{
00399 INIT = 1,
00400 BUILD_SLAB,
00401 BUILD_LEVEL,
00402 CLEAR
00403 };
00404
00405 char* m_slabBuffer;
00406 SbVec3i32 m_slabBufferDim;
00407 int64_t m_subSliceSize;
00408
00409
00410 SoVolumeHistogram* m_stat;
00411 double m_min, m_max;
00412 std::vector<int64_t> m_numValues;
00413 std::vector<double> m_values;
00414
00415 int m_numTilesGenerated;
00416 float m_progress;
00417
00418 struct Stat{
00419 double value;
00420 int64_t numValues;
00421 };
00422
00423 void checkProgress();
00424
00425
00426
00427 int m_dataSize;
00428
00429
00430 ConverterError init();
00431
00432 char* allocateSlabBuffer(int& _numTilesOnYAxis, SbVec3i32& _slabBufferDim, int64_t& _subSliceSize);
00433 int buildSlab2Level(SbBox3i32& slabBox, char*& slabBufferPtr, void* parentTile, void** octantTile,SbVec3i32& slabBufferDim, int64_t subSliceSize, std::vector<int>& fileIDsBuilt);
00434 void buildLevel(std::vector<int>&, int, int fromFileID = -1, int toFileID = -1);
00435 int initializeFiles( int argc, char ** argv );
00436 int initializeFiles( SoConverterParameters* parameters );
00437
00438 int writeSubVolume( const SbBox3i32 & subVolume, const void * data, SbBool doLowerResolution = TRUE, SbBool doOverlappingTiles = TRUE );
00439 int writeTile( const SoLDMTileID & tileID, void * data );
00440
00441 int writeSubVolume( const SbBox3i32 & subVolume, SoBufferObject* data, SbBool doLowerResolution = TRUE, SbBool doOverlappingTiles = TRUE );
00442 int writeTile( const SoLDMTileID & tileID, SoBufferObject* data );
00443
00444 const SoLDMTopoOctree* getTopo() { return m_LDMTopo; };
00445 int finalizeFiles( int retCode = 0 );
00446 int buildLevels( int fromLevel, int numLevels );
00447
00448 void * m_fout;
00449 SoConverterParameters* getParameters();
00450 void updateFileCompletion(std::vector<int>& fileIDs);
00451
00452 std::vector<SoDataSet::DatumElement> m_datum;
00453 bool m_isDataFloat;
00454 bool m_isDataSigned;
00455 size_t m_tileSize;
00456 int m_numSigBits;
00457
00458 private: protected:
00459 SoVolumeReader* m_reader;
00460
00464 SoConverter(SbBool isClient = FALSE);
00465
00467 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, void * data ) = 0;
00468
00469
00470 virtual SbBox3f getSize(int& error) = 0;
00471 virtual std::vector<SoDataSet::DatumElement> getDatum(int& error) = 0;
00472 virtual SbVec3i32 getDimension(int& error) = 0;
00473 virtual int getRange( double & rangeMin, double & rangeMax) = 0;
00474 virtual SoVolumeHistogram* getHistogram();
00475 virtual std::vector<SbVec2d>& getTileMinMax(int numTiles);
00476 virtual void closeInputFileHandles();
00477
00491 virtual void sampleTile ( const SbVec3i32& tileDim, int border, const void* const octantTile[8], const int octantExists[8], void* parentTile ) = 0;
00492 virtual void buildTile ( SbBox3i32& slabBox, SbVec3i32& slabBufferDim, void* slabBuffer, SbVec3i32& tileOrigin, void* tileBuffer );
00493 void buildTile ( const SbBox3i32& subVolume, const void* subVolumeBuffer, const SbBox3i32& tilePos, void* tileData, const SbBox3i32& intersection );
00494 virtual void outputHeader( FILE* ) {};
00495 virtual void outputTileBefore( int fileTileIndex, int dataSize, void *data, bool dataInverted );
00496 virtual void startConversion(){};
00497 virtual void endConversion(){};
00498
00499 virtual bool updateDataFile() { return true; }
00500 virtual int getSpecificOffset(bool aligned = true ) { return !aligned; }
00501 virtual SbString getOriginalFilename() const;
00502 virtual void setOriginalFileName(const SbString& originalFileName);
00503
00504
00506
00508 enum Abort {
00510 CVT_CONTINUE,
00512 CVT_ABORT
00513 };
00514
00518 enum SampleType
00519 {
00523 DECIMATION,
00527 AVERAGE
00528 };
00529
00537 virtual Abort progress( int numTilesGenerated, int numTilesToGenerate );
00538
00539 ConverterError buildHeader( const SbString&, bool conversionDone = false);
00540
00541 virtual void outputDataType(FILE* fout);
00542
00543 SbBox3f m_volumeSize;
00544
00545 void inputTile( int fileTileIndex, int dataSize, void *data, bool i = false );
00546 void printTime();
00547 int buildLevelMax();
00548 void outputTile( int fileTileIndex, int dataSize, void*, bool i = false );
00549
00550 void printCompressionInfos();
00551
00552 void (*m_xmlCB)( FILE*, void* );
00553 void *m_xmlCBUserData;
00554 SoLDMTopoOctree *m_LDMTopo;
00555
00556
00557 int64_t m_filesize;
00558 int64_t m_compressedFilesize;
00559 SbString m_fileCompletion;
00560 SbString m_fileCompletionName;
00561 SbString m_fileExt;
00562
00563
00564 int m_pid;
00565 int m_levelMax;
00566 bool m_thinDataSet;
00567 SbVec3i32 m_volumeDimension;
00568
00569
00570
00571 int m_numTilesToGenerate;
00572 bool m_abort;
00573 int getNumTileToGenerate(SbBox3i32& slabBox);
00574 SiBitFile* m_bitFile;
00575
00576
00577 SoDataCompressor *m_ldmCompressor;
00578 int64_t m_sizeOfTileIndex;
00579 char m_compressionType[256];
00580 SoDataCompressInfo* m_lastWrittenCompressInfo;
00581
00582
00583 bool m_fromInitializeFiles;
00584
00585
00586 void writeTileComplete(int fileID, bool writeHeader = false);
00587
00588
00589 void abortConversion();
00590
00591 void readSlab(SbBox3i32& slabBox, char*& slabBufferPtr,int64_t subSliceSize);
00592
00593
00594 SampleType m_sampleType;
00595
00596
00597
00598 static const char *m_dataTypeStr[];
00599 static const char *m_dataTypeXml[];
00600 int m_currentWordFormat;
00601
00602
00603 SoPerfCounterManager *m_perfManager;
00604 SoConverterParameters* m_parameters;
00605 SbString m_originalFileName;
00606
00607 virtual void adjustParameters() {};
00608 virtual void handleCustomTags(FILE*) {};
00609
00611 std::vector<SbVec2d> m_tileMinMax;
00612
00617 bool isFastUpdate();
00618
00619 SoConverter::ConverterError m_statusAdjustParameters;
00620
00621 private:
00622 bool m_userDefinedParameters;
00623 int64_t getCrc32(void* data, int dataSize, const SoDataCompressor::TileInfo& ti);
00624 void usage();
00625 template <typename T> void fillTile(void* ptrDst, int size, void* value );
00626
00627 template <typename T> void fillTileWithSingleValue(void* ptrDst, int size, T value );
00628
00630 SoConverter::ConverterError outputMinMaxInfos(FILE* fout);
00631
00633 void computeLowResMinMax(const SoLDMTileID& tileId);
00634
00635 bool m_bComplFileAlreadyExists;
00636
00638 void buildTileFast(int fileID, void* tileData, const SbVec3i32& tileOrigin);
00639
00640 static SbThreadMutex s_classMutex;
00641
00643 static bool s_doFastUpdate;
00644 };
00645
00646 inline void
00647 SoConverter::outputTileBefore( int , int , void *, bool )
00648 {
00649 }
00650
00651 inline SoConverterParameters*
00652 SoConverter::getParameters()
00653 {
00654 return m_parameters;
00655 }
00656
00657 inline SbString
00658 SoConverter::getOriginalFilename() const
00659 {
00660 return m_originalFileName;
00661 }
00662
00663 inline void
00664 SoConverter::setOriginalFileName(const SbString& originalFilename)
00665 {
00666 m_originalFileName = originalFilename;
00667 }
00668
00669 #ifdef _MSC_VER
00670 #pragma warning( pop )
00671 #endif
00672
00673 #endif //_SO_BASE_CONVERTER_
00674
00675
00676