- 
                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
          
     Merged
      
      
    
  
     Merged
                    Feat/new rpcs #29
Changes from 22 commits
      Commits
    
    
            Show all changes
          
          
            28 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      06992c6
              
                feat(rpc): set_viewer_background_color
              
              
                JulienChampagnol 66836bc
              
                feat(rpc): set_opacity
              
              
                JulienChampagnol d79292e
              
                wip(classes): new layout
              
              
                JulienChampagnol d8a6f48
              
                fix classes import
              
              
                JulienChampagnol 36d9974
              
                import new folders
              
              
                JulienChampagnol 096bd7e
              
                get_schemas_dict function
              
              
                JulienChampagnol 50510c8
              
                register new classes
              
              
                JulienChampagnol b1f21f5
              
                new classes
              
              
                JulienChampagnol 522581a
              
                schemas
              
              
                JulienChampagnol d6ab160
              
                imports
              
              
                JulienChampagnol ca7d28d
              
                rename
              
              
                JulienChampagnol 0d77266
              
                test_config dynamic path
              
              
                JulienChampagnol a532994
              
                VtkView init
              
              
                JulienChampagnol 093daa4
              
                test data
              
              
                JulienChampagnol 0c3ec58
              
                generi object methods
              
              
                JulienChampagnol 6bdf7df
              
                save schemas state
              
              
                JulienChampagnol 06a1713
              
                tests viewer okay
              
              
                JulienChampagnol 9885b56
              
                object rpcs
              
              
                JulienChampagnol 608a816
              
                schemas in child classes
              
              
                JulienChampagnol 8bca026
              
                tidy
              
              
                JulienChampagnol bc1c969
              
                passing tests
              
              
                JulienChampagnol d315c2d
              
                add print in all rpcs before validation
              
              
                JulienChampagnol 6278b65
              
                call self everywhere
              
              
                JulienChampagnol acbbae0
              
                prefix & schemas_dict in classes
              
              
                JulienChampagnol 6e5aaf0
              
                comment test_set_point_size
              
              
                JulienChampagnol 9ef9a51
              
                harmonise functions name
              
              
                JulienChampagnol 6396928
              
                harmonise functions name 2
              
              
                JulienChampagnol 87075eb
              
                prefix & dict on failing tests
              
              
                JulienChampagnol File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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 | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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 contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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 = super().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() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # 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) | ||
| 
     | 
||
| class VtkMeshView(VtkObjectView): | ||
| def __init__(self): | ||
| super().__init__() | ||
| 
     | 
||
| @exportRpc(schemas_dict["register"]["rpc"]) | ||
| def register(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()) | ||
| super().register(id, file_name, reader, filter, mapper) | ||
| except Exception as e: | ||
| print("error : ", str(e), flush=True) | ||
| 
     | 
||
| @exportRpc(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"] | ||
| super().deregister(id) | ||
                
      
                  JulienChampagnol marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| @exportRpc(schemas_dict["set_visibility"]["rpc"]) | ||
| def SetVisibility(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"]) | ||
| super().SetVisibility(id, visibility) | ||
| 
     | 
||
| @exportRpc(schemas_dict["set_opacity"]["rpc"]) | ||
| def SetOpacity(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"]) | ||
| super().SetOpacity(id, opacity) | ||
| 
     | 
||
| @exportRpc(schemas_dict["set_edge_visibility"]["rpc"]) | ||
| def setEdgeVisibility(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"]) | ||
| super().SetEdgeVisibility(id, visibility) | ||
| 
     | 
||
| @exportRpc(schemas_dict["set_point_visibility"]["rpc"]) | ||
| def setPointVisibility(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"]) | ||
| super().SetVertexVisibility(id, visibility) | ||
| 
     | 
||
| @exportRpc(schemas_dict["set_point_size"]["rpc"]) | ||
| def setPointSize(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"]) | ||
| super().SetPointSize(id, size) | ||
| 
     | 
||
| @exportRpc(schemas_dict["set_color"]["rpc"]) | ||
| def setColor(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"] | ||
| super().SetColor(id, red, green, blue) | ||
| 
     | 
||
| @exportRpc(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 = super().get_object(id)["reader"] | ||
| points = reader.GetOutput().GetPointData() | ||
| points.SetActiveScalars(name) | ||
| mapper = super().get_object(id)["mapper"] | ||
| mapper.ScalarVisibilityOn() | ||
| mapper.SetScalarModeToUsePointData() | ||
| mapper.SetScalarRange(points.GetScalars().GetRange()) | ||
| super().render() | ||
| 
     | 
||
| @exportRpc(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 = super().get_object(id)["reader"] | ||
| cells = reader.GetOutput().GetCellData() | ||
| cells.SetActiveScalars(name) | ||
| mapper = super().get_object(id)["mapper"] | ||
| mapper.ScalarVisibilityOn() | ||
| mapper.SetScalarModeToUseCellData() | ||
| mapper.SetScalarRange(cells.GetScalars().GetRange()) | ||
| super().render() | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            8 changes: 5 additions & 3 deletions
          
          8 
        
  ...r/rpc/schemas/delete_object_pipeline.json → ...b_viewer/rpc/mesh/schemas/deregister.json
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| { | ||
| "rpc": "delete_object_pipeline", | ||
| "rpc": "mesh.deregister", | ||
| "type": "object", | ||
| "properties": { | ||
| "id": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": ["id"], | ||
| "required": [ | ||
| "id" | ||
| ], | ||
| "additionalProperties": false | ||
| } | ||
| } | 
        
          
          
            17 changes: 17 additions & 0 deletions
          
          17 
        
  src/opengeodeweb_viewer/rpc/mesh/schemas/display_polygon_attribute.json
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "rpc": "mesh.display_polygon_attribute", | ||
| "type": "object", | ||
| "properties": { | ||
| "id": { | ||
| "type": "string" | ||
| }, | ||
| "name": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "id", | ||
| "name" | ||
| ], | ||
| "additionalProperties": false | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.