21 #include <itkImageRegionConstIterator.h> 22 #include <itkImageRegionIteratorWithIndex.h> 23 #include <itkImageSliceConstIteratorWithIndex.h> 25 #include <vtkCellLocator.h> 26 #include <vtkPolyData.h> 33 : m_ClippingMode(CLIPPING_MODE_CONSTANT),
34 m_ClippingConstant(0.0),
35 m_MultiplicationFactor(2.0),
37 m_HeightFieldResolutionX(256),
38 m_HeightFieldResolutionY(256),
41 this->SetNumberOfIndexedInputs(8);
42 this->SetNumberOfRequiredInputs(2);
51 this->SetNthInput(1, clippingSurface);
56 if (planeList.size() > 7)
58 MITK_WARN <<
"Only 7 clipping planes are allowed!";
61 for (
unsigned int i = 0; i < planeList.size(); ++i)
63 this->SetNthInput(i + 1, planeList.at(i));
69 return dynamic_cast<const Surface *
>(itk::ProcessObject::GetInput(1));
111 itkDebugMacro(<<
"GenerateOutputInformation()");
114 auto tmpDimensions =
new unsigned int[inputImage->
GetDimension()];
124 delete[] tmpDimensions;
133 template <
typename TPixel,
unsigned int VImageDimension>
135 itk::Image<TPixel, VImageDimension> *inputItkImage,
137 vtkPolyData *clippingPolyData,
140 typedef itk::Image<TPixel, VImageDimension> ItkInputImageType;
141 typedef itk::Image<TPixel, VImageDimension> ItkOutputImageType;
143 typedef itk::ImageSliceConstIteratorWithIndex<ItkInputImageType> ItkInputImageIteratorType;
144 typedef itk::ImageRegionIteratorWithIndex<ItkOutputImageType> ItkOutputImageIteratorType;
148 outputimagetoitk->Update();
150 typename ItkOutputImageType::Pointer outputItkImage = outputimagetoitk->GetOutput();
151 std::vector<double>
test;
154 typename ItkInputImageType::RegionType inputRegionOfInterest = inputItkImage->GetLargestPossibleRegion();
155 ItkInputImageIteratorType inputIt(inputItkImage, inputRegionOfInterest);
156 ItkOutputImageIteratorType outputIt(outputItkImage, inputRegionOfInterest);
159 clippingPolyData->ComputeBounds();
160 double *bounds = clippingPolyData->GetBounds();
162 double xWidth = bounds[1] - bounds[0];
163 double yWidth = bounds[3] - bounds[2];
166 vtkCellLocator *cellLocator = vtkCellLocator::New();
167 cellLocator->SetDataSet(clippingPolyData);
168 cellLocator->CacheCellBoundsOn();
169 cellLocator->AutomaticOn();
170 cellLocator->BuildLocator();
180 MITK_INFO <<
"Calculating Height Field..." << std::endl;
185 double p0[3], p1[3], surfacePoint[3], pcoords[3];
186 p0[0] = bounds[0] + xWidth * x / (double)m_HeightFieldResolutionX;
187 p0[1] = bounds[2] + yWidth * y / (double)m_HeightFieldResolutionY;
196 if (cellLocator->IntersectWithLine(p0, p1, 0.1, t, surfacePoint, pcoords, subId))
204 heightField[y * m_HeightFieldResolutionX + x] = distance;
205 itk::Image<double, 2>::IndexType index;
213 MITK_INFO <<
"Performing clipping..." << std::endl;
218 inputIt.SetFirstDirection(0);
219 inputIt.SetSecondDirection(1);
221 for (inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); inputIt.NextSlice())
224 for (; !inputIt.IsAtEndOfSlice(); inputIt.NextLine())
228 imageP0[0] = inputIt.GetIndex()[0];
229 imageP0[1] = inputIt.GetIndex()[1];
230 imageP0[2] = inputIt.GetIndex()[2];
231 planeP0 = imageToPlaneTransform->TransformPoint(imageP0);
235 imageP1[0] = imageP0[0] + inputRegionOfInterest.GetSize(0);
236 imageP1[1] = imageP0[1];
237 imageP1[2] = imageP0[2];
238 planeP1 = imageToPlaneTransform->TransformPoint(imageP1);
241 Vector3D step = (planeP1 - planeP0) / (
double)inputRegionOfInterest.GetSize(0);
244 for (; !inputIt.IsAtEndOfLine(); ++inputIt, ++outputIt, planeP0 += step)
248 ((TPixel)inputIt.Get() == clippingConstant))
250 outputIt.Set(clippingConstant);
288 double p01 = ((double)(m_HeightFieldResolutionY) * (planeP0[1] - bounds[2]) / yWidth);
291 q00 * ((double)x1 - p00) * ((double)y1 - p01) + q01 * (p00 - (double)x0) * ((double)y1 - p01) +
292 q10 * ((double)x1 - p00) * (p01 - (double)y0) + q11 * (p00 - (double)x0) * (p01 - (double)y0);
294 if (q - planeP0[2] < 0)
313 outputIt.Set(inputIt.Get() * factor);
317 if (inputIt.Get() != 0)
320 outputIt.Set(inputIt.Get());
326 outputIt.Set(inputIt.Get());
336 cellLocator->Delete();
354 int tstart = outputRegion.GetIndex(3);
355 int tmax = tstart + outputRegion.GetSize(3);
357 for (
unsigned int i = 1; i < this->GetNumberOfInputs(); ++i)
359 Surface *inputSurface =
dynamic_cast<Surface *
>(itk::ProcessObject::GetInput(i));
361 if (!outputImage->
IsInitialized() || inputSurface ==
nullptr)
370 for (t = tstart; t < tmax; ++t)
382 AffineTransform3D::Pointer planeWorldToIndexTransform = AffineTransform3D::New();
385 AffineTransform3D::Pointer imageToPlaneTransform = AffineTransform3D::New();
386 imageToPlaneTransform->SetIdentity();
389 imageToPlaneTransform->Compose(planeWorldToIndexTransform);
391 MITK_INFO <<
"Accessing ITK function...\n";
398 imageToPlaneTransform);
void GenerateData() override
void SetRequestedRegionToLargestPossibleRegion() override
Class for storing surfaces (vtkPolyData).
#define AccessByItk_3(mitkImage, itkImageTypeFunction, arg1, arg2, arg3)
ScalarType m_MultiplicationFactor
~HeightFieldSurfaceClipImageFilter() override
virtual vtkPolyData * GetVtkPolyData(unsigned int t=0) const
unsigned int m_HeightFieldResolutionX
virtual void Initialize(const mitk::PixelType &type, unsigned int dimension, const unsigned int *dimensions, unsigned int channels=1)
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
ScalarType m_ClippingConstant
DataCollection - Class to facilitate loading/accessing structured data.
HeightFieldSurfaceClipImageFilter()
void SetClippingMode(int mode)
Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-s...
unsigned m_MultiPlaneValue
void _InternalComputeClippedImage(itk::Image< TPixel, VImageDimension > *itkImage, HeightFieldSurfaceClipImageFilter *clipImageFilter, vtkPolyData *clippingPolyData, AffineTransform3D *imageToPlaneTransform)
void SetGeometry(BaseGeometry *aGeometry3D) override
Sets a geometry to an image.
void SetPropertyList(PropertyList *propertyList)
Set the data's property list.
ImageTimeSelector::Pointer m_OutputTimeSelector
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
ImageTimeSelector::Pointer m_InputTimeSelector
unsigned int GetNumberOfChannels() const
Get the number of channels.
unsigned int GetDimension() const
Get dimension of the image.
void SetClippingSurface(Surface *clippingSurface)
Set/Get the surface defining a height field as a triangle mesh.
void SetClippingModeToMultiplyByFactor()
Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-s...
void SetClippingModeToConstant()
Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-s...
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.
void GenerateOutputInformation() override
const Surface * GetClippingSurface() const
Set/Get the surface defining a height field as a triangle mesh.
virtual const RegionType & GetRequestedRegion() const
void GenerateInputRequestedRegion() override
int GetClippingMode()
Specifies whether clipped part of the image shall be replaced by a constant or multiplied by a user-s...
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
void SetClippingSurfaces(ClippingPlaneList planeList)
Set/Get the surfaces defining a height field as a triangle mesh.
itk::TimeStamp m_TimeOfHeaderInitialization
Time when Header was last initialized.
void GenerateTimeInInputRegion(const mitk::TimeGeometry *outputTimeGeometry, const TOutputRegion &outputRegion, const mitk::TimeGeometry *inputTimeGeometry, TInputRegion &inputRegion)
void SetClippingModeToMultiPlaneValue()
mitk::PropertyList::Pointer GetPropertyList() const
Get the data's property list.
InputImageType * GetInput(void)
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
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.
unsigned int m_HeightFieldResolutionY
Filter for clipping an image with an height-field represented by an mitk::Surface.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
std::vector< mitk::Surface * > ClippingPlaneList
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.