Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPlanarFourPointAngle.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 "mitkPlaneGeometry.h"
15 
16 mitk::PlanarFourPointAngle::PlanarFourPointAngle() : FEATURE_ID_ANGLE(this->AddFeature("Angle", "deg"))
17 {
18  // Four point angle has two control points
20  this->SetNumberOfPolyLines(2);
21 }
22 
24 {
25  this->ClearPolyLines();
26 
27  for (unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i)
28  this->AppendPointToPolyLine(i / 2, this->GetControlPoint(i));
29 }
30 
31 void mitk::PlanarFourPointAngle::GenerateHelperPolyLine(double /*mmPerDisplayUnit*/, unsigned int /*displayHeight*/)
32 {
33  // Generate helper-poly-line for an four point angle
34  // Need to discuss a sensible implementation
35 }
36 
38 {
39  if (this->GetNumberOfControlPoints() < 4)
40  {
41  // Angle not yet complete.
42  return;
43  }
44 
45  // Calculate angle between lines
46  const Point2D &p0 = this->GetControlPoint(0);
47  const Point2D &p1 = this->GetControlPoint(1);
48  const Point2D &p2 = this->GetControlPoint(2);
49  const Point2D &p3 = this->GetControlPoint(3);
50 
51  Vector2D v0 = p1 - p0;
52  Vector2D v1 = p3 - p2;
53 
54  v0.Normalize();
55  v1.Normalize();
56  double angle = acos(v0 * v1);
57 
58  this->SetQuantity(FEATURE_ID_ANGLE, angle);
59 }
60 
61 void mitk::PlanarFourPointAngle::PrintSelf(std::ostream &os, itk::Indent indent) const
62 {
63  Superclass::PrintSelf(os, indent);
64 }
65 
67 {
68  const auto *otherFourPtAngle = dynamic_cast<const mitk::PlanarFourPointAngle *>(&other);
69  if (otherFourPtAngle)
70  {
71  return Superclass::Equals(other);
72  }
73  else
74  {
75  return false;
76  }
77 }
Implementation of PlanarFigure representing a four point angle, which is defined by two non-intersect...
Point2D GetControlPoint(unsigned int index) const
Returns specified control point in 2D world coordinates.
void GeneratePolyLine() override
Generates the poly-line representation of the planar figure.
void ResetNumberOfControlPoints(int numberOfControlPoints)
Set the initial number of control points of the planar figure.
unsigned int GetNumberOfControlPoints() const
Returns the current number of 2D control points defining this figure.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void SetQuantity(unsigned int index, double quantity)
void EvaluateFeaturesInternal() override
Calculates feature quantities of the planar figure.
void AppendPointToPolyLine(unsigned int index, PolyLineElement element)
Append a point to the PolyLine # index.
void SetNumberOfPolyLines(unsigned int numberOfPolyLines)
defines the number of PolyLines that will be available
Base-class for geometric planar (2D) figures, such as lines, circles, rectangles, polygons...
void GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight) override
Generates the poly-lines that should be drawn the same size regardless of zoom.
bool Equals(const mitk::PlanarFigure &other) const override
Compare two PlanarFigure objects Note: all subclasses have to implement the method on their own...
void ClearPolyLines()
clears the list of PolyLines. Call before re-calculating a new Polyline.