ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkJoinImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software 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 #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 operator!=(const JoinFunctor &) const
72  {
73  return false;
74  }
75 
76  bool operator==(const JoinFunctor & other) const
77  {
78  return !( *this != other );
79  }
80 
82  inline JoinType operator()(const TPixel1 & A, const TPixel2 & B) const
83  {
84  JoinType out;
85 
86  // Copy A into the output, casting as necessary
87  this->FirstCopier(out, 0, A);
88 
89  // Copy B into the output, starting where A left off,casting as necessary
90  this->SecondCopier(out, Dimension1, B);
91 
92  return out;
93  }
94 
95 private:
103  template< unsigned int VDimension >
105 
116  void FirstCopier(JoinType & out, unsigned int idx, const TPixel1 & A) const
117  {
119  }
120 
123  JoinType & out, unsigned int idx, const TPixel1 & A) const
124  {
125  for ( unsigned int i = 0; i < Dimension1; i++, idx++ )
126  {
127  out[idx] = static_cast< JoinValueType >( A[i] );
128  }
129  }
131 
134  JoinType & out, unsigned int idx, const TPixel1 & A) const
135  { out[idx] = static_cast< JoinValueType >( A ); }
136 
142  void SecondCopier(JoinType & out, unsigned int idx, const TPixel2 & B) const
143  {
145  }
146 
149  JoinType & out, unsigned int idx, const TPixel2 & B) const
150  {
151  for ( unsigned int i = 0; i < Dimension2; i++, idx++ )
152  {
153  out[idx] = static_cast< JoinValueType >( B[i] );
154  }
155  }
157 
160  JoinType & out, unsigned int idx, const TPixel2 & B) const
161  {
162  out[idx] = static_cast< JoinValueType >( B );
163  }
164 }; //class JoinFunction
166 
167 template< typename TImage1, typename TImage2 >
168 struct MakeJoin {
169  using FunctorType = JoinFunctor< typename TImage1::PixelType,
170  typename TImage2::PixelType >;
171  using ImageType = Image< typename FunctorType::JoinType,
172  TImage1 ::ImageDimension >;
173 };
174 } //namespace functor
175 
204 template< typename TInputImage1, typename TInputImage2 >
206  public BinaryGeneratorImageFilter< TInputImage1,
207  TInputImage2,
208  typename
209  Functor::MakeJoin< TInputImage1,
210  TInputImage2 >::ImageType >
211 {
212 public:
213  ITK_DISALLOW_COPY_AND_ASSIGN(JoinImageFilter);
214 
216  static constexpr unsigned int OutputImageDimension = TInputImage1::ImageDimension;
217 
220 
222  using FunctorType = typename Functor::MakeJoin< TInputImage1,
223  TInputImage2 >::FunctorType;
224  using OutputImageType = typename Functor::MakeJoin< TInputImage1,
225  TInputImage2 >::ImageType;
226  using OutputImagePixelType = typename FunctorType::JoinType;
227 
230 
233 
235  itkNewMacro(Self);
236 
239 
240 #ifdef ITK_USE_CONCEPT_CHECKING
241  // Begin concept checking
242  itkConceptMacro( Input1HasPixelTraitsCheck,
244  itkConceptMacro( Input2HasPixelTraitsCheck,
246  itkConceptMacro( Input1Input2HasJoinTraitsCheck,
249  // End concept checking
250 #endif
251 
252 protected:
254  ~JoinImageFilter() override = default;
255 };
256 } // end namespace itk
257 
258 #endif
void SecondCopier(CopierDispatch< 1 >, JoinType &out, unsigned int idx, const TPixel2 &B) const
Light weight base class for most itk classes.
static constexpr unsigned int Dimension2
JoinType operator()(const TPixel1 &A, const TPixel2 &B) const
void FirstCopier(JoinType &out, unsigned int idx, const TPixel1 &A) const
static constexpr unsigned int Dimension1
typename PixelTraits< TPixel2 >::ValueType ValueType2
typename FunctorType::JoinType OutputImagePixelType
bool operator!=(const JoinFunctor &) const
bool operator==(const JoinFunctor &other) const
Vector< JoinValueType, Self::JoinDimension > JoinType
static constexpr unsigned int OutputImageDimension
Traits for a pixel that define the dimension and component type.
typename TPixelType::ValueType ValueType
typename JoinTraits< ValueType1, ValueType2 >::ValueType JoinValueType
Join two images, resulting in an image where each pixel has the components of the first image followe...
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
void SecondCopier(CopierDispatchBase, JoinType &out, unsigned int idx, const TPixel2 &B) const
Implements pixel-wise generic operation of two images, or of an image and a constant.
void SecondCopier(JoinType &out, unsigned int idx, const TPixel2 &B) const
static constexpr unsigned int JoinDimension
typename Functor::MakeJoin< TInputImage1, TInputImage2 >::ImageType OutputImageType
void SetFunctor(const std::function< ConstRefFunctionType > &f)
void FirstCopier(CopierDispatch< 1 >, JoinType &out, unsigned int idx, const TPixel1 &A) const
Join the components of two pixel types into a single pixel type.
typename Functor::MakeJoin< TInputImage1, TInputImage2 >::FunctorType FunctorType
#define itkConceptMacro(name, concept)
void FirstCopier(CopierDispatchBase, JoinType &out, unsigned int idx, const TPixel1 &A) const
~JoinImageFilter() override=default
typename PixelTraits< TPixel1 >::ValueType ValueType1
Templated n-dimensional image class.
Definition: itkImage.h:75