-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpoint.h
178 lines (142 loc) · 3.81 KB
/
point.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef POINT_H
#define POINT_H
#define _USE_MATH_DEFINES
#include <cmath>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include <Eigen/Core>
template <size_t DIMENSION>
class Point
{
public:
typedef Eigen::Matrix<float, DIMENSION, 1> Vector;
Point(const Vector &position, const Eigen::Vector3f &color, float intensity, const Vector &normal, float normalConfidence, float curvature)
: mPosition(position)
, mColor(color)
, mIntensity(intensity)
, mNormal(normal)
, mInvNormal(1 / mNormal.array())
, mNormalConfidence(normalConfidence)
, mCurvature(curvature)
, mAngle((std::atan2(mNormal.y(), mNormal.x()) + M_PI) * 180.0f / M_PI)
{
static_assert(DIMENSION > 0, "Dimension must be greater than zero.");
}
Point(const Vector &position, const Eigen::Vector3f &color, float intensity, const Vector &normal, float normalConfidence)
: Point(position, color, intensity, normal, normalConfidence, 0)
{
}
Point(const Vector &position, const Eigen::Vector3f &color, float intensity, const Vector &normal)
: Point(position, color, intensity, normal, 0, 0)
{
}
Point(const Vector &position, const Eigen::Vector3f &color, float intensity)
: Point(position, color, intensity, Vector::Zero(), 0, 0)
{
}
Point(const Vector &position, const Eigen::Vector3f &color)
: Point(position, color, 0, Vector::Zero(), 0, 0)
{
}
Point(const Vector &position)
: Point(position, Eigen::Vector3f::Zero(), 0, Vector::Zero(), 0, 0)
{
}
Point()
: Point(Vector::Zero(), Eigen::Vector3f::Zero(), 0, Vector::Zero(), 0, 0)
{
}
const Vector& position() const
{
return mPosition;
}
void position(const Vector &position)
{
mPosition = position;
}
const Eigen::Vector3f& color() const
{
return mColor;
}
void color(const Eigen::Vector3f &color)
{
mColor = color;
}
float intensity() const
{
return mIntensity;
}
void intensity(float intensity)
{
mIntensity = intensity;
}
const Vector& normal() const
{
return mNormal;
}
void normal(const Vector& normal)
{
mNormal = normal;
mInvNormal = 1 / mNormal.array();
mAngle = (std::atan2(mNormal.y(), mNormal.x()) + M_PI) * 180.0f / M_PI;
}
const Vector& invNormal() const
{
return mInvNormal;
}
float angle() const
{
return mAngle;
}
float normalConfidence() const
{
return mNormalConfidence;
}
void normalConfidence(float normalConfidence)
{
mNormalConfidence = normalConfidence;
}
float curvature() const
{
return mCurvature;
}
void curvature(float curvature)
{
mCurvature = curvature;
}
Point<DIMENSION>& operator+=(const Point<DIMENSION> &other)
{
this->mPosition += other.mPosition;
this->mColor += other.mColor;
this->mIntensity += other.mIntensity;
this->mNormal += other.mNormal;
this->mNormalConfidence += other.mNormalConfidence;
this->mCurvature += other.mCurvature;
return *this;
}
Point<DIMENSION>& operator/=(float n)
{
this->mPosition /= n;
this->mColor /= n;
this->mIntensity /= n;
this->mNormal /= n;
this->mNormalConfidence /= n;
this->mCurvature /= n;
return *this;
}
private:
Vector mPosition;
Eigen::Vector3f mColor;
float mIntensity;
Vector mNormal;
Vector mInvNormal;
float mNormalConfidence;
float mCurvature;
float mAngle;
};
template class Point<2>;
template class Point<3>;
typedef Point<2> Point2d;
typedef Point<3> Point3d;
#endif // POINT_H