Skip to content

Commit

Permalink
Transform classic loops to range-based for loops in module surface (#…
Browse files Browse the repository at this point in the history
…2860)

Transform classic loops to range-based for loops in module surface

Changes are based on the result of run-clang-tidy -header-filter='.*' -checks='-*,modernize-loop-convert' -fix
  • Loading branch information
SunBlack authored and taketwo committed Mar 16, 2019
1 parent 9470590 commit 7d9f03e
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 122 deletions.
6 changes: 3 additions & 3 deletions surface/include/pcl/surface/impl/concave_hull.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,12 @@ pcl::ConcaveHull<PointInT>::performReconstruction (PointCloud &alpha_shape, std:
{
alpha_shape_sorted.points[sorted_idx] = alpha_shape.points[(*curr).first];
// check where we can go from (*curr).first
for (size_t i = 0; i < (*curr).second.size (); i++)
for (const int &i : (*curr).second)
{
if (!used[((*curr).second)[i]])
if (!used[i])
{
// we can go there
next = ((*curr).second)[i];
next = i;
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions surface/include/pcl/surface/impl/gp3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,10 +883,10 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
else
angle_so_far = 0;
}
for (std::vector<int>::iterator it = to_erase.begin(); it != to_erase.end(); it++)
for (const int &it : to_erase)
{
for (std::vector<int>::iterator iter = angleIdx.begin(); iter != angleIdx.end(); iter++)
if (*it == *iter)
if (it == *iter)
{
angleIdx.erase(iter);
break;
Expand Down
4 changes: 2 additions & 2 deletions surface/include/pcl/surface/impl/surfel_smoothing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ pcl::SurfelSmoothing<PointT, PointNT>::extractSalientFeaturesBetweenScales (Poin

bool largest = true;
bool smallest = true;
for (std::vector<int>::iterator nn_index_it = nn_indices.begin (); nn_index_it != nn_indices.end (); ++nn_index_it)
for (const int &nn_index : nn_indices)
{
if (diffs[point_i] < diffs[*nn_index_it])
if (diffs[point_i] < diffs[nn_index])
largest = false;
else
smallest = false;
Expand Down
67 changes: 28 additions & 39 deletions surface/include/pcl/surface/impl/texture_mapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ pcl::TextureMapping<PointInT>::mapTexture2Mesh (pcl::TextureMesh &tex_mesh)

// get texture coordinates of each face
std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > tex_coordinates = mapTexture2Face (facet[0], facet[1], facet[2]);
for (size_t n = 0; n < tex_coordinates.size (); ++n)
texture_map_tmp.push_back (tex_coordinates[n]);
for (const auto &tex_coordinate : tex_coordinates)
texture_map_tmp.push_back (tex_coordinate);
}// end faces

// texture materials
Expand Down Expand Up @@ -320,22 +320,18 @@ pcl::TextureMapping<PointInT>::mapMultipleTexturesToMeshUV (pcl::TextureMesh &te
std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;

// processing each face visible by this camera
PointInT pt;
size_t idx;
for (size_t i = 0; i < tex_mesh.tex_polygons[m].size (); ++i)
for (const auto &tex_polygon : tex_mesh.tex_polygons[m])
{
Eigen::Vector2f tmp_VT;
// for each point of this face
for (size_t j = 0; j < tex_mesh.tex_polygons[m][i].vertices.size (); ++j)
for (const unsigned int &vertex : tex_polygon.vertices)
{
// get point
idx = tex_mesh.tex_polygons[m][i].vertices[j];
pt = camera_transformed_cloud->points[idx];
PointInT pt = camera_transformed_cloud->points[vertex];

// compute UV coordinates for this point
getPointUVCoordinates (pt, current_cam, tmp_VT);
texture_map_tmp.push_back (tmp_VT);

}// end points
}// end faces

Expand All @@ -352,8 +348,8 @@ pcl::TextureMapping<PointInT>::mapMultipleTexturesToMeshUV (pcl::TextureMesh &te

// push on extra empty UV map (for unseen faces) so that obj writer does not crash!
std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
for (size_t i = 0; i < tex_mesh.tex_polygons[cams.size ()].size (); ++i)
for (size_t j = 0; j < tex_mesh.tex_polygons[cams.size ()][i].vertices.size (); ++j)
for (const auto &tex_polygon : tex_mesh.tex_polygons[cams.size ()])
for (size_t j = 0; j < tex_polygon.vertices.size (); ++j)
{
Eigen::Vector2f tmp_VT;
tmp_VT[0] = -1;
Expand All @@ -364,12 +360,9 @@ pcl::TextureMapping<PointInT>::mapMultipleTexturesToMeshUV (pcl::TextureMesh &te
tex_mesh.tex_coordinates.push_back (texture_map_tmp);

// push on an extra dummy material for the same reason
std::stringstream tex_name;
tex_name << "material_" << cams.size ();
tex_name >> tex_material_.tex_name;
tex_material_.tex_name = "material_" + std::to_string(cams.size());
tex_material_.tex_file = "occluded.jpg";
tex_mesh.tex_materials.push_back (tex_material_);

}

///////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -392,16 +385,16 @@ pcl::TextureMapping<PointInT>::isPointOccluded (const PointInT &pt, OctreePtr oc
octree->getIntersectedVoxelIndices(direction, -direction, indices);

int nbocc = static_cast<int> (indices.size ());
for (size_t j = 0; j < indices.size (); j++)
for (const int &index : indices)
{
// if intersected point is on the over side of the camera
if (pt.z * cloud->points[indices[j]].z < 0)
if (pt.z * cloud->points[index].z < 0)
{
nbocc--;
continue;
}

if (fabs (cloud->points[indices[j]].z - pt.z) <= distance_threshold)
if (fabs (cloud->points[index].z - pt.z) <= distance_threshold)
{
// points are very close to each-other, we do not consider the occlusion
nbocc--;
Expand Down Expand Up @@ -448,16 +441,16 @@ pcl::TextureMapping<PointInT>::removeOccludedPoints (const PointCloudPtr &input_
octree->getIntersectedVoxelIndices (direction, -direction, indices);

int nbocc = static_cast<int> (indices.size ());
for (size_t j = 0; j < indices.size (); j++)
for (const int &index : indices)
{
// if intersected point is on the over side of the camera
if (input_cloud->points[i].z * input_cloud->points[indices[j]].z < 0)
if (input_cloud->points[i].z * input_cloud->points[index].z < 0)
{
nbocc--;
continue;
}

if (fabs (input_cloud->points[indices[j]].z - input_cloud->points[i].z) <= maxDeltaZ)
if (fabs (input_cloud->points[index].z - input_cloud->points[i].z) <= maxDeltaZ)
{
// points are very close to each-other, we do not consider the occlusion
nbocc--;
Expand Down Expand Up @@ -508,9 +501,9 @@ pcl::TextureMapping<PointInT>::removeOccludedPoints (const pcl::TextureMesh &tex
std::vector<int>::iterator it;

// iterate over face's vertex
for (size_t points = 0; points < tex_mesh.tex_polygons[polygons][faces].vertices.size (); ++points)
for (const unsigned int &vertex : tex_mesh.tex_polygons[polygons][faces].vertices)
{
it = find (occluded.begin (), occluded.end (), tex_mesh.tex_polygons[polygons][faces].vertices[points]);
it = find (occluded.begin (), occluded.end (), vertex);

if (it == occluded.end ())
{
Expand Down Expand Up @@ -580,10 +573,10 @@ pcl::TextureMapping<PointInT>::sortFacesByCamera (pcl::TextureMesh &tex_mesh, pc
pcl::fromPCLPointCloud2 (tex_mesh.cloud, *original_cloud);

// for each camera
for (size_t cam = 0; cam < cameras.size (); ++cam)
for (const auto &camera : cameras)
{
// get camera pose as transform
Eigen::Affine3f cam_trans = cameras[cam].pose;
Eigen::Affine3f cam_trans = camera.pose;

// transform original cloud in camera coordinates
pcl::transformPointCloud (*original_cloud, *transformed_cloud, cam_trans.inverse ());
Expand Down Expand Up @@ -615,7 +608,7 @@ pcl::TextureMapping<PointInT>::sortFacesByCamera (pcl::TextureMesh &tex_mesh, pc
// does it land on the camera's image plane?
PointInT pt = transformed_cloud->points[tex_mesh.tex_polygons[0][faces].vertices[current_pt_indice]];
Eigen::Vector2f dummy_UV;
if (!getPointUVCoordinates (pt, cameras[cam], dummy_UV))
if (!getPointUVCoordinates (pt, camera, dummy_UV))
{
// point is not visible by the camera
faceIsVisible = false;
Expand Down Expand Up @@ -692,22 +685,22 @@ pcl::TextureMapping<PointInT>::showOcclusions (const PointCloudPtr &input_cloud,
nbocc = static_cast<int> (indices.size ());

// TODO need to clean this up and find tricks to get remove aliasaing effect on planes
for (size_t j = 0; j < indices.size (); j++)
for (const int &index : indices)
{
// if intersected point is on the over side of the camera
if (pt.z * input_cloud->points[indices[j]].z < 0)
if (pt.z * input_cloud->points[index].z < 0)
{
nbocc--;
}
else if (fabs (input_cloud->points[indices[j]].z - pt.z) <= maxDeltaZ)
else if (fabs (input_cloud->points[index].z - pt.z) <= maxDeltaZ)
{
// points are very close to each-other, we do not consider the occlusion
nbocc--;
}
else
{
zDist.push_back (fabs (input_cloud->points[indices[j]].z - pt.z));
ptDist.push_back (pcl::euclideanDistance (input_cloud->points[indices[j]], pt));
zDist.push_back (fabs (input_cloud->points[index].z - pt.z));
ptDist.push_back (pcl::euclideanDistance (input_cloud->points[index], pt));
}
}

Expand Down Expand Up @@ -879,18 +872,18 @@ pcl::TextureMapping<PointInT>::textureMeshwithMultipleCameras (pcl::TextureMesh
if (kdtree.radiusSearch (center, radius, idxNeighbors, neighborsSquaredDistance) > 0 )
{
// for each neighbor
for (size_t i = 0; i < idxNeighbors.size (); ++i)
for (const int &idxNeighbor : idxNeighbors)
{
if (std::max (camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[0]].z,
std::max (camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[1]].z,
camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[2]].z))
< camera_cloud->points[indexes_uv_to_points[idxNeighbors[i]].idx_cloud].z)
< camera_cloud->points[indexes_uv_to_points[idxNeighbor].idx_cloud].z)
{
// neighbor is farther than all the face's points. Check if it falls into the triangle
if (checkPointInsideTriangle(uv_coord1, uv_coord2, uv_coord3, projections->points[idxNeighbors[i]]))
if (checkPointInsideTriangle(uv_coord1, uv_coord2, uv_coord3, projections->points[idxNeighbor]))
{
// current neighbor is inside triangle and is closer => the corresponding face
visibility[indexes_uv_to_points[idxNeighbors[i]].idx_face] = false;
visibility[indexes_uv_to_points[idxNeighbor].idx_face] = false;
cpt_invisible++;
//TODO we could remove the projections of this face from the kd-tree cloud, but I fond it slower, and I need the point to keep ordered to querry UV coordinates later
}
Expand Down Expand Up @@ -953,10 +946,6 @@ pcl::TextureMapping<PointInT>::textureMeshwithMultipleCameras (pcl::TextureMesh
visible_faces.resize (cpt_visible_faces);
mesh.tex_polygons[current_cam].clear ();
mesh.tex_polygons[current_cam] = visible_faces;

int nb_faces = 0;
for (int i = 0; i < static_cast<int> (mesh.tex_polygons.size ()); i++)
nb_faces += static_cast<int> (mesh.tex_polygons[i].size ());
}

// we have been through all the cameras.
Expand Down
4 changes: 2 additions & 2 deletions surface/src/ear_clipping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pcl::EarClipping::performProcessing (PolygonMesh& output)
{
output.polygons.clear ();
output.cloud = input_mesh_->cloud;
for (int i = 0; i < static_cast<int> (input_mesh_->polygons.size ()); ++i)
triangulate (input_mesh_->polygons[i], output);
for (const auto &polygon : input_mesh_->polygons)
triangulate (polygon, output);
}

/////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 1 addition & 2 deletions surface/src/on_nurbs/closing_boundary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,10 @@ ClosingBoundary::optimizeBoundary (std::vector<ON_NurbsSurface> &nurbs_list, std
ON_NurbsSurface *nurbs2 = &nurbs_list[n2];

// for all points in the point list
for (size_t i = 0; i < boundary1.size (); i++)
for (const auto &p0 : boundary1)
{
double error;
Eigen::Vector3d p, tu, tv;
Eigen::Vector3d p0 = boundary1[i];
Eigen::Vector2d params1, params2;

switch (param.type)
Expand Down
4 changes: 2 additions & 2 deletions surface/src/on_nurbs/fitting_curve_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ FittingCurve2d::refine ()
for (size_t i = 0; i < elements.size () - 1; i++)
xi.push_back (elements[i] + 0.5 * (elements[i + 1] - elements[i]));

for (size_t i = 0; i < xi.size (); i++)
m_nurbs.InsertKnot (xi[i], 1);
for (const double &i : xi)
m_nurbs.InsertKnot (i, 1);
}

void
Expand Down
4 changes: 2 additions & 2 deletions surface/src/on_nurbs/fitting_curve_2d_apdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ FittingCurve2dAPDM::refine ()
for (size_t i = 0; i < elements.size () - 1; i++)
xi.push_back (elements[i] + 0.5 * (elements[i + 1] - elements[i]));

for (size_t i = 0; i < xi.size (); i++)
m_nurbs.InsertKnot (xi[i], 1);
for (const double &i : xi)
m_nurbs.InsertKnot (i, 1);
}

void
Expand Down
4 changes: 2 additions & 2 deletions surface/src/on_nurbs/fitting_curve_2d_pdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ FittingCurve2dPDM::refine ()
for (size_t i = 0; i < elements.size () - 1; i++)
xi.push_back (elements[i] + 0.5 * (elements[i + 1] - elements[i]));

for (size_t i = 0; i < xi.size (); i++)
m_nurbs.InsertKnot (xi[i], 1);
for (const double &i : xi)
m_nurbs.InsertKnot (i, 1);
}

void
Expand Down
4 changes: 2 additions & 2 deletions surface/src/on_nurbs/fitting_curve_pdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ FittingCurve::refine ()
for (size_t i = 0; i < elements.size () - 1; i++)
xi.push_back (elements[i] + 0.5 * (elements[i + 1] - elements[i]));

for (size_t i = 0; i < xi.size (); i++)
m_nurbs.InsertKnot (xi[i], 1);
for (const double &i : xi)
m_nurbs.InsertKnot (i, 1);
}

void
Expand Down
4 changes: 2 additions & 2 deletions surface/src/on_nurbs/fitting_cylinder_pdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ FittingCylinder::refine (int dim)
for (size_t i = 0; i < elements.size () - 1; i++)
xi.push_back (elements[i] + 0.5 * (elements[i + 1] - elements[i]));

for (size_t i = 0; i < xi.size (); i++)
m_nurbs.InsertKnot (dim, xi[i], 1);
for (const double &i : xi)
m_nurbs.InsertKnot (dim, i, 1);
}

void
Expand Down
4 changes: 2 additions & 2 deletions surface/src/on_nurbs/fitting_sphere_pdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ FittingSphere::initNurbsSphere (int order, NurbsDataSurface *data, Eigen::Vector

Eigen::Vector3d _min (DBL_MAX, DBL_MAX, DBL_MAX);
Eigen::Vector3d _max (-DBL_MAX, -DBL_MAX, -DBL_MAX);
for (size_t i = 0; i < data->interior.size (); i++)
for (const auto &i : data->interior)
{
Eigen::Vector3d p = data->interior[i] - mean;
Eigen::Vector3d p = i - mean;

if (p (0) < _min (0))
_min (0) = p (0);
Expand Down
20 changes: 10 additions & 10 deletions surface/src/on_nurbs/fitting_surface_im.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ FittingSurfaceIM::computeMean () const
double ds = 1.0 / double (m_indices.size ());

const pcl::PointCloud<pcl::PointXYZRGB> &cloud_ref = *m_cloud;
for (size_t idx = 0; idx < m_indices.size (); idx++)
for (const int &index : m_indices)
{
int i = m_indices[idx] % cloud_ref.width;
int j = m_indices[idx] / cloud_ref.width;
int i = index % cloud_ref.width;
int j = index / cloud_ref.width;

const pcl::PointXYZRGB &point = cloud_ref (i, j);
if (std::isnan (point.x) || std::isnan (point.y) || std::isnan (point.z))
Expand All @@ -76,10 +76,10 @@ FittingSurfaceIM::computeIndexBoundingBox (pcl::PointCloud<pcl::PointXYZRGB>::Pt
Eigen::Vector4d bb = Eigen::Vector4d (DBL_MAX, 0, DBL_MAX, 0);
const pcl::PointCloud<pcl::PointXYZRGB> &cloud_ref = *cloud;

for (size_t idx = 0; idx < indices.size (); idx++)
for (const int &index : indices)
{
int i = indices[idx] % cloud_ref.width;
int j = indices[idx] / cloud_ref.width;
int i = index % cloud_ref.width;
int j = index / cloud_ref.width;

const pcl::PointXYZRGB &point = cloud_ref (i, j);
if (std::isnan (point.x) || std::isnan (point.y) || std::isnan (point.z))
Expand Down Expand Up @@ -273,12 +273,12 @@ FittingSurfaceIM::assemble (bool inverse_mapping)

// assemble data points
const pcl::PointCloud<pcl::PointXYZRGB> &cloud_ref = *m_cloud;
for (size_t i = 0; i < m_indices.size (); i++)
for (const int &index : m_indices)
{
int px = m_indices[i] % cloud_ref.width;
int py = m_indices[i] / cloud_ref.width;
int px = index % cloud_ref.width;
int py = index / cloud_ref.width;

const pcl::PointXYZRGB &pt = cloud_ref.at (m_indices[i]);
const pcl::PointXYZRGB &pt = cloud_ref.at (index);
Eigen::Vector2i params (px, py);

if (std::isnan (pt.z) || pt.z == 0.0)
Expand Down
8 changes: 4 additions & 4 deletions surface/src/on_nurbs/fitting_surface_pdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ FittingSurface::refine (int dim)
for (size_t i = 0; i < elements.size () - 1; i++)
xi.push_back (elements[i] + 0.5 * (elements[i + 1] - elements[i]));

for (size_t i = 0; i < xi.size (); i++)
m_nurbs.InsertKnot (dim, xi[i], 1);
for (const double &i : xi)
m_nurbs.InsertKnot (dim, i, 1);

m_elementsU = getElementVector (m_nurbs, 0);
m_elementsV = getElementVector (m_nurbs, 1);
Expand All @@ -109,8 +109,8 @@ FittingSurface::refine (ON_NurbsSurface &nurbs, int dim)
for (size_t i = 0; i < elements.size () - 1; i++)
xi.push_back (elements[i] + 0.5 * (elements[i + 1] - elements[i]));

for (size_t i = 0; i < xi.size (); i++)
nurbs.InsertKnot (dim, xi[i], 1);
for (const double &i : xi)
nurbs.InsertKnot (dim, i, 1);
}

void
Expand Down
Loading

0 comments on commit 7d9f03e

Please sign in to comment.