21 : FEATURE_ID_CIRCUMFERENCE(this->AddFeature(
"Circumference",
"mm")), FEATURE_ID_AREA(this->AddFeature(
"Area",
"mm2"))
56 for (ControlPointListType::size_type i = 0; i <
m_ControlPoints.size(); ++i)
68 double circumference = 0.0;
76 for (i = 0; i < (polyLine.size() - 1); ++i)
78 circumference +=
static_cast<Point2D>(polyLine[i]).EuclideanDistanceTo(static_cast<Point2D>(polyLine[i + 1]));
83 circumference +=
static_cast<Point2D>(polyLine[i]).EuclideanDistanceTo(static_cast<Point2D>(polyLine.front()));
90 bool intersection =
false;
95 const unsigned int numberOfPoints = polyLine.size();
96 if (numberOfPoints >= 4)
98 for (i = 0; i < (numberOfPoints - 1); ++i)
101 const Point2D p0 = polyLine[i];
102 const Point2D p1 = polyLine[i + 1];
105 for (j = i + 1; j < (numberOfPoints - 1); ++j)
107 const Point2D p2 = polyLine[j];
108 const Point2D p3 = polyLine[j + 1];
117 const Point2D p2 = polyLine.front();
118 const Point2D p3 = polyLine.back();
127 for (i = 0; i < polyLine.size(); ++i)
129 const Point2D p0 = polyLine[i];
130 const Point2D p1 = polyLine[(i + 1) % polyLine.size()];
132 area += p0[0] * p1[1] - p1[0] * p0[1];
138 if (this->
IsClosed() && !intersection)
152 Superclass::PrintSelf(os, indent);
155 os << indent <<
"Polygon is closed\n";
157 os << indent <<
"Polygon is not closed\n";
169 if (p1 == p2 || p1 == p3 || p1 == p4 || p2 == p3 || p2 == p4 || p3 == p4)
174 const double x1 = p1[0], x2 = p2[0], x3 = p3[0], x4 = p4[0];
175 const double y1 = p1[1], y2 = p2[1], y3 = p3[1], y4 = p4[1];
177 const double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
184 const double pre = (x1 * y2 - y1 * x2);
185 const double post = (x3 * y4 - y3 * x4);
186 const double x = (pre * (x3 - x4) - (x1 - x2) * post) / d;
187 const double y = (pre * (y3 - y4) - (y1 - y2) * post) / d;
189 double tolerance = 0.001;
191 if (x < (
std::min(x1, x2) - tolerance) || x > (
std::max(x1, x2) + tolerance) || x < (
std::min(x3, x4) - tolerance) ||
198 if (y < (
std::min(y1, y2) - tolerance) || y > (
std::max(y1, y2) + tolerance) || y < (
std::min(y3, y4) - tolerance) ||
224 std::vector<mitk::Point2D> intersectionList;
228 for (
auto iter = tempList.cbegin(); iter != tempList.cend(); ++iter)
230 polyLinePoints.push_back(*iter);
233 for (ControlPointListType::size_type i = 0; i < polyLinePoints.size() - 1; i++)
241 intersectionList.push_back(intersection);
248 const mitk::Point2D lastControlPoint = polyLinePoints.back();
249 const mitk::Point2D firstControlPoint = polyLinePoints.front();
253 intersectionList.push_back(intersection);
257 return intersectionList;
265 return Superclass::Equals(other);
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...
virtual void SetClosed(bool closed)
Set whether the polygon should be closed between first and last control point or not.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void GeneratePolyLine() override
Generates the poly-line representation of the planar figure.
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
Implementation of PlanarFigure representing a polygon with two or more control points.
const unsigned int FEATURE_ID_CIRCUMFERENCE
const unsigned int FEATURE_ID_AREA
void EvaluateFeaturesInternal() override
Calculates feature quantities of the planar figure.
std::vector< mitk::Point2D > CheckForLineIntersection(const Point2D &p1, const Point2D &p2) const