25 : FEATURE_ID_CIRCUMFERENCE(this->AddFeature(
"Circumference",
"mm")), FEATURE_ID_AREA(this->AddFeature(
"Area",
"mm2"))
43 this->SetFeatureName(FEATURE_ID_CIRCUMFERENCE,
"Length");
44 this->DeactivateFeature(FEATURE_ID_AREA);
49 this->SetFeatureName(FEATURE_ID_CIRCUMFERENCE,
"Circumference");
50 this->ActivateFeature(FEATURE_ID_AREA);
58 this->ClearPolyLines();
60 for (ControlPointListType::size_type i = 0; i < m_ControlPoints.size(); ++i)
61 this->AppendPointToPolyLine(0, this->GetControlPoint(i));
72 double circumference = 0.0;
80 for (i = 0; i < (polyLine.size() - 1); ++i)
82 circumference +=
static_cast<Point2D>(polyLine[i]).EuclideanDistanceTo(static_cast<Point2D>(polyLine[i + 1]));
87 circumference +=
static_cast<Point2D>(polyLine[i]).EuclideanDistanceTo(static_cast<Point2D>(polyLine.front()));
90 this->SetQuantity(FEATURE_ID_CIRCUMFERENCE, circumference);
94 bool intersection =
false;
96 if (this->IsClosed() && (this->GetPlaneGeometry() !=
nullptr))
99 const unsigned int numberOfPoints = polyLine.size();
100 if (numberOfPoints >= 4)
102 for (i = 0; i < (numberOfPoints - 1); ++i)
105 const Point2D p0 = polyLine[i];
106 const Point2D p1 = polyLine[i + 1];
109 for (j = i + 1; j < (numberOfPoints - 1); ++j)
111 const Point2D p2 = polyLine[j];
112 const Point2D p3 = polyLine[j + 1];
113 intersection = CheckForLineIntersection(p0, p1, p2, p3);
121 const Point2D p2 = polyLine.front();
122 const Point2D p3 = polyLine.back();
124 intersection = CheckForLineIntersection(p0, p1, p2, p3);
131 for (i = 0; i < polyLine.size(); ++i)
133 const Point2D p0 = polyLine[i];
134 const Point2D p1 = polyLine[(i + 1) % polyLine.size()];
136 area += p0[0] * p1[1] - p1[0] * p0[1];
142 if (this->IsClosed() && !intersection)
144 SetQuantity(FEATURE_ID_AREA, fabs(area));
145 this->ActivateFeature(FEATURE_ID_AREA);
149 SetQuantity(FEATURE_ID_AREA, 0);
150 this->DeactivateFeature(FEATURE_ID_AREA);
156 Superclass::PrintSelf(os, indent);
158 if (this->IsClosed())
159 os << indent <<
"Polygon is closed\n";
161 os << indent <<
"Polygon is not closed\n";
173 if (p1 == p2 || p1 == p3 || p1 == p4 || p2 == p3 || p2 == p4 || p3 == p4)
178 const double x1 = p1[0], x2 = p2[0], x3 = p3[0], x4 = p4[0];
179 const double y1 = p1[1], y2 = p2[1], y3 = p3[1], y4 = p4[1];
181 const double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
188 const double pre = (x1 * y2 - y1 * x2);
189 const double post = (x3 * y4 - y3 * x4);
190 const double x = (pre * (x3 - x4) - (x1 - x2) * post) / d;
191 const double y = (pre * (y3 - y4) - (y1 - y2) * post) / d;
193 double tolerance = 0.001;
195 if (x < (
std::min(x1, x2) - tolerance) || x > (
std::max(x1, x2) + tolerance) || x < (
std::min(x3, x4) - tolerance) ||
202 if (y < (
std::min(y1, y2) - tolerance) || y > (
std::max(y1, y2) + tolerance) || y < (
std::min(y3, y4) - tolerance) ||
228 std::vector<mitk::Point2D> intersectionList;
232 for (
auto iter = tempList.cbegin(); iter != tempList.cend(); ++iter)
234 polyLinePoints.push_back(*iter);
237 for (ControlPointListType::size_type i = 0; i < polyLinePoints.size() - 1; i++)
245 intersectionList.push_back(intersection);
249 if (this->IsClosed())
252 const mitk::Point2D lastControlPoint = polyLinePoints.back();
253 const mitk::Point2D firstControlPoint = polyLinePoints.front();
257 intersectionList.push_back(intersection);
261 return intersectionList;
269 return Superclass::Equals(other);
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...
virtual void SetClosed(bool closed)
Set whether the polygon should be closed between first and last control point or not.
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const override
virtual void GeneratePolyLine() override
Generates the poly-line representation of the planar figure.
Implementation of PlanarFigure representing a polygon with two or more control points.
void SetProperty(const char *propertyKey, BaseProperty *property)
virtual void EvaluateFeaturesInternal() override
Calculates feature quantities of the planar figure.
std::vector< mitk::Point2D > CheckForLineIntersection(const Point2D &p1, const Point2D &p2) const