From c2e209c74752d29c049463f85a06794b7a883b5a Mon Sep 17 00:00:00 2001 From: Wolfgang Merkt Date: Mon, 6 Nov 2017 20:10:38 +0000 Subject: [PATCH 1/4] Fix failure in building point cloud models for OBB/RSS/kIOS/OBBRSS - Resolves issue #67 - Port of 49edfc67ba3fee0c90771e332ee879bdebdd1265 by @ricardoglc to new master --- include/fcl/geometry/bvh/BVH_model-inl.h | 25 +++++++++++++++++------- test/test_fcl_bvh_models.cpp | 11 ----------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/fcl/geometry/bvh/BVH_model-inl.h b/include/fcl/geometry/bvh/BVH_model-inl.h index ce0131ac7..2f9757f57 100644 --- a/include/fcl/geometry/bvh/BVH_model-inl.h +++ b/include/fcl/geometry/bvh/BVH_model-inl.h @@ -215,20 +215,23 @@ int BVHModel::beginModel(int num_tris_, int num_vertices_) num_vertices_allocated = num_vertices = num_tris_allocated = num_tris = num_bvs_allocated = num_bvs = 0; } - if(num_tris_ <= 0) num_tris_ = 8; + if(num_tris_ < 0) num_tris_ = 8; if(num_vertices_ <= 0) num_vertices_ = 8; num_vertices_allocated = num_vertices_; num_tris_allocated = num_tris_; - tri_indices = new Triangle[num_tris_allocated]; - vertices = new Vector3[num_vertices_allocated]; - - if(!tri_indices) + if(num_tris_ > 0) { - std::cerr << "BVH Error! Out of memory for tri_indices array on BeginModel() call!" << std::endl; - return BVH_ERR_MODEL_OUT_OF_MEMORY; + tri_indices = new Triangle[num_tris_allocated]; + if(!tri_indices) + { + std::cerr << "BVH Error! Out of memory for tri_indices array on BeginModel() call!" << std::endl; + return BVH_ERR_MODEL_OUT_OF_MEMORY; + } } + + vertices = new Vector3[num_vertices_allocated]; if(!vertices) { std::cerr << "BVH Error! Out of memory for vertices array on BeginModel() call!" << std::endl; @@ -314,6 +317,10 @@ int BVHModel::addTriangle(const Vector3& p1, const Vector3& p2, const if(num_tris >= num_tris_allocated) { + if(num_tris_allocated == 0) + { + num_tris_allocated = 1; + } Triangle* temp = new Triangle[num_tris_allocated * 2]; if(!temp) { @@ -409,6 +416,10 @@ int BVHModel::addSubModel(const std::vector>& ps, const std::vect if(num_tris + num_tris_to_add - 1 >= num_tris_allocated) { + if(num_tris_allocated == 0) + { + num_tris_allocated = 1; + } Triangle* temp = new Triangle[num_tris_allocated * 2 + num_tris_to_add - 1]; if(!temp) { diff --git a/test/test_fcl_bvh_models.cpp b/test/test_fcl_bvh_models.cpp index 3aa56f7c2..95c2de75c 100644 --- a/test/test_fcl_bvh_models.cpp +++ b/test/test_fcl_bvh_models.cpp @@ -50,17 +50,6 @@ void testBVHModelPointCloud() std::shared_ptr > model(new BVHModel); - if (model->getNodeType() != BV_AABB - && model->getNodeType() != BV_KDOP16 - && model->getNodeType() != BV_KDOP18 - && model->getNodeType() != BV_KDOP24) - { - std::cout << "Abort test since '" << test::getNodeTypeName(model->getNodeType()) - << "' does not support point cloud model. " - << "Please see issue #67." << std::endl; - return; - } - Box box; auto a = box.side[0]; auto b = box.side[1]; From 154595e8a47ff3be1358a605def6c557450b933f Mon Sep 17 00:00:00 2001 From: Wolfgang Merkt Date: Mon, 6 Nov 2017 20:30:03 +0000 Subject: [PATCH 2/4] std::nothrow for Triangle, BVNode, unsigned int - Partial port of 8d0441e27c0496c26f7df90469b0caa0c82cba09 by @ricardoglc --- include/fcl/geometry/bvh/BVH_model-inl.h | 10 +++++----- include/fcl/geometry/bvh/BVH_model.h | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/fcl/geometry/bvh/BVH_model-inl.h b/include/fcl/geometry/bvh/BVH_model-inl.h index 2f9757f57..5e760d088 100644 --- a/include/fcl/geometry/bvh/BVH_model-inl.h +++ b/include/fcl/geometry/bvh/BVH_model-inl.h @@ -223,7 +223,7 @@ int BVHModel::beginModel(int num_tris_, int num_vertices_) if(num_tris_ > 0) { - tri_indices = new Triangle[num_tris_allocated]; + tri_indices = new(std::nothrow) Triangle[num_tris_allocated]; if(!tri_indices) { std::cerr << "BVH Error! Out of memory for tri_indices array on BeginModel() call!" << std::endl; @@ -420,7 +420,7 @@ int BVHModel::addSubModel(const std::vector>& ps, const std::vect { num_tris_allocated = 1; } - Triangle* temp = new Triangle[num_tris_allocated * 2 + num_tris_to_add - 1]; + Triangle* temp = new(std::nothrow) Triangle[num_tris_allocated * 2 + num_tris_to_add - 1]; if(!temp) { std::cerr << "BVH Error! Out of memory for tri_indices array on addSubModel() call!" << std::endl; @@ -461,7 +461,7 @@ int BVHModel::endModel() if(num_tris_allocated > num_tris) { - Triangle* new_tris = new Triangle[num_tris]; + Triangle* new_tris = new(std::nothrow) Triangle[num_tris]; if(!new_tris) { std::cerr << "BVH Error! Out of memory for tri_indices array in endModel() call!" << std::endl; @@ -496,8 +496,8 @@ int BVHModel::endModel() num_bvs_to_be_allocated = 2 * num_tris - 1; - bvs = new BVNode [num_bvs_to_be_allocated]; - primitive_indices = new unsigned int [num_bvs_to_be_allocated]; + bvs = new(std::nothrow) BVNode [num_bvs_to_be_allocated]; + primitive_indices = new(std::nothrow) unsigned int [num_bvs_to_be_allocated]; if(!bvs || !primitive_indices) { std::cerr << "BVH Error! Out of memory for BV array in endModel()!" << std::endl; diff --git a/include/fcl/geometry/bvh/BVH_model.h b/include/fcl/geometry/bvh/BVH_model.h index bab7304f5..06096c200 100644 --- a/include/fcl/geometry/bvh/BVH_model.h +++ b/include/fcl/geometry/bvh/BVH_model.h @@ -40,6 +40,7 @@ #include #include +#include #include "fcl/math/bv/OBB.h" #include "fcl/math/bv/kDOP.h" From 3b2c2e4b3f2ca5403a73f776086e7cacc78d7f33 Mon Sep 17 00:00:00 2001 From: Wolfgang Merkt Date: Sat, 11 Nov 2017 12:20:46 +0000 Subject: [PATCH 3/4] Address review comments --- include/fcl/geometry/bvh/BVH_model-inl.h | 3 ++- include/fcl/geometry/bvh/BVH_model.h | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fcl/geometry/bvh/BVH_model-inl.h b/include/fcl/geometry/bvh/BVH_model-inl.h index 5e760d088..e3ee60be2 100644 --- a/include/fcl/geometry/bvh/BVH_model-inl.h +++ b/include/fcl/geometry/bvh/BVH_model-inl.h @@ -39,6 +39,7 @@ #define FCL_BVH_MODEL_INL_H #include "fcl/geometry/bvh/BVH_model.h" +#include namespace fcl { @@ -475,7 +476,7 @@ int BVHModel::endModel() if(num_vertices_allocated > num_vertices) { - Vector3* new_vertices = new Vector3[num_vertices]; + Vector3* new_vertices = new(std::nothrow) Vector3[num_vertices]; if(!new_vertices) { std::cerr << "BVH Error! Out of memory for vertices array in endModel() call!" << std::endl; diff --git a/include/fcl/geometry/bvh/BVH_model.h b/include/fcl/geometry/bvh/BVH_model.h index 06096c200..bab7304f5 100644 --- a/include/fcl/geometry/bvh/BVH_model.h +++ b/include/fcl/geometry/bvh/BVH_model.h @@ -40,7 +40,6 @@ #include #include -#include #include "fcl/math/bv/OBB.h" #include "fcl/math/bv/kDOP.h" From cc0eb875d96a0857403f09359a644c1a55588298 Mon Sep 17 00:00:00 2001 From: Wolfgang Merkt Date: Sat, 11 Nov 2017 13:52:31 +0000 Subject: [PATCH 4/4] Revert std::nothrow on Eigen::Vector3 --- include/fcl/geometry/bvh/BVH_model-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fcl/geometry/bvh/BVH_model-inl.h b/include/fcl/geometry/bvh/BVH_model-inl.h index e3ee60be2..8dbd8b6a5 100644 --- a/include/fcl/geometry/bvh/BVH_model-inl.h +++ b/include/fcl/geometry/bvh/BVH_model-inl.h @@ -476,7 +476,7 @@ int BVHModel::endModel() if(num_vertices_allocated > num_vertices) { - Vector3* new_vertices = new(std::nothrow) Vector3[num_vertices]; + Vector3* new_vertices = new Vector3[num_vertices]; if(!new_vertices) { std::cerr << "BVH Error! Out of memory for vertices array in endModel() call!" << std::endl;