Skip to content

Commit 5bad562

Browse files
authored
Merge pull request #231 from Geode-solutions/perf/model-components
perf(Model): merge model components with save viewable
2 parents f60a9f3 + 1be3c43 commit 5bad562

11 files changed

Lines changed: 240 additions & 426 deletions

opengeodeweb_back_schemas.json

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,6 @@
3232
"additionalProperties": false
3333
}
3434
},
35-
"models": {
36-
"model_components": {
37-
"$id": "opengeodeweb_back/models/model_components",
38-
"route": "/model_components",
39-
"methods": [
40-
"POST"
41-
],
42-
"type": "object",
43-
"properties": {
44-
"id": {
45-
"type": "string",
46-
"minLength": 1
47-
}
48-
},
49-
"required": [
50-
"id"
51-
],
52-
"additionalProperties": false
53-
}
54-
},
5535
"vertex_attribute_names": {
5636
"$id": "opengeodeweb_back/vertex_attribute_names",
5737
"route": "/vertex_attribute_names",

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ werkzeug==3.1.2
6060
# flask
6161
# flask-cors
6262

63-
opengeodeweb-microservice==1.*,>=1.0.16rc1

src/opengeodeweb_back/app.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from werkzeug.exceptions import HTTPException
1111
from opengeodeweb_back import utils_functions, app_config
1212
from opengeodeweb_back.routes import blueprint_routes
13-
from opengeodeweb_back.routes.models import blueprint_models
1413
from opengeodeweb_back.routes.create import blueprint_create
1514
from opengeodeweb_microservice.database import connection
1615

@@ -85,11 +84,6 @@ def register_ogw_back_blueprints(app: flask.Flask) -> None:
8584
url_prefix="/opengeodeweb_back",
8685
name="opengeodeweb_back",
8786
)
88-
app.register_blueprint(
89-
blueprint_models.routes,
90-
url_prefix="/opengeodeweb_back/models",
91-
name="opengeodeweb_models",
92-
)
9387
app.register_blueprint(
9488
blueprint_create.routes,
9589
url_prefix="/opengeodeweb_back/create",

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
# Local application imports
2323
from opengeodeweb_back import geode_functions, utils_functions
2424
from opengeodeweb_back.routes import schemas
25-
from opengeodeweb_back.routes.models import blueprint_models
2625
from opengeodeweb_back.geode_objects import geode_objects
2726
from opengeodeweb_back.geode_objects.geode_mesh import GeodeMesh
2827
from opengeodeweb_back.geode_objects.geode_graph import GeodeGraph
@@ -34,13 +33,6 @@
3433

3534
routes = flask.Blueprint("routes", __name__, url_prefix="/opengeodeweb_back")
3635

37-
38-
routes.register_blueprint(
39-
blueprint_models.routes,
40-
url_prefix=blueprint_models.routes.url_prefix,
41-
name=blueprint_models.routes.name,
42-
)
43-
4436
schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas"))
4537

4638

src/opengeodeweb_back/routes/models/blueprint_models.py

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/opengeodeweb_back/routes/models/schemas/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/opengeodeweb_back/routes/models/schemas/model_components.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/opengeodeweb_back/routes/models/schemas/model_components.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/opengeodeweb_back/utils_functions.py

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import threading
44
import time
5+
import xml.etree.ElementTree as ET
56
import zipfile
67
from collections.abc import Callable
78
from concurrent.futures import ThreadPoolExecutor
@@ -22,6 +23,7 @@
2223
# Local application imports
2324
from . import geode_functions
2425
from .geode_objects import geode_objects
26+
from .geode_objects.geode_model import GeodeModel
2527
from .geode_objects.geode_object import GeodeObject
2628

2729

@@ -191,11 +193,69 @@ def create_data_folder_from_id(data_id: str) -> str:
191193
return data_path
192194

193195

196+
def model_components(
197+
data_id: str, model: GeodeModel, viewable_file: str
198+
) -> dict[str, Any]:
199+
vtm_file_path = geode_functions.data_file_path(data_id, viewable_file)
200+
tree = ET.parse(vtm_file_path)
201+
root = tree.find("vtkMultiBlockDataSet")
202+
if root is None:
203+
flask.abort(500, "Failed to read viewable file")
204+
uuid_to_flat_index = {}
205+
current_index = 0
206+
assert root is not None
207+
for elem in root.iter():
208+
if "uuid" in elem.attrib and elem.tag == "DataSet":
209+
uuid_to_flat_index[elem.attrib["uuid"]] = current_index
210+
current_index += 1
211+
model_mesh_components = model.mesh_components()
212+
mesh_components = []
213+
for mesh_component, ids in model_mesh_components.items():
214+
component_type = mesh_component.get()
215+
for id in ids:
216+
geode_id = id.string()
217+
component_name = geode_id
218+
viewer_id = uuid_to_flat_index[geode_id]
219+
boundaries = model.boundaries(id)
220+
boundaries_uuid = [boundary.id().string() for boundary in boundaries]
221+
internals = model.internals(id)
222+
internals_uuid = [internal.id().string() for internal in internals]
223+
mesh_component_object = {
224+
"viewer_id": viewer_id,
225+
"geode_id": geode_id,
226+
"name": component_name,
227+
"type": component_type,
228+
"boundaries": boundaries_uuid,
229+
"internals": internals_uuid,
230+
}
231+
mesh_components.append(mesh_component_object)
232+
233+
model_collection_components = model.collection_components()
234+
collection_components = []
235+
for collection_component, ids in model_collection_components.items():
236+
component_type = collection_component.get()
237+
for id in ids:
238+
geode_id = id.string()
239+
items = model.items(id)
240+
items_uuid = [item.id().string() for item in items]
241+
collection_component_object = {
242+
"geode_id": geode_id,
243+
"name": geode_id,
244+
"type": component_type,
245+
"items": items_uuid,
246+
}
247+
collection_components.append(collection_component_object)
248+
return {
249+
"mesh_components": mesh_components,
250+
"collection_components": collection_components,
251+
}
252+
253+
194254
def save_all_viewables_and_return_info(
195255
geode_object: GeodeObject,
196256
data: Data,
197257
data_path: str,
198-
) -> dict[str, str | list[str]]:
258+
) -> dict[str, Any]:
199259
with ThreadPoolExecutor() as executor:
200260
native_files, viewable_path, light_path = executor.map(
201261
lambda args: args[0](args[1]),
@@ -225,7 +285,8 @@ def save_all_viewables_and_return_info(
225285
name = geode_object.identifier.name()
226286
if not name:
227287
flask.abort(400, "Geode object has no name defined.")
228-
return {
288+
289+
response: dict[str, Any] = {
229290
"native_file": data.native_file,
230291
"viewable_file": data.viewable_file,
231292
"id": data.id,
@@ -234,11 +295,14 @@ def save_all_viewables_and_return_info(
234295
"binary_light_viewable": binary_light_viewable.decode("utf-8"),
235296
"geode_object_type": data.geode_object,
236297
}
298+
if isinstance(geode_object, GeodeModel):
299+
response |= model_components(data.id, geode_object, data.viewable_file)
300+
return response
237301

238302

239303
def generate_native_viewable_and_light_viewable_from_object(
240304
geode_object: GeodeObject,
241-
) -> dict[str, str | list[str]]:
305+
) -> dict[str, Any]:
242306
data = Data.create(
243307
geode_object=geode_object.geode_object_type(),
244308
viewer_object=geode_object.viewer_type(),
@@ -250,7 +314,7 @@ def generate_native_viewable_and_light_viewable_from_object(
250314

251315
def generate_native_viewable_and_light_viewable_from_file(
252316
geode_object_type: GeodeObjectType, input_file: str
253-
) -> dict[str, str | list[str]]:
317+
) -> dict[str, Any]:
254318
generic_geode_object = geode_objects[geode_object_type]
255319
data = Data.create(
256320
geode_object=geode_object_type,

0 commit comments

Comments
 (0)