Skip to content

Commit 7b96ac9

Browse files
committed
Reuse vector for double_edges.
1 parent 53bb5a9 commit 7b96ac9

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

surface/include/pcl/surface/gp3.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ namespace pcl
374374

375375
/** \brief Temporary variable to store 3 coordinates **/
376376
Eigen::Vector3f tmp_;
377-
377+
/** \brief Reusable buffer for projected boundary edges to avoid repeated allocations **/
378+
std::vector<doubleEdge> double_edges_{};
378379
/** \brief The actual surface reconstruction method.
379380
* \param[out] output the resultant polygonal mesh
380381
*/

surface/include/pcl/surface/impl/gp3.hpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
181181
//searchForNeighbors ((*indices_)[R_], nnIdx, sqrDists);
182182
//tree_->nearestKSearch ((*input_)[(*indices_)[R_]], nnn_, nnIdx, sqrDists);
183183
tree_->nearestKSearch (indices_->at (R_), nnn_, nnIdx, sqrDists);
184-
double sqr_dist_threshold = (std::min)(sqr_max_edge, sqr_mu * sqrDists[1]);
184+
const double sqr_dist_threshold = (std::min)(sqr_max_edge, sqr_mu * sqrDists[1]);
185185

186186
// Search tree returns indices into the original cloud, but we are working with indices. TODO: make that optional!
187187
for (int i = 1; i < nnn_; i++)
@@ -198,7 +198,8 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
198198

