Medical Imaging Interaction Toolkit  2018.4.99-c4b6bb11
Medical Imaging Interaction Toolkit
mitkAbstractTransformGeometry.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include <vtkAbstractTransform.h>
15 
16 mitk::AbstractTransformGeometry::AbstractTransformGeometry() : Superclass(), m_Plane(nullptr), m_FrameGeometry(nullptr)
17 {
18  Initialize();
20 }
21 
24 {
25  if (other.m_ParametricBoundingBox.IsNotNull())
26  {
28  this->SetParametricBounds(m_ParametricBoundingBox->GetBounds());
29  }
30 
31  this->SetPlane(other.m_Plane);
32 
33  this->SetFrameGeometry(other.m_FrameGeometry);
35 }
36 
38 {
39 }
40 
42 {
44 }
45 
47 {
48  if (m_Plane.IsNull())
49  {
50  itkExceptionMacro(<< "m_Plane is nullptr.");
51  }
52  return m_Plane->GetExtentInMM(direction);
53 }
54 
55 const itk::Transform<mitk::ScalarType, 3, 3> *mitk::AbstractTransformGeometry::GetParametricTransform() const
56 {
58 }
59 
60 bool mitk::AbstractTransformGeometry::Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const
61 {
62  assert(this->IsBoundingBoxNull() == false);
63 
64  mitk::Point2D pt2d_mm;
65  bool isInside;
66  isInside = Map(pt3d_mm, pt2d_mm);
67  Map(pt2d_mm, projectedPt3d_mm);
68  return isInside;
69  // Point3D pt3d_units;
70  // pt3d_units = m_ItkVtkAbstractTransform->BackTransform(pt3d_mm);
71  // pt3d_units[2] = 0;
72  // projectedPt3d_mm = m_ItkVtkAbstractTransform->TransformPoint(pt3d_units);
73  // return const_cast<BoundingBox*>(m_BoundingBox.GetPointer())->IsInside(pt3d_units);
74 }
75 
77 {
78  assert((m_ItkVtkAbstractTransform.IsNotNull()) && (m_Plane.IsNotNull()));
79 
80  Point3D pt3d_units;
81  pt3d_units = m_ItkVtkAbstractTransform->BackTransform(pt3d_mm);
82 
83  return m_Plane->Map(pt3d_units, pt2d_mm);
84 }
85 
87 {
88  assert((m_ItkVtkAbstractTransform.IsNotNull()) && (m_Plane.IsNotNull()));
89 
90  m_Plane->Map(pt2d_mm, pt3d_mm);
91  pt3d_mm = m_ItkVtkAbstractTransform->TransformPoint(pt3d_mm);
92 }
93 
95  const mitk::Vector3D &vec3d_mm,
96  mitk::Vector3D &projectedVec3d_mm) const
97 {
98  itkExceptionMacro("not implemented yet - replace GetIndexToWorldTransform by "
99  "m_ItkVtkAbstractTransform->GetInverseVtkAbstractTransform()");
100  assert(this->IsBoundingBoxNull() == false);
101 
102  Vector3D vec3d_units;
103  vec3d_units = GetIndexToWorldTransform()->GetInverseMatrix() * vec3d_mm;
104  vec3d_units[2] = 0;
105  projectedVec3d_mm = GetIndexToWorldTransform()->TransformVector(vec3d_units);
106 
107  Point3D pt3d_units;
108  mitk::ScalarType temp[3];
109  unsigned int i, j;
110 
111  for (j = 0; j < 3; ++j)
112  temp[j] = atPt3d_mm[j] - GetIndexToWorldTransform()->GetOffset()[j];
113 
114  for (i = 0; i < 3; ++i)
115  {
116  pt3d_units[i] = 0.0;
117 
118  for (j = 0; j < 3; ++j)
119  pt3d_units[i] += GetIndexToWorldTransform()->GetInverseMatrix()[i][j] * temp[j];
120  }
121 
122  return this->GetBoundingBox()->IsInside(pt3d_units);
123 }
124 
126  mitk::Vector3D & /*projectedVec3d_mm*/) const
127 {
128  MITK_WARN << "Need additional point! No standard value defined. Please use Project(const mitk::Point3D & atPt3d_mm, "
129  "const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm). Unfortunatley this one is not "
130  "implemented at the moment. Sorry :(";
131  itkExceptionMacro("not implemented yet - replace GetIndexToWorldTransform by "
132  "m_ItkVtkAbstractTransform->GetInverseVtkAbstractTransform()");
133  return false;
134 }
135 
137  const mitk::Vector3D &vec3d_mm,
138  mitk::Vector2D &vec2d_mm) const
139 {
140  assert((m_ItkVtkAbstractTransform.IsNotNull()) && (m_Plane.IsNotNull()));
141 
142  ScalarType vtkpt[3], vtkvec[3];
143  itk2vtk(atPt3d_mm, vtkpt);
144  itk2vtk(vec3d_mm, vtkvec);
145  m_ItkVtkAbstractTransform->GetInverseVtkAbstractTransform()->TransformVectorAtPoint(vtkpt, vtkvec, vtkvec);
146  mitk::Vector3D vec3d_units;
147  vtk2itk(vtkvec, vec3d_units);
148  return m_Plane->Map(atPt3d_mm, vec3d_units, vec2d_mm);
149 }
150 
152  const mitk::Vector2D &vec2d_mm,
153  mitk::Vector3D &vec3d_mm) const
154 {
155  m_Plane->Map(atPt2d_mm, vec2d_mm, vec3d_mm);
156  Point3D atPt3d_mm;
157  Map(atPt2d_mm, atPt3d_mm);
158  float vtkpt[3], vtkvec[3];
159  itk2vtk(atPt3d_mm, vtkpt);
160  itk2vtk(vec3d_mm, vtkvec);
161  m_ItkVtkAbstractTransform->GetVtkAbstractTransform()->TransformVectorAtPoint(vtkpt, vtkvec, vtkvec);
162  vtk2itk(vtkvec, vec3d_mm);
163 }
164 
166 {
167  m_Plane->IndexToWorld(pt_units, pt_mm);
168 }
169 
171 {
172  m_Plane->WorldToIndex(pt_mm, pt_units);
173 }
174 
176  const mitk::Vector2D &vec_units,
177  mitk::Vector2D &vec_mm) const
178 {
179  MITK_WARN << "Warning! Call of the deprecated function AbstractTransformGeometry::IndexToWorld(point, vec, vec). Use "
180  "AbstractTransformGeometry::IndexToWorld(vec, vec) instead!";
181  this->IndexToWorld(vec_units, vec_mm);
182 }
183 
185 {
186  m_Plane->IndexToWorld(vec_units, vec_mm);
187 }
188 
190  const mitk::Vector2D &vec_mm,
191  mitk::Vector2D &vec_units) const
192 {
193  MITK_WARN << "Warning! Call of the deprecated function AbstractTransformGeometry::WorldToIndex(point, vec, vec). Use "
194  "AbstractTransformGeometry::WorldToIndex(vec, vec) instead!";
195  this->WorldToIndex(vec_mm, vec_units);
196 }
197 
199 {
200  m_Plane->WorldToIndex(vec_mm, vec_units);
201 }
202 
203 bool mitk::AbstractTransformGeometry::IsAbove(const mitk::Point3D &pt3d_mm, bool /*considerBoundingBox*/) const
204 {
205  assert((m_ItkVtkAbstractTransform.IsNotNull()) && (m_Plane.IsNotNull()));
206 
207  Point3D pt3d_ParametricWorld;
208  pt3d_ParametricWorld = m_ItkVtkAbstractTransform->BackTransform(pt3d_mm);
209 
210  Point3D pt3d_ParametricUnits;
211  ((BaseGeometry *)m_Plane)->WorldToIndex(pt3d_ParametricWorld, pt3d_ParametricUnits);
212 
213  return (pt3d_ParametricUnits[2] > m_ParametricBoundingBox->GetBounds()[4]);
214 }
215 
216 void mitk::AbstractTransformGeometry::SetVtkAbstractTransform(vtkAbstractTransform *aVtkAbstractTransform)
217 {
218  m_ItkVtkAbstractTransform->SetVtkAbstractTransform(aVtkAbstractTransform);
219 }
220 
222 {
223  if (aPlane != nullptr)
224  {
225  m_Plane = static_cast<mitk::PlaneGeometry *>(aPlane->Clone().GetPointer());
226 
227  BoundingBox::BoundsArrayType b = m_Plane->GetBoundingBox()->GetBounds();
228 
230 
232  }
233  else
234  {
235  if (m_Plane.IsNull())
236  return;
237  m_Plane = nullptr;
238  }
239  Modified();
240 }
241 
243 {
244  if ((m_Plane.IsNull()) || (m_FrameGeometry.IsNotNull()))
245  return;
246  //@warning affine-transforms and bounding-box should be set by specific sub-classes!
247  SetBounds(m_Plane->GetBoundingBox()->GetBounds());
248 }
249 
251 {
252  if ((frameGeometry != nullptr) && (frameGeometry->IsValid()))
253  {
254  m_FrameGeometry = static_cast<mitk::BaseGeometry *>(frameGeometry->Clone().GetPointer());
255  SetIndexToWorldTransform(m_FrameGeometry->GetIndexToWorldTransform());
256  SetBounds(m_FrameGeometry->GetBounds());
257  }
258  else
259  {
260  m_FrameGeometry = nullptr;
261  }
262 }
263 
265 {
266  if (Superclass::GetMTime() < m_ItkVtkAbstractTransform->GetMTime())
268 
269  return Superclass::GetMTime();
270 }
271 
273 {
274  if (m_Plane.IsNull())
275  {
276  itkExceptionMacro(<< "m_Plane is not set.");
277  }
278 
279  mitk::BoundingBox::BoundsArrayType bounds = m_Plane->GetBounds();
280  bounds[1] *= oversampling;
281  bounds[3] *= oversampling;
282  bounds[5] *= oversampling;
283  SetParametricBounds(bounds);
284 }
285 
286 itk::LightObject::Pointer mitk::AbstractTransformGeometry::InternalClone() const
287 {
288  Self::Pointer newGeometry = new AbstractTransformGeometry(*this);
289  newGeometry->UnRegister();
290  return newGeometry.GetPointer();
291 }
292 
294 {
295  m_ParametricBoundingBox = BoundingBoxType::New();
296 
297  BoundingBoxType::PointsContainer::Pointer pointscontainer = BoundingBoxType::PointsContainer::New();
298  BoundingBoxType::PointType p;
299  BoundingBoxType::PointIdentifier pointid;
300 
301  for (pointid = 0; pointid < 2; ++pointid)
302  {
303  unsigned int i;
304  for (i = 0; i < GetNDimensions(); ++i)
305  {
306  p[i] = bounds[2 * i + pointid];
307  }
308  pointscontainer->InsertElement(pointid, p);
309  }
310 
311  m_ParametricBoundingBox->SetPoints(pointscontainer);
312  m_ParametricBoundingBox->ComputeBoundingBox();
313  this->Modified();
314 }
315 
317 {
318  assert(m_ParametricBoundingBox.IsNotNull());
319  return m_ParametricBoundingBox->GetBounds();
320 }
321 
323 {
324  if (direction < 0 || direction >= 3)
325  mitkThrow() << "Invalid direction. Must be between either 0, 1 or 2. ";
326  assert(m_ParametricBoundingBox.IsNotNull());
327 
329  return bounds[direction * 2 + 1] - bounds[direction * 2];
330 }
virtual void CalculateFrameGeometry()
Calculates the standard part of a BaseGeometry (IndexToWorldTransform and bounding box) around the cu...
virtual InputPointType BackTransform(const OutputPointType &point) const
void SetIndexToWorldTransform(mitk::AffineTransform3D *transform)
bool IsBoundingBoxNull() const
virtual const itk::Transform< mitk::ScalarType, 3, 3 > * GetParametricTransform() const
bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const override
Project a 3D point given in mm (pt3d_mm) onto the 2D geometry. The result is a 2D point in mm (pt2d_m...
OutputPointType TransformPoint(const InputPointType &) const override
mitk::BoundingBox::Pointer m_ParametricBoundingBox
double ScalarType
static Pointer New()
Pointer Clone() const
mitk::ScalarType GetParametricExtent(int direction) const
Get the parametric extent.
Pointer Clone() const
void Initialize()
Initialize the BaseGeometry.
virtual vtkAbstractTransform * GetInverseVtkAbstractTransform() const
Get the inverse vtkAbstractTransform (stored in m_InverseVtkAbstractTransform)
void IndexToWorld(const mitk::Point2D &pt_units, mitk::Point2D &pt_mm) const override
const BoundingBox::BoundsArrayType & GetParametricBounds() const
Get the parametric bounds.
virtual void SetVtkAbstractTransform(vtkAbstractTransform *aVtkAbstractTransform)
Set the vtkAbstractTransform (stored in m_VtkAbstractTransform)
virtual void SetFrameGeometry(const mitk::BaseGeometry *frameGeometry)
Set the frame geometry which is used as the standard part of an BaseGeometry (IndexToWorldTransform a...
virtual void SetOversampling(mitk::ScalarType oversampling)
Change the parametric bounds to oversampling times the bounds of m_Plane.
void WorldToIndex(const mitk::Point2D &pt_mm, mitk::Point2D &pt_units) const override
unsigned long GetMTime() const override
#define MITK_WARN
Definition: mitkLogMacros.h:19
bool Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const override
projects the given point onto the curved plane
#define mitkThrow()
void Modified() const override
Overload of function Modified() to prohibit several calls of Modified() using the ModifiedLock class...
itk::LightObject::Pointer InternalClone() const override
clones the geometry
void vtk2itk(const Tin &in, Tout &out)
virtual void SetVtkAbstractTransform(vtkAbstractTransform *aVtkAbstractTransform)
Set the vtkAbstractTransform (stored in m_VtkAbstractTransform)
Describes a geometry defined by an vtkAbstractTransform and a plane.
virtual void SetParametricBounds(const BoundingBox::BoundsArrayType &bounds)
Set the parametric bounds.
virtual unsigned int GetNDimensions() const
virtual bool IsValid() const
Is this BaseGeometry in a state that is valid?
void itk2vtk(const Tin &in, Tout &out)
void SetBounds(const BoundsArrayType &bounds)
Set the bounding box (in index/unit coordinates)
itk::VtkAbstractTransform< ScalarType >::Pointer m_ItkVtkAbstractTransform
virtual vtkAbstractTransform * GetVtkAbstractTransform() const
Get the vtkAbstractTransform (stored in m_VtkAbstractTransform)
virtual void SetPlane(const mitk::PlaneGeometry *aPlane)
Set the rectangular area that is used for transformation by m_VtkAbstractTransform and therewith defi...
mitk::PlaneGeometry::Pointer m_Plane
The rectangular area that is used for transformation by m_VtkAbstractTransform and therewith defines ...
Describes a two-dimensional, rectangular plane.
virtual vtkAbstractTransform * GetVtkAbstractTransform() const
Get the vtkAbstractTransform (stored in m_VtkAbstractTransform)
virtual mitk::ScalarType GetParametricExtentInMM(int direction) const
bool IsAbove(const Point3D &pt3d_mm, bool considerBoundingBox=false) const override
Calculates, whether a point is below or above the plane. There are two different calculation methods...
BaseGeometry Describes the geometry of a data object.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
BoundingBoxType::BoundsArrayType BoundsArrayType
virtual const BoundingBoxType * GetBoundingBox()