16 CollisionCheckerBase(env), m_server(NULL), m_treeClone(NULL)
51 ROS_ERROR(
"No tree exists");
58 CollisionCheckerBase::Clone(preference, cloningoptions);
89 static float boxCenter[3];
94 static float boxExtents[3];
99 static float triVerts[3][3];
101 triVerts[0][0] = t1.x;
102 triVerts[0][1] = t1.y;
103 triVerts[0][2] = t1.z;
105 triVerts[1][0] = t2.x;
106 triVerts[1][1] = t2.y;
107 triVerts[1][2] = t2.z;
109 triVerts[2][0] = t3.x;
110 triVerts[2][1] = t3.y;
111 triVerts[2][2] = t3.z;
138 std::vector<OpenRAVE::KinBodyConstPtr> vbodyExcluded;
139 const std::vector< OpenRAVE::KinBody::LinkConstPtr > vlinkExcluded;
165 std::vector<OpenRAVE::KinBodyConstPtr> vbodyExcluded;
166 const std::vector< OpenRAVE::KinBody::LinkConstPtr > vlinkExcluded;
188 for(
size_t i = 0; i < bodies.size(); i++)
201 for(
size_t i = 0; i < links.size(); i++)
214 for(
size_t i = 0; i < links.size(); i++)
225 inline float min(
float a,
float b,
float c)
227 return fmin(a, fmin(b, c));
230 inline float max(
float a,
float b,
float c)
232 return fmax(a, fmax(b, c));
238 float minX =
min(t1.x, t2.x, t3.x);
239 float minY =
min(t1.y, t2.y, t3.y);
240 float minZ =
min(t1.z, t2.z, t3.z);
242 float maxX =
max(t1.x, t2.x, t3.x);
243 float maxY =
max(t1.y, t2.y, t3.y);
244 float maxZ =
max(t1.z, t2.z, t3.z);
247 aabb.pos.x = (minX + maxX) * 0.5f;
248 aabb.pos.y = (minY + maxY) * 0.5f;
249 aabb.pos.z = (minZ + maxZ) * 0.5f;
251 aabb.extents.x = (maxX - minX) * 0.5f;
252 aabb.extents.y = (maxY - minY) * 0.5f;
253 aabb.extents.z = (maxZ - minZ) * 0.5f;
259 const octomap::point3d& point = it.getCoordinate();
260 double resolution = it.getSize();
270 bool OctomapCollisionChecker::CheckOctomapCollision(OpenRAVE::KinBody::LinkConstPtr plink,
const std::vector< OpenRAVE::KinBodyConstPtr > &vbodyexcluded,
const std::vector< OpenRAVE::KinBody::LinkConstPtr > &vlinkexcluded, OpenRAVE::CollisionReportPtr report)
278 OpenRAVE::AABB aabb = plink->ComputeAABB();
280 const OpenRAVE::TriMesh& mesh = plink->GetCollisionData();
282 OpenRAVE::Transform globalTransform = plink->GetTransform();
284 octomap::OcTree::leaf_bbx_iterator leafIterBegin =
GetTreeClone()->begin_leafs_bbx(octomap::point3d(aabb.pos.x - aabb.extents.x, aabb.pos.y - aabb.extents.y, aabb.pos.z - aabb.extents.z), octomap::point3d(aabb.pos.x + aabb.extents.x, aabb.pos.y + aabb.extents.y, aabb.pos.z + aabb.extents.z));
285 octomap::OcTree::leaf_bbx_iterator endIter =
GetTreeClone()->end_leafs_bbx();
288 for(octomap::OcTree::leaf_bbx_iterator it = leafIterBegin; it!= endIter; it++)
290 if(it->getOccupancy() <=
GetTreeClone()->getOccupancyThres())
295 for(
size_t j = 0; j < mesh.indices.size() / 3; j++)
297 OpenRAVE::Vector v1 = globalTransform * mesh.vertices.at(mesh.indices.at(j * 3 + 0));
298 OpenRAVE::Vector v2 = globalTransform * mesh.vertices.at(mesh.indices.at(j * 3 + 1));
299 OpenRAVE::Vector v3 = globalTransform * mesh.vertices.at(mesh.indices.at(j * 3 + 2));
312 bool OctomapCollisionChecker::CheckOctomapCollision(OpenRAVE::KinBodyConstPtr pbody,
const std::vector< OpenRAVE::KinBodyConstPtr > &vbodyexcluded,
const std::vector< OpenRAVE::KinBody::LinkConstPtr > &vlinkexcluded, OpenRAVE::CollisionReportPtr report)
322 OpenRAVE::AABB aabb = pbody->ComputeAABB();
324 octomap::point3d minPoint = octomap::point3d(aabb.pos.x - aabb.extents.x, aabb.pos.y - aabb.extents.y, aabb.pos.z - aabb.extents.z);
325 octomap::point3d maxPoint = octomap::point3d(aabb.pos.x + aabb.extents.x, aabb.pos.y + aabb.extents.y, aabb.pos.z + aabb.extents.z);
327 octomap::OcTree::leaf_bbx_iterator it =
GetTreeClone()->begin_leafs_bbx(minPoint, maxPoint);
328 bool foundOccupied =
false;
331 if(it->getOccupancy() >
GetTreeClone()->getOccupancyThres())
333 foundOccupied =
true;
339 if(!foundOccupied)
return false;
341 for(
size_t i = 0; i < pbody->GetLinks().size(); i++)
344 OpenRAVE::KinBody::LinkConstPtr link = pbody->GetLinks().at(i);
361 std::vector<OpenRAVE::KinBodyPtr> bodies;
362 GetEnv()->GetBodies(bodies);
364 for(
size_t i = 0; i < bodies.size(); i++)
366 OpenRAVE::KinBodyConstPtr body = bodies.at(i);
402 octomap::point3d origin;
403 origin(0) = ray.pos.x;
404 origin(1) = ray.pos.y;
405 origin(2) = ray.pos.z;
407 octomap::point3d dir;
412 octomap::point3d end;
417 bool collision =
GetTreeClone()->castRay(origin, dir, end,
true, ray.dir.lengthsqr3());
418 report->minDistance = (end - origin).norm();
451 bool OctomapCollisionChecker::CheckCollision(OpenRAVE::KinBody::LinkConstPtr plink,
const std::vector< OpenRAVE::KinBodyConstPtr > &vbodyexcluded,
const std::vector< OpenRAVE::KinBody::LinkConstPtr > &vlinkexcluded, OpenRAVE::CollisionReportPtr report)
456 bool OctomapCollisionChecker::CheckCollision(OpenRAVE::KinBodyConstPtr pbody,
const std::vector< OpenRAVE::KinBodyConstPtr > &vbodyexcluded,
const std::vector< OpenRAVE::KinBody::LinkConstPtr > &vlinkexcluded, OpenRAVE::CollisionReportPtr report)
504 ROS_INFO(
"Finding nodes colliding with %s\n", objectName.c_str());
507 if (!tree->getRoot())
509 ROS_WARN(
"Tree has no root.\n");
513 OpenRAVE::KinBodyPtr pbody = GetEnv()->GetKinBody(objectName);
517 ROS_WARN(
"Unable to find object %s\n", objectName.c_str());
522 ROS_INFO(
"Masking...\n");
525 OpenRAVE::AABB aabb = pbody->ComputeAABB();
528 ROS_ERROR(
"No tree!\n");
531 float halfResolution = tree->getResolution() * 1.5f;
533 for(
size_t i = 0; i < pbody->GetLinks().size(); i++)
535 OpenRAVE::KinBody::LinkConstPtr plink = pbody->GetLinks().at(i);
537 aabb = plink->ComputeAABB();
538 aabb.extents *= 1.25f;
540 octomap::point3d minPoint = octomap::point3d(aabb.pos.x - aabb.extents.x, aabb.pos.y - aabb.extents.y, aabb.pos.z - aabb.extents.z);
541 octomap::point3d maxPoint = octomap::point3d(aabb.pos.x + aabb.extents.x, aabb.pos.y + aabb.extents.y, aabb.pos.z + aabb.extents.z);
542 ROS_INFO(
"Computing nodes for link %s\n", plink->GetName().c_str());
543 ROS_INFO(
"Bounding box is %f %f %f %f %f %f\n", minPoint.x(), minPoint.y(), minPoint.z(), maxPoint.x(), maxPoint.y(), maxPoint.z());
544 octomap::OcTree::leaf_bbx_iterator it = tree->begin_leafs_bbx(minPoint, maxPoint);
545 printf(
"Created iterator\n");
546 bool foundOccupied =
false;
547 while(it !=tree->end_leafs_bbx())
549 if(it->getOccupancy() > tree->getOccupancyThres())
551 foundOccupied =
true;
557 if(!foundOccupied)
continue;
559 const OpenRAVE::TriMesh& mesh = plink->GetCollisionData();
561 OpenRAVE::Transform globalTransform = plink->GetTransform();
563 octomap::OcTree::leaf_bbx_iterator leafIterBegin = tree->begin_leafs_bbx(octomap::point3d(aabb.pos.x - aabb.extents.x, aabb.pos.y - aabb.extents.y, aabb.pos.z - aabb.extents.z), octomap::point3d(aabb.pos.x + aabb.extents.x, aabb.pos.y + aabb.extents.y, aabb.pos.z + aabb.extents.z));
564 octomap::OcTree::leaf_bbx_iterator endIter = tree->end_leafs_bbx();
566 for(octomap::OcTree::leaf_bbx_iterator it = leafIterBegin; it!= endIter; it++)
568 const octomap::point3d& point = it.getCoordinate();
569 float size = it.getSize() * 1.5f;
571 if(it->getOccupancy() > tree->getOccupancyThres())
573 for(
size_t j = 0; j < mesh.indices.size() / 3; j++)
575 OpenRAVE::Vector t1 = globalTransform * mesh.vertices.at(mesh.indices.at(j * 3 + 0));
576 OpenRAVE::Vector t2 = globalTransform * mesh.vertices.at(mesh.indices.at(j * 3 + 1));
577 OpenRAVE::Vector t3 = globalTransform * mesh.vertices.at(mesh.indices.at(j * 3 + 2));
583 nodes.push_back(tree->search(it.getKey()));
593 std::vector<octomap::OcTreeNode*> nodes;
596 ROS_INFO(
"Got %lu colliding nodes\n", nodes.size());
597 for(std::vector<octomap::OcTreeNode*>::iterator it = nodes.begin(); it != nodes.end(); it++)
601 for(
int i = 0; i < 10; i++)
void ComputeTriangleAABB(const OpenRAVE::Vector &t1, const OpenRAVE::Vector &t2, const OpenRAVE::Vector &t3, OpenRAVE::AABB &aabb)
int CollisionTestTriangleAABB(const OpenRAVE::Vector &t1, const OpenRAVE::Vector &t2, const OpenRAVE::Vector &t3, float x, float y, float z, float eX, float eY, float eZ)
OpenRAVE::CollisionCheckerBasePtr m_wrappedChecker
virtual bool CheckCollision(OpenRAVE::KinBodyConstPtr pbody1, OpenRAVE::CollisionReportPtr report=OpenRAVE::CollisionReportPtr())
OctomapCollisionChecker(OpenRAVE::EnvironmentBasePtr env)
virtual bool CheckStandaloneSelfCollision(OpenRAVE::KinBodyConstPtr body, OpenRAVE::CollisionReportPtr report=OpenRAVE::CollisionReportPtr())
bool ContainsBody(const std::vector< OpenRAVE::KinBodyConstPtr > &links, OpenRAVE::KinBodyConstPtr link)
virtual bool InitEnvironment()
virtual ~OctomapCollisionChecker()
float max(float a, float b, float c)
octomap::OcTree * m_treeClone
octomap::OcTree * GetTreeClone()
bool ContainsLink(const std::vector< OpenRAVE::KinBody::LinkConstPtr > &links, OpenRAVE::KinBody::LinkConstPtr link)
virtual void Clone(OpenRAVE::InterfaceBaseConstPtr preference, int cloningoptions)
octomap::OcTree * GetTree()
float min(float a, float b, float c)
void GetNodesColliding(const std::string &objectName, std::vector< octomap::OcTreeNode * > &nodes)
virtual bool CheckOctomapCollision(OpenRAVE::KinBodyConstPtr pbody1, OpenRAVE::CollisionReportPtr report=OpenRAVE::CollisionReportPtr())
bool MaskObject(std::string name)
virtual bool SetCollisionOptions(int collisionoptions)
virtual void RemoveKinBody(OpenRAVE::KinBodyPtr body)
virtual bool InitKinBody(OpenRAVE::KinBodyPtr pbody)
boost::mutex & GetMutex()
virtual void DestroyEnvironment()
OctomapInterface * m_server
virtual int GetCollisionOptions() const
bool ContainsSpecialBody(const std::vector< OpenRAVE::KinBodyConstPtr > &bodies)
int CollisionTestTriangle(const OpenRAVE::Vector &t1, const OpenRAVE::Vector &t2, const OpenRAVE::Vector &t3, octomap::OcTree::leaf_bbx_iterator &it)
virtual void SetTolerance(OpenRAVE::dReal tolerance)
int triBoxOverlap(float boxcenter[3], float boxhalfsize[3], float triverts[3][3])
std::string m_specialObject