22 #include <vtkGeneralTransform.h> 23 #include <vtkImageChangeInformation.h> 24 #include <vtkImageData.h> 25 #include <vtkPoints.h> 26 #include <vtkSmartPointer.h> 27 #include <vtkTransform.h> 28 #include <vtkTransform.h> 32 MITK_WARN <<
"Class ExtractDirectedPlaneImageFilter is deprecated! Use ExtractSliceFilter instead.";
55 itkWarningMacro(<<
"No world geometry has been set. Returning.");
64 itkWarningMacro(<<
"No input set.");
68 const TimeGeometry *inputTimeGeometry = input->GetTimeGeometry();
69 if ((inputTimeGeometry ==
nullptr) || (inputTimeGeometry->
CountTimeSteps() == 0))
71 itkWarningMacro(<<
"Error reading input image geometry.");
80 itkWarningMacro(<<
"This is not a valid timestep: " << timestep);
85 if (!input->IsVolumeSet(timestep))
87 itkWarningMacro(<<
"No volume data existent at given timestep " << timestep);
92 requestedRegion.SetIndex(3, timestep);
93 requestedRegion.SetSize(3, 1);
94 requestedRegion.SetSize(4, 1);
95 input->SetRequestedRegion(&requestedRegion);
98 vtkImageData *inputData = input->GetVtkImageData(timestep);
100 if (inputData ==
nullptr)
102 itkWarningMacro(<<
"Could not extract vtk image data for given timestep" << timestep);
107 inputData->GetSpacing(spacing);
115 Vector3D rightInIndex, bottomInIndex;
117 assert(input->GetTimeGeometry() == inputTimeGeometry);
121 if (inputGeometry ==
nullptr)
123 itkWarningMacro(<<
"There is no Geometry3D at given timestep " << timestep);
132 bool boundsInitialized =
false;
134 for (
auto &bound : bounds)
144 dynamic_cast<const AbstractTransformGeometry *>(
m_WorldGeometry) ==
nullptr)
147 origin = planeGeometry->GetOrigin();
148 right = planeGeometry->GetAxisVector(0);
149 bottom = planeGeometry->GetAxisVector(1);
150 normal = planeGeometry->GetNormal();
167 inputGeometry->WorldToIndex(right, rightInIndex);
168 inputGeometry->WorldToIndex(bottom, bottomInIndex);
169 extent[0] = rightInIndex.GetNorm();
170 extent[1] = bottomInIndex.GetNorm();
178 mmPerPixel[0] = widthInMM / extent[0];
179 mmPerPixel[1] = heightInMM / extent[1];
192 m_Reslicer->SetResliceTransform(inputGeometry->GetVtkTransform()->GetLinearInverse());
212 else if (dynamic_cast<const AbstractTransformGeometry *>(
m_WorldGeometry))
214 const auto *abstractGeometry =
217 extent[0] = abstractGeometry->GetParametricExtent(0);
218 extent[1] = abstractGeometry->GetParametricExtent(1);
220 widthInMM = abstractGeometry->GetParametricExtentInMM(0);
221 heightInMM = abstractGeometry->GetParametricExtentInMM(1);
223 mmPerPixel[0] = widthInMM / extent[0];
224 mmPerPixel[1] = heightInMM / extent[1];
226 origin = abstractGeometry->GetPlane()->GetOrigin();
228 right = abstractGeometry->GetPlane()->GetAxisVector(0);
231 bottom = abstractGeometry->GetPlane()->GetAxisVector(1);
234 normal = abstractGeometry->GetPlane()->GetNormal();
239 vtkGeneralTransform *composedResliceTransform = vtkGeneralTransform::New();
240 composedResliceTransform->Identity();
241 composedResliceTransform->Concatenate(inputGeometry->GetVtkTransform()->GetLinearInverse());
242 composedResliceTransform->Concatenate(abstractGeometry->GetVtkAbstractTransform());
244 m_Reslicer->SetResliceTransform(composedResliceTransform);
249 composedResliceTransform->Delete();
253 itkWarningMacro(<<
"World Geometry has to be a PlaneGeometry or an AbstractTransformGeometry.");
258 if ((extent[0] <= 2) && (extent[1] <= 2))
260 itkWarningMacro(<<
"Image is too small to be resliced...");
264 vtkSmartPointer<vtkImageChangeInformation> unitSpacingImageFilter = vtkImageChangeInformation::New();
265 unitSpacingImageFilter->SetOutputSpacing(1.0, 1.0, 1.0);
266 unitSpacingImageFilter->SetInputData(inputData);
268 m_Reslicer->SetInputConnection(unitSpacingImageFilter->GetOutputPort());
276 pixelsPerMM[0] = 1.0 / mmPerPixel[0];
277 pixelsPerMM[1] = 1.0 / mmPerPixel[1];
280 double originArray[3];
283 m_Reslicer->SetResliceAxesOrigin(originArray);
288 vnl2vtk(right.GetVnlVector(), cosines);
291 vnl2vtk(bottom.GetVnlVector(), cosines + 3);
294 vnl2vtk(normal.GetVnlVector(), cosines + 6);
296 m_Reslicer->SetResliceAxesDirectionCosines(cosines);
298 int xMin, xMax, yMin, yMax;
299 if (boundsInitialized)
301 xMin =
static_cast<int>(bounds[0] / mmPerPixel[0]);
302 xMax =
static_cast<int>(bounds[1] / mmPerPixel[0]);
303 yMin =
static_cast<int>(bounds[2] / mmPerPixel[1]);
304 yMax =
static_cast<int>(bounds[3] / mmPerPixel[1]);
312 xMax =
static_cast<int>(extent[0] - pixelsPerMM[0]);
313 yMax =
static_cast<int>(extent[1] - pixelsPerMM[1]);
316 m_Reslicer->SetOutputSpacing(mmPerPixel[0], mmPerPixel[1], 1.0);
320 m_Reslicer->SetOutputExtent(xMin, xMax - 1, yMin, yMax - 1, 0, 1);
331 vtkImageData *reslicedImage =
m_Reslicer->GetOutput();
333 if ((reslicedImage ==
nullptr) || (reslicedImage->GetDataDimension() < 1))
335 itkWarningMacro(<<
"Reslicer returned empty image");
339 unsigned int dimensions[2];
340 dimensions[0] = (
unsigned int)extent[0];
341 dimensions[1] = (
unsigned int)extent[1];
343 FillVector3D(spacingVector, mmPerPixel[0], mmPerPixel[1], 1.0);
346 resultImage->Initialize(input->GetPixelType(), 2, dimensions);
347 resultImage->SetSpacing(spacingVector);
352 Superclass::GenerateOutputInformation();
366 BoundingBox::PointType bbMin = boundingBox->GetMinimum();
367 BoundingBox::PointType bbMax = boundingBox->GetMaximum();
369 vtkPoints *points = vtkPoints::New();
372 points->InsertPoint(0, bbMin[0] - 0.5, bbMin[1] - 0.5, bbMin[2] - 0.5);
373 points->InsertPoint(1, bbMin[0] - 0.5, bbMin[1] - 0.5, bbMax[2] - 0.5);
374 points->InsertPoint(2, bbMin[0] - 0.5, bbMax[1] - 0.5, bbMax[2] - 0.5);
375 points->InsertPoint(3, bbMin[0] - 0.5, bbMax[1] - 0.5, bbMin[2] - 0.5);
376 points->InsertPoint(4, bbMax[0] - 0.5, bbMin[1] - 0.5, bbMin[2] - 0.5);
377 points->InsertPoint(5, bbMax[0] - 0.5, bbMin[1] - 0.5, bbMax[2] - 0.5);
378 points->InsertPoint(6, bbMax[0] - 0.5, bbMax[1] - 0.5, bbMax[2] - 0.5);
379 points->InsertPoint(7, bbMax[0] - 0.5, bbMax[1] - 0.5, bbMin[2] - 0.5);
383 points->InsertPoint(0, bbMin[0], bbMin[1], bbMin[2]);
384 points->InsertPoint(1, bbMin[0], bbMin[1], bbMax[2]);
385 points->InsertPoint(2, bbMin[0], bbMax[1], bbMax[2]);
386 points->InsertPoint(3, bbMin[0], bbMax[1], bbMin[2]);
387 points->InsertPoint(4, bbMax[0], bbMin[1], bbMin[2]);
388 points->InsertPoint(5, bbMax[0], bbMin[1], bbMax[2]);
389 points->InsertPoint(6, bbMax[0], bbMax[1], bbMax[2]);
390 points->InsertPoint(7, bbMax[0], bbMax[1], bbMin[2]);
393 vtkPoints *newPoints = vtkPoints::New();
395 vtkTransform *transform = vtkTransform::New();
396 transform->Identity();
397 transform->Concatenate(planeGeometry->
GetVtkTransform()->GetLinearInverse());
401 transform->TransformPoints(points, newPoints);
404 bounds[0] = bounds[2] = 10000000.0;
405 bounds[1] = bounds[3] = -10000000.0;
406 bounds[4] = bounds[5] = 0.0;
425 if ((bounds[0] > 9999999.0) || (bounds[2] > 9999999.0) || (bounds[1] < -9999999.0) || (bounds[3] < -9999999.0))
434 bounds[0] *= planeSpacing[0];
435 bounds[1] *= planeSpacing[0];
436 bounds[2] *= planeSpacing[1];
437 bounds[3] *= planeSpacing[1];
438 bounds[4] *= planeSpacing[2];
439 bounds[5] *= planeSpacing[2];
448 points->GetPoint(p1, point1);
449 points->GetPoint(p2, point2);
451 if ((point1[2] * point2[2] <= 0.0) && (point1[2] != point2[2]))
454 x = (point1[0] * point2[2] - point1[2] * point2[0]) / (point2[2] - point1[2]);
455 y = (point1[1] * point2[2] - point1[2] * point2[1]) / (point2[2] - point1[2]);
473 bounds[4] = bounds[5] = 0.0;
itk::BoundingBox< unsigned long, 3, ScalarType > BoundingBox
Standard 3D-BoundingBox typedef.
virtual bool GetImageGeometry() const
Is this an ImageGeometry?
virtual TimeStepType CountTimeSteps() const =0
Returns the number of time steps.
vtkLinearTransform * GetVtkTransform() const
Get the m_IndexToWorldTransform as a vtkLinearTransform.
ScalarType GetExtent(unsigned int direction) const
Set the time bounds (in ms)
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
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.
void vnl2vtk(const vnl_vector< Tin > &in, Tout *out)
itk::ImageRegion< RegionDimension > RegionType
Image class for storing images.
void itk2vtk(const Tin &in, Tout &out)
InputImageType * GetInput(void)
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
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.
virtual const BoundingBoxType * GetBoundingBox()