-
Notifications
You must be signed in to change notification settings - Fork 1
/
PointCloudData.cpp
137 lines (111 loc) · 3.61 KB
/
PointCloudData.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
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
//
// PointCloudData.cpp
// 3DA_assignment1_bin
//
// Created by Benjamin Barral on 11/02/2019.
//
#include "PointCloudData.hpp"
#include <random>
using namespace std;
PointCloudData::PointCloudData() {
num_points_ = 0;
}
PointCloudData::PointCloudData(const MatrixXd &originalVertices) {
original_vertices_ = originalVertices;
updated_vertices_ = originalVertices;
ChangeColorRandomly();
num_points_ = originalVertices.rows();
}
PointCloudData::PointCloudData(const MatrixXd &originalVertices, const Vector3d& color) {
original_vertices_ = originalVertices;
updated_vertices_ = originalVertices;
for (int i = 0; i<3; i++){
colors_(0,i) = color(i);
}
num_points_ = originalVertices.rows();
}
MatrixXd PointCloudData::original_vertices() const {
return original_vertices_;
}
void PointCloudData::set_original_vertices(const MatrixXd &originalVertices) {
original_vertices_ = originalVertices;
}
MatrixXd PointCloudData::updated_vertices() const {
return updated_vertices_;
}
void PointCloudData::ResetVertices() {
updated_vertices_ = original_vertices_;
}
void PointCloudData::ChangeColorRandomly() {
for (int i=0; i<3; i++){
colors_(0,i) = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
}
}
void PointCloudData::TransformVerticesUser(const Transform <double , 3, Affine > &transformMatrix) {
Matrix<double, 4, Dynamic> verticesBHomogeneous = (original_vertices_.rowwise().homogeneous()).transpose();
MatrixXd temp = (transformMatrix * verticesBHomogeneous).transpose();
updated_vertices_ = temp.rowwise().hnormalized();
}
void PointCloudData::UpdateVertices(const MatrixXd &transformMatrix) {
Matrix<double, 4, Dynamic> verticesBHomogeneous = (updated_vertices_.rowwise().homogeneous()).transpose();
MatrixXd temp = (transformMatrix * verticesBHomogeneous).transpose();
updated_vertices_ = temp.rowwise().hnormalized();;
}
Matrix<double, 1, 3> PointCloudData::colors() const {
return colors_;
}
void PointCloudData::set_updated_vertices(const MatrixXd &updatedVertices) {
updated_vertices_ = updatedVertices;
}
void PointCloudData::set_colors(const Vector3d &color){
for (int i=0; i<3; i++){
colors_(0,i) = color(i);
}
}
void PointCloudData::ComputeBoundingBox(){
xMin = __DBL_MAX__;
yMin = __DBL_MAX__;
zMin = __DBL_MAX__;
xMax = __DBL_MIN__;
yMax = __DBL_MIN__;
zMax = __DBL_MIN__;
for (int i = 0; i < num_points_; i++){
Vector3d vec = original_vertices_.row(i);
double x = vec(0);
double y = vec(1);
double z = vec(2);
if (x > xMax){
xMax = x;
}
if (x < xMin){
xMin = x;
}
if (y > yMax){
yMax = y;
}
if (y < yMin){
yMin = y;
}
if (z > zMax){
zMax = z;
}
if (z < zMin){
zMin = z;
}
}
}
void PointCloudData::AddNoise(const double &sigmaRate) {
ComputeBoundingBox();
std::default_random_engine generator;
double sigmaX = sigmaRate * (xMax - xMin);
double sigmaY = sigmaRate * (yMax - yMin);
double sigmaZ = sigmaRate * (zMax - zMin);
normal_distribution<double> distX(0, sigmaX);
normal_distribution<double> distY(0, sigmaY);
normal_distribution<double> distZ(0, sigmaZ);
for (int i =0; i<num_points_; i++){
updated_vertices_(i,0) = original_vertices_(i,0) + distX(generator);
updated_vertices_(i,1) = original_vertices_(i,1) + distY(generator);
updated_vertices_(i,2) = original_vertices_(i,2) + distZ(generator);
}
}