Skip to content
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

Correspondence estimation with different point types #4901

Merged
merged 2 commits into from
Jun 11, 2023

Conversation

al-tu
Copy link
Contributor

@al-tu al-tu commented Aug 17, 2021

isSamePointType function

  1. is constexpr now
  2. uses type traits instead of typeid comparison
    correspondence estimation functions forward point selection to helper template functions specializations instead of if blocks with runtime type checks

@@ -319,10 +319,10 @@ namespace pcl
pcl::PCLPointCloud2 &cloud_out);

/** \brief Check if two given point types are the same or not. */
template <typename Point1T, typename Point2T> inline bool
template <typename Point1T, typename Point2T> inline constexpr bool
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this function live in common/include/pcl/type_traits.h perhaps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify this a lot more (and deprecate it) since this is just a function call instead of std::is_same_v<A, B>. Thoughts: @mvieth ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not necessarily against deprecating isSamePointType, but I don't really see a problem with people using pcl::isSamePointType<A, B>() instead of std::is_same<A, B>::value (or is_same_v starting with C++17).
How would you simplify it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. If we don't deprecate it, should we move it to type_traits.h or some other file than io.h?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from this, LGTM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I see with moving the function to a different header file is that if someone uses the function and includes the current header file (io.h), they would get an error that the function can not be found (unless they also include the new header file by chance), without any prior warning that the function will move or similar. I agree that, if isSamePointType was new and we had to decide where to put it, type_traits.h seems more fitting than io.h, but I honestly don't think it is worth to move this existing function

@al-tu al-tu changed the title no more typeid its constexpr no more typeid, it's constexpr Aug 17, 2021
Comment on lines 366 to 367
constexpr const bool status0 = isSamePointType<PointXYZ, PointXYZ> ();
EXPECT_TRUE (status0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on combining into a single line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done
also, only two of these tests seem like relevant, should i remove duplication, eg there's no point to test
EXPECT_TRUE (isSamePointType<PointNormal, PointNormal> ());
if there's
EXPECT_TRUE (isSamePointType<PointXYZ, PointXYZ> ());
what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I would rather keep those tests. Yes, knowing the implementation of isSamePointType, it is clear that they will pass, but the tests should not make any assumptions about the implementation. If, for some reason, isSamePointType is changed in the future, we would want to test it with all these tests. Plus they cost practically nothing (compilation time/...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conversely, someone reading those tests would (mistakenly) assume that there is some difference in comparison logic for PointXYZ and PointNormal types (because we have two tests and you usually don't pay for what you don't need, especially in library code). and checking out the implementation of isSamePointType would cause even more confusion, because std::is_same works the same in both cases, of course.
so, if there's some need in description forisSamePointType logic, i suggest we leave it as a comment, just quoting cppreference.com:

If T and U name the same type (taking into account const/volatile qualifications), provides the member constant value equal to true. Otherwise value is false.

Commutativity is satisfied, i.e. for any two types T and U, is_same<T, U>::value == true if and only if is_same<U, T>::value == true.

if for some reason it does not seem sufficient, i will revert removal of those extra tests, of course

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi! should i revert my changes in tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay.

someone reading those tests would (mistakenly) assume that there is some difference in comparison logic for PointXYZ and PointNormal types

I don't really agree with that thought. I think it is normal to test a function with many different parameters, also template parameters, without any implication that the function works differently for some parameters. I think the EXPECT_TRUE and EXPECT_FALSE also make clear what the function should do in each case. If you want to add a clarifying comment somewhere, that is of course always a good idea. I just think removing already existing tests is counter-intuitive, considering that too much code in PCL is untested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decreasing code coverage is certainly not a good idea, that's right, so i did roll back my changes. hopefully this PR is an overall improvement and may be merged without changes in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also an opened question whether isSamePointType should live in io.h

@@ -319,10 +319,10 @@ namespace pcl
pcl::PCLPointCloud2 &cloud_out);

/** \brief Check if two given point types are the same or not. */
template <typename Point1T, typename Point2T> inline bool
template <typename Point1T, typename Point2T> inline constexpr bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify this a lot more (and deprecate it) since this is just a function call instead of std::is_same_v<A, B>. Thoughts: @mvieth ?

kunaltyagi
kunaltyagi previously approved these changes Aug 24, 2021
Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If CI is 🟢

@@ -319,10 +319,10 @@ namespace pcl
pcl::PCLPointCloud2 &cloud_out);

