Skip to content

Commit 88d18ce

Browse files
Merge pull request #48 from Geode-solutions/feat/mesh_polyhedrons_protocols
feat(protocols): new polyhedrons protocols
2 parents 41eca1e + 4be5438 commit 88d18ce

22 files changed

+244
-32
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ __pycache__/
99
latest_logs
1010
schemas.json
1111
build
12-
src/tests/tests_output/
12+
/src/tests/tests_output/
1313
*.egg-info

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ where = ["src"]
4141
"opengeodeweb_viewer.rpc.mesh.points.schemas" = ["*.json"]
4242
"opengeodeweb_viewer.rpc.mesh.edges.schemas" = ["*.json"]
4343
"opengeodeweb_viewer.rpc.mesh.polygons.schemas" = ["*.json"]
44+
"opengeodeweb_viewer.rpc.mesh.polyhedrons.schemas" = ["*.json"]
4445
"opengeodeweb_viewer.rpc.model.schemas" = ["*.json"]
4546
"opengeodeweb_viewer.rpc.viewer.schemas" = ["*.json"]
4647

src/opengeodeweb_viewer/object/object_methods.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def applyTextures(self, id, textures):
8888

8989
self.render()
9090

91-
9291
def SetVisibility(self, id, visibility):
9392
actor = self.get_object(id)["actor"]
9493
actor.SetVisibility(visibility)
@@ -103,7 +102,7 @@ def SetColor(self, id, red, green, blue):
103102
mapper = self.get_object(id)["mapper"]
104103
mapper.ScalarVisibilityOff()
105104
actor = self.get_object(id)["actor"]
106-
actor.GetProperty().SetColor([red, green, blue])
105+
actor.GetProperty().SetColor([red/255, green/255, blue/255])
107106
self.render()
108107

109108
def SetEdgesVisibility(self, id, visibility):
@@ -116,10 +115,11 @@ def SetEdgesSize(self, id, size):
116115
actor.GetProperty().SetEdgeWidth(size)
117116
self.render()
118117

119-
def SetEdgesColor(self, id, color):
118+
def SetEdgesColor(self, id, red, green, blue):
120119
actor = self.get_object(id)["actor"]
121-
actor.GetProperty().SetEdgeColor(color)
120+
actor.GetProperty().SetEdgeColor([red/255, green/255, blue/255])
122121
self.render()
122+
123123
def SetPointsVisibility(self, id, visibility):
124124
actor = self.get_object(id)["actor"]
125125
actor.GetProperty().SetVertexVisibility(visibility)
@@ -131,19 +131,9 @@ def SetPointsSize(self, id, size):
131131
actor.GetProperty().SetPointSize(size)
132132
self.render()
133133

134-
def SetPointsColor(self, id, color):
135-
actor = self.get_object(id)["actor"]
136-
actor.GetProperty().SetVertexColor(color)
137-
self.render()
138-
139-
def SetPolygonsVisibility(self, id, visibility):
140-
actor = self.get_object(id)["actor"]
141-
actor.SetVisibility(visibility)
142-
self.render()
143-
144-
def SetPolygonsColor(self, id, color):
134+
def SetPointsColor(self, id, red, green, blue):
145135
actor = self.get_object(id)["actor"]
146-
actor.GetProperty().SetColor(color)
136+
actor.GetProperty().SetVertexColor([red/255, green/255, blue/255])
147137
self.render()
148138

149139
def clearColors(self, id):

src/opengeodeweb_viewer/rpc/mesh/edges/edges_protocols.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def setMeshEdgesColor(self, params):
2828
print(self.mesh_edges_prefix + self.mesh_edges_schemas_dict["color"]["rpc"], f"{params=}", flush=True)
2929
validate_schema(params, self.mesh_edges_schemas_dict["color"])
3030
id = params["id"]
31-
red, green, blue = params["color"]["r"]/255, params["color"]["g"]/255, params["color"]["b"]/255
32-
self.SetEdgesColor(id, [red, green, blue])
31+
red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"]
32+
self.SetEdgesColor(id, red, green, blue)
3333

