trame-vtklocal 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- trame-vtklocal-0.1.0/LICENSE +15 -0
- trame-vtklocal-0.1.0/MANIFEST.in +1 -0
- trame-vtklocal-0.1.0/PKG-INFO +77 -0
- trame-vtklocal-0.1.0/README.rst +58 -0
- trame-vtklocal-0.1.0/setup.cfg +38 -0
- trame-vtklocal-0.1.0/setup.py +3 -0
- trame-vtklocal-0.1.0/trame/__init__.py +1 -0
- trame-vtklocal-0.1.0/trame/modules/__init__.py +1 -0
- trame-vtklocal-0.1.0/trame/modules/vtklocal.py +1 -0
- trame-vtklocal-0.1.0/trame/widgets/__init__.py +1 -0
- trame-vtklocal-0.1.0/trame/widgets/vtklocal.py +7 -0
- trame-vtklocal-0.1.0/trame_vtklocal/__init__.py +3 -0
- trame-vtklocal-0.1.0/trame_vtklocal/module/__init__.py +33 -0
- trame-vtklocal-0.1.0/trame_vtklocal/module/protocol.py +111 -0
- trame-vtklocal-0.1.0/trame_vtklocal/module/serve/js/trame_vtklocal.umd.js +13 -0
- trame-vtklocal-0.1.0/trame_vtklocal/module/wasm.py +55 -0
- trame-vtklocal-0.1.0/trame_vtklocal/widgets/__init__.py +0 -0
- trame-vtklocal-0.1.0/trame_vtklocal/widgets/vtklocal.py +60 -0
- trame-vtklocal-0.1.0/trame_vtklocal.egg-info/PKG-INFO +77 -0
- trame-vtklocal-0.1.0/trame_vtklocal.egg-info/SOURCES.txt +22 -0
- trame-vtklocal-0.1.0/trame_vtklocal.egg-info/dependency_links.txt +1 -0
- trame-vtklocal-0.1.0/trame_vtklocal.egg-info/requires.txt +1 -0
- trame-vtklocal-0.1.0/trame_vtklocal.egg-info/top_level.txt +2 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Apache Software License 2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024, Kitware Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
graft trame_vtklocal/module/serve
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: trame-vtklocal
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: VTK Local Rendering using WASM
|
|
5
|
+
Author: Kitware Inc.
|
|
6
|
+
License: Apache Software License
|
|
7
|
+
Keywords: Python,Interactive,Web,Application,Framework
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Web Environment
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: JavaScript
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Description-Content-Type: text/x-rst
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
|
|
20
|
+
==============
|
|
21
|
+
trame-vtklocal
|
|
22
|
+
==============
|
|
23
|
+
|
|
24
|
+
VTK Local Rendering using VTK/WASM to match server side rendering pipeline on the client side.
|
|
25
|
+
The current code base is still at its infancy but we aim to make it the default implementation for local rendering using VTK/ParaView with trame.
|
|
26
|
+
|
|
27
|
+
License
|
|
28
|
+
----------------------------------------
|
|
29
|
+
|
|
30
|
+
This library is OpenSource and follow the Apache Software License
|
|
31
|
+
|
|
32
|
+
Installation
|
|
33
|
+
----------------------------------------
|
|
34
|
+
|
|
35
|
+
.. code-block:: console
|
|
36
|
+
|
|
37
|
+
pip install trame-vtklocal
|
|
38
|
+
|
|
39
|
+
# We need a VTK that has its wasm counterpart
|
|
40
|
+
# This is the first version available with it
|
|
41
|
+
# For ParaView (not yet supported), VTK don't need to be installed
|
|
42
|
+
pip install "vtk==9.3.20240418.dev0" --extra-index-url https://wheels.vtk.org
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
Development
|
|
46
|
+
----------------------------------------
|
|
47
|
+
|
|
48
|
+
Build and install the Vue components
|
|
49
|
+
|
|
50
|
+
.. code-block:: console
|
|
51
|
+
|
|
52
|
+
cd vue-components
|
|
53
|
+
npm i
|
|
54
|
+
npm run build
|
|
55
|
+
cd -
|
|
56
|
+
|
|
57
|
+
Install the library
|
|
58
|
+
|
|
59
|
+
.. code-block:: console
|
|
60
|
+
|
|
61
|
+
pip install -e .
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
Running examples
|
|
65
|
+
----------------------------------------
|
|
66
|
+
|
|
67
|
+
.. code-block:: console
|
|
68
|
+
|
|
69
|
+
pip install trame trame-vtklocal trame-vuetify trame-vtk
|
|
70
|
+
|
|
71
|
+
# We need a VTK that has its wasm counterpart
|
|
72
|
+
# This is the first version available with it
|
|
73
|
+
# For ParaView (not yet supported), VTK don't need to be installed
|
|
74
|
+
pip install "vtk==9.3.20240418.dev0" --extra-index-url https://wheels.vtk.org
|
|
75
|
+
|
|
76
|
+
# regular trame app
|
|
77
|
+
python ./examples/vtk/cone.py
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
==============
|
|
2
|
+
trame-vtklocal
|
|
3
|
+
==============
|
|
4
|
+
|
|
5
|
+
VTK Local Rendering using VTK/WASM to match server side rendering pipeline on the client side.
|
|
6
|
+
The current code base is still at its infancy but we aim to make it the default implementation for local rendering using VTK/ParaView with trame.
|
|
7
|
+
|
|
8
|
+
License
|
|
9
|
+
----------------------------------------
|
|
10
|
+
|
|
11
|
+
This library is OpenSource and follow the Apache Software License
|
|
12
|
+
|
|
13
|
+
Installation
|
|
14
|
+
----------------------------------------
|
|
15
|
+
|
|
16
|
+
.. code-block:: console
|
|
17
|
+
|
|
18
|
+
pip install trame-vtklocal
|
|
19
|
+
|
|
20
|
+
# We need a VTK that has its wasm counterpart
|
|
21
|
+
# This is the first version available with it
|
|
22
|
+
# For ParaView (not yet supported), VTK don't need to be installed
|
|
23
|
+
pip install "vtk==9.3.20240418.dev0" --extra-index-url https://wheels.vtk.org
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Development
|
|
27
|
+
----------------------------------------
|
|
28
|
+
|
|
29
|
+
Build and install the Vue components
|
|
30
|
+
|
|
31
|
+
.. code-block:: console
|
|
32
|
+
|
|
33
|
+
cd vue-components
|
|
34
|
+
npm i
|
|
35
|
+
npm run build
|
|
36
|
+
cd -
|
|
37
|
+
|
|
38
|
+
Install the library
|
|
39
|
+
|
|
40
|
+
.. code-block:: console
|
|
41
|
+
|
|
42
|
+
pip install -e .
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
Running examples
|
|
46
|
+
----------------------------------------
|
|
47
|
+
|
|
48
|
+
.. code-block:: console
|
|
49
|
+
|
|
50
|
+
pip install trame trame-vtklocal trame-vuetify trame-vtk
|
|
51
|
+
|
|
52
|
+
# We need a VTK that has its wasm counterpart
|
|
53
|
+
# This is the first version available with it
|
|
54
|
+
# For ParaView (not yet supported), VTK don't need to be installed
|
|
55
|
+
pip install "vtk==9.3.20240418.dev0" --extra-index-url https://wheels.vtk.org
|
|
56
|
+
|
|
57
|
+
# regular trame app
|
|
58
|
+
python ./examples/vtk/cone.py
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
name = trame-vtklocal
|
|
3
|
+
version = 0.1.0
|
|
4
|
+
description = VTK Local Rendering using WASM
|
|
5
|
+
long_description = file: README.rst
|
|
6
|
+
long_description_content_type = text/x-rst
|
|
7
|
+
author = Kitware Inc.
|
|
8
|
+
license = Apache Software License
|
|
9
|
+
classifiers =
|
|
10
|
+
Development Status :: 4 - Beta
|
|
11
|
+
Environment :: Web Environment
|
|
12
|
+
License :: OSI Approved :: Apache Software License
|
|
13
|
+
Natural Language :: English
|
|
14
|
+
Operating System :: OS Independent
|
|
15
|
+
Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Programming Language :: JavaScript
|
|
17
|
+
Topic :: Software Development :: Libraries :: Application Frameworks
|
|
18
|
+
Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
keywords =
|
|
20
|
+
Python
|
|
21
|
+
Interactive
|
|
22
|
+
Web
|
|
23
|
+
Application
|
|
24
|
+
Framework
|
|
25
|
+
|
|
26
|
+
[options]
|
|
27
|
+
packages = find:
|
|
28
|
+
include_package_data = True
|
|
29
|
+
install_requires =
|
|
30
|
+
trame
|
|
31
|
+
|
|
32
|
+
[semantic_release]
|
|
33
|
+
version_pattern = setup.cfg:version = (\d+\.\d+\.\d+)
|
|
34
|
+
|
|
35
|
+
[egg_info]
|
|
36
|
+
tag_build =
|
|
37
|
+
tag_date = 0
|
|
38
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from trame_vtklocal.module import *
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from .wasm import register_wasm
|
|
3
|
+
from .protocol import ObjectManagerHelper
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"serve",
|
|
7
|
+
"scripts",
|
|
8
|
+
"vue_use",
|
|
9
|
+
"setup",
|
|
10
|
+
"get_helper",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
serve_path = str(Path(__file__).with_name("serve").resolve())
|
|
14
|
+
|
|
15
|
+
serve = {"__trame_vtklocal": serve_path}
|
|
16
|
+
scripts = ["__trame_vtklocal/js/trame_vtklocal.umd.js"]
|
|
17
|
+
vue_use = ["trame_vtklocal"]
|
|
18
|
+
|
|
19
|
+
# -----------------------------------------------------------------------------
|
|
20
|
+
# Module advanced initialization
|
|
21
|
+
# -----------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
HELPERS_PER_SERVER = {}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_helper(server):
|
|
27
|
+
return HELPERS_PER_SERVER.get(server.name)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def setup(trame_server, **kwargs):
|
|
31
|
+
global HELPERS_PER_SERVER
|
|
32
|
+
HELPERS_PER_SERVER[trame_server.name] = ObjectManagerHelper(trame_server)
|
|
33
|
+
trame_server.enable_module(register_wasm(serve_path))
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
from wslink import register as export_rpc
|
|
2
|
+
from wslink.websocket import LinkProtocol
|
|
3
|
+
|
|
4
|
+
from vtkmodules.vtkSerializationManager import vtkObjectManager
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def map_id_mtime(object_manager, vtk_id):
|
|
8
|
+
vtk_obj = object_manager.GetObjectAtId(vtk_id)
|
|
9
|
+
return (vtk_id, vtk_obj.GetMTime())
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ObjectManagerAPI(LinkProtocol):
|
|
13
|
+
def __init__(self, *args, **kwargs):
|
|
14
|
+
super().__init__(*args, **kwargs)
|
|
15
|
+
self.vtk_object_manager = vtkObjectManager()
|
|
16
|
+
self.vtk_object_manager.Initialize()
|
|
17
|
+
self._subscriptions = {}
|
|
18
|
+
self._last_publish_states = {}
|
|
19
|
+
self._last_publish_hash = set()
|
|
20
|
+
|
|
21
|
+
self._debug_state = False
|
|
22
|
+
self._debug_state_counter = 1
|
|
23
|
+
|
|
24
|
+
def update(self):
|
|
25
|
+
self.vtk_object_manager.UpdateStatesFromObjects()
|
|
26
|
+
if self._debug_state:
|
|
27
|
+
self.vtk_object_manager.Export(f"snapshot-{self._debug_state_counter}")
|
|
28
|
+
self._debug_state_counter += 1
|
|
29
|
+
|
|
30
|
+
# Handle subscription push
|
|
31
|
+
remove_from_subscriptions = []
|
|
32
|
+
for obj_id, count in self._subscriptions.items():
|
|
33
|
+
if count == 0:
|
|
34
|
+
remove_from_subscriptions.append(obj_id)
|
|
35
|
+
elif count > 0:
|
|
36
|
+
status = self.get_status(obj_id)
|
|
37
|
+
for state_id, mtime in status.get("ids", []):
|
|
38
|
+
if mtime > self._last_publish_states.get(state_id, 0):
|
|
39
|
+
self._last_publish_states[state_id] = mtime
|
|
40
|
+
self.publish(
|
|
41
|
+
"vtklocal.subscriptions",
|
|
42
|
+
dict(
|
|
43
|
+
type="state",
|
|
44
|
+
id=state_id,
|
|
45
|
+
mtime=mtime,
|
|
46
|
+
content=self.get_state(state_id),
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
for hash in status.get("hashes", []):
|
|
50
|
+
if hash not in self._last_publish_hash:
|
|
51
|
+
self._last_publish_hash.add(hash)
|
|
52
|
+
self.publish(
|
|
53
|
+
"vtklocal.subscriptions",
|
|
54
|
+
dict(type="blob", hash=hash, content=self.get_hash(hash)),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
for id_to_gc in remove_from_subscriptions:
|
|
58
|
+
self._subscriptions.pop(id_to_gc)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def active_ids(self):
|
|
62
|
+
return self.vtk_object_manager.GetAllDependencies("")
|
|
63
|
+
|
|
64
|
+
@export_rpc("vtklocal.subscribe.update")
|
|
65
|
+
def update_subscription(self, obj_id, delta):
|
|
66
|
+
if obj_id in self._subscriptions:
|
|
67
|
+
self._subscriptions[obj_id] += delta
|
|
68
|
+
elif delta > 0:
|
|
69
|
+
self._subscriptions[obj_id] = delta
|
|
70
|
+
|
|
71
|
+
if delta > 0:
|
|
72
|
+
self._last_publish_states.clear()
|
|
73
|
+
self._last_publish_hash.clear()
|
|
74
|
+
|
|
75
|
+
@export_rpc("vtklocal.get.state")
|
|
76
|
+
def get_state(self, obj_id):
|
|
77
|
+
# print(f"get_state {obj_id} {self.vtk_object_manager.GetObjectAtId(obj_id).GetClassName()}")
|
|
78
|
+
state = self.vtk_object_manager.GetState(obj_id)
|
|
79
|
+
return state
|
|
80
|
+
|
|
81
|
+
@export_rpc("vtklocal.get.hash")
|
|
82
|
+
def get_hash(self, hash):
|
|
83
|
+
# print("get_hash", hash)
|
|
84
|
+
return self.addAttachment(memoryview(self.vtk_object_manager.GetBlob(hash)))
|
|
85
|
+
|
|
86
|
+
@export_rpc("vtklocal.get.status")
|
|
87
|
+
def get_status(self, obj_id):
|
|
88
|
+
# print("get_status", obj_id)
|
|
89
|
+
ids = self.vtk_object_manager.GetAllDependencies(obj_id)
|
|
90
|
+
hashes = self.vtk_object_manager.GetBlobHashes(ids)
|
|
91
|
+
renderWindow = self.vtk_object_manager.GetObjectAtId(obj_id)
|
|
92
|
+
ids_mtime = [map_id_mtime(self.vtk_object_manager, v) for v in ids]
|
|
93
|
+
ignore_ids = []
|
|
94
|
+
if renderWindow:
|
|
95
|
+
renderers = renderWindow.GetRenderers()
|
|
96
|
+
for renderer in renderers:
|
|
97
|
+
activeCamera = renderer.GetActiveCamera()
|
|
98
|
+
ignore_ids.append(self.vtk_object_manager.GetId(activeCamera))
|
|
99
|
+
return dict(ids=ids_mtime, hashes=hashes, ignore_ids=ignore_ids)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class ObjectManagerHelper:
|
|
103
|
+
def __init__(self, trame_server):
|
|
104
|
+
self.trame_server = trame_server
|
|
105
|
+
self.root_protocol = None
|
|
106
|
+
self.api = ObjectManagerAPI()
|
|
107
|
+
self.trame_server.add_protocol_to_configure(self.configure_protocol)
|
|
108
|
+
|
|
109
|
+
def configure_protocol(self, protocol):
|
|
110
|
+
self.root_protocol = protocol
|
|
111
|
+
self.root_protocol.registerLinkProtocol(self.api)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
(function(u,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],s):(u=typeof globalThis<"u"?globalThis:u||self,s(u.trame_vtklocal={},u.Vue))})(this,function(u,s){"use strict";async function W(r,c){const d={canvas:r,locateFile(){return c},print(){console.info(Array.prototype.slice.call(arguments).join(" "))},printErr(){console.error(Array.prototype.slice.call(arguments).join(" "))}},p=await window.createVTKWasmSceneManager(d);return p.initialize(),p}const k={VtkLocal:{emits:["updated","memory-vtk","memory-arrays"],props:{renderWindow:{type:Number},eagerSync:{type:Boolean,default:!1},cacheSize:{type:Number,default:1e8},wsClient:{type:Object}},setup(r,{emit:c}){const d=s.inject("trame"),p=d.state.get("__trame_vtklocal_wasm_url"),T=s.ref(null),v=s.ref(null),y=r.wsClient||(d==null?void 0:d.client),S={},g={},M={},m=s.ref(1);let o=null,w=0,b=null;function E([e]){if(e.type==="state"){const{mtime:i,content:n,id:t}=e;o.unRegisterState(t),o.registerState(n),S[t]=i}if(e.type==="blob"){const{hash:i,content:n}=e;M[i]=new Promise(t=>{n.arrayBuffer?n.arrayBuffer().then(a=>{o.registerBlob(i,new Uint8Array(a)),t()}):(o.registerBlob(i,n),t())})}}async function U(){const e=y.getConnection().getSession();b=e.subscribe("vtklocal.subscriptions",E),await e.call("vtklocal.subscribe.update",[r.renderWindow,1])}async function C(){const e=y.getConnection().getSession();b&&(e.unsubscribe(b),b=null),await e.call("vtklocal.subscribe.update",[r.renderWindow,-1])}function O(){const{width:e,height:i}=T.value.getBoundingClientRect(),n=Math.floor(e*window.devicePixelRatio+.5),t=Math.floor(i*window.devicePixelRatio+.5),a=s.unref(v);a&&o&&r.renderWindow&&(a.width=n,a.height=t,o.setSize(r.renderWindow,n,t),o.render(r.renderWindow))}let h=new ResizeObserver(O);async function z(e){const n=await y.getConnection().getSession().call("vtklocal.get.state",[e]);return n.length>0?(S[e]=JSON.parse(n).MTime,o.unRegisterState(e),o.registerState(n)):console.log(`Server returned empty state for ${e}`),n}async function A(e){if(M[e]){await M[e],g[e]=s.unref(m),delete M[e];return}const n=await y.getConnection().getSession().call("vtklocal.get.hash",[e]),t=n.arrayBuffer?new Uint8Array(await n.arrayBuffer()):n;return o.registerBlob(e,t),g[e]=s.unref(m),t}function V(){const e=o.getTotalVTKDataObjectMemoryUsage(),i=o.getTotalBlobMemoryUsage(),n=Number(r.cacheSize)+e;if(i>n){const t={};let a=s.unref(m);for(Object.entries(g).forEach(([f,l])=>{l<a&&(a=l);const j=l.toString();t[j]?t[j].push(f):t[j]=[f]});o.getTotalBlobMemoryUsage()>n;){const f=t[a];if(f)for(let l=0;l<f.length;l++)o.unRegisterBlob(f[l]),delete g[f[l]];a++}}c("memory-vtk",o.getTotalVTKDataObjectMemoryUsage()),c("memory-arrays",o.getTotalBlobMemoryUsage())}async function B(){if(w++,w===1)try{const i=await y.getConnection().getSession().call("vtklocal.get.status",[r.renderWindow]),n=[];i.ids.forEach(([t,a])=>{(!S[t]||S[t]<a)&&n.push(z(t))}),i.ignore_ids.forEach(t=>{o.unRegisterState(t)}),i.hashes.forEach(t=>{g[t]||n.push(A(t)),g[t]=s.unref(m)}),await Promise.all(n),m.value++;try{o.updateObjectsFromStates(),O()}catch(t){console.error("WASM update failed"),console.log(t)}c("updated"),V()}catch(e){console.error("Error in update",e)}finally{w--,w&&(w=0,await B())}}return s.onMounted(async()=>{o=await W(s.unref(v),p),r.eagerSync&&U(),await B(),o.startEventLoop(r.renderWindow),h&&h.observe(s.unref(T))}),s.onBeforeUnmount(()=>{b&&C(),o.stopEventLoop(r.renderWindow),h&&(h.disconnect(),h=null)}),{container:T,canvas:v,update:B}},template:`
|
|
2
|
+
<div ref="container" style="position: relative; width: 100%; height: 100%;">
|
|
3
|
+
<canvas
|
|
4
|
+
id="canvas"
|
|
5
|
+
ref="canvas"
|
|
6
|
+
style="position: absolute; left: 0; top: 0; width: 100%; height: 100%;"
|
|
7
|
+
tabindex="0"
|
|
8
|
+
|
|
9
|
+
@contextmenu.prevent
|
|
10
|
+
@click="canvas.focus()"
|
|
11
|
+
@mouseenter="canvas.focus()"
|
|
12
|
+
/>
|
|
13
|
+
</div>`}};function R(r){Object.keys(k).forEach(c=>{r.component(c,k[c])})}u.install=R,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import aiohttp
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import tarfile
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
async def download_file(url, filename):
|
|
8
|
+
async with aiohttp.ClientSession() as session:
|
|
9
|
+
async with session.get(url) as response:
|
|
10
|
+
data = await response.read()
|
|
11
|
+
with open(filename, "wb") as f:
|
|
12
|
+
f.write(data)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
async def setup_wasm_directory(target_directory, wasm_url):
|
|
16
|
+
# Need to install wasm
|
|
17
|
+
target_directory.mkdir(parents=True, exist_ok=True)
|
|
18
|
+
|
|
19
|
+
dest_file = str((target_directory / "vtk-wasm.tgz").resolve())
|
|
20
|
+
dest_folder = str(target_directory.resolve())
|
|
21
|
+
await download_file(wasm_url, dest_file)
|
|
22
|
+
|
|
23
|
+
# unpack
|
|
24
|
+
with tarfile.open(dest_file) as tgz:
|
|
25
|
+
tgz.extractall(dest_folder)
|
|
26
|
+
|
|
27
|
+
print(f"Downloaded WASM in {dest_folder}")
|
|
28
|
+
Path(dest_file).unlink()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_wasm_info():
|
|
32
|
+
from vtkmodules.vtkCommonCore import vtkVersion
|
|
33
|
+
|
|
34
|
+
vtk_version = vtkVersion()
|
|
35
|
+
version = vtk_version.GetVTKVersion()
|
|
36
|
+
return (
|
|
37
|
+
version,
|
|
38
|
+
f"https://gitlab.kitware.com/api/v4/projects/13/packages/generic/vtk-wasm/{version}/vtk-wasm.{version}.tar.gz",
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def register_wasm(serve_path):
|
|
43
|
+
version, wasm_url = get_wasm_info()
|
|
44
|
+
BASE_URL = f"__trame_vtklocal/wasm/{version}"
|
|
45
|
+
dest_directory = Path(serve_path) / "wasm" / version
|
|
46
|
+
|
|
47
|
+
if not dest_directory.exists():
|
|
48
|
+
asyncio.new_event_loop().run_until_complete(
|
|
49
|
+
setup_wasm_directory(dest_directory, wasm_url)
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
return dict(
|
|
53
|
+
module_scripts=[f"{BASE_URL}/vtkWasmSceneManager.mjs"],
|
|
54
|
+
state={"__trame_vtklocal_wasm_url": f"{BASE_URL}/vtkWasmSceneManager.wasm"},
|
|
55
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from trame_client.widgets.core import AbstractElement
|
|
2
|
+
from .. import module
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class HtmlElement(AbstractElement):
|
|
6
|
+
def __init__(self, _elem_name, children=None, **kwargs):
|
|
7
|
+
super().__init__(_elem_name, children, **kwargs)
|
|
8
|
+
if self.server:
|
|
9
|
+
self.server.enable_module(module)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"LocalView",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class LocalView(HtmlElement):
|
|
18
|
+
_next_id = 0
|
|
19
|
+
|
|
20
|
+
def __init__(self, render_window, **kwargs):
|
|
21
|
+
super().__init__(
|
|
22
|
+
"vtk-local",
|
|
23
|
+
**kwargs,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
self.__ref = kwargs.get("ref")
|
|
27
|
+
if self.__ref is None:
|
|
28
|
+
LocalView._next_id += 1
|
|
29
|
+
self.__ref = f"_vtklocalview_{LocalView._next_id}"
|
|
30
|
+
|
|
31
|
+
# Must trigger update after registration
|
|
32
|
+
self._window_id = self.object_manager.RegisterObject(render_window)
|
|
33
|
+
render_window.Render()
|
|
34
|
+
self.object_manager.UpdateStatesFromObjects()
|
|
35
|
+
if self.api._debug_state:
|
|
36
|
+
self.object_manager.Export(f"snapshot-{self.api._debug_state_counter}")
|
|
37
|
+
|
|
38
|
+
self._attributes["rw_id"] = f':render-window="{self._window_id}"'
|
|
39
|
+
self._attributes["ref"] = f'ref="{self.__ref}"'
|
|
40
|
+
self._attr_names += [
|
|
41
|
+
("cache_size", "cacheSize"),
|
|
42
|
+
("eager_sync", "eagerSync"),
|
|
43
|
+
]
|
|
44
|
+
self._event_names += [
|
|
45
|
+
"updated",
|
|
46
|
+
("memory_vtk", "memory-vtk"),
|
|
47
|
+
("memory_arrays", "memory-arrays"),
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def api(self):
|
|
52
|
+
return module.get_helper(self.server).api
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def object_manager(self):
|
|
56
|
+
return self.api.vtk_object_manager
|
|
57
|
+
|
|
58
|
+
def update(self):
|
|
59
|
+
self.api.update()
|
|
60
|
+
self.server.js_call(self.__ref, "update")
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: trame-vtklocal
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: VTK Local Rendering using WASM
|
|
5
|
+
Author: Kitware Inc.
|
|
6
|
+
License: Apache Software License
|
|
7
|
+
Keywords: Python,Interactive,Web,Application,Framework
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Web Environment
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: JavaScript
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Description-Content-Type: text/x-rst
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
|
|
20
|
+
==============
|
|
21
|
+
trame-vtklocal
|
|
22
|
+
==============
|
|
23
|
+
|
|
24
|
+
VTK Local Rendering using VTK/WASM to match server side rendering pipeline on the client side.
|
|
25
|
+
The current code base is still at its infancy but we aim to make it the default implementation for local rendering using VTK/ParaView with trame.
|
|
26
|
+
|
|
27
|
+
License
|
|
28
|
+
----------------------------------------
|
|
29
|
+
|
|
30
|
+
This library is OpenSource and follow the Apache Software License
|
|
31
|
+
|
|
32
|
+
Installation
|
|
33
|
+
----------------------------------------
|
|
34
|
+
|
|
35
|
+
.. code-block:: console
|
|
36
|
+
|
|
37
|
+
pip install trame-vtklocal
|
|
38
|
+
|
|
39
|
+
# We need a VTK that has its wasm counterpart
|
|
40
|
+
# This is the first version available with it
|
|
41
|
+
# For ParaView (not yet supported), VTK don't need to be installed
|
|
42
|
+
pip install "vtk==9.3.20240418.dev0" --extra-index-url https://wheels.vtk.org
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
Development
|
|
46
|
+
----------------------------------------
|
|
47
|
+
|
|
48
|
+
Build and install the Vue components
|
|
49
|
+
|
|
50
|
+
.. code-block:: console
|
|
51
|
+
|
|
52
|
+
cd vue-components
|
|
53
|
+
npm i
|
|
54
|
+
npm run build
|
|
55
|
+
cd -
|
|
56
|
+
|
|
57
|
+
Install the library
|
|
58
|
+
|
|
59
|
+
.. code-block:: console
|
|
60
|
+
|
|
61
|
+
pip install -e .
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
Running examples
|
|
65
|
+
----------------------------------------
|
|
66
|
+
|
|
67
|
+
.. code-block:: console
|
|
68
|
+
|
|
69
|
+
pip install trame trame-vtklocal trame-vuetify trame-vtk
|
|
70
|
+
|
|
71
|
+
# We need a VTK that has its wasm counterpart
|
|
72
|
+
# This is the first version available with it
|
|
73
|
+
# For ParaView (not yet supported), VTK don't need to be installed
|
|
74
|
+
pip install "vtk==9.3.20240418.dev0" --extra-index-url https://wheels.vtk.org
|
|
75
|
+
|
|
76
|
+
# regular trame app
|
|
77
|
+
python ./examples/vtk/cone.py
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.rst
|
|
4
|
+
setup.cfg
|
|
5
|
+
setup.py
|
|
6
|
+
trame/__init__.py
|
|
7
|
+
trame/modules/__init__.py
|
|
8
|
+
trame/modules/vtklocal.py
|
|
9
|
+
trame/widgets/__init__.py
|
|
10
|
+
trame/widgets/vtklocal.py
|
|
11
|
+
trame_vtklocal/__init__.py
|
|
12
|
+
trame_vtklocal.egg-info/PKG-INFO
|
|
13
|
+
trame_vtklocal.egg-info/SOURCES.txt
|
|
14
|
+
trame_vtklocal.egg-info/dependency_links.txt
|
|
15
|
+
trame_vtklocal.egg-info/requires.txt
|
|
16
|
+
trame_vtklocal.egg-info/top_level.txt
|
|
17
|
+
trame_vtklocal/module/__init__.py
|
|
18
|
+
trame_vtklocal/module/protocol.py
|
|
19
|
+
trame_vtklocal/module/wasm.py
|
|
20
|
+
trame_vtklocal/module/serve/js/trame_vtklocal.umd.js
|
|
21
|
+
trame_vtklocal/widgets/__init__.py
|
|
22
|
+
trame_vtklocal/widgets/vtklocal.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
trame
|