OSDN Git Service

12313
authorHOSOKAWA Kenchi <hskwk@users.sourceforge.jp>
Tue, 22 Mar 2011 13:54:13 +0000 (22:54 +0900)
committerHOSOKAWA Kenchi <hskwk@users.sourceforge.jp>
Tue, 22 Mar 2011 13:54:13 +0000 (22:54 +0900)
dev4/psychlops/core/device/hid.cs
dev4/psychlops/core/graphic/canvas.cs
dev4/psychlops/core/graphic/image.cs
dev4/psychlops/core/math/util.cs
dev4/psychlops/extention/compatibility/compatibility.cs
test4/PsychlopsMain.cs

index b71caeb..ff824ae 100644 (file)
@@ -52,6 +52,9 @@ namespace Psychlops
                static public int y { get { return (int)position_.y; } }\r
                static public Point wheelDelta { get { return wheelDelta_; } }\r
 \r
+               static public void show() { }\r
+               static public void hide() { }\r
+\r
                static public void Canvas_MousePos(object sender, MouseEventArgs e)\r
                {\r
                        System.Windows.Point p = e.GetPosition(_prime);\r
index 5b58b03..4d65ec4 100644 (file)
@@ -651,7 +651,22 @@ namespace Psychlops
                        api_canvas = default_api_canvas;\r
                        initialize(500, 500);\r
                }\r
