[chronojump] Triggers shown on instaneous graphs if not used for cutting repetitions



commit 3900925fce27d0290d2e36b6b7b6d2a8cad33d54
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Jan 15 17:28:45 2018 +0100

    Triggers shown on instaneous graphs if not used for cutting repetitions

 encoder/capture.R   |    6 ++--
 encoder/graph.R     |   60 ++++++++++++++++++++++++++++++++++++++------------
 encoder/util.R      |   24 +++++++++++++++++---
 src/encoder.cs      |    5 +++-
 src/encoderRProc.cs |    8 ++++++-
 src/gui/encoder.cs  |    3 ++
 src/utilEncoder.cs  |    6 +++-
 7 files changed, 86 insertions(+), 26 deletions(-)
---
diff --git a/encoder/capture.R b/encoder/capture.R
index 6d0f5a2..8f9eecb 100644
--- a/encoder/capture.R
+++ b/encoder/capture.R
@@ -41,8 +41,8 @@ calcule <- function(displacement, op, curveNum, startInSet)
        if(length(displacement) < 4)
                return (curveNum)
 
-       #minHeight is checked when ! using triggers
-       if(op$TriggersOnList != -1 && abs(sum(displacement)) < op$MinHeight)
+       #minHeight is checked when ! cut by triggers
+       if(! cutByTriggers(op) && abs(sum(displacement)) < op$MinHeight)
                return (curveNum)
 
 
@@ -224,7 +224,7 @@ doProcess <- function(options)
 
                start = NULL
                end = NULL
-               if(op$TriggersOnList != -1)
+               if(cutByTriggers(op))
                {
                        start = 1
                        end = length(displacement)
diff --git a/encoder/graph.R b/encoder/graph.R
index 3e94be5..6d4c0a9 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -37,7 +37,7 @@
 #if(singleFile) define curves using findCurves function
 #if analysis is single: paint 
 #if analysis is side: kinematicRanges will call kinematicsF to know common axes (max and mins) and the call 
to paint 
-#using curves and powerBars, paf table will be created. This will be used always, because writeCurves (on a 
file) is always true
+#using curves and powerBars, paf table will be created. This will be used always, because writeCurves (on a 
file) is always TRUE
 #if(Analysis=="exportCSV") data will be exported to CSV file
 #----------------------------------
 
@@ -500,7 +500,8 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
                   
encoderConfigurationName,diameter,diameterExt,anglePush,angleWeight,inertiaMomentum,gearedDown, 
#encoderConfiguration stuff
                   title, subtitle, draw, width, showLabels, marShrink, showAxes, legend,
                   Analysis, isPropulsive, inertialType, exercisePercentBodyWeight,
-                  showSpeed, showAccel, showForce, showPower   
+                  showSpeed, showAccel, showForce, showPower,
+                 triggersOnList #will be empty if cutByTriggers
 ) {
         
         meanSpeedE = 0
@@ -582,6 +583,14 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
                 else
                         
plot(startX:length(position),yValues,type="l",xlim=c(1,length(position)),ylim=ylim,xlab="",ylab="",col=colNormal,lty=2,lwd=3,axes=F)
                 abline(h=0,lty=3,col="black")
+
+               if(triggersOnList != "" && triggersOnList != -1)
+               {
+                       print("triggersOnList-xmin")
+                       print(triggersOnList-xmin)
+                       abline(v=(triggersOnList-xmin), col="yellow", lwd=2)
+                       #mtext(side=3, at=(triggersOnList-xmin), text=(triggersOnList-xmin), cex=.8)
+               }
                 
                 #abline(v=seq(from=0,to=length(position),by=500),lty=3,col="gray")
         }
@@ -1097,7 +1106,8 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
         #legend, axes and title
         if(draw) {
                 if(legend & showAxes) {
-                        paintVariablesLegend(showSpeed, showAccel, showForce, showPower)
+                        paintVariablesLegend(showSpeed, showAccel, showForce, showPower,
+                                            (triggersOnList != "" && triggersOnList != -1))
                 }
                 if(showLabels) {
                         mtext(paste(translateToPrint("time"),"(ms)"),side=1,adj=1,line=-1,cex=.9)
@@ -1106,7 +1116,7 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
         }
 }
 
-paintVariablesLegend <- function(showSpeed, showAccel, showForce, showPower) 
+paintVariablesLegend <- function(showSpeed, showAccel, showForce, showPower, showTriggers)
 {
         legendText=c(paste(translateToPrint("Distance"),"(mm)"))
         lty=c(1)
@@ -1142,6 +1152,13 @@ paintVariablesLegend <- function(showSpeed, showAccel, showForce, showPower)
                 colors=c(colors,cols[3]) 
                 ncol=ncol+1
         }
