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