3 #include <jsoncpp/json/json.h>
7 std::chrono::high_resolution_clock::time_point TSTART_;
8 std::chrono::high_resolution_clock::time_point TEND_;
9 inline void TSTART() { TSTART_ = std::chrono::high_resolution_clock::now(); }
10 inline void TEND() { TEND_ = std::chrono::high_resolution_clock::now(); }
13 std::chrono::duration<double> DT_;
14 DT_ = std::chrono::duration_cast<std::chrono::duration<double>>(
19 inline void TPRINT(const char *what)
21 std::cerr << what << ": " << TDIFF() << std::endl;
26 Json::Value jvi; // JSON input
27 Json::Value jvo; // JSON output
29 if (jvi["init"] == Json::nullValue) {
30 std::cerr << "I need `init` in JSON input scenario";
31 std::cerr << std::endl;
34 if (jvi["goal"] == Json::nullValue) {
35 std::cerr << "I need `goal` in JSON input scenario";
36 std::cerr << std::endl;
39 if (jvi["goals"] == Json::nullValue) {
40 std::cerr << "I need `goals` in JSON input scenario";
41 std::cerr << std::endl;
44 if (jvi["obst"] == Json::nullValue) {
45 std::cerr << "I need `obst` in JSON input scenario";
46 std::cerr << std::endl;
51 rrts.nodes().front().x(jvi["init"][0].asDouble());
52 rrts.nodes().front().y(jvi["init"][1].asDouble());
53 rrts.nodes().front().h(jvi["init"][2].asDouble());
56 tmp_node.x(jvi["goal"][0].asDouble());
57 tmp_node.y(jvi["goal"][1].asDouble());
58 tmp_node.h(jvi["goal"][2].asDouble());
59 rrts.goals().push_back(tmp_node);
60 for (auto g: jvi["goals"]) {
61 tmp_node.x(g[0].asDouble());
62 tmp_node.y(g[1].asDouble());
63 tmp_node.h(g[2].asDouble());
64 rrts.goals().push_back(tmp_node);
68 Obstacle tmp_obstacle;
69 for (auto o: jvi["obst"]) {
70 tmp_obstacle.poly().clear();
72 double tmp_x = c[0].asDouble();
73 double tmp_y = c[1].asDouble();
74 auto tmp_tuple = std::make_tuple(tmp_x, tmp_y);
75 tmp_obstacle.poly().push_back(tmp_tuple);
77 rrts.obstacles().push_back(tmp_obstacle);
81 double edist_init_goal = sqrt(
83 rrts.nodes().front().x()
84 - rrts.goals().front().x(),
88 rrts.nodes().front().y()
89 - rrts.goals().front().y(),
94 rrts.nodes().front().x(), edist_init_goal,
95 rrts.nodes().front().y(), edist_init_goal,
104 jvo["time"] = TDIFF();
107 jvo["iterations"] = rrts.icnt();
110 jvo["init"][0] = rrts.nodes().front().x();
111 jvo["init"][1] = rrts.nodes().front().y();
112 jvo["init"][2] = rrts.nodes().front().h();
115 if (rrts.path().size() > 0) {
116 jvo["cost"] = cc(*rrts.path().back());
122 if (rrts.path().size() > 0) {
123 jvo["goal"][0] = rrts.path().back()->x();
124 jvo["goal"][1] = rrts.path().back()->y();
125 jvo["goal"][2] = rrts.path().back()->h();
129 unsigned int pcnt = 0;
130 for (auto n: rrts.path()) {
131 jvo["path"][pcnt][0] = n->x();
132 jvo["path"][pcnt][1] = n->y();
133 jvo["path"][pcnt][2] = n->h();
134 if (n->t(RRTNodeType::cusp))
136 if (n->t(RRTNodeType::connected))
140 jvo["cusps-in-path"] = cu;
141 jvo["connecteds-in-path"] = co;
144 unsigned int gcnt = 0;
145 for (auto g: rrts.goals()) {
146 jvo["goals"][gcnt][0] = g.x();
147 jvo["goals"][gcnt][1] = g.y();
148 jvo["goals"][gcnt][2] = g.h();
153 unsigned int ocnt = 0;
154 for (auto o: rrts.obstacles()) {
155 unsigned int ccnt = 0;
156 for (auto c: o.poly()) {
157 jvo["obst"][ocnt][ccnt][0] = std::get<0>(c);
158 jvo["obst"][ocnt][ccnt][1] = std::get<1>(c);
165 jvo["nodes"] = (unsigned int) rrts.nodes().size();
168 // unsigned int ncnt = 0;
169 // for (auto n: rrts.nodes()) {
170 // jvo["nodes_x"][ncnt] = n.x();
171 // jvo["nodes_y"][ncnt] = n.y();
172 // //jvo["nodes_h"][ncnt] = n.h();
176 std::cout << jvo << std::endl;