Medical Imaging Interaction Toolkit  2016.11.0
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,
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 "mitkPlaneGeometry.h"
19 
20 mitk::PlanarFourPointAngle::PlanarFourPointAngle() : FEATURE_ID_ANGLE(this->AddFeature("Angle", "deg"))
21 {
22  // Four point angle has two control points
24  this->SetNumberOfPolyLines(2);
25 }
26 
28 {
29  this->ClearPolyLines();
30 
31  for (unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i)
32  this->AppendPointToPolyLine(i / 2, this->GetControlPoint(i));
33 }
34 
35 void mitk::PlanarFourPointAngle::GenerateHelperPolyLine(double /*mmPerDisplayUnit*/, unsigned int /*displayHeight*/)
36 {
37  // Generate helper-poly-line for an four point angle
38  // Need to discuss a sensible implementation
39 }
40 
42 {
43  if (this->GetNumberOfControlPoints() < 4)
44  {
45  // Angle not yet complete.
46  return;
47  }
48 
49  // Calculate angle between lines
50  const Point2D &p0 = this->GetControlPoint(0);
51  const Point2D &p1 = this->GetControlPoint(1);
52  const Point2D &p2 = this->GetControlPoint(2);
53  const Point2D &p3 = this->GetControlPoint(3);
54 
55  Vector2D v0 = p1 - p0;
56  Vector2D v1 = p3 - p2;
57 
58  v0.Normalize();
59  v1.Normalize();
60  double angle = acos(v0 * v1);
61 
62  this->SetQuantity(FEATURE_ID_ANGLE, angle);
63 }
64 
65 void mitk::PlanarFourPointAngle::PrintSelf(std::ostream &os, itk::Indent indent) const
66 {
67  Superclass::PrintSelf(os, indent);
68 }
69 
71 {
72  const mitk::PlanarFourPointAngle *otherFourPtAngle = dynamic_cast<const mitk::PlanarFourPointAngle *>(&other);
73  if (otherFourPtAngle)
74  {
75  return Superclass::Equals(other);
76  }
77  else
78  {
79  return false;
80  }
81 }
Implementation of PlanarFigure representing a four point angle, which is defined by two non-intersect...
virtual 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.
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const override
virtual void EvaluateFeaturesInternal() override
Calculates feature quantities of the planar figure.
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...
virtual void GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight) override
Generates the poly-lines that should be drawn the same size regardless of zoom.
virtual bool Equals(const mitk::PlanarFigure &other) const override
Compare two PlanarFigure objects Note: all subclasses have to implement the method on their own...