17 #ifndef HPP_CONSTRAINTS_CONVEX_SHAPE_HH 18 # define HPP_CONSTRAINTS_CONVEX_SHAPE_HH 22 # include <hpp/fcl/shape/geometric_shapes.h> 25 # include <pinocchio/multibody/model.hpp> 30 # include <hpp/constraints/config.hh> 33 namespace constraints {
46 else if (c2 <= c1) B = A + v;
47 else B = A + c1 / c2 * v;
59 assert (std::abs (n.dot(u)) > 1e-8);
60 return A + u * (n.dot(P - A)) / n.dot (u);
76 Pts_ (pts), joint_ (joint)
82 Pts_ (triangleToPoints (t)), joint_ (joint)
91 Pts_ (
points(p0,p1,p2)), joint_ (joint)
98 Pts_ (t.Pts_), joint_ (t.joint_)
104 std::reverse (Pts_.begin (), Pts_.end());
116 assert (shapeDimension_ > 2);
117 for (std::size_t i = 0; i < shapeDimension_; ++i) {
118 if (Ns_[i].dot (Ap-Pts_[i]) > 0)
return false;
128 assert (shapeDimension_ > 1);
129 const value_type inf = std::numeric_limits<value_type>::infinity();
130 value_type minPosDist = inf, maxNegDist = - inf;
131 bool outside =
false;
132 for (std::size_t i = 0; i < shapeDimension_; ++i) {
136 if (d < minPosDist) minPosDist =
d;
138 if (d <= 0 && d > maxNegDist) maxNegDist =
d;
140 if (outside)
return minPosDist;
146 assert (shapeDimension_ > 2);
152 assert (shapeDimension_ > 2);
170 std::vector <vector3_t> Ns_,
Us_;
183 return (u.dot (w) > 0)?(w.norm()):(- w.norm());
187 return (u.dot (w) > 0)?((w-c2*v).norm()):(-(w-c2*v).norm());
191 static std::vector <vector3_t> triangleToPoints (
const fcl::TriangleP& t) {
194 std::vector <vector3_t> ret (3);
202 std::vector <vector3_t> ret (3);
203 ret[0] = p0; ret[1] = p1; ret[2] = p2;
209 shapeDimension_ = Pts_.size ();
211 switch (shapeDimension_) {
213 throw std::logic_error (
"Cannot represent an empty shape.");
225 C_ = (Pts_[0] + Pts_[1])/2;
228 Us_.push_back (Pts_[1] - Pts_[0]);
229 Ls_[0] = Us_[0].norm();
231 if (Us_[0][0] != 0) N_ =
vector3_t(-Us_[0][1],Us_[0][0],0);
232 else N_ =
vector3_t(0,-Us_[0][2],Us_[0][1]);
234 Ns_.push_back (Us_[0].cross (N_));
240 for (std::size_t i = 0; i < shapeDimension_; ++i)
244 N_ = (Pts_[1] - Pts_[0]).cross (Pts_[2] - Pts_[1]);
248 Us_.resize (Pts_.size());
249 Ns_.resize (Pts_.size());
250 for (std::size_t i = 0; i < shapeDimension_; ++i) {
251 Us_[i] = Pts_[(i+1)%shapeDimension_] - Pts_[i];
252 Ls_[i] = Us_[i].norm();
254 Ns_[i] = Us_[i].cross (N_);
257 for (std::size_t i = 0; i < shapeDimension_; ++i) {
258 assert (Us_[(i+1)%shapeDimension_].dot (Ns_[i]) < 0 &&
259 "The sequence does not define a convex surface");
264 MinJoint_.translation() = C_;
265 MinJoint_.rotation().col(0) = N_;
266 MinJoint_.rotation().col(1) = Ns_[0];
267 MinJoint_.rotation().col(2) = Us_[0];
285 _recompute<true> (cs);
287 oMj_ = cs.
joint_->currentTransformation();
288 _recompute<false> (cs);
298 _recompute<true> (cs);
300 oMj_ = cs.
joint_->currentTransformation(d);
301 _recompute<false> (cs);
305 template <
bool WorldFrame>
312 center_ = oMj_.act (cs.
C_);
313 normal_ = oMj_.rotation () * cs.
N_;
330 return isInside (cs, intersection (A, u));
345 yaxis = oMj_.actInv(yaxis);
347 if (yproj.isZero ())
return cs.
MinJoint_;
350 M.translation() = cs.
C_;
351 M.rotation().col(0) = cs.
N_;
352 M.rotation().col(1) = yaxis;
353 M.rotation().col(2) = cs.
N_.cross (yaxis);
363 if (cs.
joint_!=NULL) a = oMj_.actInv(a);
370 #endif // HPP_CONSTRAINTS_CONVEX_SHAPE_HH JointPtr_t joint_
Definition: convex-shape.hh:173
pinocchio::vector_t vector_t
Definition: fwd.hh:45
void closestPointToSegment(const vector3_t &P, const vector3_t &A, const vector3_t &v, vector3_t &B)
Definition: convex-shape.hh:39
vector3_t intersectionLocal(const vector3_t &A, const vector3_t &u) const
Definition: convex-shape.hh:110
vector3_t C_
the center in the joint frame. It is constant.
Definition: convex-shape.hh:163
ConvexShape(const std::vector< vector3_t > &pts, JointPtr_t joint=JointPtr_t())
Definition: convex-shape.hh:75
bool isInside(const ConvexShape &cs, const vector3_t &A, const vector3_t &u) const
Definition: convex-shape.hh:327
void updateToCurrentTransform(const ConvexShape &cs, const pinocchio::DeviceData &d)
Definition: convex-shape.hh:294
vector_t Ls_
Definition: convex-shape.hh:171
bool isInside(const ConvexShape &cs, const vector3_t &Ap) const
Check whether the point As in world frame is inside the triangle.
Definition: convex-shape.hh:333
const Transform3f & positionInJoint() const
Transform of the shape in the joint frame.
Definition: convex-shape.hh:157
ConvexShape(const ConvexShape &t)
Definition: convex-shape.hh:97
vector3_t linePlaneIntersection(const vector3_t &A, const vector3_t &u, const vector3_t &P, const vector3_t &n)
Definition: convex-shape.hh:55
const vector3_t & planeXaxis() const
Return the X axis of the plane in the joint frame.
Definition: convex-shape.hh:145
Definition: convex-shape.hh:271
vector3_t center_
Definition: convex-shape.hh:276
Transform3f MinJoint_
Definition: convex-shape.hh:172
pinocchio::vector3_t vector3_t
Definition: fwd.hh:39
vector3_t intersection(const vector3_t &A, const vector3_t &u) const
Definition: convex-shape.hh:319
void reverse()
Definition: convex-shape.hh:103
vector3_t N_
the normal to the shape in the joint frame. It is constant.
Definition: convex-shape.hh:165
assert(d.lhs()._blocks()==d.rhs()._blocks())
pinocchio::JointPtr_t JointPtr_t
Definition: fwd.hh:37
std::vector< vector3_t > Pts_
The points in the joint frame. It is constant.
Definition: convex-shape.hh:160
value_type distanceLocal(const vector3_t &a) const
Definition: convex-shape.hh:127
ConvexShape(const fcl::TriangleP &t, const JointPtr_t &joint=JointPtr_t())
Definition: convex-shape.hh:81
Transform3f oMj_
Definition: convex-shape.hh:278
FCL_REAL dist(short i) const
void _recompute(const ConvexShape &cs)
Definition: convex-shape.hh:306
void updateToCurrentTransform(const ConvexShape &cs)
Compute center and normal in world frame.
Definition: convex-shape.hh:281
Definition: convex-shape.hh:64
pinocchio::value_type value_type
Definition: fwd.hh:36
Transform3f alignedPositionInJoint(const ConvexShape &cs, vector3_t yaxis) const
Definition: convex-shape.hh:341
bool isInsideLocal(const vector3_t &Ap) const
As isInside but consider A as expressed in joint frame.
Definition: convex-shape.hh:115
value_type distance(const ConvexShape &cs, vector3_t a) const
Definition: convex-shape.hh:361
std::vector< vector3_t > Us_
Definition: convex-shape.hh:170
ConvexShape(const vector3_t &p0, const vector3_t &p1, const vector3_t &p2, const JointPtr_t &joint=JointPtr_t())
Definition: convex-shape.hh:89
const vector3_t & planeYaxis() const
Definition: convex-shape.hh:151
vector3_t normal_
Definition: convex-shape.hh:274
pinocchio::Transform3f Transform3f
Definition: fwd.hh:50
size_t shapeDimension_
Definition: convex-shape.hh:161