[chronojump] ForceSensor cubic interpolation done at load



commit cbaf8f072c372b4211bc0f26a306d1820bd15ec8
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon May 10 11:39:58 2021 +0200

    ForceSensor cubic interpolation done at load

 src/gui/app1/chronojump.cs  |   2 +-
 src/gui/app1/forceSensor.cs |  41 +++++++++++++++++
 src/utilMath.cs             | 109 ++++++++++++++++++++++++++++++--------------
 3 files changed, 116 insertions(+), 36 deletions(-)
---
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 42e55f8a..2f542fc8 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -941,7 +941,7 @@ public partial class ChronoJumpWindow
                ForceSensorCapturePoints.TestVariabilityCVRMSSD();
 
                //InterpolateSignal.TestInterpolateBetween();
-               InterpolateSignal.TestCosineAndCubicInterpolate();
+               //InterpolateSignal.TestCosineAndCubicInterpolate();
        }
 
 
diff --git a/src/gui/app1/forceSensor.cs b/src/gui/app1/forceSensor.cs
index bb4ef118..4cb5bf1b 100644
--- a/src/gui/app1/forceSensor.cs
+++ b/src/gui/app1/forceSensor.cs
@@ -126,6 +126,7 @@ public partial class ChronoJumpWindow
        Gdk.GC pen_white_force_capture;
        //Gdk.GC pen_yellow_force_capture;
        Gdk.GC pen_blue_light_force_capture;
+       Gdk.GC pen_blue_light_force_capture_interpolated_feedback;
        Gdk.GC pen_yellow_dark_force_capture;
        //Gdk.GC pen_orange_dark_force_capture;
        Gdk.GC pen_blue_dark_force_capture;
@@ -190,6 +191,10 @@ public partial class ChronoJumpWindow
                pen_blue_light_force_capture.Foreground = UtilGtk.LIGHT_BLUE_PLOTS;
                pen_blue_light_force_capture.SetLineAttributes (2, Gdk.LineStyle.Solid, Gdk.CapStyle.NotLast, 
Gdk.JoinStyle.Miter);
 
+               pen_blue_light_force_capture_interpolated_feedback = new 
Gdk.GC(force_capture_drawingarea.GdkWindow);
+               pen_blue_light_force_capture_interpolated_feedback.Foreground = UtilGtk.LIGHT_BLUE_PLOTS;
+               pen_blue_light_force_capture_interpolated_feedback.SetLineAttributes (60, 
Gdk.LineStyle.Solid, Gdk.CapStyle.NotLast, Gdk.JoinStyle.Round);
+
                //pen_yellow_force_capture = new Gdk.GC(force_capture_drawingarea.GdkWindow);
                //pen_yellow_force_capture.Foreground = UtilGtk.YELLOW;
                //pen_yellow_force_capture.SetLineAttributes (2, Gdk.LineStyle.Solid, Gdk.CapStyle.NotLast, 
Gdk.JoinStyle.Miter);
@@ -1939,6 +1944,8 @@ LogB.Information(" fs R ");
                                );
                //showForceSensorTriggers (); TODO until know where to put it
 
+               createForceSensorCaptureInterpolateSignal();
+
                forceSensorCopyTempAndDoGraphs(forceSensorGraphsEnum.SIGNAL);
                //image_force_sensor_graph.Sensitive = false; //unsensitivize the RFD image (can contain info 
of previous data)
                notebook_force_sensor_analyze_top.CurrentPage = 
Convert.ToInt32(notebook_force_sensor_analyze_top_pages.CURRENTSETSIGNAL);
@@ -2025,6 +2032,15 @@ LogB.Information(" fs R ");
                Sqlite.Close();
        }
 
+       //right now to do tests
+       List<PointF> interpolate_l;
+       private void createForceSensorCaptureInterpolateSignal()
+       {
+               //create random forces from 1200 to 2400, 4000 ms aprox, 4 points (4000/1000)
+               //between each of the points interpolation will happen
+               InterpolateSignal interpolateS = new InterpolateSignal(1200, 2400, 4000, 1000);
+               interpolate_l = interpolateS.GetCubicInterpolated();
+       }
 
        // ----start of forceSensorDeleteTest stuff -------
 
@@ -2342,6 +2358,30 @@ LogB.Information(" fs R ");
                                        forceSensorValues.Min, false))
                        fscPoints.Redo();
 
