Klamp't  0.8.1
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 struct Triangle3DSampler;
10 
23 
31 {
32  enum Type { Point, Edge, Face, MultipleFaces, Wheel };
33 
34  ContactFeatureBase() :link(-1),weight(1) {}
35  virtual ~ContactFeatureBase() {}
36  virtual Type GetType() const =0;
37 
38  int link;
39  string name;
40  Real weight;
41 };
42 
45 {
46  virtual Type GetType() const { return Point; }
47 
52  void GetHold(const Vector3& x,Hold&) const;
53 
54  Vector3 p;
55 };
56 
59 {
60  virtual Type GetType() const { return Edge; }
61 
67  void GetHold(const Vector3& x,const Vector3& axis,Hold&) const;
68 
75  void GetHold(const Vector3& x,const Vector3& n,Real theta,Hold&) const;
76 
77  Vector3 p1,p2;
78 };
79 
86 struct FaceContactFeature : public ContactFeatureBase, Polygon3D
87 {
88  virtual Type GetType() const { return Face; }
89 
91  void GetPlane(Plane3D& p) const;
92 
93  void GetCentroid(Vector3& p) const;
94 
103  void GetHold(const Vector3& x,const Vector3& n,Real theta,Hold&) const;
105  void GetHold(const Vector3& localPos,const Vector3& x,const Vector3& n,Real theta,Hold&) const;
106 };
107 
110 {
111  virtual Type GetType() const { return Wheel; }
112 
114  Vector3 GetCenter() const { Vector3 center; axis.closestPoint(p,center); return center; }
116  Real GetRadius() const { return axis.distance(p); }
117 
126  void GetHold(const Vector3& x,const Vector3& n,Real theta,Hold&) const;
127 
137  void GetFixedHold(const Vector3& x,const Vector3& n,Real theta,Real roll,Hold&) const;
138 
139  Line3D axis;
140  Vector3 p;
141  Real width; //wheel's extent along the axis
142 };
143 
151 {
152  virtual Type GetType() const { return MultipleFaces; }
153 
154  //TODO: get the holds
155 
156  vector<Polygon3D> faces;
157 };
158 
161 typedef std::shared_ptr<ContactFeatureBase> ContactFeature;
162 
163 bool LoadContactFeatures(const char* fn,vector<ContactFeature>& ccs);
164 bool SaveContactFeatures(const char* fn,const vector<ContactFeature>& ccs);
165 
166 void SampleHold(const Vector3& x,const Vector3& n,const ContactFeatureBase*,Hold&);
167 void SampleHold(const Vector3& x,const Vector3& n,const vector<ContactFeature>&,Hold&);
168 void SampleHold(Triangle3DSampler& smp,const ContactFeatureBase*,Hold&);
169 void SampleHold(Triangle3DSampler& smp,const vector<ContactFeature>&,Hold&);
170 
172 void HoldFromTransform(const ContactFeatureBase* f,const RigidTransform& T,Hold& h);
173 
175 bool FeatureRayIntersection(const ContactFeatureBase* f,const Ray3D& ray,Real tol=0);
176 
178 Vector3 FeatureContactPoint(const ContactFeatureBase* f);
182 Vector3 FeatureContactNormal(const ContactFeatureBase* f);
185 
188 #endif
Real GetRadius() const
Returns the radius of the wheel.
Definition: ContactFeature.h:116
A single point contact feature.
Definition: ContactFeature.h:44
A single contact between the robot and the environment.
Definition: Hold.h:26
bool FeatureRayIntersection(const ContactFeatureBase *f, const Ray3D &ray, Real tol=0)
Returns true if the ray intersects the contact feature.
A feature on the robot that can be used for contact.
Definition: ContactFeature.h:30
Samples points in a list of 3d triangles.
Definition: TriangleSampler.h:37
Vector3 SampleFeatureContactPoint(const ContactFeatureBase *f)
Uniformly samples a contact point in the feature contact region.
A wheel contact feature.
Definition: ContactFeature.h:109
Real weight
weight for picking this feature
Definition: ContactFeature.h:40
std::shared_ptr< ContactFeatureBase > ContactFeature
Definition: ContactFeature.h:161
void HoldFromTransform(const ContactFeatureBase *f, const RigidTransform &T, Hold &h)
Computes a hold that transforms the contact feature by T.
A contact feature consisting of multiple faces.
Definition: ContactFeature.h:150
Vector3 FeatureContactPoint(const ContactFeatureBase *f)
Returns the centroid of the feature contact region.
Vector3 FeatureContactNormal(const ContactFeatureBase *f)
Vector3 GetCenter() const
Returns the center of the wheel.
Definition: ContactFeature.h:114
An edge contact feature.
Definition: ContactFeature.h:58
Structures defining the finalized contacts used in stances.
A (planar) face contact feature.
Definition: ContactFeature.h:86