ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
34
44{
45
55{};
56
63template <bool>
65{};
66
74template <int>
76{};
77
91template <unsigned int>
93{};
94
101template <bool B1, bool B2>
109
115template <int D1, int D2>
123
134template <unsigned int D1, unsigned int D2>
162
179template <unsigned int D1, unsigned int D2>
180void
182 ImageRegion<D1> & destRegion,
183 const ImageRegion<D2> & srcRegion)
184{
185 destRegion = srcRegion;
186}
187
204template <unsigned int D1, unsigned int D2>
205void
207 ImageRegion<D1> & destRegion,
208 const ImageRegion<D2> & srcRegion)
209{
210 // Source dimension is greater than the destination dimension, copy the
211 // first part of the source into the destination
212
213
214 Index<D1> destIndex;
215 Size<D1> destSize;
216 const Index<D2> & srcIndex = srcRegion.GetIndex();
217 const Size<D2> & srcSize = srcRegion.GetSize();
218
219 // copy what we can
220 for (unsigned int dim = 0; dim < D1; ++dim)
221 {
222 destIndex[dim] = srcIndex[dim];
223 destSize[dim] = srcSize[dim];
224 }
225
226 destRegion.SetIndex(destIndex);
227 destRegion.SetSize(destSize);
228}
229
246template <unsigned int D1, unsigned int D2>
247void
249 ImageRegion<D1> & destRegion,
250 const ImageRegion<D2> & srcRegion)
251{
252 // Source dimension is less than the destination dimension, copy source
253 // into the first part of the destination and set zeros elsewhere.
254 Index<D1> destIndex;
255 Size<D1> destSize;
256 const Index<D2> & srcIndex = srcRegion.GetIndex();
257 const Size<D2> & srcSize = srcRegion.GetSize();
258
259 // copy what we can
260 {
261 unsigned int dim = 0;
262 for (; dim < D2; ++dim)
263 {
264 destIndex[dim] = srcIndex[dim];
265 destSize[dim] = srcSize[dim];
266 }
267 // fill in the rest of the dimensions with zero/one
268 for (; dim < D1; ++dim)
269 {
270 destIndex[dim] = 0;
271 destSize[dim] = 1;
272 }
273 }
274 destRegion.SetIndex(destIndex);
275 destRegion.SetSize(destSize);
276}
277
316template <unsigned int D1, unsigned int D2>
318{
319public:
320 virtual void
321 operator()(ImageRegion<D1> & destRegion, const ImageRegion<D2> & srcRegion) const
322 {
323 using ComparisonType = typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType;
324 ImageToImageFilterDefaultCopyRegion<D1, D2>(ComparisonType(), destRegion, srcRegion);
325 }
326
327 virtual ~ImageRegionCopier() = default;
328};
329
332template <unsigned int D1, unsigned int D2>
333std::ostream &
334operator<<(std::ostream & os, const ImageRegionCopier<D1, D2> &)
335{
336 os << "ImageRegionCopier: " << typeid(ImageRegionCopier<D1, D2>).name() << std::endl;
337 return os;
338}
339
341template <unsigned int D1, unsigned int D2>
342bool
344{
345 return &c1 != &c2;
346}
347
348
349template <unsigned int D1, unsigned int D2>
350void
352 ImageBase<D1> * destImage,
353 const ImageBase<D2> * srcImage)
354{
355 destImage->CopyInformation(srcImage);
356}
357
358
359template <unsigned int D1, unsigned int D2>
360void
362 ImageBase<D1> * destImage,
363 const ImageBase<D2> * srcImage)
364{
365 using DestinationImageType = ImageBase<D1>;
366 using SourceImageType = ImageBase<D2>;
367
368 // Copy what we can from the image from spacing and origin of the input
369 // This logic needs to be augmented with logic that select which
370 // dimensions to copy
371 const typename SourceImageType::SpacingType & inputSpacing = srcImage->GetSpacing();
372 const typename SourceImageType::PointType & inputOrigin = srcImage->GetOrigin();
373 const typename SourceImageType::DirectionType & inputDirection = srcImage->GetDirection();
374
375 typename DestinationImageType::SpacingType destSpacing;
376 typename DestinationImageType::PointType destOrigin;
377 typename DestinationImageType::DirectionType destDirection;
378
379 // copy the input to the output and fill the rest of the
380 // output with zeros.
381 unsigned int i = 0;
382 for (; i < SourceImageType::ImageDimension; ++i)
383 {
384 destSpacing[i] = inputSpacing[i];
385 destOrigin[i] = inputOrigin[i];
386 for (unsigned int j = 0; j < DestinationImageType::ImageDimension; ++j)
387 {
388 if (j < SourceImageType::ImageDimension)
389 {
390 destDirection[j][i] = inputDirection[j][i];
391 }
392 else
393 {
394 destDirection[j][i] = 0.0;
395 }
396 }
397 }
398 for (; i < DestinationImageType::ImageDimension; ++i)
399 {
400 destSpacing[i] = 1.0;
401 destOrigin[i] = 0.0;
402 for (unsigned int j = 0; j < DestinationImageType::ImageDimension; ++j)
403 {
404 if (j == i)
405 {
406 destDirection[j][i] = 1.0;
407 }
408 else
409 {
410 destDirection[j][i] = 0.0;
411 }
412 }
413 }
414
415 // set the spacing and origin
416 destImage->SetSpacing(destSpacing);
417 destImage->SetOrigin(destOrigin);
418 destImage->SetDirection(destDirection);
419 // propagate vector length info
421}
422
423
435template <unsigned int D1, unsigned int D2>
437{
438public:
439 virtual void
440 operator()(ImageBase<D1> * destImage, const ImageBase<D2> * srcImage) const
441 {
442 using ComparisonType = typename BinaryUnsignedIntDispatch<D1, D2>::ComparisonType;
443 ImageToImageFilterDefaultCopyInformation<D1, D2>(ComparisonType(), destImage, srcImage);
444 }
445
446 virtual ~ImageInformationCopier() = default;
447};
448
449
450} // namespace itk::ImageToImageFilterDetail
451
452#endif
Base class for templated image classes.
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 > &)
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