ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
rtkLookupTableImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright RTK Consortium
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18
19#ifndef rtkLookupTableImageFilter_h
20#define rtkLookupTableImageFilter_h
21
24
25namespace rtk
26{
27
42
43namespace Functor
44{
45
46template <class TInput, class TOutput>
47class ITK_TEMPLATE_EXPORT LUT
48{
49public:
54 using InterpolatorPointer = typename InterpolatorType::Pointer;
55
59 ~LUT() = default;
60
64 {
66 }
67 void
69 {
72 m_InverseLUTSpacing = 1. / m_LookupTablePointer->GetSpacing()[0];
73 m_Interpolator->SetInputImage(lut);
74 }
75
76 [[nodiscard]] LookupTableDataPointer
78 {
80 }
81
82 bool
83 operator!=(const LUT & lut) const
84 {
86 }
87 bool
88 operator==(const LUT & lut) const
89 {
91 }
92
93 inline TOutput
94 operator()(const TInput & val) const;
95
96private:
101};
102
103template <class TInput, class TOutput>
104TOutput
105LUT<TInput, TOutput>::operator()(const TInput & val) const
106{
107 return m_LookupTableDataPointer[val];
108}
109
110template <>
111inline float
112LUT<float, float>::operator()(const float & val) const
113{
114 InterpolatorType::ContinuousIndexType index;
115 index[0] = m_InverseLUTSpacing * (val - m_LookupTablePointer->GetOrigin()[0]);
116 return static_cast<float>(m_Interpolator->EvaluateAtContinuousIndex(index));
117}
118
119template <>
120inline double
121LUT<double, double>::operator()(const double & val) const
122{
123 InterpolatorType::ContinuousIndexType index;
124 index[0] = m_InverseLUTSpacing * (val - m_LookupTablePointer->GetOrigin()[0]);
125 return static_cast<double>(m_Interpolator->EvaluateAtContinuousIndex(index));
126}
127
128} // end namespace Functor
129
143template <class TInputImage, class TOutputImage>
144class ITK_TEMPLATE_EXPORT LookupTableImageFilter
145 : public itk::UnaryFunctorImageFilter<TInputImage,
146 TOutputImage,
147 Functor::LUT<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
148{
149public:
150 ITK_DISALLOW_COPY_AND_MOVE(LookupTableImageFilter);
151
155
161
163 itkNewMacro(Self);
164
166 itkOverrideGetNameOfClassMacro(LookupTableImageFilter);
167
169 virtual void
171 {
172 // Idem as itkSetObjectMacro + call to functor SetLookupTableDataPointer
173 itkDebugMacro("setting " << "LookupTable"
174 " to "
175 << _arg);
176 if (this->m_LookupTable != _arg || (_arg && _arg->GetTimeStamp() > this->GetTimeStamp()))
177 {
178 this->m_LookupTable = _arg;
179 this->Modified();
180 this->GetFunctor().SetLookupTable(_arg);
181 }
182 }
183
185 itkGetModifiableObjectMacro(LookupTable, LookupTableType);
186
189 void
191
192protected:
194 ~LookupTableImageFilter() override = default;
195 typename LookupTableType::Pointer m_LookupTable;
196};
197
198} // end namespace rtk
199
200#ifndef ITK_MANUAL_INSTANTIATION
201# include "rtkLookupTableImageFilter.hxx"
202#endif
203
204#endif
Templated n-dimensional image class.
Definition itkImage.h:89
virtual TPixel * GetBufferPointer()
Definition itkImage.h:270
SmartPointer< Self > Pointer
Definition itkImage.h:96
Linearly interpolate an image at specified positions.
virtual void Modified() const
Implements transparent reference counting.
Implements pixel-wise generic operation on one image.
typename LookupTableType::PixelType * LookupTableDataPointer
itk::Image< TOutput, 1 > LookupTableType
typename itk::LinearInterpolateImageFunction< LookupTableType, double > InterpolatorType
LookupTablePointer GetLookupTable()
typename LookupTableType::Pointer LookupTablePointer
typename InterpolatorType::Pointer InterpolatorPointer
TOutput operator()(const TInput &val) const
LookupTableDataPointer GetLookupTable() const
bool operator!=(const LUT &lut) const
bool operator==(const LUT &lut) const
void SetLookupTable(LookupTableType *lut)
void BeforeThreadedGenerateData() override
itk::UnaryFunctorImageFilter< itk::Image< unsigned short, TOutputImage::ImageDimension >, TOutputImage, FunctorType > Superclass
~LookupTableImageFilter() override=default
Functor::LUT< typename itk::Image< unsigned short, TOutputImage::ImageDimension >::PixelType, typename TOutputImage::PixelType > FunctorType
virtual void SetLookupTable(LookupTableType *_arg)