Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
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 
17 #include "mitkPlanarArrow.h"
18 #include "mitkPlaneGeometry.h"
19 
20 mitk::PlanarArrow::PlanarArrow() : FEATURE_ID_LENGTH(this->AddFeature("Length", "mm"))
21 {
22  // Directed arrow has two control points
24  m_ArrowTipScaleFactor = -1.0;
25 
26  this->SetNumberOfPolyLines(1);
28 
29  // Create helper polyline object (for drawing the orthogonal orientation line)
30  m_HelperPolyLinesToBePainted->InsertElement(0, false);
31  m_HelperPolyLinesToBePainted->InsertElement(1, false);
32 }
33 
35 {
36  this->ClearPolyLines();
37 
38  this->AppendPointToPolyLine(0, this->GetControlPoint(0));
39  this->AppendPointToPolyLine(0, this->GetControlPoint(1));
40 }
41 
42 void mitk::PlanarArrow::GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight)
43 {
44  // Generate helper polyline (orientation line orthogonal to first line)
45  // if the third control point is currently being set
46  if (this->GetNumberOfControlPoints() != 2)
47  {
48  m_HelperPolyLinesToBePainted->SetElement(0, false);
49  m_HelperPolyLinesToBePainted->SetElement(1, false);
50 
51  return;
52  }
53 
54  this->ClearHelperPolyLines();
55 
56  m_HelperPolyLinesToBePainted->SetElement(0, true);
57  m_HelperPolyLinesToBePainted->SetElement(1, true);
58 
59  // Fixed size depending on screen size for the angle
60  float scaleFactor = 0.015;
61  if (m_ArrowTipScaleFactor > 0.0)
62  {
63  scaleFactor = m_ArrowTipScaleFactor;
64  }
65  double nonScalingLength = displayHeight * mmPerDisplayUnit * scaleFactor;
66 
67  // Calculate arrow peak
68  const Point2D p1 = this->GetControlPoint(0);
69  const Point2D p2 = this->GetControlPoint(1);
70 
71  Vector2D n1 = p1 - p2;
72  n1.Normalize();
73 
74  double degrees = 100.0;
75  Vector2D temp;
76  temp[0] = n1[0] * cos(degrees) - n1[1] * sin(degrees);
77  temp[1] = n1[0] * sin(degrees) + n1[1] * cos(degrees);
78  Vector2D temp2;
79  temp2[0] = n1[0] * cos(-degrees) - n1[1] * sin(-degrees);
80  temp2[1] = n1[0] * sin(-degrees) + n1[1] * cos(-degrees);
81 
82  this->AppendPointToHelperPolyLine(0, p1);
83  this->AppendPointToHelperPolyLine(0, Point2D(p1 - temp * nonScalingLength));
84  this->AppendPointToHelperPolyLine(1, p1);
85  this->AppendPointToHelperPolyLine(1, Point2D(p1 - temp2 * nonScalingLength));
86 }
87 
89 {
90  // Calculate line length
91  const Point3D &p0 = this->GetWorldControlPoint(0);
92  const Point3D &p1 = this->GetWorldControlPoint(1);
93  double length = p0.EuclideanDistanceTo(p1);
94 
95  this->SetQuantity(FEATURE_ID_LENGTH, length);
96 }
97 
98 void mitk::PlanarArrow::PrintSelf(std::ostream &os, itk::Indent indent) const
99 {
100  Superclass::PrintSelf(os, indent);
101 }
102 
104 {
105  m_ArrowTipScaleFactor = scale;
106 }
107 
109 {
110  const mitk::PlanarArrow *otherArrow = dynamic_cast<const mitk::PlanarArrow *>(&other);
111  if (otherArrow)
112  {
113  if (std::abs(this->m_ArrowTipScaleFactor - otherArrow->m_ArrowTipScaleFactor) > mitk::eps)
114  return false;
115 
116  return Superclass::Equals(other);
117  }
118  else
119  {
120  return false;
121  }
122 }
Point< ScalarType, 2 > Point2D
Definition: mitkPoint.h:98
virtual 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.
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const override
void SetArrowTipScaleFactor(float scale)
void SetNumberOfHelperPolyLines(unsigned int numberOfHelperPolyLines)
defines the number of HelperPolyLines that will be available
virtual void GeneratePolyLine() override
Generates the poly-line representation 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 EvaluateFeaturesInternal() override
Calculates feature quantities of the planar figure.
BoolContainerType::Pointer m_HelperPolyLinesToBePainted
MITKCORE_EXPORT const ScalarType eps
virtual bool Equals(const mitk::PlanarFigure &other) const override
Compare two PlanarFigure objects Note: all subclasses have to implement the method on their own...
Implementation of PlanarFigure representing an arrow through two control points.