-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/new rpcs #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/new rpcs #29
Changes from all commits
06992c6
66836bc
d79292e
d8a6f48
36d9974
096bd7e
50510c8
b1f21f5
522581a
d6ab160
ca7d28d
0d77266
a532994
093daa4
0c3ec58
6bdf7df
06a1713
9885b56
608a816
8bca026
bc1c969
d315c2d
6278b65
acbbae0
6e5aaf0
9ef9a51
6396928
87075eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,5 @@ __pycache__/ | |
| latest_logs | ||
| schemas.json | ||
| build | ||
| src/tests/tests_output/ | ||
| *.egg-info | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| from .config import * | ||
| from .function import * | ||
| from .utils_functions import * | ||
| from .vtk_protocol import * |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # Standard library imports | ||
| import os | ||
|
|
||
| # Third party imports | ||
| import vtk | ||
|
|
||
| # Local application imports | ||
| from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema | ||
| from opengeodeweb_viewer.vtk_protocol import VtkView | ||
|
|
||
| class VtkObjectView(VtkView): | ||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
| def register(self, id, file_name, reader, filter, mapper): | ||
| actor = vtk.vtkActor() | ||
| self.register_object(id, reader, filter, actor, mapper, {}) | ||
|
|
||
| reader.SetFileName(os.path.join(self.DATA_FOLDER_PATH, file_name)) | ||
|
|
||
| actor.SetMapper(mapper) | ||
| mapper.SetColorModeToMapScalars() | ||
| mapper.SetResolveCoincidentTopologyLineOffsetParameters(1, -0.1) | ||
| mapper.SetResolveCoincidentTopologyPolygonOffsetParameters(2, 0) | ||
| mapper.SetResolveCoincidentTopologyPointOffsetParameter(-2) | ||
|
|
||
| renderWindow = self.getView("-1") | ||
| renderer = renderWindow.GetRenderers().GetFirstRenderer() | ||
| renderer.AddActor(actor) | ||
| renderer.ResetCamera() | ||
| renderWindow.Render() | ||
| self.render() | ||
|
|
||
| def deregister(self, id): | ||
| actor = self.get_object(id)["actor"] | ||
| renderWindow = self.getView("-1") | ||
| renderer = renderWindow.GetRenderers().GetFirstRenderer() | ||
| renderer.RemoveActor(actor) | ||
| self.deregister_object(id) | ||
| self.render() | ||
|
|
||
| def applyTextures(self, id, textures): | ||
| textures_array = [] | ||
| images_reader_array = [] | ||
|
|
||
| data = self.get_object(id) | ||
| mapper = data["mapper"] | ||
| actor = data["actor"] | ||
| reader = data["reader"] | ||
|
|
||
| polydata_mapper = mapper.GetPolyDataMapper() | ||
| poly_data = reader.GetPolyDataOutput() | ||
|
|
||
| for index, value in enumerate(textures): | ||
| texture_name = value["texture_name"] | ||
| texture_file_name = value["texture_file_name"] | ||
| print(f"{texture_name=} {texture_file_name=}", flush=True) | ||
|
|
||
| new_texture = vtk.vtkTexture() | ||
| image_reader = vtk.vtkXMLImageDataReader() | ||
| image_reader.SetFileName( | ||
| os.path.join(self.DATA_FOLDER_PATH, texture_file_name) | ||
| ) | ||
|
|
||
| shader_texture_name = f"VTK_TEXTURE_UNIT_{index}" | ||
| polydata_mapper.MapDataArrayToMultiTextureAttribute( | ||
| shader_texture_name, | ||
| texture_name, | ||
| vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, | ||
| ) | ||
|
|
||
| if index == 0: | ||
| new_texture.SetBlendingMode( | ||
| vtk.vtkTexture.VTK_TEXTURE_BLENDING_MODE_REPLACE | ||
| ) | ||
| else: | ||
| new_texture.SetBlendingMode( | ||
| vtk.vtkTexture.VTK_TEXTURE_BLENDING_MODE_ADD | ||
| ) | ||
|
|
||
| images_reader_array.append(image_reader) | ||
| new_texture.SetInputConnection(image_reader.GetOutputPort()) | ||
|
|
||
| actor.GetProperty().SetTexture(shader_texture_name, new_texture) | ||
|
|
||
| textures_array.append(new_texture) | ||
| images_reader_array.append(image_reader) | ||
|
|
||
| self.render() | ||
|
|
||
|
|
||
| def SetVisibility(self, id, visibility): | ||
| actor = self.get_object(id)["actor"] | ||
| actor.SetVisibility(visibility) | ||
| self.render() | ||
|
|
||
| def SetOpacity(self, id, opacity): | ||
| actor = self.get_object(id)["actor"] | ||
| actor.GetProperty().SetOpacity(opacity) | ||
| self.render() | ||
|
|
||
| def SetColor(self, id, red, green, blue): | ||
| reader = self.get_object(id)["reader"] | ||
| mapper = self.get_object(id)["mapper"] | ||
| mapper.ScalarVisibilityOff() | ||
| actor = self.get_object(id)["actor"] | ||
| actor.GetProperty().SetColor([red, green, blue]) | ||
| self.render() | ||
|
|
||
| def SetEdgeVisibility(self, id, visibility): | ||
| actor = self.get_object(id)["actor"] | ||
| actor.GetProperty().SetEdgeVisibility(visibility) | ||
| self.render() | ||
|
|
||
| def SetVertexVisibility(self, id, visibility): | ||
| actor = self.get_object(id)["actor"] | ||
| actor.GetProperty().SetVertexVisibility(visibility) | ||
| self.render() | ||
|
|
||
| def SetPointSize(self, id, size): | ||
| actor = self.get_object(id)["actor"] | ||
| actor.GetProperty().SetPointSize(size) | ||
| self.render() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # Standard library imports | ||
| import json | ||
| import os | ||
|
|
||
| # Third party imports | ||
| import vtk | ||
| from vtk.web import protocols as vtk_protocols | ||
| from vtkmodules.vtkIOImage import vtkPNGWriter, vtkJPEGWriter | ||
| from vtkmodules.vtkRenderingCore import (vtkWindowToImageFilter) | ||
| from wslink import register as exportRpc | ||
|
|
||
| # Local application imports | ||
| from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema | ||
| from opengeodeweb_viewer.object.object_methods import VtkObjectView | ||
|
|
||
| schemas_dir = os.path.join(os.path.dirname(__file__), "schemas") | ||
| schemas_dict = get_schemas_dict(schemas_dir) | ||
| prefix = "opengeodeweb_viewer.mesh." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. c'est un moyen, faut-il le rendre dynamique? genre c'est la concat entre ogw_viewer et tous les dossiers parents jusqua rpc
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Peut-être dans un premier temps non, mais c'est une idée |
||
|
|
||
| class VtkMeshView(VtkObjectView): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.prefix = prefix | ||
| self.schemas_dict = schemas_dict | ||
|
|
||
| @exportRpc(prefix + schemas_dict["register"]["rpc"]) | ||
| def registerMesh(self, params): | ||
| print(schemas_dict["register"]["rpc"], params, flush=True) | ||
| validate_schema(params, schemas_dict["register"]) | ||
| id = params["id"] | ||
| file_name = params["file_name"] | ||
| try: | ||
| reader = vtk.vtkXMLGenericDataObjectReader() | ||
| filter = {} | ||
| mapper = vtk.vtkDataSetMapper() | ||
| mapper.SetInputConnection(reader.GetOutputPort()) | ||
| self.register(id, file_name, reader, filter, mapper) | ||
| except Exception as e: | ||
| print("error : ", str(e), flush=True) | ||
|
|
||
| @exportRpc(prefix + schemas_dict["deregister"]["rpc"]) | ||
| def deregisterMesh(self, params): | ||
| print(schemas_dict["deregister"]["rpc"], params, flush=True) | ||
| validate_schema(params, schemas_dict["deregister"]) | ||
| id = params["id"] | ||
| self.deregister(id) | ||
|
|
||
| @exportRpc(prefix + schemas_dict["set_visibility"]["rpc"]) | ||
| def SetMeshVisibility(self, params): | ||
| print(schemas_dict["set_visibility"]["rpc"], params, flush=True) | ||
| validate_schema(params, schemas_dict["set_visibility"]) | ||
| id = params["id"] | ||
| visibility = bool(params["visibility"]) | ||
| self.SetVisibility(id, visibility) | ||
|
|
||
| @exportRpc(prefix + schemas_dict["set_opacity"]["rpc"]) | ||
| def setMeshOpacity(self, params): | ||
| print(schemas_dict["set_opacity"]["rpc"], params, flush=True) | ||
| validate_schema(params, schemas_dict["set_opacity"]) | ||
| id = params["id"] | ||
| opacity = float(params["opacity"]) | ||
| self.SetOpacity(id, opacity) | ||
|
|
||
| @exportRpc(prefix + schemas_dict["set_edge_visibility"]["rpc"]) | ||
| def setMeshEdgeVisibility(self, params): | ||
| print(schemas_dict["set_edge_visibility"]["rpc"], params, flush=True) | ||
| validate_schema(params, schemas_dict["set_edge_visibility"]) | ||
| id = params["id"] | ||
| visibility = bool(params["visibility"]) | ||
| self.SetEdgeVisibility(id, visibility) | ||
|
|
||
| @exportRpc(prefix + schemas_dict["set_point_visibility"]["rpc"]) | ||
| def setMeshPointVisibility(self, params): | ||
| print(schemas_dict["set_point_visibility"]["rpc"], params, flush=True) | ||
| validate_schema(params, schemas_dict["set_point_visibility"]) | ||
| id = params["id"] | ||
| visibility = bool(params["visibility"]) | ||
| self.SetVertexVisibility(id, visibility) | ||
|
|
||
| @exportRpc(prefix + schemas_dict["set_point_size"]["rpc"]) | ||
| def setMeshPointSize(self, params): | ||
| print(schemas_dict["set_point_size"]["rpc"], params, flush=True) | ||
| validate_schema(params, schemas_dict["set_point_size"]) | ||
| id = params["id"] | ||
| size = float(params["size"]) | ||
| self.SetPointSize(id, size) | ||
|
|
||
| @exportRpc(prefix + schemas_dict["set_color"]["rpc"]) | ||
| def setMeshColor(self, params): | ||
| print(schemas_dict["set_color"]["rpc"], params, flush=True) | ||
| validate_schema(params, schemas_dict["set_color"]) | ||
| id = params["id"] | ||
| red = params["red"] | ||
| green = params["green"] | ||
| blue = params["blue"] | ||
| self.SetColor(id, red, green, blue) | ||
|
|
||
| @exportRpc(prefix + schemas_dict["display_vertex_attribute"]["rpc"]) | ||
| def setVertexAttribute(self, params): | ||
| print(schemas_dict["display_vertex_attribute"]["rpc"], params, flush=True) | ||
| validate_schema(params, schemas_dict["display_vertex_attribute"]) | ||
| id = params["id"] | ||
| name = params["name"] | ||
| reader = self.get_object(id)["reader"] | ||
| points = reader.GetOutput().GetPointData() | ||
| points.SetActiveScalars(name) | ||
| mapper = self.get_object(id)["mapper"] | ||
| mapper.ScalarVisibilityOn() | ||
| mapper.SetScalarModeToUsePointData() | ||
| mapper.SetScalarRange(points.GetScalars().GetRange()) | ||
| self.render() | ||
|
|
||
| @exportRpc(prefix + schemas_dict["display_polygon_attribute"]["rpc"]) | ||
| def setPolygonAttribute(self, params): | ||
| print(schemas_dict["display_polygon_attribute"]["rpc"], params, flush=True) | ||
| validate_schema(params, schemas_dict["display_polygon_attribute"]) | ||
| id = params["id"] | ||
| name = params["name"] | ||
| reader = self.get_object(id)["reader"] | ||
| cells = reader.GetOutput().GetCellData() | ||
| cells.SetActiveScalars(name) | ||
| mapper = self.get_object(id)["mapper"] | ||
| mapper.ScalarVisibilityOn() | ||
| mapper.SetScalarModeToUseCellData() | ||
| mapper.SetScalarRange(cells.GetScalars().GetRange()) | ||
| self.render() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| { | ||
| "rpc": "update_data", | ||
| "rpc": "deregister", | ||
| "type": "object", | ||
| "properties": { | ||
| "id": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": ["id"], | ||
| "required": [ | ||
| "id" | ||
| ], | ||
| "additionalProperties": false | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "rpc": "display_polygon_attribute", | ||
| "type": "object", | ||
| "properties": { | ||
| "id": { | ||
| "type": "string" | ||
| }, | ||
| "name": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "id", | ||
| "name" | ||
| ], | ||
| "additionalProperties": false | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.