-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to set opacity for PDF Special case
- Loading branch information
Showing
7 changed files
with
275 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
# Compile the PNGCompare test, which is used to validate PNG images (read from | ||
# disk, not generated in VTK). The CMake/RasterizePostScript script can be used | ||
# to create a png image from GL2PS output. | ||
set(tests PNGCompare) | ||
vtk_test_cxx_executable(${vtk-module}CxxTests tests | ||
RENDERING_FACTORY | ||
) | ||
## Compile the PNGCompare test, which is used to validate PNG images (read from | ||
## disk, not generated in VTK). The CMake/RasterizePostScript script can be used | ||
## to create a png image from GL2PS output. | ||
#set(tests PNGCompare TestGL2PSAddPolyPrimitive) | ||
#vtk_test_cxx_executable(${vtk-module}CxxTests tests | ||
# RENDERING_FACTORY | ||
# ) | ||
|
||
|
||
|
||
|
||
set(GL2PSTests | ||
TestGL2PSAddPolyPrimitive.cxx | ||
) | ||
|
||
vtk_add_test_cxx(${vtk-module}CxxTests tests NO_VALID ${GL2PSTests}) | ||
|
||
vtk_test_cxx_executable(${vtk-module}CxxTests tests RENDERING_FACTORY) |
193 changes: 193 additions & 0 deletions
193
Rendering/GL2PS/Testing/Cxx/TestGL2PSAddPolyPrimitive.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/*========================================================================= | ||
Program: Visualization Toolkit | ||
Module: TestGL2PSAddPolyPrimitive.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. | ||
=========================================================================*/ | ||
|
||
// This test checks that we can use GL2PS without an OpenGL context using | ||
// a buffer size of 0, gl2psAddPolyPrimitive, and gl2psForceRasterPos. | ||
|
||
#include "vtk_gl2ps.h" | ||
|
||
#include "vtkTestingInteractor.h" | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace { | ||
|
||
static inline void setVertex(GL2PSvertex &vert, | ||
float x, float y, float z, | ||
float r, float g, float b, float a) | ||
{ | ||
vert.xyz[0] = x; | ||
vert.xyz[1] = y; | ||
vert.xyz[2] = z; | ||
vert.rgba[0] = r; | ||
vert.rgba[1] = g; | ||
vert.rgba[2] = b; | ||
vert.rgba[3] = a; | ||
} | ||
|
||
static inline void generatePixelData(std::vector<float> &data, | ||
size_t width, size_t height) | ||
{ | ||
data.resize(width * height * 4); | ||
for (size_t h = 0; h < height; ++h) | ||
{ | ||
size_t rowOffset = h * width * 4; | ||
for (size_t w = 0; w < width; ++w) | ||
{ | ||
size_t pixel = rowOffset + (w * 4); | ||
data[pixel ] = h / static_cast<float>(height); | ||
data[pixel + 1] = 0.f; | ||
data[pixel + 2] = w / static_cast<float>(width); | ||
data[pixel + 3] = 1.f; | ||
} | ||
} | ||
} | ||
|
||
} // end anon namespace | ||
|
||
#include <vtkOpenGLGL2PSExporter.h> | ||
|
||
#include <vtkTextActor.h> | ||
#include <vtkRenderer.h> | ||
#include <vtkRenderWindow.h> | ||
#include <vtkTextActor.h> | ||
#include <vtkTextProperty.h> | ||
|
||
#include <vtkPropCollection.h> | ||
|
||
int TestGL2PSAddPolyPrimitive(int , char * []) | ||
{ | ||
vtkNew<vtkOpenGLGL2PSExporter> exporter; | ||
|
||
vtkNew<vtkTextActor> ta; | ||
ta->SetPosition(0, 0); | ||
ta->SetInput("Hello"); | ||
ta->GetTextProperty()->SetColor(0.0, 1.0, 0.0); | ||
ta->GetTextProperty()->SetOpacity(0.5); | ||
exporter->SetCompress(0); | ||
exporter->DrawBackgroundOff(); | ||
|
||
vtkNew<vtkRenderer> ren; | ||
vtkNew<vtkRenderWindow> renWin; | ||
|
||
ren->AddActor(ta.GetPointer()); | ||
renWin->AddRenderer(ren.GetPointer()); | ||
|
||
|
||
vtkPropCollection* ac = ren->GetViewProps(); | ||
ac->InitTraversal(); | ||
vtkProp* act = ac->GetNextProp(); | ||
vtkIndent ind; | ||
while(act) { | ||
act->PrintSelf(std::cout, ind); | ||
act = ac->GetNextProp(); | ||
} | ||
|
||
|
||
exporter->SetTextAsPath(1); | ||
exporter->SetInput(renWin.GetPointer()); | ||
exporter->SetFileFormatToPDF(); | ||
exporter->SetFilePrefix("bad"); | ||
exporter->Write(); | ||
|
||
|
||
|
||
|
||
|
||
// std::string filename = vtkTestingInteractor::TempDirectory + | ||
// std::string("/TestGL2PSAddPolyPrimitive.pdf"); | ||
// FILE *stream = fopen(filename.c_str(), "wb"); | ||
// if (stream == NULL) | ||
// { | ||
// std::cerr << "Error opening output file." << std::endl; | ||
// return EXIT_FAILURE; | ||
// } | ||
|
||
// GLint viewport[4] = { 0, 0, 400, 400 }; | ||
// GLint result = gl2psBeginPage("AddPolyPrimitive Test", "VTK", viewport, | ||
// GL2PS_PDF, GL2PS_SIMPLE_SORT, | ||
// GL2PS_NO_OPENGL_CONTEXT | GL2PS_NO_BLENDING, | ||
// GL_RGBA, 0, NULL, 0, 0, 0, 0, stream, 0); | ||
// if (result != GL2PS_SUCCESS) | ||
// { | ||
// std::cerr << "gl2psBeginPage failed." << std::endl; | ||
// return EXIT_FAILURE; | ||
// } | ||
|
||
// // AddPolyPrimitive arguments: | ||
// GL2PSvertex vertices[3]; // Vertices. | ||
// GLint offset = 0; // line offset | ||
// GLushort pattern = 0xffff; // glLineStipple pattern | ||
// GLint factor = 1; // glLineStipple repeat factor | ||
// GLfloat ofactor = 0.f; // glPolygonOffset factor | ||
// GLfloat ounits = 0.f; // glPolygonOffset units | ||
// GLfloat width = 1; // linewidth or pointsize | ||
// // Something to do with gl2psEnable(GL2PS_POLYGON_BOUNDARY), which is not | ||
// // implemented according to the docs. | ||
// char boundary = 0; | ||
|
||
// // Point: | ||
// setVertex(vertices[0], 200, 307.5, 0, 0.f, 0.f, 1.f, 1.f); | ||
// gl2psAddPolyPrimitive(GL2PS_POINT, 1, vertices, offset, ofactor, ounits, | ||
// pattern, factor, /*width=*/15, boundary); | ||
|
||
// // Line: | ||
// // Note that the first vertex's color is used for the entire line. | ||
// setVertex(vertices[0], 100, 50, 0, 1.f, 0.f, 0.f, 1.f); | ||
// setVertex(vertices[1], 300, 50, 0, 0.f, 0.f, 1.f, 1.f); | ||
// gl2psAddPolyPrimitive(GL2PS_LINE, 2, vertices, offset, ofactor, ounits, | ||
// pattern, factor, width, boundary); | ||
|
||
// // Triangle: | ||
// setVertex(vertices[0], 100, 100, 0, 1.f, 0.f, 0.f, 1.f); | ||
// setVertex(vertices[1], 300, 100, 0, 0.f, 1.f, 0.f, 1.f); | ||
// setVertex(vertices[2], 200, 300, 0, 0.f, 0.f, 1.f, 1.f); | ||
// gl2psAddPolyPrimitive(GL2PS_TRIANGLE, 3, vertices, offset, ofactor, ounits, | ||
// pattern, factor, width, boundary); | ||
|
||
// // Text: | ||
// setVertex(vertices[0], 200, 325, 0, 0.f, 0.f, 0.f, 1.f); | ||
// gl2psForceRasterPos(vertices); | ||
// float rgba[4] = {1.0, 0.0, 0.0, 1.0}; | ||
//// gl2psTextOptColor("1", "Helvetica", 12, GL2PS_TEXT_C, 0.f, rgba); | ||
//// gl2psTextOptColor("2", "Helvetica", 12, GL2PS_TEXT_CL, 0.f, rgba); | ||
//// gl2psTextOptColor("3", "Helvetica", 12, GL2PS_TEXT_CR, 0.f, rgba); | ||
//// gl2psTextOptColor("4", "Helvetica", 12, GL2PS_TEXT_B, 0.f, rgba); | ||
//// gl2psTextOptColor("5", "Helvetica", 12, GL2PS_TEXT_BL, 0.f, rgba); | ||
//// gl2psTextOptColor("6", "Helvetica", 12, GL2PS_TEXT_BR, 0.f, rgba); | ||
//// gl2psTextOptColor("7", "Helvetica", 12, GL2PS_TEXT_T, 0.f, rgba); | ||
//// gl2psTextOptColor("8", "Helvetica", 12, GL2PS_TEXT_TL, 0.f, rgba); | ||
//// gl2psTextOptColor("9", "Helvetica", 12, GL2PS_TEXT_TR, 0.f, rgba); | ||
|
||
// // DrawPixels: | ||
// std::vector<float> pixelData; | ||
// generatePixelData(pixelData, 100, 100); | ||
// setVertex(vertices[0], 275, 275, 0, 0.f, 0.f, 0.f, 0.f); | ||
// gl2psForceRasterPos(vertices); | ||
// gl2psDrawPixels(100, 100, 0, 0, GL_RGBA, GL_FLOAT, &pixelData[0]); | ||
|
||
// result = gl2psEndPage(); | ||
// if (result != GL2PS_SUCCESS) | ||
// { | ||
// std::cerr << "gl2psEndPage failed." << std::endl; | ||
// return EXIT_FAILURE; | ||
// } | ||
|
||
// fclose(stream); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.