13 #include <itkSpatialOrientationAdapter.h> 28 : m_EvenlySpaced(true), m_Slices(0), m_ReferenceGeometry(nullptr), m_SliceNavigationController(nullptr)
47 assert(!other.
m_PlaneGeometries.empty() &&
"This may happen when you use one of the old Initialize methods, which had a bool parameter that is implicitly casted to the number of slices now.");
49 assert(geometry.IsNotNull());
65 assert(geometry2D !=
nullptr);
93 if (firstSlice !=
nullptr &&
94 dynamic_cast<AbstractTransformGeometry *>(
m_PlaneGeometries[0].GetPointer()) ==
nullptr)
108 requestedslice->SetOrigin(requestedslice->GetOrigin() + direction * s);
110 geometry2D = requestedslice;
156 assert(geometry2D !=
nullptr);
164 assert(geometry2D !=
nullptr);
168 geometry2D->Register();
182 directionVector.Normalize();
183 directionVector *= zSpacing;
214 geometry2D->UnRegister();
226 planeGeometry->InitializeStandardPlane(geometry3D, top, planeorientation, frontside, rotated);
236 matrix.GetVnlMatrix().normalize_columns();
237 mitk::AffineTransform3D::MatrixType::InternalMatrixType inverseMatrix = matrix.GetTranspose();
239 int dominantAxis = planeGeometry->CalculateDominantAxes(inverseMatrix).at(worldAxis);
245 auto slices =
static_cast<unsigned int>(geometry3D->
GetExtent(dominantAxis) + 0.5);
246 if ( slices == 0 && geometry3D->
GetExtent(dominantAxis) > 0) {
252 int upDirection = itk::Function::Sign(inverseMatrix[dominantAxis][worldAxis]);
257 Vector3D worldPlaneNormal = inverseMatrix.get_row(dominantAxis) * (upDirection * viewSpacing);
260 Vector3D standardPlaneNormal = planeGeometry->GetNormal();
265 assert((standardPlaneNormal - (top ? 1.0 : -1.0) * worldPlaneNormal).GetSquaredNorm() < 0.000001);
274 Vector3D upscaledStandardPlaneNormal = standardPlaneNormal;
275 upscaledStandardPlaneNormal *= slices;
276 assert((zAxisVector - upscaledStandardPlaneNormal).GetSquaredNorm() < 0.000001);
299 if (!firstPlane || dynamic_cast<AbstractTransformGeometry *>(firstPlane))
331 if (directedExtent >= spacing[2])
333 m_Slices =
static_cast<unsigned int>(directedExtent / spacing[2] + 0.5);
346 if (centerOfRotationDistance > 0)
348 firstPlane->
SetOrigin(firstPlane->
GetOrigin() + normal * (centerOfRotationDistance - directedExtent / 2.0));
353 firstPlane->
SetOrigin(firstPlane->
GetOrigin() + normal * (directedExtent / 2.0 + centerOfRotationDistance));
362 auto referencePointSlice =
static_cast<int>(referencePointDistance / spacing[2]);
364 double alignmentValue = referencePointDistance / spacing[2] - referencePointSlice;
366 firstPlane->
SetOrigin(firstPlane->
GetOrigin() + normal * alignmentValue * spacing[2]);
404 double scaling = d[0] * d[0] / (spacing[0] * spacing[0]) + d[1] * d[1] / (spacing[1] * spacing[1]) +
405 d[2] * d[2] / (spacing[2] * spacing[2]);
407 scaling = sqrt(scaling);
409 return (sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]) / scaling);
414 TransformType::Pointer inverse = TransformType::New();
417 Vector3D transformedNormal = inverse->TransformVector(normal);
419 transformedNormal.Normalize();
420 return transformedNormal;
431 if (geometry !=
nullptr)
444 if (geometry !=
nullptr)
455 return ((s >= 0) && (s < (
int)
m_Slices));
467 std::vector<PlaneGeometry::Pointer>::iterator it;
471 (*it)->SetReferenceGeometry(referenceGeometry);
482 bool hasEvenlySpacedPlaneGeometry =
false;
488 if (!(aSpacing[0] > 0 && aSpacing[1] > 0 && aSpacing[2] > 0))
490 mitkThrow() <<
"You try to set a spacing with at least one element equal or " 491 "smaller to \"0\". This might lead to a crash during rendering. Please double" 501 if (planeGeometry && !dynamic_cast<const AbstractTransformGeometry *>(planeGeometry))
508 hasEvenlySpacedPlaneGeometry =
true;
518 if (hasEvenlySpacedPlaneGeometry)
532 planeGeometry->InitializeStandardPlane(rightDV.GetVnlVector(), bottomDV.GetVnlVector(), &lokalSpacing);
533 planeGeometry->SetOrigin(origin);
534 planeGeometry->SetBounds(bounds);
536 firstGeometry = planeGeometry;
604 newGeometry->UnRegister();
605 return newGeometry.GetPointer();
616 os << indent <<
" Slices: " <<
m_Slices << std::endl;
619 os << indent <<
" GetPlaneGeometry(0): ";
622 os <<
"nullptr" << std::endl;
662 rotOp->GetOperationType(), center, rotOp->GetVectorOfRotation(), rotOp->GetAngleOfRotation());
665 geometry2D->ExecuteOperation(¢eredRotation);
691 if ((*iter).IsNotNull())
693 (*iter)->ExecuteOperation(operation);
708 (*iter)->ExecuteOperation(operation);
725 (!planeGeometry || dynamic_cast<AbstractTransformGeometry *>(planeGeometry.GetPointer())) || !planeOp)
737 Point3D center = planeOp->GetPoint();
740 if (planeOp->AreAxisDefined())
743 newNormal = CrossProduct(planeOp->GetAxisVec0(), planeOp->GetAxisVec1());
748 newNormal = planeOp->GetNormal();
752 currentNormal.Normalize();
753 newNormal.Normalize();
754 ScalarType rotationAngle = angle(currentNormal.GetVnlVector(), newNormal.GetVnlVector());
756 rotationAngle *= 180.0 / vnl_math::pi;
757 Vector3D rotationAxis = itk::CrossProduct(currentNormal, newNormal);
758 if (std::abs(rotationAngle - 180) <
mitk::eps)
763 helpNormal = currentNormal;
767 helpNormal.Normalize();
768 rotationAxis = itk::CrossProduct(helpNormal, currentNormal);
774 planeGeometry->ExecuteOperation(¢eredRotation);
777 if (!planeOp->AreAxisDefined())
782 planeGeometry->SetSpacing(this->
GetSpacing());
798 if (planeOp->AreAxisDefined())
801 vecAxixNew.Normalize();
803 VecAxisCurr.Normalize();
805 ScalarType rotationAngle = angle(VecAxisCurr.GetVnlVector(), vecAxixNew.GetVnlVector());
806 rotationAngle = rotationAngle * 180 /
PI;
813 rotationAxis = itk::CrossProduct(VecAxisCurr, vecAxixNew);
814 if (std::abs(rotationAngle - 180) <
mitk::eps)
818 rotationAxis = newNormal;
823 planeGeometry->ExecuteOperation(&op);
827 planeGeometry->SetSpacing(this->
GetSpacing());
844 (*iter)->ExecuteOperation(operation);
860 (planeGeometry && dynamic_cast<AbstractTransformGeometry *>(planeGeometry.GetPointer()) ==
nullptr) &&
867 planeGeometry->ExecuteOperation(restorePlaneOp);
873 if (centerOfRotationDistance <= 0)
878 Vector3D spacing = restorePlaneOp->GetSpacing();
891 if (directedExtent >= spacing[2])
893 m_Slices =
static_cast<unsigned int>(directedExtent / spacing[2] + 0.5);
926 (*iter)->ExecuteOperation(operation);
942 geometry2D->ExecuteOperation(applyMatrixOp);
virtual void InitializePlanes(const mitk::BaseGeometry *geometry3D, mitk::PlaneGeometry::PlaneOrientation planeorientation, bool top=true, bool frontside=true, bool rotated=false)
Completely initialize this instance as evenly-spaced plane slices parallel to a side of the provided ...
mitk::Vector3D m_DirectionVector
mitk::Stepper * GetSlice()
Get the Stepper through the slices.
mitk::Vector3D AdjustNormal(const mitk::Vector3D &normal) const
itk::BoundingBox< unsigned long, 3, ScalarType > BoundingBox
Standard 3D-BoundingBox typedef.
void IndexToWorld(const mitk::Vector3D &vec_units, mitk::Vector3D &vec_mm) const
Convert (continuous or discrete) index coordinates of a vector vec_units to world coordinates (in mm)...
virtual bool GetImageGeometry() const
Is this an ImageGeometry?
mitk::SliceNavigationController * m_SliceNavigationController
void SelectSliceByPoint(const mitk::Point3D &point)
Positions the SNC according to the specified point.
void SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing=false)
Set the spacing (m_Spacing).
virtual void InitializeSlicedGeometry(unsigned int slices)
Tell this instance how many PlaneGeometries it shall manage. Bounding box and the PlaneGeometries mus...
void SetIndexToWorldTransform(mitk::AffineTransform3D *transform)
bool IsBoundingBoxNull() const
Vector3D GetAxisVector(unsigned int direction) const
Get vector along bounding-box in the specified direction in mm.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Base class of all Operation-classes.
~SlicedGeometry3D() override
void _SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing=false)
virtual void ReinitializePlanes(const Point3D ¢er, const Point3D &referencePoint)
virtual void SetEvenlySpaced(bool on=true)
ScalarType GetExtent(unsigned int direction) const
Set the time bounds (in ms)
mitk::SliceNavigationController * GetSliceNavigationController()
void Initialize()
Initialize the BaseGeometry.
virtual bool SetPlaneGeometry(mitk::PlaneGeometry *geometry2D, int s)
Set PlaneGeometry of slice s.
Constants for most interaction classes, due to the generic StateMachines.
virtual const mitk::Vector3D & GetDirectionVector() const
Point3D GetCenter() const
Get the center of the bounding-box in mm.
itk::LightObject::Pointer InternalClone() const override
clones the geometry
void PreSetSpacing(const mitk::Vector3D &aSpacing) override
PreSetSpacing.
virtual void InitializeEvenlySpaced(mitk::PlaneGeometry *geometry2D, unsigned int slices)
Completely initialize this instance as evenly-spaced with slices parallel to the provided PlaneGeomet...
virtual void SetSliceNavigationController(mitk::SliceNavigationController *snc)
Set the SliceNavigationController corresponding to this sliced geometry.
std::vector< PlaneGeometry::Pointer > m_PlaneGeometries
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.
Controls the selection of the slice the associated BaseRenderer will display.
const mitk::BoundingBox * GetBoundingBox() const override
const mitk::ScalarType PI
virtual mitk::PlaneGeometry * GetPlaneGeometry(int s) const
Returns the PlaneGeometry of the slice (s).
void SetImageGeometry(const bool isAnImageGeometry) override
Define that this BaseGeometry is refering to an Image.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
bool HasReferenceGeometry() const
void ChangeImageGeometryConsideringOriginOffset(const bool isAnImageGeometry) override
When switching from an Image Geometry to a normal Geometry (and the other way around), you have to.
void SetOrigin(const Point3D &origin)
Set the origin, i.e. the upper-left corner of the plane.
ScalarType SignedDistanceFromPlane(const Point3D &pt3d_mm) const
Signed distance of the point from the plane (bounding-box not considered)
void Modified() const override
Overload of function Modified() to prohibit several calls of Modified() using the ModifiedLock class...
Operation for setting a plane (defined by its origin and normal)
virtual bool IsValidSlice(int s=0) const
Check whether a slice exists.
const mitk::BaseGeometry * m_ReferenceGeometry
virtual void SetPos(unsigned int pos)
virtual unsigned int GetFrameOfReferenceID() const
Get the DICOM FrameOfReferenceID referring to the used world coordinate system.
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
void WorldToIndex(const mitk::Point3D &pt_mm, mitk::Point3D &pt_units) const
Convert world coordinates (in mm) of a point to (continuous!) index coordinates.
Describes the geometry of a data object consisting of slices.
void AdjustSliceStepperRange()
Adjusts the numerical range of the slice stepper according to the current geometry orientation of thi...
Vector3D GetNormal() const
Normal of the plane.
virtual void ChangeImageGeometryConsideringOriginOffset(const bool isAnImageGeometry)
When switching from an Image Geometry to a normal Geometry (and the other way around), you have to.
void SetBounds(const BoundsArrayType &bounds)
Set the bounding box (in index/unit coordinates)
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
static double CalculateSpacing(const mitk::Vector3D &spacing, const mitk::Vector3D &d)
virtual const BaseGeometry * GetReferenceGeometry() const
virtual void SetFrameOfReferenceID(unsigned int _arg)
Set the DICOM FrameOfReferenceID referring to the used world coordinate system.
MITKCORE_EXPORT const ScalarType eps
Describes a two-dimensional, rectangular plane.
OperationType GetOperationType()
Operation, that holds everything necessary for an rotation operation on mitk::BaseData.
virtual void SetDirectionVector(const mitk::Vector3D &directionVector)
Set/Get the vector between slices for the evenly-spaced case (m_EvenlySpaced==true).
virtual void SetReferenceGeometry(const BaseGeometry *referenceGeometry)
void ExecuteOperation(Operation *operation) override
executes affine operations (translate, rotate, scale)
const BoundsArrayType GetBounds() const
virtual void SetImageGeometry(bool _arg)
Define that this BaseGeometry is refering to an Image.
BaseGeometry Describes the geometry of a data object.
void ExecuteOperation(Operation *operation) override
executes affine operations (translate, rotate, scale)
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
BoundingBoxType::BoundsArrayType BoundsArrayType
virtual void SetSteps(unsigned int _arg)
virtual const BoundingBoxType * GetBoundingBox()