Skip to content

Commit

Permalink
ensure attributes and geometries for 2D layers are of equal size
Browse files Browse the repository at this point in the history
  • Loading branch information
Ylannl committed Jul 28, 2020
1 parent 256ceb0 commit dad4d05
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/alpha_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ void AlphaShapeNode::process() {
PointCollection edge_points, boundary_points;
LineStringCollection alpha_edges;
auto& alpha_rings = vector_output("alpha_rings");
alpha_rings.touch();
output("alpha_triangles").touch();

std::vector<as::Triangulation_2> alpha_dts;
Expand Down
60 changes: 35 additions & 25 deletions src/stepedge_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void LOD1ExtruderNode::process() {
}

//roof
if(input("roof_elevation").has_data()) {
if(input("roof_elevation").get_data_vec()[0].has_value()) {
float h_roof = input("roof_elevation").get<float>();
LinearRing r_roof = ring;
for (auto& p : r_roof) p[2] = h_roof;
Expand Down Expand Up @@ -232,7 +232,7 @@ void PolygonGrowerNode::process(){
}

void Arr2LinearRingsNode::process(){
auto arr = input("arrangement").get<Arrangement_2>();


// auto& floor_elevation = input("floor_elevation").get<float&>();
// auto& mesh_error = input("mesh_error").get<float&>();
Expand All @@ -244,26 +244,31 @@ void Arr2LinearRingsNode::process(){

//create all output fields
std::unordered_map<std::string, gfSingleFeatureOutputTerminal*> input_attr_map;
for (auto &iterm : poly_input("attributes").sub_terminals()) {
for (auto &iterm : attributes_in.sub_terminals()) {
auto& oterm = poly_output("attributes").add_vector(iterm->get_name(), iterm->get_type());
input_attr_map[oterm.get_name()] = &oterm;
}
// auto &floor_elevation_term = poly_output("attributes").add_vector("maaiveld_h", typeid(float));
// input_attr_map["maaiveld_h"] = &floor_elevation_term;
// auto &attr_error_term = poly_output("attributes").add_vector("rmse", typeid(float));
// input_attr_map["rmse"] = &attr_error_term;
// auto &attr_rooftype_term = poly_output("attributes").add_vector("dak_type", typeid(int));
// input_attr_map["dak_type"] = &attr_rooftype_term;
// auto &attr_arr_complexity_term = poly_output("attributes").add_vector("arr_complexity", typeid(int));
// input_attr_map["arr_complexity"] = &attr_arr_complexity_term;

// attributes specific to each roofpart
auto &attr_elevation_term = poly_output("attributes").add_vector("roof_elevation", typeid(float));
input_attr_map["roof_elevation"] = &attr_elevation_term;
// auto &attr_roofid_term = poly_output("attributes").add_vector("dak_id", typeid(int));
// input_attr_map["dak_id"] = &attr_roofid_term;
// auto &attr_objectid_term = poly_output("attributes").add_vector("building_id", typeid(int));
// input_attr_map["building_id"] = &attr_objectid_term;


// in case we get an invalid roof_type (-1 or -2) push the available attribute and an empty ring
if(invalid_rooftype) {
for (auto &iterm : attributes_in.sub_terminals()) {
// if (iterm->get_name()=="roof_type")
if (iterm->has_data()) {
input_attr_map[iterm->get_name()]->push_back_any(iterm->get_data());
} else {
input_attr_map[iterm->get_name()]->push_back_any(std::any());
}
}
input_attr_map["roof_elevation"]->push_back_any(std::any());
linear_rings.push_back_any(std::any());
return;
}

auto arr = input("arrangement").get<Arrangement_2>();

// int j=0;
auto& plane_a = vector_output("plane_a");
Expand Down Expand Up @@ -298,7 +303,11 @@ void Arr2LinearRingsNode::process(){
// input_attr_map["dak_type"]->push_back((int)roof_type);
// input_attr_map["arr_complexity"]->push_back(arr_complexity);
for (auto &iterm : poly_input("attributes").sub_terminals()) {
input_attr_map[iterm->get_name()]->push_back_any(iterm->get_data());
if (iterm->has_data()) {
input_attr_map[iterm->get_name()]->push_back_any(iterm->get_data());
} else {
input_attr_map[iterm->get_name()]->push_back_any(std::any());
}
}
}
}
Expand Down Expand Up @@ -1474,20 +1483,21 @@ void DetectPlanesNode::process() {
}

bool b_is_horizontal = float(horiz_pt_cnt)/float(total_pt_cnt) > horiz_min_count;
int building_type=-2; // as built: -2=undefined; -1=no pts; 0=LOD1, 1=LOD1.3, 2=LOD2
int roof_type=-2; // as built: -2=undefined; -1=no pts; 0=LOD1, 1=LOD1.3, 2=LOD2
if (R.regions.size()==0) {
building_type=-1;
roof_type=-1;
} else if (horiz_roofplane_cnt==1 && slant_roofplane_cnt==0){
building_type=0;
roof_type=0;
} else if (b_is_horizontal){
building_type=1;
roof_type=1;
} else if (slant_roofplane_cnt > 0) {
building_type=2;
roof_type=2;
}

if(roof_elevations.size())
output("roof_elevation").set(compute_percentile(roof_elevations, roof_percentile));
output("roof_type").set(building_type);
if(roof_elevations.size()) output("roof_elevation").set(compute_percentile(roof_elevations, roof_percentile));
else output("roof_elevation").set_from_any(std::any());

output("roof_type").set(roof_type);
output("horiz_roofplane_cnt").set(float(horiz_roofplane_cnt));
output("slant_roofplane_cnt").set(float(slant_roofplane_cnt));
output("total_roofplane_cnt").set(int(horiz_roofplane_cnt+slant_roofplane_cnt));
Expand Down
27 changes: 21 additions & 6 deletions src/stepedge_nodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ namespace geoflow::nodes::stepedge {
};

class Arr2LinearRingsNode:public Node {
bool invalid_rooftype = false;

bool only_in_footprint = true;
int plane_id = 0;
public:
Expand All @@ -132,6 +134,19 @@ namespace geoflow::nodes::stepedge {

add_param(ParamBool(only_in_footprint, "only_in_footprint", "Only faces inside the footprint"));
}
bool inputs_valid() {
for (auto &iterm : poly_input("attributes").sub_terminals()) {
if(iterm->get_name() == "roof_type" && iterm->size()) {
if (iterm->get<int>()<0) {
std::cout << "invalid rooftype\n";
invalid_rooftype = true;
return true;
}
}
}
invalid_rooftype = false;
return Node::inputs_valid();
}
void process();
};

Expand Down Expand Up @@ -286,7 +301,7 @@ namespace geoflow::nodes::stepedge {
// float rel_area_thres = 0.1;
int max_arr_complexity = 400;
int dist_threshold_exp = 4;
float fp_extension = 0;
float fp_extension = 0.01;
bool insert_with_snap = false;
// int angle_threshold_exp = 5;
// bool snap_clean = true;
Expand All @@ -302,7 +317,7 @@ namespace geoflow::nodes::stepedge {
add_output("arr_complexity", typeid(int));

// add_param(ParamBoundedFloat(rel_area_thres, 0.01, 1, "rel_area_thres", "Preserve split ring area"));
// add_param(ParamBoundedFloat(fp_extension, 0.0, 0.01, "fp_extension", "extend each footprint segment on both sides with this distance"));
add_param(ParamBoundedFloat(fp_extension, 0.0, 0.01, "fp_extension", "extend each footprint segment on both sides with this distance"));
add_param(ParamInt(max_arr_complexity, "max_arr_complexity", "Maximum nr of lines"));
add_param(ParamBoundedInt(dist_threshold_exp, 0, 15, "dist_threshold_exp", "10-base exponent to set distance threshold. Eg a value of 2 yields a value of 10^(-2) = 0.01"));
// add_param(ParamBoundedInt(angle_threshold_exp, 0, 15, "angle_threshold_exp", "10-base exponent to set angle threshold in degrees. Eg a value of 2 yields a value of 10^(-2) = 0.01"));
Expand Down Expand Up @@ -943,10 +958,10 @@ namespace geoflow::nodes::stepedge {
for (auto &iterm : poly_input("attributes").sub_terminals()) {
if (iterm->get_name() == manager.substitute_globals(attribute_name)) {
if (iterm->accepts_type(typeid(bool))) {
std::cout << "Detected attribute of type bool\n";
// std::cout << "Detected attribute of type bool\n";
result = iterm->get<bool>();
} else {
std::cout << "Attribute type is not bool\n";
// std::cout << "Attribute type is not bool\n";
}
}
}
Expand All @@ -964,9 +979,9 @@ namespace geoflow::nodes::stepedge {
} else {
bool selectAB = selectInput.get<bool>();
if (selectAB) {
return vector_input("linear_rings_A").has_data() && poly_input("attributes_A").has_data();
return vector_input("linear_rings_A").has_data();
} else {
return vector_input("linear_rings_B").has_data() && poly_input("attributes_B").has_data();
return vector_input("linear_rings_B").has_data();
}
}
}
Expand Down

0 comments on commit dad4d05

Please sign in to comment.