Skip to content

Commit

Permalink
Merge pull request #2843 from SunBlack/range_based_loops_visualization
Browse files Browse the repository at this point in the history
Transform classic loops to range-based for loops in module visualization
  • Loading branch information
SergioRAgostinho authored Feb 18, 2019
2 parents 73f6af1 + f62c7c0 commit a6d2aad
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 152 deletions.
20 changes: 10 additions & 10 deletions visualization/include/pcl/visualization/impl/image_viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ pcl::visualization::ImageViewer::addRectangle (
min_pt_2d.x = min_pt_2d.y = std::numeric_limits<float>::max ();
max_pt_2d.x = max_pt_2d.y = -std::numeric_limits<float>::max ();
// Search for the two extrema
for (size_t i = 0; i < pp_2d.size (); ++i)
for (const auto &point : pp_2d)
{
if (pp_2d[i].x < min_pt_2d.x) min_pt_2d.x = pp_2d[i].x;
if (pp_2d[i].y < min_pt_2d.y) min_pt_2d.y = pp_2d[i].y;
if (pp_2d[i].x > max_pt_2d.x) max_pt_2d.x = pp_2d[i].x;
if (pp_2d[i].y > max_pt_2d.y) max_pt_2d.y = pp_2d[i].y;
if (point.x < min_pt_2d.x) min_pt_2d.x = point.x;
if (point.y < min_pt_2d.y) min_pt_2d.y = point.y;
if (point.x > max_pt_2d.x) max_pt_2d.x = point.x;
if (point.y > max_pt_2d.y) max_pt_2d.y = point.y;
}
min_pt_2d.y = float (image->height) - min_pt_2d.y;
max_pt_2d.y = float (image->height) - max_pt_2d.y;
Expand Down Expand Up @@ -316,12 +316,12 @@ pcl::visualization::ImageViewer::addRectangle (
min_pt_2d.x = min_pt_2d.y = std::numeric_limits<float>::max ();
max_pt_2d.x = max_pt_2d.y = -std::numeric_limits<float>::max ();
// Search for the two extrema
for (size_t i = 0; i < pp_2d.size (); ++i)
for (const auto &point : pp_2d)
{
if (pp_2d[i].x < min_pt_2d.x) min_pt_2d.x = pp_2d[i].x;
if (pp_2d[i].y < min_pt_2d.y) min_pt_2d.y = pp_2d[i].y;
if (pp_2d[i].x > max_pt_2d.x) max_pt_2d.x = pp_2d[i].x;
if (pp_2d[i].y > max_pt_2d.y) max_pt_2d.y = pp_2d[i].y;
if (point.x < min_pt_2d.x) min_pt_2d.x = point.x;
if (point.y < min_pt_2d.y) min_pt_2d.y = point.y;
if (point.x > max_pt_2d.x) max_pt_2d.x = point.x;
if (point.y > max_pt_2d.y) max_pt_2d.y = point.y;
}
min_pt_2d.y = float (image->height) - min_pt_2d.y;
max_pt_2d.y = float (image->height) - max_pt_2d.y;
Expand Down
18 changes: 9 additions & 9 deletions visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,10 +1122,10 @@ pcl::visualization::PCLVisualizer::addCorrespondences (
corrs.resize (correspondences.size ());

size_t index = 0;
for (pcl::Correspondences::iterator corrs_it (corrs.begin ()); corrs_it != corrs.end (); ++corrs_it)
for (auto &corr : corrs)
{
corrs_it->index_query = index;
corrs_it->index_match = correspondences[index];
corr.index_query = index;
corr.index_match = correspondences[index];
index++;
}

Expand Down Expand Up @@ -1691,9 +1691,9 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (

// Get the maximum size of a polygon
int max_size_of_polygon = -1;
for (size_t i = 0; i < vertices.size (); ++i)
if (max_size_of_polygon < static_cast<int> (vertices[i].vertices.size ()))
max_size_of_polygon = static_cast<int> (vertices[i].vertices.size ());
for (const auto &vertex : vertices)
if (max_size_of_polygon < static_cast<int> (vertex.vertices.size ()))
max_size_of_polygon = static_cast<int> (vertex.vertices.size ());

if (vertices.size () > 1)
{
Expand Down Expand Up @@ -1870,9 +1870,9 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh (

// Get the maximum size of a polygon
int max_size_of_polygon = -1;
for (size_t i = 0; i < verts.size (); ++i)
if (max_size_of_polygon < static_cast<int> (verts[i].vertices.size ()))
max_size_of_polygon = static_cast<int> (verts[i].vertices.size ());
for (const auto &vertex : verts)
if (max_size_of_polygon < static_cast<int> (vertex.vertices.size ()))
max_size_of_polygon = static_cast<int> (vertex.vertices.size ());

// Update the cells
cells = vtkSmartPointer<vtkCellArray>::New ();
Expand Down
8 changes: 4 additions & 4 deletions visualization/src/common/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ pcl::visualization::getCorrespondingPointCloud (vtkPolyData *src,
std::vector<int> nn_indices (1);
std::vector<float> nn_dists (1);
// For each point on screen, find its correspondent in the target
for (size_t i = 0; i < cloud.points.size (); ++i)
for (const auto &point : cloud.points)
{
kdtree.nearestKSearch (cloud.points[i], 1, nn_indices, nn_dists);
kdtree.nearestKSearch (point, 1, nn_indices, nn_dists);
indices.push_back (nn_indices[0]);
}
// Sort and remove duplicate indices
Expand Down Expand Up @@ -106,9 +106,9 @@ pcl::visualization::savePointData (vtkPolyData* data, const std::string &out_fil

// Attempting to load all Point Cloud data input files (using the actor name)...
int i = 1;
for (auto it = actors->cbegin (); it != actors->cend (); ++it)
for (const auto &actor : *actors)
{
std::string file_name = (*it).first;
std::string file_name = actor.first;

// Is there a ".pcd" in the name? If no, then do not attempt to load this actor
std::string::size_type position;
Expand Down
44 changes: 22 additions & 22 deletions visualization/src/histogram_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ pcl::visualization::PCLHistogramVisualizer::PCLHistogramVisualizer () :
void
pcl::visualization::PCLHistogramVisualizer::spinOnce (int time)
{
for (RenWinInteractMap::iterator am_it = wins_.begin (); am_it != wins_.end (); ++am_it)
for (auto &win : wins_)
{
DO_EVERY(1.0/(*am_it).second.interactor_->GetDesiredUpdateRate (),
(*am_it).second.interactor_->Render ();
exit_main_loop_timer_callback_->right_timer_id = (*am_it).second.interactor_->CreateRepeatingTimer (time);
DO_EVERY(1.0/win.second.interactor_->GetDesiredUpdateRate (),
win.second.interactor_->Render ();
exit_main_loop_timer_callback_->right_timer_id = win.second.interactor_->CreateRepeatingTimer (time);

// Set the correct interactor for callbacks
exit_main_loop_timer_callback_->interact = (*am_it).second.interactor_;
(*am_it).second.interactor_->Start ();
(*am_it).second.interactor_->DestroyTimer (exit_main_loop_timer_callback_->right_timer_id);
exit_main_loop_timer_callback_->interact = win.second.interactor_;
win.second.interactor_->Start ();
win.second.interactor_->DestroyTimer (exit_main_loop_timer_callback_->right_timer_id);
);
}
}
Expand Down Expand Up @@ -119,21 +119,21 @@ pcl::visualization::PCLHistogramVisualizer::setBackgroundColor (const double &r,
++i;
}
*/
for (RenWinInteractMap::iterator am_it = wins_.begin (); am_it != wins_.end (); ++am_it)
for (auto &win : wins_)
{
(*am_it).second.ren_->SetBackground (r, g, b);
(*am_it).second.ren_->Render ();
win.second.ren_->SetBackground (r, g, b);
win.second.ren_->Render ();
}
}

//////////////////////////////////////////////////////////////////////////////////////////////
void
pcl::visualization::PCLHistogramVisualizer::setGlobalYRange (float minp, float maxp)
{
for (RenWinInteractMap::iterator am_it = wins_.begin (); am_it != wins_.end (); ++am_it)
for (auto &win : wins_)
{
(*am_it).second.xy_plot_->SetYRange (minp, maxp);
(*am_it).second.xy_plot_->Modified ();
win.second.xy_plot_->SetYRange (minp, maxp);
win.second.xy_plot_->Modified ();
}
}

Expand All @@ -142,15 +142,15 @@ void
pcl::visualization::PCLHistogramVisualizer::updateWindowPositions ()
{
int posx = 0, posy = 0;
for (RenWinInteractMap::iterator am_it = wins_.begin (); am_it != wins_.end (); ++am_it)
for (auto &win : wins_)
{
// Get the screen size
int *scr_size = (*am_it).second.win_->GetScreenSize ();
int *win_size = (*am_it).second.win_->GetActualSize ();
int *scr_size = win.second.win_->GetScreenSize ();
int *win_size = win.second.win_->GetActualSize ();

// Update the position of the current window
(*am_it).second.win_->SetPosition (posx, posy);
(*am_it).second.win_->Modified ();
win.second.win_->SetPosition (posx, posy);
win.second.win_->Modified ();
// If there is space on Y, go on Y first
if ((posy + win_size[1]) <= scr_size[1])
posy += win_size[1];
Expand Down Expand Up @@ -353,8 +353,8 @@ pcl::visualization::PCLHistogramVisualizer::addFeatureHistogram (

// Compute the total size of the fields
unsigned int fsize = 0;
for (size_t i = 0; i < cloud.fields.size (); ++i)
fsize += cloud.fields[i].count * pcl::getFieldSize (cloud.fields[i].datatype);
for (const auto &field : cloud.fields)
fsize += field.count * pcl::getFieldSize (field.datatype);

// Parse the cloud data and store it in the array
double xy[2];
Expand Down Expand Up @@ -448,8 +448,8 @@ pcl::visualization::PCLHistogramVisualizer::updateFeatureHistogram (

// Compute the total size of the fields
unsigned int fsize = 0;
for (size_t i = 0; i < cloud.fields.size (); ++i)
fsize += cloud.fields[i].count * pcl::getFieldSize (cloud.fields[i].datatype);
for (const auto &field : cloud.fields)
fsize += field.count * pcl::getFieldSize (field.datatype);

// Parse the cloud data and store it in the array
double xy[2];
Expand Down
16 changes: 8 additions & 8 deletions visualization/src/image_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ pcl::visualization::ImageViewer::spinOnce (int time, bool force_redraw)
interactor_->Start ();
interactor_->DestroyTimer (exit_main_loop_timer_callback_->right_timer_id);
);
for(size_t i = 0; i < image_data_.size(); i++)
delete [] image_data_[i];
for(auto &i : image_data_)
delete [] i;
image_data_.clear ();
}

Expand Down Expand Up @@ -871,8 +871,8 @@ void
pcl::visualization::ImageViewer::render ()
{
win_->Render ();
for(size_t i = 0; i < image_data_.size(); i++)
delete [] image_data_[i];
for(auto &i : image_data_)
delete [] i;
image_data_.clear ();
}

Expand All @@ -883,9 +883,9 @@ pcl::visualization::ImageViewer::convertIntensityCloudToUChar (
boost::shared_array<unsigned char> data)
{
int j = 0;
for (size_t i = 0; i < cloud.points.size (); ++i)
for (const auto &point : cloud.points)
{
data[j++] = static_cast <unsigned char> (cloud.points[i].intensity * 255);
data[j++] = static_cast <unsigned char> (point.intensity * 255);
}
}

Expand All @@ -896,8 +896,8 @@ pcl::visualization::ImageViewer::convertIntensityCloud8uToUChar (
boost::shared_array<unsigned char> data)
{
int j = 0;
for (size_t i = 0; i < cloud.points.size (); ++i)
data[j++] = static_cast<unsigned char> (cloud.points[i].intensity);
for (const auto &point : cloud.points)
data[j++] = static_cast<unsigned char> (point.intensity);
}

//////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit a6d2aad

Please sign in to comment.