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