Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkExtractSliceFilter.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkExtractSliceFilter_h
14 #define mitkExtractSliceFilter_h
15 
16 #include <MitkCoreExports.h>
17 #include <mitkImageToImageFilter.h>
18 
19 #include <vtkAbstractTransform.h>
20 #include <vtkImageData.h>
21 #include <vtkImageReslice.h>
22 #include <vtkMatrix4x4.h>
23 #include <vtkPoints.h>
24 #include <vtkSmartPointer.h>
25 #include <vtkTransform.h>
26 
27 namespace mitk
28 {
64  {
65  public:
67  itkFactorylessNewMacro(Self);
68  itkCloneMacro(Self);
69 
70  mitkNewMacro1Param(Self, vtkImageReslice *);
71 
77  void SetWorldGeometry(const PlaneGeometry *geometry)
78  {
79  if (geometry != m_WorldGeometry)
80  {
81  this->m_WorldGeometry = geometry;
82  this->Modified();
83  }
84  }
85 
91  void SetTimeStep(unsigned int timestep) { m_TimeStep = timestep; }
92 
98  unsigned int GetTimeStep() { return m_TimeStep; }
99 
105  void SetComponent(unsigned int component) { m_Component = component; }
106 
114  void SetResliceTransformByGeometry(const BaseGeometry *transform) { this->m_ResliceTransform = transform; }
115 
122  void SetInPlaneResampleExtentByGeometry(bool inPlaneResampleExtentByGeometry)
123  {
124  this->m_InPlaneResampleExtentByGeometry = inPlaneResampleExtentByGeometry;
125  }
126 
132  void SetOutputDimensionality(unsigned int dimension) { this->m_OutputDimension = dimension; }
133 
141  void SetOutputSpacingZDirection(double zSpacing) { this->m_ZSpacing = zSpacing; }
142 
151  void SetOutputExtentZDirection(int zMin, int zMax)
152  {
153  this->m_ZMin = zMin;
154  this->m_ZMax = zMax;
155  }
156 
168  bool GetClippedPlaneBounds(double bounds[6]);
169 
178  bool GetClippedPlaneBounds(const BaseGeometry *boundingGeometry,
179  const PlaneGeometry *planeGeometry,
180  double *bounds);
181 
188 
197  vtkImageData *GetVtkOutput()
198  {
199  m_VtkOutputRequested = true;
200  return m_Reslicer->GetOutput();
201  }
202 
213  void SetVtkOutputRequest(bool isRequested) { m_VtkOutputRequested = isRequested; }
214 
222  vtkMatrix4x4 *GetResliceAxes() { return this->m_Reslicer->GetResliceAxes(); }
223 
229  void SetBackgroundLevel(double backgroundLevel) { m_BackgroundLevel = backgroundLevel; }
231  {
232  RESLICE_NEAREST = 0,
233  RESLICE_LINEAR = 1,
234  RESLICE_CUBIC = 3
235  };
236 
243  {
244  this->m_InterpolationMode = interpolation;
245  }
246 
247  protected:
253  ExtractSliceFilter(vtkImageReslice *reslicer = nullptr);
254 
257 
259  void GenerateData() override;
260 
262  void GenerateOutputInformation() override;
263 
266 
267  PlaneGeometry::ConstPointer m_WorldGeometry;
269 
270  unsigned int m_TimeStep;
271 
272  unsigned int m_OutputDimension;
273 
274  double m_ZSpacing;
275 
276  int m_ZMin;
277 
278  int m_ZMax;
279 
281 
282  bool m_InPlaneResampleExtentByGeometry; // Resampling grid corresponds to: false->image true->worldgeometry
283 
285 
287 
289 
290  unsigned int m_Component;
291 
292  private:
293  BaseGeometry::ConstPointer m_ResliceTransform;
294  /* Axis vectors of the relevant geometry. Set in GenerateOutputInformation() and also used in GenerateData().*/
295  Vector3D m_Right, m_Bottom;
296  /* Bounds of the relevant plane. Set in GenerateOutputInformation() and also used in GenerateData().*/
297  int m_XMin, m_XMax, m_YMin, m_YMax;
298 
299  };
300 }
301 
302 #endif
#define MITKCORE_EXPORT
Abstract base class describing the geometry of a data object.
ExtractSliceFilter extracts a 2D arbitrary oriented slice from a 3D volume.
void SetTimeStep(unsigned int timestep)
Set the time step in the 4D volume.
ResliceInterpolation m_InterpolationMode
void SetOutputSpacingZDirection(double zSpacing)
Set the spacing in z direction manually.
PlaneGeometry::ConstPointer m_WorldGeometry
void SetInterpolationMode(ExtractSliceFilter::ResliceInterpolation interpolation)
Set the interpolation mode for reslicing.
unsigned int GetTimeStep()
Get the current time step.
void SetOutputExtentZDirection(int zMin, int zMax)
Set the extent in pixels for the z direction manually.
vtkMatrix4x4 * GetResliceAxes()
Get the reslice axes matrix.
bool GetClippedPlaneBounds(double bounds[6])
Get the bounding box of the slice [xMin, xMax, yMin, yMax, zMin, zMax].
void SetComponent(unsigned int component)
Set the component of a multi-component image to be extracted.
mitk::ScalarType * m_OutPutSpacing
mitkNewMacro1Param(Self, vtkImageReslice *)
mitkClassMacro(ExtractSliceFilter, ImageToImageFilter)
ExtractSliceFilter(vtkImageReslice *reslicer=nullptr)
Constructor.
vtkSmartPointer< vtkImageReslice > m_Reslicer
void SetVtkOutputRequest(bool isRequested)
Set VtkOutputRequest to suppress the conversion of the image.
void GenerateOutputInformation() override
Compute output information (spacing, origin, extent) based on input and world geometry.
bool GetClippedPlaneBounds(const BaseGeometry *boundingGeometry, const PlaneGeometry *planeGeometry, double *bounds)
Get the bounding box of the slice [xMin, xMax, yMin, yMax, zMin, zMax].
void GenerateInputRequestedRegion() override
Set the requested region on the input image.
void SetOutputDimensionality(unsigned int dimension)
Set the output dimensionality of the slice.
vtkImageData * GetVtkOutput()
Get the output as vtkImageData.
void SetBackgroundLevel(double backgroundLevel)
Set the background level for areas outside the volume.
void SetInPlaneResampleExtentByGeometry(bool inPlaneResampleExtentByGeometry)
Set whether the resampling grid is derived from image or world geometry.
void SetWorldGeometry(const PlaneGeometry *geometry)
Set the plane geometry defining the reslice axis.
mitk::ScalarType * GetOutputSpacing()
Get the spacing of the slice.
void SetResliceTransformByGeometry(const BaseGeometry *transform)
Set a transform for the reslice axes.
~ExtractSliceFilter() override
Destructor.
void GenerateData() override
Perform the actual reslicing.
Superclass of all classes having one or more Images as input and generating Images as output.
Describes the geometry of a plane object.
Find image slices visible on a given plane.
double ScalarType
Scalar type used throughout MITK for geometric computations.