Mercurial Hosting > traffic-intelligence
comparison trajectorymanagement/src/ManhattanMetric.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 MANHATTANMETRIC_H_ | |
2 #define MANHATTANMETRIC_H_ | |
3 | |
4 #include "Metric.h" | |
5 | |
6 #include "TrajectoryExceptions.h" | |
7 | |
8 /** | |
9 * ManhattanMetric class. | |
10 * | |
11 * The Manhattan metric measures the similarity between two trajectories. | |
12 */ | |
13 template<typename Tr, typename To> | |
14 class ManhattanMetric: public Metric<Tr, To> | |
15 { | |
16 public: | |
17 /** | |
18 * Compute similarity between two trajectories. | |
19 * | |
20 * @param[in] a input trajectory | |
21 * @param[in] b input trajectory | |
22 * @param[out] result distance between two trajectories | |
23 */ | |
24 void distance(const Trajectory<Tr> *a, const Trajectory<Tr> *b, To &result, unsigned int nbOfPoints = std::numeric_limits<unsigned int>::max()) | |
25 { | |
26 result = To(0); | |
27 | |
28 if (nbOfPoints == std::numeric_limits<unsigned int>::max()) | |
29 checkTrajectoryLength(a->size(), b->size()); | |
30 | |
31 To diff = To(0); | |
32 for (unsigned int i = 0; i < a->size() and i < nbOfPoints; ++i) | |
33 { | |
34 cv::Point3_<typeof(static_cast<Tr>(a->getPoint(i)).x)> p(a->getPoint(i) - b->getPoint(i)); | |
35 diff += abs(p.x) + abs(p.y) + abs(p.z); | |
36 } | |
37 | |
38 result = diff; | |
39 } | |
40 | |
41 private: | |
42 /** | |
43 * Check the length of the trajectories. | |
44 * | |
45 * @param[in] a the size of the trajectory | |
46 * @param[in] b the size of the trajectory | |
47 */ | |
48 void checkTrajectoryLength(size_t a, size_t b) const | |
49 { | |
50 if (a != b || a == 0) | |
51 { | |
52 throw TrajectoryLengthErrorException(); | |
53 } | |
54 } | |
55 }; | |
56 | |
57 #endif /* MANHATTANMETRIC_H_ */ |