24 #include "itkImageRegionConstIterator.h"
25 #include "itkImageRegionIteratorWithIndex.h"
30 : m_ClippingGeometry(nullptr),
31 m_ClipPartAboveGeometry(true),
33 m_AutoOutsideValue(false),
34 m_LabelBothSides(false),
35 m_AutoOrientLabels(false),
36 m_AboveGeometryLabel(1),
37 m_BelowGeometryLabel(2)
39 this->SetNumberOfIndexedInputs(2);
40 this->SetNumberOfRequiredInputs(2);
52 m_TimeClippingGeometry = timeClippingGeometry;
58 if (aClippingGeometry != m_ClippingGeometry.GetPointer())
60 m_ClippingGeometry = aClippingGeometry;
61 m_ClippingGeometryData->SetGeometry(const_cast<mitk::BaseGeometry *>(aClippingGeometry));
62 SetNthInput(1, m_ClippingGeometryData);
69 return m_ClippingGeometry;
74 return m_TimeClippingGeometry;
79 Superclass::GenerateInputRequestedRegion();
83 if ((output->
IsInitialized() ==
false) || (m_ClippingGeometry.IsNull()))
96 if ((output->IsInitialized()) && (this->GetMTime() <= m_TimeOfHeaderInitialization.GetMTime()))
99 itkDebugMacro(<<
"GenerateOutputInformation()");
102 auto tmpDimensions =
new unsigned int[input->GetDimension()];
104 for (i = 0; i < input->GetDimension(); ++i)
105 tmpDimensions[i] = input->GetDimension(i);
107 output->Initialize(input->GetPixelType(), input->GetDimension(), tmpDimensions, input->GetNumberOfChannels());
109 delete[] tmpDimensions;
111 output->SetGeometry(static_cast<mitk::BaseGeometry *>(input->GetGeometry()->Clone().GetPointer()));
113 output->SetPropertyList(input->GetPropertyList()->Clone());
115 m_TimeOfHeaderInitialization.Modified();
118 template <
typename TPixel,
unsigned int VImageDimension>
119 void mitk::_InternalComputeClippedImage(itk::Image<TPixel, VImageDimension> *inputItkImage,
123 typedef itk::Image<TPixel, VImageDimension> ItkInputImageType;
124 typedef itk::Image<TPixel, VImageDimension> ItkOutputImageType;
126 typedef itk::ImageRegionConstIteratorWithIndex<ItkInputImageType> ItkInputImageIteratorType;
127 typedef itk::ImageRegionIteratorWithIndex<ItkOutputImageType> ItkOutputImageIteratorType;
131 outputimagetoitk->Update();
135 typename ItkInputImageType::RegionType inputRegionOfInterest = inputItkImage->GetLargestPossibleRegion();
136 ItkInputImageIteratorType inputIt(inputItkImage, inputRegionOfInterest);
137 ItkOutputImageIteratorType outputIt(outputItkImage, inputRegionOfInterest);
149 int i, dim = IndexType::GetIndexDimension();
158 if (clippingPlaneGeometry->
IsAbove(pointInMM) != above)
162 MITK_INFO << leftMostPoint <<
" is BELOW geometry. Inverting meaning of above" << std::endl;
165 MITK_INFO << leftMostPoint <<
" is above geometry" << std::endl;
173 for (inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt, ++outputIt)
177 outputIt.Set(outsideValue);
181 for (i = 0; i < dim; ++i)
183 inputGeometry->IndexToWorld(indexPt, pointInMM);
184 if (clippingPlaneGeometry->
IsAbove(pointInMM) == above)
187 outputIt.Set(aboveLabel);
189 outputIt.Set(outsideValue);
194 outputIt.Set(belowLabel);
196 outputIt.Set(inputIt.Get());
209 if ((output->IsInitialized() ==
false) || (m_ClippingGeometry.IsNull()))
212 const PlaneGeometry *clippingGeometryOfCurrentTimeStep =
nullptr;
214 if (m_TimeClippingGeometry.IsNull())
216 clippingGeometryOfCurrentTimeStep =
dynamic_cast<const PlaneGeometry *
>(m_ClippingGeometry.GetPointer());
220 clippingGeometryOfCurrentTimeStep =
221 dynamic_cast<const PlaneGeometry *
>(m_TimeClippingGeometry->GetGeometryForTimeStep(0).GetPointer());
224 if (clippingGeometryOfCurrentTimeStep ==
nullptr)
227 m_InputTimeSelector->SetInput(input);
228 m_OutputTimeSelector->SetInput(this->GetOutput());
236 int tstart = outputRegion.GetIndex(3);
237 int tmax = tstart + outputRegion.GetSize(3);
240 for (t = tstart; t < tmax; ++t)
245 m_InputTimeSelector->SetTimeNr(timestep);
246 m_InputTimeSelector->UpdateLargestPossibleRegion();
247 m_OutputTimeSelector->SetTimeNr(t);
248 m_OutputTimeSelector->UpdateLargestPossibleRegion();
250 if (m_TimeClippingGeometry.IsNotNull())
252 timestep = m_TimeClippingGeometry->TimePointToTimeStep(timeInMS);
253 if (m_TimeClippingGeometry->IsValidTimeStep(timestep) ==
false)
256 clippingGeometryOfCurrentTimeStep =
257 dynamic_cast<const PlaneGeometry *
>(m_TimeClippingGeometry->GetGeometryForTimeStep(timestep).GetPointer());
261 m_InputTimeSelector->GetOutput(), _InternalComputeClippedImage,
this, clippingGeometryOfCurrentTimeStep);
264 m_TimeOfHeaderInitialization.Modified();
virtual void SetRequestedRegionToLargestPossibleRegion() override
virtual void GenerateOutputInformation() override
ScalarType m_OutsideValue
itk::SmartPointer< Self > Pointer
mitk::ImageTimeSelector::Pointer m_InputTimeSelector
virtual ScalarType GetBelowGeometryLabel() const
const mitk::BaseGeometry * GetClippingGeometry() const
virtual void GenerateData() override
A version of GenerateData() specific for image processing filters.
bool m_ClipPartAboveGeometry
GeometryClipImageFilter()
mitk::ImageTimeSelector::Pointer m_OutputTimeSelector
void SetClippingGeometry(const mitk::BaseGeometry *aClippingGeometry)
virtual bool IsAbove(const Point3D &pt3d_mm, bool considerBoundingBox=false) const
Calculates, whether a point is below or above the plane. There are two different calculation methods...
mitk::GeometryData::Pointer m_ClippingGeometryData
const mitk::TimeGeometry * GetClippingTimeGeometry() const
itk::ImageRegion< RegionDimension > RegionType
virtual TimeStepType TimePointToTimeStep(TimePointType timePoint) const =0
Converts a time point to the corresponding time step.
Image class for storing images.
virtual TimePointType TimeStepToTimePoint(TimeStepType timeStep) const =0
Converts a time step to a time point.
virtual bool GetLabelBothSides() const
virtual void GenerateInputRequestedRegion() override
void GenerateTimeInInputRegion(const mitk::TimeGeometry *outputTimeGeometry, const TOutputRegion &outputRegion, const mitk::TimeGeometry *inputTimeGeometry, TInputRegion &inputRegion)
~GeometryClipImageFilter()
virtual ScalarType GetAboveGeometryLabel() const
virtual BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const =0
Returns the geometry which corresponds to the given time step.
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
virtual bool GetAutoOrientLabels() const
Describes a two-dimensional, rectangular plane.
#define AccessByItk_2(mitkImage, itkImageTypeFunction, arg1, arg2)
BaseGeometry Describes the geometry of a data object.
Filter for clipping an image with a PlaneGeometry.