Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from werkzeug.exceptions import HTTPException

from src.opengeodeweb_back.routes import blueprint_routes
from src.opengeodeweb_back.routes.models import blueprint_models
from src.opengeodeweb_back.utils_functions import handle_exception
from src.opengeodeweb_back import app_config

Expand Down Expand Up @@ -34,6 +35,12 @@
name="blueprint_routes",
)

app.register_blueprint(
blueprint_models.routes,
url_prefix="/models",
name="blueprint_models",
)


@app.errorhandler(HTTPException)
def errorhandler(e):
Expand Down
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ flask[async]==3.1.0
# flask-cors
flask-cors==5.0.1
# via -r requirements.in
geode-background==9.1.5
geode-background==9.2.0
# via
# geode-explicit
# geode-implicit
# geode-simplex
geode-common==33.7.2
geode-common==33.7.5
# via
# -r requirements.in
# geode-background
Expand All @@ -35,27 +35,27 @@ geode-common==33.7.2
# geode-numerics
# geode-simplex
# geode-viewables
geode-conversion==6.2.7
geode-conversion==6.2.9
# via
# geode-explicit
# geode-implicit
# geode-simplex
geode-explicit==6.1.35
geode-explicit==6.1.37
# via
# -r requirements.in
# geode-implicit
geode-implicit==3.7.4
geode-implicit==3.7.6
# via -r requirements.in
geode-numerics==6.0.3
# via
# -r requirements.in
# geode-implicit
# geode-simplex
geode-simplex==9.2.5
geode-simplex==9.2.6
# via
# -r requirements.in
# geode-implicit
geode-viewables==3.0.12
geode-viewables==3.1.0
# via -r requirements.in
itsdangerous==2.2.0
# via flask
Expand All @@ -69,7 +69,7 @@ markupsafe==3.0.2
# via
# jinja2
# werkzeug
opengeode-core==15.17.8
opengeode-core==15.17.12
# via
# -r requirements.in
# geode-background
Expand All @@ -84,7 +84,7 @@ opengeode-core==15.17.8
# opengeode-geosciencesio
# opengeode-inspector
# opengeode-io
opengeode-geosciences==8.4.3
opengeode-geosciences==8.4.4
# via
# -r requirements.in
# geode-implicit
Expand Down
12 changes: 11 additions & 1 deletion src/opengeodeweb_back/routes/blueprint_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# Local application imports
from .. import geode_functions, utils_functions

routes = flask.Blueprint("routes", __name__)
from .models import blueprint_models

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


@routes.before_request
Expand All @@ -23,11 +25,19 @@ def before_request():

@routes.teardown_request
def teardown_request(exception):

if "ping" not in flask.request.path:
utils_functions.decrement_request_counter(flask.current_app)
utils_functions.update_last_request_time(flask.current_app)


routes.register_blueprint(
blueprint_models.routes,
url_prefix=blueprint_models.routes.url_prefix,
name=blueprint_models.routes.name,
)


schemas = os.path.join(os.path.dirname(__file__), "schemas")