+        if(showTriggers) {
+                legendText=c(legendText, translateToPrint("Triggers"))
+                lty=c(lty,1)
+                lwd=c(lwd,2)
+                colors=c(colors,"yellow")
+                ncol=ncol+1
+        }
         
         
         #plot legend on top exactly out
@@ -2472,7 +2489,7 @@ doProcess <- function(options)
                 par(mar=c(2,2.5,2,1))
         }
         
-        #when a csv is used (it links to lot of files) then singleFile = false
+        #when a csv is used (it links to lot of files) then singleFile = FALSE
         singleFile = TRUE
         if(nchar(op$File) >= 40) {
                 #file="/tmp...../chronojump-encoder-graph-input-multi.csv"
@@ -2676,7 +2693,7 @@ doProcess <- function(options)
                 }
                 
                 print(c("SmoothingsEC:",SmoothingsEC))
-        } else {       #singleFile == True. reads a signal file
+        } else {       #singleFile == TRUE reads a signal file
                 displacement <- scan(file=op$File,sep=",")
                 #if data file ends with comma. Last character will be an NA. remove it
                 #this removes all NAs
@@ -2721,7 +2738,7 @@ doProcess <- function(options)
                 position=cumsum(displacement)
 
                #if(usingTriggers)
-               if(op$TriggersOnList != -1)
+               if(cutByTriggers(op))
                         curves <- findCurvesByTriggers(displacement, op$TriggersOnList)
                 else
                         curves <- findCurvesNew(displacement, op$Eccon,
@@ -2746,8 +2763,8 @@ doProcess <- function(options)
                 
                 for(i in 1:n)
                 {
-                       #reduceCurveBySpeed only when ! triggers
-                       if(op$TriggersOnList == -1)
+                       #reduceCurveBySpeed only when ! cutBytriggers
+                       if(! cutByTriggers(op))
                         {
                                 reduceTemp = reduceCurveBySpeed(op$Eccon,
                                                                 curves[i,1], curves[i,3], #startT, startH
@@ -2890,8 +2907,11 @@ doProcess <- function(options)
                         smoothingPos <- 1
                         if(op$Jump %in% rownames(curves))
                                 smoothingPos <- which(rownames(curves) == op$Jump)
-                        
-                        
+
+                       triggersOnList = "";
+                       if(! cutByTriggers(op))
+                               triggersOnList = op$TriggersOnList;
+
                         paint(displacement, repOp$eccon, myStart, myEnd,"undefined","undefined",FALSE,FALSE,
                               
1,curves[op$Jump,3],SmoothingsEC[smoothingPos],op$SmoothingOneC,repOp$massBody,repOp$massExtra,
                               
repOp$econfName,repOp$diameter,repOp$diameterExt,repOp$anglePush,repOp$angleWeight,repOp$inertiaM,repOp$gearedDown,
@@ -2904,7 +2924,8 @@ doProcess <- function(options)
                               TRUE,    #showAxes
                               TRUE,    #legend
                               op$Analysis, isPropulsive, inertialType, repOp$exPercentBodyWeight,
-                              showSpeed, showAccel, showForce, showPower
+                              showSpeed, showAccel, showForce, showPower,
+                             triggersOnList
                         )
                         
                         
@@ -3042,7 +3063,10 @@ doProcess <- function(options)
                                 abline(v=c(curves[i,1], curves[i,2]), lty=2)
                                 mtext(i, side=3, at=(curves[i,1] + curves[i,2])/2)
                         }
-                        
+
+                       if(op$TriggersOnList != "" && op$TriggersOnList != -1)
+                               abline(v=op$TriggersOnList, col="yellow", lwd=2);
+
                         #showSpeed only on gravitatory until speed is fixed on this experimental graph
                         if (showSpeed && ! isInertial(op$EncoderConfigurationName)) {
                                 par(new=T)
@@ -3089,7 +3113,8 @@ doProcess <- function(options)
                         if(showSpeed || showAccel || showForce || showPower)
                                 abline(h=0,lty=3,col="black")
                         
-                        paintVariablesLegend(showSpeed && ! isInertial(op$EncoderConfigurationName), 
showAccel, showForce, showPower)
+                        paintVariablesLegend(showSpeed && ! isInertial(op$EncoderConfigurationName), 
showAccel, showForce, showPower,
+                                            (op$TriggersOnList != "" && op$TriggersOnList != -1))
                 }
                 
                 #needed to align the AB vertical lines on C#
@@ -3132,6 +3157,10 @@ doProcess <- function(options)
                         
                         mySubtitle = paste("curve=", rownames(curves)[i], ", ", repOp$laterality, " ", 
repOp$massExtra, "Kg", sep="")
                         
+                       triggersOnList = "";
+                       if(! cutByTriggers(op))
+                               triggersOnList = op$TriggersOnList;
+
                         paint(displacement, repOp$eccon, curves[i,1],curves[i,2],yrange,knRanges,FALSE,FALSE,
                               1,curves[i,3],SmoothingsEC[i],op$SmoothingOneC,repOp$massBody,repOp$massExtra,
                               
repOp$econfName,repOp$diameter,repOp$diameterExt,repOp$anglePush,repOp$angleWeight,repOp$inertiaM,repOp$gearedDown,
@@ -3146,7 +3175,8 @@ doProcess <- function(options)
                               (op$AnalysisVariables[1] == "Speed"), #show speed
                               (op$AnalysisVariables[2] == "Accel"), #show accel
                               (op$AnalysisVariables[3] == "Force"), #show force
-                              (op$AnalysisVariables[4] == "Power")  #show power
+                              (op$AnalysisVariables[4] == "Power"),  #show power
+                             triggersOnList
                         )
                 }
                 par(mfrow=c(1,1))
diff --git a/encoder/util.R b/encoder/util.R
index 9a0ed84..f63cb8a 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -80,10 +80,17 @@ assignOptions <- function(options) {
                    OperatingSystem     = options[28],  #if this changes, change it also at call_graph.R
                    Debug               = options[31],
                    CrossValidate       = options[32],
-                   TriggersOnList      = as.numeric(unlist(strsplit(options[33], "\\;")))
-                   #TriggersOnList:
-                   #   at capture is +1/-1 to indicate use or not.
-                   #   at graph.R is first ms where trigger is pressed at each repetition, or -1 if they are 
not going to be used
+                   TriggersCut         = options[33],  #if TRUE ten cut by triggers, else use TriggersOnList 
(if any) only for vertical ablines on instaneous graphs
+                   TriggersOnList      = as.numeric(unlist(strsplit(options[34], "\\;")))
+
+                   #Triggers:
+                   #  at capture.R
+                   #           if triggers are used to cut: TriggersCut == TRUE, TriggersOnList == 1
+                   #           if not use triggers: TriggersCut == FALSE, TriggersOnList == -1 #but nothing 
will be plotted on capture
+                   #  at graph.R
+                   #           if triggers are used to cut: TriggersCut == TRUE, TriggersOnList == xxx, yyy, 
zzz, ...
+                   #           ... but if there are not enough triggers, then just plot
+                   #           if not use triggers: TriggersCut == FALSE, TriggersOnList == xxx, yyy, zzz, 
...
 
                    #Unassigned here:
                    #   englishWords [29]
@@ -91,6 +98,15 @@ assignOptions <- function(options) {
                    ))
 }
 
+cutByTriggers <- function(op)
+{
+       if(op$TriggersCut == TRUE && op$TriggersOnList != -1)
+               return(TRUE);
+
+       return(FALSE);
+}
+
+
 #gearedDown comes as:
 #4 and should be converted to 4
 #-4 and should be converted to 1/4 : 0.25
diff --git a/src/encoder.cs b/src/encoder.cs
index 087a9eb..7a5c196 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -159,6 +159,7 @@ public class EncoderGraphROptions
        public string translatedWords;
        public bool debug;
        public bool crossValidate;
+       private bool cutByTriggers;
        private string triggerList;
        
        public EncoderGraphROptions(
@@ -167,7 +168,7 @@ public class EncoderGraphROptions
                        EncoderParams ep,
                        string title, string operatingSystem,
                        string englishWords, string translatedWords,
-                       bool debug, bool crossValidate, string triggerList)
+                       bool debug, bool crossValidate, bool cutByTriggers, string triggerList)
        {
                this.inputData = inputData;
                this.outputGraph = outputGraph;
@@ -181,6 +182,7 @@ public class EncoderGraphROptions
                this.translatedWords = translatedWords;
                this.debug = debug;
                this.crossValidate = crossValidate;
+               this.cutByTriggers = cutByTriggers;
                this.triggerList = triggerList;
        }
 
@@ -198,6 +200,7 @@ public class EncoderGraphROptions
                        "#translatedWords\n" +  translatedWords + "\n" +
                        "#debug\n" +            Util.BoolToRBool(debug) + "\n" +
                        "#crossValidate\n" +    Util.BoolToRBool(crossValidate) + "\n" +
+                       "#cutByTriggers\n" +    Util.BoolToRBool(cutByTriggers) + "\n" +
                        "#triggerList\n" +      triggerList + "\n";
        }
        
