-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTFWidgetRen1.cpp
1173 lines (1056 loc) · 37.5 KB
/
TFWidgetRen1.cpp
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
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ________ ____ ___
// | \ / | / /
// +---+ \/ |/ /
// +--+| |\ /| <
// | || | \ / | |\ \
// | | \/ | | \ \
// \_____| |__| \__\
// Copyright 2001
// Joe Michael Kniss
// "All Your Base are Belong to Us"
//
// TFWidgetRen1.cpp: implementation of the TFWidgetRen class.
//
//////////////////////////////////////////////////////////////////////
#ifdef WIN32
#include <windows.h>
#endif
#include "TFWidgetRen1.h"
#include "glUE.h"
#include "gluvv.h"
#include "VectorMath.h"
#include <iostream.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
TFWidgetRen::TFWidgetRen()
{
ballRad = .1;
barRad = .05;
position[0] = -1.3;
position[1] = -1.3;
position[2] = -1;
screenwidth = .9;
screenheight = .2;
screenpos[0] = .45;
screenpos[1] = -.46;
screenbar = .01;
screenball = screenbar * 1.5;
//gluvv.tf.ptexsz[0] = 256;
//gluvv.tf.ptexsz[1] = 256;
//gluvv.tf.ptexsz[2] = 1;
//gluvv.tf.numelts = 4;
gluvv.tf.loadme = 0;
lastppos[0] = lastppos[1] = lastppos[2] = 0;
lastSlide1Pos[0] = 1;
lastSlide1Pos[1] = 0;
histo = 0;
}
TFWidgetRen::~TFWidgetRen()
{
}
//================================================================= draw
//======================================================================
void TFWidgetRen::draw()
{
if(gluvv.reblend) return;
if(!gluvv.mv) return;
glEnable(GL_LIGHTING);
float dist = position[2] - gluvv.env.eye[2];
width = ((gluvv.env.frustum[1]-gluvv.env.frustum[0]) *
dist/gluvv.env.clip[0]) * screenwidth;
height = ((gluvv.env.frustum[3]-gluvv.env.frustum[2]) *
dist/gluvv.env.clip[0]) * screenheight;
position[0] = ((gluvv.env.frustum[1]-gluvv.env.frustum[0]) *
dist/gluvv.env.clip[0]) * screenpos[0];
position[1] = ((gluvv.env.frustum[1]-gluvv.env.frustum[0]) *
dist/gluvv.env.clip[0]) * screenpos[1];
barRad = ((gluvv.env.frustum[1]-gluvv.env.frustum[0]) *
dist/gluvv.env.clip[0]) * screenbar;
ballRad = ((gluvv.env.frustum[1]-gluvv.env.frustum[0]) *
dist/gluvv.env.clip[0]) * screenball;
tris->setWH(width-ballRad*2, height-ballRad*2);
brush->setWH(width-ballRad*2, height-ballRad*2);
tris->setBallBar(ballRad/2.0, barRad/2.0);
brush->setBallBar(ballRad/2.0, barRad/2.0);
fill();
gluvvPushName();
glPushName(22);
glPushName(222);
glPushName(2222);
glPushMatrix();{
glTranslatef(position[0], position[1], position[2]);
glRotatef(180, 0, 1, 0);
drawFrame();
} glPopMatrix();
gluvvPopNames();
GlErr("TFWidgetRen","draw()");
}
//=========================================================== draw frame
//======================================================================
void TFWidgetRen::drawFrame()
{
glColor4f(.1, .07, .57, 1); //balls
float spos[3] = {0,0,0};
drawSphere(spos, blball); //bottom left
spos[0] = width;
drawSphere(spos, brball); //bottom right
spos[1] = height;
drawSphere(spos, trball); //top right
spos[0] = 0;
drawSphere(spos, tlball); //top left
glColor4f(.09, .34, .55, 1); //bars
float bpos[3] = {0,0,0};
drawBar(-90, WdgXAxis, height, bpos, lbar); //left
drawBar(90, WdgYAxis, width, bpos, bbar); //bottom
bpos[1] = height;
drawBar(90, WdgYAxis, width, bpos, tbar); //top
bpos[0] = width;
bpos[1] = 0;
drawBar(-90, WdgXAxis, height, bpos, rbar); //right
glColor3f(.8, .5, .1); //sliders
//interactive sample rate
float ispos[3] = {ballRad + (gluvv.volren.interactSamp/6.0)*(width-2*ballRad), 0,0};
drawSlider(90,WdgYAxis,ispos,islide);
glColor3f(.8, .2, .1);
//good sample rate
float gspos[3] = {ballRad + (gluvv.volren.goodSamp/6.0)*(width-2*ballRad), 0,0};
drawSlider(90,WdgYAxis,gspos,gslide);
glColor3f(.6, .2, .8);
//alpha gamma slider
float aspos[3] = {0, ballRad + (gluvv.volren.gamma/10.0)*(height-2*ballRad), 0};
drawSlider(90,WdgXAxis,aspos,aslide);
glColor3f(.5, .6, .8);
#if 1
if(gluvv.dmode == GDM_V2G){ //multiple channel
float a3spos[3] = {ballRad + (gluvv.tf.slider1hi)*(width-2*ballRad), height, 0};
drawSlider(90,WdgYAxis,a3spos,a3slidehi);
glColor3f(.2, .6, .8);
a3spos[0] = ballRad + (gluvv.tf.slider1lo)*(width-2*ballRad);
drawSlider(90,WdgYAxis,a3spos,a3slidelo);
if((lastSlide1Pos[0] != gluvv.tf.slider1hi) || (lastSlide1Pos[1] != gluvv.tf.slider1lo)){
rasterizevgH(gluvv.volren.deptex2);
gluvv.volren.loadTLUT = 1;
}
lastSlide1Pos[0] = gluvv.tf.slider1hi;
lastSlide1Pos[1] = gluvv.tf.slider1lo;
}
#endif
if((gluvv.dmode == GDM_VGH)||(gluvv.dmode == GDM_V1GH)){ //vgh
if(lastSlide1Pos[0] != gluvv.tf.slider1hi){
rasterizevgH(gluvv.volren.deptex2);
gluvv.volren.loadTLUT = 1;
}
lastSlide1Pos[0] = gluvv.tf.slider1hi;
float a3spos[3] = {ballRad + (gluvv.tf.slider1hi)*(width-2*ballRad), height, 0};
drawSlider(90,WdgYAxis,a3spos,a3slidehi);
}
glDisable(GL_LIGHTING);
glColor4f(0,0,0,1); //transfer function map depth
glLoadName(tfsheet1);
glBindTexture(GL_TEXTURE_2D, gluvv.volren.deptexName);
glBegin(GL_QUADS);{ //draw the transfer function
glVertex3f(barRad*1.5, barRad*1.5, 0);
glVertex3f(width-barRad*1.5, barRad*1.5, 0);
glVertex3f(width-barRad*1.5, height-barRad*1.5, 0);
glVertex3f(barRad*1.5, height-barRad*1.5,0);
} glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING); //---------------------------
drawProbe();
//-------------- load new pixel texture ----------------------------------
if(gluvv.tf.clearpaint){ //clear the paint texture
clearPtex(paintex);
gluvv.tf.clearpaint = 0;
gluvv.tf.loadme = 1;
}
//gluvvShade oldshade;
if(gluvv.tf.paintme){ //add to the paint texture
switch(gluvv.probe.brush){
case EllipseBrush:
case AutoEllipseBrush:
case OneDBrush:
case AutoOneDBrush:
//oldshade = gluvv.shade; //faux shading is bad for painting
//gluvv.shade = gluvvShadeAmb;
brush->rasterize(paintex);
//gluvv.shade = oldshade;
gluvv.tf.paintme = 0;
gluvv.tf.loadme = 1;
break;
case TriangleBrush:
LevWidget *lwtmp = new LevWidget(*brush);
tris->insert(lwtmp);
gluvv.tf.paintme = 0;
gluvv.tf.loadme = 1;
}
}
if(gluvv.tf.dropme){
LevWidget *lwtmp = new LevWidget(*brush);
tris->insert(lwtmp);
gluvv.tf.dropme = 0;
gluvv.tf.loadme = 1;
glutPostRedisplay();
}
if(gluvv.tf.loadme){ //generate a new transfer function
//clearPtex();
clearPtex(gluvv.volren.deptex3);
copyPtex(gluvv.volren.deptex, paintex);
tris->rasterize(gluvv.volren.deptex, gluvv.volren.deptex3);
if(gluvv.tf.brushon)
brush->rasterize(gluvv.volren.deptex, gluvv.volren.deptex3);
loadPtex();
gluvv.tf.loadme = 0;
gluvv.volren.loadTLUT = 1;
}
//----------------------------------------------------------------------
glColor4f(1,1,1,1); //transfer function color
glLoadName(tfsheet1);
glActiveTexture(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDisable(GL_LIGHTING);
glDepthFunc(GL_EQUAL);
if(!histo){
loadHist2D();
}
if(gluvv.tf.histOn){ //histogram
glBindTexture(GL_TEXTURE_2D, histName);
glDisable(GL_BLEND);
glBegin(GL_QUADS);{ //draw the transfer function
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,0);
glVertex3f(barRad*1.5, barRad*1.5, 0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1,0);
glVertex3f(width-barRad*1.5, barRad*1.5, 0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1,1);
glVertex3f(width-barRad*1.5, height-barRad*1.5, 0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,1);
glVertex3f(barRad*1.5, height-barRad*1.5,0);
} glEnd();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} else {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
//transfer function
glBindTexture(GL_TEXTURE_2D, gluvv.volren.deptexName);
glBegin(GL_QUADS);{ //draw the transfer function
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,0);
glVertex3f(barRad*1.5, barRad*1.5, 0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1,0);
glVertex3f(width-barRad*1.5, barRad*1.5, 0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1,1);
glVertex3f(width-barRad*1.5, height-barRad*1.5, 0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,1);
glVertex3f(barRad*1.5, height-barRad*1.5,0);
} glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING); //---------------------------
glDepthFunc(GL_LESS);
glPushMatrix();{ //draw levoy triangles
glTranslatef(ballRad, ballRad, ballRad);
tris->draw();
brush->draw();
} glPopMatrix();
}
//=========================================================== draw probe
//======================================================================
void TFWidgetRen::drawProbe()
{
int xi = gluvv.mv->xiSize; //size of volume (axies)
int yi = gluvv.mv->yiSize;
int zi = gluvv.mv->ziSize;
int px, py, pz;
float fpos[3];
if(!gluvv.mprobe){ //probe
px = gluvv.probe.vpos[0] * xi; //integer position in volume
py = gluvv.probe.vpos[1] * yi; //(least)
pz = gluvv.probe.vpos[2] * zi;
fpos[0] = gluvv.probe.vpos[0] * xi; //floating point position in volume
fpos[1] = gluvv.probe.vpos[1] * yi; //
fpos[2] = gluvv.probe.vpos[2] * zi;
if((lastppos[0] != gluvv.probe.vpos[0])||
(lastppos[1] != gluvv.probe.vpos[1])||
(lastppos[2] != gluvv.probe.vpos[2]))
if(gluvv.tf.brushon)
gluvv.tf.loadme = 1;
lastppos[0] = gluvv.probe.vpos[0];
lastppos[1] = gluvv.probe.vpos[1];
lastppos[2] = gluvv.probe.vpos[2];
} else { //clip
px = gluvv.clip.mousepnt[0] * xi; //integer position in volume
py = gluvv.clip.mousepnt[1] * yi; //(least)
pz = gluvv.clip.mousepnt[2] * zi;
fpos[0] = gluvv.clip.mousepnt[0] * xi;//floating point position in volume
fpos[1] = gluvv.clip.mousepnt[1] * yi;
fpos[2] = gluvv.clip.mousepnt[2] * zi;
if((lastppos[0] != gluvv.clip.mousepnt[0])||
(lastppos[1] != gluvv.clip.mousepnt[1])||
(lastppos[2] != gluvv.clip.mousepnt[2]))
if(gluvv.tf.brushon)
gluvv.tf.loadme = 1;
lastppos[0] = gluvv.clip.mousepnt[0];
lastppos[1] = gluvv.clip.mousepnt[1];
lastppos[2] = gluvv.clip.mousepnt[2];
}
if((px < 1) || (px > (xi-2)) || //are we within the bounds
(py < 1) || (py > (yi-2)) || //of the volume???
(pz < 1) || (pz > (zi-2))){
float tmpp[2] = {0,0};
brush->setPos(tmpp, tmpp, tmpp);
//gluvv.tf.loadme = 1;
return; //no, nothing to do here
}
unsigned char *dp = (unsigned char*)gluvv.mv->volumes[0].currentData;
//I need to handle bricked volumes !!!!
if((gluvv.mv->numSubVols != 1) && (gluvv.mv->wholeVol)){
dp = (unsigned char*)gluvv.mv->wholeVol->currentData;
}
//unsigned char *gp = (unsigned char*)gluvv.mv->volumes[0].currentData1;
float vpnts[8][3]; //voxel corners, tf space
float vvals[8][3]; //voxel values, [0..1]
int sx = gluvv.mv->xiSize;
int sy = gluvv.mv->yiSize;
int sz = gluvv.mv->ziSize;
//initialize values
for(int i=0; i<2; ++i){ //z = i
for(int j=0; j<2; ++j){ //y = j
for(int k=0; k<2; ++k){ //x = k
vpnts[i*4 + j*2 + k][0] = 0;
vpnts[i*4 + j*2 + k][1] = 0;
vvals[i*4 + j*2 + k][0] = 0;
vvals[i*4 + j*2 + k][1] = 0;
}
}
}
int ne = gluvv.mv->nelts;
float hacktmp;
for(i=0; i<2; ++i){ //z = i
for(int j=0; j<2; ++j){ //y = j
for(int k=0; k<2; ++k){ //x = k
switch(gluvv.dmode){
case GDM_V1:
vpnts[i*4 + j*2 + k][0] = ballRad + //get 1st value
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne)]/
255.0 * (width - 2*ballRad);
vvals[i*4 + j*2 + k][0] = //draw in center
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne)]/255.0;
vpnts[i*4 + j*2 + k][1] = ballRad + .5 * (height - 2*ballRad);;
break;
case GDM_V1G:
case GDM_V2:
case GDM_V2G:
vpnts[i*4 + j*2 + k][0] = ballRad + //get 1st value
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne)]/
255.0 * (width - 2*ballRad);
vvals[i*4 + j*2 + k][0] =
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne)]/255.0;
vpnts[i*4 + j*2 + k][1] = ballRad + //get 2nd value
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne) + 1]/
255.0 * (height - 2*ballRad);
vvals[i*4 + j*2 + k][1] =
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne) + 1]/255.0;
break;
case GDM_V2GH:
case GDM_V3:
case GDM_V3G: //sigh what am I going to do about 4 value volumes
case GDM_V4:
vpnts[i*4 + j*2 + k][0] = ballRad + //get 1st value
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne)]/
255.0 * (width - 2*ballRad);
vvals[i*4 + j*2 + k][0] =
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne)]/255.0;
vpnts[i*4 + j*2 + k][1] = ballRad + //get 2nd value
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne) + 1]/
255.0 * (height - 2*ballRad);
vvals[i*4 + j*2 + k][1] =
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne) + 1]/255.0;
vpnts[i*4 + j*2 + k][2] = ballRad + //get 3rd value
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne) + 2]/
255.0 * (width - 2*ballRad);
vvals[i*4 + j*2 + k][2] =
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne) + 2]/255.0;
case GDM_VGH:
case GDM_V1GH:
case GDM_VGH_VG:
case GDM_VGH_V:
vpnts[i*4 + j*2 + k][0] = ballRad + //get 1st value
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne)]/
255.0 * (width - 2*ballRad);
vvals[i*4 + j*2 + k][0] =
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne)]/255.0;
vpnts[i*4 + j*2 + k][1] = ballRad + //get 2nd value
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne) + 1]/
255.0 * (height - 2*ballRad);
vvals[i*4 + j*2 + k][1] =
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne) + 1]/255.0;
//get hessian
hacktmp = dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne) + 2]/85.0-1;
hacktmp = hacktmp > 0 ? sqrt(hacktmp) : -sqrt(-hacktmp);
vpnts[i*4 + j*2 + k][2] = (hacktmp+1)/2.0;
vvals[i*4 + j*2 + k][2] =
dp[((pz+i)*sx*sy*ne) + ((py+j)*sx*ne) + ((px+k)*ne) + 2]/169.0;
break;
}
}
}
}
//done getting voxel corner values
if(!gluvv.picking){
glDisable(GL_LIGHTING);
//glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glDisable(GL_DEPTH_TEST);
//glDepthFunc(GL_EQUAL);
glColor4f(1,1,1,.3);
glBegin(GL_LINE_STRIP);{
glVertex3f(vpnts[0][0], vpnts[0][1], .01);
glVertex3f(vpnts[1][0], vpnts[1][1], .01);
glVertex3f(vpnts[3][0], vpnts[3][1], .01);
glVertex3f(vpnts[2][0], vpnts[2][1], .01);
glVertex3f(vpnts[0][0], vpnts[0][1], .01);
glVertex3f(vpnts[4][0], vpnts[4][1], .01);
glVertex3f(vpnts[5][0], vpnts[5][1], .01);
glVertex3f(vpnts[7][0], vpnts[7][1], .01);
glVertex3f(vpnts[6][0], vpnts[6][1], .01);
glVertex3f(vpnts[4][0], vpnts[4][1], .01);
} glEnd();
glBegin(GL_LINES);{
glVertex3f(vpnts[1][0], vpnts[1][1], .01);
glVertex3f(vpnts[5][0], vpnts[5][1], .01);
glVertex3f(vpnts[3][0], vpnts[3][1], .01);
glVertex3f(vpnts[7][0], vpnts[7][1], .01);
glVertex3f(vpnts[2][0], vpnts[2][1], .01);
glVertex3f(vpnts[6][0], vpnts[6][1], .01);
} glEnd();
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
} //if not picking
float val[3];
triLerpV3(val, vvals, fpos); //trilinear interp for values
//------------ Paint Brush ---------------------------------------
if(gluvv.tf.brushon){ //wow clean this up!!!
if(gluvv.probe.brush == EllipseBrush){
float bsz = (1.0 - gluvv.probe.slider)/4.0;
float plpos[2] = {val[0]-bsz, val[1]+bsz};//paint positions
float prpos[2] = {val[0]+bsz, val[1]+bsz};
float pbpos[2] = {val[0]+bsz, val[1]-bsz};
brush->setPos(pbpos, plpos, prpos, val[0], val[1]);
brush->drawOn = 0;
brush->squareType();
glPushMatrix();{ //draw brush
glTranslatef(ballRad, ballRad, ballRad);
brush->draw();
} glPopMatrix();
} else if((gluvv.probe.brush == TriangleBrush)||(gluvv.probe.brush == AutoEllipseBrush)){
float maxx = -1000;
float maxy = -1000;
float minx = 1000;
float miny = 1000;
for(int i=0; i<8; ++i){
maxx = MAX(maxx, vvals[i][0]);
maxy = MAX(maxy, vvals[i][1]);
minx = MIN(minx, vvals[i][0]);
miny = MIN(miny, vvals[i][1]);
}
float bsz = (1.0 - gluvv.probe.slider)*2;
float w = MAX((maxx - minx)/2.0, .01);
float h = MAX((maxy - miny)/2.0, .01);
float plpos[2] = {val[0]-w*bsz, val[1]+h*bsz};
float prpos[2] = {val[0]+w*bsz, val[1]+h*bsz};
float pbpos[2] = {val[0], 0};
if(gluvv.probe.brush == TriangleBrush){
brush->setPos(pbpos, plpos, prpos, 0, val[1] - h*bsz);
brush->drawOn = 1;
brush->triangleType();
}
else {
pbpos[0] = val[0]+w*bsz;
pbpos[1] = val[1]-h*bsz;
brush->setPos(pbpos, plpos, prpos, val[0], val[1]);
brush->drawOn = 0;
brush->squareType();
glPushMatrix();{ //draw brush
glTranslatef(ballRad, ballRad, ballRad);
brush->draw();
} glPopMatrix();
}
}
if((gluvv.dmode == GDM_V1) || (gluvv.dmode == GDM_VGH_V) ||
(gluvv.probe.brush == OneDBrush)||(gluvv.probe.brush == AutoOneDBrush)){
float maxx = -1000;
float minx = 1000;
for(int i=0; i<8; ++i){
maxx = MAX(maxx, vvals[i][0]);
minx = MIN(minx, vvals[i][0]);
}
float bsz = (1.0 - gluvv.probe.slider)*2;
float w = MAX((maxx - minx)/2.0, .01);
float plpos[2] = {val[0]-w*bsz, 1};
float prpos[2] = {val[0]+w*bsz, 1};
float pbpos[2] = {val[0], 0};
if(gluvv.probe.brush == OneDBrush){
plpos[0] = val[0] + (1.0 - gluvv.probe.slider)/4.0;
prpos[0] = val[0] - (1.0 - gluvv.probe.slider)/4.0;
}
brush->setPos(pbpos, plpos, prpos, val[0], val[1]);
brush->oneDType();
}
}
//------------ end Paint Brush ------------------------------------
if(!gluvv.picking){
//position of point in tf space:
glPushMatrix();{
glTranslatef(ballRad + val[0]*(width - 2*ballRad),
ballRad + val[1]*(height - 2*ballRad),
.01);
glColor4f(1, 0, 0, 1);
glLoadName(dpoint);
glutSolidSphere(ballRad/2.5, 20, 20);
} glPopMatrix();
//draw voxel points in data domain
for(i=0; i<8; ++i){
glPushMatrix();{
glTranslatef(vpnts[i][0], vpnts[i][1], .01);
float bcol[3] = {1,1,1};
if(gluvv.dmode == GDM_VGH){
bcol[0]= don[((int)(vpnts[i][2]*22) + 1)*3 + 0]/255.0;
bcol[1]= don[((int)(vpnts[i][2]*22) + 1)*3 + 1]/255.0;
bcol[2]= don[((int)(vpnts[i][2]*22) + 1)*3 + 2]/255.0;
}
glColor4f(bcol[0], bcol[1], bcol[2], 1);
glutSolidSphere(ballRad/3.5, 20, 20);
} glPopMatrix();
}
}
glEnable(GL_LIGHTING);
}
//=========================================================== trilerp v3
//======================================================================
void TFWidgetRen::triLerpV3(float val[3], float voxels[8][3], float pos[3])
{
//fractional values
float fx = pos[0] - (int)pos[0];
float fy = pos[1] - (int)pos[1];
float fz = pos[2] - (int)pos[2];
//now interpolate to find the data value at our point
//first allong x direction
for(int i=0; i<3; ++i){
float x1 = voxels[0][i] + (float)(voxels[1][i] - voxels[0][i]) * fx;
float x2 = voxels[2][i] + (float)(voxels[3][i] - voxels[2][i]) * fx;
float x3 = voxels[4][i] + (float)(voxels[5][i] - voxels[4][i]) * fx;
float x4 = voxels[6][i] + (float)(voxels[7][i] - voxels[6][i]) * fx;
//then along y direction
float xy1 = x1 + (x2 - x1) * fy;
float xy2 = x3 + (x4 - x3) * fy;
//finaly allong z direction
val[i] = (xy1 + (xy2 - xy1) * fz);
}
}
//================================================================= init
//======================================================================
void TFWidgetRen::init()
{
widgetInit();
//-------- Levoy triangles -----------
tris = new LevWidget(&gluvv);
tris->setWH(width-ballRad*2, height-ballRad*2);
float b[2] = {.5,0}; float l[2]={.3,.7}; float r[2] = {.7,.7};
tris->setPos(b,l,r);
tris->setBallBar(ballRad/2.0, barRad/2.0);
tris->setDepth(position[2]);
tris->squareType();
tris->on = 0; //turn root triangle off
shadTris = new LevWidget(&gluvv);
shadTris->setWH(width-ballRad*2, height-ballRad*2);
shadTris->setPos(b,l,r);
shadTris->setBallBar(ballRad/2.0, barRad/2.0);
shadTris->setDepth(position[2]);
shadTris->squareType();
shadTris->on = 0; //turn root triangle off
brush= new LevWidget(&gluvv);
brush->setWH(width-ballRad*2, height-ballRad*2);
brush->setPos(b,l,r);
brush->setBallBar(ballRad/2.0, barRad/2.0);
brush->setDepth(position[2]);
brush->setAlpha(.7);
brush->squareType();
brush->on = 1; //turn paint brush on
brush->drawOn = 0; //but dont actualy draw the widget
paintex = new unsigned char[gluvv.tf.ptexsz[0]*gluvv.tf.ptexsz[1]*gluvv.tf.ptexsz[2]*gluvv.tf.numelts];
clearPtex(paintex);
}
//============================================================ load Hist
//======================================================================
void TFWidgetRen::loadHist2D()
{
histo = new unsigned char[256*256];
cerr << "Generating histogram";
if(!gluvv.mv->hist2D(histo)){
delete[] histo;
histo = 0;
return;
}
cerr << endl;
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &histName); //the dep tex that we use for the tf
glBindTexture(GL_TEXTURE_2D, histName);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_LUMINANCE,
256,
256,
0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
histo);
glFlush();
glDisable(GL_TEXTURE_2D);
}
//================================================================= pick
//======================================================================
int TFWidgetRen::pick(int data1, int data2, int data3,
float x, float y, float z)
{
//cerr << "hi you picked the tf widget" << endl;
return 1;
}
int TFWidgetRen::pick()
{
fill();
pickedObj = gluvv.pick.data3;
glutSetWindowTitle("Transfer Function Widget");
if(pickedObj == LEVWIDGNAME){
tris->release();
pickedTri = gluvv.pick.data1;
if(pickedTri == brush->id)
return brush->pick();
else
return tris->pick();
}
return 1;
}
//================================================================= key
//======================================================================
int TFWidgetRen::key(unsigned char key, int x, int y)
{
if(key == 127){ //delete key
if(pickedObj == LEVWIDGNAME){ //you must mean delete a triangle
if(pickedTri == tris->id){ //can't delete the root triangle!!!
tris->on = 0;
gluvv.tf.loadme = 1;
glutPostRedisplay();
return 1; //we used the key
}
LevWidget * tmplw = tris->remove(pickedTri);
delete tmplw;
gluvv.tf.loadme = 1;
glutPostRedisplay();
return 1; //key used
}
}
switch(key){
case 'B':
if(brush->on){
if(brush->drawOn) brush->drawOn = 0;
else brush->drawOn = 1;
return 1;
}
break;
}
return 0;
}
//================================================================ mouse
//======================================================================
int TFWidgetRen::mouse(int button, int state,
int x, int y)
{
if(pickedObj == LEVWIDGNAME){
if(pickedTri == brush->id)
return brush->mouse(button, state, x, y);
else
return tris->mouse(button, state, x, y);
}
if(state == GLUT_DOWN){
lastwinpos[0] = x;
lastwinpos[1] = y;
switch(button){
case GLUT_LEFT_BUTTON:
switch(pickedObj){
case tfsheet0:
case tfsheet1:
case tfsheet2:
//mode = color;
break;
}
break;
case GLUT_MIDDLE_BUTTON:
switch(pickedObj){
case tfsheet0:
case tfsheet1:
case tfsheet2:
//mode = colorBlend;
break;
}
break;
case GLUT_RIGHT_BUTTON:
LevWidget *lwtmp = new LevWidget(&gluvv);
mouse2plane(x,y);
float pnt[2] = {1-(mousepnt[0]+position[0])/width,
(mousepnt[1]-position[1])/height};
float b[2] = {pnt[0], 0};
float l[2] = {pnt[0]-.1, pnt[1]};
float r[2] = {pnt[0]+.1, pnt[1]};
lwtmp->setPos(b,l,r, l[1]*.5);
lwtmp->setDepth(position[2]);
tris->insert(lwtmp);
gluvv.tf.loadme = 1;
break;
}
}
else{ //state is _UP
gluvv.volren.sampleRate = gluvv.volren.goodSamp;
glutPostRedisplay();
glutSetWindowTitle("Transfer Function Widget");
}
return 1;
lastwinpos[0] = x;
lastwinpos[1] = y;
return 0;
}
//================================================================= move
//======================================================================
int TFWidgetRen::move(int x, int y)
{
if(pickedObj == LEVWIDGNAME){
if(pickedTri == brush->id)
return brush->move(x,y);
else
return tris->move(x, y);
}
float sdx = (float)(x - lastwinpos[0])/(float)gluvv.win.width;
float sdy = (float)(y - lastwinpos[1])/(float)gluvv.win.height;
//had to change this should be smarter
float d[3];
subV3(d, position, gluvv.env.eye);
//float dist = normV3(d);
float dist = position[2] - gluvv.env.eye[2];
float dx = sdx *
(gluvv.env.frustum[1]-gluvv.env.frustum[0]) * dist/gluvv.env.clip[0];
float dy = sdy *
(gluvv.env.frustum[3]-gluvv.env.frustum[2]) * dist/gluvv.env.clip[0];
switch(gluvv.mouse.state){////////////////////////////////////
case GLUT_DOWN:
switch(gluvv.mouse.button){///////////////////////
case GLUT_LEFT_BUTTON:
switch(pickedObj){///////////////////
case gslide:
gluvv.volren.goodSamp += sdx * 6;
char str[255];
sprintf(str, "High Quality Sample Rate = %f", gluvv.volren.goodSamp);
glutSetWindowTitle(str);
glutPostRedisplay();
break;
case islide:
gluvv.volren.interactSamp += sdx * 6;
str[255];
sprintf(str, "Interactive Sample Rate = %f", gluvv.volren.interactSamp);
glutSetWindowTitle(str);
glutPostRedisplay();
break;
case aslide:
gluvv.volren.gamma -= sdy/height * 10;
gluvv.volren.gamma = gluvv.volren.gamma < 0 ? 0 : gluvv.volren.gamma;
str[255];
sprintf(str, "Opacity Gamma = %f", gluvv.volren.gamma);
glutSetWindowTitle(str);
gluvv.volren.loadTLUT = 1;
glutPostRedisplay();
break;
case a3slidehi:
gluvv.tf.slider1hi += sdx;
gluvv.tf.slider1hi = gluvv.tf.slider1hi < 0 ? 0 : (gluvv.tf.slider1hi > 1 ? 1 : gluvv.tf.slider1hi);
if(gluvv.tf.slider1hi < gluvv.tf.slider1lo) gluvv.tf.slider1lo = gluvv.tf.slider1hi;
str[255];
sprintf(str, "3rd Axis Threshold HI = %f", gluvv.tf.slider1hi);
glutSetWindowTitle(str);
//gluvv.volren.loadTLUT = 1;
glutPostRedisplay();
break;
case a3slidelo:
gluvv.tf.slider1lo += sdx;
gluvv.tf.slider1lo = gluvv.tf.slider1lo < 0 ? 0 : (gluvv.tf.slider1lo > 1 ? 1 : gluvv.tf.slider1lo);
if(gluvv.tf.slider1hi < gluvv.tf.slider1lo) gluvv.tf.slider1hi = gluvv.tf.slider1lo;
str[255];
sprintf(str, "3rd Axis Threshold LO = %f", gluvv.tf.slider1lo);
glutSetWindowTitle(str);
//gluvv.volren.loadTLUT = 1;
glutPostRedisplay();
break;
case bbar:
case tbar:
case lbar:
case rbar:
screenpos[0] -= sdx;
screenpos[1] -= sdy;
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutSetWindowTitle("Transfer Function Widget: MOVE");
glutPostRedisplay();
break;
case blball:
screenpos[0] -= sdx;
screenpos[1] -= sdy;
screenwidth -= sdx;
screenheight += sdy;
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutSetWindowTitle("Transfer Function Widget: RESIZE");
glutPostRedisplay();
break;
case brball:
screenpos[1] -= sdy;
screenwidth += sdx;
screenheight += sdy;
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutSetWindowTitle("Transfer Function Widget: RESIZE");
glutPostRedisplay();
break;
case tlball:
screenpos[0] -= sdx;
screenwidth -= sdx;
screenheight -= sdy;
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutSetWindowTitle("Transfer Function Widget: RESIZE");
glutPostRedisplay();
break;
case trball:
screenwidth += sdx;
screenheight -= sdy;
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutSetWindowTitle("Transfer Function Widget: RESIZE");
glutPostRedisplay();
break;
#if 0
case beslider:
if(pickedTri){
LevWidget *tt;
if(tt = tris->get(pickedTri)){
float slider = tt->getBE();
slider += dx/width;
tt->setBE(slider);
glutSetWindowTitle("Transfer Function Widget: Boundary Emphasis");
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutPostRedisplay();
gluvv.tf.loadme = 1;
}
}
break;
#endif
}///////////////////////////////////
break;
case GLUT_RIGHT_BUTTON:
switch(pickedObj){///////////////////
case bbar:
case tbar:
case lbar:
case rbar:
position[0] -= dx;
position[2] -= dy;
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutSetWindowTitle("Transfer Function Widget: MOVE");
glutPostRedisplay();
break;
}
break;
case GLUT_MIDDLE_BUTTON:
break;
}///////////////////////////////////////////////
break;
case GLUT_UP:
break;
}////////////////////////////////////////////////////////////
lastwinpos[0] = x;
lastwinpos[1] = y;
return 1;
}
//============================================================== release
//======================================================================
int TFWidgetRen::release()
{
return 0;
}
//============================================================ clearPtex
//======================================================================
void TFWidgetRen::clearPtex()
{
int sz = (gluvv.tf.numelts*
gluvv.tf.ptexsz[0]*
gluvv.tf.ptexsz[1]*
gluvv.tf.ptexsz[2]);