From 3dc8a350976d51a7a8e35ed114897bcc873a3ea4 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Wed, 4 Jun 2014 14:21:16 +0200
Subject: [PATCH] [GeoLib] Impl. of computeAndInsertAllIntersectionPoints().

Conflicts:
	GeoLib/AnalyticalGeometry.cpp
---
 GeoLib/AnalyticalGeometry.cpp | 24 +++++++++++++++++++++++-
 GeoLib/AnalyticalGeometry.h   | 11 +++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp
index 37771bc670b..15d5275f0dc 100644
--- a/GeoLib/AnalyticalGeometry.cpp
+++ b/GeoLib/AnalyticalGeometry.cpp
@@ -155,7 +155,7 @@ bool lineSegmentIntersect(
 	return false;
 }
 
-bool lineSegmentsIntersect(const GeoLib::Polyline* ply, 
+bool lineSegmentsIntersect(const GeoLib::Polyline* ply,
                             size_t &idx0,
                             size_t &idx1,
                            GeoLib::Point& intersection_pnt)
@@ -435,4 +435,26 @@ bool isCoplanar(const GeoLib::Point& a, const GeoLib::Point& b, const GeoLib::Po
 	return (sqr_scalar_triple/normalisation_factor < 1e-11);
 }
 
+void computeAndInsertAllIntersectionPoints(GeoLib::PointVec &pnt_vec,
+	std::vector<GeoLib::Polyline*> & plys)
+{
+	for (auto it0(plys.begin()); it0 != plys.end(); it0++) {
+		auto it1(it0);
+		it1++;
+		for (; it1 != plys.end(); it1++) {
+			GeoLib::Point s;
+			for (std::size_t i(0); i<(*it0)->getNumberOfPoints()-1; i++) {
+				for (std::size_t j(0); j<(*it1)->getNumberOfPoints()-1; j++) {
+					if (lineSegmentIntersect(*(*it0)->getPoint(i), *(*it0)->getPoint(i+1),
+						*(*it1)->getPoint(j), *(*it1)->getPoint(j+1), s)) {
+						std::size_t const id(pnt_vec.push_back(new GeoLib::Point(s)));
+						(*it0)->insertPoint(i+1, id);
+						(*it1)->insertPoint(j+1, id);
+					}
+				}
+			}
+		}
+	}
+}
+
 } // end namespace GeoLib
diff --git a/GeoLib/AnalyticalGeometry.h b/GeoLib/AnalyticalGeometry.h
index 9aed682d823..41033c45cc2 100644
--- a/GeoLib/AnalyticalGeometry.h
+++ b/GeoLib/AnalyticalGeometry.h
@@ -17,6 +17,7 @@
 
 // GeoLib
 #include "Triangle.h"
+#include "PointVec.h"
 
 // MathLib
 #include "LinAlg/Dense/DenseMatrix.h"
@@ -166,6 +167,16 @@ double scalarTriple(MathLib::Vector3 const& u, MathLib::Vector3 const& v, MathLi
 	 const GeoLib::Point& c, const GeoLib::Point& d);
 
 
+/**
+ * Method first compute the intersection points of line segements of GeoLib::Polyline objects
+ * (@see computeIntersectionPoints()) and pushs each intersection point in the GeoLib::PointVec
+ * pnt_vec. For each intersection an id is returned.  This id is used to split the two
+ * intersecting straight line segments in four straight line segments.
+ */
+void computeAndInsertAllIntersectionPoints(
+	GeoLib::PointVec &pnt_vec,
+	std::vector<GeoLib::Polyline*> & plys);
+
 } // end namespace GeoLib
 
 #endif /* ANALYTICAL_GEOMETRY_H_ */
-- 
GitLab