Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include <vtkAbstractTransform.h>
19 
20 mitk::AbstractTransformGeometry::AbstractTransformGeometry() : Superclass(), m_Plane(nullptr), m_FrameGeometry(nullptr)
21 {
22  Initialize();
24 }
25 
27  : Superclass(other), m_ParametricBoundingBox(other.m_ParametricBoundingBox)
28 {
29  if (other.m_ParametricBoundingBox.IsNotNull())
30  {
32  this->SetParametricBounds(m_ParametricBoundingBox->GetBounds());
33  }
34 
35  this->SetPlane(other.m_Plane);
36 
37  this->SetFrameGeometry(other.m_FrameGeometry);
39 }
40 
42 {
43 }
44 
46 {
47  return m_ItkVtkAbstractTransform->GetVtkAbstractTransform();
48 }
49 
51 {
52  if (m_Plane.IsNull())
53  {
54  itkExceptionMacro(<< "m_Plane is NULL.");
55  }
56  return m_Plane->GetExtentInMM(direction);
57 }
58 
59 const itk::Transform<mitk::ScalarType, 3, 3> *mitk::AbstractTransformGeometry::GetParametricTransform() const
60 {
61  return m_ItkVtkAbstractTransform;
62 }
63 
64 bool mitk::AbstractTransformGeometry::Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const
65 {
66  assert(this->IsBoundingBoxNull() == false);
67 
68  mitk::Point2D pt2d_mm;
69  bool isInside;
70  isInside = Map(pt3d_mm, pt2d_mm);
71  Map(pt2d_mm, projectedPt3d_mm);
72  return isInside;
73  // Point3D pt3d_units;
74  // pt3d_units = m_ItkVtkAbstractTransform->BackTransform(pt3d_mm);
75  // pt3d_units[2] = 0;
76  // projectedPt3d_mm = m_ItkVtkAbstractTransform->TransformPoint(pt3d_units);
77  // return const_cast<BoundingBox*>(m_BoundingBox.GetPointer())->IsInside(pt3d_units);
78 }
79 
81 {
82  assert((m_ItkVtkAbstractTransform.IsNotNull()) && (m_Plane.IsNotNull()));
83 
84  Point3D pt3d_units;
85  pt3d_units = m_ItkVtkAbstractTransform->BackTransform(pt3d_mm);
86 
87  return m_Plane->Map(pt3d_units, pt2d_mm);
88 }
89 
91 {
92  assert((m_ItkVtkAbstractTransform.IsNotNull()) && (m_Plane.IsNotNull()));
93 
94  m_Plane->Map(pt2d_mm, pt3d_mm);
95  pt3d_mm = m_ItkVtkAbstractTransform->TransformPoint(pt3d_mm);
96 }
97 
99  const mitk::Vector3D &vec3d_mm,
100  mitk::Vector3D &projectedVec3d_mm) const
101 {
102  itkExceptionMacro("not implemented yet - replace GetIndexToWorldTransform by "
103  "m_ItkVtkAbstractTransform->GetInverseVtkAbstractTransform()");
104  assert(this->IsBoundingBoxNull() == false);
105 
106  Vector3D vec3d_units;
107  vec3d_units = GetIndexToWorldTransform()->GetInverseMatrix() * vec3d_mm;
108  vec3d_units[2] = 0;
109  projectedVec3d_mm = GetIndexToWorldTransform()->TransformVector(vec3d_units);
110 
111  Point3D pt3d_units;
112  mitk::ScalarType temp[3];
113  unsigned int i, j;
114 
115  for (j = 0; j < 3; ++j)
116  temp[j] = atPt3d_mm[j] - GetIndexToWorldTransform()->GetOffset()[j];
117 
118  for (i = 0; i < 3; ++i)
119  {
120  pt3d_units[i] = 0.0;
121 
122  for (j = 0; j < 3; ++j)
123  pt3d_units[i] += GetIndexToWorldTransform()->GetInverseMatrix()[i][j] * temp[j];
124  }
125 
126  return const_cast<BoundingBox *>(this->GetBoundingBox())->IsInside(pt3d_units);
127 }
128 
130  mitk::Vector3D & /*projectedVec3d_mm*/) const
131 {
132  MITK_WARN << "Need additional point! No standard value defined. Please use Project(const mitk::Point3D & atPt3d_mm, "
133  "const mitk::Vector3D &vec3d_mm, mitk::Vector3D &projectedVec3d_mm). Unfortunatley this one is not "
134  "implemented at the moment. Sorry :(";
135  itkExceptionMacro("not implemented yet - replace GetIndexToWorldTransform by "
136  "m_ItkVtkAbstractTransform->GetInverseVtkAbstractTransform()");
137  return false;
138 }
139 
141  const mitk::Vector3D &vec3d_mm,
142  mitk::Vector2D &vec2d_mm) const
143 {
144  assert((m_ItkVtkAbstractTransform.IsNotNull()) && (m_Plane.IsNotNull()));
145 
146  ScalarType vtkpt[3], vtkvec[3];
147  itk2vtk(atPt3d_mm, vtkpt);
148  itk2vtk(vec3d_mm, vtkvec);
149  m_ItkVtkAbstractTransform->GetInverseVtkAbstractTransform()->TransformVectorAtPoint(vtkpt, vtkvec, vtkvec);
150  mitk::Vector3D vec3d_units;
151  vtk2itk(vtkvec, vec3d_units);
152  return m_Plane->Map(atPt3d_mm, vec3d_units, vec2d_mm);
153 }
154 
156  const mitk::Vector2D &vec2d_mm,
157  mitk::Vector3D &vec3d_mm) const
158 {
159  m_Plane->Map(atPt2d_mm, vec2d_mm, vec3d_mm);
160  Point3D atPt3d_mm;
161  Map(atPt2d_mm, atPt3d_mm);
162  float vtkpt[3], vtkvec[3];
163  itk2vtk(atPt3d_mm, vtkpt);
164  itk2vtk(vec3d_mm, vtkvec);
165  m_ItkVtkAbstractTransform->GetVtkAbstractTransform()->TransformVectorAtPoint(vtkpt, vtkvec, vtkvec);
166  vtk2itk(vtkvec, vec3d_mm);
167 }
168 
170 {
171  m_Plane->IndexToWorld(pt_units, pt_mm);
172 }
173 
175 {
176  m_Plane->WorldToIndex(pt_mm, pt_units);
177 }
178 
180  const mitk::Vector2D &vec_units,
181  mitk::Vector2D &vec_mm) const
182 {
183  MITK_WARN << "Warning! Call of the deprecated function AbstractTransformGeometry::IndexToWorld(point, vec, vec). Use "
184  "AbstractTransformGeometry::IndexToWorld(vec, vec) instead!";
185  this->IndexToWorld(vec_units, vec_mm);
186 }
187 
189 {
190  m_Plane->IndexToWorld(vec_units, vec_mm);
191 }
192 
194  const mitk::Vector2D &vec_mm,
195  mitk::Vector2D &vec_units) const
196 {
197  MITK_WARN << "Warning! Call of the deprecated function AbstractTransformGeometry::WorldToIndex(point, vec, vec). Use "
198  "AbstractTransformGeometry::WorldToIndex(vec, vec) instead!";
199  this->WorldToIndex(vec_mm, vec_units);
200 }
201 
203 {
204  m_Plane->WorldToIndex(vec_mm, vec_units);
205 }
206 
207 bool mitk::AbstractTransformGeometry::IsAbove(const mitk::Point3D &pt3d_mm, bool /*considerBoundingBox*/) const
208 {
209  assert((m_ItkVtkAbstractTransform.IsNotNull()) && (m_Plane.IsNotNull()));
210 
211  Point3D pt3d_ParametricWorld;
212  pt3d_ParametricWorld = m_ItkVtkAbstractTransform->BackTransform(pt3d_mm);
213 
214  Point3D pt3d_ParametricUnits;
215  ((BaseGeometry *)m_Plane)->WorldToIndex(pt3d_ParametricWorld, pt3d_ParametricUnits);
216 
217  return (pt3d_ParametricUnits[2] > m_ParametricBoundingBox->GetBounds()[4]);
218 }
219 
220 void mitk::AbstractTransformGeometry::SetVtkAbstractTransform(vtkAbstractTransform *aVtkAbstractTransform)
221 {
222  m_ItkVtkAbstractTransform->SetVtkAbstractTransform(aVtkAbstractTransform);
223 }
224 
226 {
227  if (aPlane != nullptr)
228  {
229  m_Plane = static_cast<mitk::PlaneGeometry *>(aPlane->Clone().GetPointer());
230 
231  BoundingBox::BoundsArrayType b = m_Plane->GetBoundingBox()->GetBounds();
232 
233  SetParametricBounds(b);
234 
235  CalculateFrameGeometry();
236  }
237  else
238  {
239  if (m_Plane.IsNull())
240  return;
241  m_Plane = nullptr;
242  }
243  Modified();
244 }
245 
247 {
248  if ((m_Plane.IsNull()) || (m_FrameGeometry.IsNotNull()))
249  return;
250  //@warning affine-transforms and bounding-box should be set by specific sub-classes!
251  SetBounds(m_Plane->GetBoundingBox()->GetBounds());
252 }
253 
255 {
256  if ((frameGeometry != nullptr) && (frameGeometry->IsValid()))
257  {
258  m_FrameGeometry = static_cast<mitk::BaseGeometry *>(frameGeometry->Clone().GetPointer());
259  SetIndexToWorldTransform(m_FrameGeometry->GetIndexToWorldTransform());
260  SetBounds(m_FrameGeometry->GetBounds());
261  }
262  else
263  {
264  m_FrameGeometry = nullptr;
265  }
266 }
267 
269 {
270  if (Superclass::GetMTime() < m_ItkVtkAbstractTransform->GetMTime())
271  return m_ItkVtkAbstractTransform->GetMTime();
272 
273  return Superclass::GetMTime();
274 }
275 
277 {
278  if (m_Plane.IsNull())
279  {
280  itkExceptionMacro(<< "m_Plane is not set.");
281  }
282 
283  mitk::BoundingBox::BoundsArrayType bounds = m_Plane->GetBounds();
284  bounds[1] *= oversampling;
285  bounds[3] *= oversampling;
286  bounds[5] *= oversampling;
287  SetParametricBounds(bounds);
288 }
289 
291 {
292  Self::Pointer newGeometry = new AbstractTransformGeometry(*this);
293  newGeometry->UnRegister();
294  return newGeometry.GetPointer();
295 }
296 
298 {
299  m_ParametricBoundingBox = BoundingBoxType::New();
300 
303  BoundingBoxType::PointIdentifier pointid;
304 
305  for (pointid = 0; pointid < 2; ++pointid)
306  {
307  unsigned int i;
308  for (i = 0; i < GetNDimensions(); ++i)
309  {
310  p[i] = bounds[2 * i + pointid];
311  }
312  pointscontainer->InsertElement(pointid, p);
313  }
314 
315  m_ParametricBoundingBox->SetPoints(pointscontainer);
316  m_ParametricBoundingBox->ComputeBoundingBox();
317  this->Modified();
318 }
319 
321 {
322  assert(m_ParametricBoundingBox.IsNotNull());
323  return m_ParametricBoundingBox->GetBounds();
324 }
325 
327 {
328  if (direction < 0 || direction >= 3)
329  mitkThrow() << "Invalid direction. Must be between either 0, 1 or 2. ";
330  assert(m_ParametricBoundingBox.IsNotNull());
331 
332  BoundingBoxType::BoundsArrayType bounds = m_ParametricBoundingBox->GetBounds();
333  return bounds[direction * 2 + 1] - bounds[direction * 2];
334 }
mitk::Point3D PointType
itk::BoundingBox< unsigned long, 3, ScalarType > BoundingBox
Standard 3D-BoundingBox typedef.
virtual void CalculateFrameGeometry()
Calculates the standard part of a BaseGeometry (IndexToWorldTransform and bounding box) around the cu...
itk::SmartPointer< Self > Pointer
virtual 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...
mitk::BoundingBox::Pointer m_ParametricBoundingBox
virtual bool IsValid() const
Is this BaseGeometry in a state that is valid?
virtual const itk::Transform< mitk::ScalarType, 3, 3 > * GetParametricTransform() const
double ScalarType
static Pointer New()
void Initialize()
Initialize the BaseGeometry.
virtual void IndexToWorld(const mitk::Point2D &pt_units, mitk::Point2D &pt_mm) const override
Pointer Clone() const
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.
virtual void WorldToIndex(const mitk::Point2D &pt_mm, mitk::Point2D &pt_units) const override
const BoundingBox::BoundsArrayType & GetParametricBounds() const
Get the parametric bounds.
#define MITK_WARN
Definition: mitkLogMacros.h:23
virtual bool Project(const mitk::Point3D &pt3d_mm, mitk::Point3D &projectedPt3d_mm) const override
projects the given point onto the curved plane
#define mitkThrow()
virtual itk::LightObject::Pointer InternalClone() const override
clones the geometry
void vtk2itk(const Tin &in, Tout &out)
Describes a geometry defined by an vtkAbstractTransform and a plane.
virtual void SetParametricBounds(const BoundingBox::BoundsArrayType &bounds)
Set the parametric bounds.
virtual unsigned long GetMTime() const override
void itk2vtk(const Tin &in, Tout &out)
itk::VtkAbstractTransform< ScalarType >::Pointer m_ItkVtkAbstractTransform
mitk::ScalarType GetParametricExtent(int direction) const
Get the parametric extent.
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 ...
virtual mitk::ScalarType GetParametricExtentInMM(int direction) const
virtual vtkAbstractTransform * GetVtkAbstractTransform() const
Get the vtkAbstractTransform (stored in m_VtkAbstractTransform)
Describes a two-dimensional, rectangular plane.
Pointer Clone() const
virtual 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.
BoundingBoxType::BoundsArrayType BoundsArrayType
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.