Klamp't  0.9.0
ContactFeature.h
Go to the documentation of this file.
1 #ifndef CONTACT_FEATURE_H
2 #define CONTACT_FEATURE_H
3 
4 #include "Hold.h"
5 #include <KrisLibrary/math3d/Polygon3D.h>
6 #include <KrisLibrary/math3d/geometry3d.h>
7 #include <memory>
8 
9 namespace Klampt {
10 
11 struct Triangle3DSampler;
12 
25 
33 {
34  enum Type { Point, Edge, Face, MultipleFaces, Wheel };
35 
36  ContactFeatureBase() :link(-1),weight(1) {}
37  virtual ~ContactFeatureBase() {}
38  virtual Type GetType() const =0;
39 
40  int link;
41  string name;
42  Real weight;
43 };
44 
47 {
48  virtual Type GetType() const { return Point; }
49 
54  void GetHold(const Vector3& x,Hold&) const;
55 
56  Vector3 p;
57 };
58 
61 {
62  virtual Type GetType() const { return Edge; }
63 
69  void GetHold(const Vector3& x,const Vector3& axis,Hold&) const;
70 
77  void GetHold(const Vector3& x,const Vector3& n,Real theta,Hold&) const;
78 
79  Vector3 p1,p2;
80 };
81 
88 struct FaceContactFeature : public ContactFeatureBase, Polygon3D
89 {
90  virtual Type GetType() const { return Face; }
91 
93  void GetPlane(Plane3D& p) const;
94 
95  void GetCentroid(Vector3& p) const;
96 
105  void GetHold(const Vector3& x,const Vector3& n,Real theta,Hold&) const;
107  void GetHold(const Vector3& localPos,const Vector3& x,const Vector3& n,Real theta,Hold&) const;
108 };
109 
112 {
113  virtual Type GetType() const { return Wheel; }
114 
116  Vector3 GetCenter() const { Vector3 center; axis.closestPoint(p,center); return center; }
118  Real GetRadius() const { return axis.distance(p); }
119 
128  void GetHold(const Vector3& x,const Vector3& n,Real theta,Hold&) const;
129 
139  void GetFixedHold(const Vector3& x,const Vector3& n,Real theta,Real roll,Hold&) const;
140 
141  Line3D axis;
142  Vector3 p;
143  Real width; //wheel's extent along the axis
144 };
145 
153 {
154  virtual Type GetType() const { return MultipleFaces; }
155 
156  //TODO: get the holds
157 
158  vector<Polygon3D> faces;
159 };
160 
163 typedef std::shared_ptr<ContactFeatureBase> ContactFeature;
164 
165 bool LoadContactFeatures(const char* fn,vector<ContactFeature>& ccs);
166 bool SaveContactFeatures(const char* fn,const vector<ContactFeature>& ccs);
167 
168 void SampleHold(const Vector3& x,const Vector3& n,const ContactFeatureBase*,Hold&);
169 void SampleHold(const Vector3& x,const Vector3& n,const vector<ContactFeature>&,Hold&);
170 void SampleHold(Triangle3DSampler& smp,const ContactFeatureBase*,Hold&);
171 void SampleHold(Triangle3DSampler& smp,const vector<ContactFeature>&,Hold&);
172 
174 void HoldFromTransform(const ContactFeatureBase* f,const RigidTransform& T,Hold& h);
175 
177 bool FeatureRayIntersection(const ContactFeatureBase* f,const Ray3D& ray,Real tol=0);
178 
180 Vector3 FeatureContactPoint(const ContactFeatureBase* f);
184 Vector3 FeatureContactNormal(const ContactFeatureBase* f);
187 
190 } //namespace Klampt
191 
192 #endif
Vector3 SampleFeatureContactPoint(const ContactFeatureBase *f)
Uniformly samples a contact point in the feature contact region.
A contact feature consisting of multiple faces.
Definition: ContactFeature.h:152
Vector3 GetCenter() const
Returns the center of the wheel.
Definition: ContactFeature.h:116
A feature on the robot that can be used for contact.
Definition: ContactFeature.h:32
bool FeatureRayIntersection(const ContactFeatureBase *f, const Ray3D &ray, Real tol=0)
Returns true if the ray intersects the contact feature.
Vector3 FeatureContactNormal(const ContactFeatureBase *f)
Real GetRadius() const
Returns the radius of the wheel.
Definition: ContactFeature.h:118
Vector3 FeatureContactPoint(const ContactFeatureBase *f)
Returns the centroid of the feature contact region.
A single point contact feature.
Definition: ContactFeature.h:46
Samples points in a list of 3d triangles.
Definition: TriangleSampler.h:39
std::shared_ptr< ContactFeatureBase > ContactFeature
Definition: ContactFeature.h:163
A single contact between the robot and the environment.
Definition: Hold.h:28
Structures defining the finalized contacts used in stances.
An edge contact feature.
Definition: ContactFeature.h:60
A (planar) face contact feature.
Definition: ContactFeature.h:88
A wheel contact feature.
Definition: ContactFeature.h:111
Definition: ContactDistance.h:6
Real weight
weight for picking this feature
Definition: ContactFeature.h:42
void HoldFromTransform(const ContactFeatureBase *f, const RigidTransform &T, Hold &h)
Computes a hold that transforms the contact feature by T.