Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "mitkImageAccessByItk.h"
19 #include "mitkImageCast.h"
20 
22 {
23 }
24 
26 {
27 }
28 
30 {
31  mitk::Image::ConstPointer inputImage = this->GetInput();
32  mitk::Image::Pointer resultImage = this->GetOutput();
33 
34  AccessFixedDimensionByItk_1(inputImage, ItkConvert2DTo3D, 2, resultImage);
35 
36  resultImage->SetGeometry(inputImage->GetGeometry());
37 }
38 
39 template <typename TPixel, unsigned int VImageDimension>
40 void mitk::Convert2Dto3DImageFilter::ItkConvert2DTo3D(const itk::Image<TPixel, VImageDimension> *itkImage,
41  mitk::Image::Pointer &mitkImage)
42 {
43  typedef itk::Image<TPixel, 3> itkImageType3D;
44  typedef typename itkImageType3D::SizeType::SizeValueType sizeValType;
45 
46  // Create a new ITK image
47  typename itkImageType3D::Pointer outputImage = itkImageType3D::New();
48  typename itkImageType3D::RegionType myRegion;
49  typename itkImageType3D::SizeType mySize;
50  typename itkImageType3D::IndexType myIndex;
51  typename itkImageType3D::SpacingType mySpacing;
52  mySpacing[0] = itkImage->GetSpacing()[0];
53  mySpacing[1] = itkImage->GetSpacing()[1];
54  mySpacing[2] = 1;
55  myIndex[0] = 0;
56  myIndex[1] = 0;
57  myIndex[2] = 0;
58  mySize[0] = itkImage->GetLargestPossibleRegion().GetSize()[0];
59  mySize[1] = itkImage->GetLargestPossibleRegion().GetSize()[1];
60  mySize[2] = 1;
61  myRegion.SetSize(mySize);
62  myRegion.SetIndex(myIndex);
63  outputImage->SetSpacing(mySpacing);
64  outputImage->SetRegions(myRegion);
65  outputImage->Allocate();
66 
67  // Copy Values:
68  for (sizeValType x = 0; x < mySize[0]; x++)
69  {
70  for (sizeValType y = 0; y < mySize[1]; y++)
71  {
72  itk::Index<2> index2D;
73  index2D[0] = x;
74  index2D[1] = y;
75 
76  itk::Index<3> index3D;
77  index3D[0] = x;
78  index3D[1] = y;
79  index3D[2] = 0;
80 
81  outputImage->SetPixel(index3D, itkImage->GetPixel(index2D));
82  }
83  }
84 
85  mitk::CastToMitkImage(outputImage, mitkImage);
86 }
itk::SmartPointer< Self > Pointer
void ItkConvert2DTo3D(const itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer &mitkImage)
Make a 2D image to a 3D image.
virtual void GenerateData() override
Method generating the output of this filter. Called in the updated process of the pipeline...
#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:78
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.