Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Binary file added output.og_tsf3d
Binary file not shown.
82 changes: 82 additions & 0 deletions src/opengeodeweb_back/routes/models/blueprint_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import json
import os
import xml.etree.ElementTree as ET
import flask
from src.opengeodeweb_back import geode_functions, utils_functions
from opengeode import model

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


@routes.before_request
def before_request():
if "ping" not in flask.request.path:
utils_functions.increment_request_counter(flask.current_app)


@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)


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

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 uuid_to_flat_index():
utils_functions.validate_request(flask.request, mesh_components_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, "components_types.json"), "r") as file:
components_types_json = json.load(file)


@routes.route(components_types_json["route"], methods=components_types_json["methods"])
def extract_uuids_endpoint():
utils_functions.validate_request(flask.request, components_types_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, 200)
20 changes: 20 additions & 0 deletions src/opengeodeweb_back/routes/models/schemas/components_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"route": "/components_types",
"methods": [
"POST"
],
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"geode_object": {
"type": "string"
}
},
"required": [
"filename",
"geode_object"
],
"additionalProperties": false
}
16 changes: 16 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,16 @@
{
"route": "/mesh_components",
"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>
35 changes: 35 additions & 0 deletions tests/test_models_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
from werkzeug.datastructures import FileStorage
from src.opengeodeweb_back import geode_functions, geode_objects, test_utils


def test_model_mesh_components(client):
route = f"/models/mesh_components"
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/components_types"
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
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
)