@@ -123,14 +123,34 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
123123 state_[idx] = NONE;
124124 }
125125
126- // Saving coordinates and point to index mapping
126+ // Saving coordinates and point to index mapping + precomputations
127127 coords_.clear ();
128128 coords_.reserve (indices_->size ());
129+ normals_.clear ();
130+ normals_.reserve (indices_->size ());
131+ u_basis_.clear ();
132+ u_basis_.reserve (indices_->size ());
133+ v_basis_.clear ();
134+ v_basis_.reserve (indices_->size ());
135+ proj_qp_list_.clear ();
136+ proj_qp_list_.reserve (indices_->size ());
129137 std::vector<int > point2index (input_->size (), -1 );
130138 for (int cp = 0 ; cp < static_cast <int > (indices_->size ()); ++cp)
131139 {
132- coords_.push_back ((*input_)[(*indices_)[cp]].getVector3fMap ());
133- point2index[(*indices_)[cp]] = cp;
140+ const auto idx = (*indices_)[cp];
141+ const auto & p = (*input_)[idx];
142+ const Eigen::Vector3f xyz = p.getVector3fMap ();
143+ coords_.push_back (xyz);
144+ point2index[idx] = cp;
145+ const Eigen::Vector3f n = p.getNormalVector3fMap ();
146+ normals_.push_back (n);
147+ // local basis
148+ const Eigen::Vector3f v_local = n.unitOrthogonal ();
149+ const Eigen::Vector3f u_local = n.cross (v_local);
150+ v_basis_.push_back (v_local);
151+ u_basis_.push_back (u_local);
152+ const float dist = n.dot (xyz);
153+ proj_qp_list_.push_back (xyz - dist * n);
134154 }
135155
136156 // Initializing
@@ -171,16 +191,10 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
171191 nnIdx[i] = point2index[nnIdx[i]];
172192 }
173193
174- // Get the normal estimate at the current point
175- const Eigen::Vector3f nc = (*input_)[(*indices_)[R_]].getNormalVector3fMap ();
176-
177- // Get a coordinate system that lies on a plane defined by its normal
178- v_ = nc.unitOrthogonal ();
179- u_ = nc.cross (v_);
180-
181- // Projecting point onto the surface
182- float dist = nc.dot (coords_[R_]);
183- proj_qp_ = coords_[R_] - dist * nc;
194+ // Reuse precomputed normal, basis and projection
195+ u_ = u_basis_[R_];
196+ v_ = v_basis_[R_];
197+ proj_qp_ = proj_qp_list_[R_];
184198
185199 // Converting coords, calculating angles and saving the projected near boundary edges
186200 int nr_edge = 0 ;
@@ -336,16 +350,9 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
336350 increase_nnn4s++;
337351 }
338352
339- // Get the normal estimate at the current point
340- const Eigen::Vector3f nc = (*input_)[(*indices_)[R_]].getNormalVector3fMap ();
341-
342- // Get a coordinate system that lies on a plane defined by its normal
343- v_ = nc.unitOrthogonal ();
344- u_ = nc.cross (v_);
345-
346- // Projecting point onto the surface
347- float dist = nc.dot (coords_[R_]);
348- proj_qp_ = coords_[R_] - dist * nc;
353+ // Reuse precomputed normal, basis and projection
354+ u_ = u_basis_[R_]; v_ = v_basis_[R_]; proj_qp_ = proj_qp_list_[R_];
355+ const Eigen::Vector3f& nc = normals_[R_];
349356
350357 // Converting coords, calculating angles and saving the projected near boundary edges
351358 int nr_edge = 0 ;
@@ -372,7 +379,7 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
372379 if ((ffn_[R_] == nnIdx[i]) || (sfn_[R_] == nnIdx[i]))
373380 angles_[i].visible = true ;
374381 bool same_side = true ;
375- const Eigen::Vector3f neighbor_normal = (*input_)[(*indices_)[ nnIdx[i]]]. getNormalVector3fMap (); // / NOTE: nnIdx was reset
382+ const Eigen::Vector3f neighbor_normal = normals_[ nnIdx[i]];
376383 double cosine = nc.dot (neighbor_normal);
377384 if (cosine > 1 ) cosine = 1 ;
378385 if (cosine < -1 ) cosine = -1 ;
0 commit comments