OpenDroneMap-ODM/scripts/odm_meshing.py

74 wiersze
3.1 KiB
Python
Czysty Zwykły widok Historia

2019-04-22 19:14:39 +00:00
import os, math
2015-11-30 15:53:44 +00:00
from opendm import log
from opendm import io
from opendm import system
from opendm import context
from opendm import mesh
2018-08-08 19:41:08 +00:00
from opendm import gsd
2019-04-22 19:14:39 +00:00
from opendm import types
2015-11-30 15:53:44 +00:00
2019-04-22 19:14:39 +00:00
class ODMeshingStage(types.ODM_Stage):
def process(self, args, outputs):
tree = outputs['tree']
reconstruction = outputs['reconstruction']
2015-11-30 15:53:44 +00:00
# define paths and create working directories
system.mkdir_p(tree.odm_meshing)
2015-11-30 15:53:44 +00:00
# Create full 3D model unless --skip-3dmodel is set
if not args.skip_3dmodel:
2019-04-22 19:14:39 +00:00
if not io.file_exists(tree.odm_mesh) or self.rerun():
log.ODM_DEBUG('Writing ODM Mesh file in: %s' % tree.odm_mesh)
mesh.screened_poisson_reconstruction(tree.filtered_point_cloud,
tree.odm_mesh,
2019-04-22 19:14:39 +00:00
depth=self.params.get('oct_tree'),
samples=self.params.get('samples'),
maxVertexCount=self.params.get('max_vertex'),
pointWeight=self.params.get('point_weight'),
threads=self.params.get('max_concurrency'),
verbose=self.params.get('verbose'))
else:
log.ODM_WARNING('Found a valid ODM Mesh file in: %s' %
tree.odm_mesh)
# Always generate a 2.5D mesh
# unless --use-3dmesh is set.
if not args.use_3dmesh:
2019-04-22 19:14:39 +00:00
if not io.file_exists(tree.odm_25dmesh) or self.rerun():
log.ODM_DEBUG('Writing ODM 2.5D Mesh file in: %s' % tree.odm_25dmesh)
2018-10-17 15:35:18 +00:00
ortho_resolution = gsd.cap_resolution(args.orthophoto_resolution, tree.opensfm_reconstruction, ignore_gsd=args.ignore_gsd) / 100.0
dsm_multiplier = max(1.0, gsd.rounded_gsd(tree.opensfm_reconstruction, default_value=4, ndigits=3, ignore_gsd=args.ignore_gsd))
2018-10-17 15:35:18 +00:00
# A good DSM size depends on the flight altitude.
# Flights at low altitude need more details (higher resolution)
# Flights at higher altitude benefit from smoother surfaces (lower resolution)
dsm_resolution = ortho_resolution * dsm_multiplier
2018-10-24 16:30:09 +00:00
dsm_radius = dsm_resolution * math.sqrt(2)
# Sparse point clouds benefits from using
# a larger radius interolation --> less holes
if args.fast_orthophoto:
dsm_radius *= 2
log.ODM_DEBUG('ODM 2.5D DSM resolution: %s' % dsm_resolution)
mesh.create_25dmesh(tree.filtered_point_cloud, tree.odm_25dmesh,
2018-10-17 15:35:18 +00:00
dsm_radius=dsm_radius,
dsm_resolution=dsm_resolution,
2019-04-22 19:14:39 +00:00
depth=self.params.get('oct_tree'),
maxVertexCount=self.params.get('max_vertex'),
samples=self.params.get('samples'),
verbose=self.params.get('verbose'),
available_cores=args.max_concurrency,
method='poisson' if args.fast_orthophoto else 'gridded')
else:
log.ODM_WARNING('Found a valid ODM 2.5D Mesh file in: %s' %
tree.odm_25dmesh)