MeVisLab Toolbox Reference
mlDICOMTagPaletteTools.h
Go to the documentation of this file.
1 // Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2 // **InsertLicense** code
3 //----------------------------------------------------------------------------------
5 
10 //----------------------------------------------------------------------------------
11 #pragma once
12 
13 #include "MLDICOMTagsSystem.h"
14 
15 #include <mlUtilsSystem.h>
16 
17 // DICOM Tree prototypes.
18 #include <DCMTree_Lib.h>
19 
20 #include <ThirdPartyWarningsDisable.h>
21 #include <cstring>
22 #include <ThirdPartyWarningsRestore.h>
23 
24 ML_START_NAMESPACE
25 
26 //----------------------------------------------------------------------------------
28 //----------------------------------------------------------------------------------
29 namespace DICOMTagTools {
30 
31 //------------------------------------------------------------------------------------------------
33 //------------------------------------------------------------------------------------------------
37  {
38  _setUpArrays();
39  }
40 
43  {
44  _deleteArrays();
45  }
46 
48  inline DicomPaletteInfo(const DicomPaletteInfo &inputInfo)
49  {
50  _setUpArrays();
51  *this = inputInfo;
52  }
53 
55  inline DicomPaletteInfo &operator=(const DicomPaletteInfo &inputInfo)
56  {
57  if (this == &inputInfo){ return *this; }
58 
59  dataType = inputInfo.dataType;
60  minVal = inputInfo.minVal;
61  maxVal = inputInfo.maxVal;
62  numEntries = inputInfo.numEntries;
63  usesAlpha = inputInfo.usesAlpha;
64  isSupplementalPaletteLUT = inputInfo.isSupplementalPaletteLUT;
65 
66  const size_t NumEntries = 65536u*4u;
67  memcpy(rgbaLUT, inputInfo.rgbaLUT, NumEntries*sizeof(MLuint16));
68  memcpy(rgbaFloatLUT, inputInfo.rgbaFloatLUT, NumEntries*sizeof(MLfloat));
69 
70  minLUTEntry = inputInfo.minLUTEntry;
71  maxLUTEntry = inputInfo.maxLUTEntry;
72 
73  return *this;
74  }
75 
77  inline bool operator==(const DicomPaletteInfo &inputInfo) const
78  {
79  return (dataType == inputInfo.dataType) &&
80  (minVal == inputInfo.minVal) &&
81  (maxVal == inputInfo.maxVal) &&
82  (numEntries == inputInfo.numEntries) &&
83  (usesAlpha == inputInfo.usesAlpha) &&
84  (isSupplementalPaletteLUT == inputInfo.isSupplementalPaletteLUT) &&
85 
86  (memcmp(rgbaLUT, inputInfo.rgbaLUT, static_cast<size_t>(numEntries)*4u*sizeof(MLuint16)) == 0) &&
87  (memcmp(rgbaFloatLUT, inputInfo.rgbaFloatLUT, static_cast<size_t>(numEntries)*4u*sizeof(MLfloat)) == 0) &&
88 
89  (minLUTEntry == inputInfo.minLUTEntry) &&
90  (maxLUTEntry == inputInfo.maxLUTEntry);
91  }
92 
94  inline bool operator!=(const DicomPaletteInfo& inputInfo) const
95  {
96  return !(this->operator==(inputInfo));
97  }
98 
100  inline bool isValid() const {
101  return ((dataType == MLuint8Type) ||
102  (dataType == MLuint16Type)||
103  (dataType == MLfloatType)) &&
104  (numEntries > 0) &&
105  (minLUTEntry <= maxLUTEntry);
106  }
107 
111 
114  MLint32 minVal = 0;
115 
117  MLint32 maxVal = 0;
118 
120  MLuint32 numEntries = 0;
121 
123  bool usesAlpha = false;
124 
127  bool isSupplementalPaletteLUT = false;
128 
130  MLuint16 *rgbaLUT = nullptr;
131 
133  MLfloat *rgbaFloatLUT = nullptr;
134 
136  MLuint16 minLUTEntry = ML_UINT16_MAX;
137 
139  MLuint16 maxLUTEntry = ML_UINT16_MIN;
140 
141  private:
143  void _setUpArrays()
144  {
145  const size_t NumEntries = 65536u*4u;
146  rgbaLUT = new MLuint16[NumEntries*sizeof(MLuint16)];
147  std::memset(rgbaLUT, 0, NumEntries*sizeof(MLuint16));
148 
149  rgbaFloatLUT = new MLfloat[NumEntries*sizeof(MLfloat)];
150  std::memset(rgbaFloatLUT, 0, NumEntries*sizeof(MLfloat));
151  }
153  void _deleteArrays()
154  {
155  delete[] rgbaLUT;
156  rgbaLUT = nullptr;
157  delete[] rgbaFloatLUT;
158  rgbaFloatLUT = nullptr;
159  }
160 };
161 
166 
167 };
168 
169 ML_END_NAMESPACE
Project global and OS specific declarations.
#define MLDICOMTags_EXPORT
If included by external modules, exported symbols are declared as import symbols.
#define ML_INVALID_DATA_TYPE
Defines an invalid MLDataType.
Definition: mlTypeDefs.h:715
MLint32 MLDataType
MLDataType.
Definition: mlTypeDefs.h:684
@ MLuint8Type
Enumerator for the unsigned 8 bit ML integer type.
Definition: mlTypeDefs.h:723
@ MLfloatType
Enumerator for the signed 32 bit ML floating point type.
Definition: mlTypeDefs.h:728
@ MLuint16Type
Enumerator for the unsigned 16 bit ML integer type.
Definition: mlTypeDefs.h:725
#define ML_UINT16_MAX
Definition: mlTypeDefs.h:152
unsigned int MLuint32
Definition: mlTypeDefs.h:191
unsigned short MLuint16
Definition: mlTypeDefs.h:148
#define ML_UINT16_MIN
Definition: mlTypeDefs.h:151
signed int MLint32
Definition: mlTypeDefs.h:167
float MLfloat
Definition: mlTypeDefs.h:207
boost::shared_ptr< const Tree > Const_TreePtr
Definition: DCMTree_Lib.h:73
MLDICOMTags_EXPORT void determinePaletteInformation(DCMTree::Const_TreePtr dcmTree, DicomPaletteInfo &info)
Gets the palette information from dcmTree into a DicomPaletteInfo structure.
bool operator==(const Tmat2< DT > &a, const Tmat2< DT > &b)
a == b ? Return true if yes.
Definition: mlMatrix2.h:425
DICOM palette container which is to be used for ML index image to RGB image voxel translation.
bool usesAlpha
True if alpha channel is valid, otherwise false.
MLint32 maxVal
Maximum voxel value to map to a color, all larger voxel values shall be clamped to it.
MLuint32 numEntries
Number of valid table entries in rgbLUT, at most 65536.
DicomPaletteInfo & operator=(const DicomPaletteInfo &inputInfo)
Assignment operator.
bool operator!=(const DicomPaletteInfo &inputInfo) const
Comparison operator, returns false on content inequality (different array pointers are not handled as...
MLuint16 * rgbaLUT
Table of RGB[A] values as MLuint16 values if isSupplementalPaletteLUT is false, otherwise undefined.
MLint32 minVal
Minimum voxel value to map to a color, all smaller voxel values shall be clamped to it,...
bool operator==(const DicomPaletteInfo &inputInfo) const
Comparison operator, equals on content equality (arrays can have different pointers but need to have ...
MLDataType dataType
MLDataType of color table entries, MLuint8Type or MLuint16Type or ML_INVALID_DATA_TYPE if not defined...
bool isValid() const
Returns true if the palette looks valid, otherwise false.
MLuint16 maxLUTEntry
Maximum value found in all entries of LUT in any of the R, G, or B channels (but not Alpha even if it...
DicomPaletteInfo(const DicomPaletteInfo &inputInfo)
Copy constructor.
MLfloat * rgbaFloatLUT
Table of RGB[A] values as MLfloat values if isSupplementalPaletteLUT is true, otherwise undefined.
bool isSupplementalPaletteLUT
If true then the rgbaFloatLUT is used and has a meaning according to a Supplemental LUT according to ...
MLuint16 minLUTEntry
Minimum value found in all entries of LUT in any of the R, G, or B channels (but not Alpha even if it...