-               public Canvas(Mode mod) : base()\r
+               public Canvas(Mode mod)\r
+                       : base()\r
+               {\r
+                       panel = default_panel;\r
+                       api_canvas = default_api_canvas;\r
+                       initialize(500, 500);\r
+               }\r
+\r
+               public Canvas(int wid, int hei, Mode mod, Display.DisplayName name)\r
+               {\r
+                       panel = default_panel;\r
+                       api_canvas = default_api_canvas;\r
+                       initialize(500, 500);\r
+               }\r
+               public Canvas(Mode mod, Display.DisplayName name)\r
+                       : base()\r
                {\r
                        panel = default_panel;\r
                        api_canvas = default_api_canvas;\r
index c56ea61..64f3c1e 100644 (file)
@@ -38,6 +38,11 @@ namespace Psychlops{
                        self_rect = new Rectangle(wid, hei);\r
                        initialize__(wid, hei);\r
                }\r
+               public Image(double wid, double hei)\r
+               {\r
+                       self_rect = new Rectangle(Math.round(wid), Math.round(hei));\r
+                       initialize__((int)Math.round(wid), (int)Math.round(hei));\r
+               }\r
 \r
                public Image set(int wid, int hei)\r
                {\r
@@ -45,6 +50,12 @@ namespace Psychlops{
                        initialize__(wid, hei);\r
                        return this;\r
                }\r
+               public Image set(double wid, double hei)\r
+               {\r
+                       self_rect = new Rectangle(Math.round(wid), Math.round(hei));\r
+                       initialize__((int)Math.round(wid), (int)Math.round(hei));\r
+                       return this;\r
+               }\r
 \r
                public Figure shift(Point p)\r
                {\r
@@ -66,6 +77,30 @@ namespace Psychlops{
                        buffer.SetPixel(x, y, col);\r
                }\r
 \r
+               public void release()\r
+               {\r
+               }\r
+\r
+               public void cache(bool on_off = true)\r
+               {\r
+               }\r
+\r
+               public void alpha(int x, int y, double a)\r
+               {\r
+                       buffer.SetPixel(x, y, (byte)(a*255), buffer.GetPixel(x, y));\r
+               }\r
+\r
+               public void clear(Color col)\r
+               {\r
+                       for (int y = 0; y < height; y++)\r
+                       {\r
+                               for (int x = 0; x < width; x++)\r
+                               {\r
+                                       pix(x, y, col);\r
+                               }\r
+                       }\r
+               }\r
+\r
 \r
                public void field(System.Func<int, int, System.Windows.Media.Color> func)\r
                {\r
@@ -104,6 +139,15 @@ namespace Psychlops{
                public double getHcenter() { return width / 2.0; }\r
                public double getVcenter() { return height / 2.0; }\r
 \r
+               public double left { get { return datum.x; } }\r
+               public double right { get { return datum.x + width; } }\r
+               public double top { get { return datum.y; } }\r
+               public double bottom { get { return datum.y + height; } }\r
+               public double getLeft() { return left; }\r
+               public double getRight() { return right; }\r
+               public double getTop() { return top; }\r
+               public double getBottom() { return bottom; }\r
+\r
        }\r
 \r
 \r
index 20886e0..f1aa817 100644 (file)
@@ -85,6 +85,10 @@ namespace Psychlops
                {\r
                        return System.Math.Sqrt(x);\r
                }\r
+               public static double pow(double x, double y)\r
+               {\r
+                       return System.Math.Pow(x,y);\r
+               }\r
                public static double exp(double x)\r
                {\r
                        return System.Math.Exp(x);\r
index 50e4f98..fe1889f 100644 (file)
@@ -62,6 +62,9 @@ namespace Psychlops
 \r
        public static class Display\r
        {\r
+               public enum DisplayName { primary, secondary }\r
+               public static DisplayName primary = DisplayName.primary, secondary = DisplayName.secondary;\r
+\r
                public static void pix(int x, int y, Color col) { Main.canvas.pix(x, y, col); }\r
                public static void line(Line drawee) { Main.canvas.line(drawee); }\r
                public static void rect(Rectangle drawee) { Main.canvas.rect(drawee); }\r
index 71d18a5..c0b941a 100644 (file)
-\r
-using Psychlops;\r
+//Two types of plaid motion\r
+//E. H. Adelson and J. A. Movshon (1982).\r
+//Phenomenal coherence of moving visual patterns. Nature 300, 523-525\r
 \r
-namespace PsychlopsSilverlightApp\r
-{\r
+///+ Prefix\r
+//// Include Psychlops Package\r
+using Psychlops;\r
 \r
-       public class PsychlopsMain\r
+       namespace PsychlopsSilverlightApp\r
        {\r
 \r
-               public void psychlops_main()\r
+               public class PsychlopsMain\r
                {\r
-                       Psychlops.ColorSpaces.CIERGB rgb = new Psychlops.ColorSpaces.CIERGB { R = 1, G = 1, B = 1 };\r
-                       var xyz = rgb.convertToCIEXYZ();\r
+                       ///- Prefix\r
 \r
-                       Canvas window = new Canvas(300,300);\r
-\r
-                       Rectangle figure = new Rectangle();\r
-                       figure.set(100, 100);\r
-                       figure.fill = new Color(1, 1, 1);\r
-                       figure.centering().shift(0, 0);\r
+                       ///+ Global\r
+                       // Struct for component paremeters\r
+                       struct component\r
+                       {\r
+                               public double contrast;\r
+                               public double orientation;\r
+                               public double lambda;\r
+                               public double tf;\r
+                       }\r
+                       ///- Global\r
 \r
-                       int frame = 0;\r
-                       int looming_direction = 1, motion_dir = 1;\r
+                       ///+ Stimulus drawing function\r
+                       //// A function for stimulus drawing (main body)\r
+                       void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)\r
+                       {\r
+                               double _xp, _xp2, col1, col2;\r
+                               double contrast1, contrast2;\r
+                               double imageheight, imagewidth;\r
 \r
+                               contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);\r
+                               contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);\r
 \r
-                       while (!Keyboard.esc.pushed())\r
-                       {\r
-                               window.clear(0);\r
+                               imageheight = img[0].getHeight();\r
+                               imagewidth = img[0].getWidth();\r
 \r
-                               if (frame % 30 == 0)\r
-                               {\r
-                                       looming_direction = looming_direction * -1;\r
+                               for(int frame=start; frame<start+maxframe+1; frame++){\r
+                                       //Display.progressbar(frame, maxframe+1);\r
+                                       //img[frame].convert(Image::RGBA);\r
+                                       for(int i=0; i<imagewidth; i++){\r
+                                               for(int j=0; j<imageheight; j++){\r
+                                                       _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);\r
+                                                       _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);\r
+                                                       col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);\r
+                                                       col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);\r
+                                                       img[frame].pix(i,j,new Color(col1+col2+bg_lum));\r
+                                                       img[frame].alpha(i,j,alpha);\r
+                                               }\r
+                                       }\r
+                                       //img[frame].cache();\r
                                }\r
-                               if (frame % 90 == 0)\r
+                       }\r
+\r
+                       ///+ Stimulus drawing function\r
+                       //// A function for stimulus drawing (main body)\r
+                       void drawplaid() {\r
+                               Canvas display = new Canvas(Canvas.window);\r
+                               ///+ Preperation\r
+                               //// Declare and initialize local variables\r
+                               int rect_size = 150;\r
+                               double rect_lum  = 0.5;\r
+                               double bg_lum    = 0.2;\r
+                               double duration = 400;\r
+\r
+                               double[] lambda = new double[2], contrast = new double[2], tf = new double[2];\r
+                               double center_orientation = 0.0;\r
+                               Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);\r
+                               Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);\r
+                               Image envelope = new Image(), envelope_small = new Image();\r
+\r
+                               for(int i=0; i<120; i++)\r
                                {\r
-                                       motion_dir *= -1;\r
+                                       movie[0, i].set(rect_size, rect_size);\r
+                                       movie[1, i].set(rect_size, rect_size);\r
+                                       component_movie[0, i].set(rect_size/2, rect_size/2);\r
+                                       component_movie[1, i].set(rect_size/2, rect_size/2);\r
+                                       component_movie[2, i].set(rect_size/2, rect_size/2);\r
+                                       component_movie[3, i].set(rect_size/2, rect_size/2);\r
                                }\r
+                               envelope.set(rect_size, rect_size);\r
+                               envelope_small.set(rect_size/2, rect_size/2);\r
+\r
+                               Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();\r
+                               let1.str = "Component1";\r
+                               let2.str = "Component2";\r
+                               let3.str = "Superposition";\r
+                               let1.centering().shift(-rect_size*1.25, -rect_size);\r
+                               //let1.cache();\r
+                               let2.centering().shift(rect_size*1.25, -rect_size);\r
+                               //let2.cache();\r
+                               let3.centering().shift(0.0, rect_size*0.75);\r
+                               //let3.cache();\r
+\r
+                               component c1, c2, c0;\r
+                               c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie\r
+                               ///+ type-I\r
+                               // Prepare Type-I plaid movie\r
+                               center_orientation = 0.0;\r
+                               orientation_offset = Math.PI/6;\r
+                               contrast[0] = 1.0, contrast[1] = 1.0;\r
+                               lambda[0] = 30.0, lambda[1] = 30.0;\r
+                               tf[0] = 1.0; tf[1] = 1.0;\r
+\r
+                               c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
+                               c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
+\r
+                       drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       ///- type-I\r
 \r
-                               figure.resize(figure.getWidth() + looming_direction * 1,\r
-                                                                       figure.getHeight() + looming_direction * 1);\r
-                               figure.shift(motion_dir * 1, motion_dir * 0);\r
+                       ///+ type-II\r
+                       // Prepare Type-II plaid movie\r
+                       center_orientation = -0.0, orientation_offset = Math.PI/12;\r
+                       contrast[0] = 1.0, contrast[1] = 1.0;\r
+                       lambda[0] = 30.0, lambda[1] = 30.0;\r
+                       tf[0] = 1.0; tf[1] = 4.0;\r
 \r
-                               figure.draw();\r
+                       c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
+                       c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
 \r
-                               window.msg(xyz.Y.ToString(), 100, 100);\r
-                               window.flip();\r
+                       drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       ///- type-II\r
 \r
-                               frame++;\r
+                       ///+ gaussian\r
+                       //draw Gaussian envelopes\r
+                       envelope.clear(new Color(bg_lum)); //clear offscreen image\r
+                       double _x, _y;\r
+                       for(int i=0; i<rect_size; i++){\r
+                       _x=i-0.5*rect_size;\r
+                       for(int j=0; j<rect_size; j++){\r
+                       _y=j-0.5*rect_size;\r
+                       envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));\r
+                       }\r
                        }\r
 \r
-               }\r
+                       envelope_small.clear(new Color(bg_lum)); //clear offscreen image\r
+                       for(int i=0; i<rect_size*0.5; i++){\r
+                       _x=i-0.25*rect_size;\r
+                       for(int j=0; j<rect_size*0.5; j++){\r
+                       _y=j-0.25*rect_size;\r
+                       envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));\r
+                       }\r
+                       }\r
+                       envelope.cache(); //send offscreen image from main memory to GPU\r
+                       envelope_small.cache(); //send offscreen image from main memory to GPU\r
+                       ///- gaussian\r
+\r
+                       ///+ user interface\r
+                       // Draw user interface\r
+                       Widgets::SelectBox stimulus_type;\r
+                       stimulus_type.area.set(120, 20);\r
+                       stimulus_type.append(L"TypeI");\r
+                       stimulus_type.append(L"TypeII");\r
+                       stimulus_type.centering().shift(-120.0,250.0);\r
+\r
+                       Psychlops::Widgets::SelectBox stimulus_type2;\r
+                       stimulus_type2.area.set(120, 20);\r
+                       stimulus_type2.append(L"Continuous");\r
+                       stimulus_type2.append(L"Periodic");\r
+                       stimulus_type2.centering().shift(120.0,250.0);\r
 \r
