-
-
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
[OCTREE] Add bounding box checks in isVoxelOccupiedAtPoint() and deleteVoxelAtPoint() #1976
[OCTREE] Add bounding box checks in isVoxelOccupiedAtPoint() and deleteVoxelAtPoint() #1976
Conversation
I think we should not remove the assertion, it may be helpful for catching other bugs. My proposal would be to add a tree emptiness check in the beginning of the (A small clarification for others reading this issue: this is not a "proper" unit test failure, it's an assertion. This only shows up if compiled in "debug" mode. This is why on Travis everything is fine.) |
Short answerI disagree. Removing the assertions is still the better solution in my opinion. The real long answerIn the case you keep the assertions and you add a check like this: pcl::octree::OctreePointCloud::isVoxelOccupiedAtPoint (const PointT& point_arg) const
{
if(this->leaf_count_ == 0) {
return false;
}
[...]
} at runtime in this unit test, you will be able to add the first point but for the second point, things go wrong. The loop inside the test for (point = 0; point < pointcount; point++)
{
// gereate a random point
PointXYZ newPoint (static_cast<float> (1024.0 * rand () / RAND_MAX),
static_cast<float> (1024.0 * rand () / RAND_MAX),
static_cast<float> (1024.0 * rand () / RAND_MAX));
if (!octreeA.isVoxelOccupiedAtPoint (newPoint))
{
// add point only to OctreePointCloudSinglePoint if voxel at point location doesn't exist
octreeA.addPointToCloud (newPoint, cloudA);
}
// OctreePointCloudPointVector can store all points..
cloudB->push_back (newPoint);
} When you check the condition pcl::octree::OctreePointCloud::genOctreeKeyforPoint (const PointT& point_arg,
OctreeKey & key_arg) const
{
// calculate integer key for point coordinates
key_arg.x = static_cast<unsigned int> ((point_arg.x - this->min_x_) / this->resolution_);
key_arg.y = static_cast<unsigned int> ((point_arg.y - this->min_y_) / this->resolution_);
key_arg.z = static_cast<unsigned int> ((point_arg.z - this->min_z_) / this->resolution_);
assert (key_arg.x <= this->max_key_.x);
assert (key_arg.y <= this->max_key_.y);
assert (key_arg.z <= this->max_key_.z);
} and let see an example of execution.
Obvously, an assertion comparing I don't think that the pcl::octree::OctreePointCloud::addPointIdx (const int point_idx_arg)
{
[...]
// make sure bounding box is big enough
adoptBoundingBoxToPoint (point);
The function `adoptBoundingBoxToPoint(), which takes as input a point, manages to reshape the octree to be able to generate the right voxel for this new point. Remove assert test are usually a bad idea, but in this particular case, I'm not sure because the right behavior of the class seems to happen without them. PS: sorry for this too long answer. |
Thanks for the detailed explanation, now I get your point. Summarizing, the problem is that Your solution is to remove the assertion. However, it's still not obvious for me that this check is not needed. Perhaps it was the intention of the author to make sure that key generation happens only for points in the bounding box. (Because otherwise an invalid key is generated and some other function may explode if given such a key.) I do agree that my previous suggestion with leaf count test is not valid. But here is an alternative. In one of the overloads of the What do you think? |
Your suggestion seems to be the good one. Put |
Thanks. Can you also add a check to the |
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.
When the test passes and you squash, please also fix the style.
@@ -129,13 +129,17 @@ pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT> | |||
template<typename PointT, typename LeafContainerT, typename BranchContainerT, typename OctreeT> bool | |||
pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT>::isVoxelOccupiedAtPoint (const PointT& point_arg) const | |||
{ | |||
if (!isPointWithinBoundingBox (point_arg)){ |
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.
{
should go to the new line. Or delete braces completely, no need here.
} | ||
|
||
////////////////////////////////////////////////////////////////////////////////////////////// | ||
template<typename PointT, typename LeafContainerT, typename BranchContainerT, typename OctreeT> void | ||
pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT>::deleteVoxelAtPoint (const PointT& point_arg) | ||
{ | ||
if (!isPointWithinBoundingBox (point_arg)){ |
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.
Same comment
b8a3c58
to
c00861d
Compare
Things should be fine now. |
The function which failed on my computer was
Octree_Pointcloud_Test
in test/octree/test_octree.cpp. In this function at line 749, we have:if (!octreeA.isVoxelOccupiedAtPoint (newPoint))
and in this context the
octreeA
is empty. The first step of the functionisVoxelOccupiedAtPoint
is to query the key corresponding to the point argumentnewPoint
. The generated key for this point is of course out of the score of the current octree becauseoctreeA
is empty.To fix this test, on one hand the easy way is to remove the
assert()
call inpcl::octree::OctreePointCloud::genOctreeKeyforPoint()
and on the other hand the harder way is to allowpcl::octree::OctreePointCloud::genOctreeKeyforPoint()
to return a status (a bool) to be able to check if everything goes well or not: this means to change its prototype. I chose the first solution to minimize the number of changes.This pull request is relative to issue #677.