+
+               //draw interpolated feedback
+               if(interpolate_l != null)
+               {
+                       //LogB.Information(string.Format("interpolate counts: {0} {1}",
+                       //      fscPoints.Points.Count, interpolate_l.Count));
+
+                       Gdk.Point [] paintPointsInterpolate = new Gdk.Point[fscPoints.Points.Count];
+                       for(int i = 0, j= 0; i < fscPoints.Points.Count; i ++, j ++)
+                       {
+                               //to cycle
+                               if(j == interpolate_l.Count)
+                                       j = 0;
+
+                               paintPointsInterpolate[i].X = fscPoints.Points[i].X;
+                               paintPointsInterpolate[i].Y = fscPoints.GetForceInPx(interpolate_l[j].Y);
+                               //LogB.Information(string.Format("interpolate_l: {0} {1}",
+                               //                      interpolate_l[i].X, interpolate_l[i].Y));
+                       }
+
+                       force_capture_pixmap.DrawLines(pen_blue_light_force_capture_interpolated_feedback, 
paintPointsInterpolate);
+               }
+
+
                forcePaintHVLines(ForceSensorGraphs.CAPTURE,
                                getForceSensorMaxForceIncludingRectangle(forceSensorValues.Max),
                                forceSensorValues.Min, forceSensorValues.TimeLast,
@@ -2359,6 +2399,7 @@ LogB.Information(" fs R ");
 
                force_capture_pixmap.DrawLines(pen_black_force_capture, paintPoints);
 
+
                //draw rectangle in maxForce
                //force_capture_pixmap.DrawRectangle(pen_red_force_capture, false,
                //              new Gdk.Rectangle(fscPoints.GetTimeInPx(maxForceTime) -5, 
fscPoints.GetForceInPx(maxForce) -5, 10, 10));
diff --git a/src/utilMath.cs b/src/utilMath.cs
index ff1cf456..76c02ed2 100644
--- a/src/utilMath.cs
+++ b/src/utilMath.cs
@@ -398,6 +398,15 @@ public class InterpolateSignal
        {
                this.point_l = point_l;
        }
+       public InterpolateSignal (int minY, int maxY, int maxX, int stepX)
+       {
+               Random random = new Random();
+               this.point_l = new List<PointF>();
+               int range = maxY - minY;
+
+               for(int i = 0; i < maxX; i += stepX)
+                       point_l.Add(new PointF(i, minY + (random.NextDouble() * range)));
+       }
 
        //thanks to: http://paulbourke.net/miscellaneous/interpolation/
        public double CosineInterpolate(double y1, double y2, double mu)
@@ -431,55 +440,85 @@ public class InterpolateSignal
                        l.Add(new PointF(i, random.NextDouble() * 10));
 
                InterpolateSignal fsp = new InterpolateSignal(l);
-               fsp.testCosineCubicInterpolateDo(types.COSINE);
-               fsp.testCosineCubicInterpolateDo(types.CUBIC);
+
+               //cosine
+               fsp.testCosineCubicInterpolateDo(types.COSINE, false);
+
+               //cubic
+               //List<PointF> interpolated_l = fsp.testCosineCubicInterpolateDo(types.CUBIC, false);
+               //toFile(interpolated_l, types.CUBIC);
+               fsp.testCosineCubicInterpolateDo(types.CUBIC, false);
        }
 
-       private void testCosineCubicInterpolateDo(types type)
+       public List<PointF> GetCubicInterpolated()
        {
-               TextWriter writer = File.CreateText(
-                               Path.Combine(Path.GetTempPath(), 
string.Format("chronojump_testinterpolate_{0}.csv", type.ToString())));
-               writer.WriteLine("X;Y;color;cex");
+               return testCosineCubicInterpolateDo(types.CUBIC, false);
+       }
+
+       private List<PointF> testCosineCubicInterpolateDo(types type, bool toFile)
+       {
+               List<PointF> interpolated_l = new List<PointF>();
 
-               for(int i = 0; i < point_l.Count -1; i ++) //each known point
+               for(int i = 0; i < point_l.Count; i ++) //each known point
                {
-                       writer.WriteLine(string.Format("{0};{1};{2};{3}",
-                                               point_l[i].X, point_l[i].Y, "red", 2));
-                       for(double d = 0; d < 1 ; d += .1) //each interpolated value
+                       for(double j = 0; j < 1 ; j += .01) //each interpolated value
                        {
                                if (type == types.COSINE)
-                                       writer.WriteLine(string.Format("{0};{1};{2};{3}",
-                                                               point_l[i].X + d*(point_l[i+1].X - 
point_l[i].X),
-                                                               CosineInterpolate(point_l[i].Y, 
point_l[i+1].Y, d),
-                                                               "black", 1));
-                               //else if(type == types.CUBIC && i > 0 && i < point_l.Count -2)
+                               {
+                                       int second = i+1; //the second point
+                                       if(i == point_l.Count -1)
+                                               second = 0;
+
+                                       interpolated_l.Add(new PointF(
+                                                       point_l[i].X + j*(point_l[second].X - point_l[i].X),
+                                                       CosineInterpolate(point_l[i].Y, point_l[second].Y, 
j)));
+                               }
                                else if(type == types.CUBIC)
                                {
                                        //for cubic we need two extra points
-                                       double pre2Y = 0;
-                                       double post2Y = 0;
-                                       if(i == 0) {
-                                               pre2Y = point_l[point_l.Count -1].Y;
-                                               post2Y = point_l[i+2].Y;
-                                       } else if(i == point_l.Count -2) {
-                                               pre2Y = point_l[i-1].Y;
-                                               post2Y = point_l[0].Y;
-                                       } else {
-                                               pre2Y = point_l[i-1].Y;
-                                               post2Y = point_l[i+2].Y;
+                                       int a = i-1;
+                                       int b = i;
+                                       int c = i+1;
+                                       int d = i+2;
+                                       if(i == 0)
+                                               a = point_l.Count -1;
+                                       else if(i == point_l.Count -2)
+                                               d = 0;
+                                       else if(i == point_l.Count -1) {
+                                               c = 0;
+                                               d = 1;
                                        }
 
-                                       writer.WriteLine(string.Format("{0};{1};{2};{3}",
-                                                               point_l[i].X + d*(point_l[i+1].X - 
point_l[i].X),
-                                                               //CubicInterpolate(point_l[i-1].Y, 
point_l[i].Y, point_l[i+1].Y, point_l[i+2].Y, d),
-                                                               CubicInterpolate(pre2Y, point_l[i].Y, 
point_l[i+1].Y, post2Y, d),
-                                                               "green", 1));
+                                       interpolated_l.Add(new PointF(
+                                                               point_l[b].X + j*(point_l[c].X - 
point_l[b].X),
+                                                               CubicInterpolate(
+                                                                       point_l[a].Y,
+                                                                       point_l[b].Y,
+                                                                       point_l[c].Y,
+                                                                       point_l[d].Y,
+                                                                       j)));
                                }
                        }
                }
-               //write the last known point
-               writer.WriteLine(string.Format("{0};{1};{2};{3}",
-                                       point_l[point_l.Count -1].X, point_l[point_l.Count -1].Y, "red", 2));
+
+               return interpolated_l;
+       }
+
+       //just to debug, unused right now
+       private void toFile(List<PointF> interpolated_l, types type)
+       {
+               TextWriter writer = File.CreateText(
+                               Path.Combine(Path.GetTempPath(), 
string.Format("chronojump_testinterpolate_{0}.csv", type.ToString())));
+
+               writer.WriteLine("X;Y;color;cex");
+
+               for(int i = 0; i < point_l.Count; i ++)
+                       writer.WriteLine(string.Format("{0};{1};{2};{3}",
+                                               point_l[i].X, point_l[i].Y, "red", 2));
+
+               for(int i = 0; i < interpolated_l.Count; i ++)
+                       writer.WriteLine(string.Format("{0};{1};{2};{3}",
+                                               interpolated_l[i].X, interpolated_l[i].Y, "black", 1));
 
                writer.Flush();
                writer.Close();
@@ -492,7 +531,7 @@ public class InterpolateSignal
                   par(new=T)
                   d=read.csv2("/tmp/chronojump_testinterpolate_CUBIC.csv")
                   plot(d$X, d$Y, col=d$color, cex=d$cex, type="b", xlim=c(0,90), ylim=c(0,10))
-                  */
+                */
        }
 
        /* unused


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]