Commit bcf03bc8 authored by David C. Lonie's avatar David C. Lonie

Insert comments into PS, EPS, and SVG exports for paths.

Place markers in the exported vector graphics files marking
where paths are. This makes it easier to track down what
path is being drawn.

Change-Id: Id8582cc2bcb33c2afca6db545f4048c3b8ad1ad0
parent 0b20a7ba
......@@ -30,6 +30,8 @@
#include "vtk_gl2ps.h"
#include <sstream>
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkGL2PSContextDevice2D)
......@@ -164,7 +166,14 @@ void vtkGL2PSContextDevice2D::DrawEllipseWedge(float x, float y,
unsigned char color[4];
this->Brush->GetColor(color);
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, color);
std::stringstream label;
label << "vtkGL2PSContextDevice2D::DrawEllipseWedge("
<< x << ", " << y << ", " << outRx << ", " << outRy << ", "
<< inRx << ", " << inRy << ", " << startAngle << ", " << stopAngle
<< ") path:";
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, color, NULL,
0.0, -1.f, label.str().c_str());
}
//-----------------------------------------------------------------------------
......@@ -194,14 +203,27 @@ void vtkGL2PSContextDevice2D::DrawEllipticArc(float x, float y,
// Fill
unsigned char fillColor[4];
this->Brush->GetColor(fillColor);
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, fillColor);
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());
// and stroke
unsigned char strokeColor[4];
this->Pen->GetColor(strokeColor);
float strokeWidth = this->Pen->GetWidth();
label.str("");
label.clear();
label << "vtkGL2PSContextDevice2D::DrawEllipticArc("
<< x << ", " << y << ", " << rx << ", " << ry << ", "
<< startAngle << ", " << stopAngle << ") stroke:";
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, strokeColor,
NULL, 0.0, strokeWidth);
NULL, 0.0, strokeWidth, label.str().c_str());
}
//-----------------------------------------------------------------------------
......@@ -220,6 +242,7 @@ void vtkGL2PSContextDevice2D::DrawString(float *point,
vtkGL2PSUtilities::DrawString(string.utf8_str(), this->TextProp, p);
}
//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::DrawMathTextString(float apoint[],
const vtkStdString &string)
{
......@@ -256,7 +279,8 @@ void vtkGL2PSContextDevice2D::DrawMathTextString(float apoint[],
this->TransformPath(path.GetPointer());
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, color, NULL,
rotateAngle);
rotateAngle, -1.f,
("Pathified string: " + string).c_str());
}
//-----------------------------------------------------------------------------
......
......@@ -94,7 +94,9 @@ void vtkGL2PSUtilities::DrawString(const char *str,
double devicePos[3] = {pos[0], pos[1], pos[2]};
vtkGL2PSUtilities::ProjectPoint(devicePos);
vtkGL2PSUtilities::DrawPath(path.GetPointer(), pos, devicePos, rgba);
vtkGL2PSUtilities::DrawPath(path.GetPointer(), pos, devicePos, rgba, NULL,
0.0, -1.f, (std::string("Pathified string: ")
+ str).c_str());
}
}
......@@ -236,35 +238,36 @@ int vtkGL2PSUtilities::TextPropertyToGL2PSAlignment(vtkTextProperty *tprop)
void vtkGL2PSUtilities::Draw3DPath(vtkPath *path, vtkMatrix4x4 *actorMatrix,
double rasterPos[3],
unsigned char actorColor[4])
unsigned char actorColor[4],
const char *label)
{
double translation[2] = {0.0, 0.0};
vtkNew<vtkPath> projPath;
projPath->DeepCopy(path);
vtkGL2PSUtilities::ProjectPoints(projPath->GetPoints(), actorMatrix);
vtkGL2PSUtilities::DrawPath(projPath.GetPointer(), rasterPos, translation,
actorColor);
actorColor, NULL, 0.0, -1.f, label);
}
void vtkGL2PSUtilities::DrawPath(vtkPath *path, double rasterPos[3],
double windowPos[2], unsigned char rgba[4],
double scale[2], double rotateAngle,
float strokeWidth)
float strokeWidth, const char *label)
{
switch (gl2psGetFileFormat())
{
case GL2PS_PS:
case GL2PS_EPS:
vtkGL2PSUtilities::DrawPathPS(path, rasterPos, windowPos, rgba, scale,
rotateAngle, strokeWidth);
rotateAngle, strokeWidth, label);
break;
case GL2PS_SVG:
vtkGL2PSUtilities::DrawPathSVG(path, rasterPos, windowPos, rgba, scale,
rotateAngle, strokeWidth);
rotateAngle, strokeWidth, label);
break;
case GL2PS_PDF:
vtkGL2PSUtilities::DrawPathPDF(path, rasterPos, windowPos, rgba, scale,
rotateAngle, strokeWidth);
rotateAngle, strokeWidth, label);
break;
default:
break;
......@@ -302,7 +305,7 @@ void vtkGL2PSUtilities::FinishExport()
void vtkGL2PSUtilities::DrawPathPS(vtkPath *path, double rasterPos[3],
double windowPos[2], unsigned char rgba[4],
double scale[2], double rotateAngle,
float strokeWidth)
float strokeWidth, const char *label)
{
vtkFloatArray *points =
vtkFloatArray::SafeDownCast(path->GetPoints()->GetData());
......@@ -334,6 +337,10 @@ void vtkGL2PSUtilities::DrawPathPS(vtkPath *path, double rasterPos[3],
int *codeBegin = code;
#endif
int *codeEnd = code + codes->GetNumberOfTuples();
if (label != NULL && label[0] != '\0')
{
out << "% " << label << endl;
}
out << "gsave" << endl;
out << "initmatrix" << endl;
out << windowPos[0] << " " << windowPos[1] << " translate" << endl;
......@@ -435,7 +442,8 @@ void vtkGL2PSUtilities::DrawPathPS(vtkPath *path, double rasterPos[3],
void vtkGL2PSUtilities::DrawPathPDF(vtkPath *path, double rasterPos[3],
double windowPos[2], unsigned char rgba[4],
double scale[2], double rotateAngle,
float strokeWidth)
float strokeWidth,
const char *)
{
vtkFloatArray *points =
vtkFloatArray::SafeDownCast(path->GetPoints()->GetData());
......@@ -583,7 +591,7 @@ void vtkGL2PSUtilities::DrawPathPDF(vtkPath *path, double rasterPos[3],
void vtkGL2PSUtilities::DrawPathSVG(vtkPath *path, double rasterPos[3],
double windowPos[2], unsigned char rgba[4],
double scale[2], double rotateAngle,
float strokeWidth)
float strokeWidth, const char *label)
{
vtkFloatArray *points =
vtkFloatArray::SafeDownCast(path->GetPoints()->GetData());
......@@ -625,6 +633,12 @@ void vtkGL2PSUtilities::DrawPathSVG(vtkPath *path, double rasterPos[3],
float *ptBegin = pt;
int *codeBegin = code;
#endif
if (label != NULL && label[0] != '\0')
{
out << "<!-- " << label << " -->" << endl;
}
int *codeEnd = code + codes->GetNumberOfTuples();
out << "<g transform=\"" << endl
<< " translate(" << windowPos[0] << " "
......
......@@ -63,9 +63,11 @@ public:
// Description:
// Transform the path using the actor's matrix and current GL state, then
// draw it to GL2PS.
// draw it to GL2PS. The label string is inserted into the GL2PS output at the
// beginning of the path specification as a comment on supported backends.
static void Draw3DPath(vtkPath *path, vtkMatrix4x4 *actorMatrix,
double rasterPos[3], unsigned char actorColor[4]);
double rasterPos[3], unsigned char actorColor[4],
const char *label = NULL);
// Description:
// Generate PS, EPS, or SVG markup from a vtkPath object, and then inject it
// into the output using the gl2psSpecial command. The path is translated
......@@ -74,9 +76,12 @@ public:
// and determines clipping and depth. If scale is NULL, no scaling is done.
// If strokeWidth is positive, the path will be stroked with the indicated
// width. If zero or negative, the path will be filled (default).
// The label string is inserted into the GL2PS output at the beginning of the
// path specification as a comment on supported backends.
static void DrawPath(vtkPath *path, double rasterPos[3], double windowPos[2],
unsigned char rgba[4], double scale[2] = NULL,
double rotateAngle = 0.0, float strokeWidth = -1);
double rotateAngle = 0.0, float strokeWidth = -1,
const char *label = NULL);
// Description:
// Get whether all text will be exported as paths.
......@@ -118,15 +123,15 @@ protected:
static void DrawPathPS(vtkPath *path, double rasterPos[3],
double windowPos[2], unsigned char rgba[4],
double scale[2] = NULL, double rotateAngle = 0.0,
float strokeWidth = -1);
float strokeWidth = -1, const char *label = NULL);
static void DrawPathPDF(vtkPath *path, double rasterPos[3],
double windowPos[2], unsigned char rgba[4],
double scale[2] = NULL, double rotateAngle = 0.0,
float strokeWidth = -1);
float strokeWidth = -1, const char *label = NULL);
static void DrawPathSVG(vtkPath *path, double rasterPos[3],
double windowPos[2], unsigned char rgba[4],
double scale[2] = NULL, double rotateAngle = 0.0,
float strokeWidth = -1);
float strokeWidth = -1, const char *label = NULL);
vtkGL2PSUtilities() {}
~vtkGL2PSUtilities() {}
......
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