18 #include "itkImageRegionIterator.h"
25 : m_CurrentWorldPlaneGeometry(nullptr), m_ActualInputTimestep(0)
27 MITK_WARN <<
"Class ExtractDirectedPlaneImageFilterNew is deprecated! Use ExtractSliceFilter instead.";
40 MITK_ERROR <<
"mitk::ExtractDirectedPlaneImageFilterNew: No input available. Please set the input!" << std::endl;
41 itkExceptionMacro(
"mitk::ExtractDirectedPlaneImageFilterNew: No input available. Please set the input!");
45 m_ImageGeometry = inputImage->GetGeometry();
50 if (inputImage->GetDimension() > 4 || inputImage->GetDimension() < 2)
52 MITK_ERROR <<
"mitk::ExtractDirectedPlaneImageFilterNew:GenerateData works only with 3D and 3D+t images, sorry."
54 itkExceptionMacro(
"mitk::ExtractDirectedPlaneImageFilterNew works only with 3D and 3D+t images, sorry.");
57 else if (inputImage->GetDimension() == 4)
60 timeselector->SetInput(inputImage);
61 timeselector->SetTimeNr(m_ActualInputTimestep);
62 timeselector->UpdateLargestPossibleRegion();
63 inputImage = timeselector->GetOutput();
65 else if (inputImage->GetDimension() == 2)
68 resultImage =
const_cast<mitk::Image *
>(inputImage.GetPointer());
69 ImageToImageFilter::SetNthOutput(0, resultImage);
73 if (!m_CurrentWorldPlaneGeometry)
75 MITK_ERROR <<
"mitk::ExtractDirectedPlaneImageFilterNew::GenerateData has no CurrentWorldPlaneGeometry set"
85 Superclass::GenerateOutputInformation();
94 template <
typename TPixel,
unsigned int VImageDimension>
95 void mitk::ExtractDirectedPlaneImageFilterNew::ItkSliceExtraction(
const itk::Image<TPixel, VImageDimension> *inputImage)
98 typedef itk::Image<TPixel, VImageDimension - 1> SliceImageType;
100 typedef itk::ImageRegionConstIterator<SliceImageType> SliceIterator;
105 typename SliceImageType::IndexType start;
110 Point3D origin = m_CurrentWorldPlaneGeometry->GetOrigin();
111 Vector3D right = m_CurrentWorldPlaneGeometry->GetAxisVector(0);
112 Vector3D bottom = m_CurrentWorldPlaneGeometry->GetAxisVector(1);
115 Vector3D newPixelSpacing = m_ImageGeometry->GetSpacing();
116 float minSpacing = newPixelSpacing[0];
117 for (
unsigned int i = 1; i < newPixelSpacing.Size(); i++)
119 if (newPixelSpacing[i] < minSpacing)
121 minSpacing = newPixelSpacing[i];
125 newPixelSpacing[0] = 0.5 * minSpacing;
126 newPixelSpacing[1] = 0.5 * minSpacing;
127 newPixelSpacing[2] = 0.5 * minSpacing;
129 float pixelSpacing[2];
130 pixelSpacing[0] = newPixelSpacing[0];
131 pixelSpacing[1] = newPixelSpacing[1];
134 typename SliceImageType::SizeType size;
136 extentInMM[0] = m_CurrentWorldPlaneGeometry->GetExtentInMM(0);
137 extentInMM[1] = m_CurrentWorldPlaneGeometry->GetExtentInMM(1);
140 double maxExtent = sqrt(extentInMM[0] * extentInMM[0] + extentInMM[1] * extentInMM[1]);
141 unsigned int xTranlation = (maxExtent - extentInMM[0]);
142 unsigned int yTranlation = (maxExtent - extentInMM[1]);
143 size[0] = (maxExtent + xTranlation) / newPixelSpacing[0];
144 size[1] = (maxExtent + yTranlation) / newPixelSpacing[1];
147 typename SliceImageType::RegionType region;
149 region.SetSize(size);
150 region.SetIndex(start);
153 resultSlice->SetRegions(region);
154 resultSlice->SetSpacing(pixelSpacing);
155 resultSlice->Allocate();
166 origin[0] -= xTranlation * right[0] + yTranlation * bottom[0];
167 origin[1] -= xTranlation * right[1] + yTranlation * bottom[1];
168 origin[2] -= xTranlation * right[2] + yTranlation * bottom[2];
172 dynamic_cast<BaseGeometry *
>(m_CurrentWorldPlaneGeometry->Clone().GetPointer());
173 newSliceGeometryTest->ChangeImageGeometryConsideringOriginOffset(
true);
176 newSliceGeometryTest->GetIndexToWorldTransform()->SetMatrix(
177 m_CurrentWorldPlaneGeometry->GetIndexToWorldTransform()->GetMatrix());
180 newSliceGeometryTest->SetOrigin(origin);
181 ScalarType bounds[6] = {0,
static_cast<ScalarType>(size[0]), 0, static_cast<ScalarType>(size[1]), 0, 1};
182 newSliceGeometryTest->SetBounds(bounds);
183 newSliceGeometryTest->SetSpacing(newPixelSpacing);
184 newSliceGeometryTest->Modified();
187 itk::MatrixOffsetTransformBase<mitk::ScalarType, 3, 3>::MatrixType tempTransform =
188 newSliceGeometryTest->GetIndexToWorldTransform()->GetMatrix();
197 Point3D currentSliceIndexPointIn2D;
198 Point3D currentImageWorldPointIn3D;
199 typename InputImageType::IndexType inputIndex;
201 SliceIterator sliceIterator(resultSlice, resultSlice->GetLargestPossibleRegion());
202 sliceIterator.GoToBegin();
204 while (!sliceIterator.IsAtEnd())
210 currentSliceIndexPointIn2D[0] = sliceIterator.GetIndex()[0] + 0.5;
211 currentSliceIndexPointIn2D[1] = sliceIterator.GetIndex()[1] + 0.5;
212 currentSliceIndexPointIn2D[2] = 0;
214 newSliceGeometryTest->IndexToWorld(currentSliceIndexPointIn2D, currentImageWorldPointIn3D);
216 m_ImageGeometry->WorldToIndex(currentImageWorldPointIn3D, inputIndex);
218 if (m_ImageGeometry->IsIndexInside(inputIndex))
220 resultSlice->SetPixel(sliceIterator.GetIndex(), inputImage->GetPixel(inputIndex));
224 resultSlice->SetPixel(sliceIterator.GetIndex(), 0);
232 resultImage->SetClonedGeometry(newSliceGeometryTest);
234 resultImage->GetGeometry()->GetIndexToWorldTransform()->SetMatrix(tempTransform);
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
itk::SmartPointer< Self > Pointer
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.
Vector< ScalarType, 2 > Vector2D
itk::Image< double, 3 > InputImageType
Image class for storing images.
Point< ScalarType, 3 > Point3D
InputImageType * GetInput(void)
OutputType * GetOutput()
Get the output data of this image source object.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.