yangjiaolong / Go-ICP

Implementation of the Go-ICP algorithm for globally optimal 3D pointset registration
http://jlyang.org/go-icp/
GNU General Public License v3.0
442 stars 97 forks source link

Bad alloc error #5

Open Harsharma2308 opened 5 years ago

Harsharma2308 commented 5 years ago

I am always getting bad alloc error while building distance transform? Any idea why is this happening? The number of points in my pointcloud are around 250 only.

Building Distance Transform...
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
[1]    9507 abort

Problem occurs somewhere in the initiliasation of Array3d object.

void Array3d<T>::Init(int x, int y, int z)
{

    Xdim = x;
    Ydim = y;
    Zdim = z;
  // allocate the memory for the first level pointers.
  int n1 = z, n2 = y, n3 = x;

  data = new T** [n1];

  // set the first level pointers and allocate the memory for the second level pointers.

  {

    data[0] = new T* [n1 * n2];

    for (int row1_index = 0; row1_index < n1; row1_index++)
      data [row1_index] = data[0] + n2 * row1_index;
  }

  T* array_ptr = new T [n1*n2*n3];
  data_array = array_ptr;

  // set the second level pointers.
  for (int row1_index = 0; row1_index < n1; row1_index++)
    for (int row2_index = 0; row2_index < n2; row2_index++) {
      data [row1_index][row2_index] = array_ptr;
      array_ptr += n3;
    }

}