-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineModel.hpp
59 lines (46 loc) · 1.22 KB
/
LineModel.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include "RANSAC.hpp"
class Point2D
{
public:
Point2D(double x_, double y_)
{
x = x_;
y = y_;
};
double x;
double y;
};
class Line2DModel : public ransac::Model<Point2D>
{
protected:
// Parametric form
double A, B, C; // Ax + By + C = 0
double m_dist_denominator; // = sqrt(A^2 + B^2). Stored for efficiency reasons
public:
void getParams(std::vector<double>& params)
{
params.clear();
params.resize(3);
params[0] = A;
params[1] = B;
params[2] = C;
}
virtual void initModel(const std::vector<std::shared_ptr<Point2D>> &v_data) override
{
if (v_data.size() != 2)
throw std::runtime_error("Line2DModel - Number of input parameters does not match minimum number required for this model.");
auto p1 = v_data[0];
auto p2 = v_data[1];
// Compute the line parameters
A = p2->y - p1->y;
B = p1->x - p2->x;
C = p2->x*p1->y - p1->x*p2->y;
m_dist_denominator = sqrt(A * A + B * B); // Cache square root for efficiency
};
virtual double computeDistanceMeasure(std::shared_ptr<Point2D> p) override
{
// Return distance between passed "point" and this line
return fabs(A * p->x + B * p->y + C) / m_dist_denominator;
};
};