From: unknown Date: Wed, 4 Aug 2010 06:24:58 +0000 (+0900) Subject: faster2 X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=a20f03a97a7f2375b92496bad49f6ec520e162d2;p=psychlops%2Fsilverlight.git faster2 --- diff --git a/PsychlopsSilverlight4Dev.sln b/PsychlopsSilverlight4Dev.sln index bec6cfd..8a731bd 100644 --- a/PsychlopsSilverlight4Dev.sln +++ b/PsychlopsSilverlight4Dev.sln @@ -1,8 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Web Developer Express 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PsychlopsSilverlight4", "dev4\PsychlopsSilverlight4.csproj", "{58F3CEF1-8123-4105-9525-B7E2C7F188AC}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PsychlopsSilverlight4test", "test4\PsychlopsSilverlight4test.csproj", "{46CA4F41-B3F5-43E0-9BC7-DDD7EBF3C1E4}" EndProject Global @@ -11,10 +9,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {58F3CEF1-8123-4105-9525-B7E2C7F188AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {58F3CEF1-8123-4105-9525-B7E2C7F188AC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {58F3CEF1-8123-4105-9525-B7E2C7F188AC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {58F3CEF1-8123-4105-9525-B7E2C7F188AC}.Release|Any CPU.Build.0 = Release|Any CPU {46CA4F41-B3F5-43E0-9BC7-DDD7EBF3C1E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {46CA4F41-B3F5-43E0-9BC7-DDD7EBF3C1E4}.Debug|Any CPU.Build.0 = Debug|Any CPU {46CA4F41-B3F5-43E0-9BC7-DDD7EBF3C1E4}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index 7f6360c..6216e53 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -56,7 +56,7 @@ namespace Psychlops { polygonStack[i] = new Polygon(); lettersStack[i] = new Letters(); - //imageStack[i] = new Image(); + imageStack[i] = new Image(1,1); } } @@ -75,7 +75,8 @@ namespace Psychlops public virtual void line(Line drawee) { -// stack.Enqueue(drawee.clone()); + // stack.Enqueue(drawee.clone()); + drawee.copyToStack(this); } public virtual void rect(Rectangle drawee) @@ -141,6 +142,10 @@ namespace Psychlops internal int ellipsePoolN; internal System.Windows.Shapes.Polygon[] polygonPool; internal int polygonPoolN; + internal System.Windows.Controls.TextBlock[] lettersPool; + internal int lettersPoolN; + internal System.Windows.Controls.Image[] imagePool; + internal int imagePoolN; #region initializer @@ -171,11 +176,17 @@ namespace Psychlops api_canvas = apicnvs; initialize(wid, hei); } + + protected bool AsyncInitBool; protected void initialize(int wid, int hei) { + AsyncInitBool = false; width_ = wid; height_ = hei; api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei); + while(!AsyncInitBool) + { + } Mouse._prime = api_canvas; Main.drawable = this; Main.canvas = this; @@ -206,22 +217,29 @@ namespace Psychlops brushPool = new SolidColorBrush[10000]; linePool = new System.Windows.Shapes.Line[10000]; rectPool = new System.Windows.Shapes.Rectangle[10000]; + ellipsePool = new System.Windows.Shapes.Ellipse[10000]; for (int i = 0; i < 10000; i++) { pointPool[i] = new System.Windows.Point(); brushPool[i] = new SolidColorBrush(); linePool[i] = new System.Windows.Shapes.Line(); rectPool[i] = new System.Windows.Shapes.Rectangle(); + ellipsePool[i] = new System.Windows.Shapes.Ellipse(); } - for (int i = 0; i < 300; i++) + polygonPool = new System.Windows.Shapes.Polygon[1000]; + lettersPool = new System.Windows.Controls.TextBlock[1000]; + for (int i = 0; i < 1000; i++) { - api_canvas.Children.Add(rectStack[i].poolNative(this)); - api_canvas.Children.Add(rectStack[i].poolNative(this)); + polygonPool[i] = new System.Windows.Shapes.Polygon(); + lettersPool[i] = new System.Windows.Controls.TextBlock(); } masterPool = new System.Windows.Controls.Canvas(); prevPool = new System.Windows.Controls.Canvas(); -// masterPool.Children.Add() + api_canvas.Children.Add(masterPool); + //api_canvas.Children.Remove(Internal.Main.widgetStack); + + AsyncInitBool = true; } #endregion @@ -258,78 +276,15 @@ namespace Psychlops public override void clear(Color col) { back_panel.fill = col; -// stack.Clear(); stackN = 0; rect(back_panel); } int nextIntervalFrame = 1, chacked = 0; - /* - public void flip() + public void flip(int n) { - //api_canvas.Dispatcher.BeginInvoke(flipexec); - //flipexec(); - //System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); - lock (this) - { - nextIntervalFrame = 1; - chacked = 1; - } -// pointPoolN = 0; -// brushPoolN = 0; -// linePoolN = 0; - rectPoolN = 0; - lineStackN = 0; - rectStackN = 0; - Internal.Main.canvas_flag.WaitOne(); + flip(); } - public void executeFlip() - { - lock (this) - { - nextIntervalFrame--; - } - if (nextIntervalFrame <= 0) - { - var rr = new Random(); - //Psychlops.AppState.statusBar = chacked.ToString(); - if (chacked > 0) - { - // prevPool.Children.Clear(); - var tmp = new System.Windows.Controls.Canvas(); - if (stack.Count > 0) - // if (stackN > 0) - { - //foreach (UIElement e in api_canvas.Children) - //{ - //} -// foreach (Internal.PrimitiveFigure f in stack) - for (int i = 0; i < stackN - 2; i++) - { - // tmp.Children.Add(f.toNative()); -// tmp.Children.Add(f.poolNative(this)); - tmp.Children.Add(stack[i].poolNative(this)); - // System.Windows.Controls.Canvas.SetLeft(api_canvas.Children[i + 1], rectStack[i].left); - // api_canvas.Children[0] = api_canvas.Children[0]; - } - stackN = 0; - - } - api_canvas.Children.Clear(); - api_canvas.Children.Add(tmp); - // stack.Clear(); - lock (this) - { - chacked = 0; - } - Psychlops.Internal.Main.canvas_flag.Set(); - // prevPool = tmp; - } - } - System.Threading.Thread.Sleep(0); - } - */ - public void flip() { lock (this) @@ -339,10 +294,24 @@ namespace Psychlops } // pointPoolN = 0; // brushPoolN = 0; - // linePoolN = 0; + linePoolN = 0; rectPoolN = 0; lineStackN = 0; rectStackN = 0; + polygonStackN = 0; + ellipseStackN = 0; + lettersStackN = 0; + imageStackN = 0; + + pointPoolN = 0; + brushPoolN = 0; + linePoolN = 0; + rectPoolN = 0; + ellipsePoolN = 0; + polygonPoolN = 0; + lettersPoolN = 0; + imagePoolN = 0; + Internal.Main.canvas_flag.WaitOne(); } public void executeFlip() @@ -355,19 +324,15 @@ namespace Psychlops { if (chacked > 0) { - //api_canvas.Children.Clear(); - //var tmp = new System.Windows.Controls.Canvas(); + masterPool.Children.Clear(); if (stackN > 0) { for (int i = 0; i < stackN - 2; i++) { - //api_canvas.Children.Add(stack[i].poolNative(this)); - api_canvas.Children.Add(stack[i].poolNative(this)); + masterPool.Children.Add(stack[i].poolNative(this)); } stackN = 0; } - //api_canvas.Children.Clear(); - //api_canvas.Children.Add(tmp); lock (this) { chacked = 0; @@ -454,6 +419,19 @@ namespace Psychlops } public UIElement toNative() { return this; } + public void copyToStack(Templates.StackableDrawable d) + { + var tmp = d.lineStack[d.lineStackN]; + tmp.begin.x = begin.x; + tmp.begin.y = begin.y; + tmp.end.x = end.x; + tmp.end.y = end.y; + tmp.fill = fill; + tmp.stroke = stroke; + d.stack[d.stackN] = tmp; + d.lineStackN++; + d.stackN++; + } public UIElement poolNative(Canvas d) { var tmp = d.linePool[d.linePoolN]; @@ -548,7 +526,7 @@ namespace Psychlops tmp.ydiameter = ydiameter; tmp.fill = fill; d.stack[d.stackN] = tmp; - d.rectStackN++; + d.ellipseStackN++; d.stackN++; } public UIElement poolNative(Canvas d) @@ -561,7 +539,7 @@ namespace Psychlops System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); tmp.Visibility = Visibility.Visible; d.ellipsePoolN++; - return this; + return tmp; } } @@ -600,20 +578,23 @@ namespace Psychlops } tmp.fill = fill; d.stack[d.stackN] = tmp; - d.rectStackN++; + d.polygonStackN++; d.stackN++; } public UIElement poolNative(Canvas d) { var tmp = d.polygonPool[d.polygonPoolN]; tmp.Fill = fill; - /* - System.Windows.Controls.Canvas.SetLeft(tmp, left); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); - */ + tmp.Points.Clear(); + foreach (var v in vertices) + { + tmp.Points.Add(v); + } + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); tmp.Visibility = Visibility.Visible; d.polygonPoolN++; - return this; + return tmp; } } @@ -675,25 +656,31 @@ namespace Psychlops public void copyToStack(Templates.StackableDrawable d) { - var tmp = d.polygonStack[d.polygonStackN]; + var tmp = d.lettersStack[d.lettersStackN]; + tmp.str = str; tmp.datum = datum; tmp.fill = fill; d.stack[d.stackN] = tmp; - d.rectStackN++; + d.lettersStackN++; d.stackN++; } public UIElement poolNative(Canvas d) { - /* var tmp = d.rectPool[d.rectPoolN]; - tmp.Width = width; - tmp.Height = height; - tmp.Fill = fill; - System.Windows.Controls.Canvas.SetLeft(tmp, left); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); - tmp.Visibility = Visibility.Visible; - d.rectPoolN++; -*/ - return this; + var tmp = d.lettersPool[d.lettersPoolN]; + tmp.Text = str; + tmp.Width = 500; + tmp.Height = 500; + tmp.FontSize = font.size; + //tmp.FontFamily = , + tmp.FontStyle = FONT_STYLE_BRIDGE[font.style]; + tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight]; + tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align]; + tmp.Foreground = fill; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + tmp.Visibility = Visibility.Visible; + d.lettersPoolN++; + return tmp; } } @@ -707,6 +694,7 @@ namespace Psychlops internal void create__(int wid, int hei) { buffer = new WriteableBitmap(wid, hei); + AsyncBool = true; } delegate void FieldFunc1(System.Func func); delegate void FieldFunc2(System.Func func); @@ -743,17 +731,24 @@ namespace Psychlops } public UIElement toNative() { return this; } + public void copyToStack(Templates.StackableDrawable d) + { + var tmp = d.imageStack[d.imageStackN]; + tmp.datum = datum; + tmp.buffer = buffer; + tmp.self_rect = self_rect; + d.stack[d.stackN] = tmp; + d.imageStackN++; + d.stackN++; + } public UIElement poolNative(Canvas d) { - /* var tmp = d.rectPool[d.rectPoolN]; - tmp.Width = width; - tmp.Height = height; - tmp.Fill = fill; - System.Windows.Controls.Canvas.SetLeft(tmp, left); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); - tmp.Visibility = Visibility.Visible; - d.rectPoolN++; -*/ + var tmp = d.imagePool[d.imagePoolN]; + tmp.Source = buffer; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + tmp.Visibility = Visibility.Visible; + d.rectPoolN++; return this; } diff --git a/dev4/psychlops/core/graphic/image.cs b/dev4/psychlops/core/graphic/image.cs index c3df14e..6d5f3f5 100644 --- a/dev4/psychlops/core/graphic/image.cs +++ b/dev4/psychlops/core/graphic/image.cs @@ -19,19 +19,16 @@ namespace Psychlops{ public Point getDatum() { return datum; } public Point setDatum(Point p) { datum = p; return datum; } public Rectangle self_rect; + protected bool AsyncBool; public Image(int wid, int hei) { + AsyncBool = false; initialize__(wid, hei); self_rect = new Rectangle(wid, hei); + while (!AsyncBool) { } } - /*public Image shift(double x, double y) - { - datum.x += x; - datum.y += y; - return this; - }*/ public Figure shift(Point p) { datum = datum + p; diff --git a/dev4/psychlops/core/math/util.cs b/dev4/psychlops/core/math/util.cs index 7f498d3..85134a9 100644 --- a/dev4/psychlops/core/math/util.cs +++ b/dev4/psychlops/core/math/util.cs @@ -5,13 +5,38 @@ namespace Psychlops public static class Math { - public static readonly double PI = 3.14159265, E = 2.718281828459045; + public static readonly double PI = 3.14159265, E = 2.718281828459045, LOG2E = 1.44269504088896340736; public static Random random_generator; static Math() { random_generator = new Random(); } + public static double max(double val1, double val2) + { + return val1 > val2 ? val1 : val2; + } + public static double min(double val1, double val2) + { + return val1 < val2 ? val1 : val2; + } + public static void shuffle(X[] array, int n) + { + int a; + X tmp; + for(int i = 1; i < n; i++){ + a = random(i + 1); + tmp = array[i]; + array[i] = array[a]; + array[a] = tmp; + } + } + + + public static double mod(double lhs, double rhs) + { + return lhs - System.Math.Floor(lhs/rhs)*rhs; + } public static double abs(double x) { return System.Math.Abs(x); @@ -40,6 +65,16 @@ namespace Psychlops { return System.Math.Log(x); } + public static double log2(double val) + { + return log(val) * LOG2E; + } + /*public static int round(double val) + { + double integer_part, particle = modf(val, &integer_part); + return ((particle < 0.5 | (particle == 0.5 && (int)integer_part % 2 == 0)) ? (int)integer_part : (int)integer_part + 1); + }*/ + public static double radius(double x, double y) { return System.Math.Sqrt(x * x + y * y); @@ -49,6 +84,10 @@ namespace Psychlops { return (random_generator.NextDouble()); } + public static int random(int x) + { + return (int)((random_generator.NextDouble()) * x); + } public static double random(double x) { return (random_generator.NextDouble()) * x; diff --git a/dev4/psychlops/extention/experiments/experiments.cs b/dev4/psychlops/extention/experiments/experiments.cs index 0192688..9a1aaf0 100644 --- a/dev4/psychlops/extention/experiments/experiments.cs +++ b/dev4/psychlops/extention/experiments/experiments.cs @@ -1,4 +1,17 @@ namespace Psychlops { +/* + public class Independent + { + public double value; + public Independent() + { + value = 0; + } + + + public static implicit operator double(Independent i) { return i.value; } + } + */ } diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs index b9daaa9..7461d42 100644 --- a/test4/PsychlopsMain.cs +++ b/test4/PsychlopsMain.cs @@ -1,4 +1,137 @@ - +using Psychlops; + +namespace PsychlopsSilverlight4test +{ + + public class PsychlopsMain + { + + Canvas cnvs; + int i; + object xxx; + 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 DotNumber = 50, thetaSpeed = 3.0, Axis = 0.0, BGRadii = 150, BGSize = 5.0; + Psychlops.Widgets.Slider DotNumberS; + + public void psychlops_main() + { + DotNumberS = new Psychlops.Widgets.Slider("test", new Interval(10, 500)); + //Independent ind = new Independent(); + + cnvs = new Canvas(500, 500); + xxx = 1; + Image img = new Image(100,100); + for (int x = 0; x < 100; x++) + { + for (int y = 0; y < 100; y++) + { + img.pix(x,y, new Color( Math.sin(x+y)) ); + } + } + + + //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]; + + + + //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; + + //Main stimulus loop + while(true){ + //Clear the main window + cnvs.clear(Color.black); + + + 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