File: index.html

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; 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: 178; javascript: 165; objc: 153; tcl: 59
file content (159 lines) | stat: -rw-r--r-- 4,711 bytes parent folder | download | duplicates (4)
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
159
<!doctype html>
<html>

<head>
  <meta charset="utf-8" />
  <style>
    #controls {
      width: 30%;
      border: 10px;
      border-radius: 1%;
      color: azure;
      float: left;
    }

    #vtk_render_area {
      position: absolute;
      left: 0;
      top: 0;
      width: 100vw;
      height: 100vh;
      z-index: -1;
    }

    #canvas {
      position: absolute;
      background-color: black;
      padding-right: 0;
      margin-left: auto;
      margin-right: auto;
      display: block;
    }

    #logs {
      width: 30%;
      border: 10px;
      border-radius: 1%;
      resize: none;
      color: rgb(0, 255, 102);
      background-color: rgba(32, 0, 39, 0.0);
      float: right;
    }
  </style>
</head>

<body>
  <div id="vtk_render_area">
    <div>
      <canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
    </div>
  </div>
  <div id="controls">
    <label> Normal of clip plane </label>
    <div>
      <div>
        <input type="range" min="-1" max="1" value="0" class="slider" step="0.1" id="nx"
          oninput="this.nextElementSibling.value = this.value">
        <output>0</output>
      </div>
      <div>
        <input type="range" min="-1" max="1" value="0" class="slider" step="0.1" id="ny"
          oninput="this.nextElementSibling.value = this.value">
        <output>0</output>
      </div>
      <div>
        <input type="range" min="-1" max="1" value="1" class="slider" step="0.1" id="nz"
          oninput="this.nextElementSibling.value = this.value">
        <output>1</output>
      </div>
    </div>
  </div>
  <textarea title="Console output" id="logs" cols="32" rows="20"></textarea>
  <script type='text/javascript'>
    var vtkWasmRuntime = null;
    var demoApp = null;
    var mouseDown = false;

    var Module = {
      'print': (function () {
        var logs = document.getElementById('logs');
        if (logs) logs.value = ''; // clear browser cache
        return function (text) {
          text = Array.prototype.slice.call(arguments).join(' ');
          console.info(text);
          if (logs) {
            logs.value += text + "\n";
            logs.scrollTop = logs.scrollHeight; // focus on bottom
          }
        };
      })(),
      'printErr': function (text) {
        var logs = document.getElementById('logs');
        if (logs) logs.value = ''; // clear browser cache
        text = Array.prototype.slice.call(arguments).join(' ');
        console.error(text);
        if (logs) {
          logs.value += text + "\n";
          logs.scrollTop = logs.scrollHeight; // focus on bottom
        }
      },
      'preRun': [(runtime) => {
        // Enable SMP after https://gitlab.kitware.com/vtk/vtk/-/issues/19424 is resolved
        runtime.ENV.VTK_SMP_BACKEND_IN_USE = "Sequential";
        // cache the VTK wasm runtime instance.
        vtkWasmRuntime = runtime;
      }],
      'onRuntimeInitialized': function () {
        console.log('WASM runtime initialized');
        demoApp = new vtkWasmRuntime.WrappedAsyncClipper("#canvas");
        demoApp.AddClipPlaneModifiedUIObserver((_nx, _ny, _nz) => {
          nx.value = _nx;
          nx.nextElementSibling.value = _nx;
          ny.value = _ny;
          ny.nextElementSibling.value = _ny;
          nz.value = _nz;
          nz.nextElementSibling.value = _nz;
        });
        demoApp.Start();
        // focus on the canvas to grab keyboard inputs.
        canvas.setAttribute('tabindex', '0');
        // grab focus when the render window region receives mouse clicks.
        canvas.addEventListener('click', () => canvas.focus());
        canvas.addEventListener('mousedown', (e) => {
          mouseDown = true;
          demoApp.Abort();
          e.preventDefault();
        });
        canvas.addEventListener('mousemove', () => {
          if (mouseDown) {
            demoApp.Abort();
          }
        });
        canvas.addEventListener('mouseup', (e) => {
          mouseDown = false;
          demoApp.ResetAbortFlag();
        });
      }
    };

    var nx = document.getElementById('nx');
    var ny = document.getElementById('ny');
    var nz = document.getElementById('nz');

    function onClipPlaneNormalChange() {
      if (vtkWasmRuntime === null) {
        console.warn("WASM runtime not yet ready!");
        return;
      }
      demoApp.Abort();
      demoApp.UpdateClipPlaneNormal(Number(nx.value), Number(ny.value), Number(nz.value));
      demoApp.AsyncRender();
    }
    nx.oninput = onClipPlaneNormalChange;
    ny.oninput = onClipPlaneNormalChange;
    nz.oninput = onClipPlaneNormalChange;
  </script>
  <script async type="text/javascript" src="WrappedAsyncClipper.js"></script>
</body>

</html>