ITK  5.2.0
Insight Toolkit
itkJoinImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 #ifndef itkJoinImageFilter_h
19 #define itkJoinImageFilter_h
20 
22 #include "itkPixelTraits.h"
23 
24 namespace itk
25 {
26 namespace Functor
27 {
47 template <typename TPixel1, typename TPixel2>
49 {
50 public:
51  JoinFunctor() = default;
52  ~JoinFunctor() = default;
54 
56  using Self = JoinFunctor;
57 
62 
64  static constexpr unsigned int Dimension1 = PixelTraits<TPixel1>::Dimension;
65  static constexpr unsigned int Dimension2 = PixelTraits<TPixel2>::Dimension;
66  static constexpr unsigned int JoinDimension = Dimension1 + Dimension2;
67 
70 
71  bool
72  operator!=(const JoinFunctor &) const
73  {
74  return false;
75  }
76 
77  bool
78  operator==(const JoinFunctor & other) const
79  {
80  return !(*this != other);
81  }
82 
84  inline JoinType
85  operator()(const TPixel1 & A, const TPixel2 & B) const
86  {
87  JoinType out;
88 
89  // Copy A into the output, casting as necessary
90  this->FirstCopier(out, 0, A);
91 
92  // Copy B into the output, starting where A left off,casting as necessary
93  this->SecondCopier(out, Dimension1, B);
94 
95  return out;
96  }
97 
98 private:
106  {};
107  template <unsigned int VDimension>
109  {};
110 
121  void
122  FirstCopier(JoinType & out, unsigned int idx, const TPixel1 & A) const
123  {
124  FirstCopier(CopierDispatch<Dimension1>(), out, idx, A);
125  }
126 
128  void
129  FirstCopier(CopierDispatchBase, JoinType & out, unsigned int idx, const TPixel1 & A) const
130  {
131  for (unsigned int i = 0; i < Dimension1; i++, idx++)
132  {
133  out[idx] = static_cast<JoinValueType>(A[i]);
134  }
135  }
137 
139  void FirstCopier(CopierDispatch<1>, JoinType & out, unsigned int idx, const TPixel1 & A) const
140  {
141  out[idx] = static_cast<JoinValueType>(A);
142  }
143 
149  void
150  SecondCopier(JoinType & out, unsigned int idx, const TPixel2 & B) const
151  {
153  }
154 
156  void
157  SecondCopier(CopierDispatchBase, JoinType & out, unsigned int idx, const TPixel2 & B) const
158  {
159  for (unsigned int i = 0; i < Dimension2; i++, idx++)
160  {
161  out[idx] = static_cast<JoinValueType>(B[i]);
162  }
163  }
165 
167  void SecondCopier(CopierDispatch<1>, JoinType & out, unsigned int idx, const TPixel2 & B) const
168  {
169  out[idx] = static_cast<JoinValueType>(B);
170  }
171 }; // class JoinFunction
173 
174 template <typename TImage1, typename TImage2>
175 struct MakeJoin
176 {
179 };
180 } // namespace Functor
181 
212 template <typename TInputImage1, typename TInputImage2>
214  : public BinaryGeneratorImageFilter<TInputImage1,
215  TInputImage2,
216  typename Functor::MakeJoin<TInputImage1, TInputImage2>::ImageType>
217 {
218 public:
219  ITK_DISALLOW_COPY_AND_ASSIGN(JoinImageFilter);
220 
222  static constexpr unsigned int OutputImageDimension = TInputImage1::ImageDimension;
223 
226 
230  using OutputImagePixelType = typename FunctorType::JoinType;
231 
234 
237 
239  itkNewMacro(Self);
240 
243 
244 #ifdef ITK_USE_CONCEPT_CHECKING
245  // Begin concept checking
248  itkConceptMacro(Input1Input2HasJoinTraitsCheck,
251  // End concept checking
252 #endif
253 
254 protected:
256  ~JoinImageFilter() override = default;
257 };
258 } // end namespace itk
259 
260 #endif
itk::Functor::JoinFunctor::JoinType
Vector< JoinValueType, Self::JoinDimension > JoinType
Definition: itkJoinImageFilter.h:69
itk::JoinImageFilter::OutputImageDimension
static constexpr unsigned int OutputImageDimension
Definition: itkJoinImageFilter.h:222
itk::Functor::JoinFunctor::operator!=
bool operator!=(const JoinFunctor &) const
Definition: itkJoinImageFilter.h:72
itk::Functor::JoinFunctor::SecondCopier
void SecondCopier(JoinType &out, unsigned int idx, const TPixel2 &B) const
Definition: itkJoinImageFilter.h:150
itk::Functor::JoinFunctor::FirstCopier
void FirstCopier(CopierDispatchBase, JoinType &out, unsigned int idx, const TPixel1 &A) const
Definition: itkJoinImageFilter.h:129
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::JoinImageFilter
Join two images, resulting in an image where each pixel has the components of the first image followe...
Definition: itkJoinImageFilter.h:213
itk::BinaryGeneratorImageFilter
Implements pixel-wise generic operation of two images, or of an image and a constant.
Definition: itkBinaryGeneratorImageFilter.h:56
itk::JoinImageFilter::FunctorType
typename Functor::MakeJoin< TInputImage1, TInputImage2 >::FunctorType FunctorType
Definition: itkJoinImageFilter.h:228
itkPixelTraits.h
itk::Functor::JoinFunctor::ValueType2
typename PixelTraits< TPixel2 >::ValueType ValueType2
Definition: itkJoinImageFilter.h:60
itk::SmartPointer< Self >
itk::Functor::JoinFunctor::JoinValueType
typename JoinTraits< ValueType1, ValueType2 >::ValueType JoinValueType
Definition: itkJoinImageFilter.h:61
itk::PixelTraits
Traits for a pixel that define the dimension and component type.
Definition: itkPixelTraits.h:45
itk::JoinImageFilter::~JoinImageFilter
~JoinImageFilter() override=default
itk::JoinImageFilter::JoinImageFilter
JoinImageFilter()
Definition: itkJoinImageFilter.h:255
itkBinaryGeneratorImageFilter.h
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::Functor::JoinFunctor::~JoinFunctor
~JoinFunctor()=default
itk::Functor::JoinFunctor::JoinFunctor
JoinFunctor()=default
itk::Functor::JoinFunctor::operator==
bool operator==(const JoinFunctor &other) const
Definition: itkJoinImageFilter.h:78
itk::Functor::JoinFunctor::SecondCopier
void SecondCopier(CopierDispatch< 1 >, JoinType &out, unsigned int idx, const TPixel2 &B) const
Definition: itkJoinImageFilter.h:167
itk::Functor::JoinFunctor::JoinDimension
static constexpr unsigned int JoinDimension
Definition: itkJoinImageFilter.h:66
itk::Functor::JoinFunctor
Join the components of two pixel types into a single pixel type.
Definition: itkJoinImageFilter.h:48
itk::Functor::JoinFunctor::Dimension2
static constexpr unsigned int Dimension2
Definition: itkJoinImageFilter.h:65
itk::Functor::JoinFunctor::ValueType1
typename PixelTraits< TPixel1 >::ValueType ValueType1
Definition: itkJoinImageFilter.h:59
itk::Functor::JoinFunctor::FirstCopier
void FirstCopier(CopierDispatch< 1 >, JoinType &out, unsigned int idx, const TPixel1 &A) const
Definition: itkJoinImageFilter.h:139
itk::JoinTraits::ValueType
TValue1 ValueType
Definition: itkPixelTraits.h:198
itk::JoinImageFilter::OutputImagePixelType
typename FunctorType::JoinType OutputImagePixelType
Definition: itkJoinImageFilter.h:230
itk::JoinImageFilter::OutputImageType
typename Functor::MakeJoin< TInputImage1, TInputImage2 >::ImageType OutputImageType
Definition: itkJoinImageFilter.h:229
itk::PixelTraits::ValueType
typename TPixelType::ValueType ValueType
Definition: itkPixelTraits.h:52
itk::Functor::JoinFunctor::CopierDispatchBase
Definition: itkJoinImageFilter.h:105
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:64
itk::Functor::JoinFunctor::SecondCopier
void SecondCopier(CopierDispatchBase, JoinType &out, unsigned int idx, const TPixel2 &B) const
Definition: itkJoinImageFilter.h:157
itk::Concept::HasJoinTraits
Definition: itkConceptChecking.h:805
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Functor::MakeJoin
Definition: itkJoinImageFilter.h:175
itk::Functor::JoinFunctor::FirstCopier
void FirstCopier(JoinType &out, unsigned int idx, const TPixel1 &A) const
Definition: itkJoinImageFilter.h:122
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itk::Concept::HasPixelTraits
Definition: itkConceptChecking.h:750
itk::Functor::JoinFunctor::operator()
JoinType operator()(const TPixel1 &A, const TPixel2 &B) const
Definition: itkJoinImageFilter.h:85
itk::Functor::JoinFunctor::CopierDispatch
Definition: itkJoinImageFilter.h:108
itk::Functor::JoinFunctor::Dimension1
static constexpr unsigned int Dimension1
Definition: itkJoinImageFilter.h:64
itk::BinaryGeneratorImageFilter::SetFunctor
void SetFunctor(const std::function< ConstRefFunctionType > &f)
Definition: itkBinaryGeneratorImageFilter.h:150