diff --git a/VERSION b/VERSION index 9cec7165..23887f6e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.6 +3.1.7 diff --git a/opendm/entwine.py b/opendm/entwine.py index e430d867..fbfddbf9 100644 --- a/opendm/entwine.py +++ b/opendm/entwine.py @@ -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) \ No newline at end of file + for d in cleanup: + if os.path.exists(d): + shutil.rmtree(d) \ No newline at end of file diff --git a/opendm/point_cloud.py b/opendm/point_cloud.py index f178c08c..abe7ee91 100644 --- a/opendm/point_cloud.py +++ b/opendm/point_cloud.py @@ -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) \ No newline at end of file + entwine.build_copc([tree.odm_georeferencing_model_laz], copc_output, convert_rgb_8_to_16=True) \ No newline at end of file