From: HOSOKAWA Kenchi Date: Mon, 30 Aug 2010 13:29:15 +0000 (+0900) Subject: enable X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=c778254ba66748949fba1e807aec154cdf5dadf1;p=psychlops%2Fsilverlight.git enable --- diff --git a/dev4/Properties/AssemblyInfo.cs b/dev4/Properties/AssemblyInfo.cs index 212e1f5..100e216 100644 --- a/dev4/Properties/AssemblyInfo.cs +++ b/dev4/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ using System.Runtime.InteropServices; // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 // アセンブリに関連付けられている情報を変更するには、 // これらの属性値を変更してください。 -[assembly: AssemblyTitle("PsychlopsSilverlight3")] +[assembly: AssemblyTitle("PsychlopsSilverlight4")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("PsychlopsSilverlight3")] +[assembly: AssemblyProduct("PsychlopsSilverlight4")] [assembly: AssemblyCopyright("Copyright © 2010")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/dev4/PsychlopsSilverlight4.csproj b/dev4/PsychlopsSilverlight4.csproj index f2dcc40..2ee575b 100644 --- a/dev4/PsychlopsSilverlight4.csproj +++ b/dev4/PsychlopsSilverlight4.csproj @@ -48,14 +48,15 @@ prompt 4 + + false + - - diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index e037ef7..5b58b03 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -47,7 +47,6 @@ namespace Psychlops internal Group[] groupStack; internal int groupStackN = 0; - public StackableDrawable() { stack = new Internal.PrimitiveFigure[CONST.MAX_OBJ_N]; @@ -71,8 +70,8 @@ namespace Psychlops } for (int i = 0; i < CONST.HOBJ_N; i++) { - imageStack[i] = new Image(1, 1); - groupStack[i] = new Group(); + imageStack[i] = new Image(); +// groupStack[i] = new Group(); } } @@ -82,6 +81,7 @@ namespace Psychlops public virtual void line(Line drawee) { drawee.copyToStack(this); } public virtual void rect(Rectangle drawee) { drawee.copyToStack(this); } public virtual void ellipse(Ellipse drawee) { drawee.copyToStack(this); } + public virtual void oval(Ellipse drawee) { drawee.copyToStack(this); } public virtual void polygon(Polygon drawee) { drawee.copyToStack(this); } public virtual void letters(Letters drawee) { drawee.copyToStack(this); } public virtual void image(Image drawee) { drawee.copyToStack(this); } @@ -165,12 +165,15 @@ namespace Psychlops { before = new Clock(); before.update(); + var after = new Clock(); AsyncInitBool = false; width_ = wid; height_ = hei; api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei); - while(!AsyncInitBool) + while (!AsyncInitBool) { + after.update(); + if ((after - before).at_msec() > 1000) break; } Mouse._prime = api_canvas; Main.drawable = this; @@ -179,7 +182,6 @@ namespace Psychlops back_panel = new Rectangle(wid, hei); flipexec = new SimpleProcedure(executeFlip); - AppState.statusBar = ""; } protected void initialize__(int wid, int hei) { @@ -195,7 +197,7 @@ namespace Psychlops HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost"); //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null"); htmlHost.SetStyleAttribute("width", (wid).ToString()+"px"); - htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px"); + htmlHost.SetStyleAttribute("height", (hei).ToString() + "px"); htmlHost.SetStyleAttribute("margin", "2em auto auto auto"); pointPool = new System.Windows.Point[CONST.MOBJ_N]; @@ -251,7 +253,6 @@ namespace Psychlops dummyRectPool[i].Visibility = Visibility.Collapsed; } - AsyncInitBool = true; } @@ -326,9 +327,9 @@ namespace Psychlops #region version modifyNative2 public void executeFlip() { - Clock after = new Clock(); - after.update(); - AppState.statusBar = ((after - before).at_msec().ToString()) + " msec"; +// Clock after = new Clock(); +// after.update(); +// AppState.statusBar = ((after - before).at_msec().ToString()) + " msec"; Line lineS; Rectangle rectS; @@ -466,6 +467,8 @@ namespace Psychlops } #endregion + + #region version modifyNative /* public void executeFlip() diff --git a/dev4/psychlops/core/graphic/shape.cs b/dev4/psychlops/core/graphic/shape.cs index aa0885d..9c7ed2b 100644 --- a/dev4/psychlops/core/graphic/shape.cs +++ b/dev4/psychlops/core/graphic/shape.cs @@ -157,6 +157,34 @@ namespace Psychlops{ public Stroke stroke { get; set; } } + public partial class Rectangle_ + { + public Point v1, v2; + + public double left { get { return v1.x; } } + public double top { get { return v1.y; } } + public double right { get { return v2.x; } } + public double bottom { get { return v2.y; } } + public double width { get { return Math.abs(v1.x - v2.x); } } + public double height { get { return Math.abs(v1.y - v2.y); } } + public double getLeft() { return left; } + public double getTop() { return top; } + public double getRight() { return right; } + public double getBottom() { return bottom; } + public double getWidth() { return width; } + public double getHeight() { return height; } + + + + public Color fill { get; set; } + public Stroke stroke { get; set; } + + public override string ToString() + { + return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString(); + } + } + public partial class Rectangle : Shape { diff --git a/dev4/psychlops/extention/compatibility/compatibility.cs b/dev4/psychlops/extention/compatibility/compatibility.cs index f43b5d5..50e4f98 100644 --- a/dev4/psychlops/extention/compatibility/compatibility.cs +++ b/dev4/psychlops/extention/compatibility/compatibility.cs @@ -25,6 +25,40 @@ namespace Psychlops } } **/ + public class Procedure + { + System.Action acc; + System.Action acc_c; + int func = 0; + + public void setDesign() + { + } + public void setProcedure(System.Action ac) + { + acc = ac; + func = 1; + } + public void setProcedure(System.Action ac) + { + acc_c = ac; + func = 2; + } + public void run() + { + if (func == 1) + { + acc(); + } + } + public void run(Canvas c) + { + if (func == 2) + { + acc_c(c); + } + } + } public static class Display { @@ -32,6 +66,7 @@ namespace Psychlops public static void line(Line drawee) { Main.canvas.line(drawee); } public static void rect(Rectangle drawee) { Main.canvas.rect(drawee); } public static void ellipse(Ellipse drawee) { Main.canvas.ellipse(drawee); } + public static void oval(Ellipse drawee) { Main.canvas.ellipse(drawee); } public static void polygon(Polygon drawee) { Main.canvas.polygon(drawee); } public static void letters(Letters drawee) { Main.canvas.letters(drawee); } public static void image(Image drawee) { Main.canvas.image(drawee); } diff --git a/dev4/psychlops/extention/math/solver.cs b/dev4/psychlops/extention/math/solver.cs index 8aaafbb..8ff2b38 100644 --- a/dev4/psychlops/extention/math/solver.cs +++ b/dev4/psychlops/extention/math/solver.cs @@ -262,7 +262,7 @@ namespace Psychlops System.Windows.Controls.ChildWindow page = new PsychlopsSilverlight4.Pages.BinomialSolver(f); page.Show(); } - * */ + */ public int iteration; diff --git a/dev4/psychlops/extention/standard/figures.cs b/dev4/psychlops/extention/standard/figures.cs index a7a8273..f82d1a2 100644 --- a/dev4/psychlops/extention/standard/figures.cs +++ b/dev4/psychlops/extention/standard/figures.cs @@ -13,7 +13,7 @@ namespace Psychlops img = new Image(width, height); double freq = 2 * Math.PI / wavelength; img.field( - (x, y) => new Color(.5 +.5 * Math.sin(phase + (Math.sin(orientation)*x-Math.cos(orientation)*y) * freq)) + (x, y) => new Color(.5 + contrast * .5 * Math.sin(phase + (Math.sin(orientation)*x-Math.cos(orientation)*y) * freq)) ); } public static void drawGaussian(ref Image img, double sigma, double factor) @@ -27,15 +27,15 @@ namespace Psychlops ); } - public static void drawGabor(ref Image img, double sigma, double wavelength, double contrast, double orientation, double phase) + public static void drawGabor(ref Image img, double sigma, double frequency, double contrast, double orientation, double phase) { int width = (int)(sigma * 8), height = (int)(sigma * 8); double width_half = width / 2.0, height_half = height / 2.0; if (img==null || img.width != width || img.height != height) img = new Image(width, height); - double freq = 2 * Math.PI / wavelength; + double freq = 2 * Math.PI * frequency; img.field( - (x, y) => new Color(.5 + Math.gaussian(Math.radius(x - width_half, y - height_half), width / 8.0) * .5 * Math.sin(phase + (Math.sin(orientation)*x-Math.cos(orientation)*y) * freq)) + (x, y) => new Color(.5 + contrast * Math.gaussian(Math.radius(x - width_half, y - height_half), width / 8.0) * .5 * Math.sin(phase + (Math.sin(orientation) * x - Math.cos(orientation) * y) * freq)) ); } diff --git a/test4/MainPage.xaml.cs b/test4/MainPage.xaml.cs index e368a54..2a1ef51 100644 --- a/test4/MainPage.xaml.cs +++ b/test4/MainPage.xaml.cs @@ -44,7 +44,7 @@ namespace PsychlopsSilverlight4test /* var ur = new System.Uri("Resources/Benham.png", System.UriKind.RelativeOrAbsolute); - var bitmap = new System.Windows.Media.Imaging.BitmapImage(ur); + var bitmap = new System.Windows.Media.Imaging.BitmapImage(ur); var img = new System.Windows.Controls.Image(); img.Source = bitmap; System.Windows.Controls.Canvas.SetLeft(img, 100); diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs index 120388a..4ed837b 100644 --- a/test4/PsychlopsMain.cs +++ b/test4/PsychlopsMain.cs @@ -1,76 +1,47 @@ - -///+ Prefix -//// Lines for set up Psychlops environment -using Psychlops; - +using Psychlops; +//Position Bias Program namespace PsychlopsSilverlightApp { - public class PsychlopsMain - {///- Prefix - - ///+ Main Routine - //// Psychlops runs at the first line of this function psychlops_main(). - public void psychlops_main() - { - ///+ 1 - //// Set a window for drawing stimulus - Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode. - // You can write this statement as" Canvas window = new Canvas(Canvas.fullscreen); " for fullscreen mode - // or as " Canvas window = new Canvas(1024, 768, 32, 60.0); " This statement changes screenmode to 1024 x 768, 32bit color, 60 Hz refresh. - ///- 1 - - var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE"); - var SIZE_X = Psychlops.Widgets.Browser.Element.byID("SIZE_X"); - var SIZE_Y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y"); - var SHIFT_X = Psychlops.Widgets.Browser.Element.byID("SHIFT_X"); - var SHIFT_Y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y"); - var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R"); - var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G"); - var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B"); - - - ///+ 2 - //// Set a figure size, position and color. - Rectangle figure = new Rectangle(); - Ellipse figure2 = new Ellipse(); - - window.flip(); // Reflect the drawing for the display by flipping frame buffers. - // Till this point, you will not see drawn figures. - ///- 2 - - ///+ 3 - //// Detect a Keyboard input - while (!Keyboard.esc.pushed()) - { - - window.clear(); - - if ("Rectangle".Equals(FIGURE)) - { - figure.set(SIZE_X, SIZE_Y); // Set the size of figure. - figure.centering(); // Centering the figure in the window - figure.shift(SHIFT_X, SHIFT_Y); // Displacing the figure by designated vector. - figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the rectangle with a designated color. - } - else - { - figure2.set(SIZE_X, SIZE_Y); // Set the size of figure. - figure2.centering(); // Centering the figure in the window - figure2.shift(SHIFT_X, SHIFT_Y); // Displacing the figure by designated vector. - figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the rectangle with a designated color. - } - - window.flip(); - - } //exit a program when the escape key is pressed down. - ///- 3 - - } - ///- Main Routine - - } - -} - - + 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); + + 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); + 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(); + + if (!Mouse.left.pressed()) frames++; + + cnvs.flip(); + } + } + } +} \ No newline at end of file diff --git a/test4/PsychlopsSilverlight4test.csproj b/test4/PsychlopsSilverlight4test.csproj index 5c12523..44c62e0 100644 --- a/test4/PsychlopsSilverlight4test.csproj +++ b/test4/PsychlopsSilverlight4test.csproj @@ -63,7 +63,7 @@ - ..\dev4\Bin\Debug\PsychlopsSilverlight4.dll + ..\dev4\Bin\Release\PsychlopsSilverlight4.dll diff --git a/test4/Store.cs b/test4/Store.cs index e319002..d77d038 100644 --- a/test4/Store.cs +++ b/test4/Store.cs @@ -39,6 +39,243 @@ namespace PsychlopsSilverlight4test +/* +using Psychlops; + +namespace PsychlopsSilverlightApp +{ + + public class PsychlopsMain + { + + Psychlops.Widgets.Slider rect_size, freq, contrast; + + void PositionalBiasisInMovingGabor() + { + double vel = 30.0; + double StimWidth = 120; + + Interval rng = new Interval(); + Psychlops.Widgets.Slider rect_size, freq, contrast; + rect_size = new Psychlops.Widgets.Slider("Rect Size", 1 < rng < 500, 120.0); + freq = new Psychlops.Widgets.Slider("Sptial Frequency", 0.0 <= rng <= 1.0, 0.125); + contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.1); + + int IMAGES = (int)vel; + + Image[] GaborIMG = new Image[200]; + for (int i = 0; i < 200; i++) GaborIMG[i] = new Image(); + + Color clrcol = new Color(), clrFP = new Color(); + Display.clear(0.5); + clrcol.set(128.0 / 255.0); + clrFP.set(128.0 / 255.0, 0.0, 0.0); + + int phase = 0; + double distance = rect_size; + bool changed = true, stop = false; + double prev_contrast = 0.0, prev_freq = 0.0, prev_size = 0.0; + + while (!Keyboard.esc.pushed()) + { + Display.clear(); + + if (prev_contrast != contrast || prev_freq != freq || prev_size != rect_size) changed = true; + prev_contrast = contrast; + prev_freq = freq; + prev_size = rect_size; + if (changed) + { + for (int i = 0; i < 2; i++) + { + for (int j = 0; j < IMAGES; j++) + { + Figures.drawGabor(ref GaborIMG[i * IMAGES + j], rect_size / 8.0, freq, contrast, Math.PI * 0.5, 2.0 * Math.PI * j / IMAGES); + distance = rect_size; + } + } + changed = false; + } + + if (!stop) + { + Display.clear(127.0 / 255.0); + for (int i = 0; i < 3; i++) + { + switch (i) + { + case 0: + GaborIMG[IMAGES - phase - 1].centering().shift(0, -distance); + GaborIMG[IMAGES - phase - 1].draw(); break; + case 1: + GaborIMG[phase].centering().shift(0, 0); + GaborIMG[phase].draw(); break; + case 2: + GaborIMG[IMAGES - phase - 1].centering().shift(0, +distance); + GaborIMG[IMAGES - phase - 1].draw(); break; + } + } + } + if (Keyboard.spc.pushed()) stop = !stop; + //GaborIMG[0].draw(); + + phase++; + phase %= IMAGES; + //if (!stop) Display.flip(); + Display.flip(); + + } + + } + + + public void psychlops_main() + { + + Canvas display = new Canvas(Canvas.window); + + PositionalBiasisInMovingGabor(); + + } + + + + } + +} + */ +/* + * + * using Psychlops; + +namespace PsychlopsSilverlightApp +{ + + public class PsychlopsMain + { + + Psychlops.Canvas cnvs; + int i; + double x, y, z, t, p, temp, xx, yy; + + //Set Target Initial Value + double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0; + + //Set Background Initial Value + double Axis = 0.0, BGRadii = 150, BGSize = 5.0; + Psychlops.Widgets.Slider thetaSpeed, DotNumber; + Image img; + + + + public void psychlops_main() + { + + cnvs = new Canvas(500, 500); + +// Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution); +// img = new Image("Resources/logo.png"); + + Interval rng = new Interval(); + thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0); + DotNumber = new Psychlops.Widgets.Slider("DotNum", 0 <= rng <= 100, 50.0); + + //Declare background dots and target + Rectangle[] BGDot = new Rectangle[2048]; + for (int i = 0; i < 2048; i++) + { + BGDot[i]=new Rectangle(); + } + Rectangle[] Target= new Rectangle[10]; + for(int i=0; i<10; i++){ + Target[i]=new Rectangle(); + } + + + + //Declare Matrix to keep back ground dots' coordinate value + double[] DotX=new double[2048]; + double[] DotY = new double[2048]; + + AppState.statusBar = "dvcscxz"; + //Set Independent variables to manipulate + + + //Initialize positions of background dots + for(int i=0; i<2048; i++){ + t=2.0*Math.PI*Math.random(1.0); + p=2.0*Math.PI*Math.random(1.0); + DotX[i]=t; + DotY[i]=p; + + x=BGRadii*Math.cos(t)*Math.cos(p); + y=BGRadii*Math.sin(t)*Math.cos(p); + BGDot[i].set(BGSize, BGSize); + BGDot[i].centering().shift(x,y); + } + + //Initialize positions of targets + for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize); + + double COS, SIN; + //DotNumber = 200; + //Main stimulus loop + while(true){ + //Clear the main window + cnvs.clear(); + + + temp=Axis/360*2*Math.PI; + COS=Math.cos(temp); + SIN=Math.sin(temp); + + //Calculate positions of background dots and set them + for(int i=0; i