Skip to content

Commit ef6b54e

Browse files
committed
more tests
1 parent ee5d5c9 commit ef6b54e

31 files changed

Lines changed: 448 additions & 57 deletions

ngsolve_webgpu/cf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,24 @@ def __init__(
572572
):
573573
# calling super-super class to not create points and vectors
574574
BaseVectorRenderer.__init__(self)
575+
self.scale_with_vector_length = False
575576
self.cf = cf
576577
self.mesh = mesh
577578
# this somehow segfaults in pyodide?
578579
self.grid_size = grid_size
579580
self.size = size
580581

582+
def get_bounding_box(self):
583+
bb = self.mesh.ngmesh.bounding_box
584+
pmin = [bb[0][0], bb[0][1], bb[0][2]]
585+
pmax = [bb[1][0], bb[1][1], bb[1][2]]
586+
return (pmin, pmax)
587+
581588
def redraw(self, timestamp=None):
582589
super().redraw(timestamp=timestamp, cf=self.cf, mesh=self.mesh, grid_size=self.grid_size)
583590

584591
def update(self, options: RenderOptions):
592+
self.options = options
585593
bb = self.mesh.ngmesh.bounding_box
586594
self.bounding_box = np.array(
587595
[[bb[0][0], bb[0][1], bb[0][2]], [bb[1][0], bb[1][1], bb[1][2]]]

ngsolve_webgpu/jupyter.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import ngsolve as ngs
23
import webgpu.jupyter as wj
34
from webgpu.clipping import Clipping
@@ -204,16 +205,21 @@ def Draw(
204205
contact_renderer = ContactPairs(mesh, contact, **kwargs)
205206
render_objects.append(contact_renderer)
206207

207-
scene = wj.Draw(render_objects, width, height)
208+
boxes = [o.get_bounding_box() for o in render_objects]
209+
boxes = [b for b in boxes if b is not None]
210+
if boxes:
211+
pmin = np.array(boxes[0][0])
212+
pmax = np.array(boxes[0][1])
213+
for b in boxes[1:]:
214+
pmin = np.minimum(pmin, np.array(b[0]))
215+
pmax = np.maximum(pmax, np.array(b[1]))
216+
center = 0.5 * (pmin + pmax)
217+
if _clip is not None and isinstance(_clip, dict):
218+
clipping.center = [_clip.get("x", center[0]), _clip.get("y", center[1]), _clip.get("z", center[2])]
219+
else:
220+
clipping.center = list(center)
208221

209-
center = 0.5 * (scene.bounding_box[0] + scene.bounding_box[1])
210-
if _clip is not None and isinstance(_clip, dict):
211-
clipping.center = [_clip.get("x", center[0]), _clip.get("y", center[1]), _clip.get("z", center[2])]
212-
else:
213-
clipping.center = center
214-
import time
215-
clipping.update(time.time())
216-
scene.render()
222+
scene = wj.Draw(render_objects, width, height)
217223
if dim == 3:
218224
clipping.add_options_to_gui(scene.gui)
219225
for r in render_objects:

tests/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ARG BASE_IMAGE=webgpu-base
22
FROM ${BASE_IMAGE}
33

4-
RUN pip install --no-cache-dir --break-system-packages ngsolve ipython
4+
RUN pip install --no-cache-dir --break-system-packages ngsolve ipython webgpu
55

66
WORKDIR /app
77
COPY pyproject.toml .

tests/baselines/cf_3d.png

Lines changed: 3 additions & 0 deletions
Loading

tests/baselines/cf_order1.png

Lines changed: 3 additions & 0 deletions
Loading

tests/baselines/cf_order4.png

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

tests/baselines/cf_vector.png

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)