Skip to content

Commit

Permalink
Add parameter for max_angle_curvepolygon and log for amount stroked poly
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Commandeur committed Nov 6, 2019
1 parent deb9dfb commit 334db07
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion resources/config_files/myconfig_DEFAULTS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ options:
building_radius_vertex_elevation: 3.0
radius_vertex_elevation: 1.0
threshold_jump_edges: 0.5
threshold_bridge_jump_edges: 0.5
threshold_bridge_jump_edges: 0.5
max_angle_curvepolygon: 0.0
1 change: 1 addition & 0 deletions resources/config_files/myconfig_README.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ options: # Global options
radius_vertex_elevation: 1.0 # Radius in meters used for point-vertex distance between 3D points and vertices of polygons
threshold_jump_edges: 0.5 # Threshold in meters for stitching adjacent objects, when the height difference is larger then the threshold a vertical wall is created
threshold_bridge_jump_edges: 0.5 # Threshold in meters for stitching bridges to adjacent objects, if not specified it falls back to threshold_jump_edges
max_angle_curvepolygon: 0.0 # The largest allowed step in degrees along the arc of a curved polygon. Value for dfMaxAngleStepSizeDegrees passed to OGR CurvePolyToPoly(), zero to use the default setting.
extent: xmin, ymin, xmax, ymax # Filter the input polygons to this extent
12 changes: 11 additions & 1 deletion src/Map3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Map3d::Map3d() {
_maxxradius = 9999999;
_minyradius = -9999999;
_maxyradius = -9999999;
_max_angle_curvepolygon = 0;
}

Map3d::~Map3d() {
Expand Down Expand Up @@ -160,6 +161,10 @@ void Map3d::set_requested_extent(double xmin, double ymin, double xmax, double y
_requestedExtent = Box2(Point2(xmin, ymin), Point2(xmax, ymax));
}

void Map3d::set_max_angle_curvepolygon(double max_angle) {
_max_angle_curvepolygon = max_angle;
}

Box2 Map3d::get_bbox() {
return _bbox;
}
Expand Down Expand Up @@ -978,6 +983,7 @@ bool Map3d::extract_and_add_polygon(GDALDataset* dataSource, PolygonFile* file)

int numSplitMulti = 0;
int numSplitPoly = 0;
int numCurvePoly = 0;
while ((f = dataLayer->GetNextFeature()) != NULL) {
OGRGeometry *geometry = f->GetGeometryRef();
if (!geometry->IsValid()) {
Expand Down Expand Up @@ -1017,9 +1023,10 @@ bool Map3d::extract_and_add_polygon(GDALDataset* dataSource, PolygonFile* file)
}
case wkbCurvePolygon: {
OGRCurvePolygon* curve_polygon = geometry->toCurvePolygon();
OGRPolygon* polygon = curve_polygon->CurvePolyToPoly(0);
OGRPolygon* polygon = curve_polygon->CurvePolyToPoly(_max_angle_curvepolygon);
f->SetGeometry(polygon);
extract_feature(f, layerName, idfield, heightfield, l.second, multiple_heights);
numCurvePoly++;
break;
}
default: {
Expand All @@ -1031,6 +1038,9 @@ bool Map3d::extract_and_add_polygon(GDALDataset* dataSource, PolygonFile* file)
if (numSplitMulti > 0) {
std::clog << "\tSplit " << numSplitMulti << " MultiPolygon(s) into " << numSplitPoly << " Polygon(s)\n";
}
if (numCurvePoly > 0) {
std::clog << "\tStroked " << numCurvePoly << " CurvePolygon(s) with a maximum angle of " << _max_angle_curvepolygon << "\n";
}
wentgood = true;
}
return wentgood;
Expand Down
2 changes: 2 additions & 0 deletions src/Map3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Map3d {
void set_threshold_jump_edges(float threshold);
void set_threshold_bridge_jump_edges(float threshold);
void set_requested_extent(double xmin, double ymin, double xmax, double ymax);
void set_max_angle_curvepolygon(double max_angle);

void add_allowed_las_class(AllowedLASTopo c, int i);
void add_allowed_las_class_within(AllowedLASTopo c, int i);
Expand Down Expand Up @@ -140,6 +141,7 @@ class Map3d {
double _minyradius;
double _maxyradius;
Box2 _requestedExtent;
double _max_angle_curvepolygon; //-- the largest step in degrees along the arc, zero to use the default setting.

//-- storing the LAS allowed for each TopoFeature
std::array<std::set<int>,NUM_ALLOWEDLASTOPO> _las_classes_allowed;
Expand Down
11 changes: 11 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ int main(int argc, const char * argv[]) {
map3d.set_threshold_bridge_jump_edges(n["threshold_jump_edges"].as<float>());
if (n["stitching"] && n["stitching"].as<std::string>() == "false")
bStitching = false;
if (n["max_angle_curvepolygon"])
map3d.set_max_angle_curvepolygon(n["max_angle_curvepolygon"].as<double>());

if (n["extent"]) {
std::vector<std::string> extent_split = stringsplit(n["extent"].as<std::string>(), ',');
Expand Down Expand Up @@ -1163,6 +1165,15 @@ bool validate_yaml(const char* arg, std::set<std::string>& allowedFeatures) {
std::cerr << "\tOption 'options.stitching' invalid; must be 'true' or 'false'.\n";
}
}
if (n["max_angle_curvepolygon"]) {
try {
boost::lexical_cast<double>(n["max_angle_curvepolygon"].as<std::string>());
}
catch (boost::bad_lexical_cast& e) {
wentgood = false;
std::cerr << "\tOption 'options.max_angle_curvepolygon' invalid.\n";
}
}
if (n["extent"]) {
std::vector<std::string> extent_split = stringsplit(n["extent"].as<std::string>(), ',');
double xmin, xmax, ymin, ymax;
Expand Down

0 comments on commit 334db07

Please sign in to comment.