3434
@exportRpc(mesh_edges_prefix + mesh_edges_schemas_dict["size"]["rpc"])
3535
def setMeshEdgesSize(self, params):

src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ def setMeshColor(self, params):
5959
print(self.mesh_prefix + self.mesh_schemas_dict["color"]["rpc"], f"{params=}", flush=True)
6060
validate_schema(params, self.mesh_schemas_dict["color"])
6161
id = params["id"]
62-
red, green, blue = params["color"]["r"]/255, params["color"]["g"]/255, params["color"]["b"]/255
62+
red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"]
6363
self.SetColor(id, red, green, blue)
6464

65-
def setMeshVertexAttribute(self, id, name):
65+
def displayAttributeOnVertices(self, id, name):
6666
reader = self.get_object(id)["reader"]
6767
points = reader.GetOutput().GetPointData()
6868
points.SetActiveScalars(name)
@@ -72,7 +72,8 @@ def setMeshVertexAttribute(self, id, name):
7272
mapper.SetScalarRange(points.GetScalars().GetRange())
7373
self.render()
7474

75-
def setMeshPolygonAttribute(self, id, name):
75+
76+
def displayAttributeOnCells(self, id, name):
7677
reader = self.get_object(id)["reader"]
7778
cells = reader.GetOutput().GetCellData()
7879
cells.SetActiveScalars(name)

src/opengeodeweb_viewer/rpc/mesh/points/points_protocols.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def setMeshPointsColor(self, params):
2828
print(self.mesh_points_prefix + self.mesh_points_schemas_dict["color"]["rpc"], f"{params=}", flush=True)
2929
validate_schema(params, self.mesh_points_schemas_dict["color"])
3030
id = str(params["id"])
31-
red, green, blue = params["color"]["r"]/255, params["color"]["g"]/255, params["color"]["b"]/255
32-
self.SetPointsColor(id, [red, green, blue])
31+
red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"]
32+
self.SetPointsColor(id, red, green, blue)
3333

3434
@exportRpc(mesh_points_prefix + mesh_points_schemas_dict["size"]["rpc"])
3535
def setMeshPointsSize(self, params):
@@ -45,5 +45,5 @@ def setMeshPointsVertexAttribute(self, params):
4545
validate_schema(params, self.mesh_points_schemas_dict["vertex_attribute"])
4646
id = str(params["id"])
4747
name = str(params["name"])
48-
self.setMeshVertexAttribute(id, name)
48+
self.displayAttributeOnVertices(id, name)
4949

src/opengeodeweb_viewer/rpc/mesh/polygons/polygons_protocols.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ def setMeshPolygonsVisibility(self, params):
2121
validate_schema(params, self.mesh_polygons_schemas_dict["visibility"])
2222
id = params["id"]
2323
visibility = bool(params["visibility"])
24-
self.SetPolygonsVisibility(id, visibility)
25-
24+
self.SetVisibility(id, visibility)
25+
2626
@exportRpc(mesh_polygons_prefix + mesh_polygons_schemas_dict["color"]["rpc"])
2727
def setMeshPolygonsColor(self, params):
2828
print(self.mesh_polygons_prefix + self.mesh_polygons_schemas_dict["color"]["rpc"], f"{params=}", flush=True)
2929
validate_schema(params, self.mesh_polygons_schemas_dict["color"])
3030
id = params["id"]
31-
red, green, blue = params["color"]["r"]/255, params["color"]["g"]/255, params["color"]["b"]/255
32-
self.SetPolygonsColor(id, [red, green, blue])
31+
red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"]
32+
self.SetColor(id, red, green, blue)
3333

3434
@exportRpc(mesh_polygons_prefix + mesh_polygons_schemas_dict["vertex_attribute"]["rpc"])
3535
def setMeshPolygonsVertexAttribute(self, params):
3636
print(self.mesh_polygons_prefix + self.mesh_polygons_schemas_dict["vertex_attribute"]["rpc"], f"{params=}", flush=True)
3737
validate_schema(params, self.mesh_polygons_schemas_dict["vertex_attribute"])
3838
id = params["id"]
3939
name = str(params["name"])
40-
self.setMeshVertexAttribute(id, name)
40+
self.displayAttributeOnVertices(id, name)
4141

