18 #include <vtkGeneralTransform.h> 19 #include <vtkImageChangeInformation.h> 20 #include <vtkImageData.h> 21 #include <vtkImageExtractComponents.h> 22 #include <vtkLinearTransform.h> 26 if (reslicer ==
nullptr)
28 m_Reslicer = vtkSmartPointer<vtkImageReslice>::New();
38 m_ResliceTransform =
nullptr;
52 m_ResliceTransform =
nullptr;
72 double widthInMM, heightInMM;
83 Point3D sliceOrigin = sliceGeometry->GetOrigin();
85 auto abstractGeometry =
90 if (abstractGeometry !=
nullptr)
92 extent[0] = abstractGeometry->GetParametricExtent(0);
93 extent[1] = abstractGeometry->GetParametricExtent(1);
95 widthInMM = abstractGeometry->GetParametricExtentInMM(0);
96 heightInMM = abstractGeometry->GetParametricExtentInMM(1);
98 right = abstractGeometry->GetPlane()->GetAxisVector(0);
99 bottom = abstractGeometry->GetPlane()->GetAxisVector(1);
103 if (planeGeometry !=
nullptr)
106 right = planeGeometry->GetAxisVector(0);
107 bottom = planeGeometry->GetAxisVector(1);
119 const TimeGeometry *inputTimeGeometry = input->GetTimeGeometry();
120 if ((inputTimeGeometry ==
nullptr) || (inputTimeGeometry->
CountTimeSteps() <= 0))
122 itkWarningMacro(<<
"Error reading input image TimeGeometry.");
130 Vector3D rightInIndex, bottomInIndex;
133 extent[0] = rightInIndex.GetNorm();
134 extent[1] = bottomInIndex.GetNorm();
144 mitkThrow()<<
"mitk::ExtractSliceFilter: No fitting geometry for reslice axis!";
156 int xMin, xMax, yMin, yMax;
159 xMax =
static_cast<int>(extent[0]);
160 yMax =
static_cast<int>(extent[1]);
164 double sliceBounds[6];
165 for (
auto &sliceBound : sliceBounds)
185 sliceGeometry->ImageGeometryOn();
193 Vector3D axis0 = sliceGeometry->GetAxisVector(0);
194 Vector3D axis1 = sliceGeometry->GetAxisVector(1);
201 sliceGeometry->SetOrigin(sliceOrigin);
208 boundsCopy[0] = boundsCopy[2] = boundsCopy[4] = 0;
210 boundsCopy[1] = xMax - xMin;
211 boundsCopy[3] = yMax - yMin;
212 sliceGeometry->SetBounds(boundsCopy);
214 sliceGeometry->Modified();
217 output->Initialize(input->GetPixelType(), 2, *sliceGeometry);
235 input->SetRequestedRegionToLargestPossibleRegion();
249 MITK_ERROR <<
"mitk::ExtractSliceFilter: No input image available. Please set the input!" << std::endl;
250 itkExceptionMacro(
"mitk::ExtractSliceFilter: No input image available. Please set the input!");
256 MITK_ERROR <<
"mitk::ExtractSliceFilter: No Geometry for reslicing available." << std::endl;
257 itkExceptionMacro(
"mitk::ExtractSliceFilter: No Geometry for reslicing available.");
262 if ((inputTimeGeometry ==
nullptr) || (inputTimeGeometry->
CountTimeSteps() <= 0))
264 itkWarningMacro(<<
"Error reading input image TimeGeometry.");
271 itkWarningMacro(<<
"This is not a valid timestep: " <<
m_TimeStep);
278 itkWarningMacro(<<
"No volume data existent at given timestep " <<
m_TimeStep);
290 const auto *abstractGeometry =
293 if (abstractGeometry !=
nullptr)
295 m_ResliceTransform = abstractGeometry;
297 origin = abstractGeometry->GetPlane()->GetOrigin();
299 normal = abstractGeometry->GetPlane()->GetNormal();
304 vtkSmartPointer<vtkGeneralTransform> composedResliceTransform = vtkSmartPointer<vtkGeneralTransform>::New();
305 composedResliceTransform->Identity();
306 composedResliceTransform->Concatenate(
308 composedResliceTransform->Concatenate(abstractGeometry->GetVtkAbstractTransform());
310 m_Reslicer->SetResliceTransform(composedResliceTransform);
319 if (planeGeometry !=
nullptr)
323 origin = planeGeometry->GetOrigin();
324 normal = planeGeometry->GetNormal();
340 if (m_ResliceTransform.IsNotNull())
341 m_Reslicer->SetResliceTransform(m_ResliceTransform->GetVtkTransform()->GetLinearInverse());
350 itkExceptionMacro(
"mitk::ExtractSliceFilter: No fitting geometry for reslice axis!");
355 if (m_ResliceTransform.IsNotNull())
360 vtkSmartPointer<vtkImageChangeInformation> unitSpacingImageFilter =
361 vtkSmartPointer<vtkImageChangeInformation>::New();
362 unitSpacingImageFilter->ReleaseDataFlagOn();
364 unitSpacingImageFilter->SetOutputSpacing(1.0, 1.0, 1.0);
367 m_Reslicer->SetInputConnection(unitSpacingImageFilter->GetOutputPort());
378 double originInVtk[3];
380 m_Reslicer->SetResliceAxesOrigin(originInVtk);
389 vnl2vtk(m_Right.GetVnlVector(), cosines);
391 vnl2vtk(m_Bottom.GetVnlVector(), cosines + 3);
393 vnl2vtk(normal.GetVnlVector(), cosines + 6);
395 m_Reslicer->SetResliceAxesDirectionCosines(cosines);
404 m_Reslicer->SetInterpolationModeToNearestNeighbor();
414 m_Reslicer->SetInterpolationModeToNearestNeighbor();
447 auto reslicedImage = vtkSmartPointer<vtkImageData>::New();
450 if (
nullptr == reslicedImage)
452 itkWarningMacro(<<
"Reslicer returned empty image");
457 int numberOfScalarComponent = reslicedImage->GetNumberOfScalarComponents();
458 if (numberOfScalarComponent > 1 && static_cast<unsigned int>(numberOfScalarComponent) >=
m_Component)
461 auto vectorComponentExtractor = vtkSmartPointer<vtkImageExtractComponents>::New();
462 vectorComponentExtractor->SetInputData(reslicedImage);
463 vectorComponentExtractor->SetComponents(
m_Component);
464 vectorComponentExtractor->Update();
466 reslicedImage = vectorComponentExtractor->GetOutput();
478 if (reslicedImage->GetDataDimension() == 1)
482 resultImage->Initialize(reslicedImage, 1, -1, -1, 1);
486 resultImage->Initialize(reslicedImage);
490 resultImage->SetVolume(reslicedImage->GetScalarPointer());
494 resultImage->SetGeometry(resultGeometry);
virtual TimeStepType CountTimeSteps() const =0
Returns the number of time steps.
static bool CalculateClippedPlaneBounds(const BaseGeometry *boundingGeometry, const PlaneGeometry *planeGeometry, double *bounds)
Calculate the bounding box of the resliced image. This is necessary for arbitrarily rotated planes in...
bool IsVolumeSet(int t=0, int n=0) const override
Check whether volume at time t in channel n is set.
ScalarType GetExtent(unsigned int direction) const
Set the time bounds (in ms)
virtual vtkImageData * GetVtkImageData(int t=0, int n=0)
Get a volume at a specific time t of channel n as a vtkImageData.
ScalarType GetExtentInMM(int direction) const
Get the extent of the bounding-box in the specified direction in mm.
const BaseGeometry * GetReferenceGeometry() const
Get the geometrical frame of reference for this PlaneGeometry.
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
void vnl2vtk(const vnl_vector< Tin > &in, Tout *out)
Image class for storing images.
void itk2vtk(const Tin &in, Tout &out)
InputImageType * GetInput(void)
virtual BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const =0
Returns the geometry which corresponds to the given time step.
OutputType * GetOutput()
Get the output data of this image source object.
Describes a two-dimensional, rectangular plane.
virtual bool IsValidTimeStep(TimeStepType timeStep) const =0
Test for the given time step if a geometry is availible.
BaseGeometry Describes the geometry of a data object.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
BoundingBoxType::BoundsArrayType BoundsArrayType