Medical Imaging Interaction Toolkit  2018.4.99-e1268d66
Medical Imaging Interaction Toolkit
mitkConvert2Dto3DImageFilter.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include "mitkImageAccessByItk.h"
15 #include "mitkImageCast.h"
16 
18 {
19 }
20 
22 {
23 }
24 
26 {
27  mitk::Image::ConstPointer inputImage = this->GetInput();
28  mitk::Image::Pointer resultImage = this->GetOutput();
29 
30  AccessFixedDimensionByItk_1(inputImage, ItkConvert2DTo3D, 2, resultImage);
31 
32  resultImage->SetGeometry(inputImage->GetGeometry());
33 }
34 
35 template <typename TPixel, unsigned int VImageDimension>
36 void mitk::Convert2Dto3DImageFilter::ItkConvert2DTo3D(const itk::Image<TPixel, VImageDimension> *itkImage,
37  mitk::Image::Pointer &mitkImage)
38 {
39  typedef itk::Image<TPixel, 3> itkImageType3D;
40  typedef typename itkImageType3D::SizeType::SizeValueType sizeValType;
41 
42  // Create a new ITK image
43  typename itkImageType3D::Pointer outputImage = itkImageType3D::New();
44  typename itkImageType3D::RegionType myRegion;
45  typename itkImageType3D::SizeType mySize;
46  typename itkImageType3D::IndexType myIndex;
47  typename itkImageType3D::SpacingType mySpacing;
48  mySpacing[0] = itkImage->GetSpacing()[0];
49  mySpacing[1] = itkImage->GetSpacing()[1];
50  mySpacing[2] = 1;
51  myIndex[0] = 0;
52  myIndex[1] = 0;
53  myIndex[2] = 0;
54  mySize[0] = itkImage->GetLargestPossibleRegion().GetSize()[0];
55  mySize[1] = itkImage->GetLargestPossibleRegion().GetSize()[1];
56  mySize[2] = 1;
57  myRegion.SetSize(mySize);
58  myRegion.SetIndex(myIndex);
59  outputImage->SetSpacing(mySpacing);
60  outputImage->SetRegions(myRegion);
61  outputImage->Allocate();
62 
63  // Copy Values:
64  for (sizeValType x = 0; x < mySize[0]; x++)
65  {
66  for (sizeValType y = 0; y < mySize[1]; y++)
67  {
68  itk::Index<2> index2D;
69  index2D[0] = x;
70  index2D[1] = y;
71 
72  itk::Index<3> index3D;
73  index3D[0] = x;
74  index3D[1] = y;
75  index3D[2] = 0;
76 
77  outputImage->SetPixel(index3D, itkImage->GetPixel(index2D));
78  }
79  }
80 
81  mitk::CastToMitkImage(outputImage, mitkImage);
82 }
void ItkConvert2DTo3D(const itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer &mitkImage)
Make a 2D image to a 3D image.
void GenerateData() override
Method generating the output of this filter. Called in the updated process of the pipeline...
~Convert2Dto3DImageFilter() override
standard destructor
InputImageType * GetInput(void)
#define AccessFixedDimensionByItk_1(mitkImage, itkImageTypeFunction, dimension, arg1)
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
Definition: mitkImageCast.h:74
OutputType * GetOutput()
Get the output data of this image source object.