| 1 | #include "Plotter2.h"
|
|---|
| 2 |
|
|---|
| 3 | namespace asap {
|
|---|
| 4 |
|
|---|
| 5 | Plotter2RectInfo::Plotter2RectInfo() {
|
|---|
| 6 | xmin = 0.0;
|
|---|
| 7 | xmax = 1.0;
|
|---|
| 8 | ymin = 0.0;
|
|---|
| 9 | ymax = 1.0;
|
|---|
| 10 | color = 15; // gray
|
|---|
| 11 | fill = 4; // hatch
|
|---|
| 12 | width = 1;
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | Plotter2RectInfo::~Plotter2RectInfo() {
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | Plotter2DataInfo::Plotter2DataInfo() {
|
|---|
| 19 | xData.clear();
|
|---|
| 20 | yData.clear();
|
|---|
| 21 |
|
|---|
| 22 | drawLine = true;
|
|---|
| 23 | lineStyle = 1; // solid line
|
|---|
| 24 | lineWidth = 1;
|
|---|
| 25 | lineColor = -1; // undefined (default color should be assigned)
|
|---|
| 26 |
|
|---|
| 27 | drawMarker = false;
|
|---|
| 28 | markerType = 20; // small circle
|
|---|
| 29 | markerSize = 1.0;
|
|---|
| 30 | markerColor = 1; // default foreground color (black)
|
|---|
| 31 |
|
|---|
| 32 | hasData = false; // has no data
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | Plotter2DataInfo::~Plotter2DataInfo() {
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | Plotter2ViewportInfo::Plotter2ViewportInfo() {
|
|---|
| 39 | showViewport = true;
|
|---|
| 40 |
|
|---|
| 41 | vpPosXMin = 0.1;
|
|---|
| 42 | vpPosXMax = 0.9;
|
|---|
| 43 | vpPosYMin = 0.1;
|
|---|
| 44 | vpPosYMax = 0.9;
|
|---|
| 45 |
|
|---|
| 46 | vpRangeXMin = 0.0;
|
|---|
| 47 | vpRangeXMax = 1.0;
|
|---|
| 48 | vpRangeYMin = 0.0;
|
|---|
| 49 | vpRangeYMax = 1.0;
|
|---|
| 50 | isAutoRangeX = true;
|
|---|
| 51 | isAutoRangeY = true;
|
|---|
| 52 | autoRangeMarginX = 0.0;
|
|---|
| 53 | autoRangeMarginY = 0.1;
|
|---|
| 54 |
|
|---|
| 55 | hasDataRange = false;
|
|---|
| 56 |
|
|---|
| 57 | nMajorTickWithinTickNumsX = 2;
|
|---|
| 58 | nMajorTickWithinTickNumsY = 2;
|
|---|
| 59 | isAutoTickIntervalX = true;
|
|---|
| 60 | isAutoTickIntervalY = true;
|
|---|
| 61 |
|
|---|
| 62 | numLocationX = "l";
|
|---|
| 63 | numLocationY = "b";
|
|---|
| 64 |
|
|---|
| 65 | fontSizeDef = 1.0;
|
|---|
| 66 |
|
|---|
| 67 | vpBColor = -1;
|
|---|
| 68 |
|
|---|
| 69 | vData.clear();
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | Plotter2ViewportInfo::~Plotter2ViewportInfo() {
|
|---|
| 73 | vData.clear();
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | void Plotter2ViewportInfo::adjustRange() {
|
|---|
| 77 | if (hasDataRange) {
|
|---|
| 78 | if (isAutoRangeX) {
|
|---|
| 79 | adjustRangeX(&vpRangeXMin, &vpRangeXMax);
|
|---|
| 80 | }
|
|---|
| 81 | if (isAutoRangeY) {
|
|---|
| 82 | adjustRangeY(&vpRangeYMin, &vpRangeYMax);
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | void Plotter2ViewportInfo::adjustRangeX(float* xmin, float* xmax) {
|
|---|
| 88 | float xmargin = (maxXData - minXData) * autoRangeMarginX;
|
|---|
| 89 | *xmin = minXData - xmargin;
|
|---|
| 90 | *xmax = maxXData + xmargin;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | void Plotter2ViewportInfo::adjustRangeY(float* ymin, float* ymax) {
|
|---|
| 94 | float ymargin = (maxYData - minYData) * autoRangeMarginY;
|
|---|
| 95 | *ymin = minYData - ymargin;
|
|---|
| 96 | *ymax = maxYData + ymargin;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | std::vector<float> Plotter2ViewportInfo::getRangeX() {
|
|---|
| 100 | float minX, maxX;
|
|---|
| 101 |
|
|---|
| 102 | if (isAutoRangeX) {
|
|---|
| 103 | adjustRangeX(&minX, &maxX);
|
|---|
| 104 | } else {
|
|---|
| 105 | minX = vpRangeXMin;
|
|---|
| 106 | maxX = vpRangeXMax;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | std::vector<float> res;
|
|---|
| 110 | res.clear();
|
|---|
| 111 | res.push_back(minX);
|
|---|
| 112 | res.push_back(maxX);
|
|---|
| 113 |
|
|---|
| 114 | return res;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | std::vector<float> Plotter2ViewportInfo::getRangeY() {
|
|---|
| 118 | float minY, maxY;
|
|---|
| 119 |
|
|---|
| 120 | if (isAutoRangeY) {
|
|---|
| 121 | adjustRangeY(&minY, &maxY);
|
|---|
| 122 | } else {
|
|---|
| 123 | minY = vpRangeYMin;
|
|---|
| 124 | maxY = vpRangeYMax;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | std::vector<float> res;
|
|---|
| 128 | res.clear();
|
|---|
| 129 | res.push_back(minY);
|
|---|
| 130 | res.push_back(maxY);
|
|---|
| 131 |
|
|---|
| 132 | return res;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | void Plotter2ViewportInfo::adjustTickInterval() {
|
|---|
| 136 | if (hasDataRange) {
|
|---|
| 137 | if (isAutoTickIntervalX) {
|
|---|
| 138 | adjustTickIntervalX();
|
|---|
| 139 | }
|
|---|
| 140 | if (isAutoTickIntervalY) {
|
|---|
| 141 | adjustTickIntervalY();
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | void Plotter2ViewportInfo::adjustTickIntervalX() {
|
|---|
| 147 | adjustTickIntervalX(vpRangeXMin, vpRangeXMax);
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | void Plotter2ViewportInfo::adjustTickIntervalX(const float xmin, const float xmax) {
|
|---|
| 151 | majorTickIntervalX = (float)pow(10.0, ceil(log10((xmax - xmin)/10.0)));
|
|---|
| 152 | if ((xmax - xmin) / majorTickIntervalX < 2.0) {
|
|---|
| 153 | majorTickIntervalX /= 10.0;
|
|---|
| 154 | }
|
|---|
| 155 | nMinorTickWithinMajorTicksX = 5;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | void Plotter2ViewportInfo::adjustTickIntervalY() {
|
|---|
| 159 | adjustTickIntervalY(vpRangeYMin, vpRangeYMax);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | void Plotter2ViewportInfo::adjustTickIntervalY(const float ymin, const float ymax) {
|
|---|
| 163 | majorTickIntervalY = (float)pow(10.0, ceil(log10((ymax - ymin)/10.0)));
|
|---|
| 164 | if ((ymax - ymin) / majorTickIntervalY < 2.0) {
|
|---|
| 165 | majorTickIntervalY /= 10.0;
|
|---|
| 166 | }
|
|---|
| 167 | nMinorTickWithinMajorTicksY = 5;
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | void Plotter2ViewportInfo::setData(const std::vector<float>& inXData, const std::vector<float>& inYData, const int id) {
|
|---|
| 171 | if (!hasDataRange) {
|
|---|
| 172 | minXData = inXData[0];
|
|---|
| 173 | maxXData = inXData[0];
|
|---|
| 174 | minYData = inYData[0];
|
|---|
| 175 | maxYData = inYData[0];
|
|---|
| 176 |
|
|---|
| 177 | hasDataRange = true;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | Plotter2DataInfo* info = &vData[id];
|
|---|
| 181 |
|
|---|
| 182 | info->xData.clear();
|
|---|
| 183 | info->xData.reserve(inXData.size());
|
|---|
| 184 | for (uint i = 0; i < inXData.size(); ++i) {
|
|---|
| 185 | info->xData.push_back(inXData[i]);
|
|---|
| 186 |
|
|---|
| 187 | if (!info->hasData) {
|
|---|
| 188 | updateXDataRange(inXData[i]);
|
|---|
| 189 | }
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | info->yData.clear();
|
|---|
| 193 | info->yData.reserve(inYData.size());
|
|---|
| 194 | for (uint i = 0; i < inYData.size(); ++i) {
|
|---|
| 195 | info->yData.push_back(inYData[i]);
|
|---|
| 196 |
|
|---|
| 197 | if (!info->hasData) {
|
|---|
| 198 | updateYDataRange(inYData[i]);
|
|---|
| 199 | }
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | if (info->hasData) {
|
|---|
| 203 | updateAllDataRanges();
|
|---|
| 204 | } else {
|
|---|
| 205 | info->hasData = true;
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | void Plotter2ViewportInfo::updateXDataRange(const float data) {
|
|---|
| 210 | if (data < minXData) {
|
|---|
| 211 | minXData = data;
|
|---|
| 212 | }
|
|---|
| 213 | if (maxXData < data) {
|
|---|
| 214 | maxXData = data;
|
|---|
| 215 | }
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | void Plotter2ViewportInfo::updateYDataRange(const float data) {
|
|---|
| 219 | if (data < minYData) {
|
|---|
| 220 | minYData = data;
|
|---|
| 221 | }
|
|---|
| 222 | if (maxYData < data) {
|
|---|
| 223 | maxYData = data;
|
|---|
| 224 | }
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | void Plotter2ViewportInfo::updateAllDataRanges() {
|
|---|
| 228 | minXData = vData[0].xData[0];
|
|---|
| 229 | maxXData = minXData;
|
|---|
| 230 | minYData = vData[0].yData[0];
|
|---|
| 231 | maxYData = minYData;
|
|---|
| 232 |
|
|---|
| 233 | for (uint i = 0; i < vData.size(); ++i) {
|
|---|
| 234 | for (uint j = 0; j < vData[i].xData.size(); ++j) {
|
|---|
| 235 | updateXDataRange(vData[i].xData[j]);
|
|---|
| 236 | updateYDataRange(vData[i].yData[j]);
|
|---|
| 237 | }
|
|---|
| 238 | }
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | void Plotter2ViewportInfo::getWorldCoordByWindowCoord(const float winX, const float winY, float* worldX, float* worldY) {
|
|---|
| 242 | float xratio = (winX - vpPosXMin) / (vpPosXMax - vpPosXMin);
|
|---|
| 243 | if (winX < 0.0) {
|
|---|
| 244 | xratio = 0.5;
|
|---|
| 245 | }
|
|---|
| 246 | *worldX = vpRangeXMin + xratio * (vpRangeXMax - vpRangeXMin);
|
|---|
| 247 | float yratio = (winY - vpPosYMin) / (vpPosYMax - vpPosYMin);
|
|---|
| 248 | if (winY < 0.0) {
|
|---|
| 249 | yratio = 0.5;
|
|---|
| 250 | }
|
|---|
| 251 | *worldY = vpRangeYMin + yratio * (vpRangeYMax - vpRangeYMin);
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | Plotter2::Plotter2() {
|
|---|
| 255 | filename = "";
|
|---|
| 256 | device = "xwindow";
|
|---|
| 257 | hasDevice = false;
|
|---|
| 258 |
|
|---|
| 259 | vInfo.clear();
|
|---|
| 260 | Plotter2ViewportInfo vi;
|
|---|
| 261 | vInfo.push_back(vi);
|
|---|
| 262 |
|
|---|
| 263 | hasDefaultViewport = true;
|
|---|
| 264 | currentViewportId = 0;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | Plotter2::~Plotter2() {
|
|---|
| 268 | close();
|
|---|
| 269 | vInfo.clear();
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | void Plotter2::setFileName(const std::string& inFilename) {
|
|---|
| 273 | filename = inFilename;
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | void Plotter2::setDevice(const std::string& inDevice) {
|
|---|
| 277 | device = inDevice;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | void Plotter2::open() {
|
|---|
| 281 | cpgopen((filename + "/" + device).c_str());
|
|---|
| 282 | hasDevice = true;
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | int Plotter2::addViewport(const float xmin, const float xmax, const float ymin, const float ymax) {
|
|---|
| 286 | Plotter2ViewportInfo vi;
|
|---|
| 287 |
|
|---|
| 288 | vi.vpPosXMin = xmin;
|
|---|
| 289 | vi.vpPosXMax = xmax;
|
|---|
| 290 | vi.vpPosYMin = ymin;
|
|---|
| 291 | vi.vpPosYMax = ymax;
|
|---|
| 292 |
|
|---|
| 293 | vInfo.push_back(vi);
|
|---|
| 294 | currentViewportId = vInfo.size() - 1;
|
|---|
| 295 |
|
|---|
| 296 | return currentViewportId;
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | void Plotter2::setViewport(const float xmin, const float xmax, const float ymin, const float ymax, const int id) {
|
|---|
| 300 | Plotter2ViewportInfo* vi = &vInfo[id];
|
|---|
| 301 |
|
|---|
| 302 | vi->vpPosXMin = xmin;
|
|---|
| 303 | vi->vpPosXMax = xmax;
|
|---|
| 304 | vi->vpPosYMin = ymin;
|
|---|
| 305 | vi->vpPosYMax = ymax;
|
|---|
| 306 |
|
|---|
| 307 | hasDefaultViewport = false;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | void Plotter2::showViewport(const int inVpid) {
|
|---|
| 311 | int vpid = inVpid;
|
|---|
| 312 | if (vpid < 0) {
|
|---|
| 313 | vpid = vInfo.size() - 1;
|
|---|
| 314 | }
|
|---|
| 315 | if (vpid < 0) {
|
|---|
| 316 | exit(0);
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 320 | vi->showViewport = true;
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | void Plotter2::hideViewport(const int inVpid) {
|
|---|
| 324 | int vpid = inVpid;
|
|---|
| 325 | if (vpid < 0) {
|
|---|
| 326 | vpid = vInfo.size() - 1;
|
|---|
| 327 | }
|
|---|
| 328 | if (vpid < 0) {
|
|---|
| 329 | exit(0);
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 333 | vi->showViewport = false;
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | bool Plotter2::getHasDefaultViewport() {
|
|---|
| 337 | return hasDefaultViewport;
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | int Plotter2::getCurrentViewportId() {
|
|---|
| 341 | return currentViewportId;
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | void Plotter2::getViewInfo() {
|
|---|
| 345 | std::cout << "===================" << std::endl << std::flush;
|
|---|
| 346 | for (uint i = 0; i < vInfo.size(); ++i) {
|
|---|
| 347 | std::cout << "[" << i << "] " << std::endl;
|
|---|
| 348 | std::cout << "vpPos: ";
|
|---|
| 349 | std::cout << "xmin=" << vInfo[i].vpPosXMin << ", ";
|
|---|
| 350 | std::cout << "xmax=" << vInfo[i].vpPosXMax << ", ";
|
|---|
| 351 | std::cout << "ymin=" << vInfo[i].vpPosYMin << ", ";
|
|---|
| 352 | std::cout << "ymax=" << vInfo[i].vpPosYMax << std::endl;
|
|---|
| 353 |
|
|---|
| 354 | std::cout << "vpRange: ";
|
|---|
| 355 | std::cout << "xmin=" << vInfo[i].vpRangeXMin << ", ";
|
|---|
| 356 | std::cout << "xmax=" << vInfo[i].vpRangeXMax << ", ";
|
|---|
| 357 | std::cout << "ymin=" << vInfo[i].vpRangeYMin << ", ";
|
|---|
| 358 | std::cout << "ymax=" << vInfo[i].vpRangeYMax << std::endl;;
|
|---|
| 359 |
|
|---|
| 360 | std::cout << "vdatasize=" << vInfo[i].vData.size() << std::endl;
|
|---|
| 361 | for (uint j = 0; j < vInfo[i].vData.size(); ++j) {
|
|---|
| 362 | std::cout << "vdataxdatasize=" << vInfo[i].vData[j].xData.size() << ", ";
|
|---|
| 363 | for (uint k = 0; k < vInfo[i].vData[j].xData.size(); ++k) {
|
|---|
| 364 | std::cout << "(" << vInfo[i].vData[j].xData[k] << ", ";
|
|---|
| 365 | std::cout << vInfo[i].vData[j].yData[k] << ") ";
|
|---|
| 366 | }
|
|---|
| 367 | std::cout << std::endl;
|
|---|
| 368 | }
|
|---|
| 369 | std::cout << "===================" << std::endl << std::flush;
|
|---|
| 370 | }
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | void Plotter2::setRange(const float xmin, const float xmax, const float ymin, const float ymax, const int inVpid) {
|
|---|
| 374 | setRangeX(xmin, xmax, inVpid);
|
|---|
| 375 | setRangeY(ymin, ymax, inVpid);
|
|---|
| 376 | }
|
|---|
| 377 |
|
|---|
| 378 | void Plotter2::setRangeX(const float xmin, const float xmax, const int inVpid) {
|
|---|
| 379 | int vpid = inVpid;
|
|---|
| 380 | if (vpid < 0) {
|
|---|
| 381 | vpid = vInfo.size() - 1;
|
|---|
| 382 | }
|
|---|
| 383 | if (vpid < 0) {
|
|---|
| 384 | Plotter2ViewportInfo vi;
|
|---|
| 385 | vInfo.push_back(vi);
|
|---|
| 386 | vpid = 0;
|
|---|
| 387 | }
|
|---|
| 388 |
|
|---|
| 389 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 390 | vi->vpRangeXMin = xmin;
|
|---|
| 391 | vi->vpRangeXMax = xmax;
|
|---|
| 392 | vi->isAutoRangeX = false;
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | void Plotter2::setRangeY(const float ymin, const float ymax, const int inVpid) {
|
|---|
| 396 | int vpid = inVpid;
|
|---|
| 397 | if (vpid < 0) {
|
|---|
| 398 | vpid = vInfo.size() - 1;
|
|---|
| 399 | }
|
|---|
| 400 | if (vpid < 0) {
|
|---|
| 401 | Plotter2ViewportInfo vi;
|
|---|
| 402 | vInfo.push_back(vi);
|
|---|
| 403 | vpid = 0;
|
|---|
| 404 | }
|
|---|
| 405 |
|
|---|
| 406 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 407 | vi->vpRangeYMin = ymin;
|
|---|
| 408 | vi->vpRangeYMax = ymax;
|
|---|
| 409 | vi->isAutoRangeY = false;
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | std::vector<float> Plotter2::getRangeX(const int inVpid) {
|
|---|
| 413 | int vpid = inVpid;
|
|---|
| 414 | if (vpid < 0) {
|
|---|
| 415 | vpid = vInfo.size() - 1;
|
|---|
| 416 | }
|
|---|
| 417 | if (vpid < 0) {
|
|---|
| 418 | exit(0);
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | return vInfo[vpid].getRangeX();
|
|---|
| 422 | }
|
|---|
| 423 |
|
|---|
| 424 | std::vector<float> Plotter2::getRangeY(const int inVpid) {
|
|---|
| 425 | int vpid = inVpid;
|
|---|
| 426 | if (vpid < 0) {
|
|---|
| 427 | vpid = vInfo.size() - 1;
|
|---|
| 428 | }
|
|---|
| 429 | if (vpid < 0) {
|
|---|
| 430 | exit(0);
|
|---|
| 431 | }
|
|---|
| 432 |
|
|---|
| 433 | return vInfo[vpid].getRangeY();
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | void Plotter2::setAutoRange(const int inVpid) {
|
|---|
| 437 | setAutoRangeX(inVpid);
|
|---|
| 438 | setAutoRangeY(inVpid);
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | void Plotter2::setAutoRangeX(const int inVpid) {
|
|---|
| 442 | int vpid = inVpid;
|
|---|
| 443 | if (vpid < 0) {
|
|---|
| 444 | vpid = vInfo.size() - 1;
|
|---|
| 445 | }
|
|---|
| 446 | if (vpid < 0) {
|
|---|
| 447 | Plotter2ViewportInfo vi;
|
|---|
| 448 | vInfo.push_back(vi);
|
|---|
| 449 | vpid = 0;
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 453 | vi->isAutoRangeX = true;
|
|---|
| 454 | }
|
|---|
| 455 |
|
|---|
| 456 | void Plotter2::setAutoRangeY(const int inVpid) {
|
|---|
| 457 | int vpid = inVpid;
|
|---|
| 458 | if (vpid < 0) {
|
|---|
| 459 | vpid = vInfo.size() - 1;
|
|---|
| 460 | }
|
|---|
| 461 | if (vpid < 0) {
|
|---|
| 462 | Plotter2ViewportInfo vi;
|
|---|
| 463 | vInfo.push_back(vi);
|
|---|
| 464 | vpid = 0;
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 468 | vi->isAutoRangeY = true;
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | void Plotter2::setFontSizeDef(const float size, const int inVpid) {
|
|---|
| 472 | int vpid = inVpid;
|
|---|
| 473 | if (vpid < 0) {
|
|---|
| 474 | vpid = vInfo.size() - 1;
|
|---|
| 475 | }
|
|---|
| 476 | if (vpid < 0) {
|
|---|
| 477 | Plotter2ViewportInfo vi;
|
|---|
| 478 | vInfo.push_back(vi);
|
|---|
| 479 | vpid = 0;
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 483 | vi->fontSizeDef = size;
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | void Plotter2::setTicksX(const float interval, const int num, const int inVpid) {
|
|---|
| 487 | int vpid = inVpid;
|
|---|
| 488 | if (vpid < 0) {
|
|---|
| 489 | vpid = vInfo.size() - 1;
|
|---|
| 490 | }
|
|---|
| 491 | if (vpid < 0) {
|
|---|
| 492 | Plotter2ViewportInfo vi;
|
|---|
| 493 | vInfo.push_back(vi);
|
|---|
| 494 | vpid = 0;
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 498 | vi->majorTickIntervalX = interval;
|
|---|
| 499 | vi->nMinorTickWithinMajorTicksX = num;
|
|---|
| 500 | vi->isAutoTickIntervalX = false;
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 | void Plotter2::setTicksY(const float interval, const int num, const int inVpid) {
|
|---|
| 504 | int vpid = inVpid;
|
|---|
| 505 | if (vpid < 0) {
|
|---|
| 506 | vpid = vInfo.size() - 1;
|
|---|
| 507 | }
|
|---|
| 508 | if (vpid < 0) {
|
|---|
| 509 | Plotter2ViewportInfo vi;
|
|---|
| 510 | vInfo.push_back(vi);
|
|---|
| 511 | vpid = 0;
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 515 | vi->majorTickIntervalY = interval;
|
|---|
| 516 | vi->nMinorTickWithinMajorTicksY = num;
|
|---|
| 517 | vi->isAutoTickIntervalY = false;
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 | void Plotter2::setAutoTicks(const int inVpid) {
|
|---|
| 521 | setAutoTicksX(inVpid);
|
|---|
| 522 | setAutoTicksY(inVpid);
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | void Plotter2::setAutoTicksX(const int inVpid) {
|
|---|
| 526 | int vpid = inVpid;
|
|---|
| 527 | if (vpid < 0) {
|
|---|
| 528 | vpid = vInfo.size() - 1;
|
|---|
| 529 | }
|
|---|
| 530 | if (vpid < 0) {
|
|---|
| 531 | Plotter2ViewportInfo vi;
|
|---|
| 532 | vInfo.push_back(vi);
|
|---|
| 533 | vpid = 0;
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 537 | vi->isAutoTickIntervalX = true;
|
|---|
| 538 | }
|
|---|
| 539 |
|
|---|
| 540 | void Plotter2::setAutoTicksY(const int inVpid) {
|
|---|
| 541 | int vpid = inVpid;
|
|---|
| 542 | if (vpid < 0) {
|
|---|
| 543 | vpid = vInfo.size() - 1;
|
|---|
| 544 | }
|
|---|
| 545 | if (vpid < 0) {
|
|---|
| 546 | Plotter2ViewportInfo vi;
|
|---|
| 547 | vInfo.push_back(vi);
|
|---|
| 548 | vpid = 0;
|
|---|
| 549 | }
|
|---|
| 550 |
|
|---|
| 551 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 552 | vi->isAutoTickIntervalY = true;
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 | void Plotter2::setNumIntervalX(const float interval, const int inVpid) {
|
|---|
| 556 | int vpid = inVpid;
|
|---|
| 557 | if (vpid < 0) {
|
|---|
| 558 | vpid = vInfo.size() - 1;
|
|---|
| 559 | }
|
|---|
| 560 | if (vpid < 0) {
|
|---|
| 561 | Plotter2ViewportInfo vi;
|
|---|
| 562 | vInfo.push_back(vi);
|
|---|
| 563 | vpid = 0;
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 567 | vi->nMajorTickWithinTickNumsX = (int)(interval / vi->majorTickIntervalX);
|
|---|
| 568 | }
|
|---|
| 569 |
|
|---|
| 570 | void Plotter2::setNumIntervalY(const float interval, const int inVpid) {
|
|---|
| 571 | int vpid = inVpid;
|
|---|
| 572 | if (vpid < 0) {
|
|---|
| 573 | vpid = vInfo.size() - 1;
|
|---|
| 574 | }
|
|---|
| 575 | if (vpid < 0) {
|
|---|
| 576 | Plotter2ViewportInfo vi;
|
|---|
| 577 | vInfo.push_back(vi);
|
|---|
| 578 | vpid = 0;
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 582 | vi->nMajorTickWithinTickNumsY = (int)(interval / vi->majorTickIntervalY);
|
|---|
| 583 | }
|
|---|
| 584 |
|
|---|
| 585 | void Plotter2::setNumLocationX(const std::string& side, const int inVpid) {
|
|---|
| 586 | int vpid = inVpid;
|
|---|
| 587 | if (vpid < 0) {
|
|---|
| 588 | vpid = vInfo.size() - 1;
|
|---|
| 589 | }
|
|---|
| 590 | if (vpid < 0) {
|
|---|
| 591 | Plotter2ViewportInfo vi;
|
|---|
| 592 | vInfo.push_back(vi);
|
|---|
| 593 | vpid = 0;
|
|---|
| 594 | }
|
|---|
| 595 |
|
|---|
| 596 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 597 | vi->numLocationX = side;
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | void Plotter2::setNumLocationY(const std::string& side, const int inVpid) {
|
|---|
| 601 | int vpid = inVpid;
|
|---|
| 602 | if (vpid < 0) {
|
|---|
| 603 | vpid = vInfo.size() - 1;
|
|---|
| 604 | }
|
|---|
| 605 | if (vpid < 0) {
|
|---|
| 606 | Plotter2ViewportInfo vi;
|
|---|
| 607 | vInfo.push_back(vi);
|
|---|
| 608 | vpid = 0;
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 612 | vi->numLocationY = side;
|
|---|
| 613 | }
|
|---|
| 614 |
|
|---|
| 615 | void Plotter2::setData(const std::vector<float>& xdata, const std::vector<float>& ydata, const int inVpid, const int inDataid) {
|
|---|
| 616 | int vpid = inVpid;
|
|---|
| 617 | if (vpid < 0) {
|
|---|
| 618 | vpid = vInfo.size() - 1;
|
|---|
| 619 | }
|
|---|
| 620 | if (vpid < 0) {
|
|---|
| 621 | Plotter2ViewportInfo vi;
|
|---|
| 622 | vInfo.push_back(vi);
|
|---|
| 623 | vpid = 0;
|
|---|
| 624 | }
|
|---|
| 625 |
|
|---|
| 626 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 627 |
|
|---|
| 628 | int dataid = inDataid;
|
|---|
| 629 | if (dataid < 0) {
|
|---|
| 630 | Plotter2DataInfo di;
|
|---|
| 631 | vi->vData.push_back(di);
|
|---|
| 632 | dataid = vi->vData.size() - 1;
|
|---|
| 633 | }
|
|---|
| 634 |
|
|---|
| 635 | vi->setData(xdata, ydata, dataid);
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 | void Plotter2::setLine(const int color, const int width, const int style, const int inVpid, const int inDataid) {
|
|---|
| 639 | int vpid = inVpid;
|
|---|
| 640 | if (vpid < 0) {
|
|---|
| 641 | vpid = vInfo.size() - 1;
|
|---|
| 642 | }
|
|---|
| 643 | if (vpid < 0) {
|
|---|
| 644 | Plotter2ViewportInfo vi;
|
|---|
| 645 | vInfo.push_back(vi);
|
|---|
| 646 | vpid = 0;
|
|---|
| 647 | }
|
|---|
| 648 |
|
|---|
| 649 | int dataid = inDataid;
|
|---|
| 650 | if (dataid < 0) {
|
|---|
| 651 | dataid = vInfo[vpid].vData.size() - 1;
|
|---|
| 652 | }
|
|---|
| 653 |
|
|---|
| 654 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 655 | vi->vData[dataid].drawLine = true;
|
|---|
| 656 | vi->vData[dataid].lineColor = color;
|
|---|
| 657 | vi->vData[dataid].lineWidth = width;
|
|---|
| 658 | vi->vData[dataid].lineStyle = style;
|
|---|
| 659 | }
|
|---|
| 660 |
|
|---|
| 661 | void Plotter2::showLine(const int inVpid, const int inDataid) {
|
|---|
| 662 | int vpid = inVpid;
|
|---|
| 663 | if (vpid < 0) {
|
|---|
| 664 | vpid = vInfo.size() - 1;
|
|---|
| 665 | }
|
|---|
| 666 | if (vpid < 0) {
|
|---|
| 667 | exit(0);
|
|---|
| 668 | }
|
|---|
| 669 |
|
|---|
| 670 | int dataid = inDataid;
|
|---|
| 671 | if (dataid < 0) {
|
|---|
| 672 | dataid = vInfo[vpid].vData.size() - 1;
|
|---|
| 673 | }
|
|---|
| 674 | if (dataid < 0) {
|
|---|
| 675 | exit(0);
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 679 | vi->vData[dataid].drawLine = true;
|
|---|
| 680 | }
|
|---|
| 681 |
|
|---|
| 682 | void Plotter2::hideLine(const int inVpid, const int inDataid) {
|
|---|
| 683 | int vpid = inVpid;
|
|---|
| 684 | if (vpid < 0) {
|
|---|
| 685 | vpid = vInfo.size() - 1;
|
|---|
| 686 | }
|
|---|
| 687 | if (vpid < 0) {
|
|---|
| 688 | exit(0);
|
|---|
| 689 | }
|
|---|
| 690 |
|
|---|
| 691 | int dataid = inDataid;
|
|---|
| 692 | if (dataid < 0) {
|
|---|
| 693 | dataid = vInfo[vpid].vData.size() - 1;
|
|---|
| 694 | }
|
|---|
| 695 | if (dataid < 0) {
|
|---|
| 696 | exit(0);
|
|---|
| 697 | }
|
|---|
| 698 |
|
|---|
| 699 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 700 | vi->vData[dataid].drawLine = false;
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | void Plotter2::setPoint(const int type, const float size, const int color, const int inVpid, const int inDataid) {
|
|---|
| 704 | int vpid = inVpid;
|
|---|
| 705 | if (vpid < 0) {
|
|---|
| 706 | vpid = vInfo.size() - 1;
|
|---|
| 707 | }
|
|---|
| 708 | if (vpid < 0) {
|
|---|
| 709 | Plotter2ViewportInfo vi;
|
|---|
| 710 | vInfo.push_back(vi);
|
|---|
| 711 | vpid = 0;
|
|---|
| 712 | }
|
|---|
| 713 |
|
|---|
| 714 | int dataid = inDataid;
|
|---|
| 715 | if (dataid < 0) {
|
|---|
| 716 | dataid = vInfo[vpid].vData.size() - 1;
|
|---|
| 717 | }
|
|---|
| 718 |
|
|---|
| 719 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 720 | vi->vData[dataid].drawMarker = true;
|
|---|
| 721 | vi->vData[dataid].markerType = type;
|
|---|
| 722 | vi->vData[dataid].markerSize = size;
|
|---|
| 723 | vi->vData[dataid].markerColor = color;
|
|---|
| 724 | }
|
|---|
| 725 |
|
|---|
| 726 | void Plotter2::showPoint(const int inVpid, const int inDataid) {
|
|---|
| 727 | int vpid = inVpid;
|
|---|
| 728 | if (vpid < 0) {
|
|---|
| 729 | vpid = vInfo.size() - 1;
|
|---|
| 730 | }
|
|---|
| 731 | if (vpid < 0) {
|
|---|
| 732 | exit(0);
|
|---|
| 733 | }
|
|---|
| 734 |
|
|---|
| 735 | int dataid = inDataid;
|
|---|
| 736 | if (dataid < 0) {
|
|---|
| 737 | dataid = vInfo[vpid].vData.size() - 1;
|
|---|
| 738 | }
|
|---|
| 739 | if (dataid < 0) {
|
|---|
| 740 | exit(0);
|
|---|
| 741 | }
|
|---|
| 742 |
|
|---|
| 743 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 744 | vi->vData[dataid].drawMarker = true;
|
|---|
| 745 | }
|
|---|
| 746 |
|
|---|
| 747 | void Plotter2::hidePoint(const int inVpid, const int inDataid) {
|
|---|
| 748 | int vpid = inVpid;
|
|---|
| 749 | if (vpid < 0) {
|
|---|
| 750 | vpid = vInfo.size() - 1;
|
|---|
| 751 | }
|
|---|
| 752 | if (vpid < 0) {
|
|---|
| 753 | exit(0);
|
|---|
| 754 | }
|
|---|
| 755 |
|
|---|
| 756 | int dataid = inDataid;
|
|---|
| 757 | if (dataid < 0) {
|
|---|
| 758 | dataid = vInfo[vpid].vData.size() - 1;
|
|---|
| 759 | }
|
|---|
| 760 | if (dataid < 0) {
|
|---|
| 761 | exit(0);
|
|---|
| 762 | }
|
|---|
| 763 |
|
|---|
| 764 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 765 | vi->vData[dataid].drawMarker = false;
|
|---|
| 766 | }
|
|---|
| 767 |
|
|---|
| 768 | void Plotter2::setMaskX(const float xmin, const float xmax, const int color, const int fill, const int width, const float hsep, const int inVpid) {
|
|---|
| 769 | int vpid = inVpid;
|
|---|
| 770 | if (vpid < 0) {
|
|---|
| 771 | vpid = vInfo.size() - 1;
|
|---|
| 772 | }
|
|---|
| 773 | if (vpid < 0) {
|
|---|
| 774 | Plotter2ViewportInfo vi;
|
|---|
| 775 | vInfo.push_back(vi);
|
|---|
| 776 | vpid = 0;
|
|---|
| 777 | }
|
|---|
| 778 |
|
|---|
| 779 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 780 |
|
|---|
| 781 | Plotter2RectInfo ri;
|
|---|
| 782 | ri.xmin = xmin;
|
|---|
| 783 | ri.xmax = xmax;
|
|---|
| 784 | std::vector<float> yrange = vi->getRangeY();
|
|---|
| 785 | float yexcess = 0.1*(yrange[1] - yrange[0]);
|
|---|
| 786 | ri.ymin = yrange[0] - yexcess;
|
|---|
| 787 | ri.ymax = yrange[1] + yexcess;
|
|---|
| 788 | ri.color = color;
|
|---|
| 789 | ri.fill = fill;
|
|---|
| 790 | ri.width = width;
|
|---|
| 791 | ri.hsep = hsep;
|
|---|
| 792 |
|
|---|
| 793 | vi->vRect.push_back(ri);
|
|---|
| 794 | }
|
|---|
| 795 |
|
|---|
| 796 | void Plotter2::setLabelX(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
|
|---|
| 797 | int vpid = inVpid;
|
|---|
| 798 | if (vpid < 0) {
|
|---|
| 799 | vpid = vInfo.size() - 1;
|
|---|
| 800 | }
|
|---|
| 801 | if (vpid < 0) {
|
|---|
| 802 | Plotter2ViewportInfo vi;
|
|---|
| 803 | vInfo.push_back(vi);
|
|---|
| 804 | vpid = 0;
|
|---|
| 805 | }
|
|---|
| 806 |
|
|---|
| 807 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 808 |
|
|---|
| 809 | std::string styleString;
|
|---|
| 810 | if (style == "") {
|
|---|
| 811 | styleString = "";
|
|---|
| 812 | } else if (style == "roman") {
|
|---|
| 813 | styleString = "\\fr";
|
|---|
| 814 | } else if (style == "italic") {
|
|---|
| 815 | styleString = "\\fi";
|
|---|
| 816 | } else if (style == "script") {
|
|---|
| 817 | styleString = "\\fs";
|
|---|
| 818 | }
|
|---|
| 819 | vi->labelXString = styleString + label;
|
|---|
| 820 |
|
|---|
| 821 | float posx = inPosx;
|
|---|
| 822 | if (posx < 0.0) {
|
|---|
| 823 | posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
|
|---|
| 824 | }
|
|---|
| 825 | vi->labelXPosX = posx;
|
|---|
| 826 |
|
|---|
| 827 | float posy = inPosy;
|
|---|
| 828 | if (posy < 0.0) {
|
|---|
| 829 | posy = 0.35*vi->vpPosYMin;
|
|---|
| 830 | }
|
|---|
| 831 | vi->labelXPosY = posy;
|
|---|
| 832 |
|
|---|
| 833 | vi->labelXAngle = 0.0;
|
|---|
| 834 | vi->labelXFJust = 0.5;
|
|---|
| 835 | vi->labelXSize = size;
|
|---|
| 836 | vi->labelXColor = color;
|
|---|
| 837 | vi->labelXBColor = bgcolor;
|
|---|
| 838 | }
|
|---|
| 839 |
|
|---|
| 840 | void Plotter2::setLabelY(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
|
|---|
| 841 | int vpid = inVpid;
|
|---|
| 842 | if (vpid < 0) {
|
|---|
| 843 | vpid = vInfo.size() - 1;
|
|---|
| 844 | }
|
|---|
| 845 | if (vpid < 0) {
|
|---|
| 846 | Plotter2ViewportInfo vi;
|
|---|
| 847 | vInfo.push_back(vi);
|
|---|
| 848 | vpid = 0;
|
|---|
| 849 | }
|
|---|
| 850 |
|
|---|
| 851 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 852 |
|
|---|
| 853 | std::string styleString;
|
|---|
| 854 | if (style == "") {
|
|---|
| 855 | styleString = "";
|
|---|
| 856 | } else if (style == "roman") {
|
|---|
| 857 | styleString = "\\fr";
|
|---|
| 858 | } else if (style == "italic") {
|
|---|
| 859 | styleString = "\\fi";
|
|---|
| 860 | } else if (style == "script") {
|
|---|
| 861 | styleString = "\\fs";
|
|---|
| 862 | }
|
|---|
| 863 | vi->labelYString = styleString + label;
|
|---|
| 864 |
|
|---|
| 865 | float posx = inPosx;
|
|---|
| 866 | if (posx < 0.0) {
|
|---|
| 867 | posx = 0.35*vi->vpPosXMin;
|
|---|
| 868 | }
|
|---|
| 869 | vi->labelYPosX = posx;
|
|---|
| 870 |
|
|---|
| 871 | float posy = inPosy;
|
|---|
| 872 | if (posy < 0.0) {
|
|---|
| 873 | posy = 0.5*(vi->vpPosYMin + vi->vpPosYMax);
|
|---|
| 874 | }
|
|---|
| 875 | vi->labelYPosY = posy;
|
|---|
| 876 |
|
|---|
| 877 | vi->labelYAngle = 90.0;
|
|---|
| 878 | vi->labelYFJust = 0.5;
|
|---|
| 879 | vi->labelYSize = size;
|
|---|
| 880 | vi->labelYColor = color;
|
|---|
| 881 | vi->labelYBColor = bgcolor;
|
|---|
| 882 | }
|
|---|
| 883 |
|
|---|
| 884 | void Plotter2::setTitle(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
|
|---|
| 885 | int vpid = inVpid;
|
|---|
| 886 | if (vpid < 0) {
|
|---|
| 887 | vpid = vInfo.size() - 1;
|
|---|
| 888 | }
|
|---|
| 889 | if (vpid < 0) {
|
|---|
| 890 | Plotter2ViewportInfo vi;
|
|---|
| 891 | vInfo.push_back(vi);
|
|---|
| 892 | vpid = 0;
|
|---|
| 893 | }
|
|---|
| 894 |
|
|---|
| 895 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 896 |
|
|---|
| 897 | std::string styleString;
|
|---|
| 898 | if (style == "") {
|
|---|
| 899 | styleString = "";
|
|---|
| 900 | } else if (style == "roman") {
|
|---|
| 901 | styleString = "\\fr";
|
|---|
| 902 | } else if (style == "italic") {
|
|---|
| 903 | styleString = "\\fi";
|
|---|
| 904 | } else if (style == "script") {
|
|---|
| 905 | styleString = "\\fs";
|
|---|
| 906 | }
|
|---|
| 907 | vi->titleString = styleString + label;
|
|---|
| 908 |
|
|---|
| 909 | float posx = inPosx;
|
|---|
| 910 | if (posx < 0.0) {
|
|---|
| 911 | posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
|
|---|
| 912 | }
|
|---|
| 913 | vi->titlePosX = posx;
|
|---|
| 914 |
|
|---|
| 915 | float posy = inPosy;
|
|---|
| 916 | if (posy < 0.0) {
|
|---|
| 917 | posy = vi->vpPosYMax + 0.25*(1.0 - vi->vpPosYMax);
|
|---|
| 918 | }
|
|---|
| 919 | vi->titlePosY = posy;
|
|---|
| 920 |
|
|---|
| 921 | vi->titleAngle = 0.0;
|
|---|
| 922 | vi->titleFJust = 0.5;
|
|---|
| 923 | vi->titleSize = size;
|
|---|
| 924 | vi->titleColor = color;
|
|---|
| 925 | vi->titleBColor = bgcolor;
|
|---|
| 926 | }
|
|---|
| 927 |
|
|---|
| 928 | void Plotter2::setViewportBackgroundColor(const int bgcolor, const int inVpid) {
|
|---|
| 929 | int vpid = inVpid;
|
|---|
| 930 | if (vpid < 0) {
|
|---|
| 931 | vpid = vInfo.size() - 1;
|
|---|
| 932 | }
|
|---|
| 933 | if (vpid < 0) {
|
|---|
| 934 | exit(0);
|
|---|
| 935 | }
|
|---|
| 936 |
|
|---|
| 937 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 938 | vi->vpBColor = bgcolor;
|
|---|
| 939 | }
|
|---|
| 940 |
|
|---|
| 941 | /*
|
|---|
| 942 | void Plotter2::setAnnotation(const std::string& label, const float posx, const float posy, const float angle, const float fjust, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
|
|---|
| 943 | int vpid = inVpid;
|
|---|
| 944 | if (vpid < 0) {
|
|---|
| 945 | vpid = vInfo.size() - 1;
|
|---|
| 946 | }
|
|---|
| 947 | if (vpid < 0) {
|
|---|
| 948 | Plotter2ViewportInfo vi;
|
|---|
| 949 | vInfo.push_back(vi);
|
|---|
| 950 | vpid = 0;
|
|---|
| 951 | }
|
|---|
| 952 |
|
|---|
| 953 | std::string styleString;
|
|---|
| 954 | if (style == "") {
|
|---|
| 955 | styleString = "";
|
|---|
| 956 | } else if (style == "roman") {
|
|---|
| 957 | styleString = "\\fr";
|
|---|
| 958 | } else if (style == "italic") {
|
|---|
| 959 | styleString = "\\fi";
|
|---|
| 960 | } else if (style == "script") {
|
|---|
| 961 | styleString = "\\fs";
|
|---|
| 962 | }
|
|---|
| 963 |
|
|---|
| 964 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
|---|
| 965 | //vi->titleString = styleString + label;
|
|---|
| 966 | //vi->titlePosX = posx;
|
|---|
| 967 | //vi->titlePosY = posy;
|
|---|
| 968 | //vi->titleAngle = angle;
|
|---|
| 969 | //vi->titleFJust = fjust;
|
|---|
| 970 | //vi->titleSize = size;
|
|---|
| 971 | //vi->titleColor = color;
|
|---|
| 972 | //vi->titleBColor = bgcolor;
|
|---|
| 973 | }
|
|---|
| 974 | */
|
|---|
| 975 |
|
|---|
| 976 | void Plotter2::close() {
|
|---|
| 977 | if (hasDevice) {
|
|---|
| 978 | cpgclos();
|
|---|
| 979 | hasDevice = false;
|
|---|
| 980 | }
|
|---|
| 981 | }
|
|---|
| 982 |
|
|---|
| 983 | void Plotter2::plot() {
|
|---|
| 984 | open();
|
|---|
| 985 |
|
|---|
| 986 | cpgscr(0, 1.0, 1.0, 1.0); // set background color white
|
|---|
| 987 | cpgscr(1, 0.0, 0.0, 0.0); // set foreground color black
|
|---|
| 988 |
|
|---|
| 989 | for (uint i = 0; i < vInfo.size(); ++i) {
|
|---|
| 990 | Plotter2ViewportInfo vi = vInfo[i];
|
|---|
| 991 |
|
|---|
| 992 | if (vi.showViewport) {
|
|---|
| 993 | cpgstbg(0); // reset background colour to the initial one (white)
|
|---|
| 994 | cpgsci(1); // reset foreground colour to the initial one (black)
|
|---|
| 995 | cpgsls(1); // reset line style to solid
|
|---|
| 996 | cpgslw(1); // reset line width to 1
|
|---|
| 997 | cpgscf(1); // reset font style to normal
|
|---|
| 998 | cpgsch(vi.fontSizeDef);// reset font size
|
|---|
| 999 | cpgsfs(1); // reset fill style (solid)
|
|---|
| 1000 |
|
|---|
| 1001 | cpgsvp(vi.vpPosXMin, vi.vpPosXMax, vi.vpPosYMin, vi.vpPosYMax);
|
|---|
| 1002 | vi.adjustRange();
|
|---|
| 1003 | vi.adjustTickInterval();
|
|---|
| 1004 |
|
|---|
| 1005 | cpgswin(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax);
|
|---|
| 1006 |
|
|---|
| 1007 | if (vi.vpBColor >= 0) {
|
|---|
| 1008 | cpgsci(vi.vpBColor);
|
|---|
| 1009 | cpgrect(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax);
|
|---|
| 1010 | cpgsci(1); // reset foreground colour to the initial one (black)
|
|---|
| 1011 | }
|
|---|
| 1012 |
|
|---|
| 1013 | // data
|
|---|
| 1014 | for (uint j = 0; j < vi.vData.size(); ++j) {
|
|---|
| 1015 | cpgstbg(0); // reset background colour to the initial one (white)
|
|---|
| 1016 | cpgsci(1); // reset foreground colour to the initial one (black)
|
|---|
| 1017 | cpgsls(1); // reset line style to solid
|
|---|
| 1018 | cpgslw(1); // reset line width to 1
|
|---|
| 1019 | cpgscf(1); // reset font style to normal
|
|---|
| 1020 | cpgsch(vi.fontSizeDef);// reset font size
|
|---|
| 1021 |
|
|---|
| 1022 | Plotter2DataInfo di = vi.vData[j];
|
|---|
| 1023 | std::vector<float> vxdata = di.xData;
|
|---|
| 1024 | int ndata = vxdata.size();
|
|---|
| 1025 | float* pxdata = new float[ndata];
|
|---|
| 1026 | float* pydata = new float[ndata];
|
|---|
| 1027 | for (int k = 0; k < ndata; ++k) {
|
|---|
| 1028 | pxdata[k] = di.xData[k];
|
|---|
| 1029 | pydata[k] = di.yData[k];
|
|---|
| 1030 | }
|
|---|
| 1031 |
|
|---|
| 1032 | if (di.drawLine) {
|
|---|
| 1033 | cpgsls(di.lineStyle);
|
|---|
| 1034 | cpgslw(di.lineWidth);
|
|---|
| 1035 | int colorIdx = di.lineColor;
|
|---|
| 1036 | if (colorIdx < 0) {
|
|---|
| 1037 | colorIdx = (j + 1) % 15 + 1;
|
|---|
| 1038 | }
|
|---|
| 1039 | cpgsci(colorIdx);
|
|---|
| 1040 | cpgline(ndata, pxdata, pydata);
|
|---|
| 1041 | }
|
|---|
| 1042 |
|
|---|
| 1043 | if (di.drawMarker) {
|
|---|
| 1044 | cpgsch(di.markerSize);
|
|---|
| 1045 | cpgsci(di.markerColor);
|
|---|
| 1046 | cpgpt(ndata, pxdata, pydata, di.markerType);
|
|---|
| 1047 | }
|
|---|
| 1048 |
|
|---|
| 1049 | delete [] pxdata;
|
|---|
| 1050 | delete [] pydata;
|
|---|
| 1051 | }
|
|---|
| 1052 |
|
|---|
| 1053 | // masks
|
|---|
| 1054 | for (uint j = 0; j < vi.vRect.size(); ++j) {
|
|---|
| 1055 | cpgstbg(0); // reset background colour to the initial one (white)
|
|---|
| 1056 | cpgsci(1); // reset foreground colour to the initial one (black)
|
|---|
| 1057 | cpgsls(1); // reset line style to solid
|
|---|
| 1058 | cpgslw(1); // reset line width to 1
|
|---|
| 1059 | cpgscf(1); // reset font style to normal
|
|---|
| 1060 | cpgsch(vi.fontSizeDef);// reset font size
|
|---|
| 1061 | cpgsfs(1); // reset fill style (solid)
|
|---|
| 1062 |
|
|---|
| 1063 | Plotter2RectInfo ri = vi.vRect[j];
|
|---|
| 1064 | cpgsci(ri.color);
|
|---|
| 1065 | cpgsfs(ri.fill);
|
|---|
| 1066 | cpgslw(ri.width);
|
|---|
| 1067 | cpgshs(45.0, ri.hsep, 0.0);
|
|---|
| 1068 | float* mxdata = new float[4];
|
|---|
| 1069 | float* mydata = new float[4];
|
|---|
| 1070 | mxdata[0] = ri.xmin;
|
|---|
| 1071 | mxdata[1] = ri.xmax;
|
|---|
| 1072 | mxdata[2] = ri.xmax;
|
|---|
| 1073 | mxdata[3] = ri.xmin;
|
|---|
| 1074 | mydata[0] = ri.ymin;
|
|---|
| 1075 | mydata[1] = ri.ymin;
|
|---|
| 1076 | mydata[2] = ri.ymax;
|
|---|
| 1077 | mydata[3] = ri.ymax;
|
|---|
| 1078 | cpgpoly(4, mxdata, mydata);
|
|---|
| 1079 | }
|
|---|
| 1080 |
|
|---|
| 1081 | cpgstbg(0); // reset background colour to the initial one (white)
|
|---|
| 1082 | cpgsci(1); // reset foreground colour to the initial one (black)
|
|---|
| 1083 | cpgsls(1); // reset line style to solid
|
|---|
| 1084 | cpgslw(1); // reset line width to 1
|
|---|
| 1085 | cpgscf(1); // reset font style to normal
|
|---|
| 1086 | cpgsch(vi.fontSizeDef);// reset font size
|
|---|
| 1087 | cpgsfs(1); // reset fill style (solid)
|
|---|
| 1088 |
|
|---|
| 1089 | cpgbox("BCTS", vi.majorTickIntervalX, vi.nMinorTickWithinMajorTicksX,
|
|---|
| 1090 | "BCTSV", vi.majorTickIntervalY, vi.nMinorTickWithinMajorTicksY);
|
|---|
| 1091 |
|
|---|
| 1092 | std::string numformatx, numformaty;
|
|---|
| 1093 | if (vi.numLocationX == "l") {
|
|---|
| 1094 | numformatx = "N";
|
|---|
| 1095 | } else if (vi.numLocationX == "r") {
|
|---|
| 1096 | numformatx = "M";
|
|---|
| 1097 | } else if (vi.numLocationX == "") {
|
|---|
| 1098 | numformatx = "";
|
|---|
| 1099 | }
|
|---|
| 1100 | if (vi.numLocationY == "b") {
|
|---|
| 1101 | numformaty = "NV";
|
|---|
| 1102 | } else if (vi.numLocationY == "t") {
|
|---|
| 1103 | numformaty = "MV";
|
|---|
| 1104 | } else if (vi.numLocationY == "") {
|
|---|
| 1105 | numformaty = "";
|
|---|
| 1106 | }
|
|---|
| 1107 |
|
|---|
| 1108 | cpgbox(numformatx.c_str(), vi.majorTickIntervalX * vi.nMajorTickWithinTickNumsX, 0,
|
|---|
| 1109 | numformaty.c_str(), vi.majorTickIntervalY * vi.nMajorTickWithinTickNumsY, 0);
|
|---|
| 1110 |
|
|---|
| 1111 | float xpos, ypos;
|
|---|
| 1112 |
|
|---|
| 1113 | // x-label
|
|---|
| 1114 | vi.getWorldCoordByWindowCoord(vi.labelXPosX, vi.labelXPosY, &xpos, &ypos);
|
|---|
| 1115 | cpgsch(vi.labelXSize);
|
|---|
| 1116 | cpgsci(vi.labelXColor);
|
|---|
| 1117 | cpgstbg(vi.labelXBColor); //outside viewports, works ONLY with /xwindow
|
|---|
| 1118 | cpgptxt(xpos, ypos, vi.labelXAngle, vi.labelXFJust, vi.labelXString.c_str());
|
|---|
| 1119 |
|
|---|
| 1120 | // y-label
|
|---|
| 1121 | vi.getWorldCoordByWindowCoord(vi.labelYPosX, vi.labelYPosY, &xpos, &ypos);
|
|---|
| 1122 | cpgsch(vi.labelYSize);
|
|---|
| 1123 | cpgsci(vi.labelYColor);
|
|---|
| 1124 | cpgstbg(vi.labelYBColor); //outside viewports, works ONLY with /xwindow
|
|---|
| 1125 | cpgptxt(xpos, ypos, vi.labelYAngle, vi.labelYFJust, vi.labelYString.c_str());
|
|---|
| 1126 |
|
|---|
| 1127 | // title
|
|---|
| 1128 | vi.getWorldCoordByWindowCoord(vi.titlePosX, vi.titlePosY, &xpos, &ypos);
|
|---|
| 1129 | cpgsch(vi.titleSize);
|
|---|
| 1130 | cpgsci(vi.titleColor);
|
|---|
| 1131 | cpgstbg(vi.titleBColor); //outside viewports, works ONLY with /xwindow
|
|---|
| 1132 | cpgptxt(xpos, ypos, vi.titleAngle, vi.titleFJust, vi.titleString.c_str());
|
|---|
| 1133 | }
|
|---|
| 1134 |
|
|---|
| 1135 | }
|
|---|
| 1136 |
|
|---|
| 1137 | close();
|
|---|
| 1138 | }
|
|---|
| 1139 |
|
|---|
| 1140 | } // namespace asap
|
|---|