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