-
Notifications
You must be signed in to change notification settings - Fork 0
/
FittedDSModel.js
756 lines (705 loc) · 26.2 KB
/
FittedDSModel.js
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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
/* Hardcode file names or URL below */
filename1 = "BackTransformedUPFFinalRotated_Endo.exdata";
filename2 = "BackTransformedUPFFinalRotated_Epi.exdata";
filename3 = "fitted_epi_humanLV.exelem";
filename4 = "fitted_epi_humanLV.exnode";
filename5 = "LVCanineModel_Transformed_EndoTrans.exelem";
filename6 = "LVCanineModel_Transformed_EndoTrans.exnode";
textureRegions = new Array();
stage = 0;
proteinNames = ["none","clcn1","SCN5A", "kvlqt1"];
cardiacModelNames = ["none", "biventricular", "One chamber", "LV", "RV", "full heart"];
wsGimiasURL = "http://ricordo.insigneo.org:9090/axis2/services/wsGimias";
function ShowHide(divId)
{
if(document.getElementById(divId).style.display == 'none')
{
document.getElementById(divId).style.display='block';
}
else
{
document.getElementById(divId).style.display = 'none';
}
}
function materialSetFieldImage(zincPlugin, region, material, name_series, start, end)
{
var fieldModule = region.getFieldModule();
xiField = fieldModule.findFieldByName("xi");
var imageField = fieldModule.createImage(xiField);
imageField.setName("sample_image");
var downloadManager = zincPlugin.createDownloadManager();
/* add in URIs for downloadManager to read files from.
In this case files from the local directories. Each item stores
a block of memory for each file. */
var new_str = name_series;
var i = 0;
var numberOfItems = 0;
var itemsArray = new Array();
for (i = start; i <= end; i++)
{
new_str = new_str.replace("XXX", i.toString());
itemsArray[numberOfItems] = downloadManager.addURI(new_str);
new_str = name_series;
numberOfItems++;
}
downloadManager.addCompletionCallback(
getImageReadyFunction(material, imageField, itemsArray, numberOfItems));
}
function createTextureMaterial(graphicsModule, textureItem, textureNumber, imageField)
{
var materialName = "textureMaterial"+textureNumber;
var texture_material = graphicsModule.findMaterialByName(materialName);
if (!texture_material)
{
texture_material = graphicsModule.createMaterial();
texture_material.setName(materialName);
texture_material.setAttributeReal3(texture_material.ATTRIBUTE.DIFFUSE, [1.0,1.0,1.0]);
texture_material.setAttributeReal3(texture_material.ATTRIBUTE.AMBIENT, [1.0,1.0,1.0]);
texture_material.setAttributeReal3(texture_material.ATTRIBUTE.SPECULAR, [1.0,1.0,1.0]);
}
var streamInformation = imageField.createStreamInformation();
streamInformation.createResourceDownloadItem(textureItem);
streamInformation.setFileFormat(streamInformation.FILE_FORMAT.PNG);
imageField.read(streamInformation);
texture_material.setImageField(1, imageField);
imageField.setImageAttributeReal(imageField.IMAGE_ATTRIBUTE.PHYSICAL_WIDTH_PIXELS, 1.0);
imageField.setImageAttributeReal(imageField.IMAGE_ATTRIBUTE.PHYSICAL_HEIGHT_PIXELS, 1.0);
imageField.setImageAttributeReal(imageField.IMAGE_ATTRIBUTE.PHYSICAL_DEPTH_PIXELS, 1.0);
return materialName;
}
function getDownloadsTextureReadyFunction(zincPluginIn, textureNumberIn, textureItemIn, textureNodeItemIn, textureElemItemIn)
{
var zincPlugin = zincPluginIn;
var textureNumber = textureNumberIn;
var textureNodeItem = textureNodeItemIn;
var textureElemItem = textureElemItemIn;
var textureItem = textureItemIn;
return function()
{
var rootRegion = zincPlugin.context.getDefaultRegion();
var regionName = "textureBlock"+textureNumber;
var texureRegion = rootRegion.createChild("textureBlock"+textureNumber);
var regionStreamInformation = texureRegion.createStreamInformation();
regionStreamInformation.createResourceDownloadItem(textureNodeItem);
regionStreamInformation.createResourceDownloadItem(textureElemItem);
texureRegion.read(regionStreamInformation);
if (texureRegion)
{
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
var fieldModule = texureRegion.getFieldModule();
var xiField = fieldModule.findFieldByName("xi");
var imageField = fieldModule.createImage(xiField);
imageField.setName("sample_image");
var materialName = createTextureMaterial(graphicsModule, textureItem, textureNumber, imageField);
var rendition = graphicsModule.getRendition(texureRegion);
rendition.beginChange();
rendition.executeCommand('cylinders constant_radius 0.3 select_on material green selected_material default_selected render_shaded');
rendition.executeCommand('surfaces texture xi select_on material '+materialName);
rendition.endChange();
textureRegions.push(texureRegion);
}
zincPlugin.sceneViewer.viewAll();
}
}
function drawTexture()
{
var zincPlugin = document.getElementById('zincplugin1');
if (zincPlugin)
{
//var baseURL = "ftp://ftp.bioeng.auckland.ac.nz/pub/ywan215/VisualisingDICOM/";
var baseURL = "ftp://ftp.bioeng.auckland.ac.nz/pub/ywan215/VisualisingDICOM_WithSegmentedData/";
var imageURL = "Image_PNG/SA_00X.png";
var textureBoxURL = "TextureBox_PatientCoor/tex_block_SA_X";
var i = 0;
var new_str = null;
for (i = 1; i < 10; i++)
{
var downloadManager = zincPlugin.createDownloadManager();
new_str = baseURL+imageURL;
new_str = new_str.replace("X", i.toString());
var textureItem = downloadManager.addURI(new_str);
console.log(new_str);
new_str = baseURL + textureBoxURL;
new_str = new_str.replace("X", i.toString());
var textureNodeItem = downloadManager.addURI(new_str+".exnode");
console.log(new_str+".exnode");
var textureElemItem = downloadManager.addURI(new_str+".exelem");
downloadManager.addCompletionCallback(
getDownloadsTextureReadyFunction(zincPlugin, i, textureItem, textureNodeItem, textureElemItem));
}
}
}
function removeTextures()
{
var zincPlugin = document.getElementById('zincplugin1');
var rootRegion = zincPlugin.context.getDefaultRegion();
var i = 0;
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
for (i = 0; i < textureRegions.length; i++)
{
var rendition = graphicsModule.getRendition(textureRegions[i]);
rendition.beginChange();
rendition.executeCommand('cylinders constant_radius 0.3 select_on render_shaded invisible');
rendition.executeCommand('surfaces invisible texture xi select_on ');
rendition.endChange();
}
textureRegions = new Array();
}
function drawPointWithSurfaceData(regionName, materialName, dataArray)
{
var zincPlugin = document.getElementById('zincplugin1');
var downloadManager = zincPlugin.createDownloadManager();
var rootRegion = zincPlugin.context.getDefaultRegion();
var region = rootRegion.createChild(regionName);
var fieldModule = region.getFieldModule();
fieldModule.beginChange();
var coordinatesField = fieldModule.createFiniteElement(3);
coordinatesField.setName("coordinates");
coordinatesField.setAttributeInteger(coordinatesField.ATTRIBUTE.IS_COORDINATE, 1);
coordinatesField.setAttributeInteger(coordinatesField.ATTRIBUTE.IS_MANAGED, 1);
var nodeset = fieldModule.findNodesetByName("cmiss_nodes");
var nodeTemplate1 = nodeset.createNodeTemplate();
nodeTemplate1.defineField(coordinatesField);
var node_coordinates = [ 0, 0, 0 ];
var fieldCache = fieldModule.createCache();
var i = 0;
var node;
var size = dataArray.length;
for (i=0; i<size; i++)
{
node_coordinates[0] = dataArray[i][0];
node_coordinates[1] = dataArray[i][1];
node_coordinates[2] = dataArray[i][2];
node = nodeset.createNode(i+1, nodeTemplate1);
fieldCache.setNode(node);
coordinatesField.assignReal(fieldCache, /*number_of_values*/3, node_coordinates);
node = null;
}
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
if (region)
{
var rendition = graphicsModule.getRendition(region);
rendition.beginChange();
rendition.executeCommand('node_points glyph sphere general size "1*1*1" centre 0,0,0 select_on material ' + materialName);
rendition.endChange();
}
zincPlugin.sceneViewer.viewAll();
}
function getDownloadsFirstPointReadyFunction(zincPluginIn, BTEndoItemIn, BTEpiItemIn)
{
var zincPlugin = zincPluginIn;
var BTEndoItem = BTEndoItemIn;
var BTEpiItem = BTEpiItemIn;
return function()
{
var rootRegion = zincPlugin.context.getDefaultRegion();
var BT_epi_region = rootRegion.createChild("firstBT_epi");
var BT_endo_region = rootRegion.createChild("firstBT_endo");
var BTepistreamInformation = BT_epi_region.createStreamInformation();
BTepistreamInformation.createResourceDownloadItem(BTEpiItem);
BT_epi_region.read(BTepistreamInformation);
var BTendostreamInformation = BT_endo_region.createStreamInformation();
BTendostreamInformation.createResourceDownloadItem(BTEndoItem);
BT_endo_region.read(BTendostreamInformation);
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
if (BT_epi_region)
{
var rendition = graphicsModule.getRendition(BT_epi_region);
rendition.beginChange();
rendition.executeCommand('node_points glyph sphere general size "1*1*1" centre 0,0,0 select_on material blue');
rendition.endChange();
}
if (BT_endo_region)
{
var rendition = graphicsModule.getRendition(BT_endo_region);
rendition.beginChange();
rendition.executeCommand('node_points glyph sphere general size "1*1*1" centre 0,0,0 select_on material gold');
rendition.endChange();
}
ShowHide('now_loading_text');
ShowHide('next_button');
}
}
function drawFirstPoints()
{
var zincPlugin = document.getElementById('zincplugin1');
var downloadManager = zincPlugin.createDownloadManager();
//removeTextures();
var BackTransformedUPFFinalRotated_EndoItem = downloadManager.addURI("ftp://ftp.bioeng.auckland.ac.nz/pub/ywan215/VisualisingDICOM_WithSegmentedData/SC-N-02_ds_lvendo.exdata");
var BackTransformedUPFFinalRotated_EpiItem = downloadManager.addURI("ftp://ftp.bioeng.auckland.ac.nz/pub/ywan215/VisualisingDICOM_WithSegmentedData/SC-N-02_ds_lvepi.exdata");
downloadManager.addCompletionCallback(
getDownloadsFirstPointReadyFunction(zincPlugin, BackTransformedUPFFinalRotated_EndoItem,BackTransformedUPFFinalRotated_EpiItem));
}
function upfVTPToExdata(regionName, materialName, upfVtpString)
{
var surface_data=new Array();
var lines = upfVtpString.split("\n");
var i = 0;
var cont = 1;
var setData = 0;
for (i = 0; (i <lines.length && cont == 1); i ++)
{
var tempString = lines[i];
if (lines[i].search("POLYGONS") != -1)
{
cont = 0;
}
if (setData == 1 && cont == 1)
{
var line_data = lines[i].split(" ");
var j = 0;
var myArray = [0.0, 0.0, 0.0];
for (j = 0; (j < line_data.length -1 );)
{
myArray[0] = parseFloat(line_data[j]);
j++;
myArray[1] = parseFloat(line_data[j]);
j++;
myArray[2] = parseFloat(line_data[j]);
j++;
surface_data.push(myArray);
}
}
if (lines[i].search("POINTS") != -1)
{
setData = 1;
}
}
drawPointWithSurfaceData(regionName, materialName, surface_data);
}
function triggerDrawPointService()
{
$.ajax({
type: "GET",
url: "file:///E:/work/Ricordo/RICORDO-Demo-04-2012/fitted-javascript-endo.vtk",
dataType: "text",
success: function(myFile)
{
upfVTPToExdata("BT_endo", "gold", myFile);
},
error: function(x,y,z)
{
alert("error" + "ready state: " + x.readyState + x.statusText);
}
});
$.ajax({
type: "GET",
url: "file:///E:/work/Ricordo/RICORDO-Demo-04-2012/fitted-javascript-epi.vtk",
dataType: "text",
success: function(mySecondFile)
{
upfVTPToExdata("BT_epi", "blue", mySecondFile);
},
error: function(x,y,z)
{
alert("error" + "ready state: " + x.readyState + x.statusText);
}
});
}
function CallCardiacFitting_callBack(r, soapResponse)
{
if(r.length + "" == "undefined")
{
alert("Error: " + r.message + "\n" + r.fileName);
}
else
{
//triggerDrawPointService();
drawFirstPoints();
}
}
function CallCardiacFitting()
{
var parameters = new SOAPClientParameters();
parameters.add("inputMesh", "/home/ubuntu/webservice-data/init-javascript.vtk");
parameters.add("inputImage", "/home/ubuntu/SC-HF-I-01-VTK/ST07.vtk");
parameters.add("outputMesh", "/home/ubuntu/webservice-data/fitted-javascript.vtk");
parameters.add("outputMeshEpi", "/home/ubuntu/webservice-data/fitted-javascript-epi.vtk");
parameters.add("outputMeshEndo", "/home/ubuntu/webservice-data/fitted-javascript-endo.vtk");
SOAPClient.invoke(wsGimiasURL, "Cardiac_Fitting", parameters, true, CallCardiacFitting_callBack);
}
function CallCardiacInitialization_callBack(r, soapResponse)
{
if(r.length + "" != "undefined")
{
CallCardiacFitting();
}
else
{
alert("Error");
}
}
function CallCardiacInitialization()
{
ShowHide('now_loading_text');
ShowHide('next_button');
var parameters = new SOAPClientParameters();
var selector = document.getElementById('mySelect');
parameters.add("cardiacModel", cardiacModelNames[selector.value - 1]);
parameters.add("landmarks", document.getElementById('initialization_landmarks').value);
parameters.add("outputMeshName", "/home/ubuntu/webservice-data/init-javascript.vtk");
SOAPClient.invoke(wsGimiasURL, "Cardiac_Initialization", parameters, true, CallCardiacInitialization_callBack);
}
function getDownloadsUnfittedModelReadyFunction(zincPluginIn, LVEndoElementItemIn, LVEndoNodeItemIn)
{
var zincPlugin = zincPluginIn;
var LVEndoElementItem = LVEndoElementItemIn;
var LVEndoNodeItem = LVEndoNodeItemIn;
return function()
{
var rootRegion = zincPlugin.context.getDefaultRegion();
var LV_region = rootRegion.createChild("LV");
var LVstreamInformation = LV_region.createStreamInformation();
LVstreamInformation.createResourceDownloadItem(LVEndoElementItem);
LVstreamInformation.createResourceDownloadItem(LVEndoNodeItem);
LV_region.read(LVstreamInformation);
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
if (LV_region)
{
var rendition = graphicsModule.getRendition(LV_region);
rendition.beginChange();
rendition.executeCommand('general clear circle_discretization 48 default_coordinate coordinates element_discretization "12*12*12" native_discretization none');
rendition.executeCommand('node_points glyph sphere general size "2*2*2" centre 0,0,0 select_on material default');
rendition.executeCommand('cylinders constant_radius 0.2 material default');
rendition.executeCommand('surfaces select_on material muscle');
rendition.endChange();
}
}
}
function drawUnfittedModel()
{
var zincPlugin = document.getElementById('zincplugin1');
var downloadManager = zincPlugin.createDownloadManager();
var LVCanineModel_Transformed_EndoTransElementItem = downloadManager.addURI(filename5);
var LVCanineModel_Transformed_EndoTransNodeItem = downloadManager.addURI(filename6);
downloadManager.addCompletionCallback(
getDownloadsUnfittedModelReadyFunction(zincPlugin,
LVCanineModel_Transformed_EndoTransElementItem, LVCanineModel_Transformed_EndoTransNodeItem));
}
function getDownloadsPointsReadyFunction(zincPluginIn, BTEndoItemIn, BTEpiItemIn)
{
var zincPlugin = zincPluginIn;
var BTEndoItem = BTEndoItemIn;
var BTEpiItem = BTEpiItemIn;
return function()
{
var rootRegion = zincPlugin.context.getDefaultRegion();
var BT_epi_region = rootRegion.createChild("BT_epi");
var BT_endo_region = rootRegion.createChild("BT_endo");
var BTepistreamInformation = BT_epi_region.createStreamInformation();
BTepistreamInformation.createResourceDownloadItem(BTEpiItem);
BT_epi_region.read(BTepistreamInformation);
var BTendostreamInformation = BT_endo_region.createStreamInformation();
BTendostreamInformation.createResourceDownloadItem(BTEndoItem);
BT_endo_region.read(BTendostreamInformation);
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
if (BT_epi_region)
{
var rendition = graphicsModule.getRendition(BT_epi_region);
rendition.beginChange();
rendition.executeCommand('node_points glyph sphere general size "1*1*1" centre 0,0,0 select_on material blue');
rendition.endChange();
}
if (BT_endo_region)
{
var rendition = graphicsModule.getRendition(BT_endo_region);
rendition.beginChange();
rendition.executeCommand('node_points glyph sphere general size "1*1*1" centre 0,0,0 select_on material gold');
rendition.endChange();
}
zincPlugin.sceneViewer.viewAll();
}
}
function drawPoints()
{
var zincPlugin = document.getElementById('zincplugin1');
var downloadManager = zincPlugin.createDownloadManager();
var BackTransformedUPFFinalRotated_EndoItem = downloadManager.addURI(filename1);
var BackTransformedUPFFinalRotated_EpiItem = downloadManager.addURI(filename2);
downloadManager.addCompletionCallback(
getDownloadsPointsReadyFunction(zincPlugin, BackTransformedUPFFinalRotated_EndoItem,BackTransformedUPFFinalRotated_EpiItem));
}
function removeFirstPoints()
{
var zincPlugin = document.getElementById('zincplugin1');
var rootRegion = zincPlugin.context.getDefaultRegion();
var BT_epi_region = rootRegion.findSubregionAtPath("firstBT_epi");
var BT_endo_region = rootRegion.findSubregionAtPath("firstBT_endo");
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
if (BT_epi_region)
{
var rendition = graphicsModule.getRendition(BT_epi_region);
rendition.removeAllGraphics();
}
if (BT_endo_region)
{
var rendition = graphicsModule.getRendition(BT_endo_region);
rendition.removeAllGraphics();
}
}
function callCardiofitService()
{
var values = new Array();
var proxy = "http://130.216.208.77";
$.ajax
({
type: "POST",
url: "http://130.216.208.77/cardiofitter/default/fitting",
data: { 'mesh.name': "patient_1",
'epi.ds': "http://130.216.208.77:8380/pmr/w/tommy/sc-n-02/rawfile/2ca1558b76ec38e56cdd6a1d661447e0590f5e06/ph11_epi_DS.vtp",
'epi.ed': "http://130.216.208.77:8380/pmr/w/tommy/sc-n-02/rawfile/2ca1558b76ec38e56cdd6a1d661447e0590f5e06/ph07_epi_ES.vtp",
'epi.es': "http://130.216.208.77:8380/pmr/w/tommy/sc-n-02/rawfile/2ca1558b76ec38e56cdd6a1d661447e0590f5e06/ph19_epi_ED.vtp",
'endo.ds': "http://130.216.208.77:8380/pmr/w/tommy/sc-n-02/rawfile/2ca1558b76ec38e56cdd6a1d661447e0590f5e06/ph11_endo_DS.vtp",
'endo.ed': "http://130.216.208.77:8380/pmr/w/tommy/sc-n-02/rawfile/2ca1558b76ec38e56cdd6a1d661447e0590f5e06/ph07_endo_ES.vtp",
'endo.es': "http://130.216.208.77:8380/pmr/w/tommy/sc-n-02/rawfile/2ca1558b76ec38e56cdd6a1d661447e0590f5e06/ph19_endo_ED.vtp" },
dataType: "json",
success: function(data)
{
var fileroot = data['fileroot'];
var files = data['files'];
filename1 = proxy + fileroot + "/DS/"+ files['DS'][0];
filename2 = proxy + fileroot + "/DS/"+ files['DS'][1];
filename3 = proxy + fileroot + "/DS/"+ files['DS'][2];
filename4 = proxy + fileroot + "/DS/"+ files['DS'][3];
filename5 = proxy + fileroot + "/DS/"+ files['DS'][4];
filename6 = proxy + fileroot + "/DS/"+ files['DS'][5];
removeFirstPoints();
removeTextures();
drawPoints();
drawUnfittedModel();
},
error: function(x,y,z)
{
alert("error" + "ready state: " + x.readyState + x.statusText);
}
});
}
function triggerDrawUnfittedModel()
{
callCardiofitService();
}
function getDownloadsFittedModelReadyFunction(zincPluginIn, fittedElementItemIn, fittedNodeItemIn)
{
var zincPlugin = zincPluginIn;
var fittedElementItem = fittedElementItemIn;
var fittedNodeItem = fittedNodeItemIn;
return function()
{
var rootRegion = zincPlugin.context.getDefaultRegion();
var fitted_region = rootRegion.createChild("fitted");
var fittedstreamInformation = fitted_region.createStreamInformation();
fittedstreamInformation.createResourceDownloadItem(fittedElementItem);
fittedstreamInformation.createResourceDownloadItem(fittedNodeItem);
fitted_region.read(fittedstreamInformation);
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
if (fitted_region)
{
var rendition = graphicsModule.getRendition(fitted_region);
rendition.beginChange();
rendition.executeCommand('general clear circle_discretization 48 default_coordinate coordinates element_discretization "12*12*12" native_discretization none');
rendition.executeCommand('node_points glyph sphere general size "2*2*2" centre 0,0,0 select_on material default');
rendition.executeCommand('cylinders constant_radius 0.2 material green');
rendition.executeCommand('surfaces select_on material green');
rendition.endChange();
}
}
}
function removeUnfittedModel()
{
var zincPlugin = document.getElementById('zincplugin1');
var rootRegion = zincPlugin.context.getDefaultRegion();
var LV_region = rootRegion.findSubregionAtPath("LV");
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
if (LV_region)
{
var rendition = graphicsModule.getRendition(LV_region);
rendition.removeAllGraphics();
}
}
function drawFittedModel()
{
var zincPlugin = document.getElementById('zincplugin1');
var downloadManager = zincPlugin.createDownloadManager();
removeUnfittedModel();
var fitted_epi_humanLVElementItem = downloadManager.addURI(filename3);
var fitted_epi_humanLVNodeItem = downloadManager.addURI(filename4);
downloadManager.addCompletionCallback(
getDownloadsFittedModelReadyFunction(zincPlugin, fitted_epi_humanLVElementItem, fitted_epi_humanLVNodeItem));
}
function visualiseProteinConcentration(zincPlugin, region)
{
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
var rendition = graphicsModule.getRendition(region);
rendition.executeCommand('node_points glyph sphere general size "3*3*3" centre 0,0,0 select_on material default data concentration spectrum default');
var spectrum = graphicsModule.findSpectrumByName("default");
spectrum.executeCommand("autorange");
ShowHide('click_next_to_see_density_text');
ShowHide('next_button');
}
function removeAllProteinGraphics()
{
var zincPlugin = document.getElementById('zincplugin1');
var rootRegion = zincPlugin.context.getDefaultRegion();
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
var i = 0;
for (i = 1; i < proteinNames.length; i++)
{
var region = rootRegion.findSubregionAtPath(proteinNames[i]);
if (region)
{
var rendition = graphicsModule.getRendition(region);
rendition.removeAllGraphics();
}
}
}
function createAndDrawProteinConcentration(region, dataArray)
{
var zincPlugin = document.getElementById('zincplugin1');
var rootRegion = zincPlugin.context.getDefaultRegion();
if (region)
{
var fieldModule = region.getFieldModule();
fieldModule.beginChange();
var coordinatesField = fieldModule.createFiniteElement(3);
coordinatesField.setName("coordinates");
coordinatesField.setAttributeInteger(coordinatesField.ATTRIBUTE.IS_COORDINATE, 1);
coordinatesField.setAttributeInteger(coordinatesField.ATTRIBUTE.IS_MANAGED, 1);
var concentrationField = fieldModule.createFiniteElement(1);
concentrationField.setName("concentration");
concentrationField.setAttributeInteger(coordinatesField.ATTRIBUTE.IS_COORDINATE, 0);
concentrationField.setAttributeInteger(coordinatesField.ATTRIBUTE.IS_MANAGED, 1);
var nodeset = fieldModule.findNodesetByName("cmiss_nodes");
var nodeTemplate1 = nodeset.createNodeTemplate();
nodeTemplate1.defineField(coordinatesField);
nodeTemplate1.defineField(concentrationField);
var node_coordinates = [ 0, 0, 0 ];
var concentrationValue = new Array();
var fieldCache = fieldModule.createCache();
var i = 0;
var node;
var size = dataArray.length;
for (i=0; i<size; i++)
{
node_coordinates[0] = dataArray[i][0];
node_coordinates[1] = dataArray[i][1];
node_coordinates[2] = dataArray[i][2];
concentrationValue[0] = dataArray[i][3];
node = nodeset.createNode(i+1, nodeTemplate1);
fieldCache.setNode(node);
coordinatesField.assignReal(fieldCache, /*number_of_values*/3, node_coordinates);
concentrationField.assignReal(fieldCache, /*number_of_values*/1, concentrationValue);
node = null;
}
}
}
function getFromWebServiceJSONToArray(proteinName)
{
var zincPlugin = document.getElementById('zincplugin1');
var rootRegion = zincPlugin.context.getDefaultRegion();
var region = rootRegion.findSubregionAtPath(proteinName);
if (region == null)
{
var values = new Array();
ShowHide('now_loading_text');
$.ajax({
type: "GET",
url: "http://lxbisel.macs.hw.ac.uk:8080/ricordo/getProteinDistribution/"+proteinName,
dataType: "json",
success: function(data)
{
$.each(data[proteinName], function(key, val)
{
values.push([parseFloat(val['x']), parseFloat(val['y']),parseFloat(val['z']),parseFloat(val['value'])]);
});
ShowHide('now_loading_text');
region = rootRegion.createChild(proteinName);
createAndDrawProteinConcentration(region, values);
removeAllProteinGraphics();
visualiseProteinConcentration(zincPlugin, region);
},
error: function(x,y,z)
{
alert("error" + "ready state: " + x.readyState + x.statusText);
}
});
}
else
{
removeAllProteinGraphics();
visualiseProteinConcentration(zincPlugin, region);
}
}
function removeDataPoint()
{
var zincPlugin = document.getElementById('zincplugin1');
var rootRegion = zincPlugin.context.getDefaultRegion();
var BT_epi_region = rootRegion.findSubregionAtPath("BT_epi");
var BT_endo_region = rootRegion.findSubregionAtPath("BT_endo");
var graphicsModule = zincPlugin.context.getDefaultGraphicsModule();
if (BT_epi_region)
{
var rendition = graphicsModule.getRendition(BT_epi_region);
rendition.removeAllGraphics();
}
if (BT_endo_region)
{
var rendition = graphicsModule.getRendition(BT_endo_region);
rendition.removeAllGraphics();
}
}
function displayConcentration()
{
removeDataPoint();
var selector = document.getElementById('proteinSelector');
if (selector.value != 1 && selector.value <=4)
{
getFromWebServiceJSONToArray(proteinNames[selector.value - 1]);
}
}
/* This function is called when the primary scene is constructed and read */
function sceneViewerReadyFunction()
{
var zincPlugin = document.getElementById('zincplugin1');
zincPlugin.sceneViewer.setBackgroundColourRGB(1.0, 1.0, 1.0);
ZN_OK = zincPlugin.OK;
zincPlugin.context.getDefaultGraphicsModule().defineStandardMaterials();
}
function next()
{
if (stage == 0)
{
drawTexture();
ShowHide('patient_text');
ShowHide('radio');
ShowHide('select_patient_text');
ShowHide('select_segmentation_text');
ShowHide('initialization_landmarks_textbox');
ShowHide('mySelect');
}
if (stage == 1)
{
ShowHide('select_segmentation_text');
ShowHide('initialization_landmarks_textbox');
ShowHide('mySelect');
CallCardiacInitialization();
}
if (stage == 2)
{
triggerDrawUnfittedModel();
ShowHide('next_to_fit_mesh_text');
}
if (stage == 3)
{
drawFittedModel();
ShowHide('next_to_fit_mesh_text');
ShowHide('proteinSelector_panel');
ShowHide('click_next_to_see_density_text');
}
if (stage >= 4)
{
displayConcentration();
ShowHide('click_next_to_see_density_text');
ShowHide('next_button');
}
stage++;
}