ITK  4.2.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< class TPixel1, class 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,
177 };
178 } //namespace functor
179 
208 template< class TInputImage1, class TInputImage2 >
209 class ITK_EXPORT JoinImageFilter:
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 
249  itkConceptMacro( Input1HasPixelTraitsCheck,
251  itkConceptMacro( Input2HasPixelTraitsCheck,
253  itkConceptMacro( Input1Input2HasJoinTraitsCheck,
256 
258 #endif
259 protected:
261  virtual ~JoinImageFilter() {}
262 private:
263  JoinImageFilter(const Self &); //purposely not implemented
264  void operator=(const Self &); //purposely not implemented
265 };
266 } // end namespace itk
268 
269 #endif
270