Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
06992c6
feat(rpc): set_viewer_background_color
JulienChampagnol Nov 13, 2024
66836bc
feat(rpc): set_opacity
JulienChampagnol Nov 14, 2024
d79292e
wip(classes): new layout
JulienChampagnol Nov 18, 2024
d8a6f48
fix classes import
JulienChampagnol Nov 18, 2024
36d9974
import new folders
JulienChampagnol Nov 18, 2024
096bd7e
get_schemas_dict function
JulienChampagnol Nov 18, 2024
50510c8
register new classes
JulienChampagnol Nov 18, 2024
b1f21f5
new classes
JulienChampagnol Nov 18, 2024
522581a
schemas
JulienChampagnol Nov 18, 2024
d6ab160
imports
JulienChampagnol Nov 18, 2024
ca7d28d
rename
JulienChampagnol Nov 18, 2024
0d77266
test_config dynamic path
JulienChampagnol Nov 19, 2024
a532994
VtkView init
JulienChampagnol Nov 19, 2024
093daa4
test data
JulienChampagnol Nov 19, 2024
0c3ec58
generi object methods
JulienChampagnol Nov 19, 2024
6bdf7df
save schemas state
JulienChampagnol Nov 19, 2024
06a1713
tests viewer okay
JulienChampagnol Nov 19, 2024
9885b56
object rpcs
JulienChampagnol Nov 20, 2024
608a816
schemas in child classes
JulienChampagnol Nov 20, 2024
8bca026
tidy
JulienChampagnol Nov 22, 2024
bc1c969
passing tests
JulienChampagnol Nov 22, 2024
d315c2d
add print in all rpcs before validation
JulienChampagnol Nov 22, 2024
6278b65
call self everywhere
JulienChampagnol Nov 22, 2024
acbbae0
prefix & schemas_dict in classes
JulienChampagnol Nov 25, 2024
6e5aaf0
comment test_set_point_size
JulienChampagnol Nov 25, 2024
9ef9a51
harmonise functions name
JulienChampagnol Nov 25, 2024
6396928
harmonise functions name 2
JulienChampagnol Nov 25, 2024
87075eb
prefix & dict on failing tests
JulienChampagnol Nov 25, 2024
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ __pycache__/
latest_logs
schemas.json
build
src/tests/tests_output/
*.egg-info
2 changes: 1 addition & 1 deletion generate_schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function return_json_schema(directoryPath, folder_path, project_name) {
return acc;
}, folders_schemas);
} else {
var new_folder_path = folder_path + "/" + folder.name;
var new_folder_path = folder_path + "." + folder.name;
var test = return_json_schema(folder.path, new_folder_path, project_name);
folders_schemas[folder.name] = test;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "@geode/opengeodeweb-viewer",
"scripts": {
"json": "node generate_schemas.js"
"json": "node generate_schemas.js",
"test": "npm run json && pytest"
},
"dependencies": {
"glob": "^10.3.10"
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ dependencies = {file = ["requirements.txt"]}
where = ["src"]

[tool.setuptools.package-data]
"opengeodeweb_viewer.rpc.schemas" = ["*.json"]
"opengeodeweb_viewer.rpc.viewer.schemas" = ["*.json"]
"opengeodeweb_viewer.rpc.mesh.schemas" = ["*.json"]
"opengeodeweb_viewer.rpc.model.schemas" = ["*.json"]


[tool.semantic_release]
version_toml = [
Expand Down
2 changes: 1 addition & 1 deletion src/opengeodeweb_viewer/__init__.py
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 *
8 changes: 5 additions & 3 deletions src/opengeodeweb_viewer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ def dev_config():
os.mkdir(os.environ.get("DATA_FOLDER_PATH"))


def test_config():
def test_config(path):
default_config()
print(f"{os.path.dirname(__file__)=}", flush=True)
os.environ["DATA_FOLDER_PATH"] = os.path.join(
os.path.dirname(__file__), "..", "tests", "data"
os.environ["DATA_FOLDER_PATH"] = os.path.join(path,
"data"
)

print(f"{os.environ.get('DATA_FOLDER_PATH')=}", flush=True)
17 changes: 0 additions & 17 deletions src/opengeodeweb_viewer/function.py

This file was deleted.

123 changes: 123 additions & 0 deletions src/opengeodeweb_viewer/object/object_methods.py
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()
126 changes: 126 additions & 0 deletions src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py
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."
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Expand Up @@ -17,12 +17,18 @@
"type": "string"
}
},
"required": ["texture_name", "texture_file_name"],
"required": [
"texture_name",
"texture_file_name"
],
"additionalProperties": false
},
"minItems": 1
}
},
"required": ["id", "textures"],
"required": [
"id",
"textures"
],
"additionalProperties": false
}
}
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
}
Loading