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;
49 b2Transform pose {b2Transform(b2Vec2(0,0), b2Rot(0))} ;
50 float halfLength=MIN_BODY_DIMENSION;
51 float halfWidth=MIN_BODY_DIMENSION;
53 b2BodyType bodyType = b2_dynamicBody;
55 b2Shape::Type shape = b2Shape::e_polygon;
62 void setHalfLength(
const float & f){
63 if (f<MIN_BODY_DIMENSION){
64 halfLength=MIN_BODY_DIMENSION;
71 void setHalfWidth(
const float & f){
72 if (f<MIN_BODY_DIMENSION){
73 halfWidth=MIN_BODY_DIMENSION;
97 return width()*length();
100 std::vector <b2Vec2> vertices()
const;
102 std::vector <cv::Point2f> vertices_cv()
const;
104 bool is_point()
const{
105 return halfWidth==MIN_BODY_DIMENSION && halfLength==MIN_BODY_DIMENSION;
109 return Bundle(pose.p.x, pose.p.y, pose.q.GetAngle(), halfWidth, halfLength);
117 friend class ControlInterface;
119 AffordanceIndex affordanceIndex = NONE;
121 bool rotation_valid=0;
123 void setOrientation(
float f){
128 void addToOrientation(
float dtheta){
130 setOrientation(bf.pose.q.GetAngle()+dtheta);
133 setOrientation(dtheta);
158 affordanceIndex=AVOID;
162 bf.pose=b->GetTransform();
163 b2Fixture * fixture =b->GetFixtureList();
164 bf.shape=(fixture->GetShape()->GetType());
166 if (bf.shape==b2Shape::e_polygon){
167 b2PolygonShape * poly=(b2PolygonShape*)fixture->GetShape();
168 std::vector <b2Vec2> local_vertices=arrayToVec(poly->m_vertices, poly->m_count);
171 float minx=(std::min_element(local_vertices.begin(), local_vertices.end(), compareX)).base()->x;
172 float miny=(std::min_element(local_vertices.begin(), local_vertices.end(), compareY)).base()->y;
173 float maxx=(std::max_element(local_vertices.begin(), local_vertices.end(), compareX)).base()->x;
174 float maxy=(std::max_element(local_vertices.begin(), local_vertices.end(), compareY)).base()->y;
175 bf.halfLength=(fabs(maxy-miny))/2;
176 bf.halfWidth=(fabs(maxx-minx))/2;
182 float getAngle(b2Transform);
184 float getAngle(b2Body* b){
185 return getAngle(b->GetTransform());
188 void setPosition(b2Vec2 pos){
189 bf.pose.p.Set(pos.x, pos.y);
192 void setPosition(
float x,
float y){
196 b2Vec2 getPosition()
const{
205 AffordanceIndex getAffIndex()
const{
206 return affordanceIndex;
209 void set_affordance(AffordanceIndex a){
222 std::pair<bool, float> getOrientation(){
224 return std::pair<bool, float>(rotation_valid, bf.pose.q.GetAngle());
227 b2Transform pose()
const{
231 void setPose(b2Transform t){
235 void setAsBox(
float w,
float l){
245 void subtractPose(b2Transform dPose){
246 bf.pose.p.x-=dPose.p.x;
247 bf.pose.p.y-=dPose.p.y;
248 addToOrientation(-dPose.q.GetAngle());
252 return bf.halfLength;
259 void setOrientation(
float,
float);
261 std::vector <b2Vec2> vertices()
const;
271 enum resultType {successful =0, crashed =1, safeForNow=2};
272 resultType resultCode= resultType::successful;
275 b2Transform endPose = b2Transform(b2Vec2(0.0, 0.0), b2Rot(0));
281 simResult(resultType code): resultCode(code){
290 std::vector <b2Vec2> GetLocalPoints( std::vector <b2Vec2>,
const b2Body *);
Definition: disturbance.h:47
bool match(const BodyFeatures &, Bundle *bundle=NULL, b2Transform t=b2Transform_zero) const
Definition: disturbance.cpp:3
Definition: threshold.h:10
Definition: graphTools.h:453
Definition: disturbance.h:24
Definition: disturbance.h:17
Definition: disturbance.h:114
Definition: disturbance.h:270