Skip to content

getCentroidIndexAt in voxel_grid.h deliver wrong leaf_layout_[idx] #3529

Closed

Description

@zhangliyin126

Your Environment

  • Operating System and version: ubuntu 16.04
  • Compiler:gcc 5.4.0
  • PCL Version:1.9

Context

Here is original code

 inline int
      getCentroidIndexAt (const Eigen::Vector3i &ijk) const
      {
        int idx = ((Eigen::Vector4i() << ijk, 0).finished() - min_b_).dot (divb_mul_);
        if (idx < 0 || idx >= static_cast<int> (leaf_layout_.size ())) // this checks also if leaf_layout_.size () == 0 i.e. everything was computed as needed
        {
          //if (verbose)
          //  PCL_ERROR ("[pcl::%s::getCentroidIndexAt] Specified coordinate is outside grid bounds, or leaf layout is not saved, make sure to call setSaveLeafLayout(true) and filter(output) first!\n", getClassName ().c_str ());
          return (-1);
        }
        return (leaf_layout_[idx]);
      }

If you retrieve points out of voxel grids, and let's see its ijk[0] is large, you will get a index with wrong number rather than -1, due to its use of idx.

Solution

Directly check ijk, add following code to getCentroidIndexAt function:
if (ijk[0]<min_b_[0] || ijk[0]>max_b_[0] || ijk[1]<min_b_[1] ||
ijk[1]> max_b_[1] || ijk[2]<min_b_[2] || ijk[2]>max_b_[2]) return (-1);

Activity

  1. stale commented on May 19, 2020

    @stale

    Marking this as stale due to 30 days of inactivity. It will be closed in 7 days if no further activity occurs.

  2. nilsgr commented on Jan 4, 2023

    @nilsgr

    I can confirm this bug. It caused random artifacts using voxel_grid_occlusion_estimation.hpp... The provided solution fixed it for me.

  3. mvieth commented on Jan 9, 2023

    @mvieth
    Member

    @nilsgr I checked voxel_grid_occlusion_estimation.hpp, and getCentroidIndexAt is used in three places: one, two, three
    But in all three places, the for/while loops make sure that the values passed to getCentroidIndexAt are okay with respect to min_b_ and max_b_. Can you say which values min_b_ and max_b_ have in your case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions