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