Chinaunix首页 | 论坛 | 博客
  • 博客访问: 200852
  • 博文数量: 67
  • 博客积分: 375
  • 博客等级: 一等列兵
  • 技术积分: 525
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-29 22:28
文章分类

全部博文(67)

文章存档

2021年(2)

2019年(1)

2018年(19)

2017年(23)

2016年(4)

2011年(18)

我的朋友
FCL

分类: C/C++

2017-12-13 18:26:11

中的代码无法编译通过,好在ubuntu仓库自带fcl

1.安装fcl

sudo apt-get install libfcl-dev

2.测试

点击(此处)折叠或打开

  1. cmake_minimum_required(VERSION 2.8)
  2. project( fcl_test )
  3. include(CheckCXXCompilerFlag)
  4. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  5. CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
  6. if(COMPILER_SUPPORTS_CXX11)
  7. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  8. elseif(COMPILER_SUPPORTS_CXX0X)
  9. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  10. else()
  11. message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  12. endif()
  13. include_directories(/usr/include)
  14. link_directories(/usr/lib)
  15. add_executable( fcl_test test_fcl_collision.cpp)
  16. target_link_libraries( fcl_test fcl)

main函数框架

点击(此处)折叠或打开

  1. #include "fcl/collision.h"
  2. #include "fcl/math/transform.h"
  3. #include "fcl/math/vec_3f.h"
  4. #include "fcl/config.h"
  5. #include "fcl/BVH/BVH_model.h"
  6. #include "fcl/broadphase/broadphase.h"
  7. #include "fcl/collision.h"
  8. #include "fcl/distance.h"
  9. #include "fcl/continuous_collision.h"
  10. #include "types.h"
  11. #include <iostream>
  12. using namespace fcl;



  13. //==============================================================================
  14. int main(int argc, char* argv[])
  15. {

  16.    return 1;
  17. }

三角网格模型
通过输入一系列的定点和三角网格,通过BVH模型可以测试

点击(此处)折叠或打开

  1. // set mesh triangles and vertice indices
  2.     std::vector<Vec3f> vertices;
  3.     std::vector<Triangle> triangles;
  4.     // code to set the vertices and triangles

  5.     // BVHModel is a template class for mesh geometry, for default OBBRSS template is used
  6.     typedef BVHModel<OBBRSS> Model;
  7.     Model* model = new Model();
  8.     // add the mesh data into the BVHModel structure
  9.     model->beginModel();
  10.     model->addSubModel(vertices, triangles);
  11.     model->endModel();
定义shape

点击(此处)折叠或打开

  1. // // R and T are the rotation matrix and translation vector
  2.     Matrix3f R;
  3.     R.setIdentity();
  4.     Vec3f T1(0,0,0);
  5.     Vec3f T2(2,0,1);
  6.     // code for setting R and T

  7.     // transform is configured according to R and T
  8. // Transform3f pose(R, T);


  9.     std::shared_ptr<Box> box0(new Box(1,1,1));
  10.     std::shared_ptr<Box> box1(new Box(1,1,1));

  11.     std::shared_ptr<Cylinder> cylinder0(new Cylinder(1,1));
  12.     std::shared_ptr<Cylinder> cylinder1(new Cylinder(1,1));
  13.     // Given two objects o1 and o2
  14.     CollisionObject* o1=new CollisionObject(cylinder0,Transform3f(R,T1));

  15.     //o1->cgeom=box0;
  16.     CollisionObject* o2=new CollisionObject(cylinder1,Transform3f(R,T2));

测试是否碰撞

点击(此处)折叠或打开

  1. // set the collision request structure, here we just use the default setting
  2.     CollisionRequest request;
  3.     // result will be returned via the collision result structure
  4.     CollisionResult result;
  5.     // perform collision test
  6.     collide(o1, o2, request, result);
  7.     bool res=result.isCollision()?1:0;
  8.     if(res) std::cerr<<"y"<<std::endl;
  9.     else std::cerr<<"n"<<std::endl;
测量距离

点击(此处)折叠或打开

  1. set the distance request structure, here we just use the default setting
  2.     DistanceRequest request;
  3. // result will be returned via the collision result structure
  4.     DistanceResult result;
  5. // perform distance test
  6.     distance(o1, o2, request, result);
  7.     std::cerr<<result.min_distance<<std::endl;
  8.     std::cerr<<o1->getAABB().center()<<std::endl;
  9.     std::cerr<<o1->getAABB().min_<<std::endl;
  10.     std::cerr<<o1->getAABB().max_<<std::endl;

当两个物体按照一定的轨迹运动时,需要提前预测碰撞,可采用连续碰撞

点击(此处)折叠或打开

  1. // // The goal transforms for o1 and o2
  2.     Transform3f tf_goal_o1 ;
  3.     Transform3f tf_goal_o2 ;
  4. // // set the continuous collision request structure, here we just use the default setting
  5.     ContinuousCollisionRequest request;
  6. // // result will be returned via the continuous collision result structure
  7.     ContinuousCollisionResult result;
  8. // // perform continuous collision test
  9.     continuousCollide(o1, tf_goal_o1, o2, tf_goal_o2, request, result);

  10.     std::cerr<<result.time_of_contact<<std::endl;



阅读(2945) | 评论(0) | 转发(0) |
0

上一篇:KDL

下一篇:ros-moveit

给主人留下些什么吧!~~