From 19a83d1885d85ad505d2a0929af3a6d3d072e180 Mon Sep 17 00:00:00 2001 From: Ravi Peters Date: Wed, 2 Dec 2020 23:53:53 +0100 Subject: [PATCH] add node to calculate proper data_coverage --- CMakeLists.txt | 1 + register.hpp | 1 + src/data_coverage_node.cpp | 59 ++++++++++++++++++++++++++++++++++++++ src/stepedge_nodes.hpp | 17 +++++++++++ 4 files changed, 78 insertions(+) create mode 100644 src/data_coverage_node.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8283a91..6c89823 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ geoflow_create_plugin( src/polygon_offset.cpp src/alpha_shape.cpp src/CityGMLMeshWriter.cpp + src/data_coverage_node.cpp ) target_include_directories(gfp_buildingreconstruction PRIVATE diff --git a/register.hpp b/register.hpp index 278a3f4..8b0df4d 100644 --- a/register.hpp +++ b/register.hpp @@ -42,4 +42,5 @@ void register_nodes(geoflow::NodeRegister& node_register) { node_register.register_node("PolygonOffsetter"); node_register.register_node("CityGMLMeshWriter"); node_register.register_node("Arr2LinearRingsDebug"); + node_register.register_node("DataCoverageCalc"); } \ No newline at end of file diff --git a/src/data_coverage_node.cpp b/src/data_coverage_node.cpp new file mode 100644 index 0000000..9069386 --- /dev/null +++ b/src/data_coverage_node.cpp @@ -0,0 +1,59 @@ + +// Let 'vertices' be an array of N pairs (x,y), indexed from 0 +// Let 'area' = 0.0 +// for i = 0 to N-1, do +// Let j = (i+1) mod N +// Let area = area + vertices[i].x * vertices[j].y +// Let area = area - vertices[i].y * vertices[j].x +// end for +// Return 'area' + +#include "stepedge_nodes.hpp" +#include + +namespace geoflow::nodes::stepedge { + +template float compute_ring_area(const T& ring) { + + size_t n = ring.size(); + float area = 0; + for(size_t i=0; i(); + auto data_area = input("data_area").get(); + auto& groundparts = vector_input("ground_parts"); + + // non_ground_area is sum of the area of the roofparts, thus excluding all groundparts + auto non_ground_area = compute_polygon_area(footprint_polygon); + + for(size_t i=0; i< groundparts.size(); ++i) { + auto& groundpart = groundparts.get(i); + non_ground_area -= compute_polygon_area(groundpart); + } + + output("data_coverage").set( data_area / non_ground_area ); +} + +} \ No newline at end of file diff --git a/src/stepedge_nodes.hpp b/src/stepedge_nodes.hpp index 09428ce..faf9076 100644 --- a/src/stepedge_nodes.hpp +++ b/src/stepedge_nodes.hpp @@ -1113,4 +1113,21 @@ namespace geoflow::nodes::stepedge { void process(); }; + class DataCoverageCalcNode:public Node { + public: + using Node::Node; + + void init() { + add_vector_input("ground_parts", typeid(LinearRing)); + add_input("footprint_polygon", typeid(LinearRing)); + add_input("data_area", typeid(float)); + + add_output("data_coverage", typeid(float)); + } + bool inputs_valid() { + return vector_input("footprint_polygon").has_data() && input("data_area").has_data(); + } + void process(); + }; + } \ No newline at end of file