From e4e27c21f2266a7125987477126537bb0335f06b Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 17 May 2024 14:55:26 -0400 Subject: [PATCH 1/2] Skip feathered raster generation when possible --- VERSION | 2 +- opendm/osfm.py | 6 ++++++ stages/odm_orthophoto.py | 15 ++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/VERSION b/VERSION index 1545d966..d5c0c991 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.5.0 +3.5.1 diff --git a/opendm/osfm.py b/opendm/osfm.py index 7a3f2e03..113d4c1c 100644 --- a/opendm/osfm.py +++ b/opendm/osfm.py @@ -793,3 +793,9 @@ def get_all_submodel_paths(submodels_path, *all_paths): result.append([os.path.join(submodels_path, f, ap) for ap in all_paths]) return result + +def is_submodel(opensfm_root): + # A bit hackish, but works without introducing additional markers / flags + return os.path.islink(os.path.join(opensfm_root, "exif")) or \ + os.path.isfile(os.path.join(opensfm_root, "split_merge_stop_at_reconstruction.txt")) or \ + os.path.isfile(os.path.join(opensfm_root, "features", "empty")) \ No newline at end of file diff --git a/stages/odm_orthophoto.py b/stages/odm_orthophoto.py index cf362bb3..e66d89db 100644 --- a/stages/odm_orthophoto.py +++ b/stages/odm_orthophoto.py @@ -7,6 +7,7 @@ from opendm import context from opendm import types from opendm import gsd from opendm import orthophoto +from opendm.osfm import is_submodel from opendm.concurrency import get_max_memory_mb from opendm.cutline import compute_cutline from opendm.utils import double_quote @@ -114,6 +115,7 @@ class ODMOrthoPhotoStage(types.ODM_Stage): # Cutline computation, before cropping # We want to use the full orthophoto, not the cropped one. + submodel_run = is_submodel(tree.opensfm) if args.orthophoto_cutline: cutline_file = os.path.join(tree.odm_orthophoto, "cutline.gpkg") @@ -122,15 +124,18 @@ class ODMOrthoPhotoStage(types.ODM_Stage): cutline_file, args.max_concurrency, scale=0.25) - - orthophoto.compute_mask_raster(tree.odm_orthophoto_tif, cutline_file, - os.path.join(tree.odm_orthophoto, "odm_orthophoto_cut.tif"), - blend_distance=20, only_max_coords_feature=True) + + if submodel_run: + orthophoto.compute_mask_raster(tree.odm_orthophoto_tif, cutline_file, + os.path.join(tree.odm_orthophoto, "odm_orthophoto_cut.tif"), + blend_distance=20, only_max_coords_feature=True) + else: + log.ODM_INFO("Not a submodel run, skipping mask raster generation") orthophoto.post_orthophoto_steps(args, bounds_file_path, tree.odm_orthophoto_tif, tree.orthophoto_tiles, resolution) # Generate feathered orthophoto also - if args.orthophoto_cutline: + if args.orthophoto_cutline and submodel_run: orthophoto.feather_raster(tree.odm_orthophoto_tif, os.path.join(tree.odm_orthophoto, "odm_orthophoto_feathered.tif"), blend_distance=20 From 6da366f806389df10c9e2fd16f09e1505ba99bb6 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 17 May 2024 15:23:10 -0400 Subject: [PATCH 2/2] Windows fix --- opendm/osfm.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/opendm/osfm.py b/opendm/osfm.py index 113d4c1c..0d49e1e4 100644 --- a/opendm/osfm.py +++ b/opendm/osfm.py @@ -796,6 +796,9 @@ def get_all_submodel_paths(submodels_path, *all_paths): def is_submodel(opensfm_root): # A bit hackish, but works without introducing additional markers / flags - return os.path.islink(os.path.join(opensfm_root, "exif")) or \ + # Look at the path of the opensfm directory and see if "submodel_" is part of it + parts = os.path.abspath(opensfm_root).split(os.path.sep) + + return (len(parts) >= 2 and parts[-2][:9] == "submodel_") or \ os.path.isfile(os.path.join(opensfm_root, "split_merge_stop_at_reconstruction.txt")) or \ os.path.isfile(os.path.join(opensfm_root, "features", "empty")) \ No newline at end of file