Skip to content

Commit

Permalink
add node to calculate proper data_coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ylannl committed Dec 2, 2020
1 parent 9ba711d commit 19a83d1
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions register.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ void register_nodes(geoflow::NodeRegister& node_register) {
node_register.register_node<PolygonOffsetNode>("PolygonOffsetter");
node_register.register_node<CityGMLMeshWriterNode>("CityGMLMeshWriter");
node_register.register_node<Arr2LinearRingsDebugNode>("Arr2LinearRingsDebug");
node_register.register_node<DataCoverageCalcNode>("DataCoverageCalc");
}
59 changes: 59 additions & 0 deletions src/data_coverage_node.cpp
Original file line number Diff line number Diff line change
@@ -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 <cmath>

namespace geoflow::nodes::stepedge {

template<typename T> float compute_ring_area(const T& ring) {

size_t n = ring.size();
float area = 0;
for(size_t i=0; i<n; ++i) {
size_t j = (i+1) % n;
area += ring[i][0] * ring[j][1];
area -= ring[i][1] * ring[j][0];
}
return std::fabs(area) / 2;

}

float compute_polygon_area(const LinearRing& polygon) {

// total exterior ring area
float area = compute_ring_area(polygon);

// subtract hole areas
for (auto& iring : polygon.interior_rings()) {
area -= compute_ring_area(iring);
}

return area;

}

void DataCoverageCalcNode::process() {
auto& footprint_polygon = input("footprint_polygon").get<LinearRing>();
auto data_area = input("data_area").get<float>();
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<LinearRing>(i);
non_ground_area -= compute_polygon_area(groundpart);
}

output("data_coverage").set( data_area / non_ground_area );
}

}
17 changes: 17 additions & 0 deletions src/stepedge_nodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

}

0 comments on commit 19a83d1

Please sign in to comment.