From: HOSOKAWA Kenchi Date: Sat, 17 Jul 2010 23:34:37 +0000 (+0900) Subject: pooling X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=90eca83a1240638e0a8e450e108c1e089bd0ea5b;p=psychlops%2Fsilverlight.git pooling --- diff --git a/dev4/PsychlopsSilverlight4.csproj b/dev4/PsychlopsSilverlight4.csproj index 230fa1e..e33dd51 100644 --- a/dev4/PsychlopsSilverlight4.csproj +++ b/dev4/PsychlopsSilverlight4.csproj @@ -53,6 +53,7 @@ + @@ -74,6 +75,8 @@ + + diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index a695257..568565b 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -19,11 +19,26 @@ namespace Psychlops public class StackableDrawable : Drawable { - protected System.Collections.Generic.Queue stack; +// protected System.Collections.Generic.Queue stack; + internal Internal.PrimitiveFigure[] stack; + internal int stackN; + internal Line[] lineStack; + internal int lineStackN; + internal Rectangle[] rectStack; + internal int rectStackN; + public StackableDrawable() { - stack = new System.Collections.Generic.Queue(); +// stack = new System.Collections.Generic.Queue(); + stack = new Internal.PrimitiveFigure[40000]; + lineStack = new Line[10000]; + rectStack = new Rectangle[10000]; + for (int i = 0; i < 10000; i++) + { + lineStack[i] = new Line(0,0,0,0); + rectStack[i] = new Rectangle(); + } } public void clear() @@ -41,32 +56,34 @@ namespace Psychlops public virtual void line(Line drawee) { - stack.Enqueue(drawee.clone()); +// stack.Enqueue(drawee.clone()); } public virtual void rect(Rectangle drawee) { - stack.Enqueue(drawee.clone()); + //stack.Enqueue(drawee.clone()); +// stack.Enqueue(drawee.copyToStack(this)); + drawee.copyToStack(this); } public virtual void ellipse(Ellipse drawee) { - stack.Enqueue(drawee.clone()); +// stack.Enqueue(drawee.clone()); } public virtual void polygon(Polygon drawee) { - stack.Enqueue(drawee.clone()); +// stack.Enqueue(drawee.clone()); } public virtual void letters(Letters drawee) { - stack.Enqueue(drawee.clone()); +// stack.Enqueue(drawee.clone()); } public virtual void image(Image drawee) { - stack.Enqueue(drawee.clone()); +// stack.Enqueue(drawee.clone()); } public void msg(string str, double x, double y) { msg(str, x, y, Color.white); } @@ -88,6 +105,16 @@ namespace Psychlops public class Canvas : Templates.StackableDrawable { + internal System.Windows.Controls.Canvas masterPool, prevPool; + internal System.Windows.Point[] pointPool; + internal int pointPoolN; + internal SolidColorBrush[] brushPool; + internal int brushPoolN; + internal System.Windows.Shapes.Line[] linePool; + internal int linePoolN; + internal System.Windows.Shapes.Rectangle[] rectPool; + internal int rectPoolN; + #region initializer internal delegate void TwoIntProcedure(int x, int y); @@ -119,7 +146,6 @@ namespace Psychlops } protected void initialize(int wid, int hei) { - width_ = wid; height_ = hei; api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei); @@ -147,6 +173,28 @@ namespace Psychlops htmlHost.SetStyleAttribute("width", (wid).ToString()+"px"); htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px"); htmlHost.SetStyleAttribute("margin", "2em auto auto auto"); + + + pointPool = new System.Windows.Point[10000]; + brushPool = new SolidColorBrush[10000]; + linePool = new System.Windows.Shapes.Line[10000]; + rectPool = new System.Windows.Shapes.Rectangle[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(); + } + for (int i = 0; i < 300; i++) + { + api_canvas.Children.Add(rectStack[i].poolNative(this)); + api_canvas.Children.Add(rectStack[i].poolNative(this)); + } + + masterPool = new System.Windows.Controls.Canvas(); + prevPool = new System.Windows.Controls.Canvas(); +// masterPool.Children.Add() } #endregion @@ -183,6 +231,8 @@ namespace Psychlops public override void clear(Color col) { back_panel.fill = col; +// stack.Clear(); + stackN = 0; rect(back_panel); } @@ -197,6 +247,12 @@ namespace Psychlops nextIntervalFrame = 1; chacked = 1; } +// pointPoolN = 0; +// brushPoolN = 0; +// linePoolN = 0; + rectPoolN = 0; + lineStackN = 0; + rectStackN = 0; Internal.Main.canvas_flag.WaitOne(); } public void executeFlip() @@ -207,25 +263,36 @@ namespace Psychlops } if (nextIntervalFrame <= 0) { + var rr = new Random(); //Psychlops.AppState.statusBar = chacked.ToString(); if (chacked > 0) { - var tmp = new System.Windows.Controls.Canvas(); - if (stack.Count > 0) + // prevPool.Children.Clear(); + // var tmp = new System.Windows.Controls.Canvas(); +// if (stack.Count > 0) + if (stackN > 0) { - foreach (Internal.PrimitiveFigure f in stack) +// foreach (Internal.PrimitiveFigure f in stack) + for (int i = 0; i < stackN - 2; i++ ) { - tmp.Children.Add(f.toNative()); + // 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(); + // 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); @@ -304,6 +371,22 @@ namespace Psychlops return tmp; } public UIElement toNative() { return this; } + + public UIElement poolNative(Canvas d) + { + var tmp = d.linePool[d.linePoolN]; + tmp.X1 = begin.x; + tmp.Y1 = begin.y; + tmp.X2 = end.x; + tmp.Y2 = end.y; + if (stroke.thick == 0.0) tmp.Stroke = fill; + else stroke.apply(tmp); + System.Windows.Controls.Canvas.SetLeft(tmp, left); + System.Windows.Controls.Canvas.SetTop(tmp, top); + tmp.Visibility = Visibility.Visible; + d.linePoolN++; + return tmp; + } } partial class Rectangle @@ -316,6 +399,16 @@ namespace Psychlops { return (Rectangle)MemberwiseClone(); } + public void copyToStack(Templates.StackableDrawable d) + { + var tmp = d.rectStack[d.rectStackN]; + tmp.v1 = v1; + tmp.v2 = v2; + tmp.fill = fill; + d.stack[d.stackN] = tmp; + d.rectStackN++; + d.stackN++; + } public static implicit operator System.Windows.Rect(Rectangle d) { return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y); @@ -329,6 +422,19 @@ namespace Psychlops return tmp; } public UIElement toNative() { return this; } + + 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(tmp, top); + tmp.Visibility = Visibility.Visible; + d.rectPoolN++; + return tmp; + } } partial class Ellipse @@ -350,6 +456,20 @@ namespace Psychlops return tmp; } public UIElement toNative() { return this; } + + 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; + } } partial class Polygon @@ -375,6 +495,21 @@ namespace Psychlops return tmp; } public UIElement toNative() { return this; } + + 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; + } + } partial class Letters @@ -431,6 +566,20 @@ namespace Psychlops return tmp; } public UIElement toNative() { return this; } + + 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; + } } partial class Image @@ -478,6 +627,21 @@ namespace Psychlops return tmp; } public UIElement toNative() { return this; } + + 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; + } + } #endregion diff --git a/dev4/psychlops/core/graphic/module.cs b/dev4/psychlops/core/graphic/module.cs index 6fc1f15..85c49aa 100644 --- a/dev4/psychlops/core/graphic/module.cs +++ b/dev4/psychlops/core/graphic/module.cs @@ -138,6 +138,7 @@ namespace Psychlops public interface PrimitiveFigure : Figure { UIElement toNative(); + UIElement poolNative(Canvas c); } } } \ No newline at end of file diff --git a/dev4/psychlops/core/graphic/shape.cs b/dev4/psychlops/core/graphic/shape.cs index d6ec793..9cebe91 100644 --- a/dev4/psychlops/core/graphic/shape.cs +++ b/dev4/psychlops/core/graphic/shape.cs @@ -74,15 +74,17 @@ namespace Psychlops{ { set(v1, v2); } - public void set(double x1, double y1, double x2, double y2) + public Line set(double x1, double y1, double x2, double y2) { begin.set(x1, y1); end.set(x2, y2); + return this; } - public void set(Point v1, Point v2) + public Line set(Point v1, Point v2) { begin = v1; end = v2; + return this; } public Figure shift(Point p) @@ -101,7 +103,7 @@ namespace Psychlops{ return this; } - public void draw() + public virtual void draw() { Main.drawable.line(this); } @@ -200,7 +202,7 @@ namespace Psychlops{ return this; } - public void draw() + public virtual void draw() { Main.drawable.rect(this); } @@ -304,6 +306,13 @@ namespace Psychlops{ ydiameter = hei; return this; } + public Ellipse resize(double width, double height) + { + Point po = center; + set(width, height); + centering(po); + return this; + } public Figure shift(Point p) { datum += p; @@ -315,7 +324,7 @@ namespace Psychlops{ return this; } - public void draw() + public virtual void draw() { Main.drawable.ellipse(this); } @@ -387,7 +396,7 @@ namespace Psychlops{ return this; } - public void draw() + public virtual void draw() { Main.drawable.polygon(this); } diff --git a/dev4/psychlops/extention/experiments/experiments.cs b/dev4/psychlops/extention/experiments/experiments.cs new file mode 100644 index 0000000..0192688 --- /dev/null +++ b/dev4/psychlops/extention/experiments/experiments.cs @@ -0,0 +1,4 @@ +namespace Psychlops +{ + +} diff --git a/dev4/psychlops/extention/math/probit.cs b/dev4/psychlops/extention/math/probit.cs new file mode 100644 index 0000000..0659e6e --- /dev/null +++ b/dev4/psychlops/extention/math/probit.cs @@ -0,0 +1,38 @@ +/* + * http://crsouza.blogspot.com/2010/02/logistic-regression-in-c.html + * + Copyright (c) 2009, César Roberto de Souza + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the software author(s) nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE SOFTWARE AUTHOR(S) ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE SOFTWARE AUTHOR(S) BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE./// +*/ + +namespace Psychlops +{ + + public class LogisticRegression + { + + } + +} \ No newline at end of file diff --git a/dev4/psychlops/extention/media/dom.cs b/dev4/psychlops/extention/media/dom.cs new file mode 100644 index 0000000..a733682 --- /dev/null +++ b/dev4/psychlops/extention/media/dom.cs @@ -0,0 +1,6 @@ + +namespace Psychlops +{ + + +} \ No newline at end of file diff --git a/test4/PsychlopsSilverlight4test.csproj b/test4/PsychlopsSilverlight4test.csproj index f53bc0c..ba41041 100644 --- a/test4/PsychlopsSilverlight4test.csproj +++ b/test4/PsychlopsSilverlight4test.csproj @@ -77,6 +77,7 @@ App.xaml + MainPage.xaml diff --git a/test4/Store.cs b/test4/Store.cs new file mode 100644 index 0000000..bff2e6d --- /dev/null +++ b/test4/Store.cs @@ -0,0 +1,254 @@ +/* +using Psychlops; + +namespace PsychlopsSilverlight4test +{ + public class PsychlopsMain + { + public void psychlops_main() + { + Canvas window = new Canvas(300, 300); + + var figure_r = new Rectangle(); + var figure_e = new Ellipse(); + figure_r.set(100,100).centering().shift(0, 0); + figure_e.set(100,100).centering().shift(0, 0); + + while (!Keyboard.esc.pushed()) + { + figure_r.fill = new Color(0, 0, 1); + figure_r.centering(new Point(100,100)).draw(); + figure_e.fill = new Color(1, 0, 0); + figure_e.centering(new Point(100, 100)).draw(); + window.flip(); + } + } + } + +} + +/* + + + +using Psychlops; + +namespace PsychlopsSilverlight4test +{ + public class PsychlopsMain + { + public void psychlops_main() + { + var figure_type = 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 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"); + + Canvas window = new Canvas(300, 300); + + var figure_r = new Rectangle(); + var figure_e = new Ellipse(); + figure_r.centering().shift(0, 0); + figure_e.centering().shift(0, 0); + + int frame = 0; + int direction = 1, motion_dir = 1; + + while (!Keyboard.esc.pushed()) + { + window.clear(); + + if (frame % 30 == 0) + { + direction = direction * -1; + + } + + if (frame % 90 == 0) + { + motion_dir *= -1; + } + + figure_r.resize(figure_r.getWidth() + direction * 1, figure_r.getHeight() + direction * 1); + figure_r.shift(motion_dir * 1, 0); + figure_r.fill = new Color(color_r, color_g, color_b); + + figure_e.resize(figure_e.getWidth() + direction * 1, figure_e.getHeight() + direction * 1); + figure_e.shift(motion_dir * 1, 0); + figure_e.fill = new Color(color_r, color_g, color_b); + + if (System.String.Compare(figure_type, "Rectangle") == 0) + { + figure_r.draw(); + } + else + { + figure_e.draw(); + } + + + frame++; + + + window.flip(); + } + } + } + +} + * */ + + +/* +using Psychlops; + +namespace PsychlopsSilverlight4test +{ + public class PsychlopsMain + { + public void psychlops_main() + { + var figure_type = 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"); + + Canvas window = new Canvas(300, 300); + + var figure_r = new Rectangle(); + var figure_e = new Ellipse(); + Shape figure = figure_r; + + while (!Keyboard.esc.pushed()) + { + if (System.String.Compare(figure_type, "Rectangle") == 0) + { + figure_r.set(size_x, size_y); + figure = figure_r; + } + else + { + figure_e.set(size_x, size_y); + figure = figure_e; + } + figure.fill = new Color(color_r, color_g, color_b); + + window.clear(Color.black); + figure.centering().shift(shift_x, shift_y).draw(); + window.flip(); + } + } + } + +} +*/ + + +/* +using Psychlops; + +namespace Psychlops +{ + + public class RandomDots + { + Rectangle dot; + public Point[] cood; + public RandomDots() + { + cood = new Point[250]; + dot = new Rectangle(5, 5); + } + public void draw() + { + dot.fill = Color.white; + foreach (Point p in cood) + { + dot.centering(p).draw(); + } + } + } + +} + + +namespace PsychlopsSilverlight4test +{ + + public class PsychlopsMain + { + Canvas cnvs; + Image img; + Rectangle fixation; + Shape shape; + Color col; + int isize = 100; + double tfreq = 1; + int frames; + RandomDots dots; + + public void psychlops_main() + { + cnvs = new Canvas(500, 500); + img = new Image(isize * 2, isize * 2); + fixation = new Rectangle(10, 10); + fixation.fill = Color.red; + //var poly = new Rectangle(100, 100); + var poly = new Letters("日本語"); + //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0); + //var poly = new Ellipse(100, 100); + //var poly = new Line(0,0,100, 0); + poly.fill = Color.red; + poly.stroke = new Stroke { color = Color.yellow, thick = 1 }; + shape = poly; + + var rng = new Interval(); + var slider = new Psychlops.Widgets.Slider("tesrt", 0 <= rng <= 5); + + dots = new RandomDots(); + + + while(true) { + frames++; + + cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5)); + col.set(Math.random(1.0)); + + fixation.centering(); + fixation.draw(Color.red); + + //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60); + //Figures.drawGaussian(ref img, 20, 1); + Figures.drawGrating(ref img, 30, 30, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60); + img.centering(Mouse.position); + img.draw(); + + shape.centering(Mouse.position).shift(100,0); + shape.draw(); + if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100); + + cnvs.var(frames, 20, 20); + slider.value = frames/100.0; + + fixation.shift(100,100); + fixation.draw(new Stroke(Color.blue, 3)); + + for (int i=0; i