From d02f6095cbb743213e9b23182d550aee2ac9fedb Mon Sep 17 00:00:00 2001
From: Mohcine Chraibi <m.chraibi@fz-juelich.de>
Date: Tue, 19 Feb 2019 17:04:15 +0100
Subject: [PATCH] Without Measurement areas

define a measurement are with vertexes

for example

<area_B id="1" type="BoundingBox" zPos="None">

area 1 will get automatically vertixes of rectangle
slightly bigger than the entire geometry
---
 Analysis.cpp               |  2 +-
 general/ArgumentParser.cpp | 41 ++++++++++++++++++++++++++++++++++++++
 geometry/Building.cpp      |  6 ++++--
 geometry/Building.h        |  7 ++++++-
 4 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/Analysis.cpp b/Analysis.cpp
index bbafdb43..036abac1 100644
--- a/Analysis.cpp
+++ b/Analysis.cpp
@@ -247,7 +247,7 @@ std::map<int, polygon_2d> Analysis::ReadGeometry(const fs::path& geometryFile, c
           if(geoPoly.count(area->_id)==0)
           {
                Log->Write("ERROR: \t No polygon containing the measurement id [%d]", area->_id);
-               exit(1);
+               geoPoly[area->_id] = area->_poly;
           }
      }
 
diff --git a/general/ArgumentParser.cpp b/general/ArgumentParser.cpp
index 0bcc4e09..34b2bf5a 100644
--- a/general/ArgumentParser.cpp
+++ b/general/ArgumentParser.cpp
@@ -480,14 +480,55 @@ bool ArgumentParser::ParseIniFile(const string& inifile)
                {
                     areaB->_zPos=10000001.0;
                }
+               // get bounding box
+               // loading geometry is done in  analysis.cpp
+               // so this is done twice, which is not nice.
+               // For big geometries it could be slow.
+               Building*  building  = new Building();
+               building->LoadGeometry(GetGeometryFilename().string());
+               building->InitGeometry();
+               building->AddSurroundingRoom(); // this is a big reactagle
+                                               // slightly bigger than the
+                                               // geometry boundaries
+               double geo_minX = building->_xMin;
+               double geo_minY = building->_yMin;
+               double geo_maxX = building->_xMax;
+               double geo_maxY = building->_yMax;
+
+
+               std::map<int, polygon_2d> geoPoly;
                polygon_2d poly;
                Log->Write("INFO: \tMeasure area id  <%d> with type <%s>",areaB->_id, areaB->_type.c_str());
+               int num_verteces = 0;
                for(TiXmlElement* xVertex=xMeasurementArea_B->FirstChildElement("vertex"); xVertex; xVertex=xVertex->NextSiblingElement("vertex") )
                {
                     double box_px = xmltof(xVertex->Attribute("x"))*M2CM;
                     double box_py = xmltof(xVertex->Attribute("y"))*M2CM;
                     boost::geometry::append(poly, boost::geometry::make<point_2d>(box_px, box_py));
                     Log->Write("\t\tMeasure area points  < %.3f, %.3f>",box_px*CMtoM,box_py*CMtoM);
+                    num_verteces++;
+               }
+               if(num_verteces < 3 && num_verteces > 0)
+                    Log->Write("\tWARNING: Less than 3 measure area points given (%d). At least 3 or nothing at all!!", num_verteces);
+               if(num_verteces == 0) // big bounding box
+               {
+                    Log->Write("\tWARNING: NO measure area points given (%d). default BB!!", num_verteces);
+                    //1
+                    double box_px = geo_minX*M2CM;
+                    double box_py = geo_minY*M2CM;
+                    boost::geometry::append(poly, boost::geometry::make<point_2d>(box_px, box_py));
+                    //2
+                    box_px = geo_minX*M2CM;
+                    box_py = geo_maxY*M2CM;
+                    boost::geometry::append(poly, boost::geometry::make<point_2d>(box_px, box_py));
+                    //3
+                    box_px = geo_maxX*M2CM;
+                    box_py = geo_maxY*M2CM;
+                    boost::geometry::append(poly, boost::geometry::make<point_2d>(box_px, box_py));
+                    //4
+                    box_px = geo_maxX*M2CM;
+                    box_py = geo_minY*M2CM;
+                    boost::geometry::append(poly, boost::geometry::make<point_2d>(box_px, box_py));
                }
                correct(poly); // in the case the Polygone is not closed
                areaB->_poly=poly;
diff --git a/geometry/Building.cpp b/geometry/Building.cpp
index 6722ea01..8c8272f6 100644
--- a/geometry/Building.cpp
+++ b/geometry/Building.cpp
@@ -259,6 +259,10 @@ void Building::AddSurroundingRoom()
      bigRoom->SetCaption("outside");
      bigRoom->SetID(_rooms.size());
      AddRoom(bigRoom);
+     _xMin = x_min;
+     _xMax = x_max;
+     _yMin = y_min;
+     _yMax = y_max;
 }
 
 
@@ -1411,5 +1415,3 @@ bool Building::SaveGeometry(const std::string &filename)
 }
 
 #endif // _SIMULATOR
-
-
diff --git a/geometry/Building.h b/geometry/Building.h
index 109d7986..a2e16330 100644
--- a/geometry/Building.h
+++ b/geometry/Building.h
@@ -24,7 +24,7 @@
  *
  *
  **/
- 
+
 
 #ifndef _BUILDING_H
 #define _BUILDING_H
@@ -206,6 +206,11 @@ public:
       * output user specific informations.
       */
      bool SanityCheck();
+     // ---
+     double _xMin;
+     double _xMax;
+     double _yMin;
+     double _yMax;
 
 
 private:
-- 
GitLab