4242
@exportRpc(mesh_polygons_prefix + mesh_polygons_schemas_dict["polygon_attribute"]["rpc"])
4343
def setMeshPolygonsPolygonAttribute(self, params):
4444
print(self.mesh_polygons_prefix + self.mesh_polygons_schemas_dict["polygon_attribute"]["rpc"], f"{params=}", flush=True)
4545
validate_schema(params, self.mesh_polygons_schemas_dict["polygon_attribute"])
4646
id = params["id"]
4747
name = str(params["name"])
48-
self.setMeshPolygonAttribute(id, name)
48+
self.displayAttributeOnCells(id, name)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Standard library imports
2+
import os
3+
4+
# Third party imports
5+
from wslink import register as exportRpc
6+
7+
# Local application imports
8+
from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema
9+
from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView
10+
11+
class VtkMeshPolyhedronsView(VtkMeshView):
12+
mesh_polyhedrons_prefix = "opengeodeweb_viewer.mesh.polyhedrons."
13+
mesh_polyhedrons_schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas"))
14+
15+
def __init__(self):
16+
super().__init__()
17+
18+
@exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["visibility"]["rpc"])
19+
def setMeshPolyhedronsVisibility(self, params):
20+
print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["visibility"]["rpc"], f"{params=}", flush=True)
21+
validate_schema(params, self.mesh_polyhedrons_schemas_dict["visibility"])
22+
id = params["id"]
23+
visibility = bool(params["visibility"])
24+
self.SetVisibility(id, visibility)
25+
26+
@exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["color"]["rpc"])
27+
def setMeshPolyhedronsColor(self, params):
28+
print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["color"]["rpc"], f"{params=}", flush=True)
29+
validate_schema(params, self.mesh_polyhedrons_schemas_dict["color"])
30+
id = params["id"]
31+
red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"]
32+
self.SetColor(id, red, green, blue)
33+
34+
@exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"])
35+
def setMeshPolyhedronsVertexAttribute(self, params):
36+
print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"], f"{params=}", flush=True)
37+
validate_schema(params, self.mesh_polyhedrons_schemas_dict["vertex_attribute"])
38+
id = params["id"]
39+
name = str(params["name"])
40+
self.displayAttributeOnVertices(id, name)
41+
42+
@exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["polyhedron_attribute"]["rpc"])
43+
def setMeshPolyhedronsPolyhedronAttribute(self, params):
44+
print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"], f"{params=}", flush=True)
45+
validate_schema(params, self.mesh_polyhedrons_schemas_dict["vertex_attribute"])
46+
id = params["id"]
47+
name = str(params["name"])
48+
self.displayAttributeOnCells(id, name)
49+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"rpc": "color",
3+
"type": "object",
4+
"properties": {
5+
"id": {
6+
"type": "string"
7+
},
8+
"color": {
9+
"type": "object",
10+
"properties": {
11+
"r": {
12+
"type": "integer",
13+
"minimum": 0,
14+
"maximum": 255
15+
},
16+
"g": {
17+
"type": "integer",
18+
"minimum": 0,
19+
"maximum": 255
20+
},
21+
"b": {
22+
"type": "integer",
23+
"minimum": 0,
24+
"maximum": 255
25+
},
26+
"a": {
27+
"type": "number",
28+
"minimum": 0,
29+
"maximum": 1,
30+
"default": 1
31+
}
32+
},
33+
"required": [
34+
"r",
35+
"g",
36+
"b"
37+
],
38+
"additionalProperties": false
39+
}
40+
},
41+
"required": [
42+
"id",
43+
"color"
44+
],
45+
"additionalProperties": false
46+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"rpc": "polyhedron_attribute",
3+
"type": "object",
4+
"properties": {
5+
"id": {
6+
"type": "string"
7+
},
8+
"name": {
9+
"type": "string"
10+
}
11+
},
12+
"required": [
13+
"id",
14+
"name"
15+
],
16+
"additionalProperties": false
17+
}

0 commit comments

Comments
 (0)