Skip to content

Commit 1c4f4ee

Browse files
committed
last changes back
1 parent 5ac94f6 commit 1c4f4ee

File tree

2 files changed

+18
-56
lines changed

2 files changed

+18
-56
lines changed

src/opengeodeweb_back/routes/create/blueprint_create.py

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
)
2121
def create_point() -> flask.Response:
2222
"""Endpoint to create a single point in 3D space."""
23-
print(f"create_point : {flask.request=}", flush=True)
2423
utils_functions.validate_request(flask.request, schemas_dict["create_point"])
2524
params = schemas.CreatePoint.from_dict(flask.request.get_json())
2625

@@ -43,7 +42,6 @@ def create_point() -> flask.Response:
4342
)
4443
def create_aoi() -> flask.Response:
4544
"""Endpoint to create an Area of Interest (AOI) as an EdgedCurve3D."""
46-
print(f"create_aoi : {flask.request=}", flush=True)
4745
utils_functions.validate_request(flask.request, schemas_dict["create_aoi"])
4846
params = schemas.CreateAoi.from_dict(flask.request.get_json())
4947

@@ -54,7 +52,6 @@ def create_aoi() -> flask.Response:
5452

5553
# Create vertices first
5654
for point in params.points:
57-
# pp = opengeode.Point3D([point.x, point.y, params.z])
5855
builder.create_point(opengeode.Point3D([point.x, point.y, params.z]))
5956

6057
# Create edges between consecutive vertices and close the loop
@@ -70,66 +67,43 @@ def create_aoi() -> flask.Response:
7067
)
7168
return flask.make_response(result, 200)
7269

73-
7470
@routes.route(
75-
schemas_dict["create_voi"]["route"], methods=schemas_dict["create_voi"]["methods"]
71+
schemas_dict["create_voi"]["route"],
72+
methods=schemas_dict["create_voi"]["methods"],
7673
)
7774
def create_voi() -> flask.Response:
78-
"""Endpoint to create a Volume of Interest (VOI) as an EdgedCurve3D (a bounding box)."""
79-
print(f"create_voi : {flask.request=}", flush=True)
75+
"""Endpoint to create a Volume of Interest (VOI) as an EdgedCurve3D (a bounding box/prism)."""
8076
utils_functions.validate_request(flask.request, schemas_dict["create_voi"])
8177
params = schemas.CreateVoi.from_dict(flask.request.get_json())
8278

8379
aoi_data = geode_functions.get_data_info(params.aoi_id)
8480
if not aoi_data:
8581
flask.abort(404, f"AOI with id {params.aoi_id} not found")
8682

87-
edged_curve_aoi = geode_functions.load_data(params.aoi_id)
88-
if not isinstance(edged_curve_aoi, opengeode.EdgedCurve3D):
89-
flask.abort(400, "Referenced object is not an EdgedCurve3D (AOI)")
90-
91-
bbox_aoi = edged_curve_aoi.bounding_box()
92-
min_x = bbox_aoi.min().value(0)
93-
min_y = bbox_aoi.min().value(1)
94-
max_x = bbox_aoi.max().value(0)
95-
max_y = bbox_aoi.max().value(1)
96-
97-
aoi_vertices = [
98-
(min_x, min_y),
99-
(max_x, min_y),
100-
(max_x, max_y),
101-
(min_x, max_y),
102-
]
83+
aoi_object = geode_functions.load_data(params.aoi_id)
84+
85+
nb_points = aoi_object.nb_vertices()
10386

10487
edged_curve = geode_functions.geode_object_class("EdgedCurve3D").create()
10588
builder = geode_functions.create_builder("EdgedCurve3D", edged_curve)
10689
builder.set_name(params.name)
10790

108-
z_min = params.z_min
109-
z_max = params.z_max
110-
111-
112-
for x, y in aoi_vertices:
113-
builder.create_point(opengeode.Point3D([x, y, z_min]))
114-
115-
for x, y in aoi_vertices:
116-
builder.create_point(opengeode.Point3D([x, y, z_max]))
117-
118-
119-
bottom_edges = [(i, (i + 1) % 4) for i in range(4)]
120-
121-
top_edges = [(i + 4, (i + 1) % 4 + 4) for i in range(4)]
122-
123-
vertical_edges = [(i, i + 4) for i in range(4)]
124-
125-
all_edges = bottom_edges + top_edges + vertical_edges
91+
for point_id in range(nb_points):
92+
aoi_point= aoi_object.point(point_id)
93+
builder.create_point(opengeode.Point3D([aoi_point.value(0), aoi_point.value(1), params.z_min]))
94+
95+
for point_id in range(nb_points):
96+
aoi_point= aoi_object.point(point_id)
97+
builder.create_point(opengeode.Point3D([aoi_point.value(0), aoi_point.value(1), params.z_max]))
12698

127-
for v1, v2 in all_edges:
128-
builder.create_edge_with_vertices(v1, v2)
99+
for point_id in range(nb_points):
100+
next_point = (point_id + 1) % nb_points
101+
builder.create_edge_with_vertices(point_id, next_point)
102+
builder.create_edge_with_vertices(point_id+nb_points, next_point+nb_points)
103+
builder.create_edge_with_vertices(point_id, point_id+nb_points)
129104

130105
result = utils_functions.generate_native_viewable_and_light_viewable_from_object(
131106
geode_object="EdgedCurve3D",
132107
data=edged_curve,
133108
)
134-
result["aoi_id"] = params.aoi_id
135109
return flask.make_response(result, 200)

src/opengeodeweb_back/routes/create/schemas/create_voi.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ class CreateVoi(DataClassJsonMixin):
88
aoi_id: str
99
"""ID of the corresponding AOI"""
1010

11-
max_x: float
12-
"""Maximum X coordinate from AOI"""
13-
14-
max_y: float
15-
"""Maximum Y coordinate from AOI"""
16-
17-
min_x: float
18-
"""Minimum X coordinate from AOI"""
19-
20-
min_y: float
21-
"""Minimum Y coordinate from AOI"""
22-
2311
name: str
2412
"""Name of the VOI"""
2513

0 commit comments

Comments
 (0)