199199
// Converting coords, calculating angles and saving the projected near boundary edges
200200
int nr_edge = 0;
201-
std::vector<doubleEdge> doubleEdges;
201+
double_edges_.clear();
202+
double_edges_.reserve(nnn_);
202203
for (int i = 1; i < nnn_; i++) // nearest neighbor with index 0 is the query point R_ itself
203204
{
204205
// Transforming coordinates
@@ -229,7 +230,7 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
229230
tmp_ = coords_[sfn_[nnIdx[i]]] - proj_qp_;
230231
e.second[0] = tmp_.dot(u_);
231232
e.second[1] = tmp_.dot(v_);
232-
doubleEdges.push_back(e);
233+
double_edges_.push_back(e);
233234
}
234235
}
235236
angles_[0].visible = false;
@@ -241,12 +242,12 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
241242
bool visibility = true;
242243
for (int j = 0; j < nr_edge; j++)
243244
{
244-
if (ffn_[nnIdx[doubleEdges[j].index]] != nnIdx[i])
245-
visibility = isVisible(uvn_nn[i], uvn_nn[doubleEdges[j].index], doubleEdges[j].first, Eigen::Vector2f::Zero());
245+
if (ffn_[nnIdx[double_edges_[j].index]] != nnIdx[i])
246+
visibility = isVisible(uvn_nn[i], uvn_nn[double_edges_[j].index], double_edges_[j].first, Eigen::Vector2f::Zero());
246247
if (!visibility)
247248
break;
248-
if (sfn_[nnIdx[doubleEdges[j].index]] != nnIdx[i])
249-
visibility = isVisible(uvn_nn[i], uvn_nn[doubleEdges[j].index], doubleEdges[j].second, Eigen::Vector2f::Zero());
249+
if (sfn_[nnIdx[double_edges_[j].index]] != nnIdx[i])
250+
visibility = isVisible(uvn_nn[i], uvn_nn[double_edges_[j].index], double_edges_[j].second, Eigen::Vector2f::Zero());
250251
if (!visibility)
251252
break;
252253
}
@@ -327,13 +328,11 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
327328
// std::cerr << R_ << " [" << indices_->at (R_) << "] " << i << ": " << nnIdx[i] << " / " << point2index[nnIdx[i]] << std::endl;
328329
nnIdx[i] = point2index[nnIdx[i]];
329330
}
330-
331-
// Locating FFN and SFN to adapt distance threshold
332-
double sqr_source_dist = (coords_[R_] - coords_[source_[R_]]).squaredNorm ();
333-
double sqr_ffn_dist = (coords_[R_] - coords_[ffn_[R_]]).squaredNorm ();
334-
double sqr_sfn_dist = (coords_[R_] - coords_[sfn_[R_]]).squaredNorm ();
335-
double max_sqr_fn_dist = (std::max)(sqr_ffn_dist, sqr_sfn_dist);
336-
double sqr_dist_threshold = (std::min)(sqr_max_edge, sqr_mu * sqrDists[1]); //sqr_mu * sqr_avg_conn_dist);
331+
const double sqr_source_dist = (coords_[R_] - coords_[source_[R_]]).squaredNorm ();
332+
const double sqr_ffn_dist = (coords_[R_] - coords_[ffn_[R_]]).squaredNorm ();
333+
const double sqr_sfn_dist = (coords_[R_] - coords_[sfn_[R_]]).squaredNorm ();
334+
const double max_sqr_fn_dist = (std::max)(sqr_ffn_dist, sqr_sfn_dist);
335+
const double sqr_dist_threshold = (std::min)(sqr_max_edge, sqr_mu * sqrDists[1]);
337336
if (max_sqr_fn_dist > sqrDists[nnn_-1])
338337
{
339338
if (0 == increase_nnn4fn)
@@ -342,7 +341,7 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
342341
state_[R_] = BOUNDARY;
343342
continue;
344343
}
345-
double max_sqr_fns_dist = (std::max)(sqr_source_dist, max_sqr_fn_dist);
344+
const double max_sqr_fns_dist = (std::max)(sqr_source_dist, max_sqr_fn_dist);
346345
if (max_sqr_fns_dist > sqrDists[nnn_-1])
347346
{
348347
if (0 == increase_nnn4s)
@@ -356,8 +355,9 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
356355

357356
// Converting coords, calculating angles and saving the projected near boundary edges
358357
int nr_edge = 0;
359-
std::vector<doubleEdge> doubleEdges;
360-
for (int i = 1; i < nnn_; i++) // nearest neighbor with index 0 is the query point R_ itself
358+
double_edges_.clear();
359+
double_edges_.reserve(nnn_);
360+
for (int i = 1; i < nnn_; ++i) // nearest neighbor with index 0 is the query point R_ itself
361361
{
362362
tmp_ = coords_[nnIdx[i]] - proj_qp_;
363363
uvn_nn[i][0] = tmp_.dot(u_);
@@ -406,7 +406,7 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
406406
tmp_ = coords_[sfn_[nnIdx[i]]] - proj_qp_;
407407
e.second[0] = tmp_.dot(u_);
408408
e.second[1] = tmp_.dot(v_);
409-
doubleEdges.push_back(e);
409+
double_edges_.push_back(e);
410410
// Pruning by visibility criterion
411411
if ((state_[nnIdx[i]] == FRINGE) && (ffn_[R_] != nnIdx[i]) && (sfn_[R_] != nnIdx[i]))
412412
{
@@ -468,17 +468,17 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
468468
bool visibility = true;
469469
for (int j = 0; j < nr_edge; j++)
470470
{
471-
if (doubleEdges[j].index != i)
471+
if (double_edges_[j].index != i)
472472
{
473-
const auto& f = ffn_[nnIdx[doubleEdges[j].index]];
473+
const auto& f = ffn_[nnIdx[double_edges_[j].index]];
474474
if ((f != nnIdx[i]) && (f != R_))
475-
visibility = isVisible(uvn_nn[i], uvn_nn[doubleEdges[j].index], doubleEdges[j].first, Eigen::Vector2f::Zero());
475+
visibility = isVisible(uvn_nn[i], uvn_nn[double_edges_[j].index], double_edges_[j].first, Eigen::Vector2f::Zero());
476476
if (!visibility)
477477
break;
478478

479-
const auto& s = sfn_[nnIdx[doubleEdges[j].index]];
479+
const auto& s = sfn_[nnIdx[double_edges_[j].index]];
480480
if ((s != nnIdx[i]) && (s != R_))
481-
visibility = isVisible(uvn_nn[i], uvn_nn[doubleEdges[j].index], doubleEdges[j].second, Eigen::Vector2f::Zero());
481+
visibility = isVisible(uvn_nn[i], uvn_nn[double_edges_[j].index], double_edges_[j].second, Eigen::Vector2f::Zero());
482482
if (!visibility)
483483
break;
484484
}

0 commit comments

Comments
 (0)