-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reverted changes to score, improved drawing methods
- The score on EventBase cannot have its definition changed. I've reverted previous changes that attempted to define and normalize score values. - I've added an example on how Score can be overrided in a child class (chirp event inthis case) so that its value can be given extra semantics - I've reverted the change of adding MaxScore to CommonParameters. Not only is the field near useless (if a good constant value existrs, why not use it?) (if not, why not compute it?) but it is also almost impossible for a user to guess at what a good value should be! Additionally, why was it added to common parameters? - Added event drawer class to centralise methods - Added a bunch more options to event options to control output of events - Changed IPointData to use an ICollection and equivalently changed Track to use a List (apparently order of insertion is important) - Cleaned up spectral event, removed unnecessary additional draw method - Fixed documentation of enum tyoes in Track - Tried to write more track drawing tests but ran out of time because of all the cleaning required -
- Loading branch information
Showing
17 changed files
with
298 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// <copyright file="EventDrawer.cs" company="QutEcoacoustics"> | ||
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group). | ||
// </copyright> | ||
|
||
namespace AudioAnalysisTools.Events.Drawing | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using SixLabors.Fonts; | ||
using SixLabors.ImageSharp; | ||
using SixLabors.ImageSharp.Processing; | ||
using static Acoustics.Shared.ImageSharp.Drawing; | ||
|
||
public static class EventDrawer | ||
{ | ||
|
||
/// <summary> | ||
/// Draws a "score" indicator on the left edge of an event. | ||
/// </summary> | ||
/// <param name="graphics">The image context to draw to.</param> | ||
/// <param name="options">The event rendering optons to use.</param> | ||
/// <param name="@event">The event for which to draw the score indicator.</param> | ||
public static void DrawScoreIndicator(this SpectralEvent @event, IImageProcessingContext graphics, EventRenderingOptions options) | ||
{ | ||
if (!options.DrawScore) | ||
{ | ||
return; | ||
} | ||
|
||
// TODO: add a Interval<double> ScoreRange property to EventCommon | ||
// so we can properly normalize this value to the unit value. | ||
// For now, we just assume it is normalized to [0,1]. | ||
var clampedScore = @event.Score.Clamp(0, 1); | ||
|
||
if (clampedScore == 0) | ||
{ | ||
return; | ||
} | ||
|
||
var rect = options.Converters.GetPixelRectangle(@event); | ||
|
||
var scaledHeight = (float)clampedScore * rect.Height; | ||
|
||
graphics.NoAA().DrawLines( | ||
options.Score, | ||
new PointF(rect.Left, rect.Bottom), | ||
new PointF(rect.Left, rect.Bottom + scaledHeight)); | ||
} | ||
|
||
public static void DrawEventLabel(this SpectralEvent @event, IImageProcessingContext graphics, EventRenderingOptions options) | ||
{ | ||
if (!options.DrawLabel) | ||
{ | ||
return; | ||
} | ||
|
||
var text = @event.Name; | ||
|
||
if (string.IsNullOrWhiteSpace(text)) | ||
{ | ||
return; | ||
} | ||
|
||
var bounds = TextMeasurer.MeasureBounds(text, new RendererOptions(Roboto6)); | ||
var topLeft = options.Converters.GetPoint(@event); | ||
|
||
topLeft.Offset(0, -bounds.Height); | ||
|
||
graphics.DrawTextSafe( | ||
@event.Name, | ||
Roboto6, | ||
options.Label, | ||
topLeft); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.