forked from Tevemadar/QuickNII
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MgmtPanel.mxml
673 lines (613 loc) · 23.8 KB
/
MgmtPanel.mxml
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
<?xml version="1.0" encoding="utf-8"?>
<mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%" title="{titl}"
creationComplete="titlewindow1_activateHandler(event)" xmlns:containers="flexlib.mdi.containers.*" xmlns:local="*"
showStatusBar="false">
<mx:Script>
<![CDATA[
import flexlib.mdi.events.MDIWindowEvent;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.CloseEvent;
import mx.events.CollectionEvent;
import mx.events.DataGridEvent;
import mx.events.ListEvent;
import mx.events.ResizeEvent;
[Bindable] static public var titl:String="Empty";
static protected var xmltitl:String;
static protected var first:int;
static protected var last:int;
[Bindable] public static var rows:ArrayCollection=new ArrayCollection;
[Bindable] public static var currentidx:int=-1;
public static var baseurl:String;
private static var baseJson:Object=null;
[Bindable] public static var main:QuickNII;
public static var requestString:Vector.<Number>; //!!
protected function titlewindow1_activateHandler(event:Event):void {
serieswindow.height=chartwindow.height=height-55;
chartwindow.width=width-chartwindow.x;
stuff.selectedIndex=currentidx;
interpolate();
}
protected function button1_clickHandler(event:MouseEvent):void {
const f:File=new File;
f.addEventListener(Event.SELECT,descriptorSelected);
f.browseForOpen("Series",[new FileFilter("QuickNII Series", "*.xml;*json")]);
}
protected function descriptorSelected(e:Event):void {
stuff.selectedIndex=-1;
rows.removeAll();
baseJson=null;
const f:File=e.target as File;
baseurl=f.parent.url;
const fs:FileStream=new FileStream;
fs.open(f,FileMode.READ);
var text:String=fs.readUTFBytes(fs.bytesAvailable);
fs.close();
switch(f.extension) {
case "xml":
const xml:XML=XML(text);
titl=xmltitl=xml.@name;
for each(var slice:XML in xml.slice) {
var anchorstring:String=slice.@anchoring;
var anchoring:Vector.<Number>=null;
if(anchorstring!=null && anchorstring!="") {
const urlvar:URLVariables=new URLVariables(anchorstring.replace(/&/g,"&"));
anchoring=new <Number>[
parseFloat(urlvar.ox),parseFloat(urlvar.oy),parseFloat(urlvar.oz),
parseFloat(urlvar.ux),parseFloat(urlvar.uy),parseFloat(urlvar.uz),
parseFloat(urlvar.vx),parseFloat(urlvar.vy),parseFloat(urlvar.vz)];
}
rows.addItem(new SliceData(slice.@filename,slice.@nr,slice.@width,slice.@height,anchoring));
}
break;
case "json":
baseJson=JSONp.parse(text);
titl=xmltitl=baseJson.name;
var slices:Array=baseJson.slices as Array;
for(var i:int=0;i<slices.length;i++) {
var o:Object=slices[i];
anchoring=null;
if(o.hasOwnProperty("anchoring")) {
var a:Array=o.anchoring as Array;
anchoring=new Vector.<Number>(a);//!!
}
rows.addItem(new SliceData(o.filename,o.nr,o.width,o.height,anchoring));
}
break;
default:
Alert.show("Unknown file: "+f.extension);
return;
}
first=rows.getItemAt(0).sno;
last=rows.getItemAt(rows.length-1).sno;
interpolate();
}
public static function interpolate():void {
dointerpolate();
updategraphdata();
rows.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
}
private static function dointerpolate():void {
if(rows.length==0)return; // nothing to set
var i:int,j:int;
const anchorings:Vector.<int>=new Vector.<int>;
var regressions:Vector.<LinReg>=new Vector.<LinReg>;
for(i=0;i<11;i++)regressions.push(new LinReg);
var w:SliceData;
var ww:SliceData;
var sno:int;
for(i=0;i<rows.length;i++) {
w=rows.getItemAt(i) as SliceData;
if(w.hasanchoring) {
anchorings.push(i);
for(j=0;j<11;j++)
regressions[j].add(w.sno,w.unpacked[j]);
}
}
const control:Vector.<int>=new Vector.<int>;
if(anchorings.length==0) {
var maxw:Number=0;
var maxh:Number=0;
for(i=0;i<rows.length;i++) {
w=rows.getItemAt(i) as SliceData;
if(maxw<w.width)maxw=w.width;
if(maxh<w.height)maxh=w.height;
}
switch(main.valbox.decompcfg.selectedLabel) {
case "Coronal":
w=rows.getItemAt(0) as SliceData;
w.setUnpacked(new <Number>[main.xdim/1,main.ydim-1,main.zdim/2,1,0,0,0,0,-1,main.xdim/maxw,main.zdim/maxh]);
control.push(0);
w=rows.getItemAt(rows.length-1) as SliceData;
w.setUnpacked(new <Number>[main.xdim/1,0,main.zdim/2,1,0,0,0,0,-1,main.xdim/maxw,main.zdim/maxh]);
control.push(rows.length-1);
break;
case "Sagittal":
w=rows.getItemAt(0) as SliceData;
w.setUnpacked(new <Number>[main.xdim-1,main.ydim/2,main.zdim/2,0,-1,0,0,0,1,main.ydim/maxw,main.zdim/maxh]);
control.push(0);
w=rows.getItemAt(rows.length-1) as SliceData;
w.setUnpacked(new <Number>[0,main.ydim/2,main.zdim/2,0,-1,0,0,0,1,main.ydim/maxw,main.zdim/maxh]);
control.push(rows.length-1);
break;
case "Horizontal":
w=rows.getItemAt(0) as SliceData;
w.setUnpacked(new <Number>[main.xdim/2,main.ydim/2,main.zdim-1,0,-1,0,1,0,0,main.ydim/maxw,main.xdim/maxh]);
control.push(0);
w=rows.getItemAt(rows.length-1) as SliceData;
w.setUnpacked(new <Number>[main.xdim/2,main.ydim/2,0,0,-1,0,1,0,0,main.ydim/maxw,main.xdim/maxh]);
control.push(rows.length-1);
break;
}
}
else if(anchorings.length==1) {
i=anchorings[0];
ww=rows.getItemAt(i) as SliceData;
if(i!=0) {
w=rows.getItemAt(0) as SliceData;
var anchoring:Vector.<Number>=new <Number>[
main.valbox.decompcfg.selectedLabel=="Sagittal"?main.xdim-1:ww._mx,
main.valbox.decompcfg.selectedLabel=="Coronal"?main.ydim-1:ww._my,
main.valbox.decompcfg.selectedLabel=="Horizontal"?main.zdim-1:ww._mz];
for(j=3;j<11;j++)
anchoring.push(ww.unpacked[j]);
w.setUnpacked(anchoring);
control.push(0);
}
control.push(i);
if(i!=rows.length-1) {
w=rows.getItemAt(rows.length-1) as SliceData;
anchoring=new <Number>[
main.valbox.decompcfg.selectedLabel=="Sagittal"?0:ww._mx,
main.valbox.decompcfg.selectedLabel=="Coronal"?0:ww._my,
main.valbox.decompcfg.selectedLabel=="Horizontal"?0:ww._mz];
for(j=3;j<11;j++)
anchoring.push(ww.unpacked[j]);
w.setUnpacked(anchoring);
control.push(rows.length-1);
}
} else {
if(anchorings[0]!=0) {
w=rows.getItemAt(0) as SliceData;
anchoring=new Vector.<Number>;
for(j=0;j<11;j++)
anchoring.push(regressions[j].get(w.sno));
w.setUnpacked(anchoring);
control.push(0);
}
for(i=0;i<anchorings.length;i++)
control.push(anchorings[i]);
if(anchorings[anchorings.length-1]!=rows.length-1) {
w=rows.getItemAt(rows.length-1) as SliceData;
anchoring=new Vector.<Number>;
for(j=0;j<11;j++)
anchoring.push(regressions[j].get(w.sno));
w.setUnpacked(anchoring);
control.push(rows.length-1);
}
}
if(anchorings.length==rows.length)return; // not mandatory
for(i=0;i<control.length-1;i++) {
var i1:int=control[i];
var w1:SliceData=rows.getItemAt(i1) as SliceData;
var i2:int=control[i+1];
var w2:SliceData=rows.getItemAt(i2) as SliceData;
var linints:Vector.<LinSegment>=new Vector.<LinSegment>;
for(var k:int=0;k<11;k++)
linints.push(new LinSegment(w1.sno,w1.unpacked[k],w2.sno,w2.unpacked[k]));
for(j=i1+1;j<i2;j++) {
w=rows.getItemAt(j) as SliceData;
anchoring=new Vector.<Number>;
for(k=0;k<11;k++)
anchoring.push(linints[k].get(w.sno));
w.setUnpacked(anchoring);
}
}
}
protected function stuff_itemDoubleClickHandler(event:ListEvent):void {
currentidx=event.rowIndex;
const w:SliceData=rows.getItemAt(currentidx) as SliceData;
w.pack();
main.setImage(baseurl+File.separator+w.filename,w.packed);
main.activate();
titl=xmltitl;
}
public static function mystic_update():void {
if(currentidx<0)return;
const w:SliceData=rows.getItemAt(currentidx) as SliceData;
w.pack();
//!!requeststring=w.anchoring;
main.Restore();
}
protected function button3_clickHandler(event:MouseEvent):void {
const f:File=new File;
f.addEventListener(Event.SELECT,saveSelected);
f.browseForSave("Series");
}
protected function saveSelected(e:Event):void {
const f:File=e.target as File;
var url:String=f.url;
if(url.substr(url.length-4)==".xml")
save(f);
else{
url+=".xml";
save(new File(url));
}
}
public static function save(f:File):void {
const fs:FileStream=new FileStream;
fs.open(f,FileMode.WRITE);
fs.writeUTFBytes("<?xml version='1.0' encoding='UTF-8'?>\r\n");
fs.writeUTFBytes("<series name='"+xmltitl+"' target='"+main.pack+"' target-resolution='"+main.xdim+" "+main.ydim+" "+main.zdim+"'>\r\n");
for(var i:int=0;i<rows.length;i++) {
var l:SliceData=rows.getItemAt(i) as SliceData;
fs.writeUTFBytes(" <slice filename='"+l.filename+"' nr='"+l.sno+"' width='"+l.width+"' height='"+l.height);
if(l.hasanchoring) {
var a:Vector.<Number>=l.pack();
var prefixes:Array=["' anchoring='ox=","&oy=","&oz=","&ux=","&uy=","&uz=","&vx=","&vy=","&vz="];
for(var j:int=0;j<9;j++)
fs.writeUTFBytes(prefixes[j]+a[j]);
}
fs.writeUTFBytes("'/>\r\n");
}
fs.writeUTFBytes("</series>\r\n");
fs.close();
}
protected function jsonSave():void {
const f:File=new File;
f.addEventListener(Event.SELECT,jsonSaveSelected);
f.browseForSave("Series");
}
protected function jsonSaveSelected(e:Event):void {
const f:File=e.target as File;
var url:String=f.url;
if(url.substr(url.length-5)==".json")
saveJson(f);
else {
url+=".json";
saveJson(new File(url));
}
}
protected function saveJson(f:File):void {
if(baseJson==null) {
baseJson=new Object;
baseJson.name=xmltitl;
baseJson.target=main.pack;
baseJson["target-resolution"]=[main.xdim,main.ydim,main.zdim];
var slices:Array=[];
for(var i:int=0;i<rows.length;i++) {
var l:SliceData=rows.getItemAt(i) as SliceData;
var o:Object=new Object;
o.filename=l.filename;
o.nr=l.sno;
o.width=l.width;
o.height=l.height;
slices.push(o);
}
baseJson.slices=slices;
}
slices=baseJson.slices;
for(i=0;i<rows.length;i++) {
l=rows.getItemAt(i) as SliceData;
if(l.hasanchoring)slices[i].anchoring=l.pack();
else delete slices[i].anchoring;
}
const fs:FileStream=new FileStream;
fs.open(f,FileMode.WRITE);
fs.writeUTFBytes(JSONp.stringify(baseJson));
fs.close();
}
[Bindable] static public var regressionestimator:ArrayCollection=new ArrayCollection;
[Bindable] static public var polylineestimator:ArrayCollection=new ArrayCollection;
public static function updategraphdata():void {
const hackedScale:Number=NamedTransformation.hackedScale;
regressionestimator.removeAll();
polylineestimator.removeAll();
if(rows.length==0)return;
if(rows.length<2)return;
const src:SliceData=rows.getItemAt(0) as SliceData;
const dst:SliceData=rows.getItemAt(rows.length-1) as SliceData;
const px:Number=src._mx;
const py:Number=src._my;
const pz:Number=src._mz;
const dx:Number=dst._mx-px;
const dy:Number=dst._my-py;
const dz:Number=dst._mz-pz;
const delta:Number=Math.sqrt(dx*dx+dy*dy+dz*dz);
var i:int;
var xspacing:LinReg=new LinReg;
var yspacing:LinReg=new LinReg;
var zspacing:LinReg=new LinReg;
var rot1:LinReg=new LinReg;
var rot2:LinReg=new LinReg;
var rot3:LinReg=new LinReg;
var prevanch:SliceData=null;
for(i=0;i<rows.length;i++) {
var l:SliceData=rows.getItemAt(i) as SliceData;
var uvx:Number=l._uy*l._vz-l._uz*l._vy;
var uvy:Number=l._uz*l._vx-l._ux*l._vz;
var uvz:Number=l._ux*l._vy-l._uy*l._vx;
var oxpxwx:Number=(l._mx-px)*uvx;
var oypywy:Number=(l._my-py)*uvy;
var ozpzwz:Number=(l._mz-pz)*uvz;
var dxwx:Number=dx*uvx;
var dywy:Number=dy*uvy;
var dzwz:Number=dz*uvz;
var custom:Number=(oxpxwx+oypywy+ozpzwz)/(dxwx+dywy+dzwz);
if(l.hasanchoring) {
if(prevanch!=null) {
xspacing.add((l.sno+prevanch.sno)/2,(l._mx-prevanch._mx)/(l.sno-prevanch.sno));
yspacing.add((l.sno+prevanch.sno)/2,(l._my-prevanch._my)/(l.sno-prevanch.sno));
zspacing.add((l.sno+prevanch.sno)/2,(l._mz-prevanch._mz)/(l.sno-prevanch.sno));
}
prevanch=l;
}
var n:SliceData=i<rows.length-1?rows.getItemAt(i+1) as SliceData:null;
var xs:Number=n==null?Number.NaN:(n._mx-l._mx)/(n.sno-l.sno);
var ys:Number=n==null?Number.NaN:(n._my-l._my)/(n.sno-l.sno);
var zs:Number=n==null?Number.NaN:(n._mz-l._mz)/(n.sno-l.sno);
var u:Vector3D=new Vector3D(l._ux,l._uy,l._uz);
var v:Vector3D=new Vector3D(l._vx,l._vy,l._vz);
var nr:Vector3D=v.crossProduct(u);nr.normalize();
var o:Object=new Object;
o.sno=l.sno;
o.HStretch=l._urate;
o.VStretch=l._vrate;
if(main.valbox.decompcfg.selectedLabel=="Coronal") {
o.MainPosition=l._my;
o.MainSpacing=ys;
rot1.add(l.sno,o.Rotation1=Math.asin(nr.z)*180/Math.PI);
rot2.add(l.sno,o.Rotation2=-Math.atan2(nr.x,nr.y)*180/Math.PI);
if(Math.abs(nr.y)<0.00001)
rot3.add(l.sno,o.Rotation3=0);
else {
//!! works, but probably could be simpler
var ctx:Number=Math.sqrt(1/(1+nr.x*nr.x/nr.y/nr.y));
var ct:Vector3D=new Vector3D(ctx,-ctx*nr.x/nr.y);
var cdt:Number=-ct.dotProduct(u);
if(cdt<-1)cdt=-1;
if(cdt>1)cdt=1;
rot3.add(l.sno,o.Rotation3=(ct.crossProduct(u).dotProduct(nr)<0?1:-1)*Math.acos(cdt)*180/Math.PI);
}
o.HPosition=l._mx;
o.HSpacing=xs;
o.VPosition=l._mz;
o.VSpacing=zs;
} else if(main.valbox.decompcfg.selectedLabel=="Sagittal") {
o.MainPosition=l._mx;
o.MainSpacing=xs;
rot1.add(l.sno,o.Rotation1=-Math.asin(nr.z)*180/Math.PI);
rot2.add(l.sno,o.Rotation2=-Math.atan2(nr.y,-nr.x)*180/Math.PI);
if(Math.abs(nr.x)<0.00001)
rot3.add(l.sno,o.Rotation3=0);
else {
//!! works, but probably could be simpler
var sty:Number=Math.sqrt(1/(1+nr.y*nr.y/nr.x/nr.x));
var st:Vector3D=new Vector3D(-sty*nr.y/nr.x,sty);
var sdt:Number=-st.dotProduct(u);
if(sdt<-1)sdt=-1;
if(sdt>1)sdt=1;
rot3.add(l.sno,o.Rotation3=(st.crossProduct(u).dotProduct(nr)<0?1:-1)*Math.acos(sdt)*180/Math.PI);
}
o.HPosition=l._my;
o.HSpacing=ys;
o.VPosition=l._mz;
o.VSpacing=zs;
} else if(main.valbox.decompcfg.selectedLabel=="Horizontal") {
o.MainPosition=l._mz;
o.MainSpacing=zs;
rot1.add(l.sno,o.Rotation1=-Math.asin(nr.x)*180/Math.PI)
rot2.add(l.sno,o.Rotation2=-Math.atan2(nr.y,nr.z)*180/Math.PI);
if(Math.abs(nr.z)<0.00001)
rot3.add(l.sno,o.Rotation3=0);
else {
//!! works, but probably could be simpler
var hty:Number=Math.sqrt(1/(1+nr.y*nr.y/nr.z/nr.z));
var ht:Vector3D=new Vector3D(0,hty,-hty*nr.y/nr.z);
var hdt:Number=-ht.dotProduct(u);
if(hdt<-1)hdt=-1;
if(hdt>1)hdt=1;
rot3.add(l.sno,o.Rotation3=(ht.crossProduct(u).dotProduct(nr)<0?1:-1)*Math.acos(hdt)*180/Math.PI);
}
o.HPosition=l._my;
o.HSpacing=ys;
o.VPosition=l._mx;
o.VSpacing=xs;
}
else throw Error("!!!");
o.MainPosition*=hackedScale;
// o.MainSpacing*=hackedScale;
o.HPosition*=hackedScale;
// o.HSpacing*=hackedScale;
o.VPosition*=hackedScale;
// o.VSpacing*=hackedScale;
o.Position=custom*hackedScale*delta;
o.Spacing=Number.NaN;
if(i>0) {
var tmp:Object=polylineestimator.getItemAt(i-1);
tmp.Spacing=o.Position-tmp.Position;
}
polylineestimator.addItem(o);
}
const o1:Object=new Object;
const o2:Object=new Object;
const srctmp:Object=polylineestimator.getItemAt(0);
const dsttmp:Object=polylineestimator.getItemAt(polylineestimator.length-1);
o1.Position=srctmp.Position;
o2.Position=dsttmp.Position;
o1.Spacing=o2.Spacing=(o2.Position-o1.Position)/(polylineestimator.length);
o1.sno=first;
o1.HStretch=src._urate;
o1.VStretch=src._vrate;
o1.Rotation1=rot1.get(first);
o1.Rotation2=rot2.get(first);
o1.Rotation3=rot3.get(first);
o2.sno=last;
o2.HStretch=dst._urate;
o2.VStretch=dst._vrate;
o2.Rotation1=rot1.get(last);
o2.Rotation2=rot2.get(last);
o2.Rotation3=rot3.get(last);
if(main.valbox.decompcfg.selectedLabel=="Coronal") {
o1.MainPosition=src._my;
o1.MainSpacing=yspacing.get(first);
o1.HPosition=src._mx;
o1.HSpacing=xspacing.get(first);
o1.VPosition=src._mz;
o1.VSpacing=zspacing.get(first);
o2.MainPosition=dst._my;
o2.MainSpacing=yspacing.get(last);
o2.HPosition=dst._mx;
o2.HSpacing=xspacing.get(last);
o2.VPosition=dst._mz;
o2.VSpacing=zspacing.get(last);
} else if(main.valbox.decompcfg.selectedLabel=="Sagittal") {
o1.MainPosition=src._mx;
o1.MainSpacing=xspacing.get(first);
o1.HPosition=src._my;
o1.HSpacing=yspacing.get(first);
o1.VPosition=src._mz;
o1.VSpacing=zspacing.get(first);
o2.MainPosition=dst._mx;
o2.MainSpacing=yspacing.get(last);
o2.HPosition=dst._my;
o2.HSpacing=yspacing.get(last);
o2.VPosition=dst._mz;
o2.VSpacing=zspacing.get(last);
} else if(main.valbox.decompcfg.selectedLabel=="Horizontal") {
o1.MainPosition=src._mz;
o1.MainSpacing=zspacing.get(first);
o1.HPosition=src._my;
o1.HSpacing=yspacing.get(first);
o1.VPosition=src._mx;
o1.VSpacing=xspacing.get(first);
o2.MainPosition=dst._mz;
o2.MainSpacing=zspacing.get(last);
o2.HPosition=dst._my;
o2.HSpacing=yspacing.get(last);
o2.VPosition=dst._mx;
o2.VSpacing=xspacing.get(last);
}
o1.MainPosition*=hackedScale;
// o1.MainSpacing*=hackedScale;
o1.HPosition*=hackedScale;
// o1.HSpacing*=hackedScale;
o1.VPosition*=hackedScale;
// o1.VSpacing*=hackedScale;
o2.MainPosition*=hackedScale;
// o2.MainSpacing*=hackedScale;
o2.HPosition*=hackedScale;
// o2.HSpacing*=hackedScale;
o2.VPosition*=hackedScale;
// o2.VSpacing*=hackedScale;
regressionestimator.addItem(o1);
regressionestimator.addItem(o2);
}
protected function seriescanvas_resizeHandler(event:ResizeEvent):void {
slicesbtn.y=exportbtn.y=savebtn.y=jsonbtn.y=loadbtn.y=addchart.y=seriescanvas.height-savebtn.height-10;
stuff.height=savebtn.y-10-10;
}
protected function addchart_clickHandler(event:MouseEvent):void {
var w:MDIWindow=new MDIWindow;
w.title="Chart "+(MDImain.windowManager.windowList.length-2);
w.addChild(new SeriesChart);
MDImain.windowManager.add(w);
}
protected function exportbtn_clickHandler(event:MouseEvent):void {
const f:File=new File;
f.addEventListener(Event.SELECT,exportSelected);
f.browseForSave("Series");
}
protected function exportSelected(e:Event):void {
const f:File=e.target as File;
const fs:FileStream=new FileStream;
fs.open(f,FileMode.WRITE);
fs.writeUTFBytes("<?xml version='1.0' encoding='UTF-8'?>\r\n");
fs.writeUTFBytes("<series name='"+xmltitl+"' target='"+main.pack+"' target-resolution='"+main.xdim+" "+main.ydim+" "+main.zdim+"'>\r\n");
for(var i:int=0;i<rows.length;i++) {
var l:SliceData=rows.getItemAt(i) as SliceData;
fs.writeUTFBytes(" <slice filename='"+l.filename+"' nr='"+l.sno+"' width='"+l.width+"' height='"+l.height);
var a:Vector.<Number>=l.pack();
var prefixes:Array=["' anchoring='ox=","&oy=","&oz=","&ux=","&uy=","&uz=","&vx=","&vy=","&vz="];
for(var j:int=0;j<9;j++)
fs.writeUTFBytes(prefixes[j]+a[j]);
fs.writeUTFBytes("'/>\r\n");
}
fs.writeUTFBytes("</series>\r\n");
fs.close();
}
public static var pb_hack:ProgressBar;
protected function slicesbtn_clickHandler(event:MouseEvent):void {
pb.x=(width-pb.width)/2;
pb.y=(height-pb.height)/2;
pb_hack=pb;
main.QSlices();
}
]]>
</mx:Script>
<containers:MDICanvas id="MDImain" width="100%" height="100%">
<containers:MDIWindow id="serieswindow" title="Image series" showCloseButton="false" minWidth="725" maxWidth="725" width="725" minHeight="250" height="250">
<mx:Canvas id="seriescanvas" width="100%" height="100%" resize="seriescanvas_resizeHandler(event)">
<mx:DataGrid id="stuff" x="10" y="10" editable="true" width="700" sortableColumns="false" dataProvider="{rows}" draggableColumns="false" itemDoubleClick="stuff_itemDoubleClickHandler(event)" doubleClickEnabled="true">
<mx:columns>
<mx:DataGridColumn dataField="filename" sortable="false" headerText="File" editable="false"/>
<mx:DataGridColumn dataField="sno" headerText="s#" editable="false" width="40"/>
<mx:DataGridColumn dataField="width" headerText="width" editable="false" width="80"/>
<mx:DataGridColumn dataField="height" headerText="height" editable="false" width="80"/>
<mx:DataGridColumn dataField="{main.valbox.decompcfg.selectedIndex==0?'_my':main.valbox.decompcfg.selectedIndex==1?'_mx':'_mz'}" headerText="level" editable="false"/>
<mx:DataGridColumn dataField="hasanchoring" headerText="status" editable="false">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" verticalAlign="middle">
<mx:Script>
<![CDATA[
private var obj:SliceData;
override public function set data(value:Object):void {
super.data=value;
obj=value as SliceData;
doStuff();
}
protected function doStuff():void {
if(obj.hasanchoring) {
statelbl.text="!";
statelbl.getTextField().backgroundColor=0x80ff80;
clearbtn.visible=clearbtn.enabled=true;
} else {
statelbl.text="?";
statelbl.getTextField().backgroundColor=0xff0000;
clearbtn.visible=clearbtn.enabled=false;
}
statelbl.getTextField().background=true;
}
protected function clearbtn_clickHandler(event:MouseEvent):void {
obj.clear();
doStuff();
MgmtPanel.interpolate();
MgmtPanel.main.seriescontrols();
MgmtPanel.mystic_update();
}
]]>
</mx:Script>
<local:BGLabel id="statelbl" fontFamily="Arial" fontSize="16" fontWeight="bold" textAlign="center"/>
<mx:Button id="clearbtn" label="Clear" click="clearbtn_clickHandler(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:Button x="10" id="loadbtn" label="Load" click="button1_clickHandler(event)"/>
<mx:Button x="612" id="addchart" label="Add Chart" click="addchart_clickHandler(event)"/>
<mx:Button x="71" id="savebtn" label="Save XML" enabled="{rows.length>0}" click="button3_clickHandler(event)"/>
<mx:Button x="159" id="jsonbtn" label="Save JSON" enabled="{rows.length>0}" click="jsonSave()"/>
<mx:Button x="467" id="exportbtn" label="Export Propagation" enabled="{rows.length>0}" click="exportbtn_clickHandler(event)"/>
<mx:Button x="360" id="slicesbtn" label="Export Slices" enabled="{rows.length>0}" click="slicesbtn_clickHandler(event)"/>
</mx:Canvas>
</containers:MDIWindow>
<containers:MDIWindow id="chartwindow" title="Chart" x="726" width="250" minWidth="250">
<local:SeriesChart/>
</containers:MDIWindow>
</containers:MDICanvas>
<mx:ProgressBar id="pb" visible="false" label="%1 / %2" mode="manual">
</mx:ProgressBar>
</mx:Window>