ITK  6.0.0
Insight Toolkit
itkImageToImageFilterDetail.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 * https://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
34namespace itk
35{
44namespace ImageToImageFilterDetail
45{
46
56{};
57
64template <bool>
66{};
67
75template <int>
77{};
78
92template <unsigned int>
94{};
95
102template <bool B1, bool B2>
104{
109};
110
116template <int D1, int D2>
118{
123};
124
135template <unsigned int D1, unsigned int D2>
137{
142
158 using ComparisonType = IntDispatch<(D1 > D2) - (D1 < D2)>;
162};
163
180template <unsigned int D1, unsigned int D2>
181void
183 ImageRegion<D1> & destRegion,
184 const ImageRegion<D2> & srcRegion)
185{
186 destRegion = srcRegion;
187}
188
205template <unsigned int D1, unsigned int D2>
206void
208 ImageRegion<D1> & destRegion,
209 const ImageRegion<D2> & srcRegion)
210{
211 // Source dimension is greater than the destination dimension, copy the
212 // first part of the source into the destination
213
214
215 Index<D1> destIndex;
216 Size<D1> destSize;
217 const Index<D2> & srcIndex = srcRegion.GetIndex();
218 const Size<D2> & srcSize = srcRegion.GetSize();
219
220 // copy what we can
221 for (unsigned int dim = 0; dim < D1; ++dim)
222 {
223 destIndex[dim] = srcIndex[dim];
224 destSize[dim] = srcSize[dim];
225 }
226
227 destRegion.SetIndex(destIndex);
228 destRegion.SetSize(destSize);
229}
230
247template <unsigned int D1, unsigned int D2>
248void
250 ImageRegion<D1> & destRegion,
251 const ImageRegion<D2> & srcRegion)
252{
253 // Source dimension is less than the destination dimension, copy source
254 // into the first part of the destination and set zeros elsewhere.
255 Index<D1> destIndex;
256 Size<D1> destSize;
257 const Index<D2> & srcIndex = srcRegion.GetIndex();
258 const Size<D2> & srcSize = srcRegion.GetSize();
261 // copy what we can
262 {
263 unsigned int dim = 0;
264 for (; dim < D2; ++dim)
265 {
266 destIndex[dim] = srcIndex[dim];
267 destSize[dim] = srcSize[dim];
268 }
269 // fill in the rest of the dimensions with zero/one
270 for (; dim < D1; ++dim)
271 {
272 destIndex[dim] = 0;
273 destSize[dim] = 1;
274 }
275 }
276 destRegion.SetIndex(destIndex);
277 destRegion.SetSize(destSize);
278}
279
318template <unsigned int D1, unsigned int D2>
320{
321public:
322 virtual void
323 operator()(ImageRegion<D1> & destRegion, const ImageRegion<D2> & srcRegion) const
324 {
325 using ComparisonType = typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType;
326 ImageToImageFilterDefaultCopyRegion<D1, D2>(ComparisonType(), destRegion, srcRegion);
327 }
328
329 virtual ~ImageRegionCopier() = default;
330};
331
334template <unsigned int D1, unsigned int D2>
335std::ostream &
336operator<<(std::ostream & os, const ImageRegionCopier<D1, D2> &)
337{
338 os << "ImageRegionCopier: " << typeid(ImageRegionCopier<D1, D2>).name() << std::endl;
339 return os;
340}
344template <unsigned int D1, unsigned int D2>
345bool
347{
348 return &c1 != &c2;
349}
350
351
352template <unsigned int D1, unsigned int D2>
353void
355 ImageBase<D1> * destImage,
356 const ImageBase<D2> * srcImage)
357{
358 destImage->CopyInformation(srcImage);
359}
360
361
362template <unsigned int D1, unsigned int D2>
363void
365 ImageBase<D1> * destImage,
366 const ImageBase<D2> * srcImage)
367{
368 using DestinationImageType = ImageBase<D1>;
369 using SourceImageType = ImageBase<D2>;
370
371 // Copy what we can from the image from spacing and origin of the input
372 // This logic needs to be augmented with logic that select which
373 // dimensions to copy
374 const typename SourceImageType::SpacingType & inputSpacing = srcImage->GetSpacing();
375 const typename SourceImageType::PointType & inputOrigin = srcImage->GetOrigin();
376 const typename SourceImageType::DirectionType & inputDirection = srcImage->GetDirection();
377
378 typename DestinationImageType::SpacingType destSpacing;
379 typename DestinationImageType::PointType destOrigin;
380 typename DestinationImageType::DirectionType destDirection;
381
382 // copy the input to the output and fill the rest of the
383 // output with zeros.
384 unsigned int i = 0;
385 for (; i < SourceImageType::ImageDimension; ++i)
386 {
387 destSpacing[i] = inputSpacing[i];
388 destOrigin[i] = inputOrigin[i];
389 for (unsigned int j = 0; j < DestinationImageType::ImageDimension; ++j)
390 {
391 if (j < SourceImageType::ImageDimension)
392 {
393 destDirection[j][i] = inputDirection[j][i];
394 }
395 else
396 {
397 destDirection[j][i] = 0.0;
398 }
399 }
400 }
401 for (; i < DestinationImageType::ImageDimension; ++i)
402 {
403 destSpacing[i] = 1.0;
404 destOrigin[i] = 0.0;
405 for (unsigned int j = 0; j < DestinationImageType::ImageDimension; ++j)
406 {
407 if (j == i)
408 {
409 destDirection[j][i] = 1.0;
410 }
411 else
412 {
413 destDirection[j][i] = 0.0;
414 }
415 }
416 }
417
418 // set the spacing and origin
419 destImage->SetSpacing(destSpacing);
420 destImage->SetOrigin(destOrigin);
421 destImage->SetDirection(destDirection);
422 // propagate vector length info
424}
425
426
438template <unsigned int D1, unsigned int D2>
440{
441public:
442 virtual void
443 operator()(ImageBase<D1> * destImage, const ImageBase<D2> * srcImage) const
444 {
445 using ComparisonType = typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType;
446 ImageToImageFilterDefaultCopyInformation<D1, D2>(ComparisonType(), destImage, srcImage);
447 }
448
449 virtual ~ImageInformationCopier() = default;
450};
451
452
453} // end of namespace ImageToImageFilterDetail
454} // end namespace itk
455
456#endif
Base class for templated image classes.
Definition: itkImageBase.h:115
virtual const SpacingType & GetSpacing() const
virtual void SetDirection(const DirectionType &direction)
virtual const DirectionType & GetDirection() const
virtual const PointType & GetOrigin() const
virtual void SetSpacing(const SpacingType &spacing)
virtual void SetNumberOfComponentsPerPixel(unsigned int)
virtual void SetOrigin(PointType _arg)
virtual unsigned int GetNumberOfComponentsPerPixel() const
void CopyInformation(const DataObject *data) override
An image region represents a structured region of data.
void SetSize(const SizeType &size)
const IndexType & GetIndex() const
void SetIndex(const IndexType &index)
const SizeType & GetSize() const
A Function object used to copy image meta-data of an image.
virtual void operator()(ImageBase< D1 > *destImage, const ImageBase< D2 > *srcImage) const
A Function object used to dispatching to a routine to copy a region (start index and size).
virtual void operator()(ImageRegion< D1 > &destRegion, const ImageRegion< D2 > &srcRegion) const
void ImageToImageFilterDefaultCopyInformation(const typename BinaryUnsignedIntDispatch< D1, D2 >::FirstEqualsSecondType &, ImageBase< D1 > *destImage, const ImageBase< D2 > *srcImage)
void ImageToImageFilterDefaultCopyRegion(const typename BinaryUnsignedIntDispatch< D1, D2 >::FirstEqualsSecondType &, ImageRegion< D1 > &destRegion, const ImageRegion< D2 > &srcRegion)
bool operator!=(const ImageRegionCopier< D1, D2 > &c1, const ImageRegionCopier< D1, D2 > &c2)
std::ostream & operator<<(std::ostream &os, const ImageRegionCopier< D1, D2 > &)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Templated class to produce a unique type for a pairing of booleans.
Templated class to produce a unique type for a pairing of integers.
Templated class to produce a unique type for a pairing of unsigned integers (usually two dimensions).
Templated class to produce a unique type "true" and "false".
Base class for a class used to dispatch to dimension specific implementations.
Templated class to produce a unique type for each integer.
Templated class to produce a unique type for each unsigned integer (usually a dimension).
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:69
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:70