Skip to content

Commit

Permalink
Use emplace_back instead of push_back (#6127)
Browse files Browse the repository at this point in the history
* use emplace_back instead of push_back

* use emplace_back instead of push_back

* Remove the space between `emplace_back` and its opening bracket `(`

* Fix indentation

* Remove unused type alias
  • Loading branch information
DIlkhush00 authored Sep 9, 2024
1 parent af7b2d5 commit e81b3a7
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 162 deletions.
2 changes: 1 addition & 1 deletion filters/include/pcl/filters/impl/covariance_sampling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pcl::CovarianceSampling<PointT, PointNT>::applyFilter (Indices &sampled_indices)
for (std::size_t i = 0; i < 6; ++i)
{
for (std::size_t p_i = 0; p_i < candidate_indices.size (); ++p_i)
L[i].push_back (std::make_pair (p_i, std::abs (v[p_i].dot (x.block<6, 1> (0, i)))));
L[i].emplace_back(p_i, std::abs (v[p_i].dot (x.block<6, 1> (0, i))));

// Sort in decreasing order
L[i].sort (sort_dot_list_function);
Expand Down
2 changes: 1 addition & 1 deletion io/include/pcl/io/grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ namespace pcl
boost::signals2::connection ret = signal->connect (callback);

connections_[typeid (T).name ()].push_back (ret);
shared_connections_[typeid (T).name ()].push_back (boost::signals2::shared_connection_block (connections_[typeid (T).name ()].back (), false));
shared_connections_[typeid (T).name ()].emplace_back(connections_[typeid (T).name ()].back (), false);
signalsChanged ();
return (ret);
}
Expand Down
4 changes: 2 additions & 2 deletions io/src/ply_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ pcl::PLYReader::vertexEndCallback ()
void
pcl::PLYReader::rangeGridBeginCallback ()
{
range_grid_->push_back (std::vector <int> ());
range_grid_->emplace_back();
}

void
Expand All @@ -459,7 +459,7 @@ pcl::PLYReader::rangeGridEndCallback () {}
void
pcl::PLYReader::faceBeginCallback ()
{
polygons_->push_back (pcl::Vertices ());
polygons_->emplace_back();
}

void
Expand Down
2 changes: 1 addition & 1 deletion io/src/vtk_lib_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ pcl::io::vtk2mesh (const vtkSmartPointer<vtkPolyData>& poly_data, pcl::TextureMe
{
float tex[2];
texture_coords->GetTupleValue (i, tex);
mesh.tex_coordinates.front ().push_back (Eigen::Vector2f (tex[0], tex[1]));
mesh.tex_coordinates.front ().emplace_back(tex[0], tex[1]);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion keypoints/src/narf_keypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ NarfKeypoint::calculateSparseInterestImage ()
static_cast<int> (pcl_lrint (std::floor ( (angle+deg2rad (90.0f))/deg2rad (180.0f) * angle_histogram_size))));
float& histogram_value = angle_histogram[histogram_cell];
histogram_value = (std::max) (histogram_value, surface_change_score);
angle_elements[histogram_cell].push_back (std::make_pair(index2, surface_change_score));
angle_elements[histogram_cell].emplace_back(index2, surface_change_score);
}

// Reset was_touched to false
Expand Down
2 changes: 1 addition & 1 deletion recognition/src/ransac_based/model_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ ModelLibrary::addToHashTable (Model* model, const ORROctree::Node::Data* data1,
HashTableCell* cell = hash_table_.getVoxel (key);

// Insert the pair (data1,data2) belonging to 'model'
(*cell)[model].push_back (std::pair<const ORROctree::Node::Data*, const ORROctree::Node::Data*> (data1, data2));
(*cell)[model].emplace_back(data1, data2);

return (true);
}
Expand Down
14 changes: 7 additions & 7 deletions registration/include/pcl/registration/impl/ia_fpcs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,8 @@ pcl::registration::FPCSInitialAlignment<PointSource, PointTarget, NormalT, Scala
continue;
}

