From 1a598d4cfa0c3f9a11fcc740f0bad3ae06a47ee6 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sun, 28 Apr 2019 22:48:49 -0400 Subject: [PATCH] Relative path fix, rerun pipeline logic fix Former-commit-id: 934ee78f9b920639d132b41d10f71a9215bf1c4f --- opendm/osfm.py | 32 ++++++++++++++++++++++++++++++++ opendm/types.py | 2 +- scripts/splitmerge.py | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/opendm/osfm.py b/opendm/osfm.py index 75746049..d09c426b 100644 --- a/opendm/osfm.py +++ b/opendm/osfm.py @@ -147,6 +147,38 @@ class OSFMContext: def path(self, *paths): return os.path.join(self.opensfm_project_path, *paths) + def set_image_list_absolute(self): + """ + Checks the image_list.txt file and makes sure that all paths + written in it are absolute paths and not relative paths. + If there are relative paths, they are changed to absolute paths. + """ + image_list_file = self.path("image_list.txt") + tmp_list_file = self.path("image_list.txt.tmp") + + if io.file_exists(image_list_file): + changed = False + + with open(image_list_file, 'r') as f: + content = f.read() + + lines = [] + for line in map(str.strip, content.split('\n')): + if line and not line.startswith("/"): + changed = True + line = os.path.abspath(os.path.join(self.opensfm_project_path, line)) + lines.append(line) + + if changed: + with open(tmp_list_file, 'w') as f: + f.write("\n".join(lines)) + + os.remove(image_list_file) + os.rename(tmp_list_file, image_list_file) + + log.ODM_DEBUG("%s now contains absolute paths" % image_list_file) + else: + log.ODM_WARNING("No %s found, cannot check for absolute paths." % image_list_file) def get_submodel_argv(args, submodels_path, submodel_name): """ diff --git a/opendm/types.py b/opendm/types.py index b6a6c1cb..86fca39a 100644 --- a/opendm/types.py +++ b/opendm/types.py @@ -360,7 +360,7 @@ class ODM_Stage: log.ODM_INFO('Finished %s stage' % self.name) # Last stage? - if self.args.end_with == self.name: + if self.args.end_with == self.name or self.args.rerun == self.name: log.ODM_INFO("No more stages to run") return diff --git a/scripts/splitmerge.py b/scripts/splitmerge.py index 14fd09aa..80ef69ea 100644 --- a/scripts/splitmerge.py +++ b/scripts/splitmerge.py @@ -46,6 +46,7 @@ class ODMSplitStage(types.ODM_Stage): shutil.rmtree(tree.submodels_path) octx.run("create_submodels") + octx.set_image_list_absolute() else: log.ODM_WARNING("Submodels directory already exist at: %s" % tree.submodels_path)