4 #include "box2d_helpers.h"
7 #include <opencv2/core.hpp>
8 #include <opencv2/imgproc.hpp>
9 #include <opencv2/tracking.hpp>
10 #include <opencv2/video/tracking.hpp>
13 typedef unsigned int AffordanceIndex;
19 bool operator() ( T a, T b ){
26 bool operator()(T a, T b){
32 std::vector <C> arrayToVec(C* c,
int ct){
33 std::vector <C> result;
34 for (
int i=0; i<ct; i++){
42 class ControlInterface;
48 b2Transform pose {b2Transform(b2Vec2(0,0), b2Rot(0))} ;
49 float halfLength=MIN_BODY_DIMENSION;
50 float halfWidth=MIN_BODY_DIMENSION;
52 b2BodyType bodyType = b2_dynamicBody;
54 b2Shape::Type shape = b2Shape::e_polygon;
61 void setHalfLength(
const float & f){
62 if (f<MIN_BODY_DIMENSION){
63 halfLength=MIN_BODY_DIMENSION;
70 void setHalfWidth(
const float & f){
71 if (f<MIN_BODY_DIMENSION){
72 halfWidth=MIN_BODY_DIMENSION;
96 return width()*length();
99 std::vector <b2Vec2> vertices()
const;
101 std::vector <cv::Point2f> vertices_cv()
const;
103 bool is_point()
const{
104 return halfWidth==MIN_BODY_DIMENSION && halfLength==MIN_BODY_DIMENSION;
108 return Bundle(pose.p.x, pose.p.y, pose.q.GetAngle(), halfWidth, halfLength);
116 friend class ControlInterface;
118 AffordanceIndex affordanceIndex = NONE;
120 bool rotation_valid=0;
122 void setOrientation(
float f){
127 void addToOrientation(
float dtheta){
129 setOrientation(bf.pose.q.GetAngle()+dtheta);
132 setOrientation(dtheta);
157 affordanceIndex=AVOID;
161 bf.pose=b->GetTransform();
162 b2Fixture * fixture =b->GetFixtureList();
163 bf.shape=(fixture->GetShape()->GetType());
165 if (bf.shape==b2Shape::e_polygon){
166 b2PolygonShape * poly=(b2PolygonShape*)fixture->GetShape();
167 std::vector <b2Vec2> local_vertices=arrayToVec(poly->m_vertices, poly->m_count);
170 float minx=(std::min_element(local_vertices.begin(), local_vertices.end(), compareX)).base()->x;
171 float miny=(std::min_element(local_vertices.begin(), local_vertices.end(), compareY)).base()->y;
172 float maxx=(std::max_element(local_vertices.begin(), local_vertices.end(), compareX)).base()->x;
173 float maxy=(std::max_element(local_vertices.begin(), local_vertices.end(), compareY)).base()->y;
174 bf.halfLength=(fabs(maxy-miny))/2;
175 bf.halfWidth=(fabs(maxx-minx))/2;
181 float getAngle(b2Transform);
183 float getAngle(b2Body* b){
184 return getAngle(b->GetTransform());
187 void setPosition(b2Vec2 pos){
188 bf.pose.p.Set(pos.x, pos.y);
191 void setPosition(
float x,
float y){
195 b2Vec2 getPosition()
const{
204 AffordanceIndex getAffIndex()
const{
205 return affordanceIndex;
208 void set_affordance(AffordanceIndex a){
221 std::pair<bool, float> getOrientation(){
223 return std::pair<bool, float>(rotation_valid, bf.pose.q.GetAngle());
226 b2Transform pose()
const{
230 void setPose(b2Transform t){
234 void setAsBox(
float w,
float l){
244 void subtractPose(b2Transform dPose){
245 bf.pose.p.x-=dPose.p.x;
246 bf.pose.p.y-=dPose.p.y;
247 addToOrientation(-dPose.q.GetAngle());
251 return bf.halfLength;
258 void setOrientation(
float,
float);
260 std::vector <b2Vec2> vertices()
const;
270 enum resultType {successful =0, crashed =1, safeForNow=2};
271 resultType resultCode= resultType::successful;
274 b2Transform endPose = b2Transform(b2Vec2(0.0, 0.0), b2Rot(0));
280 simResult(resultType code): resultCode(code){
289 std::vector <b2Vec2> GetLocalPoints( std::vector <b2Vec2>,
const b2Body *);
Definition: threshold.h:10
Definition: graphTools.h:453
Definition: disturbance.h:47
bool match(const BodyFeatures &, Bundle *bundle=NULL, b2Transform t=b2Transform_zero) const
Definition: disturbance.cpp:3
Definition: disturbance.h:24
Definition: disturbance.h:17
Definition: disturbance.h:113
Definition: disturbance.h:269