From 5ef0e7c12931b0a7059761426a452d869f8ab5e7 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Tue, 4 May 2021 13:04:13 -0400 Subject: [PATCH] Windows fixes up to meshing --- SuperBuild/CMakeLists.txt | 3 --- opendm/dem/commands.py | 17 +++++++++-------- opendm/dem/pdal.py | 3 ++- opendm/osfm.py | 5 +++-- opendm/point_cloud.py | 8 ++++---- opendm/system.py | 2 +- stages/run_opensfm.py | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt index c23ed3c0..f7dee2c9 100644 --- a/SuperBuild/CMakeLists.txt +++ b/SuperBuild/CMakeLists.txt @@ -186,9 +186,6 @@ externalproject_add(dem2mesh SOURCE_DIR ${SB_SOURCE_DIR}/dem2mesh CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${SB_INSTALL_DIR} ${WIN32_GDAL_ARGS} - UPDATE_COMMAND "" - BUILD_IN_SOURCE 1 - INSTALL_COMMAND "" ) externalproject_add(dem2points diff --git a/opendm/dem/commands.py b/opendm/dem/commands.py index a12e79e0..8fc68441 100755 --- a/opendm/dem/commands.py +++ b/opendm/dem/commands.py @@ -12,6 +12,7 @@ from opendm import system from opendm.concurrency import get_max_memory, parallel_map from scipy import ndimage from datetime import datetime +from osgeo.utils.gdal_fillnodata import main as gdal_fillnodata from opendm import log try: import Queue as queue @@ -227,14 +228,14 @@ def create_dem(input_point_cloud, dem_type, output_type='max', radiuses=['0.56'] '{geotiff_tmp} {geotiff_small}'.format(**kwargs)) # Fill scaled - run('gdal_fillnodata.py ' - '-co NUM_THREADS={threads} ' - '-co BIGTIFF=IF_SAFER ' - '--config GDAL_CACHEMAX {max_memory}% ' - '-b 1 ' - '-of GTiff ' - '{geotiff_small} {geotiff_small_filled}'.format(**kwargs)) - + gdal_fillnodata(['.', + '-co', 'NUM_THREADS=%s' % kwargs['threads'], + '-co', 'BIGTIFF=IF_SAFER', + '--config', 'GDAL_CACHE_MAX', str(kwargs['max_memory']) + '%', + '-b', '1', + '-of', 'GTiff', + kwargs['geotiff_small'], kwargs['geotiff_small_filled']]) + # Merge filled scaled DEM with unfilled DEM using bilinear interpolation run('gdalbuildvrt -resolution highest -r bilinear "%s" "%s" "%s"' % (merged_vrt_path, geotiff_small_filled_path, geotiff_tmp_path)) run('gdal_translate ' diff --git a/opendm/dem/pdal.py b/opendm/dem/pdal.py index cea98c86..1b558266 100644 --- a/opendm/dem/pdal.py +++ b/opendm/dem/pdal.py @@ -31,6 +31,7 @@ # Library functions for creating DEMs from Lidar data import os +import sys import json as jsonlib import tempfile from opendm import system @@ -156,7 +157,7 @@ def run_pipeline(json, verbose=False): 'pipeline', '-i %s' % jsonfile ] - if verbose: + if verbose or sys.platform == 'win32': system.run(' '.join(cmd)) else: system.run(' '.join(cmd) + ' > /dev/null 2>&1') diff --git a/opendm/osfm.py b/opendm/osfm.py index 299bb7f6..bccedb8b 100644 --- a/opendm/osfm.py +++ b/opendm/osfm.py @@ -24,8 +24,9 @@ class OSFMContext: self.opensfm_project_path = opensfm_project_path def run(self, command): - system.run('%s/bin/opensfm %s "%s"' % - (context.opensfm_path, command, self.opensfm_project_path)) + osfm_bin = os.path.join(context.opensfm_path, 'bin', 'opensfm') + system.run('%s %s "%s"' % + (osfm_bin, command, self.opensfm_project_path)) def is_reconstruction_done(self): tracks_file = os.path.join(self.opensfm_project_path, 'tracks.csv') diff --git a/opendm/point_cloud.py b/opendm/point_cloud.py index 617d49bf..6ae92136 100644 --- a/opendm/point_cloud.py +++ b/opendm/point_cloud.py @@ -60,7 +60,7 @@ def split(input_point_cloud, outdir, filename_template, capacity, dims=None): if filename_template.endswith(".ply"): cmd += ("--writers.ply.sized_types=false " - "--writers.ply.storage_mode='little endian' ") + "--writers.ply.storage_mode=\"little endian\" ") if dims is not None: cmd += '--writers.ply.dims="%s"' % dims system.run(cmd) @@ -151,7 +151,7 @@ def filter(input_point_cloud, output_point_cloud, standard_deviation=2.5, meank= "-o \"{outputFile}\" " "{stages} " "--writers.ply.sized_types=false " - "--writers.ply.storage_mode='little endian' " + "--writers.ply.storage_mode=\"little endian\" " "--writers.ply.dims=\"{dims}\" " "").format(**filterArgs) @@ -159,13 +159,13 @@ def filter(input_point_cloud, output_point_cloud, standard_deviation=2.5, meank= cmd += "--filters.sample.radius={} ".format(sample_radius) if 'outlier' in filters: - cmd += ("--filters.outlier.method='statistical' " + cmd += ("--filters.outlier.method=\"statistical\" " "--filters.outlier.mean_k={} " "--filters.outlier.multiplier={} ").format(meank, standard_deviation) if 'range' in filters: # Remove outliers - cmd += "--filters.range.limits='Classification![7:7]' " + cmd += "--filters.range.limits=\"Classification![7:7]\" " system.run(cmd) diff --git a/opendm/system.py b/opendm/system.py index a576a68f..1d114987 100644 --- a/opendm/system.py +++ b/opendm/system.py @@ -72,7 +72,7 @@ def run(cmd, env_paths=[context.superbuild_bin_path], env_vars={}, packages_path for k in env_vars: env[k] = str(env_vars[k]) - p = subprocess.Popen(cmd, shell=True, env=env, preexec_fn=os.setsid) + p = subprocess.Popen(cmd, shell=True, env=env, start_new_session=True) running_subprocesses.append(p) retcode = p.wait() running_subprocesses.remove(p) diff --git a/stages/run_opensfm.py b/stages/run_opensfm.py index 5344b54e..275aae7c 100644 --- a/stages/run_opensfm.py +++ b/stages/run_opensfm.py @@ -70,7 +70,7 @@ class ODMOpenSfMStage(types.ODM_Stage): geocoords_flag_file = octx.path("exported_geocoords.txt") if reconstruction.is_georeferenced() and (not io.file_exists(geocoords_flag_file) or self.rerun()): - octx.run('export_geocoords --reconstruction --proj \'%s\' --offset-x %s --offset-y %s' % + octx.run('export_geocoords --reconstruction --proj "%s" --offset-x %s --offset-y %s' % (reconstruction.georef.proj4(), reconstruction.georef.utm_east_offset, reconstruction.georef.utm_north_offset)) # Destructive shutil.move(tree.opensfm_geocoords_reconstruction, tree.opensfm_reconstruction)