23 #include <itkExtractImageFilter.h>
28 : m_SliceIndex(0), m_SliceDimension(0), m_TimeStep(0), m_DirectionCollapseToStrategy(DIRECTIONCOLLAPSETOGUESS)
30 MITK_WARN <<
"Class ExtractImageFilter is deprecated! Use ExtractSliceFilter instead.";
41 if ((input->GetDimension() > 4) || (input->GetDimension() < 2))
43 MITK_ERROR <<
"mitk::ExtractImageFilter:GenerateData works only with 3D and 3D+t images, sorry." << std::endl;
44 itkExceptionMacro(
"mitk::ExtractImageFilter works only with 3D and 3D+t images, sorry.");
47 else if (input->GetDimension() == 4)
50 timeSelector->SetInput(input);
51 timeSelector->SetTimeNr(m_TimeStep);
52 timeSelector->UpdateLargestPossibleRegion();
53 input = timeSelector->GetOutput();
55 else if (input->GetDimension() == 2)
58 resultImage =
const_cast<Image *
>(input.GetPointer());
59 ImageToImageFilter::SetNthOutput(0, resultImage);
63 if (m_SliceDimension >= input->GetDimension())
65 MITK_ERROR <<
"mitk::ExtractImageFilter:GenerateData m_SliceDimension == " << m_SliceDimension
66 <<
" makes no sense with an " << input->GetDimension() <<
"D image." << std::endl;
67 itkExceptionMacro(
"This is not a sensible value for m_SliceDimension.");
75 if (!inputImageGeometry)
77 MITK_ERROR <<
"In ExtractImageFilter::ItkImageProcessing: Input image has no geometry!" << std::endl;
83 switch (m_SliceDimension)
98 planeGeometry->InitializeStandardPlane(inputImageGeometry, orientation, (
ScalarType)m_SliceIndex,
true,
false);
100 planeGeometry->ChangeImageGeometryConsideringOriginOffset(
true);
101 resultImage->SetGeometry(planeGeometry);
104 template <
typename TPixel,
unsigned int VImageDimension>
108 typedef itk::Image<TPixel, VImageDimension> ImageType3D;
109 typedef itk::Image<TPixel, VImageDimension - 1> ImageType2D;
111 typedef itk::ExtractImageFilter<ImageType3D, ImageType2D> ExtractImageFilterType;
112 typename ImageType3D::RegionType inSliceRegion = itkImage->GetLargestPossibleRegion();
114 inSliceRegion.SetSize(m_SliceDimension, 0);
118 typename ExtractImageFilterType::DIRECTIONCOLLAPSESTRATEGY collapseStrategy;
119 switch (m_DirectionCollapseToStrategy)
121 case DIRECTIONCOLLAPSETOUNKOWN:
122 collapseStrategy = ExtractImageFilterType::DIRECTIONCOLLAPSETOUNKOWN;
124 case DIRECTIONCOLLAPSETOIDENTITY:
125 collapseStrategy = ExtractImageFilterType::DIRECTIONCOLLAPSETOIDENTITY;
127 case DIRECTIONCOLLAPSETOSUBMATRIX:
128 collapseStrategy = ExtractImageFilterType::DIRECTIONCOLLAPSETOSUBMATRIX;
130 case DIRECTIONCOLLAPSETOGUESS:
132 collapseStrategy = ExtractImageFilterType::DIRECTIONCOLLAPSETOGUESS;
136 sliceExtractor->SetDirectionCollapseToStrategy(collapseStrategy);
137 sliceExtractor->SetInput(itkImage);
139 inSliceRegion.SetIndex(m_SliceDimension, m_SliceIndex);
141 sliceExtractor->SetExtractionRegion(inSliceRegion);
144 sliceExtractor->UpdateLargestPossibleRegion();
170 Superclass::GenerateInputRequestedRegion();
175 if (input->GetDimension() == 2)
177 input->SetRequestedRegionToLargestPossibleRegion();
182 requestedRegion = output->GetRequestedRegion();
183 requestedRegion.SetIndex(0, 0);
184 requestedRegion.SetIndex(1, 0);
185 requestedRegion.SetIndex(2, 0);
186 requestedRegion.SetSize(0, input->GetDimension(0));
187 requestedRegion.SetSize(1, input->GetDimension(1));
188 requestedRegion.SetSize(2, input->GetDimension(2));
190 requestedRegion.SetIndex(m_SliceDimension, m_SliceIndex);
191 requestedRegion.SetSize(m_SliceDimension, 1);
193 input->SetRequestedRegion(&requestedRegion);
214 if (m_SliceDimension >= input->GetDimension() && input->GetDimension() != 2)
216 MITK_ERROR <<
"mitk::ExtractImageFilter:GenerateOutputInformation m_SliceDimension == " << m_SliceDimension
217 <<
" makes no sense with an " << input->GetDimension() <<
"D image." << std::endl;
218 itkExceptionMacro(
"This is not a sensible value for m_SliceDimension.");
222 unsigned int sliceDimension(m_SliceDimension);
223 if (input->GetDimension() == 2)
228 unsigned int tmpDimensions[2];
230 switch (sliceDimension)
235 tmpDimensions[0] = input->GetDimension(0);
236 tmpDimensions[1] = input->GetDimension(1);
240 tmpDimensions[0] = input->GetDimension(0);
241 tmpDimensions[1] = input->GetDimension(2);
245 tmpDimensions[0] = input->GetDimension(1);
246 tmpDimensions[1] = input->GetDimension(2);
250 output->Initialize(input->GetPixelType(), 2, tmpDimensions, 1 );
262 output->SetPropertyList(input->GetPropertyList()->Clone());
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
itk::ImageRegion< RegionDimension > RegionType
Image class for storing images.
InputImageType * GetInput(void)
OutputType * GetOutput()
Get the output data of this image source object.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
BaseGeometry Describes the geometry of a data object.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.