Queries And Matchers
fort::myrmidon::Query
-
class Query
Queries are computation on an Experiment tracking data.
This class is a wrapper for all data queries that can be made on an Experiment. They takes advantages of multithreading to have efficient computation time.
Note
Some queries have two version, one returing up to two std::vector, and one with a storeMethod parameter. The later is to be used with bindings, or when a different data structure is needed.
Note
For very small Experiment in number of Ant, most of the query operation are IO bounded, and the multithreading overhead will impact performance by 40-50% in computation time, as threads are waiting for data inpout to come. This is the case for IdentifyFrames(), and ComputeAntTrajectories(). When collision detection is required, multi-threading can largely help, especially with a large number of individuals. Threading is controlled with QueryArgs::SingleThreaded
Public Static Functions
-
static ComputedMeasurement::List ComputeMeasurementFor(const Experiment &experiment, AntID antID, MeasurementTypeID typeID)
Computes all measurement for an Ant.
- Parameters:
experiment – the Experiment to query for
antID – the desired Ant
typeID – the desired measurement type
- Returns:
a ComputedMeasurement::List of the Measurement for the Ant
-
static ExperimentDataInfo GetDataInformations(const Experiment &experiment)
Gets tracking data statistics about the Experiment.
- Returns:
an ExperimentDataInfo structure of informations
-
static TagStatistics::ByTagID ComputeTagStatistics(const Experiment &experiment, const std::function<void(int, int)> &progressCallback =
[](int, int){}
, bool fixCorruptedData = false) Computes TagStatistics for an experiment.
- Parameters:
experiment – the Experiment to query for
fixCorruptedData – a boolean indicating if data corruption should be ignored and silently fixed. Please note that it could cause the loss of large chunk of tracking data. If false, an exception will be thrown.
- Returns:
the TagStatistics indexed by TagID
-
static void IdentifyFramesFunctor(const Experiment &experiment, std::function<void(const IdentifiedFrame::Ptr&)> storeData, const IdentifyFramesArgs &args = IdentifyFramesArgs())
Identifies ants in frames - functor version.
Identifies Ants in frames, data will be reported ordered by time.
Note
Zones for Ant will not be computed unless specified with IdentifyFrameArgs::ComputeZones.
Note
This version aimed to be used by language bindings to avoid large data copy.
- Parameters:
experiment – the Experiment to query for
storeData – a functor to store/convert the data
args – the IdentifyFrameArgs to use for this query
-
static void IdentifyFrames(const Experiment &experiment, std::vector<IdentifiedFrame::Ptr> &result, const IdentifyFramesArgs &args = IdentifyFramesArgs())
Identifies ants in frames.
Identifies Ants in frames, data will be reported ordered by time.
Note
Zones for Ant will not be computed unless specified with IdentifyFrameArgs::ComputeZones.
- Parameters:
experiment – the Experiment to query for
result – the resulting IdentifiedFrame
args – the IdentifyFrameArgs to use for this query
-
static void CollideFramesFunctor(const Experiment &experiment, std::function<void(const CollisionData &data)> storeData, const CollideFramesArgs &args = CollideFramesArgs())
Finds Collision in tracking frames - functor version.
Finds Collision between ants in frames, data will be reported ordered by time. Zones for each Ant will also be computed.
Note
This version aimed to be used by language bindings to avoid large data copy.
- Parameters:
experiment – the Experiment to query for
storeData – a functor to store the data as it is produced
args – the QueryArgs to use for this query
-
static void CollideFrames(const Experiment &experiment, std::vector<CollisionData> &result, const CollideFramesArgs &args = CollideFramesArgs())
Finds Collision in tracking frames.
Finds Collision between ants in frames, data will be reported ordered by time. Zones for each Ant will also be computed.
- Parameters:
experiment – the Experiment to query for
result – the resulting IdentifiedFrame and CollisionFrame
args – the QueryArgs to use for this query
-
static void ComputeAntTrajectoriesFunctor(const Experiment &experiment, std::function<void(const AntTrajectory::Ptr&)> storeTrajectory, const ComputeAntTrajectoriesArgs &args = ComputeAntTrajectoriesArgs())
Computes trajectories for ants - functor version.
Computes ant trajectories in the experiment. A trajectory is the consecutive position of an Ant in a Space, with detection gap under ComputeAntTrajectoriesArgs::MaximumGap. These will be reported ordered by ending time.
Note
This version aimed to be used by language bindings to avoid large data copy.
- Parameters:
experiment – the Experiment to query for
storeTrajectory – a functor to store/covert the data
args – the ComputeAntTrajectoriesArgs to use for this query
-
static void ComputeAntTrajectories(const Experiment &experiment, std::vector<AntTrajectory::Ptr> &trajectories, const ComputeAntTrajectoriesArgs &args = ComputeAntTrajectoriesArgs())
Computes trajectories for ants.
Computes ant trajectories in the experiment. A trajectory is the consecutive position of an Ant in a Space, with detection gap under ComputeAntTrajectoriesArgs::MaximumGap. These will be reported ordered by ending time.
- Parameters:
experiment – the Experiment to query for
trajectories – a container for storing the results.
args – the ComputeAntTrajectoriesArgs to use for this query
-
static void ComputeAntInteractionsFunctor(const Experiment &experiment, std::function<void(const AntTrajectory::Ptr&)> storeTrajectory, std::function<void(const AntInteraction::Ptr&)> storeInteraction, const ComputeAntInteractionsArgs &args = ComputeAntInteractionsArgs())
Computes interactions for ants - functor version.
Computes ant interactions, i.e. time intervals where two Ants collides. These will be reported ordered by ending time.
The parameter ComputeAntInteractionsArgs::ReportFullTrajectories controls if full trajectories should be reported in AntTrajectorySegment or if only a summary should be reported. The former have an high impact on the amount of RAM required to perform the query efficiently or at all.
Note
This version aimed to be used by language bindings to avoid large data copy.
- Parameters:
experiment – the Experiment to query for
storeTrajectory – a functor to store/convert trajectories
storeInteraction – a functor to store/convert interaction
args – the ComputeAntInteractionsArgs
-
static void ComputeAntInteractions(const Experiment &experiment, std::vector<AntTrajectory::Ptr> &trajectories, std::vector<AntInteraction::Ptr> &interactions, const ComputeAntInteractionsArgs &args = ComputeAntInteractionsArgs())
Computes interactions for ants.
Computes ant interactions, i.e. time intervals where two Ants collides. These will be reported ordered by ending time.
The parameter ComputeAntInteractionsArgs::ReportFullTrajectories controls if full trajectories should be reported in AntTrajectorySegment or if only a summary should be reported. The former have an high impact on the amount of RAM required to perform the query efficiently or at all.
- Parameters:
experiment – the Experiment to query for
trajectories – container for the AntTrajectory results
interactions – container for AntInteraction results
args – the ComputeAntInteractionsArgs
-
static void FindVideoSegments(const Experiment &experiment, std::vector<VideoSegment> &segments, SpaceID space, const fort::Time &start, const fort::Time &end)
Finds the VideoSegment in a Space of the Experiment.
Note
it would be extremly computationally inefficient to query for a large range [start;end].
- Parameters:
experiment – the Experiment to query for
segments – container for the VideoSegment results
space – the SpaceID of the Space to query for
start – the first Time to query a video frame for
end – the last Time to query a video frame for
-
static std::vector<std::tuple<AntID, Time, Time>> GetMetaDataKeyRanges(const Experiment &e, const std::string &key, const Value &value)
Gets the time ranges where metadata key has a given value.
- Parameters:
e – the Experiment to query for
key – the key to query for
value – the value to check equality to
- Throws:
std::out_of_range – if key is not defined in Experiment
std::invalid_argument – if value is not of the right type for key
- Returns:
a vector of tuple of AntID and time range where key is equal to value.
-
static std::tuple<std::vector<std::string>, std::vector<TagID>, Eigen::MatrixXd> GetTagCloseUps(const Experiment &e, const std::function<void(int, int)> &progressCallback, bool fixCorruptedData = false)
Gets the tag close-up in the experiment.
- Parameters:
e – the Experiment to query for
progrssCallback – a callback for the progress of the operation
fixCorruptedData – a boolean that will make data corruption error silently ignored. Could lead to the loss of some tag close-up
- Returns:
a tuple of a vector of string, TagID, and an Eigen::Matrix
-
struct CollideFramesArgs : public fort::myrmidon::Query::QueryArgs
Arguments for CollideFrames.
Arguments for CollideFrames() and CollideFramesFunctor().
-
struct ComputeAntInteractionsArgs : public fort::myrmidon::Query::QueryArgs
Arguments for ComputeAntInteractions.
Arguments for ComputeAntInteractions() and ComputeAntInteractionsFunctor().
Public Functions
-
ComputeAntInteractionsArgs()
Builds default arguments.
Public Members
-
Duration MaximumGap
Maximum Duration before considering the trajectory be two different parts (default: 1s)
-
std::shared_ptr<myrmidon::Matcher> Matcher
Matcher to reduce the query to an Ant subset (default: to nullptr, i.e.
anything).
-
bool ReportFullTrajectories
Reports full trajectories.
If false only mean trajectory during interactions will be reported, otherwise trajectory will be computed like ComputeAntTrajectories() and AntInteraction wil points to sub-segment (default: true).
-
bool CollisionsIgnoreZones
Collisions, and therefore interactions, happens over different zones.
-
bool SegmentOnMatcherValueChange
If a combined matcher value changes, create a new object.
-
ComputeAntInteractionsArgs()
-
struct ComputeAntTrajectoriesArgs : public fort::myrmidon::Query::QueryArgs
Arguments for ComputeAntTrajectories.
Arguments for ComputeAntTrajectories() and ComputeAntTrajectoriesFunctor().
Public Members
-
Duration MaximumGap
Maximum Duration before considering the trajectory be two different parts (default: 1s)
-
std::shared_ptr<myrmidon::Matcher> Matcher
Matcher to reduce the query to an Ant subset (default: to nullptr, i.e.
anything).
-
bool SegmentOnMatcherValueChange
If a combined matcher value changes, create a new object.
-
Duration MaximumGap
-
struct IdentifyFramesArgs : public fort::myrmidon::Query::QueryArgs
Arguments for IdentifyFrames.
Arguments for IdentifyFrames() and IdentifyFramesFunctor().
Public Members
-
bool ComputeZones
enables zone computation without collision detection
-
bool ComputeZones
-
struct QueryArgs
Arguments for any Query.
Subclassed by fort::myrmidon::Query::CollideFramesArgs, fort::myrmidon::Query::ComputeAntInteractionsArgs, fort::myrmidon::Query::ComputeAntTrajectoriesArgs, fort::myrmidon::Query::IdentifyFramesArgs
Public Functions
-
QueryArgs()
Builds default arguments.
Public Members
-
Time Start
First Time to consider (default: Time::SinceEver())
-
Time End
Last Time to consider (default: Time::Forever())
-
bool SingleThreaded
Uses a single thread for computation (default: false)
-
bool AllocationInCurrentThread
Forces result allocation from the calling thread (default: false)
-
QueryArgs()
-
static ComputedMeasurement::List ComputeMeasurementFor(const Experiment &experiment, AntID antID, MeasurementTypeID typeID)
fort::myrmidon::Matcher
-
class Matcher
A Matcher helps to build complex Query by adding one or several constraints.
Matchers works either on single Ant for trajectory computation, or on a pair of Ant when considering interactions. Some matcher have no real meaning outside of interaction (i.e. InteractionType()) and would match any trajectory.
Base Matchers
One would use the following function to get a Matcher :
AntID() : one of the considered Ant in the result should match a given AntID
AntMetaData() : one of the key-value user defined meta-data pair for one of the Ant should match.
AntDistanceSmallerThan(),AntDistanceGreaterThan() : for interaction queries only, ensure some criterion for the distance between the two considedred Ant.
AntAngleSmallerThan()/AntAngleGreaterThan() : for interaction queries only, ensure that angle between Ant meets some criterion.
AntDisplacement(): matches interaction were the displacement of either of the Ant is kept under a threshold.
Combination
Using And() or Or(), one can combine several Matcher together to build more complex criterion. For example to build a Matcher that matches ID
001
or002
:{c++} using namespace fort::myrmidon; auto m = Matcher::Or(Matcher::AntID(1),Matcher::AntID(2));
Public Static Functions
-
static Ptr And(std::vector<Ptr> matchers)
Combines several Matcher together in conjunction.
- Parameters:
matchers – the matchers to combine
- Returns:
a new Matcher which will match only when all matchers also matches.
-
static Ptr Or(std::vector<Ptr> matchers)
Combines several Matcher together in disjunction.
- Parameters:
matchers – the matchers to combine
- Returns:
a new Matcher which will match if any of the matchers matches.
-
static Ptr AntID(AntID antID)
Matches a given AntID.
In case of interactions, matches any interaction with one of the Ant having antID.
-
static Ptr AntMetaData(const std::string &key, const Value &value)
Matches a given user meta data key/value.
In case of interactions, matches any interaction with one of the Ant meeting the criterion.
-
static Ptr AntDistanceSmallerThan(double distance)
Matches a distance between two Ants.
In case of trajectories, it matches anything.
-
static Ptr AntDistanceGreaterThan(double distance)
Matches a distance between two Ants.
In case of trajectories, it matches anything.
-
static Ptr AntAngleSmallerThan(double angle)
Matches an absolute angle between two Ants.
In case of trajectories, it matches anything.
- Parameters:
angle – the angle to be smaller (in radians).
- Returns:
a Matcher that matches when the absolute angle between two Ants is smaller than angle.
-
static Ptr AntAngleGreaterThan(double angle)
Matches an absolute angle between two Ants.
In case of trajectories, it matches anything.
- Parameters:
angle – the angle to be greater to (in radians).
- Returns:
a Matcher that matches when the absolute angle between two Ants is greater than angle.
-
static Ptr InteractionType(AntShapeTypeID type1, AntShapeTypeID type2)
Matches an InteractionType.
Matches
(type1,type2)
and(type2,type1)
interactions. In the case of trajectories, it matches anything.- Parameters:
type1 – the first AntShapeTypeID to match
type2 – the second AntShapeTypeID to match
- Returns:
a Matcher that matches a given InteractionType or its opposite.
-
static Ptr AntDisplacement(double under, Duration minimumGap)
Matches Ant displacement.
Matches Trajectories and Interactions where Ant displacement between two consecutive position is smaller than under. If minimumGap is not zero, this check will be enforced only if there was at least minimumGap Time ellapsed between the two positions.
- Parameters:
under – maximal allowed displacement in pixels
minimumGap – minimal time gap
- Returns:
a Matcher that reject large displacements in a tracking gap.
Queries’ result structures
fort::myrmidon::AntTrajectory
-
struct AntTrajectory
Defines a trajectory for an Ant.
Public Types
-
typedef std::shared_ptr<AntTrajectory> Ptr
A pointer to the trajectory.
Public Functions
Public Members
-
Time Start
Reports the starting Time of this trajectory.
Reports the starting Time of this trajectory. Positions first column are second offset from this time.
-
Eigen::Matrix<double, Eigen::Dynamic, 5> Positions
Reports the time and position in the frame.
Reports the time and position in the frame.
first column: offset in second since Start
second and third column: X,Y position in the image
fourth column: Angle in ]-π,π], in trigonometric orientation. As in images Y axis points bottom, positove angle appears clockwise.
fith column: the zone of the ant
-
typedef std::shared_ptr<AntTrajectory> Ptr
fort::myrmidon::AntInteraction
-
struct AntInteraction
Defines an interaction between two Ants.
Public Types
-
typedef std::shared_ptr<AntInteraction> Ptr
A pointer to the interaction structure.
Public Members
-
InteractionID IDs
The IDs of the two Ant.
The ID of the two Ant. Always reports
IDs.first < IDs.second
.
-
InteractionTypes Types
Virtual shape body part that were in contact.
Virtual shape body part that were in contact during the interaction.
-
std::variant<std::pair<AntTrajectorySegment, AntTrajectorySegment>, std::pair<AntTrajectorySummary, AntTrajectorySummary>> Trajectories
Reports the AntTrajectory or their summary for each Ant during the interaction.
The trajectories are truncated to the interaction timing.
-
typedef std::shared_ptr<AntInteraction> Ptr
fort::myrmidon::AntTrajectorySegment
fort::myrmidon::AntTrajectorySummary
-
struct AntTrajectorySummary
Defines a trajectory sub-segment summary.
fort::myrmidon::IdentifiedFrame
-
struct IdentifiedFrame
A video frame were Ant have been identified from their TagID.
Public Types
-
typedef std::shared_ptr<IdentifiedFrame> Ptr
A pointer to an IdentifiedFrame.
-
typedef Eigen::Matrix<double, Eigen::Dynamic, 5, Eigen::RowMajor> PositionMatrix
A Matrix of ant position.
The first column is the AntID
The second and third columns are the x,y position in the original video frame.
The fourth column is the ant angle
The fifth column is the ant current zone or 0 if in no zone or zones aren’t computed.
-
typedef std::shared_ptr<IdentifiedFrame> Ptr
fort::myrmidon::CollisionFrame
-
struct CollisionFrame
Reports all Collision happening at a given time.
Public Types
-
typedef std::shared_ptr<CollisionFrame> Ptr
A pointer to a CollisionFrame.
-
typedef std::shared_ptr<CollisionFrame> Ptr
-
struct Collision
Defines an interaction between two Ant, ponctual in Time.
Public Members
-
InteractionID IDs
The AntID of the two Ants interacting.
The AntID of the two Ants interacting. Please note that
IDS.first < IDs.second
remains always true, to ensure uniqueness of IDs for AntInteraction.
-
InteractionTypes Types
Reports all virtual AntShapeTypeID interacting between the two Ants.
-
InteractionID IDs
fort::myrmidon::ComputedMeasurement
-
struct ComputedMeasurement
Represents a Measurement in millimeters at a given Time.
Measurement in myrmidon are automatically converted to MM given the Experiment tag family and size, and the size of the tag measured in the image.
Public Types
-
typedef std::vector<ComputedMeasurement> List
A list of measurement.
-
typedef std::vector<ComputedMeasurement> List
fort::myrmidon::ExperimentDataInfo
-
struct ExperimentDataInfo
Reports global tracking data stats for an Experiment.
-
struct SpaceDataInfo
Reports global tracking data stats for a Space.
Public Members
-
std::vector<TrackingDataDirectoryInfo> TrackingDataDirectories
Infos for all tracking data directories, ordered in Time.
-
std::vector<TrackingDataDirectoryInfo> TrackingDataDirectories
-
struct TrackingDataDirectoryInfo
Reports information about a tracking data directory.