-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std::size_t modifications for module common #3354
Conversation
84228e9
to
71496a9
Compare
Hey, thanks for taking the initiative. The bullet-list summary is quite helpful in understanding the contents of this PR. However, it would be even greater if each of these bullet points was a separate commit. Such an approach makes the review process more manageable. For example, the first change is trivial, so it's enough to quickly scroll through such commit. Item three, however, potentially affects class/struct layout, and requires a careful review. I consider this a good style to add outstanding TODO items to the PR descriptions. However, you should clearly state whether it's a TODO for future PRs, or you plan to update the present one. (In the latter case you can also mark it as "draft".) |
As I mentioned, no struct level changes. I've kept the changes to inside functions
Sure. I can manage that.
Hopefully the present one. One PR per module, starting with 'common', then 'features' and 'filters'. Then I dunno. Stress testing is the only way I have apart from reading every line of code 😅 so some things get past my grep and segfaults |
One of the purposes of the review is to verify your claim 😉
👍 |
d953cff
to
b3afaab
Compare
The issue in filters seems to be EDIT: |
571f238
to
57dfb4d
Compare
57dfb4d
to
976c005
Compare
In the case of matching point types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for splitting up the commits. For now, I stopped after reviewing the first two. Let's handle them first and then move on.
I accidentally rebased one commit (with I'm posting the diff manually for the accidentally rebased commit (apologies in advance) diff --git a/common/include/pcl/common/impl/centroid.hpp b/common/include/pcl/common/impl/centroid.hpp
index 6bf892550..1e5a76e32 100644
--- a/common/include/pcl/common/impl/centroid.hpp
+++ b/common/include/pcl/common/impl/centroid.hpp
@@ -88,7 +88,7 @@ pcl::compute3DCentroid (const pcl::PointCloud<PointT> &cloud,
// If the data is dense, we don't need to check for NaN
if (cloud.is_dense)
{
- for (const auto point: cloud)
+ for (const auto& point: cloud)
{
centroid[0] += point.x;
centroid[1] += point.y;
@@ -101,7 +101,7 @@ pcl::compute3DCentroid (const pcl::PointCloud<PointT> &cloud,
}
// NaN or Inf values could exist => check for them
unsigned cp = 0;
- for (const auto point: cloud)
+ for (const auto& point: cloud)
{
// Check if the point is invalid
if (!isFinite (point))
@@ -132,7 +132,7 @@ pcl::compute3DCentroid (const pcl::PointCloud<PointT> &cloud,
// If the data is dense, we don't need to check for NaN
if (cloud.is_dense)
{
- for (const int &index : indices)
+ for (const int& index : indices)
{
centroid[0] += cloud[index].x;
centroid[1] += cloud[index].y;
@@ -144,7 +144,7 @@ pcl::compute3DCentroid (const pcl::PointCloud<PointT> &cloud,
}
// NaN or Inf values could exist => check for them
unsigned cp = 0;
- for (const int &index : indices)
+ for (const int& index : indices)
{
// Check if the point is invalid
if (!isFinite (cloud [index]))
diff --git a/common/include/pcl/common/impl/io.hpp b/common/include/pcl/common/impl/io.hpp
index fe170ae68..9de4b9534 100644
--- a/common/include/pcl/common/impl/io.hpp
+++ b/common/include/pcl/common/impl/io.hpp
@@ -64,7 +64,7 @@ pcl::getFieldIndex (const std::string &field_name,
// Get the fields list
pcl::for_each_type<typename pcl::traits::fieldList<PointT>::type>(pcl::detail::FieldAdder<PointT>(fields));
const auto result = std::find_if(fields.begin (), fields.end (),
- [&field_name](const auto field) { return field.name == field_name; });
+ [&field_name](const auto& field) { return field.name == field_name; });
if (result == fields.end ())
return -1;
return std::distance(fields.begin (), result);
diff --git a/common/include/pcl/conversions.h b/common/include/pcl/conversions.h
index 9a4c40e3e..62f9eb6ff 100644
--- a/common/include/pcl/conversions.h
+++ b/common/include/pcl/conversions.h
@@ -314,7 +314,7 @@ namespace pcl
inline void
toPCLPointCloud2 (const pcl::PCLPointCloud2& cloud, pcl::PCLImage& msg)
{
- const auto predicate = [](const auto field) { return field.name == "rgb"; };
+ const auto predicate = [](const auto& field) { return field.name == "rgb"; };
const auto result = std::find_if(cloud.fields.cbegin (), cloud.fields.cend (), predicate);
if (result == cloud.fields.end ())
throw std::runtime_error ("No rgb field!!");
diff --git a/common/src/PCLPointCloud2.cpp b/common/src/PCLPointCloud2.cpp
index d3537a15d..85bdaa1af 100644
--- a/common/src/PCLPointCloud2.cpp
+++ b/common/src/PCLPointCloud2.cpp
@@ -152,7 +152,7 @@ pcl::PCLPointCloud2::concatenate (pcl::PCLPointCloud2 &cloud1, const pcl::PCLPoi
}
for (std::size_t cp = 0; cp < size2; ++cp)
{
- for (const auto field_data: valid_fields)
+ for (const auto& field_data: valid_fields)
{
const auto& i = field_data.idx1;
const auto& j = field_data.idx2;
|
No worries. Yes, I think I'm done with the first two. |
9a29b04
to
26ecc79
Compare
Oops, pressed the wrong button. Vim plugins for browsers should have an undo 😢 |
What's the rationale on this? |
My understanding of the standard says that the header Since we are slowly migrating away from C functions, there's no guarantee that the all stdlib will provide the optional declaration of We can declare in |
TL;DR: same reason as migrating from |
I'll check this code for use of reserve before proceeding |
b3af803
to
806b158
Compare
No changes, just a rebase to bring everything up to date (MacOS CI, conflict due to |
I accepted the changes, however now one of the tutorials in failing to build. I'm unsure if is related to this PR though. |
Yep, I think it should be a rule that when we deprecate something, we grep through the codebase and remove usage of deprecated functions from PCL itself. (This, by the way, has not been done for the previous deprecation, see #3349.) |
ffbe978
to
c92ae79
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please squash as appropriate.
Edit: and resolve conflicts
c92ae79
to
d312459
Compare
Adding std:: to missed size_t
d312459
to
5f75b3e
Compare
5f75b3e
to
e057089
Compare
PTAL |
Thanks. The new separation into commits makes sense to me, except for one case. In the "Letting the compiler auto-deduce template parameters" commit the changes to |
e057089
to
430b057
Compare
Another flaky test found:
|
Refactor raw for loop to algorithm More raw for loops converted Some ternary operators removed from point_types.hpp
430b057
to
16ebc3a
Compare
Fixed the separation issue after a mistake 😭 . PTAL |
size_t
withstd::size_t
std::size_t
for indices (in function internals) which don't affect class/struct layoutint
withstd::size_t
for dimensions and indicesauto
to hide unimportant typesThe aim is to to use
std::size_t
instead ofint
in all (most) modules and then convert the indices to PCL_INDEX_TYPE which can be set asuint16_t
orstd::size_t
or evenint
. This is first in a series of such commits