Skip to content

Commit

Permalink
Update Plot.cs
Browse files Browse the repository at this point in the history
Issue #370 Reorder the methods.
  • Loading branch information
towsey authored and atruskie committed Oct 14, 2020
1 parent 9c0abc7 commit 4664320
Showing 1 changed file with 90 additions and 90 deletions.
180 changes: 90 additions & 90 deletions src/TowseyLibrary/Plot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point> startEnds)
{
prunedScores = new double[scores.Length];
startEnds = new List<Point>();

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; }
Expand Down Expand Up @@ -174,95 +264,5 @@ public Image<Rgb24> 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<Point> startEnds)
{
prunedScores = new double[scores.Length];
startEnds = new List<Point>();

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));
}
}
}
}
}

0 comments on commit 4664320

Please sign in to comment.