refast_vtk_js 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.
@@ -0,0 +1,92 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .nox/
42
+ .coverage
43
+ .coverage.*
44
+ .cache
45
+ nosetests.xml
46
+ coverage.xml
47
+ *.cover
48
+ *.py,cover
49
+ .hypothesis/
50
+ .pytest_cache/
51
+
52
+ # Translations
53
+ *.mo
54
+ *.pot
55
+
56
+ # Environments
57
+ .env
58
+ .venv
59
+ env/
60
+ venv/
61
+ ENV/
62
+ env.bak/
63
+ venv.bak/
64
+
65
+ # IDEs
66
+ .idea/
67
+ .vscode/
68
+ *.swp
69
+ *.swo
70
+ *~
71
+
72
+ # Jupyter Notebook
73
+ .ipynb_checkpoints
74
+
75
+ # pyenv
76
+ .python-version
77
+
78
+ # Node.js
79
+ node_modules/
80
+ npm-debug.log*
81
+ yarn-debug.log*
82
+ yarn-error.log*
83
+
84
+ # Frontend build artifacts (keep the static directory but not its contents except .gitkeep)
85
+ # Note: Built assets are not committed, they're built during install via hatch hook
86
+ src/refast_vtk_js/static/*.js
87
+ src/refast_vtk_js/static/*.css
88
+ !src/refast_vtk_js/static/.gitkeep
89
+
90
+ # OS files
91
+ .DS_Store
92
+ Thumbs.db
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Najeem Muhammed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,309 @@
1
+ Metadata-Version: 2.4
2
+ Name: refast_vtk_js
3
+ Version: 0.1.0
4
+ Summary: Refast extension for vtk
5
+ Project-URL: Homepage, https://github.com/idling-mind/refast_vtk_js
6
+ Project-URL: Bug Tracker, https://github.com/idling-mind/refast_vtk_js/issues
7
+ Project-URL: Documentation, https://github.com/idling-mind/refast_vtk_js#readme
8
+ Author-email: Najeem Muhammed <najeem@gmail.com>
9
+ License-File: LICENSE
10
+ Classifier: Framework :: FastAPI
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: refast>=0.0.1
21
+ Description-Content-Type: text/markdown
22
+
23
+ # refast-vtk-js
24
+
25
+ 3D visualization extension for Refast powered by [react-vtk-js](https://github.com/Kitware/react-vtk-js).
26
+
27
+ A [Refast](https://github.com/idling-mind/refast) extension that provides VTK.js components for interactive 3D visualization in web applications.
28
+
29
+ ## Features
30
+
31
+ - **View Components**: `View`, `MultiViewRoot` for creating 3D scenes
32
+ - **Representations**: `GeometryRepresentation`, `VolumeRepresentation`, `SliceRepresentation` for different visualization modes
33
+ - **Data Components**: `PolyData`, `ImageData`, `DataArray` for defining geometry and data
34
+ - **Algorithms**: `Algorithm`, `Reader` for data processing and file loading
35
+ - **Interaction**: `Picking` for mouse-based selection
36
+ - **Data Sharing**: `ShareDataSetRoot`, `RegisterDataSet`, `UseDataSet` for efficient data reuse
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install refast-vtk-js
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ ### Basic 3D Triangle
47
+
48
+ ```python
49
+ from fastapi import FastAPI
50
+ from refast import RefastApp, Context
51
+ from refast.components import Container
52
+ from refast_vtk_js import View, GeometryRepresentation, PolyData
53
+
54
+ ui = RefastApp(title="VTK.js Demo")
55
+
56
+
57
+ @ui.page("/")
58
+ def home(ctx: Context):
59
+ return Container(
60
+ children=[
61
+ View(
62
+ background=[0.2, 0.3, 0.4],
63
+ style={"width": "100%", "height": "400px"},
64
+ children=[
65
+ GeometryRepresentation(
66
+ property={"color": [1, 0, 0]},
67
+ children=[
68
+ PolyData(
69
+ points=[0, 0, 0, 1, 0, 0, 0.5, 1, 0],
70
+ connectivity="triangles"
71
+ )
72
+ ]
73
+ )
74
+ ]
75
+ )
76
+ ]
77
+ )
78
+
79
+
80
+ app = FastAPI()
81
+ app.include_router(ui.router)
82
+
83
+ if __name__ == "__main__":
84
+ import uvicorn
85
+ uvicorn.run(app, host="0.0.0.0", port=8000)
86
+ ```
87
+
88
+ ### Using VTK Algorithms (Cone, Sphere, etc.)
89
+
90
+ ```python
91
+ from refast_vtk_js import View, GeometryRepresentation, Algorithm
92
+
93
+ View(
94
+ style={"width": "100%", "height": "400px"},
95
+ children=[
96
+ GeometryRepresentation(
97
+ children=[
98
+ Algorithm(
99
+ vtk_class="vtkConeSource",
100
+ state={
101
+ "height": 2.0,
102
+ "radius": 0.5,
103
+ "resolution": 60
104
+ }
105
+ )
106
+ ]
107
+ )
108
+ ]
109
+ )
110
+ ```
111
+
112
+ ### Volume Rendering
113
+
114
+ ```python
115
+ from refast_vtk_js import View, VolumeRepresentation, ImageData, PointData, DataArray
116
+
117
+ # Create a 10x10x10 volume with scalar data
118
+ dimensions = [10, 10, 10]
119
+ values = [i / 1000 for i in range(10 * 10 * 10)] # Scalar values
120
+
121
+ View(
122
+ style={"width": "100%", "height": "400px"},
123
+ children=[
124
+ VolumeRepresentation(
125
+ color_map_preset="Cool to Warm",
126
+ children=[
127
+ ImageData(
128
+ dimensions=dimensions,
129
+ spacing=[1, 1, 1],
130
+ origin=[0, 0, 0],
131
+ children=[
132
+ PointData(
133
+ children=[
134
+ DataArray(
135
+ registration="setScalars",
136
+ values=values,
137
+ number_of_components=1
138
+ )
139
+ ]
140
+ )
141
+ ]
142
+ )
143
+ ]
144
+ )
145
+ ]
146
+ )
147
+ ```
148
+
149
+ ### Loading 3D Models from URL
150
+
151
+ ```python
152
+ from refast_vtk_js import View, GeometryRepresentation, Reader
153
+
154
+ View(
155
+ style={"width": "100%", "height": "400px"},
156
+ children=[
157
+ GeometryRepresentation(
158
+ children=[
159
+ Reader(
160
+ vtk_class="vtkOBJReader",
161
+ url="https://example.com/model.obj"
162
+ )
163
+ ]
164
+ )
165
+ ]
166
+ )
167
+ ```
168
+
169
+ ### Interactive Picking
170
+
171
+ ```python
172
+ from refast_vtk_js import View, GeometryRepresentation, PolyData, Picking
173
+
174
+ async def handle_click(ctx):
175
+ selection = ctx.event_data.get("selection", {})
176
+ world_pos = selection.get("worldPosition")
177
+ print(f"Clicked at world position: {world_pos}")
178
+
179
+ View(
180
+ style={"width": "100%", "height": "400px"},
181
+ children=[
182
+ Picking(
183
+ on_click=ctx.callback(handle_click),
184
+ pointer_size=5
185
+ ),
186
+ GeometryRepresentation(
187
+ children=[
188
+ PolyData(
189
+ points=[0, 0, 0, 1, 0, 0, 0.5, 1, 0],
190
+ connectivity="triangles"
191
+ )
192
+ ]
193
+ )
194
+ ]
195
+ )
196
+ ```
197
+
198
+ ### Sharing Data Between Views
199
+
200
+ ```python
201
+ from refast_vtk_js import (
202
+ ShareDataSetRoot, RegisterDataSet, UseDataSet,
203
+ View, GeometryRepresentation, PolyData
204
+ )
205
+
206
+ ShareDataSetRoot(
207
+ children=[
208
+ # Register the shared data
209
+ RegisterDataSet(
210
+ dataset_id="shared-mesh",
211
+ children=[
212
+ PolyData(
213
+ points=[0, 0, 0, 1, 0, 0, 0.5, 1, 0],
214
+ connectivity="triangles"
215
+ )
216
+ ]
217
+ ),
218
+ # First view
219
+ View(
220
+ style={"width": "50%", "height": "300px"},
221
+ children=[
222
+ GeometryRepresentation(
223
+ property={"color": [1, 0, 0]},
224
+ children=[UseDataSet(dataset_id="shared-mesh")]
225
+ )
226
+ ]
227
+ ),
228
+ # Second view using same data
229
+ View(
230
+ style={"width": "50%", "height": "300px"},
231
+ children=[
232
+ GeometryRepresentation(
233
+ property={"color": [0, 0, 1]},
234
+ children=[UseDataSet(dataset_id="shared-mesh")]
235
+ )
236
+ ]
237
+ )
238
+ ]
239
+ )
240
+ ```
241
+
242
+ ## Available Components
243
+
244
+ ### View Components
245
+ - `View` - Main 3D view container
246
+ - `MultiViewRoot` - Container for multiple synchronized views
247
+
248
+ ### Representation Components
249
+ - `GeometryRepresentation` - For surfaces, meshes, point clouds
250
+ - `Geometry2DRepresentation` - For 2D overlays
251
+ - `VolumeRepresentation` - For volume rendering
252
+ - `SliceRepresentation` - For 2D slices of 3D data
253
+
254
+ ### Dataset Components
255
+ - `PolyData` - Polygonal geometry (points, lines, triangles)
256
+ - `ImageData` - Regular 3D grids (volumes)
257
+ - `Dataset` - Generic VTK dataset wrapper
258
+
259
+ ### Data Array Components
260
+ - `DataArray` - Attach scalar/vector data
261
+ - `PointData` - Container for point-associated arrays
262
+ - `CellData` - Container for cell-associated arrays
263
+ - `FieldData` - Container for field data
264
+
265
+ ### Algorithm & Reader Components
266
+ - `Algorithm` - VTK filters and sources
267
+ - `Reader` - File readers for OBJ, STL, VTK, etc.
268
+
269
+ ### Interaction Components
270
+ - `Picking` - Mouse-based selection
271
+ - `VolumeController` - UI for volume transfer functions
272
+
273
+ ### Data Sharing Components
274
+ - `ShareDataSetRoot` - Root for data sharing
275
+ - `RegisterDataSet` - Register shared data
276
+ - `UseDataSet` - Use registered data
277
+
278
+ ## Manual Registration
279
+
280
+ If auto-discovery doesn't work, you can manually register the extension:
281
+
282
+ ```python
283
+ from refast_vtk_js import VtkExtension
284
+
285
+ ui = RefastApp(
286
+ title="VTK Demo",
287
+ extensions=[VtkExtension()]
288
+ )
289
+ ```
290
+
291
+ ## Development
292
+
293
+ ### Building the Frontend
294
+
295
+ ```bash
296
+ cd frontend
297
+ npm install
298
+ npm run build
299
+ ```
300
+
301
+ ### Watch Mode
302
+
303
+ ```bash
304
+ npm run dev
305
+ ```
306
+
307
+ ## License
308
+
309
+ MIT
@@ -0,0 +1,287 @@
1
+ # refast-vtk-js
2
+
3
+ 3D visualization extension for Refast powered by [react-vtk-js](https://github.com/Kitware/react-vtk-js).
4
+
5
+ A [Refast](https://github.com/idling-mind/refast) extension that provides VTK.js components for interactive 3D visualization in web applications.
6
+
7
+ ## Features
8
+
9
+ - **View Components**: `View`, `MultiViewRoot` for creating 3D scenes
10
+ - **Representations**: `GeometryRepresentation`, `VolumeRepresentation`, `SliceRepresentation` for different visualization modes
11
+ - **Data Components**: `PolyData`, `ImageData`, `DataArray` for defining geometry and data
12
+ - **Algorithms**: `Algorithm`, `Reader` for data processing and file loading
13
+ - **Interaction**: `Picking` for mouse-based selection
14
+ - **Data Sharing**: `ShareDataSetRoot`, `RegisterDataSet`, `UseDataSet` for efficient data reuse
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ pip install refast-vtk-js
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### Basic 3D Triangle
25
+
26
+ ```python
27
+ from fastapi import FastAPI
28
+ from refast import RefastApp, Context
29
+ from refast.components import Container
30
+ from refast_vtk_js import View, GeometryRepresentation, PolyData
31
+
32
+ ui = RefastApp(title="VTK.js Demo")
33
+
34
+
35
+ @ui.page("/")
36
+ def home(ctx: Context):
37
+ return Container(
38
+ children=[
39
+ View(
40
+ background=[0.2, 0.3, 0.4],
41
+ style={"width": "100%", "height": "400px"},
42
+ children=[
43
+ GeometryRepresentation(
44
+ property={"color": [1, 0, 0]},
45
+ children=[
46
+ PolyData(
47
+ points=[0, 0, 0, 1, 0, 0, 0.5, 1, 0],
48
+ connectivity="triangles"
49
+ )
50
+ ]
51
+ )
52
+ ]
53
+ )
54
+ ]
55
+ )
56
+
57
+
58
+ app = FastAPI()
59
+ app.include_router(ui.router)
60
+
61
+ if __name__ == "__main__":
62
+ import uvicorn
63
+ uvicorn.run(app, host="0.0.0.0", port=8000)
64
+ ```
65
+
66
+ ### Using VTK Algorithms (Cone, Sphere, etc.)
67
+
68
+ ```python
69
+ from refast_vtk_js import View, GeometryRepresentation, Algorithm
70
+
71
+ View(
72
+ style={"width": "100%", "height": "400px"},
73
+ children=[
74
+ GeometryRepresentation(
75
+ children=[
76
+ Algorithm(
77
+ vtk_class="vtkConeSource",
78
+ state={
79
+ "height": 2.0,
80
+ "radius": 0.5,
81
+ "resolution": 60
82
+ }
83
+ )
84
+ ]
85
+ )
86
+ ]
87
+ )
88
+ ```
89
+
90
+ ### Volume Rendering
91
+
92
+ ```python
93
+ from refast_vtk_js import View, VolumeRepresentation, ImageData, PointData, DataArray
94
+
95
+ # Create a 10x10x10 volume with scalar data
96
+ dimensions = [10, 10, 10]
97
+ values = [i / 1000 for i in range(10 * 10 * 10)] # Scalar values
98
+
99
+ View(
100
+ style={"width": "100%", "height": "400px"},
101
+ children=[
102
+ VolumeRepresentation(
103
+ color_map_preset="Cool to Warm",
104
+ children=[
105
+ ImageData(
106
+ dimensions=dimensions,
107
+ spacing=[1, 1, 1],
108
+ origin=[0, 0, 0],
109
+ children=[
110
+ PointData(
111
+ children=[
112
+ DataArray(
113
+ registration="setScalars",
114
+ values=values,
115
+ number_of_components=1
116
+ )
117
+ ]
118
+ )
119
+ ]
120
+ )
121
+ ]
122
+ )
123
+ ]
124
+ )
125
+ ```
126
+
127
+ ### Loading 3D Models from URL
128
+
129
+ ```python
130
+ from refast_vtk_js import View, GeometryRepresentation, Reader
131
+
132
+ View(
133
+ style={"width": "100%", "height": "400px"},
134
+ children=[
135
+ GeometryRepresentation(
136
+ children=[
137
+ Reader(
138
+ vtk_class="vtkOBJReader",
139
+ url="https://example.com/model.obj"
140
+ )
141
+ ]
142
+ )
143
+ ]
144
+ )
145
+ ```
146
+
147
+ ### Interactive Picking
148
+
149
+ ```python
150
+ from refast_vtk_js import View, GeometryRepresentation, PolyData, Picking
151
+
152
+ async def handle_click(ctx):
153
+ selection = ctx.event_data.get("selection", {})
154
+ world_pos = selection.get("worldPosition")
155
+ print(f"Clicked at world position: {world_pos}")
156
+
157
+ View(
158
+ style={"width": "100%", "height": "400px"},
159
+ children=[
160
+ Picking(
161
+ on_click=ctx.callback(handle_click),
162
+ pointer_size=5
163
+ ),
164
+ GeometryRepresentation(
165
+ children=[
166
+ PolyData(
167
+ points=[0, 0, 0, 1, 0, 0, 0.5, 1, 0],
168
+ connectivity="triangles"
169
+ )
170
+ ]
171
+ )
172
+ ]
173
+ )
174
+ ```
175
+
176
+ ### Sharing Data Between Views
177
+
178
+ ```python
179
+ from refast_vtk_js import (
180
+ ShareDataSetRoot, RegisterDataSet, UseDataSet,
181
+ View, GeometryRepresentation, PolyData
182
+ )
183
+
184
+ ShareDataSetRoot(
185
+ children=[
186
+ # Register the shared data
187
+ RegisterDataSet(
188
+ dataset_id="shared-mesh",
189
+ children=[
190
+ PolyData(
191
+ points=[0, 0, 0, 1, 0, 0, 0.5, 1, 0],
192
+ connectivity="triangles"
193
+ )
194
+ ]
195
+ ),
196
+ # First view
197
+ View(
198
+ style={"width": "50%", "height": "300px"},
199
+ children=[
200
+ GeometryRepresentation(
201
+ property={"color": [1, 0, 0]},
202
+ children=[UseDataSet(dataset_id="shared-mesh")]
203
+ )
204
+ ]
205
+ ),
206
+ # Second view using same data
207
+ View(
208
+ style={"width": "50%", "height": "300px"},
209
+ children=[
210
+ GeometryRepresentation(
211
+ property={"color": [0, 0, 1]},
212
+ children=[UseDataSet(dataset_id="shared-mesh")]
213
+ )
214
+ ]
215
+ )
216
+ ]
217
+ )
218
+ ```
219
+
220
+ ## Available Components
221
+
222
+ ### View Components
223
+ - `View` - Main 3D view container
224
+ - `MultiViewRoot` - Container for multiple synchronized views
225
+
226
+ ### Representation Components
227
+ - `GeometryRepresentation` - For surfaces, meshes, point clouds
228
+ - `Geometry2DRepresentation` - For 2D overlays
229
+ - `VolumeRepresentation` - For volume rendering
230
+ - `SliceRepresentation` - For 2D slices of 3D data
231
+
232
+ ### Dataset Components
233
+ - `PolyData` - Polygonal geometry (points, lines, triangles)
234
+ - `ImageData` - Regular 3D grids (volumes)
235
+ - `Dataset` - Generic VTK dataset wrapper
236
+
237
+ ### Data Array Components
238
+ - `DataArray` - Attach scalar/vector data
239
+ - `PointData` - Container for point-associated arrays
240
+ - `CellData` - Container for cell-associated arrays
241
+ - `FieldData` - Container for field data
242
+
243
+ ### Algorithm & Reader Components
244
+ - `Algorithm` - VTK filters and sources
245
+ - `Reader` - File readers for OBJ, STL, VTK, etc.
246
+
247
+ ### Interaction Components
248
+ - `Picking` - Mouse-based selection
249
+ - `VolumeController` - UI for volume transfer functions
250
+
251
+ ### Data Sharing Components
252
+ - `ShareDataSetRoot` - Root for data sharing
253
+ - `RegisterDataSet` - Register shared data
254
+ - `UseDataSet` - Use registered data
255
+
256
+ ## Manual Registration
257
+
258
+ If auto-discovery doesn't work, you can manually register the extension:
259
+
260
+ ```python
261
+ from refast_vtk_js import VtkExtension
262
+
263
+ ui = RefastApp(
264
+ title="VTK Demo",
265
+ extensions=[VtkExtension()]
266
+ )
267
+ ```
268
+
269
+ ## Development
270
+
271
+ ### Building the Frontend
272
+
273
+ ```bash
274
+ cd frontend
275
+ npm install
276
+ npm run build
277
+ ```
278
+
279
+ ### Watch Mode
280
+
281
+ ```bash
282
+ npm run dev
283
+ ```
284
+
285
+ ## License
286
+
287
+ MIT