-
-
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
NormalSpaceSampling
- fix bucket assignment, remove use of raw distribution pointer, unit-test rewriting
#3862
NormalSpaceSampling
- fix bucket assignment, remove use of raw distribution pointer, unit-test rewriting
#3862
Conversation
98fd1fe
to
d178ebf
Compare
I wrote the follow approach to address both your comments and one of the tests is failing 🤦♂️ . I remember this happening before. Have a look Edit: diff --git a/filters/include/pcl/filters/impl/normal_space.hpp b/filters/include/pcl/filters/impl/normal_space.hpp
index 1bf720719..123ddb58d 100644
--- a/filters/include/pcl/filters/impl/normal_space.hpp
+++ b/filters/include/pcl/filters/impl/normal_space.hpp
@@ -59,11 +59,7 @@ pcl::NormalSpaceSampling<PointT, NormalT>::initCompute ()
return false;
}
- boost::mt19937 rng (static_cast<unsigned int> (seed_));
- boost::uniform_int<unsigned int> uniform_distrib (0, unsigned (input_->size ()));
- delete rng_uniform_distribution_;
- rng_uniform_distribution_ = new boost::variate_generator<boost::mt19937, boost::uniform_int<unsigned int> > (rng, uniform_distrib);
-
+ rng_.seed (seed_);
return (true);
}
@@ -213,11 +209,12 @@ pcl::NormalSpaceSampling<PointT, NormalT>::applyFilter (std::vector<int> &indice
unsigned int pos = 0;
unsigned int random_index = 0;
+ boost::uniform_int<unsigned> rng_uniform_distribution (0u, M - 1u);
// Picking up a sample at random from jth bin
do
{
- random_index = static_cast<unsigned int> ((*rng_uniform_distribution_) () % M);
+ random_index = rng_uniform_distribution (rng_);
pos = start_index[j] + random_index;
} while (is_sampled_flag.test (pos));
diff --git a/filters/include/pcl/filters/normal_space.h b/filters/include/pcl/filters/normal_space.h
index 5f7505d9c..34280f113 100644
--- a/filters/include/pcl/filters/normal_space.h
+++ b/filters/include/pcl/filters/normal_space.h
@@ -39,6 +39,7 @@
#include <pcl/filters/boost.h>
#include <pcl/filters/filter_indices.h>
+
#include <ctime>
#include <climits>
@@ -77,17 +78,10 @@ namespace pcl
, binsy_ ()
, binsz_ ()
, input_normals_ ()
- , rng_uniform_distribution_ (nullptr)
{
filter_name_ = "NormalSpaceSampling";
}
- /** \brief Destructor. */
- ~NormalSpaceSampling ()
- {
- delete rng_uniform_distribution_;
- }
-
/** \brief Set number of indices to be sampled.
* \param[in] sample the number of sample indices
*/
@@ -189,8 +183,7 @@ namespace pcl
bool
isEntireBinSampled (boost::dynamic_bitset<> &array, unsigned int start_index, unsigned int length);
- /** \brief Uniform random distribution. */
- boost::variate_generator<boost::mt19937, boost::uniform_int<std::uint32_t> > *rng_uniform_distribution_;
+ boost::mt19937 rng_;
};
} |
Any change in sampling strategy will result in indices being picked in a different order. This test appears to be testing the indices after a random sampling. |
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.
🚀 pending CI. Sorry for the delay, this fell through the cracks till you linked it in another PR
9026032
to
e490001
Compare
NormalSpaceSampling
- fix bucket assignment, remove use of raw distribution pointer, unit-test rewriting
@SergioRAgostinho Sorry to bother you. I'm quite confused by the function My wonder is why Take Or if we insist on using Could you please explain how the formula at the top was derived? Thanks! |
@QiMingZhenFan Do you believe that there is a bug in the code, or are you just trying to understand the code? If you suspect a bug, what is the effect? |
@mvieth Thanks for the reply! Yes, I suspect it's a bug, which may lead to a wrong division. That is, a normal vector may be assigned to the wrong bin. Let's take Let But the picture following shows that this |
@QiMingZhenFan Oh yes, you are right. With the current code, the outer two intervals are only half as wide as the other intervals. Would you like to create a pull request to fix this code? |
@mvieth Sure. I'll do it today. |
Cleaning up some code in preparation for the random mixin.
The use of bind here was intentional, to leverage the copy bind does under the hood.lamdbas bro