12 std::string
Value::toJSONString()
const {
13 std::ostringstream ss;
20 ss<<
'"'<<_string<<
'"';
break;
23 for (std::vector<
Value>::const_iterator it = _array.begin(); it != _array.end(); ++it) {
24 if (it != _array.begin()) ss <<
',';
25 ss << it->toJSONString();
30 ss <<
'{' << _object->toJSON() <<
'}';
39 std::string
Params::toJSON()
const {
40 std::ostringstream ss;
41 for(std::map<std::string,
Value>::const_iterator it = _values.begin(); it != _values.end(); ++it)
42 ss << (it==_values.begin()?
"":
", ") <<
"\"" << it->first <<
"\":" << it->second.toJSONString();
47 KeyValueMap::iterator it = _values.find(key);
49 if (it == _values.end())
50 return value_not_found;
52 Value val = it->second;
83 char * user_dir = getenv(
"USERPROFILE");
85 user_dir = getenv(
"HOME");
88 std::string file_name(user_dir);
89 file_name.append(
"/.vibes.json");
100 channel=fopen(fileName.c_str(),
"a");
116 msg =
"{\"action\":\"new\","
117 "\"figure\":\""+(figureName.empty()?
current_fig:figureName)+
"\"}\n\n";
125 msg=
"{\"action\":\"clear\","
126 "\"figure\":\""+(figureName.empty()?
current_fig:figureName)+
"\"}\n\n";
134 msg=
"{\"action\":\"close\","
135 "\"figure\":\""+(figureName.empty()?
current_fig:figureName)+
"\"}\n\n";
140 void saveImage(
const std::string &fileName,
const std::string &figureName)
143 msg=
"{\"action\":\"export\","
144 "\"figure\":\""+(figureName.empty()?
current_fig:figureName)+
"\","
145 "\"file\":\""+fileName+
"\"}\n\n";
164 if (params[
"figure"].empty()) params[
"figure"] =
current_fig;
165 params[
"action"] =
"view";
166 params[
"box"] =
"auto";
168 fputs(
Value(params).toJSONString().append(
"\n\n").c_str(),
channel);
172 void axisLimits(
const double &x_lb,
const double &x_ub,
const double &y_lb,
const double &y_ub,
Params params)
176 if (params[
"figure"].empty()) params[
"figure"] =
current_fig;
177 params[
"action"] =
"view";
178 params[
"box"] = (
Vec4d){x_lb,x_ub,y_lb,y_ub};
180 fputs(
Value(params).toJSONString().append(
"\n\n").c_str(),
channel);
188 void drawBox(
const double &x_lb,
const double &x_ub,
const double &y_lb,
const double &y_ub,
Params params)
191 msg[
"action"] =
"draw";
193 msg[
"shape"] = (params,
"type",
"box",
"bounds", (
Vec4d){x_lb,x_ub,y_lb,y_ub});
195 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
201 assert(!bounds.empty());
202 assert(bounds.size()%2 == 0);
205 msg[
"action"] =
"draw";
207 msg[
"shape"] = (params,
"type",
"box",
"bounds", vector<
Value>(bounds.begin(),bounds.end()));
209 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
214 void drawEllipse(
const double &cx,
const double &cy,
const double &a,
const double &b,
const double &rot,
Params params)
217 msg[
"action"] =
"draw";
219 msg[
"shape"] = (params,
"type",
"ellipse",
220 "center", (
Vec2d){cx,cy},
221 "axis", (
Vec2d){a,b},
224 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
229 const double &sxx,
const double &sxy,
const double &syy,
230 const double &K,
Params params)
233 msg[
"action"] =
"draw";
235 msg[
"shape"] = (params,
"type",
"ellipse",
236 "center", (
Vec2d){cx,cy},
237 "covariance", (
Vec4d){sxx,sxy,sxy,syy},
240 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
245 const double &K,
Params params)
248 msg[
"action"] =
"draw";
250 msg[
"shape"] = (params,
"type",
"ellipse",
251 "center", vector<
Value>(center.begin(),center.end()),
252 "covariance", vector<
Value>(cov.begin(),cov.end()),
255 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
262 msg[
"action"] =
"draw";
264 msg[
"shape"] = (params,
"type",
"boxes",
267 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
274 msg[
"action"] =
"draw";
276 msg[
"shape"] = (params,
"type",
"boxes union",
279 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
286 msg[
"action"] =
"draw";
288 msg[
"shape"] = (params,
"type",
"line",
291 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
295 void drawLine(
const std::vector<
double> &x,
const std::vector<
double> &y,
Params params)
298 std::vector<
Value> points;
299 std::vector<
double>::const_iterator itx = x.begin();
300 std::vector<
double>::const_iterator ity = y.begin();
301 while (itx != x.end() && ity != y.end()) {
302 points.push_back( (
Vec2d){*itx++,*ity++} );
306 msg[
"action"] =
"draw";
308 msg[
"shape"] = (params,
"type",
"line",
311 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
320 msg[
"action"] =
"draw";
322 msg[
"shape"] = (params,
"type",
"group",
325 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
329 void clearGroup(
const std::string &figureName,
const std::string &groupName)
332 msg[
"action"] =
"clear";
333 msg[
"figure"] = figureName;
334 msg[
"group"] = groupName;
336 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
346 void removeObject(
const std::string &figureName,
const std::string &objectName)
349 msg[
"action"] =
"delete";
350 msg[
"figure"] = figureName;
351 msg[
"object"] = objectName;
353 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
367 msg[
"action"] =
"set";
368 msg[
"figure"] = figureName;
369 msg[
"properties"] = properties;
371 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
384 msg[
"action"] =
"set";
385 msg[
"figure"] = figureName;
386 msg[
"object"] = objectName;
387 msg[
"properties"] = properties;
389 fputs(
Value(msg).toJSONString().append(
"\n\n").c_str(),
channel);
void beginDrawing(const std::string &fileName)
Start VIBes in file saving mode. All commands are saved to the specified file.
void removeObject(const std::string &figureName, const std::string &objectName)
Delete the named graphical object objectName from figure figureName.
void setObjectProperties(const std::string &objectName, const Params &properties)
Assign properties to the named object objectName in current figure.
void drawLine(const std::vector< double > &x, const std::vector< double > &y, Params params)
Draw a 2-D line from the list of abscissae x and the list of ordinates y.
string current_fig
Current figure name (client-maintained state)
void clearGroup(const std::string &groupName)
Clear the contents of the group groupName in current figure.
void drawEllipse(const double &cx, const double &cy, const double &a, const double &b, const double &rot, Params params)
Draw an ellipse centered at (cx, cy), with semi-major and minor axes a and b, and rotated by rot degr...
void setObjectProperties(const std::string &figureName, const std::string &objectName, const Params &properties)
Assign properties to the named object objectName in figure figureName.
Vec< double, 2 > Vec2d
A 2D floating point vector.
void endDrawing()
Close connection to the viewer or the drawing file.
void drawBoxes(const std::vector< std::vector< double > > &bounds, Params params)
Draw a list of N-D rectangles from a list of list of bounds in the form ((x_lb_1, x_ub_1...
void drawConfidenceEllipse(const double &cx, const double &cy, const double &sxx, const double &sxy, const double &syy, const double &K, Params params)
Draw a 2-D confidence ellipse centered at (cx, cy), with covariance sxx, sxy, syy and scale K...
Vec< double, 4 > Vec4d
A 4D floating point vector.
void beginDrawing()
Start VIBes in connected mode: connects to the VIBes viewer.
FILE * channel
Current communication file descriptor.
void drawBoxesUnion(const std::vector< std::vector< double > > &bounds, Params params)
Computes and draw the union of a list of N-D rectangles, from a list of list of bounds in the form ((...
void clearGroup(const std::string &figureName, const std::string &groupName)
Clear the contents of the group groupName in figure figureName.
void drawBox(const vector< double > &bounds, Params params)
Draw a N-D box from a list of bounds in the form (x_lb, x_ub, y_lb, y_ub, z_lb, z_ub, ...)
void removeObject(const std::string &objectName)
Delete the named graphical object objectName from current figure.
void drawLine(const std::vector< std::vector< double > > &points, Params params)
Draw a N-D line from the list of coordinates points in the form ((x_1, y_1, z_1, ...), (x_2, y_2, z_2, ...), ...)
void newGroup(const std::string &name, Params params)
Create a new group with the specified name.
void drawConfidenceEllipse(const vector< double > ¢er, const vector< double > &cov, const double &K, Params params)
Draw a N-D confidence ellipse centered at center, with covariance in cov and scale K...
void drawBox(const double &x_lb, const double &x_ub, const double &y_lb, const double &y_ub, Params params)
Draw a 2-D box with a left lower corner at (x_lb, y_lb) and a right upper corner at (x_ub...