OSDN Git Service

first
[psychlops/cpp.git] / win32gl / test / shader / ShaderFieldPrec.cpp
1 #include <iostream>\r
2 #include <psychlops.h>
3 using namespace Psychlops;
4
5 void psychlops_main() {
6         Canvas cnvs(1024,700,Canvas::window);
7 //      cnvs.watchFPS();
8 //      cnvs.showFPS();
9         Mouse::show();
10
11
12
13         Color::setGammaValue(1.0,1.0,1.0);
14
15
16         Image buf[10], reference[10], difference[10], difference2[10];
17
18         Figures::ShaderGrating grat;\r
19         Figures::ShaderExponentialDot dot;\r
20         Figures::ShaderGabor gabor;\r
21         //std::ofstream f("shader_prec_test.txt");\r
22
23
24         double c=1, w=48, o=-40, p=0;
25         Widgets::Dial dial[4];
26         dial[0].link(c, 2);
27         dial[1].link(w, 36);
28         dial[2].link(o, 360);
29         dial[3].link(p, 960);
30 \r
31         //for(double o=0; o<PI; o+=PI/8) {\r
32         //for(double w=4; w<128; w*=2) {\r
33         //for(double c=0.25; c<=1.0; c+=0.25) {
34         REDRAW:\r
35
36                 gabor.setSigma(30);
37                 gabor.contrast = c;
38                 gabor.wavelength = w;
39                 gabor.phase = p/360.0*2*PI;
40                 gabor.orientation = o/360.0*2*PI;
41                 gabor.to(buf[0]);
42
43                 grat.set(240,240);
44                 grat.contrast = c;
45                 grat.wavelength = w;
46                 grat.phase = p/360.0*2*PI;
47                 grat.orientation = o/360.0*2*PI;
48                 grat.to(buf[1]);
49
50                 dot.setSigma(30);
51                 dot.factor = 1;
52 //              dot.to(buf[2]);
53
54
55                 Figures::drawGaborToImage(reference[0], 30, 1.0/w, c, o/360.0*2*PI, p/360.0*2*PI);
56                 Figures::drawGratingToImage(reference[1], 240,240 , 1.0/w, c, o/360.0*2*PI, p/360.0*2*PI);
57 //              Figures::drawExponentialToImage(reference[2], 30, 1);
58
59                 cnvs.clear(Color(0.25));
60                 cnvs.msg(L"シェーダ         -         CPU         =         誤差(赤:誤差2以上)", 100, 40, Color::white);
61                 for(int i=0; i<2; i++) {\r
62                         //f << c << "\t" << w << "\t" << o/2.0/PI*360.0 << "\t";
63                         //f <<
64                                 Figures::substructImages(difference[i], buf[i], reference[i], 255.0)
65                         //<< "\t"
66                         ;
67                         buf[i].centering(170,170+i*300).draw();
68                         reference[i].centering(470,170+i*300).draw();
69                         difference[i].centering(770,170+i*300).draw();
70                 }\r
71                 //f << std::endl;
72 \r
73         /*
74                 const int DIFF = 2, SLINE = 120;
75                 difference2[DIFF].set(480,512);
76                 int y1, y2;
77                 for(int y=0; y<240; y++) {
78                         y1 = (int)(512-reference[DIFF].getPix(SLINE,y).getR()*512);
79                         y2 = (int)(512-buf[DIFF].getPix(SLINE,y).getR()*512);
80                         difference2[DIFF].rect(Psychlops::Rectangle(y*2, y1, y*2+1, 511), Color(0.4));
81                         if(y1>y2) difference2[DIFF].rect(Psychlops::Rectangle(y*2, y2, y*2+1, y1), Color::green);
82                         if(y1<y2) difference2[DIFF].rect(Psychlops::Rectangle(y*2, y1, y*2+1, y2), Color::red);
83                 }
84                 difference2[DIFF].centering().draw();
85         */\r
86
87         //      cnvs.flip();
88         //      if(Keyboard::esc.pushed()) { exit(0); }\r
89         //}\r
90         //}\r
91         //}
92 \r
93 \r
94         while(!Keyboard::esc.pushed()) {
95                 cnvs.clear(Color(0.25));
96                 cnvs.msg(L"シェーダ         -         CPU         =         誤差(赤:誤差2以上)", 200, 40, Color::white);
97                 for(int i=0; i<2; i++) {
98                         buf[i].centering(270,170+i*300).draw();
99                         reference[i].centering(570,170+i*300).draw();
100                         difference[i].centering(870,170+i*300).draw();
101                 }
102                 for(int i=0; i<4; i++) dial[i].set(50).centering(50,100+i*50).draw();
103                 if(dial[0].changed() || dial[1].changed() || dial[2].changed() || dial[3].changed()) goto REDRAW;
104                 cnvs.msg(L"ピクセルの位相に鋭敏 コントラストに不変 → π(無理数)の有効桁数の問題", 200, 640, Color::white);
105                 cnvs.msg(L"コントラストに鋭敏 → 8 bit変換時の丸めがISO丸めか四捨五入か", 200, 680, Color::white);
106                 cnvs.flip();
107         }
108 }
109