ITK  4.8.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:
54 
56  typedef JoinFunctor Self;
57 
62 
64  itkStaticConstMacro(Dimension1, unsigned int,
66  itkStaticConstMacro(Dimension2, unsigned int,
68  itkStaticConstMacro(JoinDimension, unsigned int,
71 
74 
75  bool operator!=(const JoinFunctor &) const
76  {
77  return false;
78  }
79 
80  bool operator==(const JoinFunctor & other) const
81  {
82  return !( *this != other );
83  }
84 
86  inline JoinType operator()(const TPixel1 & A, const TPixel2 & B) const
87  {
88  JoinType out;
89 
90  // Copy A into the output, casting as necessary
91  this->FirstCopier(out, 0, A);
92 
93  // Copy B into the output, starting where A left off,casting as necessary
94  this->SecondCopier(out, Dimension1, B);
95 
96  return out;
97  }
98 
99 private:
107  template< unsigned int VDimension >
109 
120  void FirstCopier(JoinType & out, unsigned int idx, const TPixel1 & A) const
121  {
123  }
124 
127  JoinType & out, unsigned int idx, const TPixel1 & A) const
128  {
129  for ( unsigned int i = 0; i < Dimension1; i++, idx++ )
130  {
131  out[idx] = static_cast< JoinValueType >( A[i] );
132  }
133  }
135 
138  JoinType & out, unsigned int idx, const TPixel1 & A) const
139  { out[idx] = static_cast< JoinValueType >( A ); }
140 
146  void SecondCopier(JoinType & out, unsigned int idx, const TPixel2 & B) const
147  {
149  }
150 
153  JoinType & out, unsigned int idx, const TPixel2 & B) const
154  {
155  for ( unsigned int i = 0; i < Dimension2; i++, idx++ )
156  {
157  out[idx] = static_cast< JoinValueType >( B[i] );
158  }
159  }
161 
164  JoinType & out, unsigned int idx, const TPixel2 & B) const
165  {
166  out[idx] = static_cast< JoinValueType >( B );
167  }
168 }; //class JoinFunction
170 
171 template< typename TImage1, typename TImage2 >
172 struct MakeJoin {
173  typedef JoinFunctor< typename TImage1::PixelType,
174  typename TImage2::PixelType > FunctorType;
175  typedef Image< typename FunctorType::JoinType,
176  TImage1 ::ImageDimension > ImageType;
177 };
178 } //namespace functor
179 
208 template< typename TInputImage1, typename TInputImage2 >
210  public BinaryFunctorImageFilter< TInputImage1,
211  TInputImage2,
212  typename
213  Functor::MakeJoin< TInputImage1,
214  TInputImage2 >::ImageType,
215  typename
216  Functor::MakeJoin< TInputImage1,
217  TInputImage2 >::FunctorType >
218 {
219 public:
221  itkStaticConstMacro(OutputImageDimension, unsigned int,
222  TInputImage1::ImageDimension);
223 
226 
228  typedef typename Functor::MakeJoin< TInputImage1,
229  TInputImage2 >::FunctorType FunctorType;
230  typedef typename Functor::MakeJoin< TInputImage1,
231  TInputImage2 >::ImageType OutputImageType;
233 
235  typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, OutputImageType,
237 
240 
242  itkNewMacro(Self);
243 
246 
247 #ifdef ITK_USE_CONCEPT_CHECKING
248  // Begin concept checking
249  itkConceptMacro( Input1HasPixelTraitsCheck,
251  itkConceptMacro( Input2HasPixelTraitsCheck,
253  itkConceptMacro( Input1Input2HasJoinTraitsCheck,
256  // End concept checking
257 #endif
258 
259 protected:
261  virtual ~JoinImageFilter() {}
262 
263 private:
264  JoinImageFilter(const Self &); //purposely not implemented
265  void operator=(const Self &); //purposely not implemented
266 };
267 } // end namespace itk
268 
269 #endif
static const unsigned int JoinDimension
void SecondCopier(CopierDispatch< 1 >, JoinType &out, unsigned int idx, const TPixel2 &B) const
JoinTraits< ValueType1, ValueType2 >::ValueType JoinValueType
JoinFunctor< typename TImage1::PixelType, typename TImage2::PixelType > FunctorType
Light weight base class for most itk classes.
TPixelType::ValueType ValueType
JoinType operator()(const TPixel1 &A, const TPixel2 &B) const
Vector< JoinValueType, itkGetStaticConstMacro(JoinDimension) > JoinType
void FirstCopier(JoinType &out, unsigned int idx, const TPixel1 &A) const
BinaryFunctorImageFilter< TInputImage1, TInputImage2, OutputImageType, FunctorType > Superclass
bool operator!=(const JoinFunctor &) const
bool operator==(const JoinFunctor &other) const
PixelTraits< TPixel1 >::ValueType ValueType1
static const unsigned int OutputImageDimension
Traits for a pixel that define the dimension and component type.
static const unsigned int Dimension2
Join two images, resulting in an image where each pixel has the components of the first image followe...
Functor::MakeJoin< TInputImage1, TInputImage2 >::ImageType OutputImageType
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
void SecondCopier(CopierDispatchBase, JoinType &out, unsigned int idx, const TPixel2 &B) const
void SecondCopier(JoinType &out, unsigned int idx, const TPixel2 &B) const
FunctorType::JoinType OutputImagePixelType
PixelTraits< TPixel2 >::ValueType ValueType2
void operator=(const Self &)
Image< typename FunctorType::JoinType, TImage1::ImageDimension > ImageType
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.
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
#define itkConceptMacro(name, concept)
static const unsigned int Dimension1
Functor::MakeJoin< TInputImage1, TInputImage2 >::FunctorType FunctorType
void FirstCopier(CopierDispatchBase, JoinType &out, unsigned int idx, const TPixel1 &A) const
Templated n-dimensional image class.
Definition: itkImage.h:75
Implements pixel-wise generic operation of two images, or of an image and a constant.