Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ where = ["src"]
"opengeodeweb_viewer.rpc.mesh.points.schemas" = ["*.json"]
"opengeodeweb_viewer.rpc.mesh.edges.schemas" = ["*.json"]
"opengeodeweb_viewer.rpc.mesh.polygons.schemas" = ["*.json"]
"opengeodeweb_viewer.rpc.mesh.polyhedrons.schemas" = ["*.json"]
"opengeodeweb_viewer.rpc.model.schemas" = ["*.json"]
"opengeodeweb_viewer.rpc.viewer.schemas" = ["*.json"]

Expand Down
14 changes: 14 additions & 0 deletions src/opengeodeweb_viewer/object/object_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,25 @@ def SetPolygonsVisibility(self, id, visibility):
actor.SetVisibility(visibility)
self.render()


def SetPolygonsColor(self, id, color):
actor = self.get_object(id)["actor"]
actor.GetProperty().SetColor(color)
self.render()

def SetPolyhedronsVisibility(self, id, visibility):
actor = self.get_object(id)["actor"]
actor.SetVisibility(visibility)
self.render()

def SetPolyhedronsColor(self, id, color):
reader = self.get_object(id)["reader"]
cells = reader.GetOutput().GetCellData()
mapper = self.get_object(id)["mapper"]
mapper.ScalarVisibilityOff()
cells.SetColor(color)


def clearColors(self, id):
db = self.get_object(id)
mapper = db["mapper"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Standard library imports
import os

# Third party imports
from wslink import register as exportRpc

# Local application imports
from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema
from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView

class VtkMeshPolyhedronsView(VtkMeshView):
mesh_polyhedrons_prefix = "opengeodeweb_viewer.mesh.polyhedrons."
mesh_polyhedrons_schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas"))

def __init__(self):
super().__init__()

# @exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["visibility"]["rpc"])
# def setMeshPolyhedronsVisibility(self, params):
# print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["visibility"]["rpc"], f"{params=}", flush=True)
# validate_schema(params, self.mesh_polyhedrons_schemas_dict["visibility"])
# id = params["id"]
# visibility = bool(params["visibility"])
# self.SetPolyhedronsVisibility(id, visibility)

@exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["color"]["rpc"])
def setMeshPolyhedronsColor(self, params):
print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["color"]["rpc"], f"{params=}", flush=True)
validate_schema(params, self.mesh_polyhedrons_schemas_dict["color"])
print("id", params["id"], flush=True)
id = params["id"]
print("color", params["color"], flush=True)
red, green, blue = params["color"]["r"]/255, params["color"]["g"]/255, params["color"]["b"]/255
self.SetColor(id, red, green, blue)

# @exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"])
# def setMeshPolyhedronsVertexAttribute(self, params):
# print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"], f"{params=}", flush=True)
# validate_schema(params, self.mesh_polyhedrons_schemas_dict["vertex_attribute"])
# id = params["id"]
# name = str(params["name"])
# self.setMeshVertexAttribute(id, name)

# @exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["polygon_attribute"]["rpc"])
# def setMeshPolyhedronsPolygonAttribute(self, params):
# print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["polygon_attribute"]["rpc"], f"{params=}", flush=True)
# validate_schema(params, self.mesh_polyhedrons_schemas_dict["polygon_attribute"])
# id = params["id"]
# name = str(params["name"])
# self.setMeshPolygonAttribute(id, name)
46 changes: 46 additions & 0 deletions src/opengeodeweb_viewer/rpc/mesh/polyhedrons/schemas/color.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"rpc": "color",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"color": {
"type": "object",
"properties": {
"r": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"g": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"b": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"a": {
"type": "number",
"minimum": 0,
"maximum": 1,
"default": 1
}
},
"required": [
"r",
"g",
"b"
],
"additionalProperties": false
}
},
"required": [
"id",
"color"
],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"rpc": "polygon_attribute",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"rpc": "vertex_attribute",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"rpc": "visibility",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"visibility": {
"type": "boolean"
}
},
"required": [
"id",
"visibility"
],
"additionalProperties": false
}
2 changes: 2 additions & 0 deletions src/opengeodeweb_viewer/vtkw_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .rpc.mesh.points.points_protocols import VtkMeshPointsView
from .rpc.mesh.edges.edges_protocols import VtkMeshEdgesView
from .rpc.mesh.polygons.polygons_protocols import VtkMeshPolygonsView
from .rpc.mesh.polyhedrons.polyhedrons_protocols import VtkMeshPolyhedronsView
from .rpc.model.model_protocols import VtkModelView
from .rpc.generic.generic_protocols import VtkGenericView

Expand Down Expand Up @@ -60,6 +61,7 @@ def initialize(self):
self.registerVtkWebProtocol(VtkMeshPointsView())
self.registerVtkWebProtocol(VtkMeshEdgesView())
self.registerVtkWebProtocol(VtkMeshPolygonsView())
self.registerVtkWebProtocol(VtkMeshPolyhedronsView())
self.registerVtkWebProtocol(model_protocols)
self.registerVtkWebProtocol(VtkGenericView(mesh_protocols, model_protocols))

Expand Down
19 changes: 19 additions & 0 deletions src/tests/data/hybrid_solid.vtu
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
<UnstructuredGrid>
<Piece NumberOfPoints="11" NumberOfCells="4">
<PointData>
<DataArray type="Float64" Name="points" format="ascii" NumberOfComponents="3" RangeMin="0" RangeMax="2">0 0 0 1 0 0 2 1 0 1 2 0 0 2 0 0 0 1 1 0 1 2 1 1 1 2 1 0 2 1 1 1 2 </DataArray>
</PointData>
<Points>
<DataArray type="Float64" Name="Points" format="ascii" NumberOfComponents="3" RangeMin="0" RangeMax="2">0 0 0 1 0 0 2 1 0 1 2 0 0 2 0 0 0 1 1 0 1 2 1 1 1 2 1 0 2 1 1 1 2 </DataArray>
</Points>
<CellData />
<Cells>
<DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="0" RangeMax="10">0 1 3 4 5 6 8 9 1 2 3 6 7 8 5 6 8 9 10 6 7 8 10 </DataArray>
<DataArray type="Int64" Name="offsets" format="ascii" RangeMin="0" RangeMax="11">8 14 19 23 </DataArray>
<DataArray type="UInt8" Name="types" format="ascii" RangeMin="1" RangeMax="42">12 13 14 10 </DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
Binary file added src/tests/data/images/mesh/polyhedrons/color.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/tests/mesh/polyhedrons/test_polyhedrons_protocols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Standard library imports

# Third party imports
from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView
from opengeodeweb_viewer.rpc.mesh.polyhedrons.polyhedrons_protocols import VtkMeshPolyhedronsView

# Local application imports


def test_register_mesh(server):

server.call(VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["register"]["rpc"], [{"id": "123456789", "file_name": "hybrid_solid.vtu"}])
assert server.compare_image(3, "mesh/polyhedrons/register.jpeg") == True

def test_polyhedrons_color(server):

test_register_mesh(server)

server.call(VtkMeshPolyhedronsView.mesh_polyhedrons_prefix + VtkMeshPolyhedronsView.mesh_polyhedrons_schemas_dict["color"]["rpc"], [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}])
assert server.compare_image(3, "mesh/polyhedrons/color.jpeg") == True
Binary file modified src/tests/tests_output/test.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.