StaticRelationHeuristic.cpp
Go to the documentation of this file.
1 
19 
20 #include <vector>
22 
23 namespace ISM {
24  StaticRelationHeuristic::StaticRelationHeuristic(const TracksPtr& tracks) : Heuristic("StaticRelationHeuristic") {
25  typedef GeometryHelper GH;
26 
27  for (TrackPtr& first : tracks->tracks) {
28  TrackPtr currentBest;
29  int bestStaticBreaks = 0;
30  int bestCommonPositions = 0;
31  double bestAvgDistance = 0;
32 
33  for (TrackPtr& second : tracks->tracks) {
34  if (first == second) {
35  continue;
36  }
37 
38  /*
39  * What we do:
40  * Calculate a vote from second to first (using first as the reference pose).
41  * Use that vote on the next frame to search first, looking from second.
42  * If the miss alignment is more than 10% of the average position difference between first and second,
43  * incease staticBreaks and recalculate the vote.
44  *
45  * At the end, if the staticBreaks are below 5% of the sample range,
46  * and they appear together in more than 95% of the frames,
47  * add second to the cluster with first as the reference point.
48  */
49 
50  VoteSpecifierPtr vote;
51  int commonPositions = 0;
52  int staticBreaks = 0;
53  double averageDistance = 0;
54 
55  for (size_t i = 0; i < first->objects.size(); i++) {
56  ObjectPtr firstObject = first->objects[i];
57  ObjectPtr secondObject = second->objects[i];
58  if (!firstObject || !secondObject) {
59  continue;
60  }
61 
62  averageDistance += GH::getDistanceBetweenPoints(
63  firstObject->pose->point,
64  secondObject->pose->point
65  );
66  commonPositions++;
67  }
68 
69  averageDistance /= (double)commonPositions;
70 
71  double maxDeviation = averageDistance * 0.1;
72 
73  for (size_t i = 0; i < first->objects.size(); i++) {
74  ObjectPtr firstObject = first->objects[i];
75  ObjectPtr secondObject = second->objects[i];
76  if (!firstObject || !secondObject) {
77  continue;
78  }
79 
80  if (!vote) {
81  vote = GH::createVoteSpecifier(secondObject->pose, firstObject->pose);
82  continue;
83  }
84 
85  PointPtr referencePoint = GH::applyQuatAndRadiusToPose(
86  secondObject->pose,
87  vote->objectToRefQuat,
88  vote->radius
89  );
90 
91  double distance = GH::getDistanceBetweenPoints(
92  firstObject->pose->point,
93  referencePoint
94  );
95 
96  if (distance > maxDeviation) {
97  staticBreaks++;
98  vote = GH::createVoteSpecifier(secondObject->pose, firstObject->pose);
99  }
100  }
101 
102  if (
103  (double)staticBreaks < ((double)commonPositions) * 0.05 &&
104  commonPositions > (double)first->objects.size() * 0.5 &&
105  (!currentBest || staticBreaks < bestStaticBreaks ||
106  (staticBreaks == bestStaticBreaks && bestAvgDistance > averageDistance))
107  ) {
108  currentBest = second;
109  bestStaticBreaks = staticBreaks;
110  bestCommonPositions = commonPositions;
111  bestAvgDistance = averageDistance;
112  }
113  }
114 
115  if (currentBest) {
116  double conf = 1 - (double)bestStaticBreaks / (double)bestCommonPositions;
117  if (conf > this->confidence) {
118  std::vector<TrackPtr> cluster;
119  cluster.push_back(first);
120  cluster.push_back(currentBest);
121  this->cluster = TracksPtr(new Tracks(cluster));
122  this->confidence = conf;
123  }
124  }
125  }
126  }
127 }
static VoteSpecifierPtr createVoteSpecifier(const PosePtr &sourcePose, const PosePtr &refPose)
boost::shared_ptr< Point > PointPtr
Definition: Point.hpp:45
static PointPtr applyQuatAndRadiusToPose(const PosePtr &pose, const QuaternionPtr &quat, double radius)
TracksPtr cluster
Definition: Heuristic.hpp:40
static double getDistanceBetweenPoints(const PointPtr &p1, const PointPtr &p2)
GeometryHelper GH
boost::shared_ptr< VoteSpecifier > VoteSpecifierPtr
boost::shared_ptr< Tracks > TracksPtr
Definition: Tracks.hpp:42
double confidence
Definition: Heuristic.hpp:39
boost::shared_ptr< Track > TrackPtr
Definition: Track.hpp:55
StaticRelationHeuristic(const TracksPtr &tracks)
this namespace contains all generally usable classes.
boost::shared_ptr< Object > ObjectPtr
Definition: Object.hpp:82


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:41