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

Cleanup the GL2PS export private API.

* Make the render window accessible from within GL2PSUtilities during
  export.
* Move Draw3DPath from GL2PSExporter to GL2PSUtilities.
* Minor changes to private API function arguments.
* Generalize code for projecting points from world coordinates to GL2PS
  device space.

Change-Id: I358b5e0bfeb7bedee5565a0855dcbba913ecc558
parent 4dbafed0
......@@ -140,6 +140,9 @@ void vtkGL2PSExporter::WriteData()
return;
}
// Setup the helper class.
vtkGL2PSUtilities::SetRenderWindow(this->RenderWindow);
// Store the "properly" rendered image's pixel data for special actors that
// need to copy bitmaps into the output (e.g. paraview's scalar bar actor)
this->PixelDataSize[0] = viewport[2];
......@@ -241,6 +244,7 @@ void vtkGL2PSExporter::WriteData()
fclose(fpObj);
// Clean up:
vtkGL2PSUtilities::SetRenderWindow(NULL);
// Re-enable depth peeling if needed
for (int i = 0; i < static_cast<int>(origDepthPeeling.size()); ++i)
{
......@@ -707,12 +711,18 @@ void vtkGL2PSExporter::DrawTextActor3D(vtkTextActor3D *textAct,
// Get actor info
vtkMatrix4x4 *actorMatrix = textAct->GetMatrix();
double *actorBounds = textAct->GetBounds();
double rasterPos[3] = {(actorBounds[1] + actorBounds[0]) * 0.5,
(actorBounds[3] + actorBounds[2]) * 0.5,
(actorBounds[5] + actorBounds[4]) * 0.5};
double *dcolor = tprop->GetColor();
unsigned char actorColor[3] = {static_cast<unsigned char>(dcolor[0]*255),
static_cast<unsigned char>(dcolor[1]*255),
static_cast<unsigned char>(dcolor[2]*255)};
this->Draw3DPath(path.GetPointer(), actorMatrix, actorBounds, actorColor);
unsigned char actorColor[4] = {
static_cast<unsigned char>(dcolor[0]*255),
static_cast<unsigned char>(dcolor[1]*255),
static_cast<unsigned char>(dcolor[2]*255),
static_cast<unsigned char>(tprop->GetOpacity()*255)};
vtkGL2PSUtilities::Draw3DPath(path.GetPointer(), actorMatrix, rasterPos,
actorColor);
}
void vtkGL2PSExporter::DrawTextMapper(vtkTextMapper *textMap,
......@@ -732,19 +742,17 @@ void vtkGL2PSExporter::DrawMathTextActor(vtkMathTextActor *textAct,
const char *string = textAct->GetInput();
vtkCoordinate *coord = textAct->GetActualPositionCoordinate();
vtkTextProperty *tprop = textAct->GetScaledTextProperty();
int *winsize = this->RenderWindow->GetSize();
vtkNew<vtkPath> path;
double scale[2] = {1.0,1.0};
vtkMathTextUtilities::GetInstance()->StringToPath(string,
path.GetPointer(),
tprop);
double *dcolor = tprop->GetColor();
unsigned char color[3] = {static_cast<unsigned char>(dcolor[0]*255),
unsigned char color[4] = {static_cast<unsigned char>(dcolor[0]*255),
static_cast<unsigned char>(dcolor[1]*255),
static_cast<unsigned char>(dcolor[2]*255)};
double winsized[2] = {static_cast<double>(winsize[0]),
static_cast<double>(winsize[1])};
static_cast<unsigned char>(dcolor[2]*255),
static_cast<unsigned char>(tprop->GetOpacity()*255)
};
// Set the raster position at the center of the front plane. This is an
// overlay annotation, it shouldn't need to be clipped.
......@@ -758,9 +766,8 @@ void vtkGL2PSExporter::DrawMathTextActor(vtkMathTextActor *textAct,
int *textPos = coord->GetComputedDisplayValue(ren);
double textPosd[2] = {static_cast<double>(textPos[0]),
static_cast<double>(textPos[1])};
vtkGL2PSUtilities::DrawPath(path.GetPointer(), rasterPos, winsized,
textPosd, scale, tprop->GetOrientation(),
color);
vtkGL2PSUtilities::DrawPath(path.GetPointer(), rasterPos, textPosd, color,
NULL, tprop->GetOrientation());
}
void vtkGL2PSExporter::DrawMathTextActor3D(vtkMathTextActor3D *textAct,
......@@ -782,12 +789,18 @@ void vtkGL2PSExporter::DrawMathTextActor3D(vtkMathTextActor3D *textAct,
// Get actor info
vtkMatrix4x4 *actorMatrix = textAct->GetMatrix();
double *actorBounds = textAct->GetBounds();
double rasterPos[3] = {(actorBounds[1] + actorBounds[0]) * 0.5,
(actorBounds[3] + actorBounds[2]) * 0.5,
(actorBounds[5] + actorBounds[4]) * 0.5};
double *dcolor = tprop->GetColor();
unsigned char actorColor[3] = {static_cast<unsigned char>(dcolor[0]*255),
static_cast<unsigned char>(dcolor[1]*255),
static_cast<unsigned char>(dcolor[2]*255)};
this->Draw3DPath(path.GetPointer(), actorMatrix, actorBounds, actorColor);
unsigned char actorColor[4] = {
static_cast<unsigned char>(dcolor[0]*255),
static_cast<unsigned char>(dcolor[1]*255),
static_cast<unsigned char>(dcolor[2]*255),
static_cast<unsigned char>(tprop->GetOpacity()*255)};
vtkGL2PSUtilities::Draw3DPath(path.GetPointer(), actorMatrix, rasterPos,
actorColor);
}
void vtkGL2PSExporter::DrawViewportTextOverlay(const char *string,
......@@ -832,77 +845,6 @@ void vtkGL2PSExporter::DrawViewportTextOverlay(const char *string,
glPopMatrix();
}
void vtkGL2PSExporter::Draw3DPath(vtkPath *path, vtkMatrix4x4 *actorMatrix,
double actorBounds[4],
unsigned char actorColor[3])
{
double scale[2] = {1.0, 1.0};
double translation[2] = {0.0, 0.0};
double rasterPos[3] = {(actorBounds[1] + actorBounds[0]) * 0.5,
(actorBounds[3] + actorBounds[2]) * 0.5,
(actorBounds[5] + actorBounds[4]) * 0.5};
int *winsize = this->RenderWindow->GetSize();
double winsized[2] = {static_cast<double>(winsize[0]),
static_cast<double>(winsize[1])};
// Build transformation matrix
double glMatrix[16];
glGetDoublev(GL_PROJECTION_MATRIX, glMatrix);
vtkNew<vtkMatrix4x4> projectionMatrix;
projectionMatrix->DeepCopy(glMatrix);
projectionMatrix->Transpose();
glGetDoublev(GL_MODELVIEW_MATRIX, glMatrix);
vtkNew<vtkMatrix4x4> modelviewMatrix;
modelviewMatrix->DeepCopy(glMatrix);
modelviewMatrix->Transpose();
vtkNew<vtkMatrix4x4> transformMatrix;
vtkMatrix4x4::Multiply4x4(projectionMatrix.GetPointer(),
modelviewMatrix.GetPointer(),
transformMatrix.GetPointer());
vtkMatrix4x4::Multiply4x4(transformMatrix.GetPointer(),
actorMatrix,
transformMatrix.GetPointer());
double viewport[4];
glGetDoublev(GL_VIEWPORT, viewport);
double depthRange[2];
glGetDoublev(GL_DEPTH_RANGE, depthRange);
const double halfWidth = viewport[2] * 0.5;
const double halfHeight = viewport[3] * 0.5;
const double zFactor1 = (depthRange[1] - depthRange[0]) * 0.5;
const double zFactor2 = (depthRange[1] + depthRange[0]) * 0.5;
vtkSmartPointer<vtkPoints> origPoints = path->GetPoints();
vtkNew<vtkPoints> newPoints;
newPoints->DeepCopy(origPoints);
double point[4];
for (vtkIdType i = 0; i < path->GetNumberOfPoints(); ++i)
{
newPoints->GetPoint(i, point);
point[3] = 1.0;
// Convert world to clip coordinates:
// <out point> = [projection] [modelview] [actor matrix] <in point>
transformMatrix->MultiplyPoint(point, point);
// Clip to NDC
const double invW = 1.0 / point[3];
point[0] *= invW;
point[1] *= invW;
point[2] *= invW;
// NDC to device:
point[0] = point[0] * halfWidth + viewport[0] + halfWidth;
point[1] = point[1] * halfHeight + viewport[1] + halfHeight;
point[2] = point[2] * zFactor1 + zFactor2;
newPoints->SetPoint(i, point);
}
path->SetPoints(newPoints.GetPointer());
vtkGL2PSUtilities::DrawPath(path, rasterPos, winsized, translation, scale,
0.0, actorColor);
}
void vtkGL2PSExporter::CopyPixels(int copyRect[4], vtkRenderer *ren)
{
......
......@@ -304,11 +304,7 @@ protected:
vtkRenderer *ren);
void DrawViewportTextOverlay(const char *string, vtkTextProperty *tprop,
vtkCoordinate *coord, vtkRenderer *ren);
// Description:
// Transform the path using the actor's matrix and current GL state, then
// draw it to GL2PS.
void Draw3DPath(vtkPath *path, vtkMatrix4x4 *actorMatrix,
double actorBounds[4], unsigned char actorColor[3]);
// Description:
// Copy the region copyRect from the framebuffer into the gl2ps document.
// copyRect is in viewport coordinates [xmin, ymin, width, height].
......
......@@ -161,17 +161,10 @@ void vtkGL2PSContextDevice2D::DrawEllipseWedge(float x, float y,
this->TransformPath(path.GetPointer());
double origin[3] = {x, y, 0.f};
double scale[2] = {1.0, 1.0};
int *renWinSize = this->RenderWindow->GetSize();
double windowSize[2];
windowSize[0] = static_cast<double>(renWinSize[0]);
windowSize[1] = static_cast<double>(renWinSize[1]);
unsigned char color[4];
this->Brush->GetColor(color);
unsigned char alpha = this->Brush->GetColorObject().GetAlpha();
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, windowSize, origin,
scale, 0, color, alpha);
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, color);
}
//-----------------------------------------------------------------------------
......@@ -197,26 +190,18 @@ void vtkGL2PSContextDevice2D::DrawEllipticArc(float x, float y,
this->TransformPath(path.GetPointer());
double origin[3] = {x, y, 0.f};
double scale[2] = {1.0, 1.0};
int *renWinSize = this->RenderWindow->GetSize();
double windowSize[2];
windowSize[0] = static_cast<double>(renWinSize[0]);
windowSize[1] = static_cast<double>(renWinSize[1]);
// Fill
unsigned char fillColor[4];
this->Brush->GetColor(fillColor);
unsigned char fillAlpha = this->Brush->GetColorObject().GetAlpha();
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, fillColor);
// and stroke
unsigned char strokeColor[4];
this->Pen->GetColor(strokeColor);
unsigned char strokeAlpha = this->Pen->GetColorObject().GetAlpha();
float strokeWidth = this->Pen->GetWidth();
// Fill
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, windowSize, origin,
scale, 0, fillColor, fillAlpha);
// and stroke
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, windowSize, origin,
scale, 0, strokeColor, strokeAlpha,
strokeWidth);
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, strokeColor,
NULL, 0.0, strokeWidth);
}
//-----------------------------------------------------------------------------
......@@ -259,23 +244,19 @@ void vtkGL2PSContextDevice2D::DrawMathTextString(float apoint[],
}
double origin[3] = {apoint[0], apoint[1], 0.f};
double scale[2] = {1.0, 1.0};
double rotateAngle = this->TextProp->GetOrientation();
int *renWinSize = this->RenderWindow->GetSize();
double windowSize[2];
windowSize[0] = static_cast<double>(renWinSize[0]);
windowSize[1] = static_cast<double>(renWinSize[1]);
double dcolor[3];
this->TextProp->GetColor(dcolor);
unsigned char color[3];
unsigned char color[4];
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);
color[3] = static_cast<unsigned char>(this->TextProp->GetOpacity()*255);
this->TransformPath(path.GetPointer());
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, windowSize, origin,
scale, rotateAngle, color);
vtkGL2PSUtilities::DrawPath(path.GetPointer(), origin, origin, color, NULL,
rotateAngle);
}
//-----------------------------------------------------------------------------
......
This diff is collapsed.
......@@ -25,7 +25,10 @@
#include "vtkRenderingGL2PSModule.h" // For export macro
class vtkImageData;
class vtkMatrix4x4;
class vtkPath;
class vtkPoints;
class vtkRenderWindow;
class vtkTextProperty;
class VTKRENDERINGGL2PS_EXPORT vtkGL2PSUtilities : public vtkObject
......@@ -51,37 +54,47 @@ public:
// Convert the alignment hint in tprop to a GL2PS text alignment constant.
static int TextPropertyToGL2PSAlignment(vtkTextProperty *tprop);
// Description:
// Set/Get the current RenderWindow that is being exported
static void SetRenderWindow(vtkRenderWindow *renWin)
{
vtkGL2PSUtilities::RenderWindow = renWin;
}
static vtkRenderWindow *GetRenderWindow()
{
return vtkGL2PSUtilities::RenderWindow;
}
// Description:
// Transform the path using the actor's matrix and current GL state, then
// draw it to GL2PS.
static void Draw3DPath(vtkPath *path, vtkMatrix4x4 *actorMatrix,
double rasterPos[3], unsigned char actorColor[4]);
// 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
// uniformly by translation. It is scaled by scale and rotated
// counter-clockwise by rotateAngle. The windowSize is used to ensure correct
// text placement in SVG output and ignored for PS/EPS. The rasterPos
// is in world coordinates and determines clipping and depth.
// uniformly in the scene by windowPos. It is scaled by scale and rotated
// counter-clockwise by rotateAngle. The rasterPos is in world coordinates
// 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).
static void DrawPath(vtkPath *path, double rasterPos[3],
double windowSize[2], double translation[2],
double scale[2], double rotateAngle,
unsigned char color[3], unsigned char alpha = 255,
float strokeWidth = -1);
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);
protected:
static void DrawPathPS(vtkPath *path, double rasterPos[3],
double windowSize[2], double translation[2],
double scale[2], double rotateAngle,
unsigned char color[3], unsigned char alpha,
float strokeWidth);
double windowPos[2], unsigned char rgba[4],
double scale[2] = NULL, double rotateAngle = 0.0,
float strokeWidth = -1);
static void DrawPathPDF(vtkPath *path, double rasterPos[3],
double windowSize[2], double translation[2],
double scale[2], double rotateAngle,
unsigned char color[3], unsigned char alpha,
float strokeWidth);
double windowPos[2], unsigned char rgba[4],
double scale[2] = NULL, double rotateAngle = 0.0,
float strokeWidth = -1);
static void DrawPathSVG(vtkPath *path, double rasterPos[3],
double windowSize[2], double translation[2],
double scale[2], double rotateAngle,
unsigned char color[3], unsigned char alpha,
float strokeWidth);
double windowPos[2], unsigned char rgba[4],
double scale[2] = NULL, double rotateAngle = 0.0,
float strokeWidth = -1);
vtkGL2PSUtilities() {}
~vtkGL2PSUtilities() {}
......@@ -89,6 +102,16 @@ protected:
private:
vtkGL2PSUtilities(const vtkGL2PSUtilities &); // Not implemented
void operator=(const vtkGL2PSUtilities&); // Not implemented
static vtkRenderWindow *RenderWindow;
// Description:
// Project the point from world coordinates into device coordinates.
static void ProjectPoint(double point[3], vtkMatrix4x4 *actorMatrix = NULL);
static void ProjectPoint(double point[4], vtkMatrix4x4 * transformMatrix,
double viewportOrigin[2], double halfWidth,
double halfHeight, double zfact1, double zfact2);
static void ProjectPoints(vtkPoints *points,
vtkMatrix4x4 *actorMatrix = NULL);
};
#endif
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