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 unsigned int dim;
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 (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 unsigned int dim;
256
257 Index<D1> destIndex;
258 Size<D1> destSize;
259 const Index<D2> & srcIndex = srcRegion.GetIndex();
260 const Size<D2> & srcSize = srcRegion.GetSize();
261
262 // copy what we can
263 for (dim = 0; dim < D2; ++dim)
264 {
265 destIndex[dim] = srcIndex[dim];
266 destSize[dim] = srcSize[dim];
267 }
268 // fill in the rest of the dimensions with zero/one
269 for (; dim < D1; ++dim)
270 {
271 destIndex[dim] = 0;
272 destSize[dim] = 1;
273 }
274
275 destRegion.SetIndex(destIndex);
276 destRegion.SetSize(destSize);
277}
278
317template <unsigned int D1, unsigned int D2>
319{
320public:
321 virtual void
322 operator()(ImageRegion<D1> & destRegion, const ImageRegion<D2> & srcRegion) const
323 {
324 using ComparisonType = typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType;
325 ImageToImageFilterDefaultCopyRegion<D1, D2>(ComparisonType(), destRegion, srcRegion);
326 }
327
328 virtual ~ImageRegionCopier() = default;
329};
330
333template <unsigned int D1, unsigned int D2>
334std::ostream &
335operator<<(std::ostream & os, const ImageRegionCopier<D1, D2> &)
336{
337 os << "ImageRegionCopier: " << typeid(ImageRegionCopier<D1, D2>).name() << std::endl;
338 return os;
339}
343template <unsigned int D1, unsigned int D2>
344bool
346{
347 return &c1 != &c2;
348}
349
350
351template <unsigned int D1, unsigned int D2>
352void
354 ImageBase<D1> * destImage,
355 const ImageBase<D2> * srcImage)
356{
357 destImage->CopyInformation(srcImage);
358}
359
360
361template <unsigned int D1, unsigned int D2>
362void
364 ImageBase<D1> * destImage,
365 const ImageBase<D2> * srcImage)
366{
367 using DestinationImageType = ImageBase<D1>;
368 using SourceImageType = ImageBase<D2>;
369
370 // Copy what we can from the image from spacing and origin of the input
371 // This logic needs to be augmented with logic that select which
372 // dimensions to copy
373 const typename SourceImageType::SpacingType & inputSpacing = srcImage->GetSpacing();
374 const typename SourceImageType::PointType & inputOrigin = srcImage->GetOrigin();
375 const typename SourceImageType::DirectionType & inputDirection = srcImage->GetDirection();
376
377 typename DestinationImageType::SpacingType destSpacing;
378 typename DestinationImageType::PointType destOrigin;
379 typename DestinationImageType::DirectionType destDirection;
380
381 // copy the input to the output and fill the rest of the
382 // output with zeros.
383 unsigned int i = 0;
384 for (; i < SourceImageType::ImageDimension; ++i)
385 {
386 destSpacing[i] = inputSpacing[i];
387 destOrigin[i] = inputOrigin[i];
388 for (unsigned int j = 0; j < DestinationImageType::ImageDimension; ++j)
389 {
390 if (j < SourceImageType::ImageDimension)
391 {
392 destDirection[j][i] = inputDirection[j][i];
393 }
394 else
395 {
396 destDirection[j][i] = 0.0;
397 }
398 }
399 }
400 for (; i < DestinationImageType::ImageDimension; ++i)
401 {
402 destSpacing[i] = 1.0;
403 destOrigin[i] = 0.0;
404 for (unsigned int j = 0; j < DestinationImageType::ImageDimension; ++j)
405 {
406 if (j == i)
407 {
408 destDirection[j][i] = 1.0;
409 }
410 else
411 {
412 destDirection[j][i] = 0.0;
413 }
414 }
415 }
416
417 // set the spacing and origin
418 destImage->SetSpacing(destSpacing);
419 destImage->SetOrigin(destOrigin);
420 destImage->SetDirection(destDirection);
421 // propagate vector length info
423}
424
425
437template <unsigned int D1, unsigned int D2>
439{
440public:
441 virtual void
442 operator()(ImageBase<D1> * destImage, const ImageBase<D2> * srcImage) const
443 {
444 using ComparisonType = typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType;
445 ImageToImageFilterDefaultCopyInformation<D1, D2>(ComparisonType(), destImage, srcImage);
446 }
447
448 virtual ~ImageInformationCopier() = default;
449};
450
451
452} // end of namespace ImageToImageFilterDetail
453} // end namespace itk
454
455#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