Commit 50287af2 authored by Scott Wittenburg's avatar Scott Wittenburg Committed by Kitware Robot

Merge topic 'context2d-fix-pdf-export-issues'

3e2f51d5 Fix context2d pdf export image flip axis
533057e9 Replace DrawPolygon with equivalent DrawQuad
4b2036a4 Enable support for VTK_POLY_LINE in pdf backend device
1f535c69 Attempt to fix pen width by computing it in world coords
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Allison Vacanti's avatarAllison Vacanti <allison.vacanti@kitware.com>
Merge-request: !4738
parents 0ac2f1c8 3e2f51d5
baa21e41b8c62abcf33c1725bad0f21c4ca9534abedfcc004eed96393ebce80bb03b02053d51cdd136b56876254dcec6f27a608f6598143d85dd00f6b15dc93d
fcdf54076525a02b974c6eed8fdf8cd3a6dc4b1666da0a9bdc4ed6d2a5d3370083a223d73e449661cca5b5b27e7448dfed9ba991ab4f25526ba4c8dcf1bc8b94
......@@ -26,6 +26,7 @@
#include "vtkImageFlip.h"
#include "vtkIntArray.h"
#include "vtkMatrix3x3.h"
#include "vtkMatrix4x4.h"
#include "vtkObjectFactory.h"
#include "vtkPath.h"
#include "vtkPen.h"
......@@ -186,6 +187,58 @@ struct vtkPDFContextDevice2D::Details
HPDF_Page Page;
std::map<unsigned char, HPDF_ExtGState> AlphaGStateMap;
float computeWorldRadius(const float x1, const float y1,
const float x2, const float y2,
vtkMatrix4x4 *matrix, const float penWidth)
{
// Attempt to compute the radius in world space. For this computation
// we make the assumption that the following expression holds true:
//
// worldDiagonalLength worldRadius
// --------------------- = -------------
// screenDiagonalLength screenRadius
//
// Then we further assume that this->Matrix can take the points of our
// polydata bounding box and transform them into top-level pixel coords
// of our render window.
double transMat[9];
double *mat = matrix->GetData();
vtkPDFContextDevice2D::Matrix4ToMatrix3(mat, transMat);
const float boundPt1[3] = {
static_cast<float>(x1),
static_cast<float>(y1),
1.0f
};
const float boundPt2[3] = {
static_cast<float>(x2),
static_cast<float>(y2),
1.0f
};
float boundPt1Px[3];
float boundPt2Px[3];
vtkMatrix3x3::MultiplyPoint(transMat, boundPt1, boundPt1Px);
vtkMatrix3x3::MultiplyPoint(transMat, boundPt2, boundPt2Px);
// Compute the length of the bounding box diagonal in world space
const float wdx = boundPt1[0] - boundPt2[0];
const float wdy = boundPt1[1] - boundPt2[1];
const float worldDiag = std::sqrt(wdx * wdx + wdy * wdy);
// Do the same as above, but in screen space
const float sdx = boundPt1Px[0] - boundPt2Px[0];
const float sdy = boundPt1Px[1] - boundPt2Px[1];
const float screenDiag = std::sqrt(sdx * sdx + sdy * sdy);
// Pen width is twice the radius in screen space, so get that in world space
const float worldPenWidth = penWidth * (worldDiag / screenDiag);
return worldPenWidth * 0.5f;
}
};
//------------------------------------------------------------------------------
......@@ -1006,6 +1059,7 @@ void vtkPDFContextDevice2D::DrawPolyData(
vtkNew<vtkCellTypes> types;
polyData->GetCellTypes(types);
if (!types->IsType(VTK_LINE) &&
!types->IsType(VTK_POLY_LINE) &&
!types->IsType(VTK_TRIANGLE) &&
!types->IsType(VTK_QUAD) &&
!types->IsType(VTK_POLYGON))
......@@ -1016,8 +1070,12 @@ void vtkPDFContextDevice2D::DrawPolyData(
double bounds[6];
polyData->GetBounds(bounds);
float radius = this->Impl->computeWorldRadius(bounds[0], bounds[2],
bounds[1], bounds[3],
this->Matrix->GetMatrix(),
this->Pen->GetWidth());
// Adjust bounds for transform, account for pen width:
const float radius = this->Pen->GetWidth() * 0.5f;
bounds[0] = (bounds[0] + p[0]) * scale - radius;
bounds[1] = (bounds[1] + p[0]) * scale + radius;
bounds[2] = (bounds[2] + p[1]) * scale - radius;
......@@ -1044,6 +1102,7 @@ void vtkPDFContextDevice2D::DrawPolyData(
switch (cellType)
{
case VTK_LINE:
case VTK_POLY_LINE:
case VTK_TRIANGLE:
case VTK_QUAD:
case VTK_POLYGON:
......@@ -1085,7 +1144,7 @@ void vtkPDFContextDevice2D::DrawPolyData(
}
}
if (cellType == VTK_LINE)
if (cellType == VTK_LINE || cellType == VTK_POLY_LINE)
{
PolyLineToShading(verts.data(), numPoints, vertColors.data(), 4, radius,
shading);
......@@ -1535,7 +1594,7 @@ vtkImageData *vtkPDFContextDevice2D::PrepareImageData(vtkImageData *in)
vtkNew<vtkImageFlip> flip;
flip->SetInputData(in);
in->UnRegister(this);
flip->SetFilteredAxis(0); // x axis
flip->SetFilteredAxis(1); // y axis
flip->Update();
in = flip->GetOutput();
in->Register(this);
......
......@@ -790,7 +790,7 @@ bool vtkLabeledContourPolyDataItem::RenderBackgrounds(vtkContext2D* painter)
pen->SetOpacityF(bgopacity);
brush->SetColorF(bgcolor);
brush->SetOpacityF(bgopacity);
painter->DrawPolygon(this->LabelHelpers[i]->boxPoints, 5);
painter->DrawQuad(this->LabelHelpers[i]->boxPoints);
}
pen->SetColorF(prevPenColor);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment