From 14b5f406aebde0b4bdc36a94f0c315a2864a1fee Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Aug 2010 20:07:41 +0900 Subject: [PATCH] 321 --- dev4/psychlops/core/device/clock.cs | 4 + dev4/psychlops/core/graphic/canvas.cs | 356 ++++++++++++---------------- dev4/psychlops/core/graphic/image.cs | 4 + dev4/psychlops/extention/math/solver.cs | 55 ++--- dev4/psychlops/extention/standard/widget.cs | 124 ++++++++-- test4/MainPage.xaml.cs | 2 +- test4/PsychlopsMain.cs | 83 +++++-- 7 files changed, 354 insertions(+), 274 deletions(-) diff --git a/dev4/psychlops/core/device/clock.cs b/dev4/psychlops/core/device/clock.cs index bc52821..f4a3ebf 100644 --- a/dev4/psychlops/core/device/clock.cs +++ b/dev4/psychlops/core/device/clock.cs @@ -34,6 +34,10 @@ namespace Psychlops { return lhs.ticks != rhs.ticks; } + public override int GetHashCode() + { + return ticks.GetHashCode(); + } public static bool operator >(Clock lhs, Clock rhs) { return lhs.ticks > rhs.ticks; diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index fdc3987..c64f7f5 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -14,6 +14,14 @@ using System.Windows.Browser; namespace Psychlops { + internal static partial class CONST + { + internal static readonly uint MAX_OBJ_N = 1500; + internal static readonly uint MOBJ_N = 1000; + internal static readonly uint COBJ_N = 300; + internal static readonly uint HOBJ_N = 100; + } + namespace Templates { @@ -40,86 +48,42 @@ namespace Psychlops public StackableDrawable() { -// stack = new System.Collections.Generic.Queue(); - stack = new Internal.PrimitiveFigure[10000]; - lineStack = new Line[2000]; - rectStack = new Rectangle[2000]; - ellipseStack = new Ellipse[2000]; - polygonStack = new Polygon[1000]; - lettersStack = new Letters[1000]; - imageStack = new Image[100]; - groupStack = new Group[100]; - for (int i = 0; i < 2000; i++) + stack = new Internal.PrimitiveFigure[CONST.MAX_OBJ_N]; + lineStack = new Line[CONST.MOBJ_N]; + rectStack = new Rectangle[CONST.MOBJ_N]; + ellipseStack = new Ellipse[CONST.MOBJ_N]; + polygonStack = new Polygon[CONST.COBJ_N]; + lettersStack = new Letters[CONST.COBJ_N]; + imageStack = new Image[CONST.HOBJ_N]; + groupStack = new Group[CONST.HOBJ_N]; + for (int i = 0; i < CONST.MOBJ_N; i++) { lineStack[i] = new Line(0,0,0,0); rectStack[i] = new Rectangle(); ellipseStack[i] = new Ellipse(); } - for (int i = 0; i < 1000; i++) + for (int i = 0; i < CONST.COBJ_N; i++) { polygonStack[i] = new Polygon(); lettersStack[i] = new Letters(); } - for (int i = 0; i < 100; i++) + for (int i = 0; i < CONST.HOBJ_N; i++) { imageStack[i] = new Image(1, 1); groupStack[i] = new Group(); } } - public void clear() - { - clear(Color.black); - } - public virtual void clear(Color col) - { - //rect(back_panel, col); - } - - public virtual void pix(int x, int y, Color col) - { - } - - public virtual void line(Line drawee) - { - // stack.Enqueue(drawee.clone()); - drawee.copyToStack(this); - } - - public virtual void rect(Rectangle drawee) - { - //stack.Enqueue(drawee.clone()); -// stack.Enqueue(drawee.copyToStack(this)); - drawee.copyToStack(this); - } - - public virtual void ellipse(Ellipse drawee) - { - // stack.Enqueue(drawee.clone()); - drawee.copyToStack(this); - } - - public virtual void polygon(Polygon drawee) - { - // stack.Enqueue(drawee.clone()); - drawee.copyToStack(this); - } - - public virtual void letters(Letters drawee) - { - // stack.Enqueue(drawee.clone()); - drawee.copyToStack(this); - } - - public virtual void image(Image drawee) - { - // stack.Enqueue(drawee.clone()); - drawee.copyToStack(this); - } - public virtual void group(Group drawee) - { - drawee.copyToStack(this); - } + public void clear() { clear(Color.black); } + public virtual void clear(Color col) { } //rect(back_panel, col); } + public virtual void pix(int x, int y, Color col) { } + 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 polygon(Polygon drawee) { drawee.copyToStack(this); } + public virtual void letters(Letters drawee) { drawee.copyToStack(this); } + public virtual void image(Image drawee) { drawee.copyToStack(this); } + public virtual void group(Group drawee) { drawee.copyToStack(this); } public void msg(string str, double x, double y) { msg(str, x, y, Color.white); } public virtual void msg(string dstr, double x, double y, Color col) @@ -139,7 +103,6 @@ namespace Psychlops public class Canvas : Templates.StackableDrawable { - internal System.Windows.Controls.Canvas masterPool, prevPool; internal System.Windows.Point[] pointPool; internal int pointPoolN; @@ -148,6 +111,7 @@ namespace Psychlops internal System.Windows.Controls.Canvas[] UIElementPool; internal int UIElementPoolN; + internal int lastVisibleN; internal System.Windows.Shapes.Line[] linePool; internal int linePoolN; @@ -171,12 +135,9 @@ namespace Psychlops internal delegate void SimpleProcedure(); SimpleProcedure flipexec; - //public static System.Windows.Controls.Image default_buffer_frame; public static System.Windows.Controls.UserControl default_panel; public static System.Windows.Controls.Canvas default_api_canvas; public static WriteableBitmap default_buffer; - //WriteableBitmap buffer; - //System.Windows.Controls.Image instance; System.Windows.Controls.Canvas api_canvas; System.Windows.Controls.UserControl panel; Rectangle back_panel; @@ -234,33 +195,29 @@ namespace Psychlops htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px"); htmlHost.SetStyleAttribute("margin", "2em auto auto auto"); - UIElementPool = new System.Windows.Controls.Canvas[2000]; - pointPool = new System.Windows.Point[2000]; - brushPool = new SolidColorBrush[2000]; - linePool = new System.Windows.Shapes.Line[2000]; - rectPool = new System.Windows.Shapes.Rectangle[2000]; - dummyRectPool = new System.Windows.Shapes.Rectangle[2000]; - ellipsePool = new System.Windows.Shapes.Ellipse[2000]; - for (int i = 0; i < 2000; i++) + pointPool = new System.Windows.Point[CONST.MOBJ_N]; + brushPool = new SolidColorBrush[CONST.MOBJ_N]; + linePool = new System.Windows.Shapes.Line[CONST.MOBJ_N]; + rectPool = new System.Windows.Shapes.Rectangle[CONST.MOBJ_N]; + ellipsePool = new System.Windows.Shapes.Ellipse[CONST.MOBJ_N]; + for (int i = 0; i < CONST.MOBJ_N; i++) { - UIElementPool[i] = new System.Windows.Controls.Canvas(); pointPool[i] = new System.Windows.Point(); brushPool[i] = new SolidColorBrush(); linePool[i] = new System.Windows.Shapes.Line(); rectPool[i] = new System.Windows.Shapes.Rectangle(); - dummyRectPool[i] = new System.Windows.Shapes.Rectangle(); ellipsePool[i] = new System.Windows.Shapes.Ellipse(); } - polygonPool = new System.Windows.Shapes.Polygon[1000]; - lettersPool = new System.Windows.Controls.TextBlock[1000]; - for (int i = 0; i < 1000; i++) + polygonPool = new System.Windows.Shapes.Polygon[CONST.COBJ_N]; + lettersPool = new System.Windows.Controls.TextBlock[CONST.COBJ_N]; + for (int i = 0; i < CONST.COBJ_N; i++) { polygonPool[i] = new System.Windows.Shapes.Polygon(); lettersPool[i] = new System.Windows.Controls.TextBlock(); } - imagePool = new System.Windows.Controls.Image[100]; - groupPool = new System.Windows.Controls.Canvas[100]; - for (int i = 0; i < 100; i++) + imagePool = new System.Windows.Controls.Image[CONST.HOBJ_N]; + groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N]; + for (int i = 0; i < CONST.HOBJ_N; i++) { imagePool[i] = new System.Windows.Controls.Image(); groupPool[i] = new System.Windows.Controls.Canvas(); @@ -270,11 +227,20 @@ namespace Psychlops prevPool = new System.Windows.Controls.Canvas(); api_canvas.Children.Add(masterPool); //api_canvas.Children.Remove(Internal.Main.widgetStack); - - for (int i = 0; i < 2000; i++) + Psychlops.Internal.Main.widgetStack = new StackPanel(); + Psychlops.Internal.Main.widgetStack.Orientation = Orientation.Vertical; + Psychlops.Internal.Main.widgetStack.Height = hei; + api_canvas.Children.Add(Psychlops.Internal.Main.widgetStack); + + UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N]; + dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N]; + for (int i = 0; i < CONST.MAX_OBJ_N; i++) { + UIElementPool[i] = new System.Windows.Controls.Canvas(); masterPool.Children.Add(UIElementPool[i]); + dummyRectPool[i] = new System.Windows.Shapes.Rectangle(); UIElementPool[i].Children.Add(dummyRectPool[i]); + dummyRectPool[i].Visibility = Visibility.Collapsed; } @@ -285,28 +251,8 @@ namespace Psychlops #region static initializer /* - static System.Windows.Shapes.Line api_line; - static System.Windows.Shapes.Path api_curve; - static System.Windows.Shapes.Rectangle api_rect; - static System.Windows.Shapes.Ellipse api_ellipse; - static System.Windows.Shapes.Polygon api_polygon; - static System.Windows.Shapes.Polyline api_polyline; - static System.Windows.Media.Color api_color; - static System.Windows.Media.SolidColorBrush api_fill; - static System.Windows.Media.SolidColorBrush api_stroke; - static System.Windows.Media.TranslateTransform api_translation; static Canvas() { - api_line = new System.Windows.Shapes.Line(); - api_curve = new System.Windows.Shapes.Path(); - api_rect = new System.Windows.Shapes.Rectangle(); - api_ellipse = new System.Windows.Shapes.Ellipse(); - api_polygon = new System.Windows.Shapes.Polygon(); - api_polyline = new System.Windows.Shapes.Polyline(); - api_color = new System.Windows.Media.Color(); - api_fill = new System.Windows.Media.SolidColorBrush(); - api_stroke = new System.Windows.Media.SolidColorBrush(); - api_translation = new System.Windows.Media.TranslateTransform(); } */ #endregion @@ -328,7 +274,6 @@ namespace Psychlops chacked = 1; } //pointStackN = 0; - //brushStackN = 0; lineStackN = 0; rectStackN = 0; polygonStackN = 0; @@ -337,6 +282,8 @@ namespace Psychlops imageStackN = 0; groupStackN = 0; + UIElementPoolN = 0; + brushPoolN = 0; /* pointPoolN = 0; brushPoolN = 0; @@ -385,113 +332,109 @@ namespace Psychlops nextIntervalFrame--; } - - - var en = masterPool.Children.GetEnumerator(); - bool full = en.MoveNext(); - var cnv = en.Current as System.Windows.Controls.Canvas; + var cnv = UIElementPool[0]; if (nextIntervalFrame <= 0) { if (chacked > 0) { if (stackN > 0) { - for (int i = 0; i < stackN - 2; i++) + for (int i = 0; i < stackN; i++) { - if (full == false) + if( null != (rectS = stack[i] as Rectangle) ) { - break; + if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle)) + { + rectS.modifyNative(rectP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); + } } - else + else if (null != (lineS = stack[i] as Line)) { - if( null != (rectS = stack[i] as Rectangle) ) + if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line)) { - if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle)) - { - rectS.modifyNative(rectP, this); - } - else - { - cnv.Children.Clear(); - cnv.Children.Add(stack[i].poolNative(this)); - } + lineS.modifyNative(lineP, this); } - else if (null != (lineS = stack[i] as Line)) + else { - if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line)) - { - lineS.modifyNative(lineP, this); - } - else - { - cnv.Children.Clear(); - cnv.Children.Add(stack[i].poolNative(this)); - } + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); } - else if (null != (ellipseS = stack[i] as Ellipse)) + } + else if (null != (ellipseS = stack[i] as Ellipse)) + { + if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse)) { - if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse)) - { - ellipseS.modifyNative(ellipseP, this); - } - else - { - cnv.Children.Clear(); - cnv.Children.Add(stack[i].poolNative(this)); - } + ellipseS.modifyNative(ellipseP, this); } - else if (null != (polygonS = stack[i] as Polygon)) + else { - if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon)) - { - polygonS.modifyNative(polygonP, this); - } - else - { - cnv.Children.Clear(); - cnv.Children.Add(stack[i].poolNative(this)); - } + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); } - else if (null != (lettersS = stack[i] as Letters)) + } + else if (null != (polygonS = stack[i] as Polygon)) + { + if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon)) { - if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock)) - { - lettersS.modifyNative(lettersP, this); - } - else - { - cnv.Children.Clear(); - cnv.Children.Add(stack[i].poolNative(this)); - } + polygonS.modifyNative(polygonP, this); } - else if (null != (imageS = stack[i] as Image)) + else { - if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image)) - { - imageS.modifyNative(imageP, this); - } - else - { - cnv.Children.Clear(); - cnv.Children.Add(stack[i].poolNative(this)); - } + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); } - else if (null != (groupS = stack[i] as Group)) + } + else if (null != (lettersS = stack[i] as Letters)) + { + if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock)) { - if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas)) - { - groupS.modifyNative(groupP, this); - } - else - { - cnv.Children.Clear(); - cnv.Children.Add(stack[i].poolNative(this)); - } + lettersS.modifyNative(lettersP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); + } + } + else if (null != (imageS = stack[i] as Image)) + { + if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image)) + { + imageS.modifyNative(imageP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); } - full = en.MoveNext(); - cnv = en.Current as System.Windows.Controls.Canvas; } + else if (null != (groupS = stack[i] as Group)) + { + if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas)) + { + groupS.modifyNative(groupP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); + } + } + cnv.Visibility = Visibility.Visible; + UIElementPoolN++; + cnv = UIElementPool[UIElementPoolN]; + } + for (int i = UIElementPoolN; i < lastVisibleN; i++) + { + cnv = UIElementPool[i]; + cnv.Visibility = Visibility.Collapsed; } + lastVisibleN = UIElementPoolN; stackN = 0; } lock (this) @@ -700,6 +643,14 @@ namespace Psychlops { return new SolidColorBrush { Color = d }; } + public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d) + { + var tmp = d.brushPool[d.brushPoolN]; + tmp.Color = this; + d.brushPoolN++; + return tmp; + } + } partial struct Stroke @@ -714,6 +665,13 @@ namespace Psychlops { return new SolidColorBrush { Color = d.color }; } + public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d) + { + var tmp = d.brushPool[d.brushPoolN]; + tmp.Color = this.color; + d.brushPoolN++; + return tmp; + } } partial class Line @@ -755,7 +713,7 @@ namespace Psychlops tmp.Y1 = begin.y; tmp.X2 = end.x; tmp.Y2 = end.y; - if (stroke.thick == 0.0) tmp.Stroke = fill; + if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d); else stroke.apply(tmp); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); @@ -769,7 +727,7 @@ namespace Psychlops tmp.Y1 = begin.y; tmp.X2 = end.x; tmp.Y2 = end.y; - if (stroke.thick == 0.0) tmp.Stroke = fill; + if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d); else stroke.apply(tmp); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); @@ -816,7 +774,7 @@ namespace Psychlops var tmp = d.rectPool[d.rectPoolN]; tmp.Width = width; tmp.Height = height; - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; @@ -827,7 +785,7 @@ namespace Psychlops { tmp.Width = width; tmp.Height = height; - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; @@ -871,7 +829,7 @@ namespace Psychlops var tmp = d.ellipsePool[d.ellipsePoolN]; tmp.Width = width; tmp.Height = height; - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; @@ -882,7 +840,7 @@ namespace Psychlops { tmp.Width = width; tmp.Height = height; - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; @@ -930,7 +888,7 @@ namespace Psychlops public UIElement poolNative(Canvas d) { var tmp = d.polygonPool[d.polygonPoolN]; - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); tmp.Points.Clear(); foreach (var v in vertices) { @@ -944,7 +902,7 @@ namespace Psychlops } public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d) { - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); tmp.Points.Clear(); foreach (var v in vertices) { @@ -1033,7 +991,7 @@ namespace Psychlops tmp.FontStyle = FONT_STYLE_BRIDGE[font.style]; tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight]; tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align]; - tmp.Foreground = fill; + tmp.Foreground = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; @@ -1050,7 +1008,7 @@ namespace Psychlops tmp.FontStyle = FONT_STYLE_BRIDGE[font.style]; tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight]; tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align]; - tmp.Foreground = fill; + tmp.Foreground = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; diff --git a/dev4/psychlops/core/graphic/image.cs b/dev4/psychlops/core/graphic/image.cs index 6d5f3f5..4c775ae 100644 --- a/dev4/psychlops/core/graphic/image.cs +++ b/dev4/psychlops/core/graphic/image.cs @@ -71,6 +71,10 @@ namespace Psychlops{ //buffer.ForEach(func); } + public void load() + { + } + public void draw() { Main.drawable.image(this); diff --git a/dev4/psychlops/extention/math/solver.cs b/dev4/psychlops/extention/math/solver.cs index e26365f..eca5c7a 100644 --- a/dev4/psychlops/extention/math/solver.cs +++ b/dev4/psychlops/extention/math/solver.cs @@ -7,6 +7,10 @@ namespace Psychlops namespace Solver { + internal static class CONST + { + public static readonly uint MAX_ARG = 5; + } static public class Constants @@ -112,6 +116,10 @@ namespace Psychlops public BinomialLikelihoodThread() { + itvl = new Interval[CONST.MAX_ARG]; + step = new double[CONST.MAX_ARG]; + champ = new double[CONST.MAX_ARG]; + data = new BernoulliProcess(); } public void waitLoop() { @@ -237,6 +245,9 @@ namespace Psychlops public BinomialLikelihood() { + itvl = new Interval[CONST.MAX_ARG]; + step = new double[CONST.MAX_ARG]; + champ = new double[CONST.MAX_ARG]; iteration = 2; } @@ -248,11 +259,8 @@ namespace Psychlops BinomialLikelihoodThread[] l = new BinomialLikelihoodThread[4]; - double r, low, high; for (int k = 0; k < iteration; k++) { - champ_like = 0; - begin_base(l); for (int i = 0; i < 4; i++) { @@ -261,14 +269,6 @@ namespace Psychlops l[i].loop1(); } end_base(l); - - for (int j = 0; j < Constants.LIMIT; j++) - { - r = itvl[j].end.val - itvl[j].begin.val; - low = champ[j] - r / 8.0 < itvl[j].begin.val ? itvl[j].begin.val : champ[j] - r / 8.0; - high = champ[j] + r / 8.0 > itvl[j].end.val ? itvl[j].end.val : champ[j] + r / 8.0; - itvl[j] = new Interval(low, high); - } } } public void begin(Constants.Func2 d_func) @@ -277,11 +277,8 @@ namespace Psychlops BinomialLikelihoodThread[] l = new BinomialLikelihoodThread[4]; - double r, low, high; for (int k = 0; k < iteration; k++) { - champ_like = 0; - begin_base(l); for (int i = 0; i < 4; i++) { @@ -290,14 +287,6 @@ namespace Psychlops l[i].loop2(); } end_base(l); - - for (int j = 0; j < Constants.LIMIT; j++) - { - r = itvl[j].end.val - itvl[j].begin.val; - low = champ[j] - r / 8.0 < itvl[j].begin.val ? itvl[j].begin.val : champ[j] - r / 8.0; - high = champ[j] + r / 8.0 > itvl[j].end.val ? itvl[j].end.val : champ[j] + r / 8.0; - itvl[j] = new Interval(low, high); - } } } public void begin(Constants.Func3 d_func) @@ -306,11 +295,8 @@ namespace Psychlops BinomialLikelihoodThread[] l = new BinomialLikelihoodThread[4]; - double r, low, high; for (int k = 0; k < iteration; k++) { - champ_like = 0; - begin_base(l); for(int i=0; i<4; i++) { l[i].data = data; @@ -318,14 +304,6 @@ namespace Psychlops l[i].loop3(); } end_base(l); - - for (int j = 0; j < Constants.LIMIT; j++) - { - r = itvl[j].end.val - itvl[j].begin.val; - low = champ[j]-r/8.0 < itvl[j].begin.val ? itvl[j].begin.val : champ[j]-r/8.0; - high = champ[j]+r/8.0 > itvl[j].end.val ? itvl[j].end.val : champ[j]+r/8.0; - itvl[j] = new Interval(low, high); - } } } @@ -338,6 +316,8 @@ namespace Psychlops void begin_base(BinomialLikelihoodThread[] l) { + champ_like = 0; + data.length = data.elems.GetLength(0); for (int i = 0; i < data.elems.GetLength(0); i++) { @@ -373,6 +353,15 @@ namespace Psychlops } } + double r, low, high; + for (int j = 0; j < Constants.LIMIT; j++) + { + r = itvl[j].end.val - itvl[j].begin.val; + low = champ[j] - r / 8.0 < itvl[j].begin.val ? itvl[j].begin.val : champ[j] - r / 8.0; + high = champ[j] + r / 8.0 > itvl[j].end.val ? itvl[j].end.val : champ[j] + r / 8.0; + itvl[j] = new Interval(low, high); + } + } diff --git a/dev4/psychlops/extention/standard/widget.cs b/dev4/psychlops/extention/standard/widget.cs index 4fe21e7..9d5a71c 100644 --- a/dev4/psychlops/extention/standard/widget.cs +++ b/dev4/psychlops/extention/standard/widget.cs @@ -79,33 +79,107 @@ namespace Psychlops public WidgetRect& pushThis(); }; */ + /* public class Slider { + public string label; public Rectangle outer; + public Rectangle inner; + public Stroke outer_strk; + + public Slider() + { + set(0, 0); + } + public Slider(double width, double height) + { + set(width, height); + } + public Slider set(double width, double height) + { + outer = new Rectangle(width, height); + outer.fill = Color.gray; + inner = new Rectangle(); + inner.fill = Color.blue; + outer_strk = new Stroke(); + outer_strk.color = Color.white; + outer_strk.thick = 1; + return this; + } + public void checkClick() + { + if (outer.include(Mouse.position)) + { + outer.stroke = outer_strk; + } + } } - */ + */ + public class Slider { + public static Color bgcolor; + internal System.Windows.UIElement instance; internal System.Windows.Controls.Slider uislider; + internal System.Windows.Controls.TextBlock uilabel; + internal System.Windows.Controls.TextBox uibox; internal string label; internal Interval range; + internal SelfDelegate get_; + internal SelfDelegate set_; + internal double retval; + internal bool setted_; + + static Slider() + { + bgcolor.set(.5,.5, .5, .3); + } - public Slider(string l, Interval r) + public Slider(string l, Interval r, double initialvalue) { + retval = initialvalue; range = r; label = l; + setted_ = false; Psychlops.Widgets.Connector.stackSlider(this); + get_ = new SelfDelegate(get__); + set_ = new SelfDelegate(set__); + while (!setted_) { System.Threading.Thread.Sleep(10); } } public static implicit operator double(Slider s) { return s.value; } - public double value { - get { return uislider.Value; } - set { if(uislider!=null) uislider.Dispatcher.BeginInvoke( new Action(Connector.sliderSet) , uislider, value ); } + + public delegate void SelfDelegate(System.Windows.Controls.Slider s); + public void get__(System.Windows.Controls.Slider s) { retval = s.Value; } + public void set__(System.Windows.Controls.Slider s) { s.Value = retval; } + + public double getValue() + { + if (uislider != null) { + uislider.Dispatcher.BeginInvoke(get_, uislider); + return retval; + } else { + return 0; + } + } + public void setValue(double v) + { + if (uislider != null) + { + retval = v; + uislider.Dispatcher.BeginInvoke(set_, uislider); + } + } + + public double value + { + get { return getValue(); } + set { setValue(value); } } public bool changed { get; set; } } @@ -178,7 +252,6 @@ namespace Psychlops } - internal static class Connector { internal delegate void VoidString(string s); @@ -193,15 +266,22 @@ namespace Psychlops } static void stackSlider__(Slider ss) { - var holder = new System.Windows.Controls.Canvas { Width = 200 }; + var label = new System.Windows.Controls.TextBlock { Text = ss.label }; + label.Foreground = Color.white; + System.Windows.Controls.Canvas.SetLeft(label, 3); + System.Windows.Controls.Canvas.SetTop(label, 3); + ss.uilabel = label; + + var holder = new System.Windows.Controls.Canvas { Width = 200, Height = 50 }; var val = new System.Windows.Controls.TextBox { Width = 100 }; System.Windows.Controls.Canvas.SetLeft(val, 100); var slide = new System.Windows.Controls.Slider { Minimum = ss.range.begin.val, Maximum = ss.range.end.val, Name = ss.label, + Value = ss.retval, Tag = ss, Width = 200, }; - System.Windows.Controls.Canvas.SetTop(slide, 25); + System.Windows.Controls.Canvas.SetTop(slide, label.ActualHeight - 3); var b = new System.Windows.Data.Binding { Path = new PropertyPath("Value"), Mode = System.Windows.Data.BindingMode.TwoWay, @@ -209,30 +289,24 @@ namespace Psychlops }; val.SetBinding(TextBox.TextProperty, b); ss.uislider = slide; - //var b2 = new System.Windows.Data.Binding - //{ - // Path = new PropertyPath("value"), - // Mode = System.Windows.Data.BindingMode.TwoWay, - // Source = ss, - //}; - //val.SetBinding(System.Windows.Controls.Slider.ValueProperty, b2); - var label = new System.Windows.Controls.TextBlock { Text = ss.label }; - System.Windows.Controls.Canvas.SetLeft(label, 3); - System.Windows.Controls.Canvas.SetTop(label, 3); + ss.uibox = val; + val.Background = Color.null_color; + val.BorderBrush = Color.null_color; + val.Foreground = Color.white; + + holder.Background = Slider.bgcolor; holder.Children.Add(label); - holder.Children.Add(slide); holder.Children.Add(val); + holder.Children.Add(slide); + holder.Height = label.ActualHeight + slide.ActualHeight + val.ActualHeight + 15; ss.instance = holder; Internal.Main.widgetStack.Children.Add(ss.instance); + ss.setted_ = true; } - public static void sliderSet(System.Windows.Controls.Slider s, double v) - { - s.Value = v; - } - } } -} \ No newline at end of file +} + diff --git a/test4/MainPage.xaml.cs b/test4/MainPage.xaml.cs index 685c460..0889ace 100644 --- a/test4/MainPage.xaml.cs +++ b/test4/MainPage.xaml.cs @@ -38,7 +38,7 @@ namespace PsychlopsSilverlight4test //main_routine = main.psychlops_main(); Psychlops.Internal.Main.statusBar = AppStatusBar; - Psychlops.Internal.Main.widgetStack = Controller; + //Psychlops.Internal.Main.widgetStack = Controller; AppStatusBar.Text = "Now starting Psychlops environment... please wait a minute"; } protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e) { diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs index e7b6754..2794969 100644 --- a/test4/PsychlopsMain.cs +++ b/test4/PsychlopsMain.cs @@ -1,4 +1,4 @@ -/*using Psychlops; +using Psychlops; namespace PsychlopsSilverlight4test { @@ -14,12 +14,19 @@ namespace PsychlopsSilverlight4test 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; + double Axis = 0.0, BGRadii = 150, BGSize = 5.0; + Psychlops.Widgets.Slider thetaSpeed, DotNumber; + + public void psychlops_main() - { + { cnvs = new Canvas(500, 500); + 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++){ @@ -56,11 +63,11 @@ namespace PsychlopsSilverlight4test for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize); double COS, SIN; - DotNumber = 200; + //DotNumber = 200; //Main stimulus loop while(true){ //Clear the main window - cnvs.clear(Color.green); + cnvs.clear(); temp=Axis/360*2*Math.PI; @@ -108,7 +115,8 @@ namespace PsychlopsSilverlight4test } } -*/ + + /*using Psychlops; @@ -156,10 +164,10 @@ namespace PsychlopsSilverlight4test } -*/ +/* using Psychlops; namespace Psychlops @@ -224,7 +232,7 @@ namespace PsychlopsSilverlight4test shape = poly; var rng = new Interval(); - var slider = new Psychlops.Widgets.Slider("tesrt", 0 <= rng <= 5); + var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100); dots = new RandomDots(); @@ -241,36 +249,37 @@ namespace PsychlopsSilverlight4test { fixation.centering().shift(100, 100); fixation.draw(new Stroke(Color.blue, 3)); - }*/ + }* / - fixation.centering(); + fixation.centering().shift(slider, 0); 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, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60); - img.centering(Mouse.position); - img.draw(); - //g.centering(Mouse.position).draw(); - //g.rotation += 1; + //img.centering(Mouse.position); + //img.draw(); + g.centering(Mouse.position).draw(); + g.rotation += 1; shape.centering(Mouse.position).shift(100, 0); shape.draw(); if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100); cnvs.var(frames, 0, 20); - slider.value = frames / 100.0; + //slider.value = frames / 100.0; /*if (frames % 2 != 0) { fixation.shift(100, 100); fixation.draw(new Stroke(Color.green, 3)); - }*/ + }* / for (int i = 0; i < dots.cood.Length; i++) { dots.cood[i].set(Math.random(500), Math.random(500)); } + cnvs.var((double)slider, 200, 200); dots.draw(); cnvs.flip(); @@ -279,3 +288,45 @@ namespace PsychlopsSilverlight4test } } +**/ + + +/* + +using Psychlops; +namespace PsychlopsSilverlight4test +{ + + public class PsychlopsMain + { + Canvas cnvs; + Rectangle[] rect; + int n; + + public void psychlops_main() + { + n = 1; + cnvs = new Canvas(500, 500); + rect = new Rectangle[n]; + for (int i = 0; i < n; i++) + { + rect[i] = new Rectangle(10, 10); + rect[i].fill = Color.red; + } + Interval rng = new Interval(); + var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100); + + while (true) + { + cnvs.clear(); + for (int i = 0; i < n; i++) + { + rect[i].centering().shift(slider * i*3, i*3).draw(); + } + cnvs.flip(); + } + } + } +} + +*/ \ No newline at end of file -- 2.11.0