Skip to content

Commit

Permalink
Merge pull request #94 from 3DBAG/issue/74
Browse files Browse the repository at this point in the history
Improve LoD11 fallback/skip mechanism + timeout
  • Loading branch information
Ylannl authored Dec 5, 2024
2 parents 4fe81b5 + 8d8411f commit 86ff4bf
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 233 deletions.
24 changes: 19 additions & 5 deletions apps/roofer-app/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ struct InputPointcloud {
roofer::vec1f pt_densities;
roofer::vec1b is_glass_roof;
roofer::vec1b lod11_forced;
roofer::vec1b pointcloud_insufficient;
std::vector<roofer::LinearRing> nodata_circles;
std::vector<roofer::PointCollection> building_clouds;
std::vector<roofer::ImageMap> building_rasters;
roofer::vec1f ground_elevations;
roofer::vec1f roof_elevations;
roofer::vec1i acquisition_years;

std::unique_ptr<roofer::misc::RTreeInterface> rtree;
Expand All @@ -84,7 +86,7 @@ struct RooferConfig {
int lod11_fallback_area = 69000;
float lod11_fallback_density = 5;
roofer::arr2f tilesize = {1000, 1000};
bool clear_if_insufficient = false;
bool clear_if_insufficient = true;

bool write_crop_outputs = false;
bool output_all = false;
Expand Down Expand Up @@ -115,12 +117,14 @@ struct RooferConfig {
std::string output_path;

// reconstruct
int lod11_fallback_planes = 900;
int lod11_fallback_time = 1800000;
roofer::ReconstructionConfig rec;

// output attribute names
std::unordered_map<std::string, std::string> n = {
{"status", "rf_status"},
{"reconstruction_time", "rf_reconstruction_time"},
{"success", "rf_success"},
{"reconstruction_time", "rf_t_run"},
{"val3dity_lod12", "rf_val3dity_lod12"},
{"val3dity_lod13", "rf_val3dity_lod13"},
{"val3dity_lod22", "rf_val3dity_lod22"},
Expand All @@ -138,7 +142,7 @@ struct RooferConfig {
{"h_roof_70p", "rf_h_roof_70p"},
{"h_roof_min", "rf_h_roof_min"},
{"h_roof_max", "rf_h_roof_max"},
{"roof_n_planes", "rf_roof_n_planes"},
{"roof_n_planes", "rf_roof_planes"},
{"rmse_lod12", "rf_rmse_lod12"},
{"rmse_lod13", "rf_rmse_lod13"},
{"rmse_lod22", "rf_rmse_lod22"},
Expand All @@ -148,6 +152,8 @@ struct RooferConfig {
{"h_ground", "rf_h_ground"},
{"slope", "rf_slope"},
{"azimuth", "rf_azimuth"},
{"extrusion_mode", "rf_extrusion_mode"},
{"pointcloud_unusable", "rf_pointcloud_unusable"},
};
};

Expand Down Expand Up @@ -642,7 +648,8 @@ struct RooferConfigHandler {
_cfg.cellsize, {roofer::v::HigherThan<float>(0)});
add("lod11-fallback-area", "lod11 fallback area", _cfg.lod11_fallback_area,
{roofer::v::HigherThan<int>(0)});
add("skip-insufficient", "skip buildings with insufficient pointcloud data",
add("reconstruct-insufficient",
"reconstruct buildings with insufficient pointcloud data",
_cfg.clear_if_insufficient, {});
// add("lod11-fallback-density", "lod11 fallback density",
// _cfg.lod11_fallback_density, {roofer::v::HigherThan<float>(0)}});
Expand Down Expand Up @@ -682,6 +689,13 @@ struct RooferConfigHandler {
_cfg.cj_scale, {});
add("cj-translate", "Translation applied to CityJSON output vertices",
_cfg.cj_translate, {});
add("lod11-fallback-plane-cnt",
"Fallback to LoD11 if number of detected planes exceeds this value.",
_cfg.lod11_fallback_planes, {roofer::v::HigherThan<int>(0)});
add("lod11-fallback-time",
"Fallback to LoD11 if time spent on detecting planes exceeds this "
"value. In milliseconds.",
_cfg.lod11_fallback_time, {roofer::v::HigherThan<int>(0)});
addr("plane-detect-k", "plane detect k", _cfg.rec.plane_detect_k,
{roofer::v::HigherThan<int>(0)});
addr("plane-detect-min-points", "plane detect min points",
Expand Down
29 changes: 17 additions & 12 deletions apps/roofer-app/crop_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ bool crop_tile(const roofer::TBox<double>& tile,

PointCloudCropper->process(
lasfiles, footprints, buffered_footprints, ipc.building_clouds,
ipc.ground_elevations, ipc.acquisition_years, polygon_extent,
ipc.ground_elevations, ipc.acquisition_years,
ipc.pointcloud_insufficient, polygon_extent,
{.ground_class = ipc.grnd_class,
.building_class = ipc.bld_class,
.clear_if_insufficient = cfg.clear_if_insufficient,
Expand Down Expand Up @@ -130,7 +131,9 @@ bool crop_tile(const roofer::TBox<double>& tile,
ipc.nodata_fractions.resize(N_fp);
ipc.pt_densities.resize(N_fp);
ipc.is_glass_roof.reserve(N_fp);
ipc.roof_elevations.reserve(N_fp);
ipc.lod11_forced.reserve(N_fp);
ipc.pointcloud_insufficient.reserve(N_fp);
if (cfg.write_index) ipc.nodata_circles.resize(N_fp);

// auto& r_nodata = attributes.insert_vec<float>("r_nodata_"+ipc.name);
Expand All @@ -145,6 +148,8 @@ bool crop_tile(const roofer::TBox<double>& tile,
roofer::misc::computePointDensity(ipc.building_rasters[i]);
ipc.is_glass_roof[i] =
roofer::misc::testForGlassRoof(ipc.building_rasters[i]);
ipc.roof_elevations[i] =
roofer::misc::computeRoofElevation(ipc.building_rasters[i], 0.7);

auto target_density = cfg.ceil_point_density;
bool do_force_lod11 =
Expand Down Expand Up @@ -187,27 +192,19 @@ bool crop_tile(const roofer::TBox<double>& tile,

// add raster stats attributes from PointCloudCropper to footprint attributes
for (auto& ipc : input_pointclouds) {
auto& h_ground =
attributes.insert_vec<float>(cfg.n.at("h_ground") + "_" + ipc.name);
auto& nodata_r =
attributes.insert_vec<float>(cfg.n.at("nodata_r") + "_" + ipc.name);
auto& nodata_frac =
attributes.insert_vec<float>(cfg.n.at("nodata_frac") + "_" + ipc.name);
auto& pt_density =
attributes.insert_vec<float>(cfg.n.at("pt_density") + "_" + ipc.name);
auto& is_glass_roof =
attributes.insert_vec<bool>(cfg.n.at("is_glass_roof") + "_" + ipc.name);
h_ground.reserve(N_fp);
nodata_r.reserve(N_fp);
nodata_frac.reserve(N_fp);
pt_density.reserve(N_fp);
is_glass_roof.reserve(N_fp);
for (unsigned i = 0; i < N_fp; ++i) {
h_ground.push_back(ipc.ground_elevations[i] + (*pj->data_offset)[2]);
nodata_r.push_back(ipc.nodata_radii[i]);
nodata_frac.push_back(ipc.nodata_fractions[i]);
pt_density.push_back(ipc.pt_densities[i]);
is_glass_roof.push_back(ipc.is_glass_roof[i]);
}
}

Expand Down Expand Up @@ -346,17 +343,25 @@ bool crop_tile(const roofer::TBox<double>& tile,
building.footprint = footprints[i];
building.h_ground =
input_pointclouds[selected->index].ground_elevations[i];
building.h_roof_70p_rough =
input_pointclouds[selected->index].roof_elevations[i];
building.force_lod11 = input_pointclouds[selected->index].lod11_forced[i];
building.pointcloud_insufficient =
input_pointclouds[selected->index].pointcloud_insufficient[i];
building.is_glass_roof =
input_pointclouds[selected->index].is_glass_roof[i];

if (input_pointclouds[selected->index].lod11_forced[i]) {
building.extrusion_mode = ExtrusionMode::LOD11_FALLBACK;
force_lod11_vec[i] = input_pointclouds[selected->index].lod11_forced[i];
}

output_building_tile.attributes = attributes;
building.jsonl_path = fmt::format(
fmt::runtime(cfg.building_jsonl_file_spec), fmt::arg("bid", bid),
fmt::arg("pc_name", input_pointclouds[selected->index].name),
fmt::arg("path", cfg.output_path));
}
if (input_pointclouds[selected->index].lod11_forced[i]) {
force_lod11_vec[i] = input_pointclouds[selected->index].lod11_forced[i];
}

if (cfg.write_crop_outputs) {
{
Expand Down
Loading

0 comments on commit 86ff4bf

Please sign in to comment.