From e81b3a71273b42db17d97ae8163ecafeb13eac32 Mon Sep 17 00:00:00 2001 From: Dilkhush Date: Tue, 10 Sep 2024 00:20:38 +0530 Subject: [PATCH] Use `emplace_back` instead of `push_back` (#6127) * 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 --- .../pcl/filters/impl/covariance_sampling.hpp | 2 +- io/include/pcl/io/grabber.h | 2 +- io/src/ply_io.cpp | 4 +- io/src/vtk_lib_io.cpp | 2 +- keypoints/src/narf_keypoint.cpp | 2 +- .../src/ransac_based/model_library.cpp | 2 +- .../include/pcl/registration/impl/ia_fpcs.hpp | 14 +- .../pcl/registration/impl/ia_kfpcs.hpp | 11 +- simulation/src/model.cpp | 12 +- test/geometry/test_mesh.cpp | 172 +++++++++--------- test/geometry/test_mesh_circulators.cpp | 30 +-- test/geometry/test_mesh_data.cpp | 6 +- test/geometry/test_polygon_mesh.cpp | 26 +-- test/geometry/test_quad_mesh.cpp | 21 +-- test/geometry/test_triangle_mesh.cpp | 2 +- test/outofcore/test_outofcore.cpp | 2 +- test/registration/test_registration_api.cpp | 8 +- tools/elch.cpp | 2 +- tools/lum.cpp | 2 +- 19 files changed, 160 insertions(+), 162 deletions(-) diff --git a/filters/include/pcl/filters/impl/covariance_sampling.hpp b/filters/include/pcl/filters/impl/covariance_sampling.hpp index 99d8da8f550..a3885cf6aeb 100644 --- a/filters/include/pcl/filters/impl/covariance_sampling.hpp +++ b/filters/include/pcl/filters/impl/covariance_sampling.hpp @@ -164,7 +164,7 @@ pcl::CovarianceSampling::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); diff --git a/io/include/pcl/io/grabber.h b/io/include/pcl/io/grabber.h index ce6f55a0890..71f4df826f9 100644 --- a/io/include/pcl/io/grabber.h +++ b/io/include/pcl/io/grabber.h @@ -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); } diff --git a/io/src/ply_io.cpp b/io/src/ply_io.cpp index 47b8de6adba..af58106a2cb 100644 --- a/io/src/ply_io.cpp +++ b/io/src/ply_io.cpp @@ -435,7 +435,7 @@ pcl::PLYReader::vertexEndCallback () void pcl::PLYReader::rangeGridBeginCallback () { - range_grid_->push_back (std::vector ()); + range_grid_->emplace_back(); } void @@ -459,7 +459,7 @@ pcl::PLYReader::rangeGridEndCallback () {} void pcl::PLYReader::faceBeginCallback () { - polygons_->push_back (pcl::Vertices ()); + polygons_->emplace_back(); } void diff --git a/io/src/vtk_lib_io.cpp b/io/src/vtk_lib_io.cpp index f13855dd6c9..9c1bc5190fc 100644 --- a/io/src/vtk_lib_io.cpp +++ b/io/src/vtk_lib_io.cpp @@ -410,7 +410,7 @@ pcl::io::vtk2mesh (const vtkSmartPointer& 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 diff --git a/keypoints/src/narf_keypoint.cpp b/keypoints/src/narf_keypoint.cpp index 35d5811d34a..c8073cf6314 100644 --- a/keypoints/src/narf_keypoint.cpp +++ b/keypoints/src/narf_keypoint.cpp @@ -555,7 +555,7 @@ NarfKeypoint::calculateSparseInterestImage () static_cast (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 diff --git a/recognition/src/ransac_based/model_library.cpp b/recognition/src/ransac_based/model_library.cpp index dd3d3efdabc..6efba154c12 100644 --- a/recognition/src/ransac_based/model_library.cpp +++ b/recognition/src/ransac_based/model_library.cpp @@ -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 (data1, data2)); + (*cell)[model].emplace_back(data1, data2); return (true); } diff --git a/registration/include/pcl/registration/impl/ia_fpcs.hpp b/registration/include/pcl/registration/impl/ia_fpcs.hpp index 7de32edca78..31533621a82 100644 --- a/registration/include/pcl/registration/impl/ia_fpcs.hpp +++ b/registration/include/pcl/registration/impl/ia_fpcs.hpp @@ -621,8 +621,8 @@ pcl::registration::FPCSInitialAlignment::handleMatches( std::numeric_limits::max(); // reset to std::numeric_limits::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) < @@ -145,8 +145,7 @@ KFPCSInitialAlignment::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 diff --git a/simulation/src/model.cpp b/simulation/src/model.cpp index 99ec4d45fc3..656600fe018 100644 --- a/simulation/src/model.cpp +++ b/simulation/src/model.cpp @@ -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()); } } @@ -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()); } } diff --git a/test/geometry/test_mesh.cpp b/test/geometry/test_mesh.cpp index 0b6df7d97cc..aa54bb4aee0 100644 --- a/test/geometry/test_mesh.cpp +++ b/test/geometry/test_mesh.cpp @@ -89,9 +89,9 @@ TEST (TestAddDeleteFace, NonManifold1) using VI = VertexIndex; VertexIndices vi; std::vector faces; - vi.push_back (VI (0)); vi.push_back (VI (3)); vi.push_back (VI (1)); faces.push_back (vi); vi.clear (); // 0 - vi.push_back (VI (2)); vi.push_back (VI (1)); vi.push_back (VI (4)); faces.push_back (vi); vi.clear (); // 1 - vi.push_back (VI (0)); vi.push_back (VI (2)); vi.push_back (VI (5)); faces.push_back (vi); vi.clear (); // 2 + vi.emplace_back(0); vi.emplace_back(3); vi.emplace_back(1); faces.push_back (vi); vi.clear (); // 0 + vi.emplace_back(2); vi.emplace_back(1); vi.emplace_back(4); faces.push_back (vi); vi.clear (); // 1 + vi.emplace_back(0); vi.emplace_back(2); vi.emplace_back(5); faces.push_back (vi); vi.clear (); // 2 for (const auto &face : faces) { ASSERT_TRUE (mesh.addFace (face).isValid ()); @@ -100,18 +100,18 @@ TEST (TestAddDeleteFace, NonManifold1) // Check if the whole boundary is reached. VertexIndices boundary_expected; - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (5)); - boundary_expected.push_back (VI (2)); - boundary_expected.push_back (VI (4)); - boundary_expected.push_back (VI (1)); - boundary_expected.push_back (VI (3)); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(5); + boundary_expected.emplace_back(2); + boundary_expected.emplace_back(4); + boundary_expected.emplace_back(1); + boundary_expected.emplace_back(3); VertexIndices boundary_vertices = getBoundaryVertices (mesh, VI (3)); EXPECT_EQ (boundary_expected, boundary_vertices); // Close the gaps. - vi.push_back (VI (0)); vi.push_back (VI (1)); vi.push_back (VI (2)); faces.push_back (vi); vi.clear (); // 3 + vi.emplace_back(0); vi.emplace_back(1); vi.emplace_back(2); faces.push_back (vi); vi.clear (); // 3 ASSERT_TRUE (mesh.addFace (faces [3]).isValid ()); EXPECT_TRUE (hasFaces (mesh, faces)); @@ -152,8 +152,8 @@ TEST (TestAddDeleteFace, NonManifold2) // 0 // // / \ // // 3 - 4 // - vi.push_back (VI (0)); vi.push_back (VI (1)); vi.push_back (VI (2)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (3)); vi.push_back (VI (4)); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(1); vi.emplace_back(2); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(3); vi.emplace_back(4); faces.push_back (vi); vi.clear (); for (const auto &face : faces) { ASSERT_TRUE (mesh.addFace (face).isValid ()); @@ -161,23 +161,23 @@ TEST (TestAddDeleteFace, NonManifold2) EXPECT_TRUE (hasFaces (mesh, faces)); // (*) Adding the next two faces would destroy the connectivity around vertex 0. E.g. a VertexAroundVertexCirculator would not be able to access all the vertices (1, 2, 3, 4) anymore. - vi.push_back (VI (3)); vi.push_back (VI (0)); vi.push_back (VI (4)); + vi.emplace_back(3); vi.emplace_back(0); vi.emplace_back(4); EXPECT_FALSE (mesh.addFace (vi).isValid ()); vi.clear (); - vi.push_back (VI (1)); vi.push_back (VI (0)); vi.push_back (VI (2)); + vi.emplace_back(1); vi.emplace_back(0); vi.emplace_back(2); EXPECT_FALSE (mesh.addFace (vi).isValid ()); vi.clear (); { // Check if the whole boundary is reached. VertexIndices boundary_expected; - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (1)); - boundary_expected.push_back (VI (2)); - boundary_expected.push_back (VI (3)); - boundary_expected.push_back (VI (4)); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(1); + boundary_expected.emplace_back(2); + boundary_expected.emplace_back(3); + boundary_expected.emplace_back(4); VertexIndices boundary_vertices = getBoundaryVertices (mesh, VI (2)); std::sort (boundary_vertices.begin (), boundary_vertices.end ()); @@ -190,35 +190,35 @@ TEST (TestAddDeleteFace, NonManifold2) // 3 - 0 - 6 // // \ / \ / // // 4 5 // - vi.push_back (VI (0)); vi.push_back (VI (5)); vi.push_back (VI (6)); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(5); vi.emplace_back(6); faces.push_back (vi); vi.clear (); EXPECT_TRUE (mesh.addFace (faces [2]).isValid ()); EXPECT_TRUE (hasFaces (mesh, faces)); // Same as (*) - vi.push_back (VI (1)); vi.push_back (VI (0)); vi.push_back (VI (2)); + vi.emplace_back(1); vi.emplace_back(0); vi.emplace_back(2); EXPECT_FALSE (mesh.addFace (vi).isValid ()); vi.clear (); - vi.push_back (VI (3)); vi.push_back (VI (0)); vi.push_back (VI (4)); + vi.emplace_back(3); vi.emplace_back(0); vi.emplace_back(4); EXPECT_FALSE (mesh.addFace (vi).isValid ()); vi.clear (); - vi.push_back (VI (5)); vi.push_back (VI (0)); vi.push_back (VI (6)); + vi.emplace_back(5); vi.emplace_back(0); vi.emplace_back(6); EXPECT_FALSE (mesh.addFace (vi).isValid ()); vi.clear (); { // Check if the whole boundary is reached. VertexIndices boundary_expected; - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (1)); - boundary_expected.push_back (VI (2)); - boundary_expected.push_back (VI (3)); - boundary_expected.push_back (VI (4)); - boundary_expected.push_back (VI (5)); - boundary_expected.push_back (VI (6)); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(1); + boundary_expected.emplace_back(2); + boundary_expected.emplace_back(3); + boundary_expected.emplace_back(4); + boundary_expected.emplace_back(5); + boundary_expected.emplace_back(6); VertexIndices boundary_vertices = getBoundaryVertices (mesh, VI (2)); std::sort (boundary_vertices.begin (), boundary_vertices.end ()); @@ -235,42 +235,42 @@ TEST (TestAddDeleteFace, NonManifold2) // | / | \ // // |/ | \ // // 4 5---6 // - vi.push_back (VI (0)); vi.push_back (VI (7)); vi.push_back (VI (8)); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(7); vi.emplace_back(8); faces.push_back (vi); vi.clear (); EXPECT_TRUE (mesh.addFace (faces [3]).isValid ()); EXPECT_TRUE (hasFaces (mesh, faces)); // Same as (*) - vi.push_back (VI (1)); vi.push_back (VI (0)); vi.push_back (VI (2)); + vi.emplace_back(1); vi.emplace_back(0); vi.emplace_back(2); EXPECT_FALSE (mesh.addFace (vi).isValid ()); vi.clear (); - vi.push_back (VI (3)); vi.push_back (VI (0)); vi.push_back (VI (4)); + vi.emplace_back(3); vi.emplace_back(0); vi.emplace_back(4); EXPECT_FALSE (mesh.addFace (vi).isValid ()); vi.clear (); - vi.push_back (VI (5)); vi.push_back (VI (0)); vi.push_back (VI (6)); + vi.emplace_back(5); vi.emplace_back(0); vi.emplace_back(6); EXPECT_FALSE (mesh.addFace (vi).isValid ()); vi.clear (); - vi.push_back (VI (7)); vi.push_back (VI (0)); vi.push_back (VI (8)); + vi.emplace_back(7); vi.emplace_back(0); vi.emplace_back(8); EXPECT_FALSE (mesh.addFace (vi).isValid ()); vi.clear (); // Check if the whole boundary is reached. { VertexIndices boundary_expected; - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (1)); - boundary_expected.push_back (VI (2)); - boundary_expected.push_back (VI (3)); - boundary_expected.push_back (VI (4)); - boundary_expected.push_back (VI (5)); - boundary_expected.push_back (VI (6)); - boundary_expected.push_back (VI (7)); - boundary_expected.push_back (VI (8)); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(1); + boundary_expected.emplace_back(2); + boundary_expected.emplace_back(3); + boundary_expected.emplace_back(4); + boundary_expected.emplace_back(5); + boundary_expected.emplace_back(6); + boundary_expected.emplace_back(7); + boundary_expected.emplace_back(8); VertexIndices boundary_vertices = getBoundaryVertices (mesh, VI (2)); std::sort (boundary_vertices.begin (), boundary_vertices.end ()); @@ -287,10 +287,10 @@ TEST (TestAddDeleteFace, NonManifold2) // | /4|2\ | // // |/ | \| // // 4---5---6 // - vi.push_back (VI (0)); vi.push_back (VI (4)); vi.push_back (VI (5)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (8)); vi.push_back (VI (1)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (2)); vi.push_back (VI (3)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (6)); vi.push_back (VI (7)); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(4); vi.emplace_back(5); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(8); vi.emplace_back(1); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(2); vi.emplace_back(3); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(6); vi.emplace_back(7); faces.push_back (vi); vi.clear (); for (std::size_t i = 4; i < faces.size (); ++i) { EXPECT_TRUE (mesh.addFace (faces [i]).isValid ()); @@ -300,7 +300,7 @@ TEST (TestAddDeleteFace, NonManifold2) VertexIndices boundary_expected; for (unsigned int i=8; i>0; --i) { - boundary_expected.push_back (VI (i)); + boundary_expected.emplace_back(i); } VertexIndices boundary_vertices = getBoundaryVertices (mesh, VI (1)); EXPECT_EQ (boundary_expected, boundary_vertices); @@ -334,7 +334,7 @@ TEST (TestAddDeleteFace, NonManifold2) TEST (TestAddDeleteFace, Manifold1) { using Mesh = ManifoldTriangleMesh; - using VI = VertexIndex; + Mesh mesh; for (unsigned int i=0; i<7; ++i) mesh.addVertex (i); @@ -346,12 +346,12 @@ TEST (TestAddDeleteFace, Manifold1) std::vector faces; std::vector > expected; VertexIndices vi; - vi.push_back (VI (0)); vi.push_back (VI (1)); vi.push_back (VI (2)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (2)); vi.push_back (VI (3)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (3)); vi.push_back (VI (4)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (4)); vi.push_back (VI (5)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (5)); vi.push_back (VI (6)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (6)); vi.push_back (VI (1)); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(1); vi.emplace_back(2); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(2); vi.emplace_back(3); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(3); vi.emplace_back(4); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(4); vi.emplace_back(5); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(5); vi.emplace_back(6); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(6); vi.emplace_back(1); faces.push_back (vi); vi.clear (); for (std::size_t i = 0; i < faces.size (); ++i) { @@ -386,11 +386,11 @@ TEST (TestAddDeleteFace, Manifold1) mesh.clear (); expected.clear (); for (unsigned int i=0; i<11; ++i) mesh.addVertex (i); - vi.push_back (VI ( 3)); vi.push_back (VI (7)); vi.push_back (VI (4)); faces.push_back (vi); vi.clear (); - vi.push_back (VI ( 3)); vi.push_back (VI (2)); vi.push_back (VI (8)); faces.push_back (vi); vi.clear (); - vi.push_back (VI ( 8)); vi.push_back (VI (2)); vi.push_back (VI (9)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (10)); vi.push_back (VI (9)); vi.push_back (VI (2)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (10)); vi.push_back (VI (2)); vi.push_back (VI (1)); faces.push_back (vi); vi.clear (); + vi.emplace_back( 3); vi.emplace_back(7); vi.emplace_back(4); faces.push_back (vi); vi.clear (); + vi.emplace_back( 3); vi.emplace_back(2); vi.emplace_back(8); faces.push_back (vi); vi.clear (); + vi.emplace_back( 8); vi.emplace_back(2); vi.emplace_back(9); faces.push_back (vi); vi.clear (); + vi.emplace_back(10); vi.emplace_back(9); vi.emplace_back(2); faces.push_back (vi); vi.clear (); + vi.emplace_back(10); vi.emplace_back(2); vi.emplace_back(1); faces.push_back (vi); vi.clear (); for (std::size_t i = 0; i < faces.size (); ++i) { ASSERT_TRUE (mesh.addFace (faces [i]).isValid ()) << "Face " << i; @@ -442,9 +442,9 @@ TEST (TestAddDeleteFace, Manifold2) // 2 // std::vector faces; VertexIndices vi; - vi.push_back (VI (0)); vi.push_back (VI (1)); vi.push_back (VI (2)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (2)); vi.push_back (VI (3)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (3)); vi.push_back (VI (1)); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(1); vi.emplace_back(2); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(2); vi.emplace_back(3); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(3); vi.emplace_back(1); faces.push_back (vi); vi.clear (); // Try all possible combinations of adding the faces and deleting a vertex. // NOTE: Some cases are redundant. @@ -511,12 +511,12 @@ TEST (TestDelete, VertexAndEdge) std::vector faces; std::vector > expected; VertexIndices vi; - vi.push_back (VI (0)); vi.push_back (VI (1)); vi.push_back (VI (2)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (2)); vi.push_back (VI (3)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (3)); vi.push_back (VI (4)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (4)); vi.push_back (VI (5)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (5)); vi.push_back (VI (6)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (6)); vi.push_back (VI (1)); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(1); vi.emplace_back(2); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(2); vi.emplace_back(3); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(3); vi.emplace_back(4); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(4); vi.emplace_back(5); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(5); vi.emplace_back(6); faces.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(6); vi.emplace_back(1); faces.push_back (vi); vi.clear (); for (std::size_t i = 0; i < faces.size (); ++i) { @@ -581,9 +581,9 @@ TEST (TestMesh, IsBoundaryIsManifold) using VI = VertexIndex; VertexIndices vi; std::vector faces; - vi.push_back (VI (0)); vi.push_back (VI (3)); vi.push_back (VI (1)); faces.push_back (vi); vi.clear (); // 0 - vi.push_back (VI (2)); vi.push_back (VI (1)); vi.push_back (VI (4)); faces.push_back (vi); vi.clear (); // 1 - vi.push_back (VI (0)); vi.push_back (VI (2)); vi.push_back (VI (5)); faces.push_back (vi); vi.clear (); // 2 + vi.emplace_back(0); vi.emplace_back(3); vi.emplace_back(1); faces.push_back (vi); vi.clear (); // 0 + vi.emplace_back(2); vi.emplace_back(1); vi.emplace_back(4); faces.push_back (vi); vi.clear (); // 1 + vi.emplace_back(0); vi.emplace_back(2); vi.emplace_back(5); faces.push_back (vi); vi.clear (); // 2 for (const auto &face : faces) { ASSERT_TRUE (mesh.addFace (face).isValid ()); @@ -592,12 +592,12 @@ TEST (TestMesh, IsBoundaryIsManifold) // Check if the whole boundary is reached. VertexIndices boundary_expected; - boundary_expected.push_back (VI (0)); - boundary_expected.push_back (VI (5)); - boundary_expected.push_back (VI (2)); - boundary_expected.push_back (VI (4)); - boundary_expected.push_back (VI (1)); - boundary_expected.push_back (VI (3)); + boundary_expected.emplace_back(0); + boundary_expected.emplace_back(5); + boundary_expected.emplace_back(2); + boundary_expected.emplace_back(4); + boundary_expected.emplace_back(1); + boundary_expected.emplace_back(3); VertexIndices boundary_vertices = getBoundaryVertices (mesh, VI (3)); EXPECT_EQ (boundary_expected, boundary_vertices); @@ -615,7 +615,7 @@ TEST (TestMesh, IsBoundaryIsManifold) } // Make manifold - vi.push_back (VI (0)); vi.push_back (VI (1)); vi.push_back (VI (2)); faces.push_back (vi); vi.clear (); // 3 + vi.emplace_back(0); vi.emplace_back(1); vi.emplace_back(2); faces.push_back (vi); vi.clear (); // 3 ASSERT_TRUE (mesh.addFace (faces [3]).isValid ()); EXPECT_TRUE (hasFaces (mesh, faces)); diff --git a/test/geometry/test_mesh_circulators.cpp b/test/geometry/test_mesh_circulators.cpp index b198c6dcb08..35b44035e68 100644 --- a/test/geometry/test_mesh_circulators.cpp +++ b/test/geometry/test_mesh_circulators.cpp @@ -90,21 +90,21 @@ class TestMeshCirculators : public ::testing::Test for (int i=0; i<7; ++i) mesh_.addVertex (); VertexIndices vi; - using VI = VertexIndex; - vi.push_back (VI (0)); vi.push_back (VI (1)); vi.push_back (VI (2)); faces_.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (2)); vi.push_back (VI (3)); faces_.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (3)); vi.push_back (VI (4)); faces_.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (4)); vi.push_back (VI (5)); faces_.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (5)); vi.push_back (VI (6)); faces_.push_back (vi); vi.clear (); - vi.push_back (VI (0)); vi.push_back (VI (6)); vi.push_back (VI (1)); faces_.push_back (vi); vi.clear (); + + vi.emplace_back(0); vi.emplace_back(1); vi.emplace_back(2); faces_.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(2); vi.emplace_back(3); faces_.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(3); vi.emplace_back(4); faces_.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(4); vi.emplace_back(5); faces_.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(5); vi.emplace_back(6); faces_.push_back (vi); vi.clear (); + vi.emplace_back(0); vi.emplace_back(6); vi.emplace_back(1); faces_.push_back (vi); vi.clear (); for (std::size_t i=0; i (mesh_.sizeFaces ()); ++i) { expected.clear (); - expected.push_back (FaceIndex (i==(n-1) ? 0 : (i+1))); - expected.push_back (FaceIndex (i== 0 ? (n-1) : (i-1))); - expected.push_back (FaceIndex ()); + expected.emplace_back(i==(n-1) ? 0 : (i+1)); + expected.emplace_back(i== 0 ? (n-1) : (i-1)); + expected.emplace_back(); FAFC circ = mesh_.getFaceAroundFaceCirculator (FaceIndex (i)); const FAFC circ_end = circ; @@ -525,9 +525,9 @@ TEST_F (TestMeshCirculators, FaceAroundFaceDecrement) for (int i = 0; i < static_cast (mesh_.sizeFaces ()); ++i) { expected.clear (); - expected.push_back (FaceIndex (i== 0 ? (n-1) : (i-1))); - expected.push_back (FaceIndex (i==(n-1) ? 0 : (i+1))); - expected.push_back (FaceIndex ()); + expected.emplace_back(i== 0 ? (n-1) : (i-1)); + expected.emplace_back(i==(n-1) ? 0 : (i+1)); + expected.emplace_back(); FAFC circ = mesh_.getFaceAroundFaceCirculator (FaceIndex (i)); const FAFC circ_end = circ; diff --git a/test/geometry/test_mesh_data.cpp b/test/geometry/test_mesh_data.cpp index 6bd229ee792..be11f9b9ed9 100644 --- a/test/geometry/test_mesh_data.cpp +++ b/test/geometry/test_mesh_data.cpp @@ -123,9 +123,9 @@ TEST (TestMesh, MeshData) // \ / \ / // // 0 - 1 // VertexIndices vi_0, vi_1, vi_2; - vi_0.push_back (VertexIndex (0)); vi_0.push_back (VertexIndex (1)); vi_0.push_back (VertexIndex (2)); - vi_1.push_back (VertexIndex (0)); vi_1.push_back (VertexIndex (2)); vi_1.push_back (VertexIndex (3)); - vi_2.push_back (VertexIndex (4)); vi_2.push_back (VertexIndex (2)); vi_2.push_back (VertexIndex (1)); + vi_0.emplace_back(0); vi_0.emplace_back(1); vi_0.emplace_back(2); + vi_1.emplace_back(0); vi_1.emplace_back(2); vi_1.emplace_back(3); + vi_2.emplace_back(4); vi_2.emplace_back(2); vi_2.emplace_back(1); // Mesh data. int vd_0 (10), vd_1 (11), vd_2 (12), vd_3 (13), vd_4 (14); diff --git a/test/geometry/test_polygon_mesh.cpp b/test/geometry/test_polygon_mesh.cpp index 41f9e73a3b6..07871763b82 100644 --- a/test/geometry/test_polygon_mesh.cpp +++ b/test/geometry/test_polygon_mesh.cpp @@ -132,7 +132,7 @@ TYPED_TEST (TestPolygonMesh, CorrectNumberOfVertices) VertexIndices vi; for (unsigned int i=0; i faces; VertexIndices vi; - vi.push_back (VertexIndex (0)); - vi.push_back (VertexIndex (1)); - vi.push_back (VertexIndex (2)); + vi.emplace_back(0); + vi.emplace_back(1); + vi.emplace_back(2); faces.push_back (vi); vi.clear (); - vi.push_back (VertexIndex (0)); - vi.push_back (VertexIndex (2)); - vi.push_back (VertexIndex (3)); - vi.push_back (VertexIndex (4)); + vi.emplace_back(0); + vi.emplace_back(2); + vi.emplace_back(3); + vi.emplace_back(4); faces.push_back (vi); vi.clear (); - vi.push_back (VertexIndex (0)); - vi.push_back (VertexIndex (4)); - vi.push_back (VertexIndex (5)); - vi.push_back (VertexIndex (6)); - vi.push_back (VertexIndex (1)); + vi.emplace_back(0); + vi.emplace_back(4); + vi.emplace_back(5); + vi.emplace_back(6); + vi.emplace_back(1); faces.push_back (vi); vi.clear (); diff --git a/test/geometry/test_quad_mesh.cpp b/test/geometry/test_quad_mesh.cpp index 3bafedb1827..f138aa93bc2 100644 --- a/test/geometry/test_quad_mesh.cpp +++ b/test/geometry/test_quad_mesh.cpp @@ -104,7 +104,7 @@ TYPED_TEST (TestQuadMesh, CorrectNumberOfVertices) VertexIndices vi; for (unsigned int i=0; i faces; VertexIndices vi; - vi.push_back (VI ( 0)); vi.push_back (VI ( 4)); vi.push_back (VI ( 5)); vi.push_back (VI ( 1)); faces.push_back (vi); vi.clear (); - vi.push_back (VI ( 1)); vi.push_back (VI ( 5)); vi.push_back (VI ( 6)); vi.push_back (VI ( 2)); faces.push_back (vi); vi.clear (); - vi.push_back (VI ( 2)); vi.push_back (VI ( 6)); vi.push_back (VI ( 7)); vi.push_back (VI ( 3)); faces.push_back (vi); vi.clear (); - vi.push_back (VI ( 4)); vi.push_back (VI ( 8)); vi.push_back (VI ( 9)); vi.push_back (VI ( 5)); faces.push_back (vi); vi.clear (); - vi.push_back (VI ( 5)); vi.push_back (VI ( 9)); vi.push_back (VI (10)); vi.push_back (VI ( 6)); faces.push_back (vi); vi.clear (); - vi.push_back (VI ( 6)); vi.push_back (VI (10)); vi.push_back (VI (11)); vi.push_back (VI ( 7)); faces.push_back (vi); vi.clear (); - vi.push_back (VI ( 8)); vi.push_back (VI (12)); vi.push_back (VI (13)); vi.push_back (VI ( 9)); faces.push_back (vi); vi.clear (); - vi.push_back (VI ( 9)); vi.push_back (VI (13)); vi.push_back (VI (14)); vi.push_back (VI (10)); faces.push_back (vi); vi.clear (); - vi.push_back (VI (10)); vi.push_back (VI (14)); vi.push_back (VI (15)); vi.push_back (VI (11)); faces.push_back (vi); vi.clear (); + vi.emplace_back( 0); vi.emplace_back( 4); vi.emplace_back( 5); vi.emplace_back( 1); faces.push_back (vi); vi.clear (); + vi.emplace_back( 1); vi.emplace_back( 5); vi.emplace_back( 6); vi.emplace_back( 2); faces.push_back (vi); vi.clear (); + vi.emplace_back( 2); vi.emplace_back( 6); vi.emplace_back( 7); vi.emplace_back( 3); faces.push_back (vi); vi.clear (); + vi.emplace_back( 4); vi.emplace_back( 8); vi.emplace_back( 9); vi.emplace_back( 5); faces.push_back (vi); vi.clear (); + vi.emplace_back( 5); vi.emplace_back( 9); vi.emplace_back(10); vi.emplace_back( 6); faces.push_back (vi); vi.clear (); + vi.emplace_back( 6); vi.emplace_back(10); vi.emplace_back(11); vi.emplace_back( 7); faces.push_back (vi); vi.clear (); + vi.emplace_back( 8); vi.emplace_back(12); vi.emplace_back(13); vi.emplace_back( 9); faces.push_back (vi); vi.clear (); + vi.emplace_back( 9); vi.emplace_back(13); vi.emplace_back(14); vi.emplace_back(10); faces.push_back (vi); vi.clear (); + vi.emplace_back(10); vi.emplace_back(14); vi.emplace_back(15); vi.emplace_back(11); faces.push_back (vi); vi.clear (); ASSERT_EQ (order_vec.size (), non_manifold.size ()); ASSERT_EQ (9, faces.size ()); diff --git a/test/geometry/test_triangle_mesh.cpp b/test/geometry/test_triangle_mesh.cpp index 3c1d8d371a7..857df978f5c 100644 --- a/test/geometry/test_triangle_mesh.cpp +++ b/test/geometry/test_triangle_mesh.cpp @@ -104,7 +104,7 @@ TYPED_TEST (TestTriangleMesh, CorrectNumberOfVertices) VertexIndices vi; for (unsigned int i=0; i(rand () % 1024), static_cast(rand () % 1024), static_cast(rand () % 1024))); + some_points.emplace_back(static_cast(rand () % 1024), static_cast(rand () % 1024), static_cast(rand () % 1024)); //(Case 1) diff --git a/test/registration/test_registration_api.cpp b/test/registration/test_registration_api.cpp index 29c5c7e6d8b..ab3fec26193 100644 --- a/test/registration/test_registration_api.cpp +++ b/test/registration/test_registration_api.cpp @@ -401,7 +401,7 @@ TEST (PCL, TransformationEstimationSVD) // Check if the estimation with correspondences gives the same results Eigen::Matrix4f T_SVD_2; pcl::Correspondences corr; corr.reserve (source->size ()); - for (std::size_t i=0; isize (); ++i) corr.push_back (pcl::Correspondence (i, i, 0.f)); + for (std::size_t i=0; isize (); ++i) corr.emplace_back(i, i, 0.f); trans_est_svd.estimateRigidTransformation(*source, *target, corr, T_SVD_2); const Eigen::Quaternionf R_SVD_2 (T_SVD_2.topLeftCorner <3, 3> ()); @@ -444,7 +444,7 @@ TEST (PCL, TransformationEstimationDualQuaternion) // Check if the estimation with correspondences gives the same results Eigen::Matrix4f T_DQ_2; pcl::Correspondences corr; corr.reserve (source->size ()); - for (std::size_t i=0; isize (); ++i) corr.push_back (pcl::Correspondence (i, i, 0.f)); + for (std::size_t i=0; isize (); ++i) corr.emplace_back(i, i, 0.f); trans_est_dual_quaternion.estimateRigidTransformation(*source, *target, corr, T_DQ_2); const Eigen::Quaternionf R_DQ_2 (T_DQ_2.topLeftCorner <3, 3> ()); @@ -540,7 +540,7 @@ TEST (PCL, TransformationEstimationLM) pcl::Correspondences corr; corr.reserve (source->size ()); for (std::size_t i = 0; i < source->size (); ++i) - corr.push_back (pcl::Correspondence (i, i, 0.f)); + corr.emplace_back(i, i, 0.f); trans_est_lm_float.estimateRigidTransformation (*source, *target, corr, T_LM_2_float); const Eigen::Quaternionf R_LM_2_float (T_LM_2_float.topLeftCorner <3, 3> ()); @@ -578,7 +578,7 @@ TEST (PCL, TransformationEstimationLM) corr.clear (); corr.reserve (source->size ()); for (std::size_t i = 0; i < source->size (); ++i) - corr.push_back (pcl::Correspondence (i, i, 0.f)); + corr.emplace_back(i, i, 0.f); trans_est_lm_double.estimateRigidTransformation (*source, *target, corr, T_LM_2_double); const Eigen::Quaterniond R_LM_2_double (T_LM_2_double.topLeftCorner <3, 3> ()); diff --git a/tools/elch.cpp b/tools/elch.cpp index e8e721955ee..071f8ccbcfa 100644 --- a/tools/elch.cpp +++ b/tools/elch.cpp @@ -126,7 +126,7 @@ main (int argc, char **argv) { CloudPtr pc (new Cloud); pcl::io::loadPCDFile (argv[pcd_indices[i]], *pc); - clouds.push_back (CloudPair (argv[pcd_indices[i]], pc)); + clouds.emplace_back(argv[pcd_indices[i]], pc); std::cout << "loading file: " << argv[pcd_indices[i]] << " size: " << pc->size () << std::endl; elch.addPointCloud (clouds[i].second); } diff --git a/tools/lum.cpp b/tools/lum.cpp index e4f80f22811..3930e189bd8 100644 --- a/tools/lum.cpp +++ b/tools/lum.cpp @@ -85,7 +85,7 @@ main (int argc, char **argv) { CloudPtr pc (new Cloud); pcl::io::loadPCDFile (argv[pcd_indices[i]], *pc); - clouds.push_back (CloudPair (argv[pcd_indices[i]], pc)); + clouds.emplace_back(argv[pcd_indices[i]], pc); std::cout << "loading file: " << argv[pcd_indices[i]] << " size: " << pc->size () << std::endl; lum.addPointCloud (clouds[i].second); }