Skip to content

Commit

Permalink
Merge pull request #166 from SainsburyWellcomeCentre/prefer-timestamped
Browse files Browse the repository at this point in the history
Ensure all tracking operators use timestamped values
  • Loading branch information
glopesdev authored Oct 22, 2023
2 parents cbcc720 + c9bd194 commit dd86e45
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Aeon.Acquisition/Aeon.Acquisition.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageTags>Bonsai Rx Project Aeon Acquisition</PackageTags>
<TargetFramework>net472</TargetFramework>
<VersionPrefix>0.5.0</VersionPrefix>
<VersionSuffix>build231008</VersionSuffix>
<VersionSuffix>build231009</VersionSuffix>
</PropertyGroup>

<ItemGroup>
Expand Down
21 changes: 15 additions & 6 deletions src/Aeon.Acquisition/DistanceFromPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,31 @@ static double Distance(Point2f left, Point2f right)
return Math.Sqrt(delta.X * delta.X + delta.Y * delta.Y);
}

public IObservable<Timestamped<double>> Process(IObservable<Tuple<ConnectedComponent, double>> source)
public IObservable<Timestamped<double>> Process(IObservable<Timestamped<Point2f>> source)
{
return source.Select(x =>
{
var distance = Distance(x.Item1.Centroid, new Point2f(Value));
return Timestamped.Create(distance, x.Item2);
var distance = Distance(x.Value, new Point2f(Value));
return Timestamped.Create(distance, x.Seconds);
});
}

public IObservable<Timestamped<double>> Process(IObservable<Tuple<ConnectedComponentCollection, double>> source)
public IObservable<Timestamped<double>> Process(IObservable<Timestamped<ConnectedComponent>> source)
{
return source.Select(x =>
{
var distance = Distance(x.Value.Centroid, new Point2f(Value));
return Timestamped.Create(distance, x.Seconds);
});
}

public IObservable<Timestamped<double>> Process(IObservable<Timestamped<ConnectedComponentCollection>> source)
{
return source.Select(x =>
{
var point = new Point2f(Value);
var distance = x.Item1.Min(component => Distance(point, component.Centroid));
return Timestamped.Create(distance, x.Item2);
var distance = x.Value.Min(component => Distance(point, component.Centroid));
return Timestamped.Create(distance, x.Seconds);
});
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/Aeon.Acquisition/FormatBinaryRegions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Bonsai;
using Bonsai;
using System;
using System.ComponentModel;
using System.Linq;
Expand All @@ -15,12 +15,12 @@ public class FormatBinaryRegions
{
const int Address = 200;

public IObservable<HarpMessage> Process(IObservable<Tuple<ConnectedComponent, double>> source)
public IObservable<HarpMessage> Process(IObservable<Timestamped<ConnectedComponent>> source)
{
return source.Select(value =>
return source.Select(x =>
{
var region = value.Item1;
var timestamp = value.Item2;
var region = x.Value;
var timestamp = x.Seconds;
return HarpMessage.FromSingle(
Address,
timestamp,
Expand All @@ -34,12 +34,12 @@ public IObservable<HarpMessage> Process(IObservable<Tuple<ConnectedComponent, do
});
}

public IObservable<HarpMessage> Process(IObservable<Tuple<ConnectedComponentCollection, double>> source)
public IObservable<HarpMessage> Process(IObservable<Timestamped<ConnectedComponentCollection>> source)
{
return source.SelectMany(value =>
return source.SelectMany(x =>
{
var regions = value.Item1;
var timestamp = value.Item2;
var regions = x.Value;
var timestamp = x.Seconds;
return regions.Select((region, index) => HarpMessage.FromSingle(
Address,
timestamp,
Expand All @@ -54,4 +54,4 @@ public IObservable<HarpMessage> Process(IObservable<Tuple<ConnectedComponentColl
});
}
}
}
}
11 changes: 8 additions & 3 deletions src/Aeon.Acquisition/PositionTracking.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:cv="clr-namespace:Bonsai.Vision;assembly=Bonsai.Vision"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:aeon="clr-namespace:Aeon.Acquisition;assembly=Aeon.Acquisition"
xmlns:harp="clr-namespace:Bonsai.Harp;assembly=Bonsai.Harp"
xmlns="https://bonsai-rx.org/2018/workflow">
<Description>Extracts information on the largest binary blob in the input image.</Description>
<Workflow>
Expand Down Expand Up @@ -76,6 +77,9 @@
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Zip" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="harp:CreateTimestamped" />
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Name" DisplayName="TrackingEvents" />
</Expression>
Expand All @@ -100,9 +104,10 @@
<Edge From="11" To="12" Label="Source2" />
<Edge From="12" To="14" Label="Source1" />
<Edge From="13" To="14" Label="Source2" />
<Edge From="14" To="16" Label="Source1" />
<Edge From="15" To="16" Label="Source2" />
<Edge From="16" To="17" Label="Source1" />
<Edge From="14" To="15" Label="Source1" />
<Edge From="15" To="17" Label="Source1" />
<Edge From="16" To="17" Label="Source2" />
<Edge From="17" To="18" Label="Source1" />
</Edges>
</Workflow>
</WorkflowBuilder>
21 changes: 15 additions & 6 deletions src/Aeon.Acquisition/RegionContainsPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,31 @@ static bool Contains(Point[][] contour, Point2f point)
return false;
}

public IObservable<Timestamped<bool>> Process(IObservable<Tuple<ConnectedComponent, double>> source)
public IObservable<Timestamped<bool>> Process(IObservable<Timestamped<Point2f>> source)
{
return source.Select(x =>
{
var containsPoint = Contains(Regions, x.Item1.Centroid);
return Timestamped.Create(containsPoint, x.Item2);
var containsPoint = Contains(Regions, x.Value);
return Timestamped.Create(containsPoint, x.Seconds);
});
}

public IObservable<Timestamped<bool>> Process(IObservable<Tuple<ConnectedComponentCollection, double>> source)
public IObservable<Timestamped<bool>> Process(IObservable<Timestamped<ConnectedComponent>> source)
{
return source.Select(x =>
{
var containsPoint = Contains(Regions, x.Value.Centroid);
return Timestamped.Create(containsPoint, x.Seconds);
});
}

public IObservable<Timestamped<bool>> Process(IObservable<Timestamped<ConnectedComponentCollection>> source)
{
return source.Select(x =>
{
var regions = Regions;
var containsPoint = x.Item1.Any(component => Contains(regions, component.Centroid));
return Timestamped.Create(containsPoint, x.Item2);
var containsPoint = x.Value.Any(component => Contains(regions, component.Centroid));
return Timestamped.Create(containsPoint, x.Seconds);
});
}
}
Expand Down

0 comments on commit dd86e45

Please sign in to comment.