-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestThreeJS.html
442 lines (367 loc) · 19.3 KB
/
testThreeJS.html
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
?<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - loaders - vtk loader</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body
{
font-family: sans-serif;
background-color: #000;
color: #fff;
margin: 0px;
overflow: hidden;
display: inline;
}
/*#info {
color: #fff;
position: absolute;
top: 10px;
width: 100%;
text-align: center;
z-index: 100;
display:block;
}
#info a, */
.button
{
color: #f00;
font-weight: bold;
text-decoration: underline;
cursor: pointer;
}
.block
{
text-align: left;
line-height: 40px;
position: absolute;
top: 20%;
left: 0%;
}
/* The ghost, nudged to maintain perfect centering */
.block:before
{
content: '';
display: inline-block;
height: 100%;
vertical-align: left;
margin-right: -0.25em; /* Adjusts for spacing */
}
div.anatomyBox span
{
color: #ffffff;
font-size: 1em;
vertical-align: middle;
margin-left: 5px;
cursor: hand;
}
.positionBlock
{
text-align: left;
line-height: 40px;
position: absolute;
top: 20%;
right: 3%;
}
/* The ghost, nudged to maintain perfect centering */
.positionBlock:before
{
content: '';
display: inline-block;
height: 100%;
vertical-align: left;
margin-right: -0.25em; /* Adjusts for spacing */
}
.cameraPositionBox span
{
color: #ffffff; /*text color*/
font-size: 1em;
vertical-align: middle;
margin-left: 5px;
cursor: hand;
}
.scene
{
position: absolute;
top: 0%;
}
.checkbox {
margin: 0 0 1em 2em;
}
.checkbox .tag {
color: #595959;
display: block;
float: left;
font-weight: bold;
position: relative;
width: 120px;
}
.checkbox label {
display: inline;
}
.checkbox .input-assumpte {
display: none;
}
.input-assumpte + label:after {
background-color: #fafafa;
border: 1px solid #cacece;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
display: inline-block;
transition-duration: 0.3s;
width: 16px;
height: 16px;
content: '';
margin-left: 10px;
}
.input-assumpte:checked + label:after {
background-color: #ff0000;
}
</style>
</head>
<body>
<!--
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> -
vtk formats loader test<br />
Legacy vtk model from <a href="http://www.cc.gatech.edu/projects/large_models/" target="_blank">The GeorgiaTech Lagre Geometric Model Archive</a>,
</div>
-->
<div id="whole_container">
<div class="block" id="block">
<div class="anatomyBox">
<span onclick="bloup();">
<input type="checkbox" id="epicardium_checkbox" checked>
<img src="icons/white.png" style="vertical-align: middle">
Load mapped mesh </span>
</div>
</div>
<div class="positionBlock">
<form action="" class="cameraPositionBox">
<input type="radio" name="position" id="roa_checkbox" onclick="moveCamera(225)">ROA <br>
<input type="radio" name="position" id="loa_checkbox" onclick="moveCamera(315)">LOA <br>
<input type="radio" name="position" id="pa_checkbox" onclick="moveCamera(90)">PA <br>
<input type="radio" name="position" id="ap_checkbox" onclick="moveCamera(270)">AP <br>
<input type="radio" name="position" id="rl_checkbox" onclick="moveCamera(180)">RL <br>
<input type="radio" name="position" id="ll_checkbox" onclick="moveCamera(0)">LL <br>
</form>
</div>
<div class="scene">
<script src='js/libs/inflate.min.js'></script>
<script src="js/three.js"></script>
<script src="js/controls/TrackballControls.js"></script>
<script src="js/loaders/VTKLoader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Lut.js"></script>
<script src="js/libs/stats.min.js"></script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container, stats;
var camera, controls, scene, renderer;
var cross;
var center = new THREE.Vector3();
var cameraFocal = new THREE.Vector3();
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10 );
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
myFunction(xhttp);
}
};
xhttp.open("GET", "meshes/mapping.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var parameterList = xmlDoc.getElementsByTagName("navigator")[0].getElementsByTagName("parameter");
var cameraPositionIndex, cameraUpIndex, cameraFocalIndex;
for(i=0 ; i<parameterList.length ; i++)
{
if(parameterList[i].getElementsByTagName("name")[0].textContent == "Camera Position")
{
cameraPositionIndex = i;
}
else if(parameterList[i].getElementsByTagName("name")[0].textContent == "Camera Up")
{
cameraUpIndex = i;
}
else if(parameterList[i].getElementsByTagName("name")[0].textContent == "Camera Focal")
{
cameraFocalIndex = i;
}
}
//setting camera position
var cameraPositionString = parameterList[cameraPositionIndex].getElementsByTagName("value")[0].textContent.split(" ");
camera.position.x = Number(cameraPositionString[0]);
camera.position.y = Number(cameraPositionString[1]);
camera.position.z = Number(cameraPositionString[2]);
//setting camera up
var cameraUpString = parameterList[cameraUpIndex].getElementsByTagName("value")[0].textContent.split(" ");
camera.up.x = Number(cameraUpString[0]);
camera.up.y = Number(cameraUpString[1]);
camera.up.z = Number(cameraUpString[2]);
//getting camera focal
var cameraFocalString = parameterList[cameraFocalIndex].getElementsByTagName("value")[0].textContent.split(" ");
cameraFocal.x = Number(cameraFocalString[0]);
cameraFocal.y = Number(cameraFocalString[1]);
cameraFocal.z = Number(cameraFocalString[2]);
}
controls = new THREE.TrackballControls( camera );
controls.rotateSpeed = 5.0;
controls.zoomSpeed = 2;
controls.panSpeed = 2;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
scene = new THREE.Scene();
scene.add( camera );
// light
var dirLight = new THREE.DirectionalLight( 0xffffff );
dirLight.position.set( 200, 200, 1000 ).normalize();
camera.add( dirLight );
camera.add( dirLight.target );
var loader = new THREE.VTKLoader();
loader.load( "meshes/12. leftVentricularEndoMesh.vtk", function ( geometry ) {
geometry.computeBoundingBox();
center.x = ( geometry.boundingBox.max.x + geometry.boundingBox.min.x ) / 2;
center.y = ( geometry.boundingBox.max.y + geometry.boundingBox.min.y ) / 2;
center.z = ( geometry.boundingBox.max.z + geometry.boundingBox.min.z ) / 2;
geometry.translate(-center.x, -center.y, -center.z);
var colorMap = "inverted_rainbow";
var colorNumber = 512;
var material = new THREE.MeshLambertMaterial( {
side: THREE.DoubleSide,
color: 0xF5F5F5,
vertexColors: THREE.VertexColors
} );
var lutColors = [];
lut = new THREE.Lut( colorMap, colorNumber );
lut.setMax(6);
lut.setMin(2);
for (var i = 0; i < geometry.userData.pointData.length; i++) {
var colorValue = geometry.userData.pointData[i];
color = lut.getColor(colorValue);
if ( color == undefined ) {
console.log( "ERROR: " + colorValue );
}
else {
lutColors[ 3 * i ] = color.r;
lutColors[ 3 * i + 1 ] = color.g;
lutColors[ 3 * i + 2 ] = color.b;
}
}
geometry.addAttribute( 'color', new THREE.BufferAttribute( new Float32Array( lutColors ), 3 ) );
var lvEndo = new THREE.Mesh( geometry, material );
lvEndo.name = 'leftVentricularEndo';
scene.add( lvEndo );
createGUI(lvEndo.name);
var visibilityON = false;
toggleVisibility(lvEndo.name, visibilityON);
var event = new Event('centerCalculated');
window.dispatchEvent(event);
} );
// renderer
renderer = new THREE.WebGLRenderer( { antialias: false } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight);
container = document.createElement( 'div' );
document.body.appendChild( container );
container.appendChild( renderer.domElement );
stats = new Stats();
container.appendChild( stats.dom );
window.addEventListener( 'resize', onWindowResize, false );
window.addEventListener('centerCalculated', onCenterCalculated,false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
controls.handleResize();
}
function onCenterCalculated() {
loadVTKMesh('meshes/11. leftEndoMesh.vtk', 'left_endocardium', 0x808080, false, 1.0, false);
loadVTKMesh('meshes/13. leftAndRightEpiMesh.vtk', 'epicardium', 0xffffff, true, 0.1, true);
loadVTKMesh('meshes/14. coronarySinusMesh.vtk', 'cs', 0x0000ff, false, 1.0, false);
loadVTKMesh('meshes/15. leftCoronaryArteryMesh.vtk', 'lca', 0xff0000, false, 1.0, false);
loadVTKMesh('meshes/16. rightCoronaryArteryMesh.vtk', 'rca', 0xff0000, false, 1.0, false);
loadVTKMesh('meshes/20. hypodensityMesh.vtk', 'hypodensity', 0x800080, false, 1.0, false); //purple
loadVTKMesh('meshes/27. WTXmmMesh.vtk', 'wtxmm', 0xff0000, false, 1.0, false);
loadVTKMesh('meshes/29. WTYmmMesh.vtk', 'wtymm', 0xffff80, true, 0.42, false); //yellow
}
//default parameter not accepted by IE
function loadVTKMesh(aFile, aName, aColor, transparentON, anOpacity, wireframeON)
{
var loader = new THREE.VTKLoader();
loader.load( aFile, function ( geometry ) {
geometry.computeVertexNormals();
geometry.translate(-center.x, -center.y, -center.z);
var material = new THREE.MeshLambertMaterial( { color: aColor, side: THREE.DoubleSide, transparent: transparentON, wireframe: wireframeON} );
material.opacity = anOpacity;
var mesh = new THREE.Mesh( geometry, material );
mesh.name = aName;
scene.add( mesh );
var visibilityON = true;
createGUI(aName, visibilityON);
} );
}
function createGUI(aName, visibilityON)
{
//Create an input type dynamically.
var checkbox = document.createElement("input");
//Assign different attributes to the element.
checkbox.type = "checkbox";
checkbox.id = aName + '_checkbox';
checkbox.name = aName;
checkbox.className = "anatomyBox";
checkbox.checked = visibilityON;
checkbox.setAttribute("onclick", "toggleVisibility('"+ aName+"');");
var label = document.createElement('label')
label.htmlFor = checkbox.id;
label.appendChild(document.createTextNode(' ' + aName));
var division = document.createElement("div");
division.class = "anatomyBox";
division.appendChild(checkbox);
division.appendChild(label);
var foo = document.getElementById("block");
//Append the element in page (in span).
foo.appendChild(division);
}
function animate() {
requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
stats.update();
}
</script>
<script>
function toggleVisibility(objectname) {
// retrieve scene
scene = eval('scene');
object = scene.getObjectByName(objectname);
// toggle visibility
object.visible = !object.visible;
// update checkbox
document.getElementById(objectname + '_checkbox').checked = object.visible;
}
</script>
<script>
function moveCamera(angle) {
var dx = Math.pow(camera.position.x - cameraFocal.x, 2);
var dy = Math.pow(camera.position.y - cameraFocal.y, 2);
var dz = Math.pow(camera.position.z - cameraFocal.z, 2);
var distCamObj = Math.sqrt(dx + dy + dz);
camera.position.x = cameraFocal.x + distCamObj * Math.cos(angle * Math.PI / 180);
camera.position.y = cameraFocal.y + distCamObj * Math.sin(angle * Math.PI / 180);
camera.position.z = cameraFocal.z;
camera.up.x = 0;
camera.up.y = 0;
camera.up.z = 1;
}
</script>
</div>
</div>
</body>
</html>