forked from augcog/OpenARK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFramePlane.cpp
66 lines (56 loc) · 1.97 KB
/
FramePlane.cpp
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
60
61
62
63
64
65
66
#include "stdafx.h"
#include "FramePlane.h"
#include "Util.h"
namespace ark {
FramePlane::FramePlane() : equation(0, 0, 0), FrameObject()
{
}
FramePlane::FramePlane(const Vec3f & v, const cv::Mat & cluster_depth_map,
DetectionParams::Ptr params)
: equation(v), FrameObject(cluster_depth_map, params)
{
initializePlane();
}
FramePlane::FramePlane(Vec3f v, VecP2iPtr points_ij, VecV3fPtr points_xyz,
const cv::Mat & depth_map, DetectionParams::Ptr params, bool sorted, int points_to_use)
: equation(v),
FrameObject(points_ij, points_xyz, depth_map, params, sorted, points_to_use)
{
initializePlane();
}
Vec3f FramePlane::getNormalVector()
{
cv::Vec3f normal(equation[0], equation[1], -1.0);
return cv::normalize(normal);
}
float FramePlane::getZ(float x, float y)
{
return equation[0] * x + equation[1] * y + equation[2];
}
bool FramePlane::touching(const Vec3f & point, const Point2i & index, float norm_thresh, bool check_bounds) const
{
if (squaredDistanceToPoint(point) > norm_thresh) return false;
else if (!check_bounds) return true;
return cv::pointPolygonTest(boundingRect, index, false) >= 0;
}
float FramePlane::squaredDistanceToPoint(const Vec3f & point) const
{
return util::pointPlaneSquaredDistance(point, equation);
}
float FramePlane::distanceToPoint(const Vec3f & point) const
{
return util::pointPlaneDistance(point, equation);
}
const std::vector<Point2f> & FramePlane::getPlaneBoundingRect() const
{
return boundingRect;
}
void FramePlane::initializePlane()
{
surfaceArea = util::surfaceArea(fullMapSize, *points, *points_xyz);
cv::RotatedRect boundingRect = cv::minAreaRect(*points);
Point2f pts[4];
boundingRect.points(pts);
this->boundingRect = std::vector<Point2f>(pts, pts + 4);
}
}