From a49d0a64a8cd5cc1629f7622fdda64c68871884c Mon Sep 17 00:00:00 2001
From: rinkk <karsten.rink@ufz.de>
Date: Mon, 21 Jun 2021 17:55:25 +0200
Subject: [PATCH] [T/MGTL] Ear clipping algorithm test.

---
 Tests/Data/MeshGeoToolsLib/buildings.gml  | 97 +++++++++++++++++++++++
 Tests/MeshGeoToolsLib/TestEarClipping.cpp | 40 ++++++++++
 2 files changed, 137 insertions(+)
 create mode 100644 Tests/Data/MeshGeoToolsLib/buildings.gml
 create mode 100644 Tests/MeshGeoToolsLib/TestEarClipping.cpp

diff --git a/Tests/Data/MeshGeoToolsLib/buildings.gml b/Tests/Data/MeshGeoToolsLib/buildings.gml
new file mode 100644
index 00000000000..60e727f3368
--- /dev/null
+++ b/Tests/Data/MeshGeoToolsLib/buildings.gml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE OGS-GML-DOM>
+<OpenGeoSysGLI xmlns:ogs="http://www.opengeosys.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <name>LoD1_2018_Kiel_Wik</name>
+    <points>
+        <point z="22.208046813563303" id="0" x="571440.166000000201166" y="6023632.926000000908971"/>
+        <point z="22.176822661386318" id="1" x="571437.066999999806285" y="6023626.228000000119209"/>
+        <point z="22.161308615105252" id="2" x="571430.379999999888241" y="6023629.316999999806285"/>
+        <point z="22.178974183800690" id="3" x="571431.959999999962747" y="6023632.745999999344349"/>
+        <point z="22.178808808928917" id="4" x="571431.839999999850988" y="6023632.796000000089407"/>
+        <point z="22.196328171633077" id="5" x="571433.408999999985099" y="6023636.195000000298023"/>
+        <point z="22.200408563065608" id="6" x="571436.787999999709427" y="6023634.634999999776483"/>
+        <point z="22.199776427109640" id="7" x="571436.728000000119209" y="6023634.515000000596046"/>
+        <point z="24.733219793371745" id="8" x="571930.470999999903142" y="6023638.054999999701977"/>
+        <point z="24.740857252115191" id="9" x="571925.502000000327826" y="6023623.051000000908971"/>
+        <point z="24.627243818959077" id="10" x="571914.946999999694526" y="6023626.539999999105930"/>
+        <point z="24.619398564206115" id="11" x="571919.924999999813735" y="6023641.623999999836087"/>
+        <point z="24.718552022201756" id="12" x="571929.111999999731779" y="6023638.515000000596046"/>
+        <point z="23.711276083481081" id="13" x="571766.394000000320375" y="6023793.335000000894070"/>
+        <point z="23.709484402211626" id="14" x="571763.165000000037253" y="6023783.969000000506639"/>
+        <point z="23.705219940274340" id="15" x="571762.655000000260770" y="6023784.149000000208616"/>
+        <point z="23.704216089170309" id="16" x="571762.894999999552965" y="6023785.319000000134110"/>
+        <point z="23.654953182533482" id="17" x="571756.997000000439584" y="6023787.378000000491738"/>
+        <point z="23.654610694424896" id="18" x="571756.597000000067055" y="6023786.267999999225140"/>
+        <point z="23.613201142567455" id="19" x="571751.639000000432134" y="6023787.997999999672174"/>
+        <point z="23.615045165139271" id="20" x="571754.859000000171363" y="6023797.313999999314547"/>
+        <point z="26.454570175425985" id="21" x="572061.082000000402331" y="6023716.508999999612570"/>
+        <point z="26.426127646541666" id="22" x="572059.973000000230968" y="6023713.760999999940395"/>
+        <point z="26.420981500007503" id="23" x="572059.492999999783933" y="6023713.960000000894070"/>
+        <point z="26.303910394481314" id="24" x="572054.953999999910593" y="6023702.585000000894070"/>
+        <point z="26.309051380803293" id="25" x="572055.434000000357628" y="6023702.384999999776483"/>
+        <point z="26.281136612067392" id="26" x="572054.354000000283122" y="6023699.666999999433756"/>
+        <point z="26.275861860773826" id="27" x="572053.864000000059605" y="6023699.866000000387430"/>
+        <point z="26.143583982176324" id="28" x="572048.735999999567866" y="6023687.012000000104308"/>
+        <point z="26.148801971145517" id="29" x="572049.225999999791384" y="6023686.801999999210238"/>
+        <point z="26.119903204138126" id="30" x="572048.105999999679625" y="6023683.993000000715256"/>
+        <point z="26.114633613059112" id="31" x="572047.616000000387430" y="6023684.192999999970198"/>
+        <point z="26.064809049863641" id="32" x="572045.686999999918044" y="6023679.345000000670552"/>
+        <point z="25.946397873309849" id="33" x="572034.730999999679625" y="6023683.702999999746680"/>
+        <point z="26.391172698520766" id="34" x="572051.976999999955297" y="6023726.914999999105930"/>
+        <point z="26.477147865262332" id="35" x="572060.202999999746680" y="6023723.635999999940395"/>
+        <point z="26.494796173899296" id="36" x="572062.911999999545515" y="6023722.557000000029802"/>
+        <point z="26.449184840051565" id="37" x="572060.582999999634922" y="6023716.709000000730157"/>
+    </points>
+    <polylines>
+        <polyline id="0" name="228">
+            <pnt>0</pnt>
+            <pnt>1</pnt>
+            <pnt>2</pnt>
+            <pnt>3</pnt>
+            <pnt>4</pnt>
+            <pnt>5</pnt>
+            <pnt>6</pnt>
+            <pnt>7</pnt>
+            <pnt>0</pnt>
+        </polyline>
+        <polyline id="1" name="229">
+            <pnt>8</pnt>
+            <pnt>9</pnt>
+            <pnt>10</pnt>
+            <pnt>11</pnt>
+            <pnt>12</pnt>
+            <pnt>8</pnt>
+        </polyline>
+        <polyline id="2" name="230">
+            <pnt>13</pnt>
+            <pnt>14</pnt>
+            <pnt>15</pnt>
+            <pnt>16</pnt>
+            <pnt>17</pnt>
+            <pnt>18</pnt>
+            <pnt>19</pnt>
+            <pnt>20</pnt>
+            <pnt>13</pnt>
+        </polyline>
+        <polyline id="3" name="1074">
+            <pnt>21</pnt>
+            <pnt>22</pnt>
+            <pnt>23</pnt>
+            <pnt>24</pnt>
+            <pnt>25</pnt>
+            <pnt>26</pnt>
+            <pnt>27</pnt>
+            <pnt>28</pnt>
+            <pnt>29</pnt>
+            <pnt>30</pnt>
+            <pnt>31</pnt>
+            <pnt>32</pnt>
+            <pnt>33</pnt>
+            <pnt>34</pnt>
+            <pnt>35</pnt>
+            <pnt>36</pnt>
+            <pnt>37</pnt>
+            <pnt>21</pnt>
+        </polyline>
+    </polylines>
+</OpenGeoSysGLI>
diff --git a/Tests/MeshGeoToolsLib/TestEarClipping.cpp b/Tests/MeshGeoToolsLib/TestEarClipping.cpp
new file mode 100644
index 00000000000..01f9f023b1a
--- /dev/null
+++ b/Tests/MeshGeoToolsLib/TestEarClipping.cpp
@@ -0,0 +1,40 @@
+/**
+ * \copyright
+ * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ *
+ */
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <vector>
+
+#include "Applications/FileIO/Legacy/createSurface.h"
+#include "GeoLib/EarClippingTriangulation.h"
+#include "GeoLib/GEOObjects.h"
+#include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h"
+#include "GeoLib/Polyline.h"
+#include "InfoLib/TestInfo.h"
+
+TEST(TestEarClipping, TestEarClippingPolygons)
+{
+    std::string const name =
+        TestInfoLib::TestInfo::data_path + "/MeshGeoToolsLib/buildings.gml";
+    GeoLib::GEOObjects geo_objects;
+    GeoLib::IO::BoostXmlGmlInterface xml(geo_objects);
+    ASSERT_TRUE(xml.readFile(name));
+    auto geo_name = geo_objects.getGeometryNames()[0];
+    auto polygons = *geo_objects.getPolylineVec(geo_name);
+    ASSERT_EQ(4, polygons.size());
+    for (auto polygon : polygons)
+    {
+        std::unique_ptr<GeoLib::Surface> sfc (FileIO::createSurfaceWithEarClipping(*polygon));
+        ASSERT_TRUE(sfc != nullptr);
+        ASSERT_EQ(sfc->getNumberOfTriangles(),
+                  polygon->getNumberOfPoints() - 3);
+    }
+}
-- 
GitLab