6 #include <opencv2/imgproc.hpp>
7 #include <opencv2/tracking.hpp>
8 #include <opencv2/video/tracking.hpp>
11 typedef unsigned int AffordanceIndex;
17 bool operator() ( T a, T b ){
24 bool operator()(T a, T b){
30 std::vector <C> arrayToVec(C* c,
int ct){
31 std::vector <C> result;
32 for (
int i=0; i<ct; i++){
40 class ControlInterface;
47 b2Transform pose {b2Transform(b2Vec2(0,0), b2Rot(0))} ;
48 float halfLength=MIN_BODY_DIMENSION;
49 float halfWidth=MIN_BODY_DIMENSION;
51 b2BodyType bodyType = b2_dynamicBody;
53 b2Shape::Type shape = b2Shape::e_polygon;
60 void setHalfLength(
const float & f){
61 if (f<MIN_BODY_DIMENSION){
62 halfLength=MIN_BODY_DIMENSION;
69 void setHalfWidth(
const float & f){
70 if (f<MIN_BODY_DIMENSION){
71 halfWidth=MIN_BODY_DIMENSION;
95 return width()*length();
98 std::vector <b2Vec2> vertices()
const;
100 std::vector <cv::Point2f> vertices_cv()
const;
102 bool is_point()
const{
103 return halfWidth==MIN_BODY_DIMENSION && halfLength==MIN_BODY_DIMENSION;
107 return Bundle(pose.p.x, pose.p.y, pose.q.GetAngle(), halfWidth, halfLength);
115 friend class ControlInterface;
117 AffordanceIndex affordanceIndex = NONE;
119 bool rotation_valid=0;
121 void setOrientation(
float f){
126 void addToOrientation(
float dtheta){
128 setOrientation(bf.pose.q.GetAngle()+dtheta);
131 setOrientation(dtheta);
156 affordanceIndex=AVOID;
160 bf.pose=b->GetTransform();
161 b2Fixture * fixture =b->GetFixtureList();
162 bf.shape=(fixture->GetShape()->GetType());
164 if (bf.shape==b2Shape::e_polygon){
165 b2PolygonShape * poly=(b2PolygonShape*)fixture->GetShape();
166 std::vector <b2Vec2> local_vertices=arrayToVec(poly->m_vertices, poly->m_count);
169 float minx=(std::min_element(local_vertices.begin(), local_vertices.end(), compareX)).base()->x;
170 float miny=(std::min_element(local_vertices.begin(), local_vertices.end(), compareY)).base()->y;
171 float maxx=(std::max_element(local_vertices.begin(), local_vertices.end(), compareX)).base()->x;
172 float maxy=(std::max_element(local_vertices.begin(), local_vertices.end(), compareY)).base()->y;
173 bf.halfLength=(fabs(maxy-miny))/2;
174 bf.halfWidth=(fabs(maxx-minx))/2;
180 float getAngle(b2Transform);
182 float getAngle(b2Body* b){
183 return getAngle(b->GetTransform());
186 void setPosition(b2Vec2 pos){
187 bf.pose.p.Set(pos.x, pos.y);
190 void setPosition(
float x,
float y){
194 b2Vec2 getPosition()
const{
203 AffordanceIndex getAffIndex()
const{
204 return affordanceIndex;
207 void set_affordance(AffordanceIndex a){
220 std::pair<bool, float> getOrientation(){
222 return std::pair<bool, float>(rotation_valid, bf.pose.q.GetAngle());
225 b2Transform pose()
const{
229 void setPose(b2Transform t){
233 void setAsBox(
float w,
float l){
243 void subtractPose(b2Transform dPose){
244 bf.pose.p.x-=dPose.p.x;
245 bf.pose.p.y-=dPose.p.y;
246 addToOrientation(-dPose.q.GetAngle());
250 return bf.halfLength;
257 void setOrientation(
float,
float);
259 std::vector <b2Vec2> vertices()
const;
269 enum resultType {successful =0, crashed =1, safeForNow=2};
270 resultType resultCode= resultType::successful;
273 b2Transform endPose = b2Transform(b2Vec2(0.0, 0.0), b2Rot(0));
279 simResult(resultType code): resultCode(code){
288 std::vector <b2Vec2> GetLocalPoints( std::vector <b2Vec2>,
const b2Body *);
Definition: disturbance.h:45
bool match(const BodyFeatures &, Bundle *bundle=NULL, b2Transform t=b2Transform_zero)
Definition: disturbance.cpp:3
Definition: threshold.h:10
Definition: graphTools.h:453
Definition: disturbance.h:22
Definition: disturbance.h:15
Definition: disturbance.h:112
Definition: disturbance.h:268