Commit 059578e6 authored by Thomas Gubler's avatar Thomas Gubler Committed by Thomas Gubler

[Survey transects generation] add basic implementation for handling

multiple polygons

need to fully implement vertexvisibility
parent d03dbb93
......@@ -1115,7 +1115,7 @@ void SurveyComplexItem::_rebuildTransectsPhase1Worker(bool refly)
}
// Create list of separate polygons
QList<QPolygonF> polygons;
QList<QPolygonF> polygons{};
_PolygonDecomposeConvex(polygon, polygons);
// iterate over polygons
......@@ -1124,13 +1124,91 @@ void SurveyComplexItem::_rebuildTransectsPhase1Worker(bool refly)
p << p.front();
// build transects for this polygon
// TODO figure out tangent origin
qCDebug(SurveyComplexItemLog) << "Transects from polynom p " << p;
_rebuildTranscetsFromPolygon(refly, p, tangentOrigin);
}
}
void SurveyComplexItem::_PolygonDecomposeConvex(const QPolygonF& polygon, QList<QPolygonF>& polygons)
void SurveyComplexItem::_PolygonDecomposeConvex(const QPolygonF& polygon, QList<QPolygonF>& decomposedPolygons)
{
polygons << polygon;
qCDebug(SurveyComplexItemLog) << "_PolygonDecomposeConvex polygon.size() " << polygon.size();
if (polygon.size() < 3) return;
int decompSize = std::numeric_limits<int>::max();
QList<QPolygonF> decomposedPolygonsMin{};
for (auto vertex = polygon.begin(); vertex != polygon.end(); ++vertex)
{
// is vertex reflex?
auto vertexBefore = vertex == polygon.begin() ? polygon.end() - 1 : vertex - 1;
auto vertexAfter = vertex == polygon.end() -1 ? polygon.begin() : vertex + 1;
auto area = (((vertex->x() - vertexBefore->x())*(vertexAfter->y() - vertexBefore->y()))-((vertexAfter->x() - vertexBefore->x())*(vertex->y() - vertexBefore->y())));
bool vertexIsReflex = area > 0;
qCDebug(SurveyComplexItemLog) << "area " << area << " vertexIsReflex " << vertexIsReflex;
if (!vertexIsReflex) continue;
for (auto vertexOther = polygon.begin(); vertexOther != polygon.end(); ++vertexOther)
{
if (vertexOther == vertex) continue;
bool canSee = _VertexCanSeeOther(polygon, vertex, vertexOther);
if (!canSee) continue;
QPolygonF polyLeft;
auto v = vertex;
while ( v != vertexOther) {
polyLeft << *v;
++v;
if (v == polygon.end()) v = polygon.begin();
}
polyLeft << *vertexOther;
qCDebug(SurveyComplexItemLog) << "polyLeft.size() " << polyLeft.size();
QPolygonF polyRight;
v = vertexOther;
while ( v != vertex) {
polyRight << *v;
++v;
if (v == polygon.end()) v = polygon.begin();
}
polyRight << *vertex;
qCDebug(SurveyComplexItemLog) << "polyRight.size() " << polyRight.size();
// recursion
QList<QPolygonF> polyLeftDecomposed{};
_PolygonDecomposeConvex(polyLeft, polyLeftDecomposed);
QList<QPolygonF> polyRightDecomposed{};
_PolygonDecomposeConvex(polyRight, polyRightDecomposed);
// compositon
if (polyLeftDecomposed.size() + polyRightDecomposed.size() < decompSize) {
decompSize = polyLeftDecomposed.size() + polyRightDecomposed.size();
decomposedPolygonsMin = polyLeftDecomposed + polyRightDecomposed;
qCDebug(SurveyComplexItemLog) << "changing decomposedPolygonsMin";
}
else {
qCDebug(SurveyComplexItemLog) << "NOT changing decomposedPolygonsMin";
}
}
}
// assemble output
if (decomposedPolygonsMin.size() > 0) {
qCDebug(SurveyComplexItemLog) << "use decomposed polygon, decomposedPolygonsMin.size() " << decomposedPolygonsMin.size();
decomposedPolygons << decomposedPolygonsMin;
} else {
qCDebug(SurveyComplexItemLog) << "use default polygon";
decomposedPolygons << polygon;
}
}
bool SurveyComplexItem::_VertexCanSeeOther(const QPolygonF& polygon, const QPointF* VertexA, const QPointF* VertexB) {
if (VertexA == VertexB) return false;
if (VertexA + 1 == VertexB) return false;
if (VertexA - 1 == VertexB) return false;
return true;
}
void SurveyComplexItem::_rebuildTranscetsFromPolygon(bool refly, const QPolygonF& polygon, const QGeoCoordinate& tangentOrigin)
......@@ -1301,6 +1379,7 @@ void SurveyComplexItem::_rebuildTranscetsFromPolygon(bool refly, const QPolygonF
_transects.append(coordInfoTransect);
}
qCDebug(SurveyComplexItemLog) << "_transects.size() " << _transects.size();
}
void SurveyComplexItem::_rebuildTransectsPhase2(void)
......
......@@ -113,7 +113,10 @@ private:
void _rebuildTransectsPhase1Worker(bool refly);
/// Adds to the _transects array from one polygon
void _rebuildTranscetsFromPolygon(bool refly, const QPolygonF& polygon, const QGeoCoordinate& tangentOrigin);
void _PolygonDecomposeConvex(const QPolygonF& polygon, QList<QPolygonF>& polygons);
// Decompose polygon into list of convex sub polygons
void _PolygonDecomposeConvex(const QPolygonF& polygon, QList<QPolygonF>& decomposedPolygons);
// return true if vertex a can see vertex b
bool _VertexCanSeeOther(const QPolygonF& polygon, const QPointF* VertexA, const QPointF* VertexB);
QMap<QString, FactMetaData*> _metaDataMap;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment