[chronojump] Fixed commit: "forceSensorAnalyze manual. Optimization on RFDs calculation"



commit 11d3bc8fc47b809c0c9367bfa425c22750cfb43a
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu May 10 15:39:03 2018 +0200

    Fixed commit: "forceSensorAnalyze manual. Optimization on RFDs calculation"

 src/forceSensor.cs            |   15 +++++++++++----
 src/gui/forceSensorAnalyze.cs |   38 ++++++++++++++++++++++----------------
 2 files changed, 33 insertions(+), 20 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 2afd6d6..45301e6 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -751,13 +751,15 @@ public class ForceSensorAnalyzeInstant
         * Calculates RFD in a point using previous and next point
         */
 //TODO: fer que es vagi recordant el max en un rang determinat pq no s'hagi de tornar a calcular
-       public double CalculateMaxRFDInRange(int countA, int countB, out int countRFDMax)
+       public double LastRFDMax;
+       public int LastRFDMaxCount;
+       public void CalculateMaxRFDInRange(int countA, int countB)
        {
                double max = 0;
                double current = 0;
-               countRFDMax = countA; //count where maxRFD is found
+               int countRFDMax = countA; //count where maxRFD is found
 
-               for(int i = countA; i < countB ; i ++)
+               for(int i = countA; i < countB; i ++)
                {
                        current = fscAIPoints.GetRFD(i-1, i+1);
                        if(current > max)
@@ -767,7 +769,9 @@ public class ForceSensorAnalyzeInstant
                        }
                }
 
-               return max;
+               //stored to read them from forceSensorAnalyze manual table and graph
+               LastRFDMax = max;
+               LastRFDMaxCount = countRFDMax;
        }
 
        /* this method is not working
@@ -794,6 +798,8 @@ public class ForceSensorAnalyzeInstant
 
        public void CalculateRFDTangentLine(int countRFDMax, out int lineXStart, out int lineXEnd, out int 
lineYStart, out int lineYEnd)
        {
+               LogB.Information(string.Format("CalculateRFDTangentLine: {0}" , countRFDMax));
+
                // 1) calculate X and Y of points before and after RFD
                int pointXBefore = GetXFromSampleCount(countRFDMax -1, GetLength());
                int pointXAfter = GetXFromSampleCount(countRFDMax +1, GetLength());
@@ -819,6 +825,7 @@ public class ForceSensorAnalyzeInstant
                lineYEnd = 0;
        }
 
+       //TODO: better if all this time, force, rfd params are on this class, so don't need to read labels 
from main gui
        public void ExportToCSV(int countA, int countB, string selectedFileName, string sepString,
                        double timeA, double timeB, double timeDiff,
                        double forceA, double forceB, double forceDiff, double forceAvg, double forceMax,
diff --git a/src/gui/forceSensorAnalyze.cs b/src/gui/forceSensorAnalyze.cs
index 08f6d4c..18926e5 100644
--- a/src/gui/forceSensorAnalyze.cs
+++ b/src/gui/forceSensorAnalyze.cs
@@ -800,11 +800,12 @@ public partial class ChronoJumpWindow
                        // 9) calculate and paint max RFD (circle and line)
                        //value of count that produce the max RFD (between the previous and next value)
 
-                       if(hscaleLower == 0 || hscaleHigher >= fsAI.GetLength() -1)
+                       if(hscaleLower <= 0 || hscaleHigher >= fsAI.GetLength() -1)
                                return;
 
-                       int countRFDMax = hscaleLower;
-                       layout_force_ai_text.SetMarkup(string.Format("RFD Max: {0} N/s", 
label_force_sensor_ai_rfd_max.Text));
+                       layout_force_ai_text.SetMarkup(string.Format("RFD Max: {0} N/s",
+                                               Math.Round(fsAI.LastRFDMax, 1) ));
+                       int countRFDMax = fsAI.LastRFDMaxCount;
 
                        layout_force_ai_text.GetPixelSize(out textWidth, out textHeight);
                        force_sensor_ai_pixmap.DrawLayout (pen_red_force_ai,
@@ -829,14 +830,17 @@ public partial class ChronoJumpWindow
                                        xAtTop, 0);
                                        */
 
-                       //calculate line
-                       int lineXStart; int lineXEnd;
-                       int lineYStart; int lineYEnd;
-                       fsAI.CalculateRFDTangentLine(countRFDMax, out lineXStart, out lineXEnd, out 
lineYStart, out lineYEnd);
-                       force_sensor_ai_pixmap.DrawLine(pen_red_force_ai, lineXStart, lineYStart, lineXEnd, 
lineYEnd);
-
-                       if(debug)
-                               plotRFDLineDebugConstruction(countRFDMax);
+                       if(countRFDMax -1 >= 0 && countRFDMax +1 < fsAI.GetLength() -1)
+                       {
+                               //calculate line
+                               int lineXStart; int lineXEnd;
+                               int lineYStart; int lineYEnd;
+                               fsAI.CalculateRFDTangentLine(countRFDMax, out lineXStart, out lineXEnd, out 
lineYStart, out lineYEnd);
+                               force_sensor_ai_pixmap.DrawLine(pen_red_force_ai, lineXStart, lineYStart, 
lineXEnd, lineYEnd);
+
+                               if(debug)
+                                       plotRFDLineDebugConstruction(countRFDMax);
+                       }
 
 
                        // 10) calculate and paint impulse
@@ -959,6 +963,7 @@ public partial class ChronoJumpWindow
                else
                        button_force_sensor_analyze_AB_save.Visible = false;
 
+               force_sensor_analyze_instant_calculate_params();
                forceSensorAIChanged = true; //to actually plot
                force_sensor_ai_drawingarea.QueueDraw(); // -- refresh
        }
@@ -1027,11 +1032,12 @@ public partial class ChronoJumpWindow
                        label_force_sensor_ai_rfd_average.Text = Math.Round(fsAI.CalculateRFD(countA, 
countB), 1).ToString();
 
                        // 3) max
-                       int countRFDMax = countA;
-                       double rfdMax = Math.Round(fsAI.CalculateMaxRFDInRange(
-                                               countA, countB,
-                                               out countRFDMax), 1);
-                       label_force_sensor_ai_rfd_max.Text = rfdMax.ToString();
+                       fsAI.CalculateMaxRFDInRange(countA, countB);
+
+                       //LogB.Information(string.Format("fsAI.LastRFDMax: {0}", fsAI.LastRFDMax));
+                       //LogB.Information(string.Format("fsAI.LastRFDMaxCount: {0}", fsAI.LastRFDMaxCount));
+
+                       label_force_sensor_ai_rfd_max.Text = Math.Round(fsAI.LastRFDMax, 1).ToString();
                } else {
                        label_force_sensor_ai_rfd_diff.Text = "";
                        label_force_sensor_ai_rfd_average.Text = "";


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