MeVisLab Toolbox Reference
mlLUTData.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_LUTDATA_H
14#define ML_LUTDATA_H
15
16
18
19#include "mlLUTSystem.h"
20#include "mlLUTBasic.h"
21
22
23// ML includes
24#include "mlDataTypes.h"
25
26
27
29
31{
32public:
34 reset();
35 }
36
37 void reset() {
38 _id = 0;
39 _minOriginalRange = 0;
40 _maxOriginalRange = 0;
41 }
42
43 void update(unsigned int id, double minOrig, double maxOrig);
44
45 bool operator==(const LUTDataId& other) const;
46 bool operator!=(const LUTDataId& other) const;
47
48 friend class LUTDataBase;
49
50private:
51 unsigned int _id;
52 double _minOriginalRange;
53 double _maxOriginalRange;
54};
55
64{
65protected:
66
69
72 int minRow, int maxRow, int minLayer, int maxLayer);
73
78 MLErrorCode initShared1D (LUTVisualType visualType, int minIndex, int maxIndex, int row, int layer,
80
87
88
89public:
91 virtual ~LUTDataBase();
92
94 void clear();
95
96
98 bool isInitialized (void) const { return _data != nullptr; }
99
101 bool ownsData (void) const { return _ownsData; }
102
104 MLDataType getDataType (void) const { return _dataType; }
105
107 int getEntrySize (void) const { return _entrySize; }
108
110 LUTVisualType getVisualType (void) const { return _visualType; }
111
113 int getNumChannels (void) const { return _numChannels; }
114
116 LUTDimensionality getDimensionality (void) const { return _dimensionality; }
117
119 int getMinIndex (void) const { return _minIndex; }
120
122 int getMaxIndex (void) const { return _maxIndex; }
123
125 int getWidth (void) const { return _maxIndex-_minIndex+1; }
126
128 int getMinRow (void) const { return _minRow; }
129
131 int getMaxRow (void) const { return _maxRow; }
132
134 int getHeight (void) const { return _maxRow-_minRow+1; }
135
137 int getMinLayer (void) const { return _minLayer; }
138
140 int getMaxLayer (void) const { return _maxLayer; }
141
143 int getDepth (void) const { return _maxLayer-_minLayer+1; }
144
146 int getLength (void) const { return _dataLength; }
147
151 int getStride (int dim) const;
152
154 int getDataSize (void) const { return _dataLength*_entrySize; }
155
158 bool isInRange (int index, int row = 0, int layer = 0) const;
159
161 unsigned int getId (void) const { return _lutId._id; }
162
164 void setId (unsigned int id) { _lutId._id = id; }
165
167 void setId (unsigned int id, double minIndex, double maxIndex) { _lutId.update(id, minIndex, maxIndex); }
168
170 const LUTDataId& getFullId() const { return _lutId; }
171
173 void setFullId(const LUTDataId& id) { _lutId = id; }
174
175protected:
176
178 void reset (void);
179
181 void clearData (void);
182
184 bool initData (void);
185
186
189
192
195
197 void *_data;
198
201
202
205
208
211
213 int _minIndex, _maxIndex;
214
216 int _minRow, _maxRow;
217
219 int _minLayer, _maxLayer;
220
223 int _strides[3];
224
227
228
231
232};
233
234
235
241template <typename T>
242class LUTData : public LUTDataBase
243{
244public:
245
248 LUTData():LUTDataBase(getType(reinterpret_cast<T*>(NULL))),_maxEntry(0) {};
249
259 MLDataType getType(float*) { return MLfloatType; }
260 MLDataType getType(double*) { return MLdoubleType; }
262
266 { return init(visualType, minIndex, maxIndex, 0, 0, 0, 0, maxEntry); }
267
271 int minRow, int maxRow, T maxEntry)
272 { return init(visualType, minIndex, maxIndex, minRow, maxRow, 0, 0, maxEntry); }
273
277 int minRow, int maxRow, int minLayer, int maxLayer, T maxEntry);
278
279
287 MLErrorCode initShared1D (LUTVisualType visualType, int minIndex, int maxIndex, int row, int layer,
289
299
300
302 T getMaxEntry (void) const { return _maxEntry; }
303
304
306 T *getData (void) { return reinterpret_cast<T*>(_data); }
307
309 const T *getData (void) const { return reinterpret_cast<const T*>(_data); }
310
312 T *getEntriesAt (int index, int row, int layer)
313 { return getData()+(index*_strides[0]+row*_strides[1]+layer*_strides[2]-_entryOffset); }
314
316 const T *getEntriesAt (int index, int row, int layer) const
317 { return getData()+(index*_strides[0]+row*_strides[1]+layer*_strides[2]-_entryOffset); }
318
320 T *getEntriesAt (int index, int row)
321 { return getEntriesAt(index, row, getMinLayer()); }
322
324 const T *getEntriesAt (int index, int row) const
325 { return getEntriesAt(index, row, getMinLayer()); }
326
328 T *getEntriesAt (int index)
329 { return getEntriesAt(index, getMinRow(), getMinLayer()); }
330
332 const T *getEntriesAt (int index) const
333 { return getEntriesAt(index, getMinRow(), getMinLayer()); }
334
335
337 virtual LUTData<T> *clone (void) const;
338
339
340protected:
341
344
345};
346
347
350template <typename T>
352 int minRow, int maxRow, int minLayer, int maxLayer, T maxEntry)
353{
355
356 if (result == ML_RESULT_OK) {
357 result = LUTDataBase::init(visualType, minIndex, maxIndex, minRow, maxRow, minLayer, maxLayer);
358 }
359 if (result == ML_RESULT_OK) {
360 _maxEntry = maxEntry;
361 }
362
363 return result;
364}
365
366
374template <typename T>
377{
379 LUTDataBase::initShared1D(visualType, minIndex, maxIndex, row, layer, srcLutData, srcIndex, srcRow, srcLayer);
380
381 if (result == ML_RESULT_OK) {
382 _maxEntry = srcLutData->getMaxEntry();
383 }
384
385 return result;
386}
387
388
396template <typename T>
399{
401 LUTDataBase::initShared2D(visualType, minRow, maxRow, layer, srcLutData, srcRow, srcLayer);
402
403 if (result == ML_RESULT_OK) {
404 _maxEntry = srcLutData->getMaxEntry();
405 }
406
407 return result;
408}
409
410
412template <typename T>
414{
416
417 if (newLutData) {
418 if (newLutData->init(_visualType, _minIndex, _maxIndex, _minRow, _maxRow,
419 _minLayer, _maxLayer, _maxEntry) != ML_RESULT_OK) {
420 delete newLutData;
421 newLutData = nullptr;
422 }
423 }
424
425 return newLutData;
426}
427
428
430
431
432
433#endif
434// __mlLUTData_H
@ T
Untyped base class for LUTData template classes.
Definition mlLUTData.h:64
bool isInRange(int index, int row=0, int layer=0) const
Return true if specified index, row and layer position is in LUT range.
int getMaxIndex(void) const
Get maximum index value.
Definition mlLUTData.h:122
int getMinRow(void) const
Get minimum row value.
Definition mlLUTData.h:128
LUTVisualType getVisualType(void) const
Get visual type.
Definition mlLUTData.h:110
unsigned int getId(void) const
Get LUT ID.
Definition mlLUTData.h:161
LUTDataBase(MLDataType dataType)
Constructor, create empty, unallocated table.
int _numChannels
Number of channels.
Definition mlLUTData.h:207
int getHeight(void) const
Get number of rows.
Definition mlLUTData.h:134
void setFullId(const LUTDataId &id)
Set full LUT data ID, including min/max ranged from renderRescaled.
Definition mlLUTData.h:173
int getDepth(void) const
Get number of layers.
Definition mlLUTData.h:143
void clearData(void)
Clear data buffer.
void setId(unsigned int id)
Set LUT ID.
Definition mlLUTData.h:164
void clear()
Clear.
int getMaxRow(void) const
Get maximum row value.
Definition mlLUTData.h:131
bool ownsData(void) const
Return true if this LUTData object owns the referenced LUT data buffer.
Definition mlLUTData.h:101
MLErrorCode initShared1D(LUTVisualType visualType, int minIndex, int maxIndex, int row, int layer, LUTDataBase *srcLutData, int srcIndex, int srcRow, int srcLayer)
Initialize 1D-LUT data for specified visual type, index range and row/layer.
int getMinLayer(void) const
Get minimum layer value.
Definition mlLUTData.h:137
int getNumChannels(void) const
Get number of channels.
Definition mlLUTData.h:113
void * _data
LUT data pointer.
Definition mlLUTData.h:197
MLErrorCode initShared2D(LUTVisualType visualType, int minRow, int maxRow, int layer, LUTDataBase *srcLutData, int srcRow, int srcLayer)
Initialize 2D-LUT data for specified visual type, row range and layer.
bool _ownsData
This flag is true if LUT data buffer is owned by this LUTData object.
Definition mlLUTData.h:200
void setId(unsigned int id, double minIndex, double maxIndex)
Set LUT ID including min/max range on rescaled luts.
Definition mlLUTData.h:167
LUTVisualType _visualType
Visual type.
Definition mlLUTData.h:204
int getDataSize(void) const
Get size of LUT data area (in bytes)
Definition mlLUTData.h:154
LUTDimensionality _dimensionality
Dimensionality (1, 2 or 3)
Definition mlLUTData.h:210
LUTDataId _lutId
LUT ID.
Definition mlLUTData.h:230
int getMinIndex(void) const
Get minimum index value.
Definition mlLUTData.h:119
MLErrorCode init(LUTVisualType visualType, int minIndex, int maxIndex, int minRow, int maxRow, int minLayer, int maxLayer)
Initialize LUT data for specified visual type and index/row/layer ranges.
bool initData(void)
Initialize data buffer, return true if successful.
int getLength(void) const
Get total number of entries.
Definition mlLUTData.h:146
void reset(void)
Reset properties.
int getStride(int dim) const
Get entry stride for index (dim = 1), row (2) and layer (3) dimension, relative to entry size,...
MLDataType _dataType
Data type identifier constant.
Definition mlLUTData.h:188
bool isInitialized(void) const
Return true if LUT initialized.
Definition mlLUTData.h:98
const LUTDataId & getFullId() const
Get full LUT data ID, including min/max ranged from renderRescaled.
Definition mlLUTData.h:170
int _entrySize
Size of single data entry.
Definition mlLUTData.h:191
int getMaxLayer(void) const
Get maximum layer value.
Definition mlLUTData.h:140
LUTDimensionality getDimensionality(void) const
Get number of dimensions (1, 2, or 3)
Definition mlLUTData.h:116
virtual ~LUTDataBase()
Destructor.
int _dataLength
Number of entries.
Definition mlLUTData.h:194
MLDataType getDataType(void) const
Get data type.
Definition mlLUTData.h:104
int _entryOffset
Entry offset for addressing via getEntriesAt() in derived LUTData class.
Definition mlLUTData.h:226
int getWidth(void) const
Get index range width.
Definition mlLUTData.h:125
int getEntrySize(void) const
Get size of a single LUT entry.
Definition mlLUTData.h:107
bool operator!=(const LUTDataId &other) const
void update(unsigned int id, double minOrig, double maxOrig)
bool operator==(const LUTDataId &other) const
void reset()
Definition mlLUTData.h:37
A LUTData object stores an instance of a LUT, rendered for a specified visual type,...
Definition mlLUTData.h:243
T * getEntriesAt(int index, int row, int layer)
Get LUT entries at given index, row and layer.
Definition mlLUTData.h:312
LUTData()
Constructor, passes data type identifier constant to LUTDataBase A specialized constructor for each s...
Definition mlLUTData.h:248
const T * getEntriesAt(int index, int row) const
Get LUT entries at given index and row (const version)
Definition mlLUTData.h:324
const T * getEntriesAt(int index, int row, int layer) const
Get LUT entries at given index, row and layer (const version)
Definition mlLUTData.h:316
MLDataType getType(MLint64 *)
Definition mlLUTData.h:257
virtual LUTData< T > * clone(void) const
Create a new LUTData object with the same properties and a new, uninitialized data buffer.
Definition mlLUTData.h:413
MLErrorCode init(LUTVisualType visualType, int minIndex, int maxIndex, int minRow, int maxRow, int minLayer, int maxLayer, T maxEntry)
Initialize 3D-LUT data for specified visual type, index/row/layer ranges and maximum entry value (= r...
Definition mlLUTData.h:351
MLDataType getType(MLint32 *)
Definition mlLUTData.h:256
MLDataType getType(float *)
Definition mlLUTData.h:259
T * getData(void)
Get LUT data pointer, entries are stored interleaved (e.g. RGBARGBA...)
Definition mlLUTData.h:306
T * getEntriesAt(int index, int row)
Get LUT entries at given index and row.
Definition mlLUTData.h:320
MLDataType getType(MLuint16 *)
Definition mlLUTData.h:253
T * getEntriesAt(int index)
Get LUT entries at given index.
Definition mlLUTData.h:328
T _maxEntry
Maximum entry value (= reference value used for scaling LUT entries)
Definition mlLUTData.h:343
MLDataType getType(MLuint64 *)
Definition mlLUTData.h:258
MLDataType getType(double *)
Definition mlLUTData.h:260
MLDataType getType(MLuint8 *)
supported basic data types
Definition mlLUTData.h:251
MLErrorCode initShared2D(LUTVisualType visualType, int minRow, int maxRow, int layer, LUTData< T > *srcLutData, int srcRow, int srcLayer)
Initialize 2D-LUT data for specified visual type, row range and layer.
Definition mlLUTData.h:397
MLErrorCode init(LUTVisualType visualType, int minIndex, int maxIndex, T maxEntry)
Initialize LUT data for specified visual type, index range and maximum entry value (= reference value...
Definition mlLUTData.h:265
const T * getData(void) const
Get LUT data pointer (const version)
Definition mlLUTData.h:309
const T * getEntriesAt(int index) const
Get LUT entries at given index (const version)
Definition mlLUTData.h:332
MLDataType getType(MLldouble *)
Definition mlLUTData.h:261
MLErrorCode init(LUTVisualType visualType, int minIndex, int maxIndex, int minRow, int maxRow, T maxEntry)
Initialize 2D-LUT data for specified visual type, index/row ranges and maximum entry value (= referen...
Definition mlLUTData.h:270
MLDataType getType(MLint8 *)
Definition mlLUTData.h:252
T getMaxEntry(void) const
Get maximum (reference) entry value.
Definition mlLUTData.h:302
MLDataType getType(MLuint32 *)
Definition mlLUTData.h:255
MLDataType getType(MLint16 *)
Definition mlLUTData.h:254
MLErrorCode initShared1D(LUTVisualType visualType, int minIndex, int maxIndex, int row, int layer, LUTData< T > *srcLutData, int srcIndex, int srcRow, int srcLayer)
Initialize 1D-LUT data for specified visual type and index range.
Definition mlLUTData.h:375
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:596
@ MLuint8Type
Enumerator for the unsigned 8 bit ML integer type.
Definition mlTypeDefs.h:621
@ MLuint32Type
Enumerator for the unsigned 32 bit ML integer type.
Definition mlTypeDefs.h:625
@ MLfloatType
Enumerator for the signed 32 bit ML floating point type.
Definition mlTypeDefs.h:626
@ MLuint16Type
Enumerator for the unsigned 16 bit ML integer type.
Definition mlTypeDefs.h:623
@ MLint64Type
Enumerator for the signed 64 bit ML integer type.
Definition mlTypeDefs.h:628
@ MLint16Type
Enumerator for the signed 16 bit ML integer type.
Definition mlTypeDefs.h:622
@ MLint32Type
Enumerator for the signed 32 bit ML integer type.
Definition mlTypeDefs.h:624
@ MLdoubleType
Enumerator for the signed 64 bit ML floating point type.
Definition mlTypeDefs.h:627
@ MLint8Type
Enumerator for the signed 8 bit ML integer type.
Definition mlTypeDefs.h:620
@ MLuint64Type
Enumerator for the unsigned 64 bit ML integer type.
Definition mlTypeDefs.h:629
@ MLldoubleType
Definition mlTypeDefs.h:669
#define ML_BAD_PARAMETER
A bad/invalid parameter (or even an inappropriate image) has been passed to a module or an algorithm;...
Definition mlTypeDefs.h:823
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:716
#define ML_RESULT_OK
No error. Everything seems to be okay.
Definition mlTypeDefs.h:724
#define MLLUT_EXPORT
System specific macro definitions.
Definition mlLUTSystem.h:25
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition mlTypeDefs.h:425
long double MLldouble
Definition mlTypeDefs.h:232
unsigned int MLuint32
Definition mlTypeDefs.h:185
unsigned char MLuint8
Definition mlTypeDefs.h:109
unsigned short MLuint16
Definition mlTypeDefs.h:142
signed short MLint16
Definition mlTypeDefs.h:125
char MLint8
Definition mlTypeDefs.h:97
INT64 MLint64
Include 64 bit integer support for Windows or Unix.
Definition mlTypeDefs.h:412
signed int MLint32
Definition mlTypeDefs.h:161
LUTDimensionality
LUT dimensionality.
Definition mlLUTBasic.h:78
LUTVisualType
LUT visual type constants to identify the visual interpretation of the individual LUT channels.
Definition mlLUTBasic.h:30