Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoConverter.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (Apr 2003)
22**=======================================================================*/
23
24#ifndef _SO_BASE_CONVERTER_
25#define _SO_BASE_CONVERTER_
26
27#ifdef _MSC_VER
28#pragma warning( push )
29#pragma warning(disable:4251)
30#endif
31
32
33#include <LDM/nodes/SoDataSet.h>
34#include <Inventor/STL/vector>
35#include <Inventor/SbBox.h>
36#include <Inventor/SbPList.h>
37
38#include <Inventor/threads/SbThreadMutex.h>
39
40#include <LDM/readers/SoLDMReader.h>
41#include <LDM/compressors/SoDataCompressor.h>
42
43class SoLDMTopoOctree;
44class ScJob;
46class SiBitFile;
47class SoDataCompressInfo;
50
308
309public:
310
314 virtual ~SoConverter();
315
347
356 int convert( SoConverterParameters* parameters = NULL);
357
363 void setXmlCallback( void (*xmlCB)( FILE*, void * userData ), void * userData );
364
365#if 1 SoDEPRECATED
371 int convert( int argc, char ** argv);
372SoDEPRECATED
374 int convert( const SbStringList& arguments );
375
376#endif
378private:
379
380 enum MessageType{
381 INIT = 1,
382 BUILD_SLAB,
383 BUILD_LEVEL,
384 CLEAR
385 };
386
387 char* m_slabBuffer;
388 SbVec3i32 m_slabBufferDim;
389 int64_t m_subSliceSize;
390
391 //statistics
392 SoVolumeHistogram* m_stat;
393 double m_min, m_max;
394 std::vector<int64_t> m_numValues;
395 std::vector<double> m_values;
396
397 int m_numTilesGenerated;
398 float m_progress;
399
400 struct Stat{
401 double value;
402 int64_t numValues;
403 };
404
405 void checkProgress();
406
407
408 //data information
409 int m_dataSize;
410
411 //routines
412 ConverterError init();
413
414 char* allocateSlabBuffer(int& _numTilesOnYAxis, SbVec3i32& _slabBufferDim, int64_t& _subSliceSize);
415 int buildSlab2Level(SbBox3i32& slabBox, char*& slabBufferPtr, void* parentTile, void** octantTile,SbVec3i32& slabBufferDim, int64_t subSliceSize, std::vector<int>& fileIDsBuilt);
416 void buildLevel(std::vector<int>&, int, int fromFileID = -1, int toFileID = -1);
417 int initializeFiles( int argc, char ** argv );
418 int initializeFiles( SoConverterParameters* parameters );
419
420 int writeSubVolume( const SbBox3i32 & subVolume, const void * data, SbBool doLowerResolution = TRUE, SbBool doOverlappingTiles = TRUE );
421 int writeTile( const SoLDMTileID & tileID, void * data );
422
423 int writeSubVolume( const SbBox3i32 & subVolume, SoBufferObject* data, SbBool doLowerResolution = TRUE, SbBool doOverlappingTiles = TRUE );
424 int writeTile( const SoLDMTileID & tileID, SoBufferObject* data );
425
426 const SoLDMTopoOctree* getTopo() { return m_LDMTopo; };
427 int finalizeFiles( int retCode = 0 );
428 int buildLevels( int fromLevel, int numLevels );
429
430 void * m_fout;
431 SoConverterParameters* getParameters();
432 void updateFileCompletion(std::vector<int>& fileIDs);
433
434 std::vector<SoDataSet::DatumElement> m_datum;
435 bool m_isDataFloat;
436 bool m_isDataSigned;
437 size_t m_tileSize;
438 int m_numSigBits;
439
440private: protected:
442
445
447 virtual void getSubSlice( const SbBox2i32& subSlice, int sliceNumber, void * data ) = 0;
448
449 //error returned : 0 = ok, 1 = pb = return
450 virtual SbBox3f getSize(int& error) = 0;
451 virtual std::vector<SoDataSet::DatumElement> getDatum(int& error) = 0;
452 virtual SbVec3i32 getDimension(int& error) = 0;
453 virtual int getRange( double & rangeMin, double & rangeMax) = 0;
455 virtual std::vector<SbVec2d>& getTileMinMax(int numTiles);
456 virtual void closeInputFileHandles();
457
471 virtual void sampleTile ( const SbVec3i32& tileDim, int border, const void* const octantTile[8], const int octantExists[8], void* parentTile ) = 0;
472 virtual void buildTile ( SbBox3i32& slabBox, SbVec3i32& slabBufferDim, void* slabBuffer, SbVec3i32& tileOrigin, void* tileBuffer );
473 void buildTile ( const SbBox3i32& subVolume, const void* subVolumeBuffer, const SbBox3i32& tilePos, void* tileData, const SbBox3i32& intersection );
474 virtual void outputHeader( FILE* ) {};
475
476#if 1 SoDEPRECATED
479 virtual void outputTileBefore(int SO_UNUSED_PARAM(fileTileIndex), int SO_UNUSED_PARAM(dataSize),
480 void* SO_UNUSED_PARAM(data), bool SO_UNUSED_PARAM(dataInverted))
481 {}
482
483#endif
485 virtual void outputTileBefore(int SO_UNUSED_PARAM(fileTileIndex), size_t SO_UNUSED_PARAM(dataSize),
486 void* SO_UNUSED_PARAM(data), bool SO_UNUSED_PARAM(dataInverted))
487 {}
488
489 virtual void startConversion(){};
490 virtual void endConversion(){};
491
492 virtual bool updateDataFile() { return true; }
493 virtual int getSpecificOffset(bool aligned = true ) { return !aligned; } // dummy return to avoid compilation warning
494 virtual SbString getOriginalFilename() const;
495 virtual void setOriginalFileName(const SbString& originalFileName);
496
497
499
507
522
530 virtual Abort progress( int numTilesGenerated, int numTilesToGenerate );
531
532 ConverterError buildHeader( const SbString&, bool conversionDone = false);
533
534 virtual void outputDataType(FILE* fout);
535
537
538 void inputTile( int fileTileIndex, size_t dataSize, void *data, bool i = false );
539 void printTime();
541 void outputTile( int fileTileIndex, size_t dataSize, void*, bool i = false );
542
544
545 void (*m_xmlCB)( FILE*, void* );
548
549 //files info
550 int64_t m_filesize;//final data file size
551 int64_t m_compressedFilesize;//final compressed file size
552 SbString m_fileCompletion; //file completion
555
556 //data info
557 int m_pid;
561
562
563 // progress
567 SiBitFile* m_bitFile;
568
569 //Compression
573 SoDataCompressInfo* m_lastWrittenCompressInfo;
574
575
577
578 //file completion
579 void writeTileComplete(int fileID, bool writeHeader = false);
580
581 //abort function
583
584 void readSlab(SbBox3i32& slabBox, char*& slabBufferPtr,int64_t subSliceSize);
585
586 // Define the algorithm used for downsampling
588
589
590 // type dependent vars/macros
591 static const char *m_dataTypeStr[];
592 static const char *m_dataTypeXml[];
594
595 // Performance counter manager
599
600 virtual void adjustParameters() {};
601 virtual void handleCustomTags(FILE*) {};
602
604 std::vector<SbVec2d> m_tileMinMax;
605
611
613
614private:
615 bool m_userDefinedParameters;
616 int64_t getCrc32(void* data, size_t dataSize, const SoDataCompressor::TileInfo& ti);
617 void usage();
618 template <typename T> void fillTile(void* ptrDst, int size, void* value );
619
620 template <typename T> void fillTileWithSingleValue(void* ptrDst, int size, T value );
621
623 SoConverter::ConverterError outputMinMaxInfos(FILE* fout);
624
626 void computeLowResMinMax(const SoLDMTileID& tileId);
627
628 bool m_bComplFileAlreadyExists;
629
631 void buildTileFast(int fileID, void* tileData, const SbVec3i32& tileOrigin);
632
633 static SbThreadMutex s_classMutex;
634
636 static bool s_doFastUpdate;
637};
638
640SoConverter::getParameters()
641{
642 return m_parameters;
643}
644
645inline SbString
650
651inline void
653{
654 m_originalFileName = originalFilename;
655}
656
657#ifdef _MSC_VER
658#pragma warning( pop )
659#endif
660
661#endif //_SO_BASE_CONVERTER_
662
663
2D box class.
Definition SbBox.h:2383
3D box class.
Definition SbBox.h:649
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 3D box class.
Definition SbBox.h:96
Class for smart character strings.
Definition SbString.h:202
Maintains a list of pointers to SbString instances.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
3D vector class.
Definition SbVec.h:1517
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Abstract...
SbBox3f m_volumeSize
void setXmlCallback(void(*xmlCB)(FILE *, void *userData), void *userData)
Specifies the callback that will be called when the LDM file header is generated.
SoConverterParameters * m_parameters
void printCompressionInfos()
void writeTileComplete(int fileID, bool writeHeader=false)
static const char * m_dataTypeStr[]
virtual void adjustParameters()
SoDEPRECATED int convert(int argc, char **argv)
void outputTile(int fileTileIndex, size_t dataSize, void *, bool i=false)
virtual void endConversion()
int getNumTileToGenerate(SbBox3i32 &slabBox)
void readSlab(SbBox3i32 &slabBox, char *&slabBufferPtr, int64_t subSliceSize)
int64_t m_compressedFilesize
void * m_xmlCBUserData
virtual ~SoConverter()
Destructor.
virtual void handleCustomTags(FILE *)
SoDataCompressor * m_ldmCompressor
int64_t m_sizeOfTileIndex
SoConverter::ConverterError m_statusAdjustParameters
SampleType m_sampleType
virtual std::vector< SbVec2d > & getTileMinMax(int numTiles)
virtual SbBox3f getSize(int &error)=0
SbString m_fileCompletionName
virtual SoDEPRECATED void outputTileBefore(int fileTileIndex, int dataSize, void *data, bool dataInverted)
void abortConversion()
int buildLevelMax()
std::vector< SbVec2d > m_tileMinMax
One minMax for each file ids.
char m_compressionType[256]
virtual void outputTileBefore(int fileTileIndex, size_t dataSize, void *data, bool dataInverted)
void(* m_xmlCB)(FILE *, void *)
virtual void setOriginalFileName(const SbString &originalFileName)
void inputTile(int fileTileIndex, size_t dataSize, void *data, bool i=false)
virtual Abort progress(int numTilesGenerated, int numTilesToGenerate)
This method is called each time a tile of data is generated.
virtual SoVolumeHistogram * getHistogram()
virtual void closeInputFileHandles()
virtual void outputDataType(FILE *fout)
virtual SbString getOriginalFilename() const
virtual int getRange(double &rangeMin, double &rangeMax)=0
virtual void buildTile(SbBox3i32 &slabBox, SbVec3i32 &slabBufferDim, void *slabBuffer, SbVec3i32 &tileOrigin, void *tileBuffer)
SoConverter()
Constructor.
SoDataCompressInfo * m_lastWrittenCompressInfo
SbString m_fileCompletion
int64_t m_filesize
virtual void startConversion()
SbString m_originalFileName
bool isFastUpdate()
Return TRUE if converter can do a fast update of the LDM file (ie: converting a ldm file with borders...
virtual std::vector< SoDataSet::DatumElement > getDatum(int &error)=0
SoLDMTopoOctree * m_LDMTopo
SampleType
Define available algorithm available for downsampling process.
@ AVERAGE
Average : Voxel value in parent tile is an average of Neighbor voxel in child tile.
@ DECIMATION
Decimation : Only one voxel out of two.
int m_numTilesToGenerate
virtual bool updateDataFile()
virtual void getSubSlice(const SbBox2i32 &subSlice, int sliceNumber, void *data)=0
virtual void outputHeader(FILE *)
SoPerfCounterManager * m_perfManager
void printTime()
int m_currentWordFormat
SoVolumeReader * m_reader
ConverterError
Converter errors.
@ CVT_CANT_CREATE_HEADER_FILE
Unable to create header file.
@ CVT_NO_LDM_LICENSE
No LDM license.
@ CVT_ABORTED
Conversion aborted.
@ CVT_NO_NODE
No node.
@ CVT_INPUT_PARAMS_PROBLEM
Input params problems.
@ CVT_NOT_INITIALIZED
Uninitialized converter.
@ CVT_CANT_READ_INPUT_FILE
Unable to read input file.
@ CVT_FINISHED_WITH_WARNINGS
Finished with warnings.
@ CVT_CANT_CREATE_DATA_FILE
Unable to create data file.
@ CVT_CANT_OPEN_INPUT_FILE
Unable to open file.
@ CVT_FILE_EXT_UNKNOWN
Unknown file extension.
@ CVT_NO_ERROR
No error.
@ CVT_NOT_ENOUGH_DISK_SPACE
No enough disk space.
int convert(SoConverterParameters *parameters=NULL)
Main converter function.
bool m_fromInitializeFiles
virtual int getSpecificOffset(bool aligned=true)
ConverterError buildHeader(const SbString &, bool conversionDone=false)
virtual SbVec3i32 getDimension(int &error)=0
SoDEPRECATED int convert(const SbStringList &arguments)
SbString m_fileExt
virtual void sampleTile(const SbVec3i32 &tileDim, int border, const void *const octantTile[8], const int octantExists[8], void *parentTile)=0
Method used to downsample a tile.
bool m_thinDataSet
SiBitFile * m_bitFile
void buildTile(const SbBox3i32 &subVolume, const void *subVolumeBuffer, const SbBox3i32 &tilePos, void *tileData, const SbBox3i32 &intersection)
SbVec3i32 m_volumeDimension
static const char * m_dataTypeXml[]
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Containe...
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Data com...
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Tile ID
Definition SoLDMTileID.h:63
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Octree t...
Performance Counter Manager.
Volume Data Histogram.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Abstract...
int SbBool
Boolean type.
Definition SbBase.h:87
This structure contains the dimension and the type of the tile being processed.