10#include <tracking/trackingUtilities/ca/Path.h>
11#include <tracking/trackingUtilities/ca/AutomatonCell.h>
13#include <tracking/trackingUtilities/utilities/WeightedRelation.h>
25 namespace TrackingUtilities {
37 template<
class ACellHolder>
43 const std::vector<ACellHolder*>& cellHolders,
45 Weight minStateToFollow = -INFINITY)
47 B2ASSERT(
"Expected the relations to be sorted",
48 std::is_sorted(cellHolderRelations.begin(), cellHolderRelations.end()));
51 std::vector<Path<ACellHolder> > paths;
54 Path<ACellHolder> path;
56 for (ACellHolder* cellHolder : cellHolders) {
57 const AutomatonCell& automatonCell = cellHolder->getAutomatonCell();
66 path.push_back(cellHolder);
81 static Path<ACellHolder>
followSingle(ACellHolder* startCellHolder,
83 Weight minStateToFollow = -INFINITY)
85 assert(std::is_sorted(cellHolderRelations.begin(), cellHolderRelations.end()));
87 Path<ACellHolder> path;
88 if (not startCellHolder)
return path;
89 const AutomatonCell& startCell = startCellHolder->getAutomatonCell();
96 path.push_back(startCellHolder);
100 ACellHolder* cellHolder = path.back();
102 auto continuations = asRange(std::equal_range(cellHolderRelations.begin(),
103 cellHolderRelations.end(),
109 ACellHolder* neighbor = relation.getTo();
110 path.push_back(neighbor);
128 std::vector<Path<ACellHolder> >& paths)
132 ACellHolder* neighbor(neighborRelation.getTo());
133 path.push_back(neighbor);
139 ACellHolder* lastCellHolder = path.back();
141 auto continuations = asRange(std::equal_range(cellHolderRelations.begin(),
142 cellHolderRelations.end(),
144 int nRelationsUsed = std::count_if(continuations.begin(),
148 if (nRelationsUsed == 0) {
150 paths.push_back(path);
159 Weight minStateToFollow)
174 const ACellHolder* cellHolderPtr(relation.
getFrom());
175 const ACellHolder* neighborCellHolderPtr(relation.
getTo());
177 if (not cellHolderPtr or not neighborCellHolderPtr)
return false;
179 const ACellHolder& cellHolder = *cellHolderPtr;
180 Weight relationWeight = relation.
getWeight();
181 const ACellHolder& neighborCellHolder = *neighborCellHolderPtr;
191 Weight relationWeight,
192 const ACellHolder& neighborCellHolder)
194 const AutomatonCell& automatonCell = cellHolder.getAutomatonCell();
195 const AutomatonCell& neighborAutomatonCell = neighborCellHolder.getAutomatonCell();
Cell used by the cellular automata.
bool hasCycleFlag() const
Gets the current state of the cycle marker flag.
bool hasStartFlag() const
Gets the current state of the start marker flag.
bool hasMaskedFlag() const
Gets the current state of the masked marker flag.
Weight getCellWeight() const
Getter for the cell weight.
Weight getCellState() const
Getter for the cell state.
Implements to pick up of the highest value path in neighborhood Following high value paths can be don...
static Path< ACellHolder > followSingle(ACellHolder *startCellHolder, const std::vector< WeightedRelation< ACellHolder > > &cellHolderRelations, Weight minStateToFollow=-INFINITY)
Follows a single maximal path starting with the given start cell.
static void growAllPaths(Path< ACellHolder > &path, const std::vector< WeightedRelation< ACellHolder > > &cellHolderRelations, std::vector< Path< ACellHolder > > &paths)
Helper function for recursively growing paths.
static bool isHighestContinuation(const WeightedRelation< ACellHolder > &relation)
Helper function determining if the given neighbor is one of the best to be followed.
static bool isHighestContinuation(const ACellHolder &cellHolder, Weight relationWeight, const ACellHolder &neighborCellHolder)
Helper function determining if the given neighbor is one of the best to be followed.
static std::vector< Path< ACellHolder > > followAll(const std::vector< ACellHolder * > &cellHolders, const std::vector< WeightedRelation< ACellHolder > > &cellHolderRelations, Weight minStateToFollow=-INFINITY)
Follow paths from all start cells marked with the start flag.
static bool validStartCell(const AutomatonCell &automatonCell, Weight minStateToFollow)
Helper function to determine, if the cell has all flags indicating to be a start cell and that its st...
Type for two related objects with a weight.
Weight getWeight() const
Getter for the weight.
From * getFrom() const
Getter for the pointer to the from side object.
To * getTo() const
Getter for the pointer to the to side object.
Abstract base class for different kinds of events.