10#include <tracking/trackingUtilities/ca/Path.h>
11#include <tracking/trackingUtilities/ca/AutomatonCell.h>
13#include <tracking/trackingUtilities/utilities/WeightedRelation.h>
24 namespace TrackingUtilities {
36 template<
class ACellHolder>
42 const std::vector<ACellHolder*>& cellHolders,
44 Weight minStateToFollow = -INFINITY)
46 B2ASSERT(
"Expected the relations to be sorted",
47 std::is_sorted(cellHolderRelations.begin(), cellHolderRelations.end()));
50 std::vector<Path<ACellHolder> > paths;
53 Path<ACellHolder> path;
55 for (ACellHolder* cellHolder : cellHolders) {
56 const AutomatonCell& automatonCell = cellHolder->getAutomatonCell();
65 path.push_back(cellHolder);
80 static Path<ACellHolder>
followSingle(ACellHolder* startCellHolder,
82 Weight minStateToFollow = -INFINITY)
84 Path<ACellHolder> path;
85 if (not startCellHolder)
return path;
86 const AutomatonCell& startCell = startCellHolder->getAutomatonCell();
93 path.push_back(startCellHolder);
97 ACellHolder* cellHolder = path.back();
99 auto continuations = asRange(std::equal_range(cellHolderRelations.begin(),
100 cellHolderRelations.end(),
106 ACellHolder* neighbor = relation.getTo();
107 path.push_back(neighbor);
125 std::vector<Path<ACellHolder> >& paths)
129 ACellHolder* neighbor(neighborRelation.getTo());
130 path.push_back(neighbor);
136 ACellHolder* lastCellHolder = path.back();
138 auto continuations = asRange(std::equal_range(cellHolderRelations.begin(),
139 cellHolderRelations.end(),
141 int nRelationsUsed = std::count_if(continuations.begin(),
145 if (nRelationsUsed == 0) {
147 paths.push_back(path);
156 Weight minStateToFollow)
171 const ACellHolder* cellHolderPtr(relation.
getFrom());
172 const ACellHolder* neighborCellHolderPtr(relation.
getTo());
174 if (not cellHolderPtr or not neighborCellHolderPtr)
return false;
176 const ACellHolder& cellHolder = *cellHolderPtr;
177 Weight relationWeight = relation.
getWeight();
178 const ACellHolder& neighborCellHolder = *neighborCellHolderPtr;
188 Weight relationWeight,
189 const ACellHolder& neighborCellHolder)
191 const AutomatonCell& automatonCell = cellHolder.getAutomatonCell();
192 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.