vtkGL2PSContextDevice2D.cxx 22.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkGL2PSContextDevice2D.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkGL2PSContextDevice2D.h"

#include "vtkBrush.h"
#include "vtkGL2PSUtilities.h"
#include "vtkMathTextUtilities.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
23
#include "vtkOpenGLGL2PSHelper.h"
24 25 26 27 28 29 30 31 32
#include "vtkOpenGLRenderWindow.h"
#include "vtkPath.h"
#include "vtkPen.h"
#include "vtkStdString.h"
#include "vtkTextProperty.h"
#include "vtkUnicodeString.h"

#include "vtk_gl2ps.h"

33 34
#include <sstream>

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkGL2PSContextDevice2D)

//-----------------------------------------------------------------------------
vtkGL2PSContextDevice2D::vtkGL2PSContextDevice2D()
{
}

//-----------------------------------------------------------------------------
vtkGL2PSContextDevice2D::~vtkGL2PSContextDevice2D()
{
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawPoly(float *f, int n, unsigned char *colors,
                                       int nc_comps)
{
  // Only draw the quad if custom colors are defined or alpha is non-zero.
  // Postscript can't handle transparency, and the resulting output will have
  // a border around every quad otherwise.
55
  if ((colors || this->Pen->GetColorObject().GetAlpha() != 0) &&
56 57 58 59 60 61 62 63 64 65
      this->Pen->GetLineType() != vtkPen::NO_PEN)
    {
    this->Superclass::DrawPoly(f, n, colors, nc_comps);
    }
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawPoints(float *points, int n,
                                         unsigned char *colors, int nc_comps)
{
66
  if (colors || this->Pen->GetColorObject().GetAlpha() != 0)
67 68 69 70 71 72 73 74 75 76 77
    {
    this->Superclass::DrawPoints(points, n, colors, nc_comps);
    }
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawPointSprites(vtkImageData *sprite,
                                               float *points, int n,
                                               unsigned char *colors,
                                               int nc_comps)
{
78
  if (colors || this->Pen->GetColorObject().GetAlpha() != 0)
79 80 81 82 83
    {
    this->Superclass::DrawPointSprites(sprite, points, n, colors, nc_comps);
    }
}

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawMarkers(int shape, bool highlight,
                                          float *points, int n,
                                          unsigned char *colors, int nc_comps)
{
  switch (shape)
    {
    case VTK_MARKER_CROSS:
      this->DrawCrossMarkers(highlight, points, n, colors, nc_comps);
      break;
    default:
      // default is here for consistency -- Superclass defaults to plus for
      // unrecognized shapes.
    case VTK_MARKER_PLUS:
      this->DrawPlusMarkers(highlight, points, n, colors, nc_comps);
      break;
    case VTK_MARKER_SQUARE:
      this->DrawSquareMarkers(highlight, points, n, colors, nc_comps);
      break;
    case VTK_MARKER_CIRCLE:
      this->DrawCircleMarkers(highlight, points, n, colors, nc_comps);
      break;
    case VTK_MARKER_DIAMOND:
      this->DrawDiamondMarkers(highlight, points, n, colors, nc_comps);
      break;
    }
}

112 113 114
//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawQuad(float *points, int n)
{
115
  if (this->Brush->GetColorObject().GetAlpha() != 0)
116 117 118 119 120 121 122 123
    {
    this->Superclass::DrawQuad(points, n);
    }
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawQuadStrip(float *points, int n)
{
124
  if (this->Brush->GetColorObject().GetAlpha() != 0)
125 126 127 128 129 130 131 132
    {
    this->Superclass::DrawQuadStrip(points, n);
    }
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawPolygon(float *points, int n)
{
133
  if (this->Brush->GetColorObject().GetAlpha() != 0)
134 135 136 137 138 139 140 141 142 143 144
    {
    this->Superclass::DrawPolygon(points, n);
    }
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawEllipseWedge(float x, float y,
                                               float outRx, float outRy,
                                               float inRx, float inRy,
                                               float startAngle, float stopAngle)
{
145 146 147 148 149 150 151
  if (this->Brush->GetColorObject().GetAlpha() == 0)
    {
    return;
    }

  // The path implementation can't handle start/stop angles. Defer to the
  // superclass in this case.
152
  if (std::fabs(startAngle) > 1e-5f || std::fabs(stopAngle - 360.0f) > 1e-5f)
153 154 155 156
    {
    this->Superclass::DrawEllipseWedge(x, y, outRx, outRy, inRx, inRy,
                                       startAngle, stopAngle);
    }
157 158 159 160 161

  vtkNew<vtkPath> path;
  this->AddEllipseToPath(path.GetPointer(), 0.f, 0.f, outRx, outRy, false);
  this->AddEllipseToPath(path.GetPointer(), 0.f, 0.f, inRx, inRy, true);

162 163 164 165 166 167
  std::stringstream label;
  label << "vtkGL2PSContextDevice2D::DrawEllipseWedge("
        << x << ", " << y << ", " << outRx << ", " << outRy << ", "
        << inRx << ", " << inRy << ", " << startAngle << ", " << stopAngle
        << ") path:";

168 169 170 171 172 173 174 175 176 177
  unsigned char color[4];
  this->Brush->GetColor(color);

  double rasterPos[3] = {static_cast<double>(x), static_cast<double>(y), 0.};

  this->TransformPoint(x, y);
  double windowPos[3] = {static_cast<double>(x), static_cast<double>(y), 0.};

  vtkGL2PSUtilities::DrawPath(path.GetPointer(), rasterPos, windowPos, color,
                              NULL, 0.0, -1.f, label.str().c_str());
178 179 180 181
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawEllipticArc(float x, float y,
182 183 184
                                              float rx, float ry,
                                              float startAngle,
                                              float stopAngle)
185
{
186 187 188 189 190 191 192 193
  if (this->Brush->GetColorObject().GetAlpha() == 0)
    {
    return;
    }

  // The path implementation can't handle start/stop angles. Defer to the
  // superclass in this case.
  if (fabs(startAngle) > 1e-5 || fabs(stopAngle - 360.0) > 1e-5)
194
    {
195
    this->Superclass::DrawEllipticArc(x, y, rx, ry, startAngle, stopAngle);
196
    }
197 198 199 200 201 202

  vtkNew<vtkPath> path;
  this->AddEllipseToPath(path.GetPointer(), 0.f, 0.f, rx, ry, false);
  this->TransformPath(path.GetPointer());

  double origin[3] = {x, y, 0.f};
203 204

  // Fill
205 206
  unsigned char fillColor[4];
  this->Brush->GetColor(fillColor);
207 208 209 210 211 212 213 214

  std::stringstream label;
  label << "vtkGL2PSContextDevice2D::DrawEllipticArc("
        << x << ", " << y << ", " << rx << ", " << ry << ", "
        << startAngle << ", " << stopAngle << ") fill:";

  vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, fillColor,
                              NULL, 0.0, -1.f, label.str().c_str());
215 216

  // and stroke
217 218 219
  unsigned char strokeColor[4];
  this->Pen->GetColor(strokeColor);
  float strokeWidth = this->Pen->GetWidth();
220 221 222 223 224 225

  label.str("");
  label.clear();
  label << "vtkGL2PSContextDevice2D::DrawEllipticArc("
        << x << ", " << y << ", " << rx << ", " << ry << ", "
        << startAngle << ", " << stopAngle << ") stroke:";
226
  vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, strokeColor,
227
                              NULL, 0.0, strokeWidth, label.str().c_str());
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawString(float *point,
                                         const vtkStdString &string)
{
  double p[3] = {point[0], point[1], 0.f};
  vtkGL2PSUtilities::DrawString(string.c_str(), this->TextProp, p);
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawString(float *point,
                                         const vtkUnicodeString &string)
{
  double p[3] = {point[0], point[1], 0.f};
  vtkGL2PSUtilities::DrawString(string.utf8_str(), this->TextProp, p);
}

246
//-----------------------------------------------------------------------------
247
void vtkGL2PSContextDevice2D::DrawMathTextString(float apoint[],
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
                                                 const vtkStdString &string)
{
  vtkNew<vtkPath> path;
  bool ok;
  if (vtkMathTextUtilities::GetInstance())
    {
    ok = vtkMathTextUtilities::GetInstance()->StringToPath(string.c_str(),
                                                           path.GetPointer(),
                                                           this->TextProp);
    }
  else
    {
    vtkWarningMacro(<<"No vtkMathTextUtilities available! Enable the "
                    "vtkMatplotlib module to fix this.");
    return;
    }

  if (!ok)
    {
    return;
    }

270
  double origin[3] = {apoint[0], apoint[1], 0.f};
271 272 273
  double rotateAngle = this->TextProp->GetOrientation();
  double dcolor[3];
  this->TextProp->GetColor(dcolor);
274
  unsigned char color[4];
275 276 277
  color[0] = static_cast<unsigned char>(dcolor[0]*255);
  color[1] = static_cast<unsigned char>(dcolor[1]*255);
  color[2] = static_cast<unsigned char>(dcolor[2]*255);
278
  color[3] = static_cast<unsigned char>(this->TextProp->GetOpacity()*255);
279

280
  this->TransformPath(path.GetPointer());
281

282
  vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, color, NULL,
283 284
                              rotateAngle, -1.f,
                              ("Pathified string: " + string).c_str());
285 286 287 288 289 290 291 292 293 294 295
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::ApplyPen(vtkPen *pen)
{
  this->Superclass::ApplyPen(pen);
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::SetPointSize(float size)
{
296 297
  glPointSize(size);
  vtkOpenGLGL2PSHelper::SetPointSize(size);
298 299 300 301 302
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::SetLineWidth(float width)
{
303 304
  glLineWidth(width);
  vtkOpenGLGL2PSHelper::SetLineWidth(width);
305 306 307 308 309 310 311 312
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::SetLineType(int type)
{
  // Must call gl2psEnable(GL_LINE_STIPPLE) after glLineStipple. Let the
  // superclass handle setting the stipple type:
  this->Superclass::SetLineType(type);
313
  if (type == vtkPen::SOLID_LINE)
314
    {
315
    vtkOpenGLGL2PSHelper::DisableStipple();
316
    }
317
  else
318
    {
319
    vtkOpenGLGL2PSHelper::EnableStipple();
320 321 322
    }
}

323 324 325 326 327 328 329 330 331 332
//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawCrossMarkers(bool highlight, float *points,
                                               int n, unsigned char *colors,
                                               int nc_comps)
{
  float oldWidth = this->Pen->GetWidth();
  unsigned char oldColor[4];
  this->Pen->GetColor(oldColor);
  int oldLineType = this->Pen->GetLineType();

333 334 335 336 337 338
  float halfWidth = oldWidth * 0.5f;
  float deltaX = halfWidth;
  float deltaY = halfWidth;

  this->TransformSize(deltaX, deltaY);

339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
  if (highlight)
    {
    this->Pen->SetWidth(1.5);
    }
  else
    {
    this->Pen->SetWidth(0.5);
    }
  this->Pen->SetLineType(vtkPen::SOLID_LINE);

  float curLine[4];
  unsigned char color[4];
  for (int i = 0; i < n; ++i)
    {
    float *point = points + (i * 2);
    if  (colors)
      {
      color[3] = 255;
      switch (nc_comps)
        {
        case 4:
        case 3:
          memcpy(color, colors + (i * nc_comps), nc_comps);
          break;
        case 2:
          color[3] = colors[i * nc_comps + 1];
        case 1:
          memset(color, colors[i * nc_comps], 3);
          break;
        default:
          vtkErrorMacro(<<"Invalid number of color components: " << nc_comps);
          break;
        }

      this->Pen->SetColor(color);
      }

    // The first line of the cross:
377 378 379 380
    curLine[0] = point[0] + deltaX;
    curLine[1] = point[1] + deltaY;
    curLine[2] = point[0] - deltaX;
    curLine[3] = point[1] - deltaY;
381 382 383
    this->DrawPoly(curLine, 2);

    // And the second:
384 385 386 387
    curLine[0] = point[0] + deltaX;
    curLine[1] = point[1] - deltaY;
    curLine[2] = point[0] - deltaX;
    curLine[3] = point[1] + deltaY;
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
    this->DrawPoly(curLine, 2);
    }

  this->Pen->SetWidth(oldWidth);
  this->Pen->SetColor(oldColor);
  this->Pen->SetLineType(oldLineType);
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawPlusMarkers(bool highlight, float *points,
                                              int n, unsigned char *colors,
                                              int nc_comps)
{
  float oldWidth = this->Pen->GetWidth();
  unsigned char oldColor[4];
  this->Pen->GetColor(oldColor);
  int oldLineType = this->Pen->GetLineType();

406 407 408 409 410 411
  float halfWidth = oldWidth * 0.5f;
  float deltaX = halfWidth;
  float deltaY = halfWidth;

  this->TransformSize(deltaX, deltaY);

412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
  if (highlight)
    {
    this->Pen->SetWidth(1.5);
    }
  else
    {
    this->Pen->SetWidth(0.5);
    }
  this->Pen->SetLineType(vtkPen::SOLID_LINE);

  float curLine[4];
  unsigned char color[4];
  for (int i = 0; i < n; ++i)
    {
    float *point = points + (i * 2);
    if  (colors)
      {
      color[3] = 255;
      switch (nc_comps)
        {
        case 4:
        case 3:
          memcpy(color, colors + (i * nc_comps), nc_comps);
          break;
        case 2:
          color[3] = colors[i * nc_comps + 1];
        case 1:
          memset(color, colors[i * nc_comps], 3);
          break;
        default:
          vtkErrorMacro(<<"Invalid number of color components: " << nc_comps);
          break;
        }

      this->Pen->SetColor(color);
      }

    // The first line of the plus:
450
    curLine[0] = point[0] - deltaX;
451
    curLine[1] = point[1];
452
    curLine[2] = point[0] + deltaX;
453 454 455 456 457
    curLine[3] = point[1];
    this->DrawPoly(curLine, 2);

    // And the second:
    curLine[0] = point[0];
458
    curLine[1] = point[1] - deltaY;
459
    curLine[2] = point[0];
460
    curLine[3] = point[1] + deltaY;
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
    this->DrawPoly(curLine, 2);
    }

  this->Pen->SetWidth(oldWidth);
  this->Pen->SetColor(oldColor);
  this->Pen->SetLineType(oldLineType);
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawSquareMarkers(bool /*highlight*/,
                                                float *points,
                                                int n, unsigned char *colors,
                                                int nc_comps)
{
  unsigned char oldColor[4];
  this->Brush->GetColor(oldColor);

  this->Brush->SetColor(this->Pen->GetColor());

480 481 482 483 484 485
  float halfWidth = this->GetPen()->GetWidth() * 0.5f;
  float deltaX = halfWidth;
  float deltaY = halfWidth;

  this->TransformSize(deltaX, deltaY);

486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
  float quad[8];
  unsigned char color[4];
  for (int i = 0; i < n; ++i)
    {
    float *point = points + (i * 2);
    if  (colors)
      {
      color[3] = 255;
      switch (nc_comps)
        {
        case 4:
        case 3:
          memcpy(color, colors + (i * nc_comps), nc_comps);
          break;
        case 2:
          color[3] = colors[i * nc_comps + 1];
        case 1:
          memset(color, colors[i * nc_comps], 3);
          break;
        default:
          vtkErrorMacro(<<"Invalid number of color components: " << nc_comps);
          break;
        }

      this->Brush->SetColor(color);
      }

513 514 515
    quad[0] = point[0] - deltaX;
    quad[1] = point[1] - deltaY;
    quad[2] = point[0] + deltaX;
516 517
    quad[3] = quad[1];
    quad[4] = quad[2];
518
    quad[5] = point[1] + deltaY;
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
    quad[6] = quad[0];
    quad[7] = quad[5];

    this->DrawQuad(quad,4);
    }

  this->Brush->SetColor(oldColor);
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawCircleMarkers(bool /*highlight*/,
                                                float *points,
                                                int n, unsigned char *colors,
                                                int nc_comps)
{
  float radius = this->GetPen()->GetWidth() * 0.475;

  unsigned char oldColor[4];
  this->Brush->GetColor(oldColor);

  this->Brush->SetColor(this->Pen->GetColor());

  unsigned char color[4];
  for (int i = 0; i < n; ++i)
    {
    float *point = points + (i * 2);
    if  (colors)
      {
      color[3] = 255;
      switch (nc_comps)
        {
        case 4:
        case 3:
          memcpy(color, colors + (i * nc_comps), nc_comps);
          break;
        case 2:
          color[3] = colors[i * nc_comps + 1];
        case 1:
          memset(color, colors[i * nc_comps], 3);
          break;
        default:
          vtkErrorMacro(<<"Invalid number of color components: " << nc_comps);
          break;
        }

      this->Brush->SetColor(color);
      }

    this->DrawEllipseWedge(point[0], point[1], radius, radius, 0, 0,
                           0, 360);
    }

  this->Brush->SetColor(oldColor);
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawDiamondMarkers(bool /*highlight*/,
                                                 float *points,
                                                 int n, unsigned char *colors,
                                                 int nc_comps)
{
  unsigned char oldColor[4];
  this->Brush->GetColor(oldColor);

  this->Brush->SetColor(this->Pen->GetColor());

585 586 587 588 589 590
  float halfWidth = this->GetPen()->GetWidth() * 0.5f;
  float deltaX = halfWidth;
  float deltaY = halfWidth;

  this->TransformSize(deltaX, deltaY);

591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
  float quad[8];
  unsigned char color[4];
  for (int i = 0; i < n; ++i)
    {
    float *point = points + (i * 2);
    if  (colors)
      {
      color[3] = 255;
      switch (nc_comps)
        {
        case 4:
        case 3:
          memcpy(color, colors + (i * nc_comps), nc_comps);
          break;
        case 2:
          color[3] = colors[i * nc_comps + 1];
        case 1:
          memset(color, colors[i * nc_comps], 3);
          break;
        default:
          vtkErrorMacro(<<"Invalid number of color components: " << nc_comps);
          break;
        }

      this->Brush->SetColor(color);
      }

618
    quad[0] = point[0] - deltaX;
619 620
    quad[1] = point[1];
    quad[2] = point[0];
621 622
    quad[3] = point[1] - deltaY;
    quad[4] = point[0] + deltaX;
623 624
    quad[5] = point[1];
    quad[6] = point[0];
625
    quad[7] = point[1] + deltaY;
626 627 628 629 630 631 632

    this->DrawQuad(quad,4);
    }

  this->Brush->SetColor(oldColor);
}

633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::AddEllipseToPath(vtkPath *path, float x, float y,
                                               float rx, float ry, bool reverse)
{
  if (rx < 1e-5 || ry < 1e-5)
    {
    return;
    }

  // method based on http://www.tinaja.com/glib/ellipse4.pdf
  const static float MAGIC = (4.0/3.0) * (sqrt(2.0) - 1);

  if (!reverse)
    {
    path->InsertNextPoint(x - rx,      y,           0, vtkPath::MOVE_TO);
    path->InsertNextPoint(x - rx,      ry * MAGIC,  0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(-rx * MAGIC, y + ry,      0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x,           y + ry,      0, vtkPath::CUBIC_CURVE);

    path->InsertNextPoint(rx * MAGIC,  y + ry,      0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x + rx,      ry * MAGIC,  0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x + rx,      y,           0, vtkPath::CUBIC_CURVE);

    path->InsertNextPoint(x + rx,      -ry * MAGIC, 0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(rx * MAGIC,  y - ry,      0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x,           y - ry,      0, vtkPath::CUBIC_CURVE);

    path->InsertNextPoint(-rx * MAGIC, y - ry,      0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x - rx,      -ry * MAGIC, 0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x - rx,      y,           0, vtkPath::CUBIC_CURVE);
    }
  else
    {
    path->InsertNextPoint(x - rx,      y,           0, vtkPath::MOVE_TO);
    path->InsertNextPoint(x - rx,      -ry * MAGIC, 0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(-rx * MAGIC, y - ry,      0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x,           y - ry,      0, vtkPath::CUBIC_CURVE);

    path->InsertNextPoint(rx * MAGIC,  y - ry,      0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x + rx,      -ry * MAGIC, 0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x + rx,      y,           0, vtkPath::CUBIC_CURVE);

    path->InsertNextPoint(x + rx,      ry * MAGIC,  0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(rx * MAGIC,  y + ry,      0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x,           y + ry,      0, vtkPath::CUBIC_CURVE);

    path->InsertNextPoint(-rx * MAGIC, y + ry,      0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x - rx,      ry * MAGIC,  0, vtkPath::CUBIC_CURVE);
    path->InsertNextPoint(x - rx,      y,           0, vtkPath::CUBIC_CURVE);
    }
}

//-----------------------------------------------------------------------------
686
void vtkGL2PSContextDevice2D::TransformPath(vtkPath *path) const
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
{
  // Transform the path with the modelview matrix:
  float modelview[16];
  glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

  // Transform the 2D path.
  float newPoint[3] = {0, 0, 0};
  vtkPoints *points = path->GetPoints();
  for (vtkIdType i = 0; i < path->GetNumberOfPoints(); ++i)
    {
    double *point = points->GetPoint(i);
    newPoint[0] = modelview[0] * point[0] + modelview[4] * point[1]
        + modelview[12];
    newPoint[1] = modelview[1] * point[0] + modelview[5] * point[1]
        + modelview[13];
    points->SetPoint(i, newPoint);
    }
}

706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::TransformPoint(float &x, float &y) const
{
  float modelview[16];
  glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

  float inX = x;
  float inY = y;
  x = modelview[0] * inX + modelview[4] * inY + modelview[12];
  y = modelview[1] * inX + modelview[5] * inY + modelview[13];
}

//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::TransformSize(float &dx, float &dy) const
{
  float modelview[16];
  glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

  dx /= modelview[0];
  dy /= modelview[5];
}

728 729 730 731 732
//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::PrintSelf(ostream &os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}