/** \brief Check if two given point types are the same or not. */
template <typename Point1T, typename Point2T> inline bool
template <typename Point1T, typename Point2T> inline constexpr bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from this, LGTM

// Check if the correspondence is reciprocal
target_idx = nn_indices[min_index];
tree_reciprocal_->nearestKSearch(
(*target_)[target_idx], 1, index_reciprocal, distance_reciprocal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am missing something here: target_ contains points of type PointTarget, but tree_reciprocal_ uses points of type PointSource, so this should not work, right? I see that you did not change this line, so is this an error that existed before but was not discovered? In correspondence_estimation_backprojection.hpp, this is the same, but in correspondence_estimation.hpp, the point is copied (copyPoint before, pointCopyOrRef with your changes). Do you have an idea?
Apart from this, looks good to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suppose that you're right, it seems like only the cases when point types are the same were covered, i've added another one for completeness (though ), so it should be correct now, but that required some additional changes
PTAL, i might have messed up that source-target logic (hope not)

@al-tu al-tu force-pushed the no-more-typeid-its-constexpr branch 3 times, most recently from 061ccb3 to a206b9a Compare November 18, 2021 07:07
@mvieth
Copy link
Member

mvieth commented Dec 23, 2021

@al-tu The new test(s) don't seem to compile yet

@al-tu al-tu force-pushed the no-more-typeid-its-constexpr branch 14 times, most recently from c53fdec to 7e7e479 Compare March 11, 2022 07:01
@al-tu
Copy link
Contributor Author

al-tu commented Mar 13, 2022

@kunaltyagi @mvieth hello! do you have any idea why one particular test on clang/macos catalina fails? may this be a flaky situation? it would be nice to be able to restart ci via bot command

@mvieth
Copy link
Member

mvieth commented Mar 13, 2022

@kunaltyagi @mvieth hello! do you have any idea why one particular test on clang/macos catalina fails? may this be a flaky situation? it would be nice to be able to restart ci via bot command

I restarted the CI. Unfortunately, there are a few tests that fail randomly (but rarely)

@al-tu
Copy link
Contributor Author

al-tu commented Mar 13, 2022

@kunaltyagi @mvieth hello! do you have any idea why one particular test on clang/macos catalina fails? may this be a flaky situation? it would be nice to be able to restart ci via bot command

I restarted the CI. Unfortunately, there are a few tests that fail randomly (but rarely)

thanks a lot! passes now, so yes, that was a random fail

@al-tu
Copy link
Contributor Author

al-tu commented Jun 7, 2022

hello. it's actually ready now, could you please re-review? thanks!

@larshg larshg added this to the pcl-1.13.0 milestone Oct 18, 2022
@larshg
Copy link
Contributor

larshg commented Oct 20, 2022

@al-tu Do you have time to rebase this?

more tests for correspondence estimation to cover cases
when source and target pointclouds have different point types
@al-tu al-tu force-pushed the no-more-typeid-its-constexpr branch from 7e7e479 to 75bd2d1 Compare October 21, 2022 20:34
@al-tu
Copy link
Contributor Author

al-tu commented Oct 21, 2022

@al-tu Do you have time to rebase this?

sure, done

@mvieth mvieth modified the milestones: pcl-1.13.0, pcl-1.13.1 Nov 19, 2022
Copy link
Member

@mvieth mvieth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, and sorry that we took so long with the reviews

@mvieth mvieth merged commit 956f89c into PointCloudLibrary:master Jun 11, 2023
@al-tu al-tu deleted the no-more-typeid-its-constexpr branch June 16, 2023 22:19
@mvieth mvieth changed the title no more typeid, it's constexpr Correspondence estimation with different point types Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants