MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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.
21
22#include <mlBase.h>
23
24#include <cstring>
25
26
28
31
32// -------------------------------------------------------------------
35// -------------------------------------------------------------------
37{
38public:
39 //--------------------------------------------------------------------------------
42 //--------------------------------------------------------------------------------
43
46 enum {
47 MaxHints = 10
48 };
49
51 enum HintType {
52 Unused = 0,
53 IsDouble = 1,
54 IsInt = 2,
55 IsBool = 3,
56 IsString = 4,
57 IsDataType = 5
58 };
60
61
62 //--------------------------------------------------------------------------------
65 //--------------------------------------------------------------------------------
66
69
71 ~DataCompressor() override;
73
74
75 //--------------------------------------------------------------------------------
78 //--------------------------------------------------------------------------------
79
83 virtual std::string getTypeName() const = 0;
84
88 virtual std::string getVersion() const = 0;
89
92 virtual bool isSupportedVersion(const std::string& ver) const = 0;
93
97 virtual std::string getVendor() const
98 {
99 return "";
100 }
101
104 virtual std::string getSuffix() const
105 {
106 return "";
107 }
108
114 virtual bool isLossy() const
115 {
116 return false;
117 }
119
120
121 //--------------------------------------------------------------------------------
124 //--------------------------------------------------------------------------------
125
127 virtual MLDataType getDataType() const
128 {
129 return _dataType;
130 }
131
134 {
135 _dataType = dt;
136 }
137
138
140 virtual size_t getVoxelSize() const
141 {
142 return _voxelSize;
143 }
144
146 virtual void setVoxelSize(size_t vSize)
147 {
148 _voxelSize = vSize;
149 }
150
151
153 virtual void getImageExtent(MLint ext[6]) const
154 {
155 memcpy(ext, _ext, sizeof(MLint) * 6);
156 }
157
159 virtual void setImageExtent(const MLint ext[6])
160 {
161 memcpy(_ext, ext, sizeof(MLint) * 6);
162 }
163
164
166 virtual MLuint8 numUsedHints() const
167 {
168 return 0;
169 }
170
172 virtual void getHint(MLuint8 hintIdx, HintType& hintType, std::string& strVal, std::string& hintName,
173 double& rangeMin, double& rangeMax) const;
174
177 virtual MLErrorCode setHint(MLuint8 hintIdx, const std::string value);
178
181 virtual MLErrorCode setHint(const std::string& hintName, const std::string& value);
182
184 virtual int findHint(const std::string& hintName);
186
187
188 //--------------------------------------------------------------------------------
191 //--------------------------------------------------------------------------------
192
207 [[nodiscard]]
208 virtual MLErrorCode compress(const void* srcMem, size_t srcSize, void*& dstMem, MLint& dstNum) const = 0;
209
225 [[nodiscard]]
226 virtual MLErrorCode decompress(const void* srcMem, size_t srcSize, void*& dstMem, MLint64& resSize) const = 0;
227
228
229protected:
232
235
237 MLint _ext[6];
238
241
243 HintType _hintType[MaxHints];
244
246 std::string _strHints[MaxHints];
247
249 std::string _hintName[MaxHints];
250
252 double _rangeMin[MaxHints];
253
255 double _rangeMax[MaxHints];
257
258
259 //-----------------------------------------------------------
262 //-----------------------------------------------------------
275 static int reorderBytePlanes(void* data, size_t dataSize, size_t voxSize);
276
280 static int unReorderBytePlanes(void* data, size_t dataSize, size_t voxSize);
281
298 static void diffCodeData(void* data, size_t dataSize, size_t voxSize = 1);
299
302 static void undiffCodeData(void* data, size_t dataSize, size_t voxSize = 1);
303
317 static int reorderDataTraversal(void* data, size_t dataSize, size_t voxSize, const MLint64 imgExt[6]);
318
322 static int unReorderDataTraversal(void* data, size_t dataSize, size_t voxSize, const MLint64 imgExt[6]);
323
328 static void packMLints(const MLint vec[6], unsigned char packedBuffer[55]);
329
331 static void unpackMLints(const unsigned char packedBuffer[55], MLint vec[6]);
332
334
335private:
339 static std::vector<CompressionRegisterEntry>::iterator findCompressorType(const std::string& typeName);
340
344 static std::vector<CompressionRegisterEntry>::iterator findCompressorType(const RuntimeType& rtType);
345
347 static std::vector<CompressionRegisterEntry> _dataCompressorTypes;
348
351};
352
354
355#endif // __mlDataCompressor_H
#define MLDATA_COMPRESSOR_EXPORT
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:63
Abstract base class for ML data compression algorithms.
size_t _voxelSize
Data type that can be specified by some applications, default is 1 if unknown.
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.
virtual void setDataType(MLDataType dt)
Sets the data type of the compressed data or -1 if unknown. Default is -1.
virtual MLDataType getDataType() const
Returns the data type of the compressed data or -1 if unknown. Default is -1.
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.
DataCompressor()
Constructor.
virtual MLErrorCode setHint(const std::string &hintName, const std::string &value)
Sets the hint value of the hint given by the name hintName.
~DataCompressor() override
Destructor.
virtual std::string getVendor() const
Returns the name of the vendor providing the compressor code or algorithm, something of the kind "MeV...
virtual void setImageExtent(const MLint ext[6])
Sets the size of one voxel or 1 if unknown. Default is 1.
static int reorderBytePlanes(void *data, size_t dataSize, size_t voxSize)
Prepares the data for optimal compression, returns 0 on success, and a non-zero 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 to use local data coherence, reducing changes between neighboring ...
static int unReorderBytePlanes(void *data, size_t dataSize, size_t voxSize)
Makes data preparation undone, returns 0 on success, and a non-zero 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)
Sets the hint value of the 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 unknown. Default is [0,...
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".
virtual void setVoxelSize(size_t vSize)
Sets the size of one voxel or 1 if unknown. Default is 1.
virtual MLuint8 numUsedHints() const
Returns the 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 unknown. Default is 1.
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 voxe...
MLDataType _dataType
Data type that can be specified by some applications, default is -1 if unknown.
virtual void getHint(MLuint8 hintIdx, HintType &hintType, std::string &strVal, std::string &hintName, double &rangeMin, double &rangeMax) const
Gets the optional parameters settings for different purposes.
RuntimeType contains type and inheritance information of a class and a static dictionary with informa...
#define ML_ABSTRACT_CLASS_HEADER(className)
Similar to ML_ABSTRACT_CLASS_HEADER_EXPORTED with a non-existing export symbol.
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:592
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:772
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
unsigned char MLuint8
Definition mlTypeDefs.h:109
INT64 MLint64
Include 64-bit integer support for Windows or Unix.
Definition mlTypeDefs.h:411
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:489