+                       Psychlops::Widgets::Slider duration_slider;\r
+                       duration_slider.area.set(100,20);\r
+                       duration_slider.centering().shift(120,280.0);\r
+                       Interval rng = new Interval();\r
+                       duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);\r
+                       ///- user interface\r
+                       ///- Preperation\r
+\r
+                       ///+ Main loop\r
+                       int frame = 0;\r
+                       int period = refresh_int;\r
+                       int movienum;\r
+                       while(!Keyboard.esc.pushed()) {\r
+                       Display.clear(new Color(bg_lum));\r
+                       movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec\r
+\r
+                       in;\r
+                       else period = refresh_int;\r
+\r
+                       if(frame>0){\r
+                       movie[movienum, frame].centering().draw();\r
+                       envelope.centering().draw();\r
+                       component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();\r
+                       envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();\r
+                       component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();\r
+                       envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();\r
+                       }\r
+\r
+                       ///+ draw user interface\r
+                       let1.draw(0.75);\r
+                       let2.draw(0.75);\r
+                       let3.draw(0.75);\r
+                       stimulus_type.draw();\r
+                       stimulus_type2.draw();\r
+                       if(stimulus_type2.getSelected())duration_slider.draw();\r
+                       ///- draw user interface\r
+                       Display.flip();\r
+                       if(frame++ >= period) frame -= refresh_int;\r
+                       }\r
+                       ///- Main loop\r
+\r
+                       }\r
+                       ///- Stimulus drawing function\r
+\r
+               ///+ Main function for demo circumstances\r
+               public void psychlops_main() {\r
+                       ///+ Demo circumstances\r
+                       //// Spells for run demonstration circumstances\r
+                       Procedure p = new Procedure();\r
+                       //p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
+                       p.setProcedure(drawplaid);  //The argument name is a name of drawing function.\r
+                       p.run();\r
+                       ///- Demo circumstances\r
+               }\r
        }\r
 }\r
 \r
