Slicer 5.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkImageMapToWindowLevelAddon.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Copyright (c) TBD
4
5 See COPYRIGHT.txt
6 or http://www.slicer.org/copyright/copyright.txt for details.
7
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13
14 This file was originally developed by Alex Allphin, PhD at Revvity.
15
16==============================================================================*/
25
26#ifndef vtkImageMapToWindowLevelAddon_h
27#define vtkImageMapToWindowLevelAddon_h
28
29// Standard includes
30#include <algorithm> // For clamp
31#include <cmath> // For log10
32
33// VTK includes
34#include "vtkImageMapToWindowLevelColors.h"
35
36// MRML includes
37#include "vtkMRML.h"
38
39class VTK_MRML_EXPORT vtkImageMapToWindowLevelAddon : public vtkImageMapToWindowLevelColors
40{
41public:
42 vtkTypeMacro(vtkImageMapToWindowLevelAddon, vtkImageMapToWindowLevelColors);
43 void PrintSelf(ostream& os, vtkIndent indent) override;
45
48 {
49 Linear = 0,
50 Logarithmic, // emphasize low values
51 InverseLogarithmic, // emphasize high values
52 };
53
57
61
64 template <typename T>
65 static inline double mapScalarToWindow(T inputValue, double rangeMin, double rangeMax, WindowMappingMode mappingMode) noexcept
66 {
67 static_assert(std::is_arithmetic_v<T>, "mapScalarToWindow requires numeric input");
68 if (rangeMin == rangeMax)
69 {
70 return 0.0;
71 }
72 const bool invertWindow = (rangeMin > rangeMax);
73 if (invertWindow)
74 {
75 std::swap(rangeMin, rangeMax);
76 }
77 const double rangeWidth = rangeMax - rangeMin;
78 return computeWindowFactor(static_cast<double>(inputValue), rangeMin, rangeMax, rangeWidth, invertWindow, mappingMode);
79 }
80
81protected:
84
85 int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
86 void ThreadedRequestData(vtkInformation* request,
87 vtkInformationVector** inputVector,
88 vtkInformationVector* outputVector,
89 vtkImageData*** inData,
90 vtkImageData** outData,
91 int outExt[6],
92 int id) override;
93 int RequestData(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector) override;
94
96
97private:
98 template <class T>
99 friend void vtkImageMapToWindowLevelAddonExecute(vtkImageMapToWindowLevelAddon*, vtkImageData*, T*, vtkImageData*, unsigned char*, int[6], int);
100
103 static inline double computeWindowFactor( //
104 double inVal,
105 double lower,
106 double upper,
107 double rangeWidth,
108 bool invertWindow,
109 WindowMappingMode mappingMode) noexcept
110 {
111 double factor;
112 if (inVal <= lower)
113 {
114 factor = 0.0;
115 }
116 else if (inVal >= upper)
117 {
118 factor = 1.0;
119 }
120 else
121 {
122 // lower < inVal < upper, so 0 < t < 1, therefore no clamping needed
123 const double t = (inVal - lower) / rangeWidth;
124 switch (mappingMode)
125 {
126 case WindowMappingMode::Logarithmic: factor = std::log10(1.0 + 9.0 * t); break;
127 case WindowMappingMode::InverseLogarithmic: factor = 1.0 - std::log10(1.0 + 9.0 * (1.0 - t)); break;
128 default: factor = t; break;
129 }
130 }
131 return invertWindow ? 1.0 - factor : factor;
132 }
133
134 vtkImageMapToWindowLevelAddon(const vtkImageMapToWindowLevelAddon&) = delete;
135 void operator=(const vtkImageMapToWindowLevelAddon&) = delete;
136};
137#endif
static double mapScalarToWindow(T inputValue, double rangeMin, double rangeMax, WindowMappingMode mappingMode) noexcept
~vtkImageMapToWindowLevelAddon() override
WindowMappingMode
Window Scalar Mapping Modes.
friend void vtkImageMapToWindowLevelAddonExecute(vtkImageMapToWindowLevelAddon *, vtkImageData *, T *, vtkImageData *, unsigned char *, int[6], int)
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
WindowMappingMode GetMappingMode() const
void PrintSelf(ostream &os, vtkIndent indent) override
void ThreadedRequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector, vtkImageData ***inData, vtkImageData **outData, int outExt[6], int id) override
static vtkImageMapToWindowLevelAddon * New()
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void SetMappingMode(vtkImageMapToWindowLevelAddon::WindowMappingMode mappingMode)