RTK  2.0.1
Reconstruction Toolkit
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  * http://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 
25 namespace rtk
26 {
27 
43 namespace Functor
44 {
45 
46 template< class TInput, class TOutput >
47 class LUT
48 {
49 public:
51  using LookupTablePointer = typename LookupTableType::Pointer;
52  using LookupTableDataPointer = typename LookupTableType::PixelType*;
54  using InterpolatorPointer = typename InterpolatorType::Pointer;
55 
56  LUT():
57  m_LookupTableDataPointer(nullptr),
59  {};
60  ~LUT() = default;
61 
64  return m_LookupTablePointer;
65  }
68  m_LookupTableDataPointer = lut->GetBufferPointer();
69  m_InverseLUTSpacing = 1. / m_LookupTablePointer->GetSpacing()[0];
70  m_Interpolator->SetInputImage(lut);
71  }
73 
76  }
77 
78  bool operator!=( const LUT & lut ) const {
80  }
81  bool operator==( const LUT & lut ) const {
83  }
84 
85  inline TOutput operator()( const TInput & val ) const;
86 
87 private:
92 };
93 
94 template< class TInput, class TOutput >
95 TOutput
97 ::operator()( const TInput & val ) const {
98  return m_LookupTableDataPointer[val];
99 }
100 
101 template<>
102 inline
103 float
105 ::operator()( const float & val ) const {
106  InterpolatorType::ContinuousIndexType index;
107  index[0] = m_InverseLUTSpacing * (val - m_LookupTablePointer->GetOrigin()[0]);
108  return float(m_Interpolator->EvaluateAtContinuousIndex(index));
109 }
110 
111 template<>
112 inline
113 double
115 ::operator()( const double & val ) const {
116  InterpolatorType::ContinuousIndexType index;
117  index[0] = m_InverseLUTSpacing * (val - m_LookupTablePointer->GetOrigin()[0]);
118  return double(m_Interpolator->EvaluateAtContinuousIndex(index));
119 }
120 
121 } // end namespace Functor
122 
136 template <class TInputImage, class TOutputImage>
137 class ITK_EXPORT LookupTableImageFilter : public
138  itk::UnaryFunctorImageFilter< TInputImage,
139  TOutputImage,
140  Functor::LUT< typename TInputImage::PixelType,
141  typename TOutputImage::PixelType> >
142 {
143 public:
144  ITK_DISALLOW_COPY_AND_ASSIGN(LookupTableImageFilter);
145 
149 
155 
157  itkNewMacro(Self);
158 
161 
163  virtual void SetLookupTable(LookupTableType* _arg) {
164  //Idem as itkSetObjectMacro + call to functor SetLookupTableDataPointer
165  itkDebugMacro("setting " << "LookupTable" " to " << _arg );
166  if (this->m_LookupTable != _arg || ( _arg && _arg->GetTimeStamp()>this->GetTimeStamp() ) ) {
167  this->m_LookupTable = _arg;
168  this->Modified();
169  this->GetFunctor().SetLookupTable(_arg);
170  }
171  }
173 
175  itkGetModifiableObjectMacro(LookupTable, LookupTableType);
176 
179  void BeforeThreadedGenerateData() override;
180 
181 protected:
182  LookupTableImageFilter() = default;
183  ~LookupTableImageFilter() override = default;
184  typename LookupTableType::Pointer m_LookupTable;
185 
186 };
187 
188 } // end namespace rtk
189 
190 #ifndef ITK_MANUAL_INSTANTIATION
191 #include "rtkLookupTableImageFilter.hxx"
192 #endif
193 
194 #endif
typename LookupTableType::PixelType * LookupTableDataPointer
bool operator==(const LUT &lut) const
LookupTablePointer GetLookupTable()
bool operator!=(const LUT &lut) const
LookupTableDataPointer GetLookupTable() const
void SetLookupTable(LookupTablePointer lut)
virtual void SetLookupTable(LookupTableType *_arg)
Function to do the lookup operation.
LookupTableDataPointer m_LookupTableDataPointer
LookupTableType::Pointer m_LookupTable
TOutput operator()(const TInput &val) const
LookupTablePointer m_LookupTablePointer
InterpolatorPointer m_Interpolator
typename InterpolatorType::Pointer InterpolatorPointer
typename itk::LinearInterpolateImageFunction< LookupTableType, double > InterpolatorType
typename FunctorType::LookupTableType LookupTableType
typename LookupTableType::Pointer LookupTablePointer