Merge pull request #1657 from pierotofy/copcfix

Fix COPC export
pull/1659/head
Piero Toffanin 2023-05-22 21:11:34 -04:00 zatwierdzone przez GitHub
commit ce6c745715
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 37 dodań i 5 usunięć

Wyświetl plik

@ -1 +1 @@
3.1.6
3.1.7

Wyświetl plik

@ -62,17 +62,48 @@ def build_untwine(input_point_cloud_files, tmpdir, output_path, max_concurrency=
# Run untwine
system.run('untwine --temp_dir "{tmpdir}" {files} --output_dir "{outputdir}"'.format(**kwargs))
def build_copc(input_point_cloud_files, output_file):
def build_copc(input_point_cloud_files, output_file, convert_rgb_8_to_16=False):
if len(input_point_cloud_files) == 0:
logger.ODM_WARNING("Cannot build COPC, no input files")
return
base_path, ext = os.path.splitext(output_file)
tmpdir = io.related_file_path(base_path, postfix="-tmp")
if os.path.exists(tmpdir):
log.ODM_WARNING("Removing previous directory %s" % tmpdir)
shutil.rmtree(tmpdir)
cleanup = [tmpdir]
if convert_rgb_8_to_16:
tmpdir16 = io.related_file_path(base_path, postfix="-tmp16")
if os.path.exists(tmpdir16):
log.ODM_WARNING("Removing previous directory %s" % tmpdir16)
shutil.rmtree(tmpdir16)
os.makedirs(tmpdir16, exist_ok=True)
cleanup.append(tmpdir16)
converted = []
ok = True
for f in input_point_cloud_files:
# Convert 8bit RGB to 16bit RGB (per COPC spec)
base = os.path.basename(f)
filename, ext = os.path.splitext(base)
out_16 = os.path.join(tmpdir16, "%s_16%s" % (filename, ext))
try:
system.run('pdal translate -i "{input}" -o "{output}" assign '
'--filters.assign.value="Red = Red / 255 * 65535" '
'--filters.assign.value="Green = Green / 255 * 65535" '
'--filters.assign.value="Blue = Blue / 255 * 65535" '.format(input=f, output=out_16))
converted.append(out_16)
except Exception as e:
log.ODM_WARNING("Cannot convert point cloud to 16bit RGB, COPC is not going to follow the official spec: %s" % str(e))
ok = False
break
if ok:
input_point_cloud_files = converted
kwargs = {
'tmpdir': tmpdir,
'files': "--files " + " ".join(map(double_quote, input_point_cloud_files)),
@ -82,5 +113,6 @@ def build_copc(input_point_cloud_files, output_file):
# Run untwine
system.run('untwine --temp_dir "{tmpdir}" {files} -o "{output}" --single_file'.format(**kwargs))
if os.path.exists(tmpdir):
shutil.rmtree(tmpdir)
for d in cleanup:
if os.path.exists(d):
shutil.rmtree(d)

Wyświetl plik

@ -311,4 +311,4 @@ def post_point_cloud_steps(args, tree, rerun=False):
log.ODM_INFO("Creating Cloud Optimized Point Cloud (COPC)")
copc_output = io.related_file_path(tree.odm_georeferencing_model_laz, postfix=".copc")
entwine.build_copc([tree.odm_georeferencing_model_laz], copc_output)
entwine.build_copc([tree.odm_georeferencing_model_laz], copc_output, convert_rgb_8_to_16=True)