MeVisLab Toolbox Reference
mlDataCompressor.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_DATA_COMPRESSOR_H
14 #define ML_DATA_COMPRESSOR_H
15 
18 
19 // Resolve platform dependencies.
20 #include "MLDataCompressorSystem.h"
21 
22 #include <mlBase.h>
23 
24 #include <cstring>
25 
26 
27 ML_UTILS_START_NAMESPACE
28 
30  class CompressionRegisterEntry;
31 
32  // -------------------------------------------------------------------
35  // -------------------------------------------------------------------
37  {
38  public:
39 
40  //--------------------------------------------------------------------------------
43  //--------------------------------------------------------------------------------
44 
47  enum { MaxHints = 10 };
48 
50  enum HintType {
51  Unused = 0,
52  IsDouble = 1,
53  IsInt = 2,
54  IsBool = 3,
55  IsString = 4,
56  IsDataType = 5
57  };
59 
60 
61  //--------------------------------------------------------------------------------
64  //--------------------------------------------------------------------------------
65 
68 
70  ~DataCompressor() override;
72 
73 
74  //--------------------------------------------------------------------------------
77  //--------------------------------------------------------------------------------
78 
82  virtual std::string getTypeName() const = 0;
83 
87  virtual std::string getVersion() const = 0;
88 
91  virtual bool isSupportedVersion(const std::string &ver) const = 0;
92 
96  virtual std::string getVendor() const { return ""; }
97 
100  virtual std::string getSuffix() const { return ""; }
101 
107  virtual bool isLossy() const { return false; }
109 
110 
111  //--------------------------------------------------------------------------------
114  //--------------------------------------------------------------------------------
115 
117  virtual MLDataType getDataType() const { return _dataType; }
118 
120  virtual void setDataType(MLDataType dt) { _dataType = dt; }
121 
122 
124  virtual size_t getVoxelSize() const { return _voxelSize; }
125 
127  virtual void setVoxelSize(size_t vSize) { _voxelSize = vSize;}
128 
129 
131  virtual void getImageExtent(MLint ext[6]) const { memcpy(ext, _ext, sizeof(MLint)*6); }
132 
134  virtual void setImageExtent(const MLint ext[6]) { memcpy(_ext, ext, sizeof(MLint)*6); }
135 
136 
138  virtual MLuint8 numUsedHints() const { return 0; }
139 
141  virtual void getHint(MLuint8 hintIdx ,
142  HintType &hintType,
143  std::string &strVal ,
144  std::string &hintName,
145  double &rangeMin,
146  double &rangeMax) const;
147 
150  virtual MLErrorCode setHint(MLuint8 hintIdx,
151  const std::string value);
152 
155  virtual MLErrorCode setHint(const std::string &hintName,
156  const std::string &value);
157 
159  virtual int findHint(const std::string &hintName);
161 
162 
163 
164  //--------------------------------------------------------------------------------
167  //--------------------------------------------------------------------------------
168 
183  [[nodiscard]]
184  virtual MLErrorCode compress(const void *srcMem,
185  size_t srcSize,
186  void *&dstMem,
187  MLint &dstNum) const = 0;
188 
204  [[nodiscard]]
205  virtual MLErrorCode decompress(const void *srcMem,
206  size_t srcSize,
207  void *&dstMem,
208  MLint64 &resSize) const = 0;
209 
210 
211  protected:
212 
215 
217  size_t _voxelSize;
218 
220  MLint _ext[6];
221 
224 
226  HintType _hintType[MaxHints];
227 
229  std::string _strHints[MaxHints];
230 
232  std::string _hintName[MaxHints];
233 
235  double _rangeMin[MaxHints];
236 
238  double _rangeMax[MaxHints];
240 
241 
242  //-----------------------------------------------------------
245  //-----------------------------------------------------------
258  static int reorderBytePlanes(void *data, size_t dataSize, size_t voxSize);
259 
263  static int unReorderBytePlanes(void *data, size_t dataSize, size_t voxSize);
264 
281  static void diffCodeData (void *data, size_t dataSize, size_t voxSize=1);
282 
285  static void undiffCodeData(void *data, size_t dataSize, size_t voxSize=1);
286 
300  static int reorderDataTraversal(void *data, size_t dataSize, size_t voxSize, const MLint64 imgExt[6]);
301 
305  static int unReorderDataTraversal(void *data, size_t dataSize, size_t voxSize, const MLint64 imgExt[6]);
306 
311  static void packMLints(const MLint vec[6], unsigned char packedBuffer[55]);
312 
314  static void unpackMLints(const unsigned char packedBuffer[55], MLint vec[6]);
315 
317 
318  private:
319 
323  static std::vector<CompressionRegisterEntry>::iterator findCompressorType(const std::string &typeName);
324 
328  static std::vector<CompressionRegisterEntry>::iterator findCompressorType(const RuntimeType &rtType);
329 
331  static std::vector<CompressionRegisterEntry> _dataCompressorTypes;
332 
335  };
336 
337 ML_UTILS_END_NAMESPACE
338 
339 #endif // __mlDataCompressor_H
340 
341 
#define MLDATA_COMPRESSOR_EXPORT
Global and OS specific declarations for the MLDataCompressor project.
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition: mlBase.h:62
Abstract base class for ML data compression algorithms.
size_t _voxelSize
Data type which can be specified by some applications, default is 1 for not known.
virtual bool isSupportedVersion(const std::string &ver) const =0
Returns true if the passed version ver is supported by the implemented compressor class and false oth...
virtual std::string getVersion() const =0
Returns the version string; the compression class itself must provide checks for compatibility with v...
virtual void setDataType(MLDataType dt)
Set the data type of the compressed data or -1 if not known (the default).
virtual MLDataType getDataType() const
Returns the data type of the compressed data or -1 if not known (the default).
static void packMLints(const MLint vec[6], unsigned char packedBuffer[55])
Packs six MLint values if possible to a smaller memory.
static int unReorderDataTraversal(void *data, size_t dataSize, size_t voxSize, const MLint64 imgExt[6])
Undoes the operation applied by reorderDataTraversal, for further information see reorderDataTraversa...
virtual MLErrorCode compress(const void *srcMem, size_t srcSize, void *&dstMem, MLint &dstNum) const =0
Compresses a chunk of memory.
virtual int findHint(const std::string &hintName)
Returns the index of the hint with name hintName or -1 if not found.
virtual bool isLossy() const
Returns true if compression is lossy, false if not; default is false.
DataCompressor()
Constructor.
virtual MLErrorCode setHint(const std::string &hintName, const std::string &value)
Set the hint value strVal of hint given by the name hintName.
~DataCompressor() override
Destructor.
virtual std::string getVendor() const
Return the name of the vendor providing the compressor code or algorithm, something of the kind "MeVi...
virtual void setImageExtent(const MLint ext[6])
Set the size of one voxel or 1 if not known (the default).
static int reorderBytePlanes(void *data, size_t dataSize, size_t voxSize)
Prepares the data for optimal compression, returns 0 on success, and a non 0 value otherwise.
virtual std::string getTypeName() const =0
Returns the name of the compression scheme, used for example in user interfaces to select a compressi...
static int reorderDataTraversal(void *data, size_t dataSize, size_t voxSize, const MLint64 imgExt[6])
Reorders the traversal of the data so that local data coherence is used to reduce changes between nei...
static int unReorderBytePlanes(void *data, size_t dataSize, size_t voxSize)
Make data preparation undone, returns 0 on success, and a non 0 value otherwise.
virtual MLErrorCode decompress(const void *srcMem, size_t srcSize, void *&dstMem, MLint64 &resSize) const =0
Uncompresses a chunk of memory.
virtual MLErrorCode setHint(MLuint8 hintIdx, const std::string value)
Set the hint value strVal of hint number hintIdx.
static void undiffCodeData(void *data, size_t dataSize, size_t voxSize=1)
See diffCodeData for the inverse operation and documentation.
static void unpackMLints(const unsigned char packedBuffer[55], MLint vec[6])
Inverse operation to packMLints.
virtual void getImageExtent(MLint ext[6]) const
Returns the extent of the compressed data chunk in voxels or [0,0,0] if not known (the default).
HintType
Possible values to describe the type of a compression parameter.
virtual std::string getSuffix() const
Returns the suffix describing the compression scheme, for example "lzw", "tiff" or so.
virtual void setVoxelSize(size_t vSize)
Set the size of one voxel or 1 if not known (the default).
virtual MLuint8 numUsedHints() const
Number of hints used by the derived compressor class, it defaults to 0.
virtual size_t getVoxelSize() const
Returns the size of one voxel or 1 if not known (the default).
static void diffCodeData(void *data, size_t dataSize, size_t voxSize=1)
This tool recodes a data array by calculating a coded difference between each voxel and its next one ...
MLDataType _dataType
Data type which can be specified by some applications, default is -1 for not known.
virtual void getHint(MLuint8 hintIdx, HintType &hintType, std::string &strVal, std::string &hintName, double &rangeMin, double &rangeMax) const
Get the optional parameters settings for different purposes.
RuntimeType contains type and inheritance information of a class and a static dictionary with informa...
Definition: mlRuntimeType.h:53
#define ML_ABSTRACT_CLASS_HEADER(className)
Same like ML_ABSTRACT_CLASS_HEADER_EXPORTED with a non existing export symbol.
MLint32 MLDataType
MLDataType.
Definition: mlTypeDefs.h:684
MLint32 MLErrorCode
Type of an ML Error code.
Definition: mlTypeDefs.h:818
unsigned char MLuint8
Definition: mlTypeDefs.h:115
INT64 MLint64
Include 64 bit integer support for Windows or Unix.
Definition: mlTypeDefs.h:500
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578