flexible-collision-library / fcl

Flexible Collision Library
https://flexible-collision-library.github.io/
Other
1.43k stars 417 forks source link

BVH_MODEL_POINTCLOUD does't work!!! #307

Open langyuxf opened 6 years ago

langyuxf commented 6 years ago

Is there anything wrong? Anyone can clarify it? thx :)

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPLYFile<pcl::PointXYZ>("F:/data/bunny/data/bun000.ply", *cloud);
std::vector<Vec3f> p1;
for (int i = 0; i < cloud->points.size(); ++i)
{
    p1.push_back(Vec3f(cloud->points[i].x, cloud->points[i].y, cloud->points[i].z));
}
BVHModel<OBB>* m1 = new BVHModel<OBB>;
m1->bv_splitter.reset(new BVSplitter<OBB>(SPLIT_METHOD_BV_CENTER));
m1->beginModel();
m1->addSubModel(p1);
m1->endModel();
SeanCurtis-TRI commented 6 years ago

Could you also include the problem you're encountering? Compiler error? Runtime error?

langyuxf commented 5 years ago

In class BVFitter, it doesn't have a Implementation of OBB fitting for a set of points. Right?

/// @brief Specification of BVFitter for OBB bounding volume
template<>
class BVFitter<OBB> : public BVFitterBase<OBB>
{
public:
  /// @brief Prepare the geometry primitive data for fitting
  void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_)
  {
    vertices = vertices_;
    prev_vertices = NULL;
    tri_indices = tri_indices_;
    type = type_;
  }

  /// @brief Prepare the geometry primitive data for fitting, for deformable mesh
  void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_, BVHModelType type_)
  {
    vertices = vertices_;
    prev_vertices = prev_vertices_;
    tri_indices = tri_indices_;
    type = type_;
  }

  /// @brief Compute a bounding volume that fits a set of primitives (points or triangles).
  /// The primitive data was set by set function and primitive_indices is the primitive index relative to the data.
  OBB fit(unsigned int* primitive_indices, int num_primitives);

  /// brief Clear the geometry primitive data
  void clear()
  {
    vertices = NULL;
    prev_vertices = NULL;
    tri_indices = NULL;
    type = BVH_MODEL_UNKNOWN;
  }

private:

  Vec3f* vertices;
  Vec3f* prev_vertices;
  Triangle* tri_indices;
  BVHModelType type;
};
OBB BVFitter<OBB>::fit(unsigned int* primitive_indices, int num_primitives)
{
  OBB bv;

  Matrix3f M; // row first matrix
  Vec3f E[3]; // row first eigen-vectors
  Matrix3f::U s[3]; // three eigen values

  getCovariance(vertices, prev_vertices, tri_indices, primitive_indices, num_primitives, M);

  eigen(M, s, E);

  axisFromEigen(E, s, bv.axis);

  // set obb centers and extensions
  getExtentAndCenter(vertices, prev_vertices, tri_indices, primitive_indices, num_primitives, bv.axis, bv.To, bv.extent);

  return bv;
}
langyuxf commented 5 years ago

It dose have this, but not integrated into the BVFitter class

/// @brief Compute a bounding volume that fits a set of n points.
template<typename BV>
void fit(Vec3f* ps, int n, BV& bv)
{
  for(int i = 0; i < n; ++i)
  {
    bv += ps[i];
  }
}

template<>
void fit<OBB>(Vec3f* ps, int n, OBB& bv);

template<>
void fit<RSS>(Vec3f* ps, int n, RSS& bv);

template<>
void fit<kIOS>(Vec3f* ps, int n, kIOS& bv);

template<>
void fit<OBBRSS>(Vec3f* ps, int n, OBBRSS& bv);