25 #include <itkImageRegionConstIterator.h>
26 #include <itkImageRegionIteratorWithIndex.h>
27 #include <itkImageSliceConstIteratorWithIndex.h>
29 #include <vtkCellLocator.h>
30 #include <vtkPolyData.h>
37 : m_ClippingMode(CLIPPING_MODE_CONSTANT),
38 m_ClippingConstant(0.0),
39 m_MultiplicationFactor(2.0),
41 m_HeightFieldResolutionX(256),
42 m_HeightFieldResolutionY(256),
45 this->SetNumberOfIndexedInputs(8);
46 this->SetNumberOfRequiredInputs(2);
55 this->SetNthInput(1, clippingSurface);
60 if (planeList.size() > 7)
62 MITK_WARN <<
"Only 7 clipping planes are allowed!";
65 for (
unsigned int i = 0; i < planeList.size(); ++i)
67 this->SetNthInput(i + 1, planeList.at(i));
73 return dynamic_cast<const Surface *
>(itk::ProcessObject::GetInput(1));
115 itkDebugMacro(<<
"GenerateOutputInformation()");
118 auto tmpDimensions =
new unsigned int[inputImage->
GetDimension()];
128 delete[] tmpDimensions;
137 template <
typename TPixel,
unsigned int VImageDimension>
139 itk::Image<TPixel, VImageDimension> *inputItkImage,
141 vtkPolyData *clippingPolyData,
144 typedef itk::Image<TPixel, VImageDimension> ItkInputImageType;
145 typedef itk::Image<TPixel, VImageDimension> ItkOutputImageType;
147 typedef itk::ImageSliceConstIteratorWithIndex<ItkInputImageType> ItkInputImageIteratorType;
148 typedef itk::ImageRegionIteratorWithIndex<ItkOutputImageType> ItkOutputImageIteratorType;
152 outputimagetoitk->Update();
155 std::vector<double>
test;
158 typename ItkInputImageType::RegionType inputRegionOfInterest = inputItkImage->GetLargestPossibleRegion();
159 ItkInputImageIteratorType inputIt(inputItkImage, inputRegionOfInterest);
160 ItkOutputImageIteratorType outputIt(outputItkImage, inputRegionOfInterest);
163 clippingPolyData->ComputeBounds();
164 double *bounds = clippingPolyData->GetBounds();
166 double xWidth = bounds[1] - bounds[0];
167 double yWidth = bounds[3] - bounds[2];
171 cellLocator->SetDataSet(clippingPolyData);
172 cellLocator->CacheCellBoundsOn();
173 cellLocator->AutomaticOn();
174 cellLocator->BuildLocator();
184 MITK_INFO <<
"Calculating Height Field..." << std::endl;
189 double p0[3], p1[3], surfacePoint[3], pcoords[3];
190 p0[0] = bounds[0] + xWidth * x / (double)m_HeightFieldResolutionX;
191 p0[1] = bounds[2] + yWidth * y / (double)m_HeightFieldResolutionY;
200 if (cellLocator->IntersectWithLine(p0, p1, 0.1, t, surfacePoint, pcoords, subId))
208 heightField[y * m_HeightFieldResolutionX + x] = distance;
209 itk::Image<double, 2>::IndexType index;
217 MITK_INFO <<
"Performing clipping..." << std::endl;
222 inputIt.SetFirstDirection(0);
223 inputIt.SetSecondDirection(1);
225 for (inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); inputIt.NextSlice())
228 for (; !inputIt.IsAtEndOfSlice(); inputIt.NextLine())
232 imageP0[0] = inputIt.GetIndex()[0];
233 imageP0[1] = inputIt.GetIndex()[1];
234 imageP0[2] = inputIt.GetIndex()[2];
235 planeP0 = imageToPlaneTransform->TransformPoint(imageP0);
239 imageP1[0] = imageP0[0] + inputRegionOfInterest.GetSize(0);
240 imageP1[1] = imageP0[1];
241 imageP1[2] = imageP0[2];
242 planeP1 = imageToPlaneTransform->TransformPoint(imageP1);
245 Vector3D step = (planeP1 - planeP0) / (
double)inputRegionOfInterest.GetSize(0);
248 for (; !inputIt.IsAtEndOfLine(); ++inputIt, ++outputIt, planeP0 += step)
252 ((TPixel)inputIt.Get() == clippingConstant))
254 outputIt.Set(clippingConstant);
292 double p01 = ((double)(m_HeightFieldResolutionY) * (planeP0[1] - bounds[2]) / yWidth);
295 q00 * ((double)x1 - p00) * ((double)y1 - p01) + q01 * (p00 - (double)x0) * ((double)y1 - p01) +
296 q10 * ((double)x1 - p00) * (p01 - (double)y0) + q11 * (p00 - (double)x0) * (p01 - (double)y0);
298 if (q - planeP0[2] < 0)
317 outputIt.Set(inputIt.Get() * factor);
321 if (inputIt.Get() != 0)
324 outputIt.Set(inputIt.Get());
330 outputIt.Set(inputIt.Get());
340 cellLocator->Delete();
358 int tstart = outputRegion.GetIndex(3);
359 int tmax = tstart + outputRegion.GetSize(3);
361 for (
unsigned int i = 1; i < this->GetNumberOfInputs(); ++i)
363 Surface *inputSurface =
const_cast<Surface *
>(
dynamic_cast<Surface *
>(itk::ProcessObject::GetInput(i)));
365 if (!outputImage->
IsInitialized() || inputSurface ==
nullptr)
374 for (t = tstart; t < tmax; ++t)
390 imageToPlaneTransform->SetIdentity();
393 imageToPlaneTransform->Compose(planeWorldToIndexTransform);
395 MITK_INFO <<
"Accessing ITK function...\n";
402 imageToPlaneTransform);
virtual void GenerateData() override
A version of GenerateData() specific for image processing filters.
virtual void SetRequestedRegionToLargestPossibleRegion() override
Class for storing surfaces (vtkPolyData).
#define AccessByItk_3(mitkImage, itkImageTypeFunction, arg1, arg2, arg3)
ScalarType m_MultiplicationFactor
itk::SmartPointer< Self > Pointer
unsigned int m_HeightFieldResolutionX
virtual const RegionType & GetRequestedRegion() const
virtual void Initialize(const mitk::PixelType &type, unsigned int dimension, const unsigned int *dimensions, unsigned int channels=1)
virtual vtkPolyData * GetVtkPolyData(unsigned int t=0) const
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
ScalarType m_ClippingConstant
DataCollection - Class to facilitate loading/accessing structured data.
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
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)
virtual void SetGeometry(BaseGeometry *aGeometry3D) override
Sets a geometry to an image.
void SetPropertyList(PropertyList *propertyList)
Set the data's property list.
~HeightFieldSurfaceClipImageFilter()
ImageTimeSelector::Pointer m_OutputTimeSelector
ImageTimeSelector::Pointer m_InputTimeSelector
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.
mitk::PropertyList::Pointer GetPropertyList() const
Get the data's property list.
virtual TimePointType TimeStepToTimePoint(TimeStepType timeStep) const =0
Converts a time step to a time point.
virtual void GenerateOutputInformation() override
virtual 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
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
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()
InputImageType * GetInput(void)
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...
unsigned int GetNumberOfChannels() const
Get the number of channels.
OutputType * GetOutput()
Get the output data of this image source object.
const Surface * GetClippingSurface() const
Set/Get the surface defining a height field as a triangle mesh.
unsigned int m_HeightFieldResolutionY
unsigned int GetDimension() const
Get dimension of the image.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Filter for clipping an image with an height-field represented by an mitk::Surface.
std::vector< mitk::Surface * > ClippingPlaneList
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.