DirectionRelationHeuristic.cpp
Go to the documentation of this file.
1 
19 
20 #include <vector>
21 #include <boost/math/constants/constants.hpp>
22 #include <algorithm>
24 
25 namespace ISM {
26 
27  DirectionRelationHeuristic::DirectionRelationHeuristic(const double pStaticBreakRatio, const double pTogetherRatio, const double pMaxAngleDeviation) :
28  Heuristic("DirectionRelationHeuristic"), mStaticBreakRatio(pStaticBreakRatio), mTogetherRatio(pTogetherRatio), mMaxAngleDeviation(pMaxAngleDeviation) {}
29 
30  void
32  typedef GeometryHelper GH;
33  typedef Eigen::Vector3d Vector;
34 
35  double bestDistance;
36  for (TrackPtr& first : tracks->tracks) {
37  TrackPtr currentBest;
38  double currentClosestDistance;
39  int currentBestBreaks = 1;
40  int currentBestCommonPositions = 1;
41 
42  for (TrackPtr& second : tracks->tracks) {
43  if (first == second) {
44  continue;
45  }
46 
47  /*
48  * What we do:
49  * Calculate a direction Vector from first to second for every Frame.
50  * Check in every frame the angle between the reference vector (first vector) and the current vector.
51  * If the misalignment is more than mMaxAngleDeviation degrees, increase staticBreaks and
52  * recalculate the reference vote.
53  * Also calculate the average distance between first and second.
54  *
55  * At the end, if the staticBreaks are below mStaticBreakRatio of the sample range,
56  * and they appear together in more than mTogetherRatio of the frames,
57  * and the second is closer to first than the current closest track,
58  * replace the current closest track with second.
59  *
60  * At the end, choose the first<->second combination with the lowest rate of static breaks.
61  *
62  * This will always create a cluster of two tracks.
63  */
64 
65  int commonPositions = 0;
66  double averageDistance = 0;
67 
68  for (size_t i = 0; i < first->objects.size(); i++) {
69  ObjectPtr firstObject = first->objects[i];
70  ObjectPtr secondObject = second->objects[i];
71  if (!firstObject || !secondObject) {
72  continue;
73  }
74 
75  averageDistance += GH::getDistanceBetweenPoints(firstObject->pose->point,
76  secondObject->pose->point);
77  commonPositions++;
78  }
79  if (commonPositions < (double) first->objects.size() * mTogetherRatio) {
80  continue;
81  }
82 
83  averageDistance /= (double) commonPositions;
84 
85  int staticBreaks = 0;
86  Vector directionVector;
87  bool firstRun = true;
88 
89  for (size_t i = 0; i < first->objects.size(); i++) {
90  ObjectPtr firstObject = first->objects[i];
91  ObjectPtr secondObject = second->objects[i];
92  if (!firstObject || !secondObject) {
93  continue;
94  }
95 
96  if (firstRun) {
97  directionVector = GH::getDirectionVector(firstObject->pose, secondObject->pose);
98  firstRun = false;
99  continue;
100  }
101 
102  Vector currentDirection = GH::getDirectionVector(firstObject->pose, secondObject->pose);
103 
104  double deviation = GH::getAngleBetweenAxes(directionVector, currentDirection);
105 
106  if (deviation > mMaxAngleDeviation) {
107  staticBreaks++;
108  directionVector = currentDirection;
109  }
110  }
111 
112  if (
113  ((double) staticBreaks < ((double) commonPositions) * mStaticBreakRatio) &&
114  (!currentBest || (currentClosestDistance > averageDistance))
115  ) {
116  currentBest = second;
117  currentClosestDistance = averageDistance;
118  currentBestBreaks = staticBreaks;
119  currentBestCommonPositions = commonPositions;
120  }
121  }
122 
123  if (currentBest) {
124  double conf = 1 - (double) currentBestBreaks / (double) currentBestCommonPositions;
125  if (!this->cluster
126  || (conf > this->confidence
127  || (conf == this->confidence && bestDistance > currentClosestDistance))) {
128  std::vector<TrackPtr> cluster;
129  cluster.push_back(first);
130  cluster.push_back(currentBest);
131  this->cluster = TracksPtr(new Tracks(cluster));
132  this->confidence = conf;
133  bestDistance = currentClosestDistance;
134  }
135  }
136  }
137  }
138 
139 }
DirectionRelationHeuristic(const double pStaticBreakRatio, const double pTogetherRatio, const double pMaxAngleDeviation)
static double getAngleBetweenAxes(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
TracksPtr cluster
Definition: Heuristic.hpp:40
static double getDistanceBetweenPoints(const PointPtr &p1, const PointPtr &p2)
static Eigen::Vector3d getDirectionVector(const PosePtr &first, const PosePtr &second)
virtual void applyHeuristic(const TracksPtr &tracks)
GeometryHelper GH
boost::shared_ptr< Tracks > TracksPtr
Definition: Tracks.hpp:42
double confidence
Definition: Heuristic.hpp:39
boost::shared_ptr< Track > TrackPtr
Definition: Track.hpp:55
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:40