pairs.push_back(pcl::Correspondence(*it_in, *it_out, dist));
pairs.push_back(pcl::Correspondence(*it_out, *it_in, dist));
pairs.emplace_back(*it_in, *it_out, dist);
pairs.emplace_back(*it_out, *it_in, dist);
}
}
}
Expand Down Expand Up @@ -766,10 +766,10 @@ pcl::registration::FPCSInitialAlignment<PointSource, PointTarget, NormalT, Scala
for (auto& match : matches) {
Eigen::Matrix4f transformation_temp;
pcl::Correspondences correspondences_temp;
correspondences_temp.push_back(pcl::Correspondence(match[0], base_indices[0], 0.0));
correspondences_temp.push_back(pcl::Correspondence(match[1], base_indices[1], 0.0));
correspondences_temp.push_back(pcl::Correspondence(match[2], base_indices[2], 0.0));
correspondences_temp.push_back(pcl::Correspondence(match[3], base_indices[3], 0.0));
correspondences_temp.emplace_back(match[0], base_indices[0], 0.0);
correspondences_temp.emplace_back(match[1], base_indices[1], 0.0);
correspondences_temp.emplace_back(match[2], base_indices[2], 0.0);
correspondences_temp.emplace_back(match[3], base_indices[3], 0.0);

// check match based on residuals of the corresponding points after
if (validateMatch(base_indices, match, correspondences_temp, transformation_temp) <
Expand Down Expand Up @@ -837,7 +837,7 @@ pcl::registration::FPCSInitialAlignment<PointSource, PointTarget, NormalT, Scala
}

// assign new correspondence and update indices of matched targets
correspondences.push_back(pcl::Correspondence(best_index, *it_base, best_diff_sqr));
correspondences.emplace_back(best_index, *it_base, best_diff_sqr);
*it_match_orig = best_index;
}
}
Expand Down
11 changes: 5 additions & 6 deletions registration/include/pcl/registration/impl/ia_kfpcs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ KFPCSInitialAlignment<PointSource, PointTarget, NormalT, Scalar>::handleMatches(
std::numeric_limits<float>::max(); // reset to std::numeric_limits<float>::max()
// to accept all candidates and not only best

correspondences_temp.push_back(pcl::Correspondence(match[0], base_indices[0], 0.0));
correspondences_temp.push_back(pcl::Correspondence(match[1], base_indices[1], 0.0));
correspondences_temp.push_back(pcl::Correspondence(match[2], base_indices[2], 0.0));
correspondences_temp.push_back(pcl::Correspondence(match[3], base_indices[3], 0.0));
correspondences_temp.emplace_back(match[0], base_indices[0], 0.0);
correspondences_temp.emplace_back(match[1], base_indices[1], 0.0);
correspondences_temp.emplace_back(match[2], base_indices[2], 0.0);
correspondences_temp.emplace_back(match[3], base_indices[3], 0.0);

// check match based on residuals of the corresponding points after transformation
if (validateMatch(base_indices, match, correspondences_temp, transformation_temp) <
Expand All @@ -145,8 +145,7 @@ KFPCSInitialAlignment<PointSource, PointTarget, NormalT, Scalar>::handleMatches(
validateTransformation(transformation_temp, fitness_score);

// store all valid match as well as associated score and transformation
candidates.push_back(
MatchingCandidate(fitness_score, correspondences_temp, transformation_temp));
candidates.emplace_back(fitness_score, correspondences_temp, transformation_temp);
}
// make sure that candidate with best fitness score is at the front, for early
// termination check
Expand Down
12 changes: 6 additions & 6 deletions simulation/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ pcl::simulation::TriangleMeshModel::TriangleMeshModel(pcl::PolygonMesh::Ptr plg)
for (const auto& polygon : plg->polygons) {
for (const auto& point : polygon.vertices) {
tmp = newcloud[point].getVector4fMap();
vertices.push_back(Vertex(Eigen::Vector3f(tmp(0), tmp(1), tmp(2)),
Eigen::Vector3f(newcloud[point].r / 255.0f,
newcloud[point].g / 255.0f,
newcloud[point].b / 255.0f)));
vertices.emplace_back(Eigen::Vector3f(tmp(0), tmp(1), tmp(2)),
Eigen::Vector3f(newcloud[point].r / 255.0f,
newcloud[point].g / 255.0f,
newcloud[point].b / 255.0f));
indices.push_back(indices.size());
}
}
Expand All @@ -39,8 +39,8 @@ pcl::simulation::TriangleMeshModel::TriangleMeshModel(pcl::PolygonMesh::Ptr plg)
for (const auto& polygon : plg->polygons) {
for (const auto& point : polygon.vertices) {
tmp = newcloud[point].getVector4fMap();
vertices.push_back(Vertex(Eigen::Vector3f(tmp(0), tmp(1), tmp(2)),
Eigen::Vector3f(1.0, 1.0, 1.0)));
vertices.emplace_back(Eigen::Vector3f(tmp(0), tmp(1), tmp(2)),
Eigen::Vector3f(1.0, 1.0, 1.0));
indices.push_back(indices.size());
}
}
Expand Down
Loading

0 comments on commit e81b3a7

Please sign in to comment.