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