Bratmobile
worldbuilder.h
1 #ifndef WORLDBUILDER_H
2 #define WORLDBUILDER_H
3 #include "sensor.h"
4 
6  int iteration=0;
7  char bodyFile[100];
8  float simulationStep=BOX2DRANGE;
9  int bodies=0;
10  std::vector <BodyFeatures> world_objects;
11  protected:
12  friend class Configurator;
13  public:
14  enum CLUSTERING{BOX=0, KMEANS=1, PARTITION=2}; //BOX: bounding box around points
16  CompareCluster()=default;
17 
18  bool operator()(const BodyFeatures & b1, const BodyFeatures & b2){ //distances of centre from start
19  bool result=false;
20  if (fabs(atan2(b1.pose.p.y, b1.pose.p.x))< fabs(atan2(b2.pose.p.y, b2.pose.p.x)) && b1.pose.p.Length()<= b2.pose.p.Length()){
21  result=true;
22  }
23  return result;
24  }
25  };
26 
27  std::pair <CoordinateContainer, bool> salientPoints(b2Transform, const CoordinateContainer &, std::pair <Pointf, Pointf>); //gets points from the raw data that are relevant to the task based on bounding boxes
28  //std::pair<points, obstaclestillthere>
29  b2Body* makeBody(b2World&, BodyFeatures);
30 
36  std::vector <BodyFeatures> processData(const CoordinateContainer&, const b2Transform&);
37 
38  std::vector <BodyFeatures> cluster_data(const CoordinateContainer &, const b2Transform&, CLUSTERING clustering=PARTITION);
39 
40  bool checkDisturbance(Pointf, bool&,Task * curr =NULL, float range=0.025);
41 
42  std::vector <BodyFeatures> getFeatures(const CoordinateContainer &, b2Transform, CLUSTERING clustering=PARTITION);
43 
52  void buildWorld(b2World&,b2Transform, Direction, Disturbance disturbance=Disturbance(), float halfWindowWidth=0.15, CLUSTERING clustering=CLUSTERING::PARTITION, Task * task=NULL);
53 
54  //returns top and bottom of rotated rectangle (not side-specific)
55  std::pair <Pointf, Pointf> bounds(Direction, b2Transform t, float boxLength, float halfWindowWidth,std::vector <Pointf> *_bounds=NULL); //returns bottom and top of bounding box
56 
66  b2PolygonShape object_filtering_box(float halfWindowWidth, float boxLength, b2Transform start, Direction d);
67 
68 
69  std::pair <bool, BodyFeatures> bounding_approx_poly(std::vector <cv::Point2f>nb);
70 
76  std::vector <std::vector<cv::Point2f>> kmeans_clusters( std::vector <cv::Point2f>, std::vector <cv::Point2f>&);
77 
83  std::vector <std::vector<cv::Point2f>> partition_clusters( std::vector <cv::Point2f>);
84 
85  b2Vec2 averagePoint(const CoordinateContainer &, Disturbance &, float rad = 0.025); //finds centroid of a poitn cluster, return position vec difference
86 
87  int getBodies(){
88  return bodies;
89  }
90 
91  int add_body_count(){
92  bodies++;
93  }
94 
95  void resetBodies(){
96  bodies =0;
97  }
98 
99  void add_iteration(int i=1){
100  iteration+=1;
101  }
102 
103  b2Body * get_robot(b2World *);
104 
105  b2Fixture * get_chassis(b2Body *);
106 
107  b2AABB makeRobotSensor(b2Body*, Disturbance *goal); //returns bounding box in world coord
108 
109 
110  std::vector <BodyFeatures>& get_world_objects(){
111  return world_objects;
112  }
113 
114  void set_world_objects(const std::vector <BodyFeatures>& wo){
115  world_objects=wo;
116  }
117 
118 };
119 #endif
Definition: disturbance.h:45
Definition: configurator.h:17
Wrapper around cv::Point2f for customisation purposes.
Definition: sensor.h:12
Definition: task.h:19
Definition: worldbuilder.h:5
std::vector< std::vector< cv::Point2f > > partition_clusters(std::vector< cv::Point2f >)
Clusters points using the partition algorithm.
Definition: worldbuilder.cpp:74
std::vector< std::vector< cv::Point2f > > kmeans_clusters(std::vector< cv::Point2f >, std::vector< cv::Point2f > &)
Clusters points using k-means algorithm.
Definition: worldbuilder.cpp:58
std::vector< BodyFeatures > processData(const CoordinateContainer &, const b2Transform &)
returns a bounding box encompassing all points provided
Definition: worldbuilder.cpp:93
b2PolygonShape object_filtering_box(float halfWindowWidth, float boxLength, b2Transform start, Direction d)
Makes a box.
Definition: worldbuilder.cpp:41
void buildWorld(b2World &, b2Transform, Direction, Disturbance disturbance=Disturbance(), float halfWindowWidth=0.15, CLUSTERING clustering=CLUSTERING::PARTITION, Task *task=NULL)
Creates bodies (objects) in the box2d world.
Definition: worldbuilder.cpp:223
Definition: disturbance.h:112
Definition: worldbuilder.h:15