diff --git a/src/encoderRProc.cs b/src/encoderRProc.cs
index 9ffd46a..fe8a7e8 100644
--- a/src/encoderRProc.cs
+++ b/src/encoderRProc.cs
@@ -256,6 +256,7 @@ public class EncoderRProcCapture : EncoderRProc
                                false,  //translate (graphs)
                                Debug,
                                false,  //crossValidate (unactive on capture at the moment)
+                               (CutByTriggers != Preferences.TriggerTypes.NO_TRIGGERS),
                                printTriggers()
                                ).ToString();
 
@@ -283,6 +284,7 @@ public class EncoderRProcAnalyze : EncoderRProc
        private string title;
        private bool neuromuscularProfileDo;
        private bool translate;
+       private bool cutByTriggers;
        private TriggerList triggerList;
 
        /*
@@ -296,10 +298,13 @@ public class EncoderRProcAnalyze : EncoderRProc
        public EncoderRProcAnalyze() {
        }
 
-       public void SendData(string title, bool neuromuscularProfileDo, bool translate, TriggerList 
triggerList) {
+       public void SendData(string title, bool neuromuscularProfileDo, bool translate,
+                       bool cutByTriggers, TriggerList triggerList)
+       {
                this.title = title;
                this.neuromuscularProfileDo = neuromuscularProfileDo;
                this.translate = translate;
+               this.cutByTriggers = cutByTriggers;
                this.triggerList = triggerList;
                
                CancelRScript = false;
@@ -508,6 +513,7 @@ public class EncoderRProcAnalyze : EncoderRProc
                                translate,
                                Debug,
                                CrossValidate,
+                               cutByTriggers,
                                printTriggers()
                                ).ToString();
 
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 6bed0c0..8327206 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1380,6 +1380,7 @@ public partial class ChronoJumpWindow
                                title,
                                false,  //do not use neuromuscularProfile script
                                preferences.RGraphsTranslate,
+                               (preferences.encoderCaptureCutByTriggers != 
Preferences.TriggerTypes.NO_TRIGGERS),
                                triggerList
                                ); 
                bool result = encoderRProcAnalyze.StartOrContinue(es);
@@ -1893,6 +1894,7 @@ public partial class ChronoJumpWindow
                                        "-(" + displacedMass + "Kg)",
                                false,                  //do not use neuromuscularProfile script
                                preferences.RGraphsTranslate,
+                               (preferences.encoderCaptureCutByTriggers != 
Preferences.TriggerTypes.NO_TRIGGERS),
                                new TriggerList()
                                );
                encoderRProcAnalyze.StartOrContinue(encoderStruct);
@@ -2936,6 +2938,7 @@ public partial class ChronoJumpWindow
                                titleStr, 
                                encoderSelectedAnalysis == "neuromuscularProfile",
                                preferences.RGraphsTranslate,
+                               (preferences.encoderCaptureCutByTriggers != 
Preferences.TriggerTypes.NO_TRIGGERS),
                                triggerList
                                );
 
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 185a15c..4cc9455 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -334,7 +334,9 @@ public class UtilEncoder
                return operatingSystem;
        }
 
-       public static EncoderGraphROptions PrepareEncoderGraphOptions(string title, EncoderStruct es, bool 
neuromuscularProfileDo, bool translate, bool debug, bool crossValidate, string triggerStr)
+       public static EncoderGraphROptions PrepareEncoderGraphOptions(
+                       string title, EncoderStruct es, bool neuromuscularProfileDo, bool translate, bool 
debug, bool crossValidate,
+                       bool cutByTriggers, string triggerStr)
        {
                string operatingSystem = OperatingSystemForRGraphs();
                        
@@ -389,7 +391,7 @@ public class UtilEncoder
                                title, operatingSystem,
                                Util.StringArrayToString(Constants.EncoderEnglishWords,";"),
                                Util.StringArrayToString(encoderTranslatedWordsOK,";"),
-                               debug, crossValidate, triggerStr
+                               debug, crossValidate, cutByTriggers, triggerStr
                                );
        }
 


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