Merge pull request #1155 from pierotofy/multid2m

Add support for maxConcurrency in dem2mesh

Former-commit-id: e0a3384d28
pull/1161/head
Piero Toffanin 2020-08-31 13:44:49 -04:00 zatwierdzone przez GitHub
commit 0ab5d1cb67
1 zmienionych plików z 27 dodań i 14 usunięć

Wyświetl plik

@ -36,7 +36,7 @@ def create_25dmesh(inPointCloud, outMesh, dsm_radius=0.07, dsm_resolution=0.05,
)
if method == 'gridded':
mesh = dem_to_mesh_gridded(os.path.join(tmp_directory, 'mesh_dsm.tif'), outMesh, maxVertexCount, verbose)
mesh = dem_to_mesh_gridded(os.path.join(tmp_directory, 'mesh_dsm.tif'), outMesh, maxVertexCount, verbose, maxConcurrency=max(1, available_cores))
elif method == 'poisson':
dsm_points = dem_to_points(os.path.join(tmp_directory, 'mesh_dsm.tif'), os.path.join(tmp_directory, 'dsm_points.ply'), verbose)
mesh = screened_poisson_reconstruction(dsm_points, outMesh, depth=depth,
@ -74,7 +74,7 @@ def dem_to_points(inGeotiff, outPointCloud, verbose=False):
return outPointCloud
def dem_to_mesh_gridded(inGeotiff, outMesh, maxVertexCount, verbose=False):
def dem_to_mesh_gridded(inGeotiff, outMesh, maxVertexCount, verbose=False, maxConcurrency=1):
log.ODM_INFO('Creating mesh from DSM: %s' % inGeotiff)
mesh_path, mesh_filename = os.path.split(outMesh)
@ -87,19 +87,32 @@ def dem_to_mesh_gridded(inGeotiff, outMesh, maxVertexCount, verbose=False):
outMeshDirty = os.path.join(mesh_path, "{}.dirty{}".format(basename, ext))
kwargs = {
'bin': context.dem2mesh_path,
'outfile': outMeshDirty,
'infile': inGeotiff,
'maxVertexCount': maxVertexCount,
'verbose': '-verbose' if verbose else ''
}
# This should work without issues most of the times,
# but just in case we lower maxConcurrency if it fails.
while True:
try:
kwargs = {
'bin': context.dem2mesh_path,
'outfile': outMeshDirty,
'infile': inGeotiff,
'maxVertexCount': maxVertexCount,
'maxConcurrency': maxConcurrency,
'verbose': '-verbose' if verbose else ''
}
system.run('{bin} -inputFile {infile} '
'-outputFile {outfile} '
'-maxTileLength 2000 '
'-maxVertexCount {maxVertexCount} '
'-maxConcurrency {maxConcurrency} '
' {verbose} '.format(**kwargs))
break
except Exception as e:
maxConcurrency = math.floor(maxConcurrency / 2)
if maxConcurrency >= 1:
log.ODM_WARNING("dem2mesh failed, retrying with lower concurrency (%s) in case this is a memory issue" % maxConcurrency)
else:
raise e
system.run('{bin} -inputFile {infile} '
'-outputFile {outfile} '
'-maxTileLength 4000 '
'-maxVertexCount {maxVertexCount} '
' {verbose} '.format(**kwargs))
# Cleanup and reduce vertex count if necessary
# (as dem2mesh cannot guarantee that we'll have the target vertex count)