File: index.html

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,992 kB
  • sloc: cpp: 2,336,570; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 185; javascript: 165; objc: 153; tcl: 59
file content (158 lines) | stat: -rw-r--r-- 4,070 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE html>
<html lang="en-us">

<head>
  <meta charset="utf-8">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <style>
    :root {
      color-scheme: light dark;
    }

    html,
    body {
      /*remove default margin*/
      margin: 0;
      /* make body fill the browser */
      height: 100%;
    }

    #outer {
      width: 100%;
      height: 100%;
      display: block;
      overflow: auto;
    }

    .canvas {
      display: inline-block;
      padding: 1em;
      background: #888;
      margin: 1em;
    }

    .size0>canvas {
      width: 300px;
      height: 300px;
    }

    .size1>canvas {
      width: 400px;
      height: 300px;
    }

    .size2>canvas {
      width: 300px;
      height: 400px;
    }

    .size3>canvas {
      width: 400px;
      height: 400px;
    }
  </style>
</head>

<body>
  <div id="outer">
  </div>
  <script>
    const numCanvases = 16;
    /**
     * Lock canvas size for VTK rendering unit tests. These settings make the canvas ignore
     * resize events from the parent HTML element.
     */
    function lockCanvasSize(wasmRuntime) {
      try {
        if (typeof wasmRuntime._setDefaultExpandVTKCanvasToContainer !== 'undefined') {
          wasmRuntime._setDefaultExpandVTKCanvasToContainer(false);
        }
        if (typeof wasmRuntime._setDefaultInstallHTMLResizeObserver !== 'undefined') {
          wasmRuntime._setDefaultInstallHTMLResizeObserver(false);
        }
      } catch (_e) {}
    }

    const resizeObserver = new ResizeObserver((entries) => {
      for (const entry of entries) {
        const canvas = entry.target;
        const width = entry.contentBoxSize[0].inlineSize;
        const height = entry.contentBoxSize[0].blockSize;
        const scaledWidth = Math.max(
          1,
          width * window.devicePixelRatio + 0.5
        );
        const scaledHeight = Math.max(
          1,
          height * window.devicePixelRatio + 0.5
        );
        Module._updateSize(canvas.internalIndex, scaledWidth, scaledHeight);
        Module._render(canvas.internalIndex);
      }
    });

    function rand(min, max) {
      if (min === undefined) {
        max = 1;
        min = 0;
      } else if (max === undefined) {
        max = min;
        min = 0;
      }
      return Math.random() * (max - min) + min;
    }

    function addCanvas(canvasId, sourceName, iCanvas) {
      canvasId = maybeCStringToJsString(canvasId);
      sourceName = maybeCStringToJsString(sourceName);
      const outerElem = document.body.querySelector("#outer");
      // making this
      // <div class="product size?">
      //   <canvas></canvas>
      //   <div>Canvas#: ?</div>
      // </div>
      const newCanvas = document.createElement('canvas');
      newCanvas.id = canvasId;
      newCanvas.oncontextmenu = (event) => event.preventDefault();
      newCanvas.tabIndex = -1;
      newCanvas.internalIndex = iCanvas;
      resizeObserver.observe(newCanvas);

      const container = document.createElement('div');
      container.className = `canvas size${Math.floor(rand(1, 4))}`;

      const description = document.createElement('div');
      description.textContent = `Canvas #: ${iCanvas + 1} ${sourceName}`;

      container.onmouseenter = () => {
        Module._startEventLoop(iCanvas);
        newCanvas.focus();
      };
      container.onmouseleave = () => {
        Module._stopEventLoop(iCanvas);
      };
      container.appendChild(newCanvas);
      container.appendChild(description);
      outerElem.appendChild(container);
      setTimeout((i) => Module._render(i), 1000, iCanvas);
    }

    var vtkWasmRuntime = null;
    var Module = {
      arguments: [`${numCanvases}`],
      preRun: (runtime) => {
        // cache the VTK wasm runtime instance.
        vtkWasmRuntime = runtime;
        vtkWasmRuntime.ENV.VTK_GRAPHICS_BACKEND = "WEBGPU";
      },
      onRuntimeInitialized: () => {
        if (vtkWasmRuntime !== null) {
          lockCanvasSize(vtkWasmRuntime);
        }
      },
    };
  </script>
  {{{ SCRIPT }}}
</body>

</html>