comparison trajectorymanagement/src/MinimumMetric.h @ 1159:e1e7acef8eab

moved trajectory management library into Traffic Intelligence
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 22 Feb 2021 22:09:35 -0500
parents
children
comparison
equal deleted inserted replaced
1158:7eb972942f22 1159:e1e7acef8eab
1 #ifndef MINIMUMMETRIC_H_
2 #define MINIMUMMETRIC_H_
3
4 #include "Metric.h"
5
6 #include "TrajectoryExceptions.h"
7
8 /**
9 * MinimumMetric class.
10 *
11 * The Minimum metric measures the similarity between two trajectories.
12 * This class represents the smallest distance all 3 dimensions, for ALL points.
13 *
14 */
15 template<typename Tr, typename To>
16 class MinimumMetric: public Metric<Tr, To>
17 {
18 public:
19 /**
20 * Compute similarity between two trajectories.
21 *
22 * @param[in] a input trajectory
23 * @param[in] b input trajectory
24 * @param[out] result distance between two trajectories
25 */
26 void distance(const Trajectory<Tr> *a, const Trajectory<Tr> *b, To &result, unsigned int nbOfPoints = std::numeric_limits<unsigned int>::max())
27 {
28 result = To(0);
29
30 if (nbOfPoints == std::numeric_limits<unsigned int>::max())
31 checkTrajectoryLength(a->size(), b->size());
32
33 To diff = abs((a->getPoint(0) - b->getPoint(0)).x);//est-ce que ça fait vraiment une différence de x ?
34 for (unsigned int i = 0; i < a->size() and i < nbOfPoints; ++i)
35 {
36 cv::Point3_<typeof(static_cast<Tr>(a->getPoint(i)).x)> p(a->getPoint(i) - b->getPoint(i));
37 diff = std::min(diff, abs(p.x));
38 diff = std::min(diff, abs(p.y));
39 if (dim(a->getPoint(i)) == 3)
40 {
41 diff = std::min(diff, abs(p.z));
42 }
43 }
44
45 result = diff;
46 }
47
48 private:
49 /**
50 * Check the length of the trajectories.
51 *
52 * @param[in] a the size of the trajectory
53 * @param[in] b the size of the trajectory
54 */
55 void checkTrajectoryLength(size_t a, size_t b) const
56 {
57 if (a != b || a == 0)
58 {
59 throw TrajectoryLengthErrorException();
60 }
61 }
62 };
63
64 #endif /* MINIMUMMETRIC_H_ */