randomDemoRecorder.cpp
Go to the documentation of this file.
1 
18 #include "randomDemoRecorder.hpp"
19 
20 using namespace ISM;
21 using namespace std;
22 namespace po = boost::program_options;
23 namespace fs = boost::filesystem;
24 
25 
26 double RandomDemoRecorder::frand(double min, double max)
27 {
28  double f = (double)rand() / RAND_MAX;
29  return min + f * (max - min);
30 }
31 
32 void RandomDemoRecorder::generateDemoRecording (string dbfile, unsigned objects, unsigned timesteps, bool genRanOrientsAdditionally)
33 {
34  //string dbfile = "/homes/students/hanselma/testDBs/demo_recordings/record.sqlite.demo_recording_" + to_string(objects) + "_" + to_string(timesteps);
35  double directioncos = cos(0.0 * (boost::math::constants::pi<double>() / 180.0));
36  double directionsin = sin(0.0 * (boost::math::constants::pi<double>() / 180.0));
37  RecorderPtr rec (new Recorder(dbfile));
38  //We can leave y constant to simulate a plane
39  double y = 0;
40  vector<TrackPtr> trackVector;
41  for (unsigned object = 0; object < objects; ++object)
42  {
43  TrackPtr track(new Track());
44  double x = frand(0, 1.0);
45  double z = frand(0, 1.0);
46  double angle = frand(0, boost::math::constants::pi<double>() * 2);
47  for (unsigned timestep = 0; timestep < timesteps; ++timestep)
48  {
49  //Calculates direction based on current direction. Sharp angles are possible, but only in edge cases
50  angle += (frand(boost::math::constants::pi<double>() * (-1), boost::math::constants::pi<double>())) * pow(frand(0, 1.0), 2);
51  double u = frand(0, 1.0);
52  double radius = frand(0, 0.01) * sqrt(u);
53  double xTranslation = radius * cos(angle);
54  double zTranslation = radius * sin(angle);
55  x += xTranslation;
56  if (x > 1)
57  {
58  x -= 1;
59  }
60  else if (x < -1)
61  {
62  x += 1;
63  }
64  z += zTranslation;
65  if (z > 1)
66  {
67  z -= 1;
68  }
69  else if (z < -1)
70  {
71  z += 1;
72  }
73 
74  ObjectPtr o;
75  if(genRanOrientsAdditionally)
76  {
77  o = ObjectPtr(new Object(string("testobj") + to_string(object), new Pose(new Point(x, y, z), new Quaternion(0.0, sin(angle), 0.0, cos(angle))), to_string(object)));
78  }
79  else
80  {
81  o = ObjectPtr(new Object(string("testobj") + to_string(object), new Pose(new Point(x, y, z), new Quaternion(directionsin, 0.0, 0.0, directioncos)), to_string(object)));
82  }
83  track->objects.push_back(o);
84  }
85  trackVector.push_back(track);
86  }
87  TracksPtr tracks(new Tracks(trackVector));
88  vector<ObjectSetPtr> objectSets = tracks->toObjectSetVector();
89  for (ObjectSetPtr objectSet : objectSets)
90  {
91  rec->insert(objectSet, "demo_recording_" + to_string(objects) + "_" + to_string(timesteps));
92  }
93  /* std::vector<std::string> modeldatabases =
94  {
95  "/homes/students/hanselma/testDBs/topologies/record.sqlite.demo_recording_" + to_string(objects) + "_" + to_string(timesteps) + "_best",
96  "/homes/students/hanselma/testDBs/topologies/record.sqlite.demo_recording_" + to_string(objects) + "_" + to_string(timesteps) + "_best_naive",
97  "/homes/students/hanselma/testDBs/topologies/record.sqlite.demo_recording_" + to_string(objects) + "_" + to_string(timesteps) + "_star",
98  "/homes/students/hanselma/testDBs/topologies/record.sqlite.demo_recording_" + to_string(objects) + "_" + to_string(timesteps) + "_fullyMeshed",
99  "/homes/students/hanselma/testDBs/topologies/record.sqlite.demo_recording_" + to_string(objects) + "_" + to_string(timesteps) + "_fullyMeshed_naive"
100  };
101  std::cout<<"creating model dbs\n";
102  for (string model : modeldatabases)
103  {
104  cout<<"current path is "<<model<<endl;
105  for (ObjectSetPtr objectSet : objectSets)
106  {
107  TableHelperPtr localTableHelper(new TableHelper(model));
108  localTableHelper->dropRecordTables();
109  RecorderPtr localrec(new Recorder(model));
110  localrec->insert(objectSet, "demo_recording_" + to_string(objects) + "_" + to_string(timesteps));
111  }
112  }*/
113  printYellow("Done. Objects are now stored in " + dbfile + "\n");
114 }
115 
void printYellow(std::string text)
Definition: Util.cpp:33
boost::shared_ptr< Recorder > RecorderPtr
Definition: Recorder.hpp:52
void generateDemoRecording(std::string dbfile, unsigned objects, unsigned timesteps, bool genRanOrientsAdditionally)
boost::shared_ptr< ObjectSet > ObjectSetPtr
Definition: ObjectSet.hpp:53
boost::shared_ptr< Tracks > TracksPtr
Definition: Tracks.hpp:42
double frand(double min, double max)
boost::shared_ptr< Track > TrackPtr
Definition: Track.hpp:55
this namespace contains all generally usable classes.
boost::shared_ptr< Object > ObjectPtr
Definition: Object.hpp:82


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:40