-       \r
-/*     \r
+\r
+\r
+\r
+/*\r
 using Psychlops;\r
 //Position Bias Program\r
 namespace PsychlopsSilverlightApp\r
 {\r
 \r
-       public class PsychlopsMain\r
-       {\r
-               Canvas cnvs;\r
-               Image img, img2, img3;\r
-               int isize = 80;        \r
-               int frames;\r
-               Psychlops.Widgets.Slider tfreq;\r
-               Psychlops.Widgets.Slider contrast;\r
-               Psychlops.Widgets.Slider lambda;\r
-\r
-                               public void psychlops_main()\r
-               {\r
-                       cnvs = new Canvas(300, 600);\r
-                       Interval rng = new Interval();\r
-                       tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);\r
-                       contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);\r
-                       lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);\r
+    public class PsychlopsMain\r
+    {\r
+        Canvas cnvs;\r
+        Image img, img2, img3;\r
+        int isize = 80;        \r
+        int frames;\r
+        Psychlops.Widgets.Slider tfreq;\r
+        Psychlops.Widgets.Slider contrast;\r
+        Psychlops.Widgets.Slider lambda;\r
 \r
-                       img = new Image(isize * 2, isize * 2);\r
-                       img2 = new Image(isize * 2, isize * 2);\r
-                       img3 = new Image(isize * 2, isize * 2);\r
+        public void psychlops_main()\r
+        {\r
+            cnvs = new Canvas(300, 600);\r
+            Interval rng = new Interval();\r
+            tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);\r
+            contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);\r
+            lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);\r
 \r
+            img = new Image(isize * 2, isize * 2);\r
+            img2 = new Image(isize * 2, isize * 2);\r
+            img3 = new Image(isize * 2, isize * 2);\r
 \r
-                       while (true)\r
-                       {\r
-                               cnvs.clear(new Color(0.5));\r
 \r
-                               Figures.drawGabor(ref img, isize / 6, 1/lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
+            while (true)\r
+            {\r
+                cnvs.clear(new Color(0.5));\r
+\r
+                Figures.drawGabor(ref img, isize / 6, 1/lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
                                Figures.drawGabor(ref img2, isize / 6, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);\r
                                Figures.drawGabor(ref img3, isize / 6, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
 \r
-                               img.centering().shift(0, -isize * 1.5).draw();\r
-                               img2.centering().draw();\r
-                               img3.centering().shift(0, isize * 1.5).draw();\r
+                img.centering().shift(0, -isize * 1.5).draw();\r
+                img2.centering().draw();\r
+                img3.centering().shift(0, isize * 1.5).draw();\r
                 \r
-                               if (!Mouse.left.pressed()) frames++;\r
+                if (!Mouse.left.pressed()) frames++;\r
 \r
-                               cnvs.flip();\r
-                       }\r
-               }\r
-       }\r
+                cnvs.flip();\r
+            }\r
+        }\r
+    }\r
 }\r
-*/\r
+\r
+*/
\ No newline at end of file