14 #include "itkImageRegionIterator.h" 21 : m_CurrentWorldPlaneGeometry(nullptr), m_ImageGeometry(nullptr), m_ActualInputTimestep(0)
23 MITK_WARN <<
"Class ExtractDirectedPlaneImageFilterNew is deprecated! Use ExtractSliceFilter instead.";
36 MITK_ERROR <<
"mitk::ExtractDirectedPlaneImageFilterNew: No input available. Please set the input!" << std::endl;
37 itkExceptionMacro(
"mitk::ExtractDirectedPlaneImageFilterNew: No input available. Please set the input!");
41 m_ImageGeometry = inputImage->GetGeometry();
46 if (inputImage->GetDimension() > 4 || inputImage->GetDimension() < 2)
48 MITK_ERROR <<
"mitk::ExtractDirectedPlaneImageFilterNew:GenerateData works only with 3D and 3D+t images, sorry." 50 itkExceptionMacro(
"mitk::ExtractDirectedPlaneImageFilterNew works only with 3D and 3D+t images, sorry.");
53 else if (inputImage->GetDimension() == 4)
56 timeselector->SetInput(inputImage);
57 timeselector->SetTimeNr(m_ActualInputTimestep);
58 timeselector->UpdateLargestPossibleRegion();
59 inputImage = timeselector->GetOutput();
61 else if (inputImage->GetDimension() == 2)
64 resultImage =
const_cast<mitk::Image *
>(inputImage.GetPointer());
65 ImageToImageFilter::SetNthOutput(0, resultImage);
69 if (!m_CurrentWorldPlaneGeometry)
71 MITK_ERROR <<
"mitk::ExtractDirectedPlaneImageFilterNew::GenerateData has no CurrentWorldPlaneGeometry set" 81 Superclass::GenerateOutputInformation();
90 template <
typename TPixel,
unsigned int VImageDimension>
91 void mitk::ExtractDirectedPlaneImageFilterNew::ItkSliceExtraction(
const itk::Image<TPixel, VImageDimension> *inputImage)
94 typedef itk::Image<TPixel, VImageDimension - 1> SliceImageType;
96 typedef itk::ImageRegionConstIterator<SliceImageType> SliceIterator;
99 typename SliceImageType::Pointer resultSlice = SliceImageType::New();
101 typename SliceImageType::IndexType start;
112 float minSpacing = newPixelSpacing[0];
113 for (
unsigned int i = 1; i < newPixelSpacing.Size(); i++)
115 if (newPixelSpacing[i] < minSpacing)
117 minSpacing = newPixelSpacing[i];
121 newPixelSpacing[0] = 0.5 * minSpacing;
122 newPixelSpacing[1] = 0.5 * minSpacing;
123 newPixelSpacing[2] = 0.5 * minSpacing;
125 float pixelSpacing[2];
126 pixelSpacing[0] = newPixelSpacing[0];
127 pixelSpacing[1] = newPixelSpacing[1];
130 typename SliceImageType::SizeType size;
132 extentInMM[0] = m_CurrentWorldPlaneGeometry->
GetExtentInMM(0);
133 extentInMM[1] = m_CurrentWorldPlaneGeometry->
GetExtentInMM(1);
136 double maxExtent = sqrt(extentInMM[0] * extentInMM[0] + extentInMM[1] * extentInMM[1]);
137 unsigned int xTranlation = (maxExtent - extentInMM[0]);
138 unsigned int yTranlation = (maxExtent - extentInMM[1]);
139 size[0] = (maxExtent + xTranlation) / newPixelSpacing[0];
140 size[1] = (maxExtent + yTranlation) / newPixelSpacing[1];
143 typename SliceImageType::RegionType region;
145 region.SetSize(size);
146 region.SetIndex(start);
149 resultSlice->SetRegions(region);
150 resultSlice->SetSpacing(pixelSpacing);
151 resultSlice->Allocate();
162 origin[0] -= xTranlation * right[0] + yTranlation * bottom[0];
163 origin[1] -= xTranlation * right[1] + yTranlation * bottom[1];
164 origin[2] -= xTranlation * right[2] + yTranlation * bottom[2];
169 newSliceGeometryTest->ChangeImageGeometryConsideringOriginOffset(
true);
172 newSliceGeometryTest->GetIndexToWorldTransform()->SetMatrix(
176 newSliceGeometryTest->SetOrigin(origin);
177 ScalarType bounds[6] = {0,
static_cast<ScalarType>(size[0]), 0, static_cast<ScalarType>(size[1]), 0, 1};
178 newSliceGeometryTest->SetBounds(bounds);
179 newSliceGeometryTest->SetSpacing(newPixelSpacing);
180 newSliceGeometryTest->Modified();
183 itk::MatrixOffsetTransformBase<mitk::ScalarType, 3, 3>::MatrixType tempTransform =
184 newSliceGeometryTest->GetIndexToWorldTransform()->GetMatrix();
193 Point3D currentSliceIndexPointIn2D;
194 Point3D currentImageWorldPointIn3D;
197 SliceIterator sliceIterator(resultSlice, resultSlice->GetLargestPossibleRegion());
198 sliceIterator.GoToBegin();
200 while (!sliceIterator.IsAtEnd())
206 currentSliceIndexPointIn2D[0] = sliceIterator.GetIndex()[0] + 0.5;
207 currentSliceIndexPointIn2D[1] = sliceIterator.GetIndex()[1] + 0.5;
208 currentSliceIndexPointIn2D[2] = 0;
210 newSliceGeometryTest->IndexToWorld(currentSliceIndexPointIn2D, currentImageWorldPointIn3D);
212 m_ImageGeometry->
WorldToIndex(currentImageWorldPointIn3D, inputIndex);
216 resultSlice->SetPixel(sliceIterator.GetIndex(), inputImage->GetPixel(inputIndex));
220 resultSlice->SetPixel(sliceIterator.GetIndex(), 0);
228 resultImage->SetClonedGeometry(newSliceGeometryTest);
230 resultImage->GetGeometry()->GetIndexToWorldTransform()->SetMatrix(tempTransform);
Vector3D GetAxisVector(unsigned int direction) const
Get vector along bounding-box in the specified direction in mm.
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
bool IsIndexInside(const mitk::Point3D &index) const
Test whether the point p ((continous!)index coordinates in units) is inside the bounding box...
ScalarType GetExtentInMM(int direction) const
Get the extent of the bounding-box in the specified direction in mm.
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.
mitk::Image InputImageType
Image class for storing images.
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
void WorldToIndex(const mitk::Point3D &pt_mm, mitk::Point3D &pt_units) const
Convert world coordinates (in mm) of a point to (continuous!) index coordinates.
InputImageType * GetInput(void)
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
OutputType * GetOutput()
Get the output data of this image source object.
BaseGeometry Describes the geometry of a data object.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.