with open(
Expand Down
74 changes: 74 additions & 0 deletions src/opengeodeweb_back/routes/models/blueprint_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import json
import os
import xml.etree.ElementTree as ET
import flask
from ... import geode_functions, utils_functions

routes = flask.Blueprint("models", __name__, url_prefix="/models")


schemas = os.path.join(os.path.dirname(__file__), "schemas")

with open(os.path.join(schemas, "vtm_component_indices.json"), "r") as file:
vtm_component_indices_json = json.load(file)


@routes.route(
vtm_component_indices_json["route"], methods=vtm_component_indices_json["methods"]
)
def uuid_to_flat_index():

print(f"uuid_to_flat_index : {flask.request=}", flush=True)
utils_functions.validate_request(flask.request, vtm_component_indices_json)
vtm_file_path = os.path.join(
flask.current_app.config["DATA_FOLDER_PATH"], flask.request.json["id"] + ".vtm"
)

tree = ET.parse(vtm_file_path)
root = tree.getroot()
uuid_to_flat_index = {}
current_index = 1

for elem in root.iter():
if "uuid" in elem.attrib and elem.tag == "DataSet":
uuid_to_flat_index[elem.attrib["uuid"]] = current_index
current_index += 1

return flask.make_response(
{"uuid_to_flat_index": uuid_to_flat_index},
200,
)


def extract_model_uuids(geode_object, file_path):
model = geode_functions.load(geode_object, file_path)
mesh_components = model.mesh_components()

uuid_dict = {}

for mesh_component, ids in mesh_components.items():
component_name = mesh_component.get()
uuid_dict[component_name] = [id.string() for id in ids]

return uuid_dict


with open(os.path.join(schemas, "mesh_components.json"), "r") as file:
mesh_components_json = json.load(file)


@routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"])
def extract_uuids_endpoint():
print(f"extract_uuids_endpoint : {flask.request=}", flush=True)

utils_functions.validate_request(flask.request, mesh_components_json)

file_path = os.path.join(
flask.current_app.config["DATA_FOLDER_PATH"], flask.request.json["filename"]
)

if not os.path.exists(file_path):
return flask.make_response({"error": "File not found"}, 404)

uuid_dict = extract_model_uuids(flask.request.json["geode_object"], file_path)
return flask.make_response({"uuid_dict": uuid_dict}, 200)
20 changes: 20 additions & 0 deletions src/opengeodeweb_back/routes/models/schemas/mesh_components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"route": "/mesh_components",
"methods": [
"POST"
],
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"geode_object": {
"type": "string"
}
},
"required": [
"filename",
"geode_object"
],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"route": "/vtm_component_indices",
"methods": [
"POST"
],
"type": "object",
"properties": {
"id": {
"type": "string"
}
},
"required": [
"id"
],
"additionalProperties": false
}
Binary file added tests/data/cube.og_brep
Binary file not shown.
40 changes: 40 additions & 0 deletions tests/data/cube.vtm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0"?>
<VTKFile type="vtkMultiBlockDataSet" version="1.0" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
<vtkMultiBlockDataSet>
<Block name="corners" index="0">
<DataSet index="0" name="default_name" uuid="00000000-3bf3-4551-8000-000064de2fdd" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-3bf3-4551-8000-000064de2fdd.vtp" />
<DataSet index="1" name="default_name" uuid="00000000-4629-412b-8000-0000edfff497" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-4629-412b-8000-0000edfff497.vtp" />
<DataSet index="2" name="default_name" uuid="00000000-7dc7-495b-8000-000052017dae" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-7dc7-495b-8000-000052017dae.vtp" />
<DataSet index="3" name="default_name" uuid="00000000-8a73-4f55-8000-00002bf05d8e" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-8a73-4f55-8000-00002bf05d8e.vtp" />
<DataSet index="4" name="default_name" uuid="00000000-96bd-4157-8000-0000213ddb29" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-96bd-4157-8000-0000213ddb29.vtp" />
<DataSet index="5" name="default_name" uuid="00000000-ecd6-40de-8000-0000f7ed1e32" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-ecd6-40de-8000-0000f7ed1e32.vtp" />
<DataSet index="6" name="default_name" uuid="00000000-f9e9-4ddd-8000-0000f19cf8cb" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-f9e9-4ddd-8000-0000f19cf8cb.vtp" />
<DataSet index="7" name="default_name" uuid="00000000-fc1e-4e5f-8000-00000af3f679" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Corner_00000000-fc1e-4e5f-8000-00000af3f679.vtp" />
</Block>
<Block name="lines" index="1">
<DataSet index="0" name="default_name" uuid="00000000-15ab-453c-8000-0000beee33c6" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-15ab-453c-8000-0000beee33c6.vtp" />
<DataSet index="1" name="default_name" uuid="00000000-1bd9-41e4-8000-000055e171a2" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-1bd9-41e4-8000-000055e171a2.vtp" />
<DataSet index="2" name="default_name" uuid="00000000-2326-4c21-8000-000054a373c7" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-2326-4c21-8000-000054a373c7.vtp" />
<DataSet index="3" name="default_name" uuid="00000000-304e-44a7-8000-0000c72260c1" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-304e-44a7-8000-0000c72260c1.vtp" />
<DataSet index="4" name="default_name" uuid="00000000-4755-4dfa-8000-000055999885" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-4755-4dfa-8000-000055999885.vtp" />
<DataSet index="5" name="default_name" uuid="00000000-57cf-41f4-8000-00006a4349dc" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-57cf-41f4-8000-00006a4349dc.vtp" />
<DataSet index="6" name="default_name" uuid="00000000-5a6b-45b2-8000-000004be554e" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-5a6b-45b2-8000-000004be554e.vtp" />
<DataSet index="7" name="default_name" uuid="00000000-93f2-437a-8000-00001b2727be" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-93f2-437a-8000-00001b2727be.vtp" />
<DataSet index="8" name="default_name" uuid="00000000-98f6-4012-8000-0000eb927a96" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-98f6-4012-8000-0000eb927a96.vtp" />
<DataSet index="9" name="default_name" uuid="00000000-9ca0-4e51-8000-00005b81d027" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-9ca0-4e51-8000-00005b81d027.vtp" />
<DataSet index="10" name="default_name" uuid="00000000-d720-47c9-8000-0000e54053cc" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-d720-47c9-8000-0000e54053cc.vtp" />
<DataSet index="11" name="default_name" uuid="00000000-f3ec-4765-8000-0000d74e506d" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Line_00000000-f3ec-4765-8000-0000d74e506d.vtp" />
</Block>
<Block name="surfaces" index="2">
<DataSet index="0" name="default_name" uuid="00000000-1702-4d26-8000-000004d7ea39" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-1702-4d26-8000-000004d7ea39.vtp" />
<DataSet index="1" name="default_name" uuid="00000000-6732-4f29-8000-00002f66bc93" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-6732-4f29-8000-00002f66bc93.vtp" />
<DataSet index="2" name="default_name" uuid="00000000-8afd-4969-8000-000092a43747" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-8afd-4969-8000-000092a43747.vtp" />
<DataSet index="3" name="default_name" uuid="00000000-cddf-4c1c-8000-00005ebbcaeb" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-cddf-4c1c-8000-00005ebbcaeb.vtp" />
<DataSet index="4" name="default_name" uuid="00000000-dc1c-420d-8000-000070dcfff5" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-dc1c-420d-8000-000070dcfff5.vtp" />
<DataSet index="5" name="default_name" uuid="00000000-dcfe-400a-8000-0000a72c4f30" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Surface_00000000-dcfe-400a-8000-0000a72c4f30.vtp" />
</Block>
<Block name="blocks" index="3">
<DataSet index="0" file="b11b028cbe4c4e7c9d27279e52ea5eb2/Block_00000000-4335-411d-8000-000079b34fe5.vtu" name="default_name" uuid="00000000-4335-411d-8000-000079b34fe5" />
</Block>
</vtkMultiBlockDataSet>
</VTKFile>
30 changes: 30 additions & 0 deletions tests/test_models_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def test_model_mesh_components(client):
route = f"/models/vtm_component_indices"
get_full_data = lambda: {"id": "cube"}
json = get_full_data()
response = client.post(route, json=json)
assert response.status_code == 200
uuid_dict = response.json["uuid_to_flat_index"]
assert type(uuid_dict) is dict

indices = list(uuid_dict.values())
indices.sort()
assert indices[0] == 1
assert all(indices[i] == indices[i - 1] + 1 for i in range(1, len(indices)))


def test_extract_brep_uuids(client):
route = "/models/mesh_components"
json_data = {"filename": "cube.og_brep", "geode_object": "BRep"}

response = client.post(route, json=json_data)

assert response.status_code == 200
uuid_dict = response.json["uuid_dict"]
assert isinstance(uuid_dict, dict)
assert (
"Block" in uuid_dict
or "Line" in uuid_dict
or "Surface" in uuid_dict
or "Corner" in uuid_dict
)