Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPlanarArrow.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 
13 #include "mitkPlanarArrow.h"
14 #include "mitkPlaneGeometry.h"
15 
16 mitk::PlanarArrow::PlanarArrow() : FEATURE_ID_LENGTH(this->AddFeature("Length", "mm"))
17 {
18  // Directed arrow has two control points
20  m_ArrowTipScaleFactor = -1.0;
21 
22  this->SetNumberOfPolyLines(1);
24 
25  // Create helper polyline object (for drawing the orthogonal orientation line)
26  m_HelperPolyLinesToBePainted->InsertElement(0, false);
27  m_HelperPolyLinesToBePainted->InsertElement(1, false);
28 }
29 
31 {
32  this->ClearPolyLines();
33 
34  this->AppendPointToPolyLine(0, this->GetControlPoint(0));
35  this->AppendPointToPolyLine(0, this->GetControlPoint(1));
36 }
37 
38 void mitk::PlanarArrow::GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight)
39 {
40  // Generate helper polyline (orientation line orthogonal to first line)
41  // if the third control point is currently being set
42  if (this->GetNumberOfControlPoints() != 2)
43  {
44  m_HelperPolyLinesToBePainted->SetElement(0, false);
45  m_HelperPolyLinesToBePainted->SetElement(1, false);
46 
47  return;
48  }
49 
50  this->ClearHelperPolyLines();
51 
52  m_HelperPolyLinesToBePainted->SetElement(0, true);
53  m_HelperPolyLinesToBePainted->SetElement(1, true);
54 
55  // Fixed size depending on screen size for the angle
56  float scaleFactor = 0.015;
57  if (m_ArrowTipScaleFactor > 0.0)
58  {
59  scaleFactor = m_ArrowTipScaleFactor;
60  }
61  double nonScalingLength = displayHeight * mmPerDisplayUnit * scaleFactor;
62 
63  // Calculate arrow peak
64  const Point2D p1 = this->GetControlPoint(0);
65  const Point2D p2 = this->GetControlPoint(1);
66 
67  Vector2D n1 = p1 - p2;
68  n1.Normalize();
69 
70  double degrees = 100.0;
71  Vector2D temp;
72  temp[0] = n1[0] * cos(degrees) - n1[1] * sin(degrees);
73  temp[1] = n1[0] * sin(degrees) + n1[1] * cos(degrees);
74  Vector2D temp2;
75  temp2[0] = n1[0] * cos(-degrees) - n1[1] * sin(-degrees);
76  temp2[1] = n1[0] * sin(-degrees) + n1[1] * cos(-degrees);
77 
78  this->AppendPointToHelperPolyLine(0, p1);
79  this->AppendPointToHelperPolyLine(0, Point2D(p1 - temp * nonScalingLength));
80  this->AppendPointToHelperPolyLine(1, p1);
81  this->AppendPointToHelperPolyLine(1, Point2D(p1 - temp2 * nonScalingLength));
82 }
83 
85 {
86  // Calculate line length
87  const Point3D &p0 = this->GetWorldControlPoint(0);
88  const Point3D &p1 = this->GetWorldControlPoint(1);
89  double length = p0.EuclideanDistanceTo(p1);
90 
91  this->SetQuantity(FEATURE_ID_LENGTH, length);
92 }
93 
94 void mitk::PlanarArrow::PrintSelf(std::ostream &os, itk::Indent indent) const
95 {
96  Superclass::PrintSelf(os, indent);
97 }
98 
100 {
101  m_ArrowTipScaleFactor = scale;
102 }
103 
105 {
106  const auto *otherArrow = dynamic_cast<const mitk::PlanarArrow *>(&other);
107  if (otherArrow)
108  {
109  if (std::abs(this->m_ArrowTipScaleFactor - otherArrow->m_ArrowTipScaleFactor) > mitk::eps)
110  return false;
111 
112  return Superclass::Equals(other);
113  }
114  else
115  {
116  return false;
117  }
118 }
Point< ScalarType, 2 > Point2D
Definition: mitkPoint.h:94
Point2D GetControlPoint(unsigned int index) const
Returns specified control point in 2D world coordinates.
Point3D GetWorldControlPoint(unsigned int index) const
Returns specified control point in world coordinates.
void GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight) override
Generates the poly-lines that should be drawn the same size regardless of zoom.
void ResetNumberOfControlPoints(int numberOfControlPoints)
Set the initial number of control points of the planar figure.
const unsigned int FEATURE_ID_LENGTH
void PrintSelf(std::ostream &os, itk::Indent indent) const override
unsigned int GetNumberOfControlPoints() const
Returns the current number of 2D control points defining this figure.
void SetQuantity(unsigned int index, double quantity)
void SetArrowTipScaleFactor(float scale)
void SetNumberOfHelperPolyLines(unsigned int numberOfHelperPolyLines)
defines the number of HelperPolyLines that will be available
void GeneratePolyLine() override
Generates the poly-line representation 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 AppendPointToHelperPolyLine(unsigned int index, PolyLineElement element)
Append a point to the HelperPolyLine # index.
void EvaluateFeaturesInternal() override
Calculates feature quantities of the planar figure.
void ClearHelperPolyLines()
clears the list of HelperPolyLines. Call before re-calculating a new HelperPolyline.
BoolContainerType::Pointer m_HelperPolyLinesToBePainted
MITKCORE_EXPORT const ScalarType eps
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.
Implementation of PlanarFigure representing an arrow through two control points.