From ff70933e842f86c57ed5c76874ebdef779bcbacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CBrandon?= Date: Mon, 15 Jul 2019 14:00:16 -0400 Subject: [PATCH] Working texture model localization --- plugins/cesium-ion/api_views.py | 19 +++-- plugins/cesium-ion/public/TaskView.jsx | 2 +- .../cesium-ion/public/components/Fetcher.jsx | 5 +- plugins/cesium-ion/texture_utils.py | 79 ------------------- 4 files changed, 14 insertions(+), 91 deletions(-) delete mode 100644 plugins/cesium-ion/texture_utils.py diff --git a/plugins/cesium-ion/api_views.py b/plugins/cesium-ion/api_views.py index 4e3bd0f7..533b8e0d 100644 --- a/plugins/cesium-ion/api_views.py +++ b/plugins/cesium-ion/api_views.py @@ -21,7 +21,6 @@ from rest_framework import status from rest_framework import serializers from .globals import PROJECT_NAME, ION_API_URL -from .texture_utils import get_texture_model_origin pluck = lambda dic, *keys: [dic[k] if k in dic else None for k in keys] @@ -246,13 +245,17 @@ class ShareTaskView(TaskView): # Skip already processing tasks if asset_type not in get_processing_assets(task.id): if asset_type == AssetType.TEXTURED_MODEL and "position" not in options: - try: - options["position"] = list(get_texture_model_origin(task)) - print(options) - except Exception as e: - print("Failed to find origin: {task}") - print(e) - print(options["position"]) + extent = None + if task.dsm_extent is not None: + extent = task.dsm_extent.extent + if task.dtm_extent is not None: + extent = task.dtm_extent.extent + if extent is None: + print(f"Unable to find task boundary: {task}") + else: + lng, lat = extent[0], extent[1] + # height is set to zero as model is already offset + options["position"] = [lng, lat, 0] del_asset_info(task.id, asset_type) asset_info = get_asset_info(task.id, asset_type) diff --git a/plugins/cesium-ion/public/TaskView.jsx b/plugins/cesium-ion/public/TaskView.jsx index 69cb37f3..50a13382 100644 --- a/plugins/cesium-ion/public/TaskView.jsx +++ b/plugins/cesium-ion/public/TaskView.jsx @@ -94,7 +94,7 @@ export default class TaskView extends Component { } }; - onCleanStatus = ({ data: { updated = false } }) => { + onCleanStatus = ({ updated = false }) => { if (!updated || this.refreshAssets == null) return; this.refreshAssets(); }; diff --git a/plugins/cesium-ion/public/components/Fetcher.jsx b/plugins/cesium-ion/public/components/Fetcher.jsx index 9d46533f..3cd10a0f 100644 --- a/plugins/cesium-ion/public/components/Fetcher.jsx +++ b/plugins/cesium-ion/public/components/Fetcher.jsx @@ -52,14 +52,13 @@ export class Fetcher extends PureComponent { .then(data => { this.setState({ data, isLoading: false }); onLoad(data); - this.cancelableFetch = null; }) .catch(out => { if (out.isCanceled) return; this.setState({ error: out, isLoading: false, isError: true }); onError(out); - this.cancelableFetch = null; - }); + }) + .finally(() => (this.cancelableFetch = null)); }; componentDidMount() { diff --git a/plugins/cesium-ion/texture_utils.py b/plugins/cesium-ion/texture_utils.py deleted file mode 100644 index acfc4614..00000000 --- a/plugins/cesium-ion/texture_utils.py +++ /dev/null @@ -1,79 +0,0 @@ -from zipfile import ZipFile, BadZipfile -from collections import namedtuple -import imp - -Coordinate = namedtuple("Coordinate", ["lng", "lat", "height"]) - - -def module_exists(module): - try: - imp.find_module(module) - return True - except ImportError: - return False - - -def get_python_texture_min_height(zip_file): - archive = ZipFile(zip_file, "r") - target_obj = "odm_textured_model_geo.obj" - if target_obj not in archive.namelist(): - raise BadZipfile(f"Cannot find georefenced file: {target_obj}") - - delimiter = b" " - start_tag, delim_tag = ord("v"), ord(delimiter) - - min_height = float("inf") - with archive.open(target_obj) as obj: - for line in obj: - if line[0] != start_tag or line[1] != delim_tag: - continue - temp_float = float(line.split(delimiter, 3)[3]) - if temp_float < min_height: - min_height = temp_float - - if min_height == float("inf"): - raise Exception("Unable to find minimum vertex") - - return min_height - - -def get_numpy_texture_min_height(zip_file): - import numpy as np - - archive = ZipFile(zip_file, "r") - target_obj = "odm_textured_model_geo.obj" - if target_obj not in archive.namelist(): - raise BadZipfile(f"Cannot find georefenced file: {target_obj}") - - vertices = np.fromregex( - archive.open(target_obj), - r"v (-?\d+\.\d+) (-?\d+\.\d+) (-?\d+\.\d+).*", - [("lat", np.float32), ("lng", np.float32), ("height", np.float32)], - ) - - if len(vertices["height"]) <= 0: - raise Exception("Unable to find minimum vertex") - - return min(vertices["height"]) - - -def get_texture_min_height(zip_file): - if module_exists("numpy"): - return get_numpy_texture_min_height(zip_file) - else: - return get_python_texture_min_height(zip_file) - - -def get_texture_model_origin(task): - extent = None - if task.dsm_extent is not None: - extent = task.dsm_extent.extent - if task.dtm_extent is not None: - extent = task.dtm_extent.extent - if extent is None: - raise Exception(f"Unable to find task boundary: {task}") - - lng, lat = extent[0], extent[1] - # texture_model_path = task.get_asset_download_path("textured_model.zip") - # height = get_texture_min_height(texture_model_path) - return Coordinate(lng=lng, lat=lat, height=0)