35 #include <Eigen/Dense> 41 #include <gsl/gsl_math.h> 42 #include <gsl/gsl_eigen.h> 50 using Vec = BaseVector<float>;
63 vector<float> normals;
68 size_t n_inPoints = in_buffer->numPoints();
69 floatArr in_points = in_buffer->getPointArray();
70 ucharArr in_colors = in_buffer->getColorArray(w_color);
73 floatArr p_arr(
new float[n_inPoints * 3]);
74 floatArr n_arr(
new float[n_inPoints * 3]);
76 if(in_buffer->hasColors())
78 c_arr =
ucharArr(
new unsigned char[n_inPoints * 3]);
107 for(
size_t i = 0; i < mat.
pixels.size(); i++)
109 #pragma omp parallel for 110 for(
size_t j = 0; j < mat.
pixels[i].size(); j++)
113 if(mat.
pixels[i][j].size() == 0)
119 vector<ModelToImage::PanoramaPoint> nb;
122 std::copy(mat.
pixels[i][j].begin(), mat.
pixels[i][j].end(), std::back_inserter(nb));
124 for(
int off_i = -di; off_i <= di; off_i++)
126 for(
int off_j = -dj; off_j <= dj; off_j++)
132 if(p_i >= 0 && p_i < mat.
pixels.size() &&
133 p_j >= 0 && p_j < mat.
pixels[i].size())
139 if(mat.
pixels[p_i][p_j].size() > 0)
141 nb.push_back(mat.
pixels[p_i][p_j][0]);
154 for(
int i = 0; i < nb.size(); i++)
157 size_t index = nb[i].index * 3;
160 Vec neighbor(in_points[index],
161 in_points[index + 1],
162 in_points[index + 2]);
165 mean.
x += neighbor.
x;
166 mean.
y += neighbor.
y;
167 mean.
z += neighbor.
z;
174 double covariance[9] = {0};
176 for(
int i = 0; i < nb.size(); i++)
178 size_t index = nb[i].index * 3;
180 Vec pt(in_points[index ] - mean.
x,
181 in_points[index + 1] - mean.
y,
182 in_points[index + 3] - mean.
z);
184 covariance[4] += pt.
y * pt.
y;
185 covariance[7] += pt.
y * pt.
z;
186 covariance[8] += pt.
z * pt.
z;
192 covariance[0] += pt.
x;
193 covariance[1] += pt.
y;
194 covariance[6] += pt.
z;
198 covariance[3] = covariance[1];
199 covariance[2] = covariance[6];
200 covariance[5] = covariance[7];
202 for(
int i = 0; i < 9; i++)
204 covariance[i] /= nb.size();
208 gsl_matrix_view m = gsl_matrix_view_array(covariance, 3, 3);
209 gsl_matrix* evec = gsl_matrix_alloc(3, 3);
210 gsl_vector* eval = gsl_vector_alloc(3);
213 gsl_eigen_symmv_workspace * w = gsl_eigen_symmv_alloc (3);
214 gsl_eigen_symmv (&m.matrix, eval, evec, w);
216 gsl_eigen_symmv_free (w);
217 gsl_eigen_symmv_sort (eval, evec, GSL_EIGEN_SORT_ABS_ASC);
219 gsl_vector_view evec_0 = gsl_matrix_column(evec, 0);
220 float nx = gsl_vector_get(&evec_0.vector, 0);
221 float ny = gsl_vector_get(&evec_0.vector, 1);
222 float nz = gsl_vector_get(&evec_0.vector, 2);
228 size_t index = mat.
pixels[i][j][0].index * 3;
229 Vec p1 = center -
Vec(in_points[index], in_points[index + 1], in_points[index + 2]);
238 for(
size_t k = 0; k < mat.
pixels[i][j].size(); k++)
243 size_t index = mat.
pixels[i][j][k].index * 3;
244 size_t color_index = mat.
pixels[i][j][k].index * w_color;
247 p_arr[index ] = in_points[index];
248 p_arr[index + 1] = in_points[index + 1];
249 p_arr[index + 2] = in_points[index + 2];
251 if(in_buffer->hasColors())
253 c_arr[index ] = in_colors[color_index];
254 c_arr[index + 1] = in_colors[color_index + 1];
255 c_arr[index + 2] = in_colors[color_index + 2];
261 n_arr[index + 1] = ny;
262 n_arr[index + 2] = nz;
320 cout <<
timestamp <<
"Finished normal estimation" << endl;
322 if(in_buffer->hasColors())
324 out_buffer->setColorArray(c_arr, n_inPoints);
326 out_buffer->setPointArray(p_arr, n_inPoints);
327 out_buffer->setNormalArray(n_arr, n_inPoints);
A class to handle point information with an arbitrarily large number of attribute channels...
PanoramaNormals(ModelToImage *mti)
PointBufferPtr computeNormals(int with, int height, bool interpolate)
void computeDepthListMatrix(DepthListMatrix &mat)
Computes a DepthListMatrix, i.e., an image matrix where each entry holds a vector of all points that ...
Image with list of projected points at each pixel.
static Timestamp timestamp
A global time stamp object for program runtime measurement.
The ModelToImage class provides methods to re-project 3D laser scans to image planes.
boost::shared_array< unsigned char > ucharArr
std::shared_ptr< PointBuffer > PointBufferPtr
boost::shared_array< float > floatArr
vector< vector< vector< PanoramaPoint > > > pixels
string getElapsedTime() const
Returns a string representation of the current timer value.
OutputIterator interpolate(InputIterator p1, InputIterator p2, float fraction, OutputIterator result)
Peforms linear interpolation between two points.
PointBufferPtr pointBuffer()
Retruns the point buffer.