-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
715 lines (576 loc) · 18.9 KB
/
index.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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>BioWeb3D</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 {
background-color: #000000;
margin: 0px;
overflow: hidden;
font-family:arial,sans-serif;
}
a {
color:#0078ff;
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
h3 {
font-size : 12px;
}
.UI {
z-index:99;
}
.UIControl {
position:absolute;
left:5px;
bottom:-5px;
height:20px;
border: 5px solid transparent;
-moz-border-radius: 15px;
border-radius: 5px;
font-size:0.8em;
background:#fff;
padding : 5px 5px;
cursor: pointer;
opacity:0.6;
text-align:center;
filter:alpha(opacity=60);
}
.heightLimited {
max-height:450px;
}
</style>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21852728-12']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<script src="build/json2.js"></script>
<script src="build/jquery-1.8.0.min.js"></script>
<script src="build/jquery-ui-1.9.0.custom.min.js"></script>
<link type="text/css" href="css/jquery-ui-1.8.24.custom.css" rel="Stylesheet" />
<script src="build/three.min.js"></script>
<script src="build/underscore.js"></script>
<script src="build/backbone.js"></script>
<script src="build/backbone-localstorage.js"></script>
<script src="build/Stats.js"></script>
<script src="build/Detector.js"></script>
<script src="build/TrackballControls.js"></script>
<script src="build/jscolor/jscolor.js"></script>
<script src="build/jquery.csv-0.71.min.js"></script>
<script>
//Checking for WebGL
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
//Defining application global variables
var KeyDown=false,axisLength=10000,renderer,container,worlds=new Array(),winHeight=window.innerHeight,winWidth=window.innerWidth,datasets=new Array(),numWorlds,timeout,alphaClust=1,alphaRaw=0.1,partSize=2,centerPoints=true;
</script>
<!-- creating the UI -->
<div class="UIControl">
Show/Hide UI
</div>
<div id='console' style="position:absolute;width:30%;padding:15px;text-align:center;font-weight:bold;background:#fff;display:none;font-color:#66A3FF;top:50%;left:35%"></div>
<div class="UI">
<div class="session" style="position:absolute;left:0px;top:0px;;width:100%;height:30px;border:1px solid #000;background:#fff;padding-top:5px;opacity:0.6;filter:alpha(opacity=60);">
<div id="current" style="display:inline"><b>BioWeb3D-1.0</b></div>
<div style="float:right;display:inline;margin-right:25px;">
<a href='http://www.ebi.ac.uk/~jbpettit/bioWeb3D/?dataset=examples/platynereis.json&cluster0=examples/20Clustbeta0Rand.json' target='_self'>See an example</a>    
<a href='https://github.com/jbogp/bioWeb3D/wiki/Getting-started' target='_blank'>Getting started</a>    
<a href='https://github.com/jbogp/bioWeb3D' target='_blank'>See project on Github</a>
</div>
</div>
<div class="controls" style="position:absolute;right:0px;top:36px;overflow: auto;width:400px;border:1px solid #000;background:#000;opacity:0.6;filter:alpha(opacity=60);">
<div id="accordion">
<h3><a href="#">Datasets</a></h3>
<div class="heightLimited">
<input type="file" id="newDataSet">
<div id="accordionData">
</div>
</div>
<h3><a href="#">View</a></h3>
<div>
<div id='worldAccordion' style="text-align:center">
<input type='checkbox' checked class="checkWorld" id='worldAccordion1' value=0 /><label for='worldAccordion1'>world 1</label>
<input type='checkbox' class="checkWorld" id='worldAccordion2' value=1 /><label for='worldAccordion2'>world 2</label><br />
<input type='checkbox' class="checkWorld" id='worldAccordion3' value=2 /><label for='worldAccordion3'>world 3</label>
<input type='checkbox' class="checkWorld" id='worldAccordion4' value=3 /><label for='worldAccordion4'>world 4</label>
</div>
</div>
<h3><a href="#">Settings</a></h3>
<div>
<div class="coefs" style="padding:10px !important;">
<input type='checkbox' checked class="checkCenter" id='checkCenter' value=1 /><label for='checkCenter'>Center points</label>
</div>
<div class="coefs" style="padding:10px !important;">
Axis Coefficients :</br>
X axis<div class="sliderCoord" id="sliderX"></div>
Y axis<div class="sliderCoord" id="sliderY"></div>
Z axis<div class="sliderCoord" id="sliderZ"></div>
</div>
<div class="coefs" style="padding:10px !important;">
Raw data transparency : </br>
<div class="alphaRaw" id="alphaRaw"></div>
</div>
<div class="coefs" style="padding:10px !important;">
Classes transparency : </br>
<div class="alphaClust" id="alphaClust"></div>
</div>
<div class="coefs" style="padding:10px !important;">
Particles size : </br>
<div class="sliderPartSize" id="sliderPartSize"></div>
</div>
</div>
</div>
</div>
</div>
<!-- importing application scripts -->
<script src="js/utils.js"></script>
<script src="js/materials.js"></script>
<script src="js/labelClasses.js"></script>
<script src="js/dataUpload.js"></script>
<script src="js/clusterUpload.js"></script>
<script>
//defining world model
function World(id,innerWidth,innerHeight,x,y,visible,labelsToUse){
//Initialisation
this.id = id;
this.visible = visible;
this.numDataSet = 0;
this.camera = new THREE.PerspectiveCamera( 75, innerWidth / innerHeight, 1, 100000 );
this.scene = new THREE.Scene();
this.controls = new THREE.TrackballControls( this.camera );
this.x = x;
this.y = y;
this.innerWidth = innerWidth;
this.innerHeight = innerHeight;
//Attached visualizations
this.datasets = new Array();
this.clusters = new Array();
//Setting camera position
this.camera.position.z = 100;
this.camera.position.x = 100;
this.camera.position.y = 100;
//Adding camera to the scene
this.scene.add( this.camera );
//Create axis (point1, point2, colour)
this.createAxis = function(p1, p2, color){
var line, lineGeometry = new THREE.Geometry(),lineMat = new THREE.LineBasicMaterial({color: color, lineWidth: 1});
lineGeometry.vertices.push(p1, p2);
line = new THREE.Line(lineGeometry, lineMat);
this.scene.add(line);
}
//Creating 3 axis
this.createAxis(v(-axisLength, 0, 0), v(axisLength, 0, 0), 0xffffff);
this.createAxis(v(0, -axisLength, 0), v(0, axisLength, 0), 0xffffff);
this.createAxis(v(0, 0, -axisLength), v(0, 0, axisLength), 0xffffff);
//Creating Axis labels
this.labelSet = new WorldLabelSet(this,labelsToUse);
//Turn off controls
this.disableControls = function () {
this.controls.enabled = false;
}
//Turn on controls
this.enableControls = function () {
this.controls.enabled = true;
}
//Change world size and localization
this.changeSize = function(innerWidth,innerHeight,x,y) {
this.innerWidth = innerWidth;
this.innerHeight = innerHeight;
this.x = x;
this.y = y;
}
//toggle visibility
this.toggle = function() {
if(this.visible) {
this.visible = false;
this.labelSet.hideAll();
}
else{
this.visible = true;
this.labelSet.worldLabel.show();
}
}
//attach a DataSet to the world
this.attachDataSet = function(dataSet,setNum,cluster) {
cluster = typeof cluster !== 'undefined' ? cluster : -1;
//Check if the dataset has been loaded
if(!dataSet.loaded) {
alert("loading is not finished");
}
else{
//Removing same already attached dataset (even if different cluster) if any
if(typeof this.datasets[""+setNum+""] !== 'undefined'){
this.detachDataSet(setNum);
}
//registering new PaticuleSystem
try{
this.datasets[""+setNum+""] = [dataSet.createParticuleSystem(cluster),setNum,cluster];
ret = this.datasetID;
//Adding particule Systems to the scene
for( var i=0; i<this.datasets[""+setNum+""][0].length ; i++ ) {
this.scene.add(this.datasets[""+setNum+""][0][i]);
}
//adding numDataSet
this.numDataSet++;
}
catch(e) {
console.log("particule system creation failed");
throw new Error("ParticleSystem error");
}
}
}
//Is a dataset attached ?
this.isAttached = function(setNum) {
return(typeof this.datasets[""+setNum+""] !== 'undefined')
}
//Is a dataset showing raw or cluster data ?
this.isRaw = function(setNum) {
return(this.isAttached(setNum) && this.datasets[""+setNum+""][2] == -1)
}
//Is the world empty ?
this.empty = function() {
return(this.numDataSet == 0)
}
//detach a DataSet from the world
this.detachDataSet = function(numDataset) {
//Catching eventual error
try{
//deleting ParticuleSystem
for( var i=0; i<this.datasets[""+numDataset+""][0].length ; i++ ) {
this.scene.remove(this.datasets[""+numDataset+""][0][i]);
if(typeof this.datasets[""+numDataset+""][0][i] !== 'undefined') {
this.datasets[""+numDataset+""][0][i].traverse( function ( object ) {
renderer.deallocateObject( object );
object.geometry.deallocate();
object.material.deallocate();
object.deallocate();
} );
}
}
delete this.datasets[""+numDataset+""];
//Removing numDataSet
this.numDataSet--;
}
catch(e) {
console.log("Deleting non-existing dataset... Just moving on with loading: "+e.message);
}
}
//Refresh DataSets
this.refreshDataSets = function() {
var numDataset;
var numClust;
var self = this;
$.each(this.datasets, function(key, value) {
if(typeof value !== 'undefined') {
numDataSet = value[1];
numClust = value[2];
self.detachDataSet(key);
self.attachDataSet(datasets[numDataSet],numDataSet,numClust);
}
});
}
//Creating the Render function
this.render = function () {
//Updating controls
this.controls.update();
if(this.visible) {
//Updating labels
this.labelSet.render();
renderer.setViewport(this.x, this.y, this.innerWidth, this.innerHeight);
renderer.render( this.scene, this.camera );
}
}
};
//defining dataset Model
function DataSet(data){
this.points;
this.name;
this.centered = new Array();
this.nonCentered = new Array();
this.clusterSets = new Array();
this.loaded = false;
this.chain;
this.mean = new Array();
this.loadMaterials = function() {
//Dataset Material
this.dataSetMaterial = new THREE.ParticleBasicMaterial({
color: 0xffffff,
size: 2,
opacity:alphaRaw,
blending: THREE.NormalBlending,
transparent: true
});
//Line Material
this.lineMaterial = new THREE.LineBasicMaterial({
color: 0xffffff,
linewidth: 4,
transparent : true,
opacity : 0.8,
});
}
//Create Three.js particle system for new dataset
this.createParticuleSystem = function(cluster){
var error = false;
var pX,pY,pZ;
this.loadMaterials();
cluster = typeof cluster !== 'undefined' ? cluster : -1;
//Take centered points if center is selected or let normal points otherwise
var points;
if(centerPoints) {
points = this.centered;
}
else {
points = this.nonCentered;
}
if(this.loaded) {
var geometry=new Array(),particles, particle,particleSystem=new Array();
//For chain
var geometryLine=new THREE.Geometry();
//Create particule system for raw data
if(cluster == -1) {
//create DataSet geometry
geometry[0] = new THREE.Geometry();
for (var i = 0; i < this.centered.length; i++) {
pX = points[i][0],
pY = points[i][1],
pZ = points[i][2],
particle = new THREE.Vector3(pX, pY, pZ);
geometry[0].vertices.push( particle );
}
if(!this.chain) {
// create the particle systems
particleSystem[0] = new THREE.ParticleSystem(geometry[0],this.dataSetMaterial);
}
else {
particleSystem[0] = new THREE.Line(geometry[0], this.lineMaterial);
}
particleSystem[0].dynamic = true;
particleSystem[0].sortParticles = true;
}
//Create particule Systems for cluster sets
else {
//Creating geometries
for( var i=0; i<this.clusterSets[cluster].numClust; i++ ) {
geometry[i] = new THREE.Geometry();
}
for (var i = 0; i < this.centered.length && !error; i++) {
var pX = points[i][0],
pY = points[i][1],
pZ = points[i][2],
particle = new THREE.Vector3(pX, pY, pZ);
if(this.chain) {
geometryLine.vertices.push( particle );
}
//Handling error in case of mismatching dataset and clusterset
try{
geometry[this.clusterSets[cluster].set[i]-1].vertices.push( particle );
}
catch(e) {
error = true;
//Zeros or negative values as class
if(this.clusterSets[cluster].set[i] <= 0) {
consoleMess("Error, the information layer contains 0s or negative values");
}
else {
consoleMess("Error, the information layer could not be read properly. Check :"
+"<ul><li> that you define a class for every point in the dataset</li><li>that the file is <a href=\"https://github.com/jibooo/bioWeb3D/wiki/Getting-started\" target='_blank'>well formated</a></li></ul>");
}
throw "bad info layer error";
}
}
for( var i=0; i<this.clusterSets[cluster].numClust && !error; i++ ) {
if(this.clusterSets[cluster].visible[i]) {
particleSystem[i] = new THREE.ParticleSystem(geometry[i],this.clusterSets[cluster].materials[i]);
}
else{
particleSystem[i] = new THREE.ParticleSystem(geometry[i],this.dataSetMaterial);
}
particleSystem[i].dynamic = true;
particleSystem[i].sortParticles = true;
}
if(this.chain && !error) {
particleSystem[i+1] = new THREE.Line(geometryLine, this.lineMaterial);
particleSystem[i+1].dynamic = true;
particleSystem[i+1].sortParticles = true;
}
}
return particleSystem;
}
}
//Setter for loaded points
this.setPoints = function(points) {
this.points = points;
//Making sure everything is numbers
for (var i = 0; i < this.points.length; i++) {
for(var j = 0; j < 3; j++) {
this.points[i][j] = Number(this.points[i][j]);
}
}
this.computeMeans();
this.center([1,1,1]);
}
//Setter for dataset Name
this.setName = function(name) {
this.name = name;
}
//Add clusterset to this dataset
this.addClusterSet = function(clusterSet) {
return this.clusterSets.push(clusterSet);
}
//Refresh clustersets to this dataset
this.refreshClusterSets = function() {
this.clusterSets.forEach(function(clusterSet) {
clusterSet.refreshSet();
});
}
//Computing mean of raw data to center on 0
this.computeMeans = function() {
var mean = new Array();
for (var i = 0; i < this.points.length; i++) {
if(i == 0) {
this.mean = [this.points[i][0],this.points[i][1],this.points[i][2]];
}
else {
this.mean[0] += this.points[i][0];
this.mean[1] += this.points[i][1];
this.mean[2] += this.points[i][2];
}
}
this.mean[0] = this.mean[0]/this.points.length;
this.mean[1] = this.mean[1]/this.points.length;
this.mean[2] = this.mean[2]/this.points.length;
}
//Centering data on 0 accounting for the axis respective coeficients
this.center = function(coef) {
for (var i = 0; i < this.points.length; i++) {
this.centered[i] = new Array();
this.nonCentered[i] = new Array();
for(var j = 0; j < 3; j++) {
this.centered[i][j] = (((this.points[i][j])-this.mean[j])*coef[j]);
this.nonCentered[i][j] = (this.points[i][j]*coef[j]);
}
}
}
//Constructor
this.setPoints(data.points);
//Setting name
if(typeof data.name !== 'undefined' && data.name !== '') {
this.setName(data.name);
}
else {
this.setName("Unamed dataset");
}
//Setting Chain
if(typeof data.chain !== 'undefined' && data.chain !== '') {
this.chain = data.chain;
}
else {
this.chain = false;
}
//Setting loaded
this.loaded = true;
}
//defining cluster Model
function ClusterSet(jsonObj){
this.set=jsonObj.values;
this.numClust = jsonObj.numClass;
this.name = jsonObj.name;
this.visible = new Array();
this.materials = new Array();
this.labels = new Array();
//Initialize visibility
for(var i=0;i<this.numClust;i++){
this.visible[i] = true;
}
//Initialize materials
for(var i=0;i<this.numClust;i++){
this.materials[i] = new THREE.ParticleBasicMaterial({
size: partSize,
opacity:1,
blending: THREE.NoBlending,
transparent: false
});
this.materials[i].color.setHex(colors[i]);
if(typeof jsonObj.labels !== 'undefined') {
this.labels[i] = jsonObj.labels[i];
}
else{
this.labels[i] = "cluster "+(i+1);
}
}
this.refreshSet = function() {
this.materials.forEach(function(material) {
material.opacity = alphaClust;
material.size = partSize;
});
}
//setter for cluster color
this.setColor = function(numClust, color) {
this.materials[numClust].color.setHex(color);
}
}
//Request Animation Frame
function animate() {
requestAnimationFrame( animate );
renderWorlds();
}
/********************************************************
LAUNCHING APPLICATION
*********************************************************/
$(function(){
//Initializing Renderer
initRenderer(window.innerWidth,window.innerHeight);
//Initializing UI
initUI();
//How many worlds
if(typeof getUrlVars()["numW"] !== 'undefined'){
numWorlds = getUrlVars()["numW"];
for(var i=1;i<=numWorlds;i++) {
$('#worldAccordion'+i+'').prop('checked',true);
$("#worldAccordion").buttonset();
}
}
else {
numWorlds = 1;
}
//Change labels ?
var i=0;
var labelsToUse = [];
if(getUrlVars()["labelset"] == 'bio'){
labelsToUse = ["lateral","medial","versal","dorsal","anterior","posterior"]
}
//Default Labels
else{
labelsToUse = ["x","x","z","z","y","y"];
}
console.log(labelsToUse);
//Starting 4 world
worlds[0] = new World(1,(window.innerWidth), (window.innerHeight),0,0,numWorlds>=1,labelsToUse);
worlds[1] = new World(2,(window.innerWidth), (window.innerHeight),0,0,numWorlds>=2,labelsToUse);
worlds[2] = new World(3,(window.innerWidth), (window.innerHeight),0,0,numWorlds>=3,labelsToUse);
worlds[3] = new World(4,(window.innerWidth), (window.innerHeight),0,0,numWorlds>=4,labelsToUse);
setWorlds();
var i=0;
if(typeof getUrlVars()["dataset"] !== 'undefined'){
setFactory(getUrlVars()["dataset"]);
while(typeof getUrlVars()["cluster"+i] !== 'undefined'){
setTimeout('clusterSetFactory(getUrlVars()["cluster'+i+'"],1)',(i+1)*2000);
i++;
}
}
animate();
});
</script>
</body>