Medical Imaging Interaction Toolkit  2018.4.99-08619e4f
Medical Imaging Interaction Toolkit
mitkPlanarLine.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 "mitkPlanarLine.h"
14 #include "mitkPlaneGeometry.h"
15 
16 mitk::PlanarLine::PlanarLine() : FEATURE_ID_LENGTH(this->AddFeature("Length", "mm"))
17 {
18  // Line has two control points
20 
21  this->SetNumberOfPolyLines(1);
22 }
23 
25 {
26  this->ClearPolyLines();
27 
28  this->AppendPointToPolyLine(0, this->GetControlPoint(0));
29  this->AppendPointToPolyLine(0, this->GetControlPoint(1));
30 }
31 
32 void mitk::PlanarLine::GenerateHelperPolyLine(double /*mmPerDisplayUnit*/, unsigned int /*displayHeight*/)
33 {
34  // A line does not require a helper object
35 }
36 
38 {
39  // Calculate line length
40  const Point3D &p0 = this->GetWorldControlPoint(0);
41  const Point3D &p1 = this->GetWorldControlPoint(1);
42  double length = p0.EuclideanDistanceTo(p1);
43 
44  this->SetQuantity(FEATURE_ID_LENGTH, length);
45 }
46 
47 void mitk::PlanarLine::PrintSelf(std::ostream &os, itk::Indent indent) const
48 {
49  Superclass::PrintSelf(os, indent);
50 }
51 
52 bool mitk::PlanarLine::Equals(const PlanarFigure &other) const
53 {
54  const auto *otherLine = dynamic_cast<const mitk::PlanarLine *>(&other);
55  if (otherLine)
56  {
57  return Superclass::Equals(other);
58  }
59  else
60  {
61  return false;
62  }
63 }
Point2D GetControlPoint(unsigned int index) const
Returns specified control point in 2D world coordinates.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Point3D GetWorldControlPoint(unsigned int index) const
Returns specified control point in world coordinates.
void ResetNumberOfControlPoints(int numberOfControlPoints)
Set the initial number of control points of the planar figure.
const unsigned int FEATURE_ID_LENGTH
bool Equals(const mitk::PlanarFigure &other) const override
Compare two PlanarFigure objects Note: all subclasses have to implement the method on their own...
void EvaluateFeaturesInternal() override
Calculates feature quantities of the planar figure.
void SetQuantity(unsigned int index, double quantity)
void GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight) override
Generates the poly-lines that should be drawn the same size regardless of zoom.
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
Implementation of PlanarFigure representing a line through two control points.
Base-class for geometric planar (2D) figures, such as lines, circles, rectangles, polygons...
void ClearPolyLines()
clears the list of PolyLines. Call before re-calculating a new Polyline.
void GeneratePolyLine() override
Generates the poly-line representation of the planar figure.