MeVisLabToolboxReference
MeVis/Foundation/Sources/MLDataCompressors/MLDataCompressor/mlDataCompressor.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00005 
00010 // Abstract base class for ML data compression algorithms.
00011 //----------------------------------------------------------------------------------
00012 
00013 #ifndef __mlDataCompressor_H
00014 #define __mlDataCompressor_H
00015 
00016 // Resolve platform independencies.
00017 #ifndef __MLDataCompressorSystem_H
00018 #include "MLDataCompressorSystem.h"
00019 #endif
00020 
00021 #ifndef __mlSystemIncludes_H
00022 #include "mlSystemIncludes.h"
00023 #endif
00024 #ifndef __mlUtils_H
00025 #include "mlUtils.h"
00026 #endif
00027 #ifndef __mlBase_H
00028 #include "mlBase.h"
00029 #endif
00030 
00031 
00032 ML_UTILS_START_NAMESPACE
00033 
00035   class CompressionRegisterEntry;
00036 
00037   // -------------------------------------------------------------------
00040   // -------------------------------------------------------------------
00041   class MLDATA_COMPRESSOR_EXPORT DataCompressor : public Base 
00042   {
00043   public:
00044 
00045     //--------------------------------------------------------------------------------
00047 
00048     //--------------------------------------------------------------------------------
00049 
00052     enum { MaxHints = 10 };
00053 
00055     enum HintType {
00056       Unused     = 0,  
00057       IsDouble   = 1,  
00058       IsInt      = 2,  
00059       IsBool     = 3,  
00060       IsString   = 4,  
00061       IsDataType = 5   
00062     };
00064 
00065 
00066     //--------------------------------------------------------------------------------
00068 
00069     //--------------------------------------------------------------------------------
00070 
00072     DataCompressor();
00073 
00075     virtual ~DataCompressor();
00077 
00078 
00079     //--------------------------------------------------------------------------------
00081 
00082     //--------------------------------------------------------------------------------
00083 
00087     virtual std::string           getTypeName()     const = 0;
00088 
00092     virtual std::string           getVersion()      const = 0;
00093 
00096     virtual bool                  isSupportedVersion(const std::string &ver) const = 0;
00097 
00101     virtual std::string           getVendor()       const { return "";           }
00102 
00105     virtual std::string           getSuffix()       const { return "";           }
00106 
00112     virtual bool                  isLossy()         const { return false;        }
00114 
00115 
00116     //--------------------------------------------------------------------------------
00118 
00119     //--------------------------------------------------------------------------------
00120 
00122     virtual MLDataType            getDataType()        const  { return _dataType; }
00123 
00125     virtual void                  setDataType(MLDataType dt)  { _dataType = dt;   }
00126 
00127 
00129     virtual size_t                getVoxelSize()        const { return _voxelSize; }
00130 
00132     virtual void                  setVoxelSize(size_t vSize)  { _voxelSize = vSize;}
00133 
00134 
00136     virtual void                  getImageExtent(MLint ext[6]) const { memcpy(ext, _ext, sizeof(MLint)*6); }
00137 
00139     virtual void                  setImageExtent(const MLint ext[6]) { memcpy(_ext, ext, sizeof(MLint)*6); }
00140 
00141 
00143     virtual MLuint8               numUsedHints()       const  { return 0;          }
00144 
00146     virtual void                  getHint(MLuint8     hintIdx  , 
00147                                           HintType    &hintType,
00148                                           std::string &strVal  ,
00149                                           std::string &hintName,
00150                                           double      &rangeMin,        
00151                                           double      &rangeMax)   const;
00152 
00155     virtual MLErrorCode           setHint(MLuint8           hintIdx, 
00156                                           const std::string value);
00157 
00160     virtual MLErrorCode           setHint(const std::string &hintName, 
00161                                           const std::string &value);
00162 
00164     virtual int                   findHint(const std::string &hintName);
00166 
00167 
00168 
00169     //--------------------------------------------------------------------------------
00171 
00172     //--------------------------------------------------------------------------------
00173 
00187     virtual ML_RETURN_VALUE_SHOULD_BE_USED
00188             MLErrorCode           compress(const  void *srcMem, 
00189                                            size_t       srcSize,
00190                                            void       *&dstMem,
00191                                            MLint       &dstNum) const = 0;
00192 
00207     virtual ML_RETURN_VALUE_SHOULD_BE_USED
00208             MLErrorCode           decompress(const  void *srcMem, 
00209                                              size_t       srcSize,
00210                                              void       *&dstMem,
00211                                              MLint64     &resSize) const = 0;
00212 
00213 
00214   protected:
00215 
00217     MLDataType  _dataType;
00218 
00220     size_t      _voxelSize;
00221 
00223     MLint       _ext[6];
00224 
00226 
00227 
00229     HintType    _hintType[MaxHints];
00230 
00232     std::string _strHints[MaxHints];
00233 
00235     std::string _hintName[MaxHints];
00236 
00238     double      _rangeMin[MaxHints];
00239 
00241     double      _rangeMax[MaxHints];
00243 
00244 
00245     //-----------------------------------------------------------
00247 
00248     //-----------------------------------------------------------
00260     static  int  reorderBytePlanes(void *data, size_t dataSize, size_t voxSize);
00261 
00264     static  int  unReorderBytePlanes(void *data, size_t dataSize, size_t voxSize);
00265     
00281     static  void diffCodeData  (void *data, size_t dataSize, size_t voxSize=1);
00282     
00284     static  void undiffCodeData(void *data, size_t dataSize, size_t voxSize=1);
00285 
00298     static int reorderDataTraversal(void *data, size_t dataSize, size_t voxSize, const MLint64 imgExt[6]);
00299 
00302     static int unReorderDataTraversal(void *data, size_t dataSize, size_t voxSize, const MLint64 imgExt[6]);
00303 
00308     static void packMLints(const MLint vec[6], unsigned char packedBuffer[55]);
00309 
00311     static void unpackMLints(const unsigned char packedBuffer[55], MLint vec[6]);
00312 
00314 
00315   private:
00316 
00320     static std::vector<CompressionRegisterEntry>::iterator findCompressorType(const std::string &typeName);
00321 
00325     static std::vector<CompressionRegisterEntry>::iterator findCompressorType(const RuntimeType &rtType);
00326 
00328     static std::vector<CompressionRegisterEntry> _dataCompressorTypes;
00329 
00331     ML_ABSTRACT_CLASS_HEADER(DataCompressor)
00332   };
00333 
00334 ML_UTILS_END_NAMESPACE
00335 
00336 #endif // __mlDataCompressor_H
00337 
00338