10#include <tracking/trackFindingCDC/ca/AutomatonCell.h>
12#include <tracking/trackFindingCDC/utilities/VectorRange.h>
13#include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
15#include <tracking/trackFindingCDC/findlets/base/Findlet.h>
17#include <framework/logging/Logger.h>
24 namespace TrackFindingCDC {
39 template <
class ACellHolder,
class ACluster = std::vector<ACellHolder*> >
41 :
public Findlet<ACellHolder* const, WeightedRelation<ACellHolder> const, ACluster> {
54 void apply(std::vector<ACellHolder*>
const& cellHolders,
56 std::vector<ACluster>& clusters)
override
59 assert(std::is_sorted(cellHolderRelations.begin(),
60 cellHolderRelations.end()));
66 for (ACellHolder* cellHolder : cellHolders) {
71 std::vector<ACellHolder*> cluster;
75 for (ACellHolder* cellHolder : cellHolders) {
82 cluster.push_back(cellHolder);
86 clusters.emplace_back(std::move(cluster));
94 std::vector<ACellHolder*>& cluster)
const
96 ACellHolder* seedCellHolder = cluster.front();
100 std::vector<ACellHolder*> checkNow;
101 std::vector<ACellHolder*> checkNext;
103 checkNow.reserve(10);
104 checkNext.reserve(10);
106 checkNext.push_back(seedCellHolder);
108 while (not checkNext.empty()) {
110 checkNow.swap(checkNext);
113 for (ACellHolder* cellHolder : checkNow) {
116 std::equal_range(cellHolderRelations.begin(),
117 cellHolderRelations.end(),
121 size_t nNeighbors = neighborRelations.
size();
125 ACellHolder* neighborCellHolder = neighborRelation.getTo();
127 Weight neighborICluster =
getCellState(neighborCellHolder);
128 if (neighborICluster == -1) {
131 cluster.push_back(neighborCellHolder);
134 checkNext.push_back(neighborCellHolder);
138 if (neighborICluster != iCluster) {
139 B2WARNING(
"Clusterizer: Neighboring item was already assigned to different "
140 "cluster. Check if the neighborhood is symmetric.");
151 AutomatonCell& automatonCell = cellHolder->getAutomatonCell();
158 const AutomatonCell& automatonCell = cellHolder->getAutomatonCell();
165 AutomatonCell& automatonCell = cellHolder->getAutomatonCell();
Cell used by the cellular automata.
Weight getCellState() const
Getter for the cell state.
void setCellState(Weight state)
Setter for the cell state.
void setCellWeight(Weight weight)
Setter for the cell weight.
Implementation of the clustering Clusters elements of a given collection using the relations presente...
void expandCluster(std::vector< WeightedRelation< ACellHolder > > const &cellHolderRelations, std::vector< ACellHolder * > &cluster) const
Helper function. Starting a new cluster and iteratively expands it.
void setCellState(ACellHolder *cellHolder, Weight cellState) const
Setter for the cell state of a pointed object that holds an AutomatonCell.
void setCellWeight(ACellHolder *cellHolder, Weight cellWeight) const
Setter for the cell weight of a pointed object that holds an AutomatonCell.
Weight getCellState(ACellHolder *cellHolder) const
Getter for the cell state of a pointed object that holds an AutomatonCell.
void apply(std::vector< ACellHolder * > const &cellHolders, std::vector< WeightedRelation< ACellHolder > > const &cellHolderRelations, std::vector< ACluster > &clusters) override
Creates the clusters.
Interface for a minimal algorithm part that wants to expose some parameters to a module.
A pair of iterators usable with the range base for loop.
std::size_t size() const
Returns the total number of objects in this range.
Type for two related objects with a weight.
Abstract base class for different kinds of events.