Skip to content

Commit 831fa1d

Browse files
committed
feat(create-surface): new blueprint to create polygonal surface
1 parent b65e54a commit 831fa1d

6 files changed

Lines changed: 192 additions & 0 deletions

File tree

opengeodeweb_back_schemas.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,62 @@
11
{
22
"opengeodeweb_back": {
33
"create": {
4+
"polygonal_surface": {
5+
"$id": "opengeodeweb_back/create/polygonal_surface",
6+
"route": "/polygonal_surface",
7+
"methods": [
8+
"POST"
9+
],
10+
"type": "object",
11+
"properties": {
12+
"name": {
13+
"type": "string",
14+
"minLength": 1
15+
},
16+
"points": {
17+
"type": "array",
18+
"items": {
19+
"title": "PolygonalSurfacePoint",
20+
"type": "object",
21+
"properties": {
22+
"x": {
23+
"type": "number"
24+
},
25+
"y": {
26+
"type": "number"
27+
},
28+
"z": {
29+
"type": "number"
30+
}
31+
},
32+
"required": [
33+
"x",
34+
"y",
35+
"z"
36+
],
37+
"additionalProperties": false
38+
},
39+
"minItems": 3
40+
},
41+
"polygons": {
42+
"type": "array",
43+
"items": {
44+
"type": "array",
45+
"items": {
46+
"type": "integer"
47+
},
48+
"minItems": 3
49+
},
50+
"minItems": 1
51+
}
52+
},
53+
"required": [
54+
"name",
55+
"points",
56+
"polygons"
57+
],
58+
"additionalProperties": false
59+
},
460
"point_set": {
561
"$id": "opengeodeweb_back/create/point_set",
662
"route": "/point_set",
@@ -102,6 +158,7 @@
102158
"additionalProperties": false
103159
}
104160
},
161+
"models": {},
105162
"vertex_attribute_names": {
106163
"$id": "opengeodeweb_back/vertex_attribute_names",
107164
"route": "/vertex_attribute_names",

src/opengeodeweb_back/routes/create/blueprint_create.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import opengeodeweb_back.routes.create.schemas as schemas
1212
from opengeodeweb_back.geode_objects.geode_point_set3d import GeodePointSet3D
1313
from opengeodeweb_back.geode_objects.geode_edged_curve3d import GeodeEdgedCurve3D
14+
from opengeodeweb_back.geode_objects.geode_polygonal_surface3d import GeodePolygonalSurface3D
1415

1516
routes = flask.Blueprint("create", __name__, url_prefix="/create")
1617
schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas"))
@@ -62,3 +63,32 @@ def edged_curve() -> flask.Response:
6263
edged_curve_obj
6364
)
6465
return flask.make_response(result, 200)
66+
67+
68+
@routes.route(
69+
schemas_dict["polygonal_surface"]["route"],
70+
methods=schemas_dict["polygonal_surface"]["methods"],
71+
)
72+
def polygonal_surface() -> flask.Response:
73+
"""Endpoint to create a polygonal surface in 3D space."""
74+
json_data = utils_functions.validate_request(
75+
flask.request, schemas_dict["polygonal_surface"]
76+
)
77+
params = schemas.PolygonalSurface.from_dict(json_data)
78+
79+
polygonal_surface_obj = GeodePolygonalSurface3D()
80+
builder = polygonal_surface_obj.builder()
81+
builder.set_name(params.name)
82+
for point in params.points:
83+
builder.create_point(opengeode.Point3D([point.x, point.y, point.z]))
84+
85+
for polygon in params.polygons:
86+
builder.create_polygon(polygon)
87+
88+
builder.compute_polygon_adjacencies()
89+
90+
result = utils_functions.generate_native_viewable_and_light_viewable_from_object(
91+
polygonal_surface_obj
92+
)
93+
return flask.make_response(result, 200)
94+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
from .polygonal_surface import *
12
from .point_set import *
23
from .edged_curve import *
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"route": "/polygonal_surface",
3+
"methods": ["POST"],
4+
"type": "object",
5+
"properties": {
6+
"name": {
7+
"type": "string",
8+
"minLength": 1
9+
},
10+
"points": {
11+
"type": "array",
12+
"items": {
13+
"title": "PolygonalSurfacePoint",
14+
"type": "object",
15+
"properties": {
16+
"x": { "type": "number" },
17+
"y": { "type": "number" },
18+
"z": { "type": "number" }
19+
},
20+
"required": ["x", "y", "z"],
21+
"additionalProperties": false
22+
},
23+
"minItems": 3
24+
},
25+
"polygons": {
26+
"type": "array",
27+
"items": {
28+
"type": "array",
29+
"items": { "type": "integer" },
30+
"minItems": 3
31+
},
32+
"minItems": 1
33+
}
34+
},
35+
"required": ["name", "points", "polygons"],
36+
"additionalProperties": false
37+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from dataclasses_json import DataClassJsonMixin
2+
from dataclasses import dataclass
3+
from typing import List
4+
5+
6+
@dataclass
7+
class PolygonalSurfacePoint(DataClassJsonMixin):
8+
def __post_init__(self) -> None:
9+
print(self, flush=True)
10+
11+
x: float
12+
y: float
13+
z: float
14+
15+
16+
@dataclass
17+
class PolygonalSurface(DataClassJsonMixin):
18+
def __post_init__(self) -> None:
19+
print(self, flush=True)
20+
21+
name: str
22+
points: List[PolygonalSurfacePoint]
23+
polygons: List[List[int]]

tests/test_create_routes.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ def curve_data() -> test_utils.JsonData:
2323
}
2424

2525

26+
@pytest.fixture
27+
def surface_data() -> test_utils.JsonData:
28+
return {
29+
"name": "test_surface",
30+
"points": [
31+
{"x": 0.0, "y": 0.0, "z": 0.0},
32+
{"x": 1.0, "y": 0.0, "z": 0.0},
33+
{"x": 1.0, "y": 1.0, "z": 0.0},
34+
{"x": 0.0, "y": 1.0, "z": 0.0},
35+
],
36+
"polygons": [[0, 1, 2, 3]],
37+
}
38+
39+
2640
def test_create_point(client: FlaskClient, point_data: test_utils.JsonData) -> None:
2741
"""Test the creation of a point with valid data."""
2842
route: str = "/opengeodeweb_back/create/point_set"
@@ -108,3 +122,33 @@ def test_create_curve(client: FlaskClient, curve_data: test_utils.JsonData) -> N
108122

109123
# Test with missing parameters
110124
test_utils.test_route_wrong_params(client, route, lambda: copy.deepcopy(curve_data))
125+
126+
127+
def test_create_polygonal_surface(
128+
client: FlaskClient, surface_data: test_utils.JsonData
129+
) -> None:
130+
"""Test the creation of a polygonal surface with valid data."""
131+
route: str = "/opengeodeweb_back/create/polygonal_surface"
132+
133+
# Test with all required data
134+
response = client.post(route, json=surface_data)
135+
assert response.status_code == 200
136+
137+
# Verify response data
138+
response_data = response.get_json()
139+
assert "viewable_file" in response_data
140+
assert "id" in response_data
141+
assert "name" in response_data
142+
assert "native_file" in response_data
143+
assert "viewer_type" in response_data
144+
assert "geode_object_type" in response_data
145+
146+
assert response_data["name"] == surface_data["name"]
147+
assert response_data["viewer_type"] == "mesh"
148+
assert response_data["geode_object_type"] == "PolygonalSurface3D"
149+
150+
# Test with missing parameters
151+
test_utils.test_route_wrong_params(
152+
client, route, lambda: copy.deepcopy(surface_data)
153+
)
154+

0 commit comments

Comments
 (0)