ed
test_wm.cpp
Go to the documentation of this file.
1 #include <ed/world_model.h>
2 #include <ed/update_request.h>
4 
5 #include <ros/time.h> // Why do we need this?
6 
7 // Profiling
8 #include <tue/profiling/timer.h>
9 
10 // ----------------------------------------------------------------------------------------------------
11 
13 {
15 
16  req.setType("map", "waypoint");
17  req.setType("table", "object");
18  req.setType("bottle", "object");
19 
20  boost::shared_ptr<ed::TransformCache> t1(new ed::TransformCache());
21  t1->insert(0, geo::Pose3D(1, 2, 3, 0, 0, M_PI / 2));
22  req.setRelation("map", "table", t1);
23 
24  boost::shared_ptr<ed::TransformCache> t2(new ed::TransformCache());
25  t2->insert(0, geo::Pose3D(1, 0, 0.75).inverse());
26  req.setRelation("bottle", "table", t2);
27 
28  std::string parent_id = "bottle";
29  for(unsigned int i = 0; i < 100000; ++i)
30  {
32  id << "e" << i;
33  req.setType(id.str(), "object");
34 
35  boost::shared_ptr<ed::TransformCache> t1(new ed::TransformCache());
36  t1->insert(0, geo::Pose3D(1, 2, 3, 0, 0, M_PI / 2));
37  req.setRelation(parent_id, id.str(), t1);
38 
39  parent_id = id.str();
40  }
41 
42  wm.update(req);
43 }
44 
45 // ----------------------------------------------------------------------------------------------------
46 
47 void profile(const ed::WorldModel& wm)
48 {
49  unsigned int N = 1000;
50 
51  ed::UUID id1 = "map";
52  ed::UUID id2 = "e100";
53 
54  tue::Timer timer;
55  timer.start();
56 
57  geo::Pose3D tr;
58  for(unsigned int i = 0; i < N; ++i)
59  {
60  wm.calculateTransform(id1, id2, 0, tr);
61  }
62 
63  std::cout << timer.getElapsedTimeInMilliSec() / N << " ms" << std::endl;
64 }
65 
66 // ----------------------------------------------------------------------------------------------------
67 
69 {
70  ed::UUID id1 = "map";
71  ed::UUID id2 = "bottle";
72 
73  geo::Pose3D tr;
74  if (wm.calculateTransform(id1, id2, 0, tr))
75  {
76  std::cout << tr << std::endl;
77  }
78 }
79 
80 // ----------------------------------------------------------------------------------------------------
81 
82 int main(int argc, char **argv)
83 {
84  ros::Time::init(); // Why do we need this?
85 
86  ed::WorldModel wm;
87  buildWorldModel(wm);
88 
90  if (argc > 1)
91  cmd = argv[1];
92 
93  if (cmd == "profile")
94  profile(wm);
95  else
96  testCorrectness(wm);
97 
98  return 0;
99 }
ed::WorldModel
Definition: world_model.h:21
ed::UpdateRequest
Definition: update_request.h:24
std::string
profile
void profile(const ed::WorldModel &wm)
Definition: test_wm.cpp:47
std::stringstream
geo::Transform3T
ed::WorldModel::update
void update(const UpdateRequest &req)
Definition: world_model.cpp:23
tue::Timer::start
void start()
std::cout
testCorrectness
void testCorrectness(const ed::WorldModel &wm)
Definition: test_wm.cpp:68
update_request.h
tue::Timer::getElapsedTimeInMilliSec
long double getElapsedTimeInMilliSec() const
main
int main(int argc, char **argv)
Definition: test_wm.cpp:82
ed::WorldModel::calculateTransform
bool calculateTransform(const UUID &source, const UUID &target, const Time &time, geo::Pose3D &tf) const
Definition: world_model.cpp:246
ed::UUID
Definition: uuid.h:10
timer.h
tue::Timer
ed::UpdateRequest::setType
void setType(const UUID &id, const std::string &type)
Definition: update_request.h:106
ed::UpdateRequest::setRelation
void setRelation(const UUID &id1, const UUID &id2, const RelationConstPtr &r)
Definition: update_request.h:141
std::endl
T endl(T... args)
transform_cache.h
cmd
char * cmd[]
Definition: repl.cpp:11
buildWorldModel
void buildWorldModel(ed::WorldModel &wm)
Definition: test_wm.cpp:12
ed::TransformCache
Definition: transform_cache.h:10
world_model.h