[2830] | 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; // transparent (<0)
|
---|
| 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());
|
---|
[2834] | 184 | for (unsigned int i = 0; i < inXData.size(); ++i) {
|
---|
[2830] | 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());
|
---|
[2834] | 194 | for (unsigned int i = 0; i < inYData.size(); ++i) {
|
---|
[2830] | 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 |
|
---|
[2834] | 233 | for (unsigned int i = 0; i < vData.size(); ++i) {
|
---|
| 234 | for (unsigned int j = 0; j < vData[i].xData.size(); ++j) {
|
---|
[2830] | 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 | std::string Plotter2::getFileName() {
|
---|
| 273 | return filename;
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | void Plotter2::setFileName(const std::string& inFilename) {
|
---|
| 277 | filename = inFilename;
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | std::string Plotter2::getDevice() {
|
---|
| 281 | return device;
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | void Plotter2::setDevice(const std::string& inDevice) {
|
---|
| 285 | device = inDevice;
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | void Plotter2::open() {
|
---|
| 289 | cpgopen((filename + "/" + device).c_str());
|
---|
| 290 | hasDevice = true;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | int Plotter2::addViewport(const float xmin, const float xmax, const float ymin, const float ymax) {
|
---|
| 294 | Plotter2ViewportInfo vi;
|
---|
| 295 |
|
---|
| 296 | vi.vpPosXMin = xmin;
|
---|
| 297 | vi.vpPosXMax = xmax;
|
---|
| 298 | vi.vpPosYMin = ymin;
|
---|
| 299 | vi.vpPosYMax = ymax;
|
---|
| 300 |
|
---|
| 301 | vInfo.push_back(vi);
|
---|
| 302 | currentViewportId = vInfo.size() - 1;
|
---|
| 303 |
|
---|
| 304 | return currentViewportId;
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | void Plotter2::setViewport(const float xmin, const float xmax, const float ymin, const float ymax, const int id) {
|
---|
| 308 | Plotter2ViewportInfo* vi = &vInfo[id];
|
---|
| 309 |
|
---|
| 310 | vi->vpPosXMin = xmin;
|
---|
| 311 | vi->vpPosXMax = xmax;
|
---|
| 312 | vi->vpPosYMin = ymin;
|
---|
| 313 | vi->vpPosYMax = ymax;
|
---|
| 314 |
|
---|
| 315 | hasDefaultViewport = false;
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | void Plotter2::showViewport(const int inVpid) {
|
---|
| 319 | int vpid = inVpid;
|
---|
| 320 | if (vpid < 0) {
|
---|
| 321 | vpid = vInfo.size() - 1;
|
---|
| 322 | }
|
---|
| 323 | if (vpid < 0) {
|
---|
| 324 | exit(0);
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 328 | vi->showViewport = true;
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | void Plotter2::hideViewport(const int inVpid) {
|
---|
| 332 | int vpid = inVpid;
|
---|
| 333 | if (vpid < 0) {
|
---|
| 334 | vpid = vInfo.size() - 1;
|
---|
| 335 | }
|
---|
| 336 | if (vpid < 0) {
|
---|
| 337 | exit(0);
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 341 | vi->showViewport = false;
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | bool Plotter2::getHasDefaultViewport() {
|
---|
| 345 | return hasDefaultViewport;
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | int Plotter2::getCurrentViewportId() {
|
---|
| 349 | return currentViewportId;
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 | void Plotter2::getViewInfo() {
|
---|
| 353 | std::cout << "===================" << std::endl << std::flush;
|
---|
[2834] | 354 | for (unsigned int i = 0; i < vInfo.size(); ++i) {
|
---|
[2830] | 355 | std::cout << "[" << i << "] " << std::endl;
|
---|
| 356 | std::cout << "vpPos: ";
|
---|
| 357 | std::cout << "xmin=" << vInfo[i].vpPosXMin << ", ";
|
---|
| 358 | std::cout << "xmax=" << vInfo[i].vpPosXMax << ", ";
|
---|
| 359 | std::cout << "ymin=" << vInfo[i].vpPosYMin << ", ";
|
---|
| 360 | std::cout << "ymax=" << vInfo[i].vpPosYMax << std::endl;
|
---|
| 361 |
|
---|
| 362 | std::cout << "vpRange: ";
|
---|
| 363 | std::cout << "xmin=" << vInfo[i].vpRangeXMin << ", ";
|
---|
| 364 | std::cout << "xmax=" << vInfo[i].vpRangeXMax << ", ";
|
---|
| 365 | std::cout << "ymin=" << vInfo[i].vpRangeYMin << ", ";
|
---|
| 366 | std::cout << "ymax=" << vInfo[i].vpRangeYMax << std::endl;;
|
---|
| 367 |
|
---|
| 368 | std::cout << "vdatasize=" << vInfo[i].vData.size() << std::endl;
|
---|
[2834] | 369 | for (unsigned int j = 0; j < vInfo[i].vData.size(); ++j) {
|
---|
[2830] | 370 | std::cout << "vdataxdatasize=" << vInfo[i].vData[j].xData.size() << ", ";
|
---|
[2834] | 371 | for (unsigned int k = 0; k < vInfo[i].vData[j].xData.size(); ++k) {
|
---|
[2830] | 372 | std::cout << "(" << vInfo[i].vData[j].xData[k] << ", ";
|
---|
| 373 | std::cout << vInfo[i].vData[j].yData[k] << ") ";
|
---|
| 374 | }
|
---|
| 375 | std::cout << std::endl;
|
---|
| 376 | }
|
---|
| 377 | std::cout << "===================" << std::endl << std::flush;
|
---|
| 378 | }
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | void Plotter2::setRange(const float xmin, const float xmax, const float ymin, const float ymax, const int inVpid) {
|
---|
| 382 | setRangeX(xmin, xmax, inVpid);
|
---|
| 383 | setRangeY(ymin, ymax, inVpid);
|
---|
| 384 | }
|
---|
| 385 |
|
---|
| 386 | void Plotter2::setRangeX(const float xmin, const float xmax, const int inVpid) {
|
---|
| 387 | int vpid = inVpid;
|
---|
| 388 | if (vpid < 0) {
|
---|
| 389 | vpid = vInfo.size() - 1;
|
---|
| 390 | }
|
---|
| 391 | if (vpid < 0) {
|
---|
| 392 | Plotter2ViewportInfo vi;
|
---|
| 393 | vInfo.push_back(vi);
|
---|
| 394 | vpid = 0;
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 398 | vi->vpRangeXMin = xmin;
|
---|
| 399 | vi->vpRangeXMax = xmax;
|
---|
| 400 | vi->isAutoRangeX = false;
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | void Plotter2::setRangeY(const float ymin, const float ymax, const int inVpid) {
|
---|
| 404 | int vpid = inVpid;
|
---|
| 405 | if (vpid < 0) {
|
---|
| 406 | vpid = vInfo.size() - 1;
|
---|
| 407 | }
|
---|
| 408 | if (vpid < 0) {
|
---|
| 409 | Plotter2ViewportInfo vi;
|
---|
| 410 | vInfo.push_back(vi);
|
---|
| 411 | vpid = 0;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 415 | vi->vpRangeYMin = ymin;
|
---|
| 416 | vi->vpRangeYMax = ymax;
|
---|
| 417 | vi->isAutoRangeY = false;
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 | std::vector<float> Plotter2::getRangeX(const int inVpid) {
|
---|
| 421 | int vpid = inVpid;
|
---|
| 422 | if (vpid < 0) {
|
---|
| 423 | vpid = vInfo.size() - 1;
|
---|
| 424 | }
|
---|
| 425 | if (vpid < 0) {
|
---|
| 426 | exit(0);
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | return vInfo[vpid].getRangeX();
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | std::vector<float> Plotter2::getRangeY(const int inVpid) {
|
---|
| 433 | int vpid = inVpid;
|
---|
| 434 | if (vpid < 0) {
|
---|
| 435 | vpid = vInfo.size() - 1;
|
---|
| 436 | }
|
---|
| 437 | if (vpid < 0) {
|
---|
| 438 | exit(0);
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | return vInfo[vpid].getRangeY();
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | void Plotter2::setAutoRange(const int inVpid) {
|
---|
| 445 | setAutoRangeX(inVpid);
|
---|
| 446 | setAutoRangeY(inVpid);
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | void Plotter2::setAutoRangeX(const int inVpid) {
|
---|
| 450 | int vpid = inVpid;
|
---|
| 451 | if (vpid < 0) {
|
---|
| 452 | vpid = vInfo.size() - 1;
|
---|
| 453 | }
|
---|
| 454 | if (vpid < 0) {
|
---|
| 455 | Plotter2ViewportInfo vi;
|
---|
| 456 | vInfo.push_back(vi);
|
---|
| 457 | vpid = 0;
|
---|
| 458 | }
|
---|
| 459 |
|
---|
| 460 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 461 | vi->isAutoRangeX = true;
|
---|
| 462 | }
|
---|
| 463 |
|
---|
| 464 | void Plotter2::setAutoRangeY(const int inVpid) {
|
---|
| 465 | int vpid = inVpid;
|
---|
| 466 | if (vpid < 0) {
|
---|
| 467 | vpid = vInfo.size() - 1;
|
---|
| 468 | }
|
---|
| 469 | if (vpid < 0) {
|
---|
| 470 | Plotter2ViewportInfo vi;
|
---|
| 471 | vInfo.push_back(vi);
|
---|
| 472 | vpid = 0;
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 476 | vi->isAutoRangeY = true;
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | void Plotter2::setFontSizeDef(const float size, const int inVpid) {
|
---|
| 480 | int vpid = inVpid;
|
---|
| 481 | if (vpid < 0) {
|
---|
| 482 | vpid = vInfo.size() - 1;
|
---|
| 483 | }
|
---|
| 484 | if (vpid < 0) {
|
---|
| 485 | Plotter2ViewportInfo vi;
|
---|
| 486 | vInfo.push_back(vi);
|
---|
| 487 | vpid = 0;
|
---|
| 488 | }
|
---|
| 489 |
|
---|
| 490 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 491 | vi->fontSizeDef = size;
|
---|
| 492 | }
|
---|
| 493 |
|
---|
| 494 | void Plotter2::setTicksX(const float interval, const int num, const int inVpid) {
|
---|
| 495 | int vpid = inVpid;
|
---|
| 496 | if (vpid < 0) {
|
---|
| 497 | vpid = vInfo.size() - 1;
|
---|
| 498 | }
|
---|
| 499 | if (vpid < 0) {
|
---|
| 500 | Plotter2ViewportInfo vi;
|
---|
| 501 | vInfo.push_back(vi);
|
---|
| 502 | vpid = 0;
|
---|
| 503 | }
|
---|
| 504 |
|
---|
| 505 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 506 | vi->majorTickIntervalX = interval;
|
---|
| 507 | vi->nMinorTickWithinMajorTicksX = num;
|
---|
| 508 | vi->isAutoTickIntervalX = false;
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | void Plotter2::setTicksY(const float interval, const int num, const int inVpid) {
|
---|
| 512 | int vpid = inVpid;
|
---|
| 513 | if (vpid < 0) {
|
---|
| 514 | vpid = vInfo.size() - 1;
|
---|
| 515 | }
|
---|
| 516 | if (vpid < 0) {
|
---|
| 517 | Plotter2ViewportInfo vi;
|
---|
| 518 | vInfo.push_back(vi);
|
---|
| 519 | vpid = 0;
|
---|
| 520 | }
|
---|
| 521 |
|
---|
| 522 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 523 | vi->majorTickIntervalY = interval;
|
---|
| 524 | vi->nMinorTickWithinMajorTicksY = num;
|
---|
| 525 | vi->isAutoTickIntervalY = false;
|
---|
| 526 | }
|
---|
| 527 |
|
---|
| 528 | void Plotter2::setAutoTicks(const int inVpid) {
|
---|
| 529 | setAutoTicksX(inVpid);
|
---|
| 530 | setAutoTicksY(inVpid);
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 | void Plotter2::setAutoTicksX(const int inVpid) {
|
---|
| 534 | int vpid = inVpid;
|
---|
| 535 | if (vpid < 0) {
|
---|
| 536 | vpid = vInfo.size() - 1;
|
---|
| 537 | }
|
---|
| 538 | if (vpid < 0) {
|
---|
| 539 | Plotter2ViewportInfo vi;
|
---|
| 540 | vInfo.push_back(vi);
|
---|
| 541 | vpid = 0;
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 545 | vi->isAutoTickIntervalX = true;
|
---|
| 546 | }
|
---|
| 547 |
|
---|
| 548 | void Plotter2::setAutoTicksY(const int inVpid) {
|
---|
| 549 | int vpid = inVpid;
|
---|
| 550 | if (vpid < 0) {
|
---|
| 551 | vpid = vInfo.size() - 1;
|
---|
| 552 | }
|
---|
| 553 | if (vpid < 0) {
|
---|
| 554 | Plotter2ViewportInfo vi;
|
---|
| 555 | vInfo.push_back(vi);
|
---|
| 556 | vpid = 0;
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 560 | vi->isAutoTickIntervalY = true;
|
---|
| 561 | }
|
---|
| 562 |
|
---|
| 563 | void Plotter2::setNumIntervalX(const float interval, const int inVpid) {
|
---|
| 564 | int vpid = inVpid;
|
---|
| 565 | if (vpid < 0) {
|
---|
| 566 | vpid = vInfo.size() - 1;
|
---|
| 567 | }
|
---|
| 568 | if (vpid < 0) {
|
---|
| 569 | Plotter2ViewportInfo vi;
|
---|
| 570 | vInfo.push_back(vi);
|
---|
| 571 | vpid = 0;
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 575 | vi->nMajorTickWithinTickNumsX = (int)(interval / vi->majorTickIntervalX);
|
---|
| 576 | }
|
---|
| 577 |
|
---|
| 578 | void Plotter2::setNumIntervalY(const float interval, const int inVpid) {
|
---|
| 579 | int vpid = inVpid;
|
---|
| 580 | if (vpid < 0) {
|
---|
| 581 | vpid = vInfo.size() - 1;
|
---|
| 582 | }
|
---|
| 583 | if (vpid < 0) {
|
---|
| 584 | Plotter2ViewportInfo vi;
|
---|
| 585 | vInfo.push_back(vi);
|
---|
| 586 | vpid = 0;
|
---|
| 587 | }
|
---|
| 588 |
|
---|
| 589 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 590 | vi->nMajorTickWithinTickNumsY = (int)(interval / vi->majorTickIntervalY);
|
---|
| 591 | }
|
---|
| 592 |
|
---|
| 593 | void Plotter2::setNumLocationX(const std::string& side, const int inVpid) {
|
---|
| 594 | int vpid = inVpid;
|
---|
| 595 | if (vpid < 0) {
|
---|
| 596 | vpid = vInfo.size() - 1;
|
---|
| 597 | }
|
---|
| 598 | if (vpid < 0) {
|
---|
| 599 | Plotter2ViewportInfo vi;
|
---|
| 600 | vInfo.push_back(vi);
|
---|
| 601 | vpid = 0;
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 605 | vi->numLocationX = side;
|
---|
| 606 | }
|
---|
| 607 |
|
---|
| 608 | void Plotter2::setNumLocationY(const std::string& side, const int inVpid) {
|
---|
| 609 | int vpid = inVpid;
|
---|
| 610 | if (vpid < 0) {
|
---|
| 611 | vpid = vInfo.size() - 1;
|
---|
| 612 | }
|
---|
| 613 | if (vpid < 0) {
|
---|
| 614 | Plotter2ViewportInfo vi;
|
---|
| 615 | vInfo.push_back(vi);
|
---|
| 616 | vpid = 0;
|
---|
| 617 | }
|
---|
| 618 |
|
---|
| 619 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 620 | vi->numLocationY = side;
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | void Plotter2::setData(const std::vector<float>& xdata, const std::vector<float>& ydata, const int inVpid, const int inDataid) {
|
---|
| 624 | int vpid = inVpid;
|
---|
| 625 | if (vpid < 0) {
|
---|
| 626 | vpid = vInfo.size() - 1;
|
---|
| 627 | }
|
---|
| 628 | if (vpid < 0) {
|
---|
| 629 | Plotter2ViewportInfo vi;
|
---|
| 630 | vInfo.push_back(vi);
|
---|
| 631 | vpid = 0;
|
---|
| 632 | }
|
---|
| 633 |
|
---|
| 634 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 635 |
|
---|
| 636 | int dataid = inDataid;
|
---|
| 637 | if (dataid < 0) {
|
---|
| 638 | Plotter2DataInfo di;
|
---|
| 639 | vi->vData.push_back(di);
|
---|
| 640 | dataid = vi->vData.size() - 1;
|
---|
| 641 | }
|
---|
| 642 |
|
---|
| 643 | vi->setData(xdata, ydata, dataid);
|
---|
| 644 | }
|
---|
| 645 |
|
---|
| 646 | void Plotter2::setLine(const int color, const int width, const int style, const int inVpid, const int inDataid) {
|
---|
| 647 | int vpid = inVpid;
|
---|
| 648 | if (vpid < 0) {
|
---|
| 649 | vpid = vInfo.size() - 1;
|
---|
| 650 | }
|
---|
| 651 | if (vpid < 0) {
|
---|
| 652 | Plotter2ViewportInfo vi;
|
---|
| 653 | vInfo.push_back(vi);
|
---|
| 654 | vpid = 0;
|
---|
| 655 | }
|
---|
| 656 |
|
---|
| 657 | int dataid = inDataid;
|
---|
| 658 | if (dataid < 0) {
|
---|
| 659 | dataid = vInfo[vpid].vData.size() - 1;
|
---|
| 660 | }
|
---|
| 661 |
|
---|
| 662 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 663 | vi->vData[dataid].drawLine = true;
|
---|
| 664 | vi->vData[dataid].lineColor = color;
|
---|
| 665 | vi->vData[dataid].lineWidth = width;
|
---|
| 666 | vi->vData[dataid].lineStyle = style;
|
---|
| 667 | }
|
---|
| 668 |
|
---|
| 669 | void Plotter2::showLine(const int inVpid, const int inDataid) {
|
---|
| 670 | int vpid = inVpid;
|
---|
| 671 | if (vpid < 0) {
|
---|
| 672 | vpid = vInfo.size() - 1;
|
---|
| 673 | }
|
---|
| 674 | if (vpid < 0) {
|
---|
| 675 | exit(0);
|
---|
| 676 | }
|
---|
| 677 |
|
---|
| 678 | int dataid = inDataid;
|
---|
| 679 | if (dataid < 0) {
|
---|
| 680 | dataid = vInfo[vpid].vData.size() - 1;
|
---|
| 681 | }
|
---|
| 682 | if (dataid < 0) {
|
---|
| 683 | exit(0);
|
---|
| 684 | }
|
---|
| 685 |
|
---|
| 686 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 687 | vi->vData[dataid].drawLine = true;
|
---|
| 688 | }
|
---|
| 689 |
|
---|
| 690 | void Plotter2::hideLine(const int inVpid, const int inDataid) {
|
---|
| 691 | int vpid = inVpid;
|
---|
| 692 | if (vpid < 0) {
|
---|
| 693 | vpid = vInfo.size() - 1;
|
---|
| 694 | }
|
---|
| 695 | if (vpid < 0) {
|
---|
| 696 | exit(0);
|
---|
| 697 | }
|
---|
| 698 |
|
---|
| 699 | int dataid = inDataid;
|
---|
| 700 | if (dataid < 0) {
|
---|
| 701 | dataid = vInfo[vpid].vData.size() - 1;
|
---|
| 702 | }
|
---|
| 703 | if (dataid < 0) {
|
---|
| 704 | exit(0);
|
---|
| 705 | }
|
---|
| 706 |
|
---|
| 707 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 708 | vi->vData[dataid].drawLine = false;
|
---|
| 709 | }
|
---|
| 710 |
|
---|
| 711 | void Plotter2::setPoint(const int type, const float size, const int color, const int inVpid, const int inDataid) {
|
---|
| 712 | int vpid = inVpid;
|
---|
| 713 | if (vpid < 0) {
|
---|
| 714 | vpid = vInfo.size() - 1;
|
---|
| 715 | }
|
---|
| 716 | if (vpid < 0) {
|
---|
| 717 | Plotter2ViewportInfo vi;
|
---|
| 718 | vInfo.push_back(vi);
|
---|
| 719 | vpid = 0;
|
---|
| 720 | }
|
---|
| 721 |
|
---|
| 722 | int dataid = inDataid;
|
---|
| 723 | if (dataid < 0) {
|
---|
| 724 | dataid = vInfo[vpid].vData.size() - 1;
|
---|
| 725 | }
|
---|
| 726 |
|
---|
| 727 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 728 | vi->vData[dataid].drawMarker = true;
|
---|
| 729 | vi->vData[dataid].markerType = type;
|
---|
| 730 | vi->vData[dataid].markerSize = size;
|
---|
| 731 | vi->vData[dataid].markerColor = color;
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | void Plotter2::showPoint(const int inVpid, const int inDataid) {
|
---|
| 735 | int vpid = inVpid;
|
---|
| 736 | if (vpid < 0) {
|
---|
| 737 | vpid = vInfo.size() - 1;
|
---|
| 738 | }
|
---|
| 739 | if (vpid < 0) {
|
---|
| 740 | exit(0);
|
---|
| 741 | }
|
---|
| 742 |
|
---|
| 743 | int dataid = inDataid;
|
---|
| 744 | if (dataid < 0) {
|
---|
| 745 | dataid = vInfo[vpid].vData.size() - 1;
|
---|
| 746 | }
|
---|
| 747 | if (dataid < 0) {
|
---|
| 748 | exit(0);
|
---|
| 749 | }
|
---|
| 750 |
|
---|
| 751 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 752 | vi->vData[dataid].drawMarker = true;
|
---|
| 753 | }
|
---|
| 754 |
|
---|
| 755 | void Plotter2::hidePoint(const int inVpid, const int inDataid) {
|
---|
| 756 | int vpid = inVpid;
|
---|
| 757 | if (vpid < 0) {
|
---|
| 758 | vpid = vInfo.size() - 1;
|
---|
| 759 | }
|
---|
| 760 | if (vpid < 0) {
|
---|
| 761 | exit(0);
|
---|
| 762 | }
|
---|
| 763 |
|
---|
| 764 | int dataid = inDataid;
|
---|
| 765 | if (dataid < 0) {
|
---|
| 766 | dataid = vInfo[vpid].vData.size() - 1;
|
---|
| 767 | }
|
---|
| 768 | if (dataid < 0) {
|
---|
| 769 | exit(0);
|
---|
| 770 | }
|
---|
| 771 |
|
---|
| 772 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 773 | vi->vData[dataid].drawMarker = false;
|
---|
| 774 | }
|
---|
| 775 |
|
---|
| 776 | void Plotter2::setMaskX(const float xmin, const float xmax, const int color, const int fill, const int width, const float hsep, const int inVpid) {
|
---|
| 777 | int vpid = inVpid;
|
---|
| 778 | if (vpid < 0) {
|
---|
| 779 | vpid = vInfo.size() - 1;
|
---|
| 780 | }
|
---|
| 781 | if (vpid < 0) {
|
---|
| 782 | Plotter2ViewportInfo vi;
|
---|
| 783 | vInfo.push_back(vi);
|
---|
| 784 | vpid = 0;
|
---|
| 785 | }
|
---|
| 786 |
|
---|
| 787 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 788 |
|
---|
| 789 | Plotter2RectInfo ri;
|
---|
| 790 | ri.xmin = xmin;
|
---|
| 791 | ri.xmax = xmax;
|
---|
| 792 | std::vector<float> yrange = vi->getRangeY();
|
---|
| 793 | float yexcess = 0.1*(yrange[1] - yrange[0]);
|
---|
| 794 | ri.ymin = yrange[0] - yexcess;
|
---|
| 795 | ri.ymax = yrange[1] + yexcess;
|
---|
| 796 | ri.color = color;
|
---|
| 797 | ri.fill = fill;
|
---|
| 798 | ri.width = width;
|
---|
| 799 | ri.hsep = hsep;
|
---|
| 800 |
|
---|
| 801 | vi->vRect.push_back(ri);
|
---|
| 802 | }
|
---|
| 803 |
|
---|
| 804 | 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) {
|
---|
| 805 | int vpid = inVpid;
|
---|
| 806 | if (vpid < 0) {
|
---|
| 807 | vpid = vInfo.size() - 1;
|
---|
| 808 | }
|
---|
| 809 | if (vpid < 0) {
|
---|
| 810 | Plotter2ViewportInfo vi;
|
---|
| 811 | vInfo.push_back(vi);
|
---|
| 812 | vpid = 0;
|
---|
| 813 | }
|
---|
| 814 |
|
---|
| 815 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 816 |
|
---|
| 817 | std::string styleString;
|
---|
| 818 | if (style == "") {
|
---|
| 819 | styleString = "";
|
---|
| 820 | } else if (style == "roman") {
|
---|
| 821 | styleString = "\\fr";
|
---|
| 822 | } else if (style == "italic") {
|
---|
| 823 | styleString = "\\fi";
|
---|
| 824 | } else if (style == "script") {
|
---|
| 825 | styleString = "\\fs";
|
---|
| 826 | }
|
---|
| 827 | vi->labelXString = styleString + label;
|
---|
| 828 |
|
---|
| 829 | float posx = inPosx;
|
---|
| 830 | if (posx < 0.0) {
|
---|
| 831 | posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
|
---|
| 832 | }
|
---|
| 833 | vi->labelXPosX = posx;
|
---|
| 834 |
|
---|
| 835 | float posy = inPosy;
|
---|
| 836 | if (posy < 0.0) {
|
---|
| 837 | posy = 0.35*vi->vpPosYMin;
|
---|
| 838 | }
|
---|
| 839 | vi->labelXPosY = posy;
|
---|
| 840 |
|
---|
| 841 | vi->labelXAngle = 0.0;
|
---|
| 842 | vi->labelXFJust = 0.5;
|
---|
| 843 | vi->labelXSize = size;
|
---|
| 844 | vi->labelXColor = color;
|
---|
| 845 | vi->labelXBColor = bgcolor;
|
---|
| 846 | }
|
---|
| 847 |
|
---|
| 848 | 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) {
|
---|
| 849 | int vpid = inVpid;
|
---|
| 850 | if (vpid < 0) {
|
---|
| 851 | vpid = vInfo.size() - 1;
|
---|
| 852 | }
|
---|
| 853 | if (vpid < 0) {
|
---|
| 854 | Plotter2ViewportInfo vi;
|
---|
| 855 | vInfo.push_back(vi);
|
---|
| 856 | vpid = 0;
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 860 |
|
---|
| 861 | std::string styleString;
|
---|
| 862 | if (style == "") {
|
---|
| 863 | styleString = "";
|
---|
| 864 | } else if (style == "roman") {
|
---|
| 865 | styleString = "\\fr";
|
---|
| 866 | } else if (style == "italic") {
|
---|
| 867 | styleString = "\\fi";
|
---|
| 868 | } else if (style == "script") {
|
---|
| 869 | styleString = "\\fs";
|
---|
| 870 | }
|
---|
| 871 | vi->labelYString = styleString + label;
|
---|
| 872 |
|
---|
| 873 | float posx = inPosx;
|
---|
| 874 | if (posx < 0.0) {
|
---|
| 875 | posx = 0.35*vi->vpPosXMin;
|
---|
| 876 | }
|
---|
| 877 | vi->labelYPosX = posx;
|
---|
| 878 |
|
---|
| 879 | float posy = inPosy;
|
---|
| 880 | if (posy < 0.0) {
|
---|
| 881 | posy = 0.5*(vi->vpPosYMin + vi->vpPosYMax);
|
---|
| 882 | }
|
---|
| 883 | vi->labelYPosY = posy;
|
---|
| 884 |
|
---|
| 885 | vi->labelYAngle = 90.0;
|
---|
| 886 | vi->labelYFJust = 0.5;
|
---|
| 887 | vi->labelYSize = size;
|
---|
| 888 | vi->labelYColor = color;
|
---|
| 889 | vi->labelYBColor = bgcolor;
|
---|
| 890 | }
|
---|
| 891 |
|
---|
| 892 | 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) {
|
---|
| 893 | int vpid = inVpid;
|
---|
| 894 | if (vpid < 0) {
|
---|
| 895 | vpid = vInfo.size() - 1;
|
---|
| 896 | }
|
---|
| 897 | if (vpid < 0) {
|
---|
| 898 | Plotter2ViewportInfo vi;
|
---|
| 899 | vInfo.push_back(vi);
|
---|
| 900 | vpid = 0;
|
---|
| 901 | }
|
---|
| 902 |
|
---|
| 903 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 904 |
|
---|
| 905 | std::string styleString;
|
---|
| 906 | if (style == "") {
|
---|
| 907 | styleString = "";
|
---|
| 908 | } else if (style == "roman") {
|
---|
| 909 | styleString = "\\fr";
|
---|
| 910 | } else if (style == "italic") {
|
---|
| 911 | styleString = "\\fi";
|
---|
| 912 | } else if (style == "script") {
|
---|
| 913 | styleString = "\\fs";
|
---|
| 914 | }
|
---|
| 915 | vi->titleString = styleString + label;
|
---|
| 916 |
|
---|
| 917 | float posx = inPosx;
|
---|
| 918 | if (posx < 0.0) {
|
---|
| 919 | posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
|
---|
| 920 | }
|
---|
| 921 | vi->titlePosX = posx;
|
---|
| 922 |
|
---|
| 923 | float posy = inPosy;
|
---|
| 924 | if (posy < 0.0) {
|
---|
| 925 | posy = vi->vpPosYMax + 0.25*(1.0 - vi->vpPosYMax);
|
---|
| 926 | }
|
---|
| 927 | vi->titlePosY = posy;
|
---|
| 928 |
|
---|
| 929 | vi->titleAngle = 0.0;
|
---|
| 930 | vi->titleFJust = 0.5;
|
---|
| 931 | vi->titleSize = size;
|
---|
| 932 | vi->titleColor = color;
|
---|
| 933 | vi->titleBColor = bgcolor;
|
---|
| 934 | }
|
---|
| 935 |
|
---|
| 936 | void Plotter2::setViewportBackgroundColor(const int bgcolor, const int inVpid) {
|
---|
| 937 | int vpid = inVpid;
|
---|
| 938 | if (vpid < 0) {
|
---|
| 939 | vpid = vInfo.size() - 1;
|
---|
| 940 | }
|
---|
| 941 | if (vpid < 0) {
|
---|
| 942 | exit(0);
|
---|
| 943 | }
|
---|
| 944 |
|
---|
| 945 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 946 | vi->vpBColor = bgcolor;
|
---|
| 947 | }
|
---|
| 948 |
|
---|
[2839] | 949 | /*
|
---|
[2830] | 950 | 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) {
|
---|
| 951 | int vpid = inVpid;
|
---|
| 952 | if (vpid < 0) {
|
---|
| 953 | vpid = vInfo.size() - 1;
|
---|
| 954 | }
|
---|
| 955 | if (vpid < 0) {
|
---|
| 956 | Plotter2ViewportInfo vi;
|
---|
| 957 | vInfo.push_back(vi);
|
---|
| 958 | vpid = 0;
|
---|
| 959 | }
|
---|
| 960 |
|
---|
| 961 | std::string styleString;
|
---|
| 962 | if (style == "") {
|
---|
| 963 | styleString = "";
|
---|
| 964 | } else if (style == "roman") {
|
---|
| 965 | styleString = "\\fr";
|
---|
| 966 | } else if (style == "italic") {
|
---|
| 967 | styleString = "\\fi";
|
---|
| 968 | } else if (style == "script") {
|
---|
| 969 | styleString = "\\fs";
|
---|
| 970 | }
|
---|
| 971 |
|
---|
| 972 | Plotter2ViewportInfo* vi = &vInfo[vpid];
|
---|
| 973 | //vi->titleString = styleString + label;
|
---|
| 974 | //vi->titlePosX = posx;
|
---|
| 975 | //vi->titlePosY = posy;
|
---|
| 976 | //vi->titleAngle = angle;
|
---|
| 977 | //vi->titleFJust = fjust;
|
---|
| 978 | //vi->titleSize = size;
|
---|
| 979 | //vi->titleColor = color;
|
---|
| 980 | //vi->titleBColor = bgcolor;
|
---|
| 981 | }
|
---|
[2839] | 982 | */
|
---|
[2830] | 983 |
|
---|
| 984 | void Plotter2::close() {
|
---|
| 985 | if (hasDevice) {
|
---|
| 986 | cpgclos();
|
---|
| 987 | hasDevice = false;
|
---|
| 988 | }
|
---|
| 989 | }
|
---|
| 990 |
|
---|
| 991 | void Plotter2::plot() {
|
---|
| 992 | open();
|
---|
| 993 |
|
---|
| 994 | cpgscr(0, 1.0, 1.0, 1.0); // set background color white
|
---|
| 995 | cpgscr(1, 0.0, 0.0, 0.0); // set foreground color black
|
---|
| 996 |
|
---|
[2834] | 997 | for (unsigned int i = 0; i < vInfo.size(); ++i) {
|
---|
[2830] | 998 | Plotter2ViewportInfo vi = vInfo[i];
|
---|
| 999 |
|
---|
| 1000 | if (vi.showViewport) {
|
---|
| 1001 | cpgstbg(0); // reset background colour to the initial one (white)
|
---|
| 1002 | cpgsci(1); // reset foreground colour to the initial one (black)
|
---|
| 1003 | cpgsls(1); // reset line style to solid
|
---|
| 1004 | cpgslw(1); // reset line width to 1
|
---|
| 1005 | cpgscf(1); // reset font style to normal
|
---|
| 1006 | cpgsch(vi.fontSizeDef);// reset font size
|
---|
| 1007 | cpgsfs(1); // reset fill style (solid)
|
---|
| 1008 |
|
---|
| 1009 | // setup viewport
|
---|
| 1010 | cpgsvp(vi.vpPosXMin, vi.vpPosXMax, vi.vpPosYMin, vi.vpPosYMax);
|
---|
| 1011 | vi.adjustRange();
|
---|
| 1012 | vi.adjustTickInterval();
|
---|
| 1013 |
|
---|
| 1014 | cpgswin(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax);
|
---|
| 1015 |
|
---|
| 1016 | // background color (default is transparent)
|
---|
| 1017 | if (vi.vpBColor >= 0) {
|
---|
| 1018 | cpgsci(vi.vpBColor);
|
---|
| 1019 | cpgrect(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax);
|
---|
| 1020 | cpgsci(1); // reset foreground colour to the initial one (black)
|
---|
| 1021 | }
|
---|
| 1022 |
|
---|
| 1023 | // data
|
---|
[2834] | 1024 | for (unsigned int j = 0; j < vi.vData.size(); ++j) {
|
---|
[2830] | 1025 | cpgstbg(0); // reset background colour to the initial one (white)
|
---|
| 1026 | cpgsci(1); // reset foreground colour to the initial one (black)
|
---|
| 1027 | cpgsls(1); // reset line style to solid
|
---|
| 1028 | cpgslw(1); // reset line width to 1
|
---|
| 1029 | cpgscf(1); // reset font style to normal
|
---|
| 1030 | cpgsch(vi.fontSizeDef);// reset font size
|
---|
| 1031 |
|
---|
| 1032 | Plotter2DataInfo di = vi.vData[j];
|
---|
| 1033 | std::vector<float> vxdata = di.xData;
|
---|
| 1034 | int ndata = vxdata.size();
|
---|
| 1035 | float* pxdata = new float[ndata];
|
---|
| 1036 | float* pydata = new float[ndata];
|
---|
| 1037 | for (int k = 0; k < ndata; ++k) {
|
---|
| 1038 | pxdata[k] = di.xData[k];
|
---|
| 1039 | pydata[k] = di.yData[k];
|
---|
| 1040 | }
|
---|
| 1041 |
|
---|
| 1042 | if (di.drawLine) {
|
---|
| 1043 | cpgsls(di.lineStyle);
|
---|
| 1044 | cpgslw(di.lineWidth);
|
---|
| 1045 | int colorIdx = di.lineColor;
|
---|
| 1046 | if (colorIdx < 0) {
|
---|
| 1047 | colorIdx = (j + 1) % 15 + 1;
|
---|
| 1048 | }
|
---|
| 1049 | cpgsci(colorIdx);
|
---|
| 1050 | cpgline(ndata, pxdata, pydata);
|
---|
| 1051 | }
|
---|
| 1052 |
|
---|
| 1053 | if (di.drawMarker) {
|
---|
| 1054 | cpgsch(di.markerSize);
|
---|
| 1055 | cpgsci(di.markerColor);
|
---|
| 1056 | cpgpt(ndata, pxdata, pydata, di.markerType);
|
---|
| 1057 | }
|
---|
| 1058 |
|
---|
| 1059 | delete [] pxdata;
|
---|
| 1060 | delete [] pydata;
|
---|
| 1061 | }
|
---|
| 1062 |
|
---|
| 1063 | // masks
|
---|
[2834] | 1064 | for (unsigned int j = 0; j < vi.vRect.size(); ++j) {
|
---|
[2830] | 1065 | cpgstbg(0); // reset background colour to the initial one (white)
|
---|
| 1066 | cpgsci(1); // reset foreground colour to the initial one (black)
|
---|
| 1067 | cpgsls(1); // reset line style to solid
|
---|
| 1068 | cpgslw(1); // reset line width to 1
|
---|
| 1069 | cpgscf(1); // reset font style to normal
|
---|
| 1070 | cpgsch(vi.fontSizeDef);// reset font size
|
---|
| 1071 | cpgsfs(1); // reset fill style (solid)
|
---|
| 1072 |
|
---|
| 1073 | Plotter2RectInfo ri = vi.vRect[j];
|
---|
| 1074 | cpgsci(ri.color);
|
---|
| 1075 | cpgsfs(ri.fill);
|
---|
| 1076 | cpgslw(ri.width);
|
---|
| 1077 | cpgshs(45.0, ri.hsep, 0.0);
|
---|
| 1078 | float* mxdata = new float[4];
|
---|
| 1079 | float* mydata = new float[4];
|
---|
| 1080 | mxdata[0] = ri.xmin;
|
---|
| 1081 | mxdata[1] = ri.xmax;
|
---|
| 1082 | mxdata[2] = ri.xmax;
|
---|
| 1083 | mxdata[3] = ri.xmin;
|
---|
| 1084 | mydata[0] = ri.ymin;
|
---|
| 1085 | mydata[1] = ri.ymin;
|
---|
| 1086 | mydata[2] = ri.ymax;
|
---|
| 1087 | mydata[3] = ri.ymax;
|
---|
| 1088 | cpgpoly(4, mxdata, mydata);
|
---|
| 1089 | }
|
---|
| 1090 |
|
---|
| 1091 | cpgstbg(0); // reset background colour to the initial one (white)
|
---|
| 1092 | cpgsci(1); // reset foreground colour to the initial one (black)
|
---|
| 1093 | cpgsls(1); // reset line style to solid
|
---|
| 1094 | cpgslw(1); // reset line width to 1
|
---|
| 1095 | cpgscf(1); // reset font style to normal
|
---|
| 1096 | cpgsch(vi.fontSizeDef);// reset font size
|
---|
| 1097 | cpgsfs(1); // reset fill style (solid)
|
---|
| 1098 |
|
---|
| 1099 | cpgbox("BCTS", vi.majorTickIntervalX, vi.nMinorTickWithinMajorTicksX,
|
---|
| 1100 | "BCTSV", vi.majorTickIntervalY, vi.nMinorTickWithinMajorTicksY);
|
---|
| 1101 |
|
---|
| 1102 | // viewport outline, ticks and number labels
|
---|
| 1103 | std::string numformatx, numformaty;
|
---|
| 1104 | if (vi.numLocationX == "l") {
|
---|
| 1105 | numformatx = "N";
|
---|
| 1106 | } else if (vi.numLocationX == "r") {
|
---|
| 1107 | numformatx = "M";
|
---|
| 1108 | } else if (vi.numLocationX == "") {
|
---|
| 1109 | numformatx = "";
|
---|
| 1110 | }
|
---|
| 1111 | if (vi.numLocationY == "b") {
|
---|
| 1112 | numformaty = "NV";
|
---|
| 1113 | } else if (vi.numLocationY == "t") {
|
---|
| 1114 | numformaty = "MV";
|
---|
| 1115 | } else if (vi.numLocationY == "") {
|
---|
| 1116 | numformaty = "";
|
---|
| 1117 | }
|
---|
| 1118 |
|
---|
| 1119 | cpgbox(numformatx.c_str(), vi.majorTickIntervalX * vi.nMajorTickWithinTickNumsX, 0,
|
---|
| 1120 | numformaty.c_str(), vi.majorTickIntervalY * vi.nMajorTickWithinTickNumsY, 0);
|
---|
| 1121 |
|
---|
| 1122 | float xpos, ypos;
|
---|
| 1123 |
|
---|
| 1124 | // x-label
|
---|
| 1125 | vi.getWorldCoordByWindowCoord(vi.labelXPosX, vi.labelXPosY, &xpos, &ypos);
|
---|
| 1126 | cpgsch(vi.labelXSize);
|
---|
| 1127 | cpgsci(vi.labelXColor);
|
---|
| 1128 | cpgstbg(vi.labelXBColor); //outside viewports, works ONLY with /xwindow
|
---|
| 1129 | cpgptxt(xpos, ypos, vi.labelXAngle, vi.labelXFJust, vi.labelXString.c_str());
|
---|
| 1130 |
|
---|
| 1131 | // y-label
|
---|
| 1132 | vi.getWorldCoordByWindowCoord(vi.labelYPosX, vi.labelYPosY, &xpos, &ypos);
|
---|
| 1133 | cpgsch(vi.labelYSize);
|
---|
| 1134 | cpgsci(vi.labelYColor);
|
---|
| 1135 | cpgstbg(vi.labelYBColor); //outside viewports, works ONLY with /xwindow
|
---|
| 1136 | cpgptxt(xpos, ypos, vi.labelYAngle, vi.labelYFJust, vi.labelYString.c_str());
|
---|
| 1137 |
|
---|
| 1138 | // title
|
---|
| 1139 | vi.getWorldCoordByWindowCoord(vi.titlePosX, vi.titlePosY, &xpos, &ypos);
|
---|
| 1140 | cpgsch(vi.titleSize);
|
---|
| 1141 | cpgsci(vi.titleColor);
|
---|
| 1142 | cpgstbg(vi.titleBColor); //outside viewports, works ONLY with /xwindow
|
---|
| 1143 | cpgptxt(xpos, ypos, vi.titleAngle, vi.titleFJust, vi.titleString.c_str());
|
---|
| 1144 | }
|
---|
| 1145 |
|
---|
| 1146 | }
|
---|
| 1147 |
|
---|
| 1148 | close();
|
---|
| 1149 | }
|
---|
| 1150 |
|
---|
| 1151 | } // namespace asap
|
---|