kopia lustrzana https://github.com/OpenDroneMap/WebODM
Working texture model localization
rodzic
cd699355d7
commit
ff70933e84
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
Ładowanie…
Reference in New Issue