ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkImageToImageFilterDetail.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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkImageToImageFilterDetail_h
29 #define itkImageToImageFilterDetail_h
30 
31 #include "itkImageRegion.h"
32 #include "itkSmartPointer.h"
33 
34 namespace itk
35 {
44 namespace ImageToImageFilterDetail
45 {
46 
55 struct DispatchBase {};
56 
64 template< bool >
65 struct BooleanDispatch {};
66 
75 template< int >
76 struct IntDispatch:public DispatchBase {};
77 
92 template< unsigned int >
95 
103 template< bool B1, bool B2 >
105 
110 };
111 
118 template< int D1, int D2 >
120 
125 };
126 
138 template< unsigned int D1, unsigned int D2 >
140 
145 
161  typedef IntDispatch < ( D1 > D2 ) - ( D1 < D2 ) > ComparisonType;
165 };
166 
183 template< unsigned int D1, unsigned int D2 >
186  ImageRegion< D1 > & destRegion,
187  const ImageRegion< D2 > & srcRegion)
188 {
189  destRegion = srcRegion;
190 }
191 
208 template< unsigned int D1, unsigned int D2 >
211  ImageRegion< D1 > & destRegion,
212  const ImageRegion< D2 > & srcRegion)
213 {
214  // Source dimension is greater than the destination dimension, copy the
215  // first part of the source into the destination
216  unsigned int dim;
217 
218  Index< D1 > destIndex;
219  Size< D1 > destSize;
220  const Index< D2 > & srcIndex = srcRegion.GetIndex();
221  const Size< D2 > & srcSize = srcRegion.GetSize();
222 
223  // copy what we can
224  for ( dim = 0; dim < D1; ++dim )
225  {
226  destIndex[dim] = srcIndex[dim];
227  destSize[dim] = srcSize[dim];
228  }
229 
230  destRegion.SetIndex(destIndex);
231  destRegion.SetSize(destSize);
232 }
233 
250 template< unsigned int D1, unsigned int D2 >
253  ImageRegion< D1 > & destRegion,
254  const ImageRegion< D2 > & srcRegion)
255 {
256  // Source dimension is less than the destination dimension, copy source
257  // into the first part of the destination and set zeros elsewhere.
258  unsigned int dim;
259 
260  Index< D1 > destIndex;
261  Size< D1 > destSize;
262  const Index< D2 > & srcIndex = srcRegion.GetIndex();
263  const Size< D2 > & srcSize = srcRegion.GetSize();
264 
265  // copy what we can
266  for ( dim = 0; dim < D2; ++dim )
267  {
268  destIndex[dim] = srcIndex[dim];
269  destSize[dim] = srcSize[dim];
270  }
271  // fill in the rest of the dimensions with zero/one
272  for (; dim < D1; ++dim )
273  {
274  destIndex[dim] = 0;
275  destSize[dim] = 1;
276  }
277 
278  destRegion.SetIndex(destIndex);
279  destRegion.SetSize(destSize);
280 }
281 
320 template< unsigned int D1, unsigned int D2 >
322 {
323 public:
324  virtual void operator()(ImageRegion< D1 > & destRegion,
325  const ImageRegion< D2 > & srcRegion) const
326  {
327  typedef typename BinaryUnsignedIntDispatch< D1, D2 >::ComparisonType ComparisonType;
328  ImageToImageFilterDefaultCopyRegion< D1, D2 >(
329  ComparisonType(),
330  destRegion, srcRegion);
331  }
332 
333  virtual ~ImageRegionCopier() {}
334 };
335 
338 template< unsigned int D1, unsigned int D2 >
339 std::ostream & operator<<(std::ostream & os,
341 {
342  os << "ImageRegionCopier: "
343  << typeid( ImageRegionCopier< D1, D2 > ).name() << std::endl;
344  return os;
345 }
347 
349 template< unsigned int D1, unsigned int D2 >
351  const ImageRegionCopier< D1, D2 > & c2)
352 {
353  return &c1 != &c2;
354 }
355 } // end of namespace ImageToImageFilterDetail
356 } // end namespace itk
357 
358 #endif
bool operator!=(const ImageRegionCopier< D1, D2 > &c1, const ImageRegionCopier< D1, D2 > &c2)
void SetSize(const SizeType &size)
const IndexType & GetIndex() const
A Function object used to dispatching to a routine to copy a region (start index and size)...
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
virtual void operator()(ImageRegion< D1 > &destRegion, const ImageRegion< D2 > &srcRegion) const
Templated class to produce a unique type &quot;true&quot; and &quot;false&quot;.
An image region represents a structured region of data.
void ImageToImageFilterDefaultCopyRegion(const typename BinaryUnsignedIntDispatch< D1, D2 >::FirstEqualsSecondType &, ImageRegion< D1 > &destRegion, const ImageRegion< D2 > &srcRegion)
Templated class to produce a unique type for a pairing of booleans.
const SizeType & GetSize() const
Templated class to produce a unique type for a pairing of integers.
Templated class to produce a unique type for each unsigned integer (usually a dimension).
Templated class to produce a unique type for each integer.
Templated class to produce a unique type for a pairing of unsigned integers (usually two dimensions)...
std::ostream & operator<<(std::ostream &os, const ImageRegionCopier< D1, D2 > &)
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:71
void SetIndex(const IndexType &index)
Base class for a class used to dispatch to dimension specific implementations.