OSDN Git Service

first
[psychlops/cpp.git] / win32gl / test / inputTest.cpp
1 #include <psychlops.h>\r
2 using namespace Psychlops;      // Initially developed with Psychlops Win32 1.5.3 / 20110311\r
3 \r
4 \r
5 std::string error_message;\r
6 \r
7 void loadGLSL(std::stringstream &buf, const std::string path)\r
8 {\r
9         char one;\r
10         std::ifstream is;\r
11         is.open(path.c_str(), std::ifstream::in);\r
12         if(is.fail()) {\r
13                 Widgets::Dialog::alert(L"File was not found, or failed to read for some reasons.");\r
14                 return;\r
15         }\r
16         while(is.good()) {\r
17                 is.get(one);\r
18                 buf << one;\r
19         }\r
20 }\r
21 void logError()\r
22 {\r
23         std::ofstream os;\r
24         os.open("GLSLTesterErrorLog.txt");\r
25         if(os.fail()) {\r
26                 Widgets::Dialog::alert(L"File was not found, or failed to read for some reasons.");\r
27                 return;\r
28         }\r
29         os << error_message;\r
30 }\r
31 \r
32 const char *default_field_glsl =\r
33                         "in float red;"\r
34                         "void main(void){ "\r
35                         "pix(red,0.0,0.0,1.0); }";\r
36 \r
37 Figures::ShaderField field;\r
38 char *source_field = (char*)default_field_glsl;\r
39 void cacheShaderField(const std::string path)\r
40 {\r
41         std::stringstream buf;\r
42         loadGLSL(buf, path);\r
43 \r
44         try{\r
45                 field.setFunction(buf.str().c_str());\r
46                 field.cache(*Display::the_canvas);\r
47                 error_message.clear();\r
48         } catch (Exception e) {\r
49                 error_message = e.getErrorString();\r
50                 logError();\r
51         } catch (Exception *e) {\r
52                 error_message = e->getErrorString();\r
53                 logError();\r
54         }\r
55 }\r
56 \r
57 const char *default_image_glsl =\r
58         "in float dr, dg, db, da;"\r
59         "void main(void) {"\r
60         "vec4 d = vec4(dr, dg, db, da);"\r
61         "pix(getPix()+d);}";\r
62 Figures::ShaderImage2 image;\r
63 char *source_image = (char*)default_image_glsl;\r
64 Image shadered_image, dummy_image;\r
65 void cacheShaderImage(const std::string path)\r
66 {\r
67         std::stringstream buf;\r
68         loadGLSL(buf, path);\r
69         try{\r
70                 image.setFunction(buf.str().c_str());\r
71                 image.cache(*Display::the_canvas);\r
72                 error_message.clear();\r
73         } catch (Exception e) {\r
74                 error_message = e.getErrorString();\r
75                 logError();\r
76         } catch (Exception *e) {\r
77                 error_message = e->getErrorString();\r
78                 logError();\r
79         }\r
80 }\r
81 \r
82 \r
83 class Pallet\r
84 {\r
85         public:\r
86         Color pallet[256];\r
87 };\r
88 \r
89 class PageCycle\r
90 {\r
91         Image *pages;\r
92         PageCycle()\r
93         {\r
94                 pages = new Image[100];\r
95         }\r
96         ~PageCycle()\r
97         {\r
98                 delete [] pages;\r
99         }\r
100 \r
101 \r
102 };\r
103 \r
104 \r
105 const int SHADER_ARG_MAX = 16;\r
106 \r
107 \r
108 \r
109 void psychlops_main() {\r
110 \r
111         Canvas cnvs(1024, 768, Canvas::window);\r
112 \r
113 \r
114         Widgets::StackPanel buttons;\r
115         Widgets::Button loader[3];\r
116         loader[0].set(L"Load GLSL/field", 18);\r
117         buttons.append(&loader[0]);\r
118         loader[1].set(L"Load GLSL/image", 18);\r
119         buttons.append(&loader[1]);\r
120         loader[2].set(L"Load PNG image", 18);\r
121         buttons.append(&loader[2]);\r
122         buttons.setWidth(150);\r
123         buttons.alignLeft(cnvs.getWidth() - 152).alignTop(cnvs.getHeight() - 18*4);\r
124         Drawable::billboard.append(buttons);\r
125 \r
126         std::string path[3];\r
127         Letters pathname[3];\r
128         std::string tmps;\r
129         int error, view;\r
130 \r
131         double Z[SHADER_ARG_MAX];\r
132         for(int i=0; i<SHADER_ARG_MAX; i++) Z[i] = 0.0;\r
133 \r
134 \r
135         Widgets::Slider slider;\r
136         slider.set("test", Interval(0,10), 1, 0.1);\r
137 \r
138         Font::default_font.family[0] = L"meiryo";\r
139         Letters let;\r
140         let.font.size = 30;\r
141         let.fill = Color::green;\r
142         let.setString("\93ú\96{\8cê ");\r
143 \r
144 \r
145                         try {\r
146                                 path[1] = File::decodePath("%APP%shader_sample/pallet.txt");//Widgets::Dialog::getOpenFileName();\r
147                                 cacheShaderImage(path[1]);\r
148                                 path[1].append("   OK ");\r
149                                 pathname[1].fill = Color::yellow;\r
150                                 error = 1;\r
151                                 view = 1;\r
152                                 for(int i=0; i<image.orig_args.size(); i++) {\r
153                                         //tmps.assign(image.orig_args[i]).append(" ");\r
154                                         //sliders[i].slide.label.setString(tmps.c_str());\r
155                                         //sliders[i].active = true;\r
156                                 }\r
157                                 for(int i=image.orig_args.size(); i<SHADER_ARG_MAX; i++) {\r
158                                         //sliders[i].active = false;\r
159                                 }\r
160                         } catch(Exception e) {\r
161                                 path[1] = e.to_s();\r
162                                 pathname[1].fill = Color::red;\r
163                                 error = -1;\r
164                         }\r
165                         pathname[1].setString(path[1].c_str());\r
166 \r
167                         try {\r
168                                 path[2] = File::decodePath("%APP%flower_png24.png");//Widgets::Dialog::getOpenFileName();\r
169                                 dummy_image.load(path[2]);\r
170                                 shadered_image.load(path[2]);\r
171                                 shadered_image.convert(Image::RGBA);\r
172                                 shadered_image.rect(Psychlops::Rectangle(100,300),Color::white);\r
173                                 shadered_image.cache();\r
174                                 path[2].append("   OK ");\r
175                                 pathname[2].fill = Color::yellow;\r
176                                 error = 1;\r
177                         } catch(Exception e) {\r
178                                 path[2] = e.to_s();\r
179                                 pathname[2].fill = Color::red;\r
180                                 error = -1;\r
181                         }\r
182                         pathname[2].setString(path[2].c_str());\r
183 \r
184         image.params.set(16,16);\r
185         image.params.clear(Color::blue);\r
186         image.params.cache();\r
187 \r
188         double l;\r
189 \r
190         while(!Input::get(Keyboard::esc)) {\r
191                 Display::clear();\r
192 \r
193                 if(Keyboard::one.pushed()) l = 0;\r
194                 if(Keyboard::two.pushed()) l = 0.2;\r
195                 if(Keyboard::three.pushed()) l = 0.4;\r
196                 if(Keyboard::four.pushed()) l = 0.6;\r
197                 if(Keyboard::five.pushed()) l = 0.8;\r
198                 if(Keyboard::six.pushed()) l = 1;\r
199 \r
200 \r
201                 shadered_image.rect(Psychlops::Rectangle(100,300),Color(l));\r
202                 shadered_image.cache();\r
203                 shadered_image.centering();\r
204                 image.draw(shadered_image, Z, 3, *Display::the_canvas);\r
205 \r
206                 for(int i=0; i<3; i++) {\r
207                         pathname[i].font.size = 15;\r
208                         pathname[i].locate(loader[i].area.getLeft() - 20, loader[i].area.getBottom()-2).align = Letters::TEXT_ALIGN_RIGHT;\r
209                         pathname[i].draw();\r
210                 }\r
211                 if(!error_message.empty()) cnvs.msg(error_message, 200,20,Color::yellow);\r
212 \r
213                 slider.centering().shift(-200,-300).draw();\r
214                 let.centering().shift(-300,-300).draw();\r
215                 cnvs.flip();\r
216                 if(AppState::shouldBeClose) return;\r
217         }\r
218 \r
219 }\r
220 \r
221 \r
222 /*\r
223 \r
224 \r
225 / Shape from Shading\r
226 // Ramachandran, V.S. (1988) Perception of shape from shading Nature 331, 163-166.\r
227 ///+ Prefix\r
228 //// Include Psychlops Package\r
229 #include <psychlops.h>\r
230 #include <platform/win32/psychlops_app_tweak_Win32.h>\r
231 using namespace Psychlops;    // Initially developed with Psychlops Win32 1.5.3 / 20110311\r
232 ///- Prefix\r
233 \r
234 \r
235 \r
236 \r
237 ///+ Stimulus drawing function\r
238 //// A function for stimulus drawing (main body)\r
239 void ShapeFromShading()\r
240 {\r
241         Canvas display(Canvas::window); //Prepare drawing window\r
242 \r
243         HWND d = Psychlops::DebugTweakTool::getRawWindowHandle(display);\r
244 \r
245         ///+ Preperation\r
246         //// Declare and initi\r
247         Widgets::SelectBox dummy(100);\r
248         Widgets::SelectBox chr[2];\r
249         char alphabet[4] = { ' ', ' ', '\0', '\0' };\r
250         for(int i=0; i<2; i++) {\r
251                 chr[i].set(50,50);\r
252                 for(int c=0; c<26; c++) {\r
253                         alphabet[0] = c+65+i*32;\r
254                         chr[i].append(alphabet);\r
255                 }\r
256                 chr[i].centering().shift(i*100,0);\r
257                 chr[i].setSelected(0);\r
258         }\r
259 \r
260         double lim;\r
261         Interval rng;\r
262         Widgets::Dial slider;\r
263         //slider.link(lim, rng, 0.1);\r
264         //slider.set("luminance", 0<=rng<=1, 0.125);\r
265         //slider.centring();\r
266 \r
267         char initial[4] = { ' ', ' ', '\0', '\0' };\r
268         ///- Preperation\r
269 \r
270         ///+ Main loop\r
271         //// Displaying stimuli\r
272         while(!Input::get(Keyboard::esc)) {\r
273 \r
274                 display.clear(Color(slider));\r
275                 for(int i=0; i<2; i++) chr[i].draw();\r
276 \r
277                 initial[0] = chr[0].getSelected()+65;\r
278                 initial[1] = chr[1].getSelected()+97;\r
279                 display.msg(initial, 300,300);\r
280                 slider.draw();\r
281                 display.flip();\r
282 \r
283         }\r
284         ///- Main loop\r
285 }\r
286 ///- Stimulus drawing function\r
287 \r
288 \r
289 ///+ Main function for demo circumstances\r
290 void psychlops_main() {\r
291         ///+ Demo circumstances\r
292         //// Spells for run demonstration circumstances\r
293         Procedure p;\r
294         p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
295         p.setProcedure(ShapeFromShading);  //The argument name is a name of drawing function.\r
296         p.run();\r
297         ///- Demo circumstances\r
298 }\r
299 ///- Main function for demo circumstances\r
300 \r
301 */\r
302 \r
303 /*\r
304 #include <psychlops.h>\r
305 using namespace Psychlops;\r
306 \r
307 \r
308 void loadImageSequence(Image *target, int number, const std::string &base_path, const std::string &prefix, const std::string &postfix)\r
309 {\r
310         std::stringstream filename;\r
311         for(int i=0; i<number; i++) {\r
312                 filename.str("");\r
313                 filename << base_path << "/" << prefix << i << postfix;\r
314                 target[i].load(filename.str());\r
315         }\r
316 }\r
317 \r
318 void psychlops_main() {\r
319         Canvas window(Canvas::window, Display::secondary);\r
320         //Canvas window(Canvas::fullscreen, Display::secondary);\r
321         //Canvas window(1024,768,32,60.0, Display::secondary);\r
322 \r
323         Procedure p;\r
324 \r
325 //      Trigger trigger(new Devices::AnalogInput_NIDAQmx);\r
326 \r
327         Psychlops::Rectangle rect;\r
328         rect.set(200,100).shift(60,100);\r
329         rect.stroke = Stroke(Color::red, 1, Stroke::SOLID);\r
330 \r
331         Widgets::Button text(L"test");\r
332         text.centering(100,100);\r
333         //window.eventroot.append(text);\r
334         //text.tabStop();\r
335 \r
336         double v = 0, w = 100;\r
337         Interval rng;\r
338         Independent << v | "dfdsfdsv" | 0<=rng<=4 | 1;\r
339         Independent.append(w).set("another", 0<=rng<=200, 2);\r
340         Widgets::Slider slider(Independent["dfdsfdsv"]), slider2(Independent[1]);\r
341         slider.centering();\r
342         slider2.centering().shift(100,100);\r
343 \r
344         Image img[5];\r
345         loadImageSequence(img, 5, "D:\\Users\\hskwk\\Documents\\Develop\\Psychlops\\cpp\\trunk\\win32gl\\test\\", "D1_low", ".png");\r
346 \r
347         img[0] -= img[1];\r
348 \r
349         Psychlops::Rectangle rect22(100,1000);\r
350         rect22.fill = Color::green;\r
351         rect22.centering();\r
352 \r
353         Psychlops::Ellipse ell(200, 300);\r
354         ell.shift(300,200);\r
355         ell.resize(100,50);\r
356 \r
357         Widgets::SelectBox box;\r
358         box.append(L"ABCDEFG");\r
359         box.set(200,30);\r
360         box.centering().shift(200,200);\r
361 \r
362     while(!Keyboard::esc.pushed()){\r
363         window.clear(Color::black);\r
364                 img[(int)v].centering().draw();\r
365 \r
366                 text.draw();\r
367                 //Events::Focus fo;\r
368                 //text.bubble(fo);\r
369 \r
370                 slider.draw();\r
371                 slider2.draw();\r
372 Display::ellipse(rect22, Color::green);\r
373                 box.draw();\r
374 \r
375 window.var(Mouse::uniX,200,200);\r
376 window.var(Mouse::uniY,200,240);\r
377 \r
378 \r
379 \r
380                 //rect22.centering(Mouse::position).draw();\r
381                 //rect22.centering(Mouse::position).draw();\r
382                 //rect22.centering(window.mouse()).draw();\r
383 \r
384 \r
385 int n = 60; // \90ü\82Ì\96{\90\94\r
386 int r = 100; // \8aO\90Ú\89~\82Ì\94¼\8ca\r
387 double angle1, angle2;\r
388 Psychlops::Point center = window.getCenter(); // \91½\8ap\8c`\82Ì\92\86\90S\r
389 for(int i=0; i<n; i++)\r
390 {\r
391         angle1 = ( (double)i   /n) *2*PI; // \92¸\93_\82Ì\8ap\93x\82ð\8cv\8eZ\r
392         window.line( center.x + r*cos(angle1), center.y + r*sin(angle1),\r
393                      center.x, center.y,\r
394                      Color::red);\r
395         // \91½\8ap\8c`\82Ì\92\86\90S\82©\82ç\92¸\93_\82Ö\82Ì\91\8a\91Î\93I\82È\88Ê\92u\82ð\8ew\92è\82µ\81A\90ü\82ð\95`\82­\r
396 }\r
397 \r
398 \r
399 \r
400         window.flip();\r
401     }\r
402 \r
403 }\r
404 \r
405 \r
406 /*\r
407 #include <psychlops.h>\r
408 using namespace Psychlops;\r
409 \r
410 const int StimKind=3;// Stimuluskind:: 1:MDC  2:TDC  3:LDC\r
411 \r
412 #define StimulusWidth 160\r
413 #define StimulusHeight 160\r
414 \r
415 #define BlankBeforeStimulus 10\r
416 #define StimulusDuration 10\r
417 #define r_duration 30\r
418 \r
419 #define LineNumber 200\r
420 #define LineWidth 2\r
421 \r
422 #define DotLife 4\r
423 #define DotNumber 300\r
424 int DotSpeed=1;\r
425 \r
426 const int SIZE_=100;\r
427 \r
428 const int ATT = 2, LAG=2,  ITERATION_PER_A_CONDITION= 10;\r
429 const int trial_max = ATT * LAG* ITERATION_PER_A_CONDITION;\r
430 int Attribute[ATT]={0, 1};\r
431 int SATlag[LAG] = {60,120};//{5, 10, 15, 20, 25, 30, 40, 50, 100, 150};\r
432 \r
433 unsigned int condition[trial_max];\r
434 int result[trial_max], resultRT[trial_max];\r
435 \r
436 int condition_att[trial_max], condition_lag[trial_max],number[trial_max];\r
437 Psychlops::Rectangle fixation,fixation2,fication3;\r
438 \r
439 Range row, col;\r
440 Matrix StimulusFieldA(StimulusWidth, StimulusHeight), StimulusFieldB(StimulusWidth, StimulusHeight), StimulusField(StimulusWidth, StimulusHeight);\r
441 Matrix Dot(DotNumber,3);\r
442 \r
443 const int WIDTH=1024, HEIGHT=768;\r
444 const int StimLU=WIDTH*0.5-StimulusWidth*0.5, StimRB=HEIGHT*0.5-StimulusHeight*0.5;\r
445 \r
446 double t1, t2;\r
447 Clock timer;\r
448 \r
449 //SAT procedure\r
450 int maximum;\r
451 int SAT_frag = 0, SAT_counter = 0;\r
452 int miss_trial[trial_max];\r
453 //\r
454 \r
455 void procedure();\r
456 void StimulusDraw();\r
457 \r
458 void DrawLDC(int trial_now, int attribute);\r
459 void DrawODC(int trial_now, int attribute);\r
460 void DrawMDC(int trial_now, int attribute);\r
461 \r
462 void Response(int trial_now);\r
463 void Recondtion();\r
464 void Data_save();\r
465 void EXPabort();\r
466 \r
467 void psychlops_main()\r
468 {\r
469         //Canvas display(Canvas::fullscreen);\r
470         Canvas display(Canvas::window);\r
471 \r
472         display.setGammaValue(2.26459,2.29437,2.12506);//CRT_21gs_090920\r
473         procedure();\r
474 }\r
475 \r
476 void procedure() {\r
477         Psychlops::Rectangle blank;\r
478         blank.set(WIDTH,HEIGHT).centering().setColor(Color::black);\r
479 \r
480         for (int i=0; i<trial_max; i++){condition[ i ] = i;}\r
481         Math::shuffle(condition, trial_max);\r
482 \r
483         //initialize\r
484         for(int i=0; i<trial_max; i++) {\r
485                 number[ i ] = i+1;\r
486                 condition_att[ i ] = Attribute[ condition[ i ] %ATT];\r
487                 condition_lag[ i ] = SATlag[ (condition[ i ]/ATT) %LAG];\r
488 \r
489                 result[ i ] = -1;\r
490         }\r
491 \r
492         //for(int i=0; i<trial_max; i++) {std::cout<<condition_att[ i ]<<" "<<condition_lag[ i ]<<std::endl;}\r
493 \r
494         while(!Keyboard::spc.pushed()) {\r
495                 Display::clear();\r
496                 Display::message("push space key to start",400,380,Color::white);\r
497                 Display::flip();\r
498         }\r
499         StimulusDraw();\r
500 }\r
501 \r
502 void StimulusDraw(){\r
503         // Stimuluskind:: 1: MDC 2: ODC 3:LDC\r
504 \r
505         fixation.set(5,5).centering().setColor(Color::yellow);\r
506         fixation2.set(10,10).centering().setColor(Color::yellow);\r
507 \r
508         if (SAT_frag ==0){maximum = trial_max;}\r
509         if (SAT_frag ==1){\r
510                 maximum = SAT_counter;\r
511                 while (!Keyboard::spc.pushed()) {\r
512                         Display::clear(0.0);\r
513                         Display::message(" Please push spc key to restart",400,380,Color::white);\r
514                         fixation.display();Display::flip();\r
515                 }\r
516                 SAT_counter = 0;\r
517         }\r
518 \r
519         std::cout<<"trials = "<<maximum<<std::endl;\r
520 \r
521         for(int trial_now=0; trial_now<maximum; trial_now++){\r
522 \r
523                 if (Keyboard::esc.pushed()){EXPabort();}\r
524 \r
525                 //Blank frame\r
526                 for(int i=0; i<BlankBeforeStimulus; i++) {\r
527                         Input::refresh();\r
528                         //Keyboard::pad1.pushed();      Keyboard::pad3.pushed();\r
529                         Display::clear(0.0);fixation.display();Display::flip();\r
530                 }\r
531 \r
532                 //DrawStimulus\r
533                 if (SAT_frag ==0){\r
534                         switch(StimKind){\r
535                                 case 1: DrawMDC(trial_now, condition_att[trial_now]); break;\r
536                                 case 2: DrawODC(trial_now, condition_att[trial_now]); break;\r
537                                 case 3: DrawLDC(trial_now, condition_att[trial_now]); break;\r
538                         }\r
539                         for(int i=0; i<condition_lag[trial_now]; i++) {\r
540                                 //Keyboard::pad1.pushed();      Keyboard::pad3.pushed();\r
541                                 Display::clear(0.0);fixation.display();Display::flip();\r
542                         }\r
543                 }\r
544                 else {\r
545                         switch(StimKind){\r
546                                 case 1: DrawMDC(trial_now, condition_att[ miss_trial[trial_now] ]); break;\r
547                                 case 2: DrawODC(trial_now, condition_att[ miss_trial[trial_now] ]); break;\r
548                                 case 3: DrawLDC(trial_now, condition_att[ miss_trial[trial_now] ]); break;\r
549                         }\r
550                         for(int i=0; i<condition_lag[ miss_trial[trial_now] ]; i++) {\r
551                                 //Keyboard::pad1.pushed();      Keyboard::pad3.pushed();\r
552                                 Display::clear(0.0);fixation.display();Display::flip();\r
553                         }\r
554                 }\r
555 \r
556                 Response(trial_now);\r
557         }\r
558 \r
559         //\83f\81[\83^\82©\82ç\8e¸\94s\8e\8e\8ds\82ð\8c\9f\8dõ\r
560         for(int trial_now=0; trial_now<trial_max; trial_now++){\r
561                 SAT_frag = 0;\r
562                 std::cout<<result[trial_now]<<std::endl;\r
563                 if (result[trial_now] == -1){SAT_frag =1;break;}\r
564         }\r
565 \r
566         std::cout<<"SAT_frag = "<<SAT_frag<<std::endl;\r
567         if (SAT_frag == 0){Data_save();}\r
568         else {Keyboard::pad5.pushed();Recondtion();}\r
569 }\r
570 \r
571 void Response(int trial_now){\r
572 \r
573         //Keyboard::pad1.pushed();      Keyboard::pad3.pushed();\r
574         Input::refresh();\r
575 \r
576 \r
577         for(int i=0; i<r_duration; i++) {\r
578                 Display::clear(0.0);fixation2.display();Display::flip();\r
579 \r
580                 if (Keyboard::esc.pushed()){EXPabort();}\r
581 \r
582                 if (SAT_frag ==0){\r
583                         if( Keyboard::pad1.pushed())  {result[trial_now]= (1-condition_att[trial_now]); break;}// white or Leftup response\r
584                         if( Keyboard::pad3.pushed())  {result[trial_now]= (condition_att[trial_now]);break;}// black or Rightup response\r
585                 }\r
586                 if (SAT_frag ==1){\r
587                         result[ miss_trial[trial_now] ] = -1;\r
588                         if( Keyboard::pad1.pushed())  {result[ miss_trial[trial_now] ]= (1-condition_att[ miss_trial[trial_now] ]); break;}// white or Leftup response\r
589                         if( Keyboard::pad3.pushed())  {result[ miss_trial[trial_now] ]= (condition_att[ miss_trial[trial_now] ]);break;}// black or Rightup response\r
590                 }\r
591 \r
592         }\r
593         if (SAT_frag ==0){std::cout<<trial_now<<" condition  = "<<condition_att[trial_now]<<" result = "<<result[trial_now]<<std::endl;}\r
594         if (SAT_frag ==1){std::cout<<miss_trial[trial_now]<<" condition  = "<<condition_att[miss_trial[trial_now]]<<" result = "<<result[miss_trial[trial_now]]<<std::endl;}\r
595 \r
596         if( result[trial_now] == -1 && SAT_frag ==0){\r
597                 miss_trial[SAT_counter] =trial_now;SAT_counter+=1;\r
598         }\r
599         if( result[ miss_trial[trial_now] ] == -1 && SAT_frag ==1){\r
600                 miss_trial[SAT_counter] =miss_trial[trial_now];SAT_counter+=1;\r
601         }\r
602 \r
603         std::cout<<"SAT_counter = "<<SAT_counter<<std::endl;\r
604 }\r
605 \r
606 void Recondtion(){\r
607         const int tmp_n= SAT_counter;\r
608         int recondition[tmp_n];\r
609 \r
610         for (int i=0; i<SAT_counter; i++){recondition[ i ] = miss_trial[ i ];}\r
611         if(SAT_counter >0){Math::shuffle(recondition, SAT_counter);}\r
612 \r
613         for (int i=0; i<SAT_counter; i++){miss_trial[ i ]= recondition[ i ];}\r
614 \r
615         StimulusDraw();\r
616 }\r
617 \r
618 void Data_save(){\r
619 \r
620         Input::refresh();\r
621         switch(StimKind){\r
622                 case 1: Data::savearray("MDCline_att_%TIME_.txt", "Num\tDirection\tLag\tjudge", trial_max, number, condition_att, condition_lag,result);break;\r
623                 case 2: Data::savearray("ODCline_att_%TIME_.txt", "Num\tOrientation\tLag\tjudge", trial_max, number, condition_att, condition_lag, result);break;\r
624                 case 3: Data::savearray("LDCline_att_%TIME_.txt", "Num\tLuminance\tLag\tjudge", trial_max, number, condition_att, condition_lag,result);break;\r
625         }\r
626 \r
627         while(!Keyboard::spc.pushed()) {\r
628                 Display::clear();\r
629                 Display::message("thanks",500,380,Color::white);\r
630                 Display::flip();\r
631         }\r
632 }\r
633 \r
634 \r
635 void DrawLDC(int trial_now, int attribute){\r
636         int XS, YS, XE, YE;\r
637         int i,j;\r
638 \r
639         StimulusField=StimulusFieldA;\r
640 \r
641         //Init Stimulus\r
642         for (i=1; i<LineNumber+1; i++){\r
643                 Dot(i,1)=1+rand()%(StimulusWidth-LineWidth);\r
644                 Dot(i,2)=1+rand()%(StimulusHeight-LineWidth);\r
645                 Dot(i,3)=DotLife;\r
646         }\r
647 \r
648         //Draw Stimulus\r
649         int Direction;\r
650         Direction=(rand()%2)*2-1;\r
651 \r
652         for(i=0; i<StimulusDuration; i++){\r
653                 Display::clear();\r
654                 //fixation.display();\r
655 \r
656                 for (j=1; j<LineNumber+1; j++){\r
657                         XS=Dot(j,1)-1; // Convert to Origin (0,0)\r
658                         YS=Dot(j,2)-1; // Convert to Origin (0,0)\r
659 \r
660                         int hv;\r
661                         hv=(rand()%2)*2-1;\r
662                         if(StimulusField(XS+1, YS+1)==condition_att[trial_now]){\r
663                                 if (hv==1){     XE=XS+LineWidth; YE=YS;}\r
664                                 else {XS=XS-LineWidth; YS=YS-LineWidth; XE=XS; YE=YS-LineWidth;}\r
665                                 Display::line(XS+StimLU, YS+StimRB, XE+StimLU, YE+StimRB, 0.9);\r
666                         }\r
667                         else{\r
668                                 if (hv==1){XS=XS-LineWidth; YS=YS-LineWidth; XE=XS+LineWidth; YE=YS;}\r
669                                 else {XE=XS; YE=YS-LineWidth;}\r
670                                 Display::line(XS+StimLU, YS+StimRB, XE+StimLU, YE+StimRB, 0.1);\r
671                         }\r
672 \r
673                         Dot(j,3)--;\r
674 \r
675                         if(Dot(j,3)<1){\r
676                                 Dot(j,1)=1+rand()%(StimulusWidth-LineWidth);\r
677                                 Dot(j,2)=1+rand()%(StimulusHeight-LineWidth);\r
678                                 Dot(j,3)=DotLife;\r
679                         }\r
680 \r
681                 }\r
682 \r
683                 Display::flip();\r
684         }\r
685 \r
686 }\r
687 \r
688 \r
689 void DrawODC(int trial_now, int attribute){\r
690         int XS, YS, XE, YE;\r
691         int i,j;\r
692 \r
693         //Init Stimulus\r
694         for (i=1; i<LineNumber+1; i++){\r
695                 Dot(i,1)=1+rand()%(StimulusWidth-LineWidth);\r
696                 Dot(i,2)=1+rand()%(StimulusHeight-LineWidth);\r
697                 Dot(i,3)=DotLife;\r
698         }\r
699 \r
700         //Draw Stimulus\r
701         int Direction;\r
702         Direction=(rand()%2)*2-1;\r
703 \r
704         for(i=0; i<StimulusDuration; i++){\r
705                 Display::clear();\r
706                 //fixation.display();\r
707 \r
708                 for (j=1; j<LineNumber+1; j++){\r
709                         XS=Dot(j,1)-1; // Convert to Origin (0,0)\r
710                         YS=Dot(j,2)-1; // Convert to Origin (0,0)\r
711 \r
712                         if(StimulusField(XS+1, YS+1)==condition_att[trial_now]){\r
713                                 XE=XS+Direction*LineWidth; YE=YS+Direction*LineWidth;\r
714                         }\r
715                         else{\r
716                                 XE=XS+Direction*LineWidth; YE=YS-Direction*LineWidth;\r
717                         }\r
718 \r
719                         Display::line(XS+StimLU, YS+StimRB, XE+StimLU, YE+StimRB, 1.0);\r
720                         Dot(j,3)--;\r
721 \r
722                         if(Dot(j,3)<1){\r
723                                 ///*LifeTime Event\r
724                                 Dot(j,1)=1+rand()%(StimulusWidth-LineWidth);\r
725                                 Dot(j,2)=1+rand()%(StimulusHeight-LineWidth);\r
726                                 Dot(j,3)=DotLife;\r
727                         }\r
728                 }\r
729                 Display::flip();\r
730         }\r
731 \r
732 }\r
733 \r
734 \r
735 void DrawMDC(int trial_now, int attribute){\r
736 \r
737         int i,j;\r
738         //Set StimulusField\r
739 \r
740     //Init Stimulus\r
741         int X, Y;\r
742         for (i=1; i<DotNumber+1; i++){\r
743                 Dot(i,1)=1+rand()%(StimulusWidth);\r
744                 Dot(i,2)=1+rand()%(StimulusHeight);\r
745                 Dot(i,3)=DotLife;\r
746         }\r
747 \r
748 \r
749         //Draw Stimulus\r
750         int orientation =1;\r
751         DotSpeed=1;\r
752 \r
753         for(i=0; i<StimulusDuration; i++){\r
754                 Display::clear();\r
755 \r
756                 //Draw Signal\r
757                 for (j=1; j<DotNumber+1; j++){\r
758                         X=Dot(j,1)-1; // Convert to Origin (0,0)\r
759                         Y=Dot(j,2)-1; // Convert to Origin (0,0)\r
760 \r
761                         Display::pix(X+StimLU, Y+StimRB,1.0);\r
762                         //Display::pix(X+StimLU, Y+StimRB,1.0);\r
763                         Dot(j,3)--;\r
764 \r
765                         if(Dot(j,3)>1){\r
766                                 switch(condition_att[trial_now]){\r
767                                         case 0 : Dot(j,1)-=DotSpeed; Dot(j,2)-=DotSpeed;break;\r
768                                         case 1 : Dot(j,1)+=DotSpeed; Dot(j,2)+=DotSpeed;break;\r
769                                 }\r
770 \r
771                                 //* Validation of Stimulus area\r
772                                 if(Dot(j,1)>StimulusWidth){\r
773                                         //if(orientation==1){Dot(j,1)-=StimulusWidth*0.5;}\r
774                                         if(orientation==1){Dot(j,1)-=StimulusWidth*0.5;}\r
775                                         else{Dot(j,1)-=StimulusWidth;}\r
776                                 }\r
777                                 if(Dot(j,1)<1){\r
778                                         if(orientation==1){Dot(j,1)+=StimulusWidth*0.5;}\r
779                                         else{Dot(j,1)+=StimulusWidth;}\r
780                                 }\r
781                                 if(Dot(j,2)>StimulusWidth){\r
782                                         if(orientation==1){Dot(j,2)-=StimulusHeight;}\r
783                                         else{Dot(j,2)-=StimulusHeight*0.5;}\r
784                                 }\r
785                                 if(Dot(j,2)<1){\r
786                                         if(orientation==1){Dot(j,2)+=StimulusHeight;}\r
787                                         else{Dot(j,2)+=StimulusHeight*0.5;}\r
788                                 }\r
789 \r
790                         }\r
791                         else{\r
792                                 ///*LifeTime Event\r
793                                 Dot(j,1)=1+rand()%(StimulusWidth);\r
794                                 Dot(j,2)=1+rand()%(StimulusHeight);//Math::random(StimHeight);\r
795                                 Dot(j,3)=DotLife;\r
796                         }\r
797                 }\r
798                 Display::flip();\r
799         }\r
800 }\r
801 void EXPabort(){\r
802         while(!Keyboard::pad5.pushed()){\r
803                 Display::clear();\r
804                 Display::message("Experiment is terminated. push 5 key to quit",500,380,Color::white);\r
805                 Display::flip();\r
806         }\r
807         exit(0);\r
808 }\r
809 */\r