hpp-fcl  3.0.0
HPP fork of FCL -- The Flexible Collision Library
geometric_shapes.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2015, Open Source Robotics Foundation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Open Source Robotics Foundation nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
38 #ifndef HPP_FCL_GEOMETRIC_SHAPES_H
39 #define HPP_FCL_GEOMETRIC_SHAPES_H
40 
41 #include <vector>
42 #include <memory>
43 
44 #include <boost/math/constants/constants.hpp>
45 
47 #include "hpp/fcl/data_types.h"
48 
49 #ifdef HPP_FCL_HAS_QHULL
50 namespace orgQhull {
51 class Qhull;
52 }
53 #endif
54 
55 namespace hpp {
56 namespace fcl {
57 
60  public:
61  ShapeBase() {}
62 
64  ShapeBase(const ShapeBase& other)
65  : CollisionGeometry(other),
66  m_swept_sphere_radius(other.m_swept_sphere_radius) {}
67 
68  ShapeBase& operator=(const ShapeBase& other) = default;
69 
70  virtual ~ShapeBase() {};
71 
73  OBJECT_TYPE getObjectType() const { return OT_GEOM; }
74 
78  if (radius < 0) {
79  HPP_FCL_THROW_PRETTY("Swept-sphere radius must be positive.",
80  std::invalid_argument);
81  }
82  this->m_swept_sphere_radius = radius;
83  }
84 
87  FCL_REAL getSweptSphereRadius() const { return this->m_swept_sphere_radius; }
88 
89  protected:
101  FCL_REAL m_swept_sphere_radius{0};
102 };
103 
107 
110  public:
111  TriangleP() {};
112 
113  TriangleP(const Vec3f& a_, const Vec3f& b_, const Vec3f& c_)
114  : ShapeBase(), a(a_), b(b_), c(c_) {}
115 
116  TriangleP(const TriangleP& other)
117  : ShapeBase(other), a(other.a), b(other.b), c(other.c) {}
118 
120  virtual TriangleP* clone() const { return new TriangleP(*this); };
121 
124 
125  NODE_TYPE getNodeType() const { return GEOM_TRIANGLE; }
126 
127  // std::pair<ShapeBase*, Transform3f> inflated(const FCL_REAL value) const {
128  // if (value == 0) return std::make_pair(new TriangleP(*this),
129  // Transform3f()); Vec3f AB(b - a), BC(c - b), CA(a - c); AB.normalize();
130  // BC.normalize();
131  // CA.normalize();
132  //
133  // Vec3f new_a(a + value * Vec3f(-AB + CA).normalized());
134  // Vec3f new_b(b + value * Vec3f(-BC + AB).normalized());
135  // Vec3f new_c(c + value * Vec3f(-CA + BC).normalized());
136  //
137  // return std::make_pair(new TriangleP(new_a, new_b, new_c),
138  // Transform3f());
139  // }
140  //
141  // FCL_REAL minInflationValue() const
142  // {
143  // return (std::numeric_limits<FCL_REAL>::max)(); // TODO(jcarpent):
144  // implement
145  // }
146 
147  Vec3f a, b, c;
148 
149  private:
150  virtual bool isEqual(const CollisionGeometry& _other) const {
151  const TriangleP* other_ptr = dynamic_cast<const TriangleP*>(&_other);
152  if (other_ptr == nullptr) return false;
153  const TriangleP& other = *other_ptr;
154 
155  return a == other.a && b == other.b && c == other.c &&
156  getSweptSphereRadius() == other.getSweptSphereRadius();
157  }
158 
159  public:
160  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
161 };
162 
164 class HPP_FCL_DLLAPI Box : public ShapeBase {
165  public:
167  : ShapeBase(), halfSide(x / 2, y / 2, z / 2) {}
168 
169  Box(const Vec3f& side_) : ShapeBase(), halfSide(side_ / 2) {}
170 
171  Box(const Box& other) : ShapeBase(other), halfSide(other.halfSide) {}
172 
173  Box& operator=(const Box& other) {
174  if (this == &other) return *this;
175 
176  this->halfSide = other.halfSide;
177  return *this;
178  }
179 
181  virtual Box* clone() const { return new Box(*this); };
182 
184  Box() {}
185 
188 
191 
193  NODE_TYPE getNodeType() const { return GEOM_BOX; }
194 
195  FCL_REAL computeVolume() const { return 8 * halfSide.prod(); }
196 
198  FCL_REAL V = computeVolume();
199  Vec3f s(halfSide.cwiseAbs2() * V);
200  return (Vec3f(s[1] + s[2], s[0] + s[2], s[0] + s[1]) / 3).asDiagonal();
201  }
202 
203  FCL_REAL minInflationValue() const { return -halfSide.minCoeff(); }
204 
213  std::pair<Box, Transform3f> inflated(const FCL_REAL value) const {
214  if (value <= minInflationValue())
215  HPP_FCL_THROW_PRETTY("value (" << value << ") "
216  << "is two small. It should be at least: "
217  << minInflationValue(),
218  std::invalid_argument);
219  return std::make_pair(Box(2 * (halfSide + Vec3f::Constant(value))),
220  Transform3f());
221  }
222 
223  private:
224  virtual bool isEqual(const CollisionGeometry& _other) const {
225  const Box* other_ptr = dynamic_cast<const Box*>(&_other);
226  if (other_ptr == nullptr) return false;
227  const Box& other = *other_ptr;
228 
229  return halfSide == other.halfSide &&
230  getSweptSphereRadius() == other.getSweptSphereRadius();
231  }
232 
233  public:
234  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
235 };
236 
239  public:
241  Sphere() {}
242 
243  explicit Sphere(FCL_REAL radius_) : ShapeBase(), radius(radius_) {}
244 
245  Sphere(const Sphere& other) : ShapeBase(other), radius(other.radius) {}
246 
248  virtual Sphere* clone() const { return new Sphere(*this); };
249 
252 
255 
257  NODE_TYPE getNodeType() const { return GEOM_SPHERE; }
258 
260  FCL_REAL I = 0.4 * radius * radius * computeVolume();
261  return I * Matrix3f::Identity();
262  }
263 
265  return 4 * boost::math::constants::pi<FCL_REAL>() * radius * radius *
266  radius / 3;
267  }
268 
269  FCL_REAL minInflationValue() const { return -radius; }
270 
279  std::pair<Sphere, Transform3f> inflated(const FCL_REAL value) const {
280  if (value <= minInflationValue())
282  "value (" << value << ") is two small. It should be at least: "
283  << minInflationValue(),
284  std::invalid_argument);
285  return std::make_pair(Sphere(radius + value), Transform3f());
286  }
287 
288  private:
289  virtual bool isEqual(const CollisionGeometry& _other) const {
290  const Sphere* other_ptr = dynamic_cast<const Sphere*>(&_other);
291  if (other_ptr == nullptr) return false;
292  const Sphere& other = *other_ptr;
293 
294  return radius == other.radius &&
295  getSweptSphereRadius() == other.getSweptSphereRadius();
296  }
297 
298  public:
299  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
300 };
301 
304  public:
307 
309  : ShapeBase(), radii(rx, ry, rz) {}
310 
311  explicit Ellipsoid(const Vec3f& radii) : radii(radii) {}
312 
313  Ellipsoid(const Ellipsoid& other) : ShapeBase(other), radii(other.radii) {}
314 
316  virtual Ellipsoid* clone() const { return new Ellipsoid(*this); };
317 
321 
324 
327 
329  FCL_REAL V = computeVolume();
330  FCL_REAL a2 = V * radii[0] * radii[0];
331  FCL_REAL b2 = V * radii[1] * radii[1];
332  FCL_REAL c2 = V * radii[2] * radii[2];
333  return (Matrix3f() << 0.2 * (b2 + c2), 0, 0, 0, 0.2 * (a2 + c2), 0, 0, 0,
334  0.2 * (a2 + b2))
335  .finished();
336  }
337 
339  return 4 * boost::math::constants::pi<FCL_REAL>() * radii[0] * radii[1] *
340  radii[2] / 3;
341  }
342 
343  FCL_REAL minInflationValue() const { return -radii.minCoeff(); }
344 
353  std::pair<Ellipsoid, Transform3f> inflated(const FCL_REAL value) const {
354  if (value <= minInflationValue())
356  "value (" << value << ") is two small. It should be at least: "
357  << minInflationValue(),
358  std::invalid_argument);
359  return std::make_pair(Ellipsoid(radii + Vec3f::Constant(value)),
360  Transform3f());
361  }
362 
363  private:
364  virtual bool isEqual(const CollisionGeometry& _other) const {
365  const Ellipsoid* other_ptr = dynamic_cast<const Ellipsoid*>(&_other);
366  if (other_ptr == nullptr) return false;
367  const Ellipsoid& other = *other_ptr;
368 
369  return radii == other.radii &&
370  getSweptSphereRadius() == other.getSweptSphereRadius();
371  }
372 
373  public:
374  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
375 };
376 
382  public:
384  Capsule() {}
385 
386  Capsule(FCL_REAL radius_, FCL_REAL lz_) : ShapeBase(), radius(radius_) {
387  halfLength = lz_ / 2;
388  }
389 
390  Capsule(const Capsule& other)
391  : ShapeBase(other), radius(other.radius), halfLength(other.halfLength) {}
392 
394  virtual Capsule* clone() const { return new Capsule(*this); };
395 
398 
401 
404 
406  NODE_TYPE getNodeType() const { return GEOM_CAPSULE; }
407 
409  return boost::math::constants::pi<FCL_REAL>() * radius * radius *
410  ((halfLength * 2) + radius * 4 / 3.0);
411  }
412 
414  FCL_REAL v_cyl = radius * radius * (halfLength * 2) *
415  boost::math::constants::pi<FCL_REAL>();
416  FCL_REAL v_sph = radius * radius * radius *
417  boost::math::constants::pi<FCL_REAL>() * 4 / 3.0;
418 
419  FCL_REAL h2 = halfLength * halfLength;
420  FCL_REAL r2 = radius * radius;
421  FCL_REAL ix = v_cyl * (h2 / 3. + r2 / 4.) +
422  v_sph * (0.4 * r2 + h2 + 0.75 * radius * halfLength);
423  FCL_REAL iz = (0.5 * v_cyl + 0.4 * v_sph) * radius * radius;
424 
425  return (Matrix3f() << ix, 0, 0, 0, ix, 0, 0, 0, iz).finished();
426  }
427 
428  FCL_REAL minInflationValue() const { return -radius; }
429 
438  std::pair<Capsule, Transform3f> inflated(const FCL_REAL value) const {
439  if (value <= minInflationValue())
441  "value (" << value << ") is two small. It should be at least: "
442  << minInflationValue(),
443  std::invalid_argument);
444  return std::make_pair(Capsule(radius + value, 2 * halfLength),
445  Transform3f());
446  }
447 
448  private:
449  virtual bool isEqual(const CollisionGeometry& _other) const {
450  const Capsule* other_ptr = dynamic_cast<const Capsule*>(&_other);
451  if (other_ptr == nullptr) return false;
452  const Capsule& other = *other_ptr;
453 
454  return radius == other.radius && halfLength == other.halfLength &&
455  getSweptSphereRadius() == other.getSweptSphereRadius();
456  }
457 
458  public:
459  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
460 };
461 
465 class HPP_FCL_DLLAPI Cone : public ShapeBase {
466  public:
468  Cone() {}
469 
470  Cone(FCL_REAL radius_, FCL_REAL lz_) : ShapeBase(), radius(radius_) {
471  halfLength = lz_ / 2;
472  }
473 
474  Cone(const Cone& other)
475  : ShapeBase(other), radius(other.radius), halfLength(other.halfLength) {}
476 
478  virtual Cone* clone() const { return new Cone(*this); };
479 
482 
485 
488 
490  NODE_TYPE getNodeType() const { return GEOM_CONE; }
491 
493  return boost::math::constants::pi<FCL_REAL>() * radius * radius *
494  (halfLength * 2) / 3;
495  }
496 
498  FCL_REAL V = computeVolume();
499  FCL_REAL ix =
500  V * (0.4 * halfLength * halfLength + 3 * radius * radius / 20);
501  FCL_REAL iz = 0.3 * V * radius * radius;
502 
503  return (Matrix3f() << ix, 0, 0, 0, ix, 0, 0, 0, iz).finished();
504  }
505 
506  Vec3f computeCOM() const { return Vec3f(0, 0, -0.5 * halfLength); }
507 
508  FCL_REAL minInflationValue() const { return -(std::min)(radius, halfLength); }
509 
518  std::pair<Cone, Transform3f> inflated(const FCL_REAL value) const {
519  if (value <= minInflationValue())
521  "value (" << value << ") is two small. It should be at least: "
522  << minInflationValue(),
523  std::invalid_argument);
524 
525  // tan(alpha) = 2*halfLength/radius;
526  const FCL_REAL tan_alpha = 2 * halfLength / radius;
527  const FCL_REAL sin_alpha = tan_alpha / std::sqrt(1 + tan_alpha * tan_alpha);
528  const FCL_REAL top_inflation = value / sin_alpha;
529  const FCL_REAL bottom_inflation = value;
530 
531  const FCL_REAL new_lz = 2 * halfLength + top_inflation + bottom_inflation;
532  const FCL_REAL new_cz = (top_inflation + bottom_inflation) / 2.;
533  const FCL_REAL new_radius = new_lz / tan_alpha;
534 
535  return std::make_pair(Cone(new_radius, new_lz),
536  Transform3f(Vec3f(0., 0., new_cz)));
537  }
538 
539  private:
540  virtual bool isEqual(const CollisionGeometry& _other) const {
541  const Cone* other_ptr = dynamic_cast<const Cone*>(&_other);
542  if (other_ptr == nullptr) return false;
543  const Cone& other = *other_ptr;
544 
545  return radius == other.radius && halfLength == other.halfLength &&
546  getSweptSphereRadius() == other.getSweptSphereRadius();
547  }
548 
549  public:
550  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
551 };
552 
556  public:
558  Cylinder() {}
559 
560  Cylinder(FCL_REAL radius_, FCL_REAL lz_) : ShapeBase(), radius(radius_) {
561  halfLength = lz_ / 2;
562  }
563 
564  Cylinder(const Cylinder& other)
565  : ShapeBase(other), radius(other.radius), halfLength(other.halfLength) {}
566 
567  Cylinder& operator=(const Cylinder& other) {
568  if (this == &other) return *this;
569 
570  this->radius = other.radius;
571  this->halfLength = other.halfLength;
572  return *this;
573  }
574 
576  virtual Cylinder* clone() const { return new Cylinder(*this); };
577 
580 
583 
586 
588  NODE_TYPE getNodeType() const { return GEOM_CYLINDER; }
589 
591  return boost::math::constants::pi<FCL_REAL>() * radius * radius *
592  (halfLength * 2);
593  }
594 
596  FCL_REAL V = computeVolume();
597  FCL_REAL ix = V * (radius * radius / 4 + halfLength * halfLength / 3);
598  FCL_REAL iz = V * radius * radius / 2;
599  return (Matrix3f() << ix, 0, 0, 0, ix, 0, 0, 0, iz).finished();
600  }
601 
602  FCL_REAL minInflationValue() const { return -(std::min)(radius, halfLength); }
603 
612  std::pair<Cylinder, Transform3f> inflated(const FCL_REAL value) const {
613  if (value <= minInflationValue())
615  "value (" << value << ") is two small. It should be at least: "
616  << minInflationValue(),
617  std::invalid_argument);
618  return std::make_pair(Cylinder(radius + value, 2 * (halfLength + value)),
619  Transform3f());
620  }
621 
622  private:
623  virtual bool isEqual(const CollisionGeometry& _other) const {
624  const Cylinder* other_ptr = dynamic_cast<const Cylinder*>(&_other);
625  if (other_ptr == nullptr) return false;
626  const Cylinder& other = *other_ptr;
627 
628  return radius == other.radius && halfLength == other.halfLength &&
629  getSweptSphereRadius() == other.getSweptSphereRadius();
630  }
631 
632  public:
633  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
634 };
635 
639  public:
652  static ConvexBase* convexHull(std::shared_ptr<std::vector<Vec3f>>& points,
653  unsigned int num_points, bool keepTriangles,
654  const char* qhullCommand = NULL);
655 
656  // TODO(louis): put this method in private sometime in the future.
658  const Vec3f* points, unsigned int num_points, bool keepTriangles,
659  const char* qhullCommand = NULL);
660 
661  virtual ~ConvexBase();
662 
666  virtual ConvexBase* clone() const { return new ConvexBase(*this); }
667 
670 
672  NODE_TYPE getNodeType() const { return GEOM_CONVEX; }
673 
674 #ifdef HPP_FCL_HAS_QHULL
677  void buildDoubleDescription();
678 #endif
679 
681  unsigned char count_;
682  unsigned int* n_;
683 
684  unsigned char const& count() const { return count_; }
685  unsigned int& operator[](int i) {
686  assert(i < count_);
687  return n_[i];
688  }
689  unsigned int const& operator[](int i) const {
690  assert(i < count_);
691  return n_[i];
692  }
693 
694  bool operator==(const Neighbors& other) const {
695  if (count_ != other.count_) return false;
696 
697  for (int i = 0; i < count_; ++i) {
698  if (n_[i] != other.n_[i]) return false;
699  }
700 
701  return true;
702  }
703 
704  bool operator!=(const Neighbors& other) const { return !(*this == other); }
705  };
706 
709  static constexpr size_t num_vertices_large_convex_threshold = 32;
710 
712  std::shared_ptr<std::vector<Vec3f>> points;
713  unsigned int num_points;
714 
716  std::shared_ptr<std::vector<Vec3f>> normals;
719  std::shared_ptr<std::vector<double>> offsets;
721 
725  std::shared_ptr<std::vector<Neighbors>> neighbors;
726 
730 
738  std::vector<Vec3f> points;
739 
743  std::vector<int> indices;
744  };
745 
747  static constexpr size_t num_support_warm_starts = 14;
748 
751 
752  protected:
756  : ShapeBase(),
757  num_points(0),
758  num_normals_and_offsets(0),
759  center(Vec3f::Zero()) {}
760 
767  void initialize(std::shared_ptr<std::vector<Vec3f>> points_,
768  unsigned int num_points_);
769 
775  void set(std::shared_ptr<std::vector<Vec3f>> points_,
776  unsigned int num_points_);
777 
780  ConvexBase(const ConvexBase& other);
781 
782 #ifdef HPP_FCL_HAS_QHULL
783  void buildDoubleDescriptionFromQHullResult(const orgQhull::Qhull& qh);
784 #endif
785 
788 
794  std::shared_ptr<std::vector<unsigned int>> nneighbors_;
795 
796  private:
797  void computeCenter();
798 
799  virtual bool isEqual(const CollisionGeometry& _other) const {
800  const ConvexBase* other_ptr = dynamic_cast<const ConvexBase*>(&_other);
801  if (other_ptr == nullptr) return false;
802  const ConvexBase& other = *other_ptr;
803 
804  if (num_points != other.num_points) return false;
805 
806  if ((!(points.get()) && other.points.get()) ||
807  (points.get() && !(other.points.get())))
808  return false;
809  if (points.get() && other.points.get()) {
810  const std::vector<Vec3f>& points_ = *points;
811  const std::vector<Vec3f>& other_points_ = *(other.points);
812  for (unsigned int i = 0; i < num_points; ++i) {
813  if (points_[i] != (other_points_)[i]) return false;
814  }
815  }
816 
817  if ((!(neighbors.get()) && other.neighbors.get()) ||
818  (neighbors.get() && !(other.neighbors.get())))
819  return false;
820  if (neighbors.get() && other.neighbors.get()) {
821  const std::vector<Neighbors>& neighbors_ = *neighbors;
822  const std::vector<Neighbors>& other_neighbors_ = *(other.neighbors);
823  for (unsigned int i = 0; i < num_points; ++i) {
824  if (neighbors_[i] != other_neighbors_[i]) return false;
825  }
826  }
827 
828  if ((!(normals.get()) && other.normals.get()) ||
829  (normals.get() && !(other.normals.get())))
830  return false;
831  if (normals.get() && other.normals.get()) {
832  const std::vector<Vec3f>& normals_ = *normals;
833  const std::vector<Vec3f>& other_normals_ = *(other.normals);
834  for (unsigned int i = 0; i < num_normals_and_offsets; ++i) {
835  if (normals_[i] != other_normals_[i]) return false;
836  }
837  }
838 
839  if ((!(offsets.get()) && other.offsets.get()) ||
840  (offsets.get() && !(other.offsets.get())))
841  return false;
842  if (offsets.get() && other.offsets.get()) {
843  const std::vector<double>& offsets_ = *offsets;
844  const std::vector<double>& other_offsets_ = *(other.offsets);
845  for (unsigned int i = 0; i < num_normals_and_offsets; ++i) {
846  if (offsets_[i] != other_offsets_[i]) return false;
847  }
848  }
849 
850  if (this->support_warm_starts.points.size() !=
851  other.support_warm_starts.points.size() ||
852  this->support_warm_starts.indices.size() !=
853  other.support_warm_starts.indices.size()) {
854  return false;
855  }
856 
857  for (size_t i = 0; i < this->support_warm_starts.points.size(); ++i) {
858  if (this->support_warm_starts.points[i] !=
859  other.support_warm_starts.points[i] ||
860  this->support_warm_starts.indices[i] !=
861  other.support_warm_starts.indices[i]) {
862  return false;
863  }
864  }
865 
866  return center == other.center &&
867  getSweptSphereRadius() == other.getSweptSphereRadius();
868  }
869 
870  public:
871  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
872 };
873 
874 template <typename PolygonT>
875 class Convex;
876 
886  public:
888  Halfspace(const Vec3f& n_, FCL_REAL d_) : ShapeBase(), n(n_), d(d_) {
889  unitNormalTest();
890  }
891 
894  : ShapeBase(), n(a, b, c), d(d_) {
895  unitNormalTest();
896  }
897 
898  Halfspace() : ShapeBase(), n(1, 0, 0), d(0) {}
899 
900  Halfspace(const Halfspace& other)
901  : ShapeBase(other), n(other.n), d(other.d) {}
902 
904  Halfspace& operator=(const Halfspace& other) {
905  n = other.n;
906  d = other.d;
907  return *this;
908  }
909 
911  virtual Halfspace* clone() const { return new Halfspace(*this); };
912 
913  FCL_REAL signedDistance(const Vec3f& p) const {
914  return n.dot(p) - (d + this->getSweptSphereRadius());
915  }
916 
917  FCL_REAL distance(const Vec3f& p) const {
918  return std::abs(this->signedDistance(p));
919  }
920 
923 
926 
928  return std::numeric_limits<FCL_REAL>::lowest();
929  }
930 
939  std::pair<Halfspace, Transform3f> inflated(const FCL_REAL value) const {
940  if (value <= minInflationValue())
942  "value (" << value << ") is two small. It should be at least: "
943  << minInflationValue(),
944  std::invalid_argument);
945  return std::make_pair(Halfspace(n, d + value), Transform3f());
946  }
947 
950 
953 
954  protected:
957 
958  private:
959  virtual bool isEqual(const CollisionGeometry& _other) const {
960  const Halfspace* other_ptr = dynamic_cast<const Halfspace*>(&_other);
961  if (other_ptr == nullptr) return false;
962  const Halfspace& other = *other_ptr;
963 
964  return n == other.n && d == other.d &&
965  getSweptSphereRadius() == other.getSweptSphereRadius();
966  }
967 
968  public:
969  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
970 };
971 
977  public:
979  Plane(const Vec3f& n_, FCL_REAL d_) : ShapeBase(), n(n_), d(d_) {
980  unitNormalTest();
981  }
982 
985  : ShapeBase(), n(a, b, c), d(d_) {
986  unitNormalTest();
987  }
988 
989  Plane() : ShapeBase(), n(1, 0, 0), d(0) {}
990 
991  Plane(const Plane& other) : ShapeBase(other), n(other.n), d(other.d) {}
992 
994  Plane& operator=(const Plane& other) {
995  n = other.n;
996  d = other.d;
997  return *this;
998  }
999 
1001  virtual Plane* clone() const { return new Plane(*this); };
1002 
1003  FCL_REAL signedDistance(const Vec3f& p) const {
1004  const FCL_REAL dist = n.dot(p) - d;
1005  FCL_REAL signed_dist =
1006  std::abs(n.dot(p) - d) - this->getSweptSphereRadius();
1007  if (dist >= 0) {
1008  return signed_dist;
1009  }
1010  if (signed_dist >= 0) {
1011  return -signed_dist;
1012  }
1013  return signed_dist;
1014  }
1015 
1016  FCL_REAL distance(const Vec3f& p) const {
1017  return std::abs(std::abs(n.dot(p) - d) - this->getSweptSphereRadius());
1018  }
1019 
1022 
1024  NODE_TYPE getNodeType() const { return GEOM_PLANE; }
1025 
1028 
1031 
1032  protected:
1035 
1036  private:
1037  virtual bool isEqual(const CollisionGeometry& _other) const {
1038  const Plane* other_ptr = dynamic_cast<const Plane*>(&_other);
1039  if (other_ptr == nullptr) return false;
1040  const Plane& other = *other_ptr;
1041 
1042  return n == other.n && d == other.d &&
1043  getSweptSphereRadius() == other.getSweptSphereRadius();
1044  }
1045 
1046  public:
1047  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
1048 };
1049 
1050 } // namespace fcl
1051 
1052 } // namespace hpp
1053 
1054 #endif
Center at zero point, axis aligned box.
Definition: geometric_shapes.h:164
Capsule It is where is the distance between the point x and the capsule segment AB,...
Definition: geometric_shapes.h:381
The geometry for the object for collision or distance computation.
Definition: collision_object.h:95
Cone The base of the cone is at and the top is at .
Definition: geometric_shapes.h:465
Base for convex polytope.
Definition: geometric_shapes.h:638
Cylinder along Z axis. The cylinder is defined at its centroid.
Definition: geometric_shapes.h:555
Ellipsoid centered at point zero.
Definition: geometric_shapes.h:303
Half Space: this is equivalent to the Plane in ODE. A Half space has a priviledged direction: the dir...
Definition: geometric_shapes.h:885
Infinite plane. A plane can be viewed as two half spaces; it has no priviledged direction....
Definition: geometric_shapes.h:976
Base class for all basic geometric shapes.
Definition: geometric_shapes.h:59
Center at zero point sphere.
Definition: geometric_shapes.h:238
Simple transform class used locally by InterpMotion.
Definition: transform.h:56
Triangle stores the points instead of only indices of points.
Definition: geometric_shapes.h:109
#define HPP_FCL_DLLAPI
Definition: config.hh:88
#define HPP_FCL_DEPRECATED
Definition: deprecated.hh:37
#define HPP_FCL_THROW_PRETTY(message, exception)
Definition: fwd.hh:64
@ OT_GEOM
Definition: collision_object.h:56
@ GEOM_TRIANGLE
Definition: collision_object.h:83
@ GEOM_CAPSULE
Definition: collision_object.h:77
@ GEOM_PLANE
Definition: collision_object.h:81
@ GEOM_HALFSPACE
Definition: collision_object.h:82
@ GEOM_ELLIPSOID
Definition: collision_object.h:85
@ GEOM_BOX
Definition: collision_object.h:75
@ GEOM_CONVEX
Definition: collision_object.h:80
@ GEOM_CYLINDER
Definition: collision_object.h:79
@ GEOM_SPHERE
Definition: collision_object.h:76
@ GEOM_CONE
Definition: collision_object.h:78
FCL_REAL computeVolume() const
compute the volume
Definition: geometric_shapes.h:492
void computeLocalAABB()
Compute AABB.
Vec3f c
Definition: geometric_shapes.h:147
void computeLocalAABB()
Compute AABB.
Plane(const Vec3f &n_, FCL_REAL d_)
Construct a plane with normal direction and offset.
Definition: geometric_shapes.h:979
FCL_REAL halfLength
Half Length along z axis.
Definition: geometric_shapes.h:400
ShapeBase()
Definition: geometric_shapes.h:61
FCL_REAL getSweptSphereRadius() const
Get radius of sphere swept around the shape. This radius is always >= 0.
Definition: geometric_shapes.h:87
std::shared_ptr< std::vector< Vec3f > > normals
An array of the normals of the polygon.
Definition: geometric_shapes.h:716
virtual Plane * clone() const
Clone *this into a new Plane.
Definition: geometric_shapes.h:1001
Capsule(const Capsule &other)
Definition: geometric_shapes.h:390
FCL_REAL computeVolume() const
compute the volume
Definition: geometric_shapes.h:195
FCL_REAL minInflationValue() const
Definition: geometric_shapes.h:927
NODE_TYPE getNodeType() const
Get node type: a plane.
Definition: geometric_shapes.h:1024
FCL_REAL computeVolume() const
compute the volume
Definition: geometric_shapes.h:590
Halfspace(FCL_REAL a, FCL_REAL b, FCL_REAL c, FCL_REAL d_)
Construct a plane with normal direction and offset.
Definition: geometric_shapes.h:893
Sphere(const Sphere &other)
Definition: geometric_shapes.h:245
unsigned int const & operator[](int i) const
Definition: geometric_shapes.h:689
Halfspace(const Halfspace &other)
Definition: geometric_shapes.h:900
ConvexBase()
Construct an uninitialized convex object Initialization is done with ConvexBase::initialize.
Definition: geometric_shapes.h:755
Halfspace()
Definition: geometric_shapes.h:898
NODE_TYPE getNodeType() const
Get node type: a convex polytope.
Definition: geometric_shapes.h:672
FCL_REAL distance(const Vec3f &p) const
Definition: geometric_shapes.h:917
std::shared_ptr< std::vector< Neighbors > > neighbors
Neighbors of each vertex. It is an array of size num_points. For each vertex, it contains the number ...
Definition: geometric_shapes.h:725
void unitNormalTest()
Turn non-unit normal into unit.
ShapeBase(const ShapeBase &other)
&#160;
Definition: geometric_shapes.h:64
NODE_TYPE getNodeType() const
Get node type: an ellipsoid.
Definition: geometric_shapes.h:326
NODE_TYPE getNodeType() const
Get node type: a capsule.
Definition: geometric_shapes.h:406
Box(FCL_REAL x, FCL_REAL y, FCL_REAL z)
Definition: geometric_shapes.h:166
Matrix3f computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition: geometric_shapes.h:497
TriangleP(const Vec3f &a_, const Vec3f &b_, const Vec3f &c_)
Definition: geometric_shapes.h:113
Halfspace(const Vec3f &n_, FCL_REAL d_)
Construct a half space with normal direction and offset.
Definition: geometric_shapes.h:888
Ellipsoid(const Vec3f &radii)
Definition: geometric_shapes.h:311
void set(std::shared_ptr< std::vector< Vec3f >> points_, unsigned int num_points_)
Set the points of the convex shape.
void computeLocalAABB()
Compute AABB.
Matrix3f computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition: geometric_shapes.h:595
void computeLocalAABB()
Compute AABB.
Cylinder(const Cylinder &other)
Definition: geometric_shapes.h:564
Ellipsoid(const Ellipsoid &other)
Definition: geometric_shapes.h:313
virtual Halfspace * clone() const
Clone *this into a new Halfspace.
Definition: geometric_shapes.h:911
std::vector< int > indices
Indices of the support points warm starts. These are the indices of the real convex,...
Definition: geometric_shapes.h:743
Vec3f a
Definition: geometric_shapes.h:147
FCL_REAL computeVolume() const
compute the volume
Definition: geometric_shapes.h:408
virtual Cylinder * clone() const
Clone *this into a new Cylinder.
Definition: geometric_shapes.h:576
unsigned int num_normals_and_offsets
Definition: geometric_shapes.h:720
std::pair< Cone, Transform3f > inflated(const FCL_REAL value) const
Inflate the cone by an amount given by value. This value can be positive or negative but must always ...
Definition: geometric_shapes.h:518
FCL_REAL halfLength
Half Length along z axis.
Definition: geometric_shapes.h:582
std::pair< Box, Transform3f > inflated(const FCL_REAL value) const
Inflate the box by an amount given by value. This value can be positive or negative but must always >...
Definition: geometric_shapes.h:213
Vec3f n
Plane normal.
Definition: geometric_shapes.h:1027
void computeLocalAABB()
Compute AABB.
std::pair< Ellipsoid, Transform3f > inflated(const FCL_REAL value) const
Inflate the ellipsoid by an amount given by value. This value can be positive or negative but must al...
Definition: geometric_shapes.h:353
void unitNormalTest()
Turn non-unit normal into unit.
Halfspace & operator=(const Halfspace &other)
operator =
Definition: geometric_shapes.h:904
NODE_TYPE getNodeType() const
get the node type
Definition: geometric_shapes.h:125
FCL_REAL radius
Radius of capsule.
Definition: geometric_shapes.h:394
void computeLocalAABB()
virtual function of compute AABB in local coordinate
virtual ~ShapeBase()
Definition: geometric_shapes.h:70
unsigned char const & count() const
Definition: geometric_shapes.h:684
Matrix3f computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition: geometric_shapes.h:197
Box(const Vec3f &side_)
Definition: geometric_shapes.h:169
TriangleP()
Definition: geometric_shapes.h:111
FCL_REAL minInflationValue() const
Definition: geometric_shapes.h:508
NODE_TYPE getNodeType() const
Get node type: a half space.
Definition: geometric_shapes.h:925
std::pair< Capsule, Transform3f > inflated(const FCL_REAL value) const
Inflate the capsule by an amount given by value. This value can be positive or negative but must alwa...
Definition: geometric_shapes.h:438
virtual Box * clone() const
Clone *this into a new Box.
Definition: geometric_shapes.h:181
Plane(const Plane &other)
Definition: geometric_shapes.h:991
Cylinder(FCL_REAL radius_, FCL_REAL lz_)
Definition: geometric_shapes.h:560
Vec3f n
Plane normal.
Definition: geometric_shapes.h:949
Cylinder()
Default constructor.
Definition: geometric_shapes.h:558
Plane()
Definition: geometric_shapes.h:989
FCL_REAL halfLength
Half Length along z axis.
Definition: geometric_shapes.h:484
bool operator!=(const Neighbors &other) const
Definition: geometric_shapes.h:704
Ellipsoid()
Default constructor.
Definition: geometric_shapes.h:306
bool operator==(const Neighbors &other) const
Definition: geometric_shapes.h:694
unsigned int * n_
Definition: geometric_shapes.h:682
FCL_REAL signedDistance(const Vec3f &p) const
Definition: geometric_shapes.h:913
unsigned int num_points
Definition: geometric_shapes.h:713
Cylinder & operator=(const Cylinder &other)
Definition: geometric_shapes.h:567
void computeLocalAABB()
Compute AABB.
FCL_REAL distance(const Vec3f &p) const
Definition: geometric_shapes.h:1016
FCL_REAL d
Plane offset.
Definition: geometric_shapes.h:1030
Vec3f computeCOM() const
compute center of mass
Definition: geometric_shapes.h:506
FCL_REAL radius
Radius of the sphere.
Definition: geometric_shapes.h:248
virtual Sphere * clone() const
Clone *this into a new Sphere.
Definition: geometric_shapes.h:248
FCL_REAL signedDistance(const Vec3f &p) const
Definition: geometric_shapes.h:1003
Sphere()
Default constructor.
Definition: geometric_shapes.h:241
Plane & operator=(const Plane &other)
operator =
Definition: geometric_shapes.h:994
Vec3f halfSide
box side half-length
Definition: geometric_shapes.h:187
virtual TriangleP * clone() const
Clone *this into a new TriangleP.
Definition: geometric_shapes.h:120
Vec3f center
center of the convex polytope, this is used for collision: center is guaranteed in the internal of th...
Definition: geometric_shapes.h:729
Plane(FCL_REAL a, FCL_REAL b, FCL_REAL c, FCL_REAL d_)
Construct a plane with normal direction and offset.
Definition: geometric_shapes.h:984
Box & operator=(const Box &other)
Definition: geometric_shapes.h:173
virtual Ellipsoid * clone() const
Clone *this into a new Ellipsoid.
Definition: geometric_shapes.h:316
void buildSupportWarmStart()
Build the support points warm starts.
std::pair< Cylinder, Transform3f > inflated(const FCL_REAL value) const
Inflate the cylinder by an amount given by value. This value can be positive or negative but must alw...
Definition: geometric_shapes.h:612
FCL_REAL minInflationValue() const
Definition: geometric_shapes.h:428
TriangleP(const TriangleP &other)
Definition: geometric_shapes.h:116
void computeLocalAABB()
Compute AABB.
Sphere(FCL_REAL radius_)
Definition: geometric_shapes.h:243
FCL_REAL radius
Radius of the cone.
Definition: geometric_shapes.h:478
Capsule()
Default constructor.
Definition: geometric_shapes.h:384
Cone()
Default constructor.
Definition: geometric_shapes.h:468
static ConvexBase * convexHull(std::shared_ptr< std::vector< Vec3f >> &points, unsigned int num_points, bool keepTriangles, const char *qhullCommand=NULL)
Build a convex hull based on Qhull library and store the vertices and optionally the triangles.
ConvexBase(const ConvexBase &other)
Copy constructor Only the list of neighbors is copied.
FCL_REAL computeVolume() const
compute the volume
Definition: geometric_shapes.h:264
Matrix3f computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition: geometric_shapes.h:413
FCL_REAL radius
Radius of the cylinder.
Definition: geometric_shapes.h:576
Box()
Default constructor.
Definition: geometric_shapes.h:184
static ConvexBase * convexHull(const Vec3f *points, unsigned int num_points, bool keepTriangles, const char *qhullCommand=NULL)
NODE_TYPE getNodeType() const
Get node type: a box.
Definition: geometric_shapes.h:193
Ellipsoid(FCL_REAL rx, FCL_REAL ry, FCL_REAL rz)
Definition: geometric_shapes.h:308
Cone(const Cone &other)
Definition: geometric_shapes.h:474
std::shared_ptr< std::vector< double > > offsets
An array of the offsets to the normals of the polygon. Note: there are as many offsets as normals.
Definition: geometric_shapes.h:719
SupportWarmStartPolytope support_warm_starts
Support warm start polytopes.
Definition: geometric_shapes.h:750
std::pair< Halfspace, Transform3f > inflated(const FCL_REAL value) const
Inflate the halfspace by an amount given by value. This value can be positive or negative but must al...
Definition: geometric_shapes.h:939
virtual Capsule * clone() const
Clone *this into a new Capsule.
Definition: geometric_shapes.h:394
virtual Cone * clone() const
Clone *this into a new Cone.
Definition: geometric_shapes.h:478
void setSweptSphereRadius(FCL_REAL radius)
Set radius of sphere swept around the shape. Must be >= 0.
Definition: geometric_shapes.h:77
ShapeBase & operator=(const ShapeBase &other)=default
FCL_REAL minInflationValue() const
Definition: geometric_shapes.h:203
virtual ConvexBase * clone() const
Clone (deep copy). This method is consistent with BVHModel clone method. The copy constructor is call...
Definition: geometric_shapes.h:666
Vec3f b
Definition: geometric_shapes.h:147
Cone(FCL_REAL radius_, FCL_REAL lz_)
Definition: geometric_shapes.h:470
Matrix3f computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition: geometric_shapes.h:328
FCL_REAL minInflationValue() const
Definition: geometric_shapes.h:602
std::shared_ptr< std::vector< unsigned int > > nneighbors_
Array of indices of the neighbors of each vertex. Since we don't know a priori the number of neighbor...
Definition: geometric_shapes.h:794
Capsule(FCL_REAL radius_, FCL_REAL lz_)
Definition: geometric_shapes.h:386
void computeLocalAABB()
Compute AABB.
OBJECT_TYPE getObjectType() const
Get object type: a geometric shape.
Definition: geometric_shapes.h:73
std::shared_ptr< std::vector< Vec3f > > points
An array of the points of the polygon.
Definition: geometric_shapes.h:712
void initialize(std::shared_ptr< std::vector< Vec3f >> points_, unsigned int num_points_)
Initialize the points of the convex shape This also initializes the ConvexBase::center.
NODE_TYPE getNodeType() const
Get node type: a cone.
Definition: geometric_shapes.h:490
FCL_REAL minInflationValue() const
Definition: geometric_shapes.h:269
Matrix3f computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition: geometric_shapes.h:259
NODE_TYPE getNodeType() const
Get node type: a cylinder.
Definition: geometric_shapes.h:588
Vec3f radii
Radii of the Ellipsoid (such that on boundary: x^2/rx^2 + y^2/ry^2.
Definition: geometric_shapes.h:316
unsigned int & operator[](int i)
Definition: geometric_shapes.h:685
NODE_TYPE getNodeType() const
Get node type: a sphere.
Definition: geometric_shapes.h:257
void computeLocalAABB()
Compute AABB.
FCL_REAL computeVolume() const
compute the volume
Definition: geometric_shapes.h:338
std::vector< Vec3f > points
Array of support points to warm start the support function computation.
Definition: geometric_shapes.h:738
std::pair< Sphere, Transform3f > inflated(const FCL_REAL value) const
Inflate the sphere by an amount given by value. This value can be positive or negative but must alway...
Definition: geometric_shapes.h:279
FCL_REAL minInflationValue() const
Definition: geometric_shapes.h:343
FCL_REAL d
Plane offset.
Definition: geometric_shapes.h:952
Box(const Box &other)
Definition: geometric_shapes.h:171
unsigned char count_
Definition: geometric_shapes.h:681
Eigen::Matrix< FCL_REAL, 3, 3 > Matrix3f
Definition: data_types.h:71
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
Definition: collision_object.h:53
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Definition: collision_object.h:65
bool isEqual(const Eigen::MatrixBase< Derived > &lhs, const Eigen::MatrixBase< OtherDerived > &rhs, const FCL_REAL tol=std::numeric_limits< FCL_REAL >::epsilon() *100)
Definition: tools.h:205
double FCL_REAL
Definition: data_types.h:66
Main namespace.
Definition: broadphase_bruteforce.h:44
Definition: geometric_shapes.h:680
The support warm start polytope contains certain points of this which are support points in specific ...
Definition: geometric_shapes.h:735