Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "volt_distr/volt_distr_viz.h"
00008
00009 #define ROWS 8
00010 #define COLS ROWS
00011 #define C_WIDTH 75 // Width of each channel (px)
00012 #define C_HEIGHT C_WIDTH // Height of each channel (px)
00013 #define P_WIDTH (C_WIDTH * COLS) // Width of plotter window (px)
00014 #define P_HEIGHT (C_HEIGHT * ROWS) // Height of plotter window (px)
00015 #define X_START 0
00016 #define Y_START X_START
00017 #define X_STEP C_WIDTH
00018 #define Y_STEP X_STEP
00019 #define MAX_COLOR 65535
00020
00021 VoltDistrViz::~VoltDistrViz()
00022 {
00023 delete plotter_;
00024 }
00025
00029 void VoltDistrViz::init(const std::string& file_name)
00030 {
00031 is_ok_ = true;
00032 file_.open(file_name.c_str());
00033
00034 if (!file_.is_open())
00035 {
00036 ROS_ERROR("Cannot open %s. Imaging will be disabled.",
00037 file_name.c_str());
00038 is_ok_ = false;
00039 return;
00040 }
00041
00042
00043 PlotterParams params;
00044
00045
00046
00047 params.setplparam("BG_COLOR", (char*) "none");
00048
00049 plotter_ = new SVGPlotter(cin, file_, cerr, params);
00050
00051 if (plotter_->openpl() < 0)
00052 {
00053 ROS_ERROR("Cannot initialize plotter. Imaging will be disabled.");
00054 is_ok_ = false;
00055 return;
00056 }
00057
00058
00059 plotter_->space(0, 0, P_WIDTH, P_HEIGHT);
00060 plotter_->pencolorname("white");
00061 plotter_->filltype(1);
00062 plotter_->erase();
00063
00064
00065 for (int y = ROWS - 1; y >= 0; y--)
00066 {
00067 for (int x = 0; x < COLS; x++)
00068 {
00069 if (!((x == 0 && y == 0) || (x == 0 && y == ROWS - 1) ||
00070 (x == COLS - 1 && y == 0) ||
00071 (x == COLS - 1 && y == ROWS - 1)))
00072 {
00073 boost::array<int, 4> coords;
00074 coords[0] = x * X_STEP + X_START;
00075 coords[1] = y * Y_STEP + Y_START;
00076 coords[2] = (x + 1) * X_STEP + X_START;
00077 coords[3] = (y + 1) * Y_STEP + Y_START;
00078 coords_.push_back(coords);
00079 }
00080 }
00081 }
00082 }
00083
00089 void VoltDistrViz::draw(const boost::array<double, 60>& percents)
00090 {
00091 if (!is_ok_)
00092 return;
00093
00094 for (int i = 0; i < 60; i++)
00095 {
00096
00097 if (percents[i] > 0.5)
00098 {
00099
00100 int red = MAX_COLOR * 2 * (percents[i] - .5);
00101 plotter_->fillcolor(red, 0, 0);
00102 }
00103 else
00104 {
00105
00106 int blue = MAX_COLOR * 2 * (.5 - percents[i]);
00107 plotter_->fillcolor(0, 0, blue);
00108 }
00109 plotter_->box(coords_[i][0], coords_[i][1], coords_[i][2], coords_[i][3]);
00110 plotter_->endpath();
00111
00112
00113 plotter_->move((coords_[i][0] + coords_[i][2]) / 2,
00114 (coords_[i][1] + coords_[i][3]) / 2);
00115 ostringstream volt;
00116 volt << fixed << setprecision(2) << (percents[i] * 100) << '%';
00117 plotter_->alabel('c', 'c', volt.str().c_str());
00118 plotter_->endpath();
00119 }
00120
00121 plotter_->closepl();
00122 file_.close();
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135