From 88e3ade10225d3e6c4b5913fd0e90d8e015cde89 Mon Sep 17 00:00:00 2001 From: towsey Date: Wed, 23 Sep 2020 18:11:48 +1000 Subject: [PATCH] Update Plot.cs Issue #370 Reorder the methods. --- src/TowseyLibrary/Plot.cs | 180 +++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/src/TowseyLibrary/Plot.cs b/src/TowseyLibrary/Plot.cs index 8084bbfff..2243fee7b 100644 --- a/src/TowseyLibrary/Plot.cs +++ b/src/TowseyLibrary/Plot.cs @@ -42,6 +42,96 @@ public static Plot PreparePlot(double[] array, string title, double threshold) return plot; } + public static double[] PruneScoreArray(double[] scores, double scoreThreshold, int minDuration, int maxDuration) + { + double[] returnData = new double[scores.Length]; + + int count = scores.Length; + bool isHit = false; + int startId = 0; + + // pass over all frames + for (int i = 0; i < count; i++) + { + if (isHit == false && scores[i] >= scoreThreshold) + { + // start of an event + isHit = true; + startId = i; + } + else // check for the end of an event + if (isHit && scores[i] < scoreThreshold) + { + // this is end of an event, so initialise it + isHit = false; + int endId = i; + + int duration = endId - startId; + if (duration < minDuration || duration > maxDuration) + { + continue; // skip events with duration shorter than threshold + } + + // pass over all frames + for (int j = startId; j < endId; j++) + { + returnData[j] = scores[j]; + } + } + } // end of pass over all frames + + return returnData; + } + + public static void FindStartsAndEndsOfScoreEvents( + double[] scores, + double scoreThreshold, + int minDuration, + int maxDuration, + out double[] prunedScores, + out List startEnds) + { + prunedScores = new double[scores.Length]; + startEnds = new List(); + + int count = scores.Length; + bool isHit = false; + int startId = 0; + + // pass over all frames + for (int i = 0; i < count; i++) + { + // Start of an event + if (isHit == false && scores[i] >= scoreThreshold) + { + isHit = true; + startId = i; + } + else // check for the end of an event + if (isHit && scores[i] < scoreThreshold) + { + // this is end of an event, so initialise it + isHit = false; + int endId = i - 1; + + int duration = endId - startId + 1; + if (duration < minDuration || duration > maxDuration) + { + // skip events with duration shorter than threshold + continue; + } + + // pass over all frames + for (int j = startId; j <= endId; j++) + { + prunedScores[j] = scores[j]; + } + + startEnds.Add(new Point(startId, endId)); + } + } + } + public string title { get; set; } public double[] data { get; set; } @@ -174,95 +264,5 @@ public Image DrawAnnotatedPlot(int height) }); return image; } - - public static double[] PruneScoreArray(double[] scores, double scoreThreshold, int minDuration, int maxDuration) - { - double[] returnData = new double[scores.Length]; - - int count = scores.Length; - bool isHit = false; - int startId = 0; - - // pass over all frames - for (int i = 0; i < count; i++) - { - if (isHit == false && scores[i] >= scoreThreshold) - { - // start of an event - isHit = true; - startId = i; - } - else // check for the end of an event - if (isHit && scores[i] < scoreThreshold) - { - // this is end of an event, so initialise it - isHit = false; - int endId = i; - - int duration = endId - startId; - if (duration < minDuration || duration > maxDuration) - { - continue; // skip events with duration shorter than threshold - } - - // pass over all frames - for (int j = startId; j < endId; j++) - { - returnData[j] = scores[j]; - } - } - } // end of pass over all frames - - return returnData; - } - - public static void FindStartsAndEndsOfScoreEvents( - double[] scores, - double scoreThreshold, - int minDuration, - int maxDuration, - out double[] prunedScores, - out List startEnds) - { - prunedScores = new double[scores.Length]; - startEnds = new List(); - - int count = scores.Length; - bool isHit = false; - int startId = 0; - - // pass over all frames - for (int i = 0; i < count; i++) - { - // Start of an event - if (isHit == false && scores[i] >= scoreThreshold) - { - isHit = true; - startId = i; - } - else // check for the end of an event - if (isHit && scores[i] < scoreThreshold) - { - // this is end of an event, so initialise it - isHit = false; - int endId = i - 1; - - int duration = endId - startId + 1; - if (duration < minDuration || duration > maxDuration) - { - // skip events with duration shorter than threshold - continue; - } - - // pass over all frames - for (int j = startId; j <= endId; j++) - { - prunedScores[j] = scores[j]; - } - - startEnds.Add(new Point(startId, endId)); - } - } - } } } \ No newline at end of file