Commit ea116f03 authored by David Lonie's avatar David Lonie Committed by Kitware Robot

Merge topic 'opengl2-gl2ps'

0811fa84 Update GL2PS baselines from dashboards.
03bd7b04 Stablize qsort call in GL2PS.
57427a4d Add GL2PS_NO_OPENGL_CONTEXT option to gl2ps.
7ba05666 Update GL2PS to latest SVN.
9ec31e00 Clean-up debugging output.
9fc9ee27 Enable linestippling for GL2PS on OpenGL2 Context2D.
d377c067 Move non-raster GL2PS tests to OpenGL backend only.
593c47c5 Add test for GL2PS scalar bar export.
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1075
parents 7c5d91dd 0811fa84
Pipeline #5195 running with stage
......@@ -37,22 +37,48 @@ endif()
# Remove any old output (in case conversion fails)
file(REMOVE "${PNGFILE}")
# Get the bounding box
execute_process(COMMAND "${GS_EXECUTABLE}" -sSAFER -sBATCH -sNOPAUSE -sDEVICE=bbox "${PSFILE}"
RESULT_VARIABLE EXITCODE ERROR_VARIABLE BBOXOUT)
# Get the bounding box from the file metadata (always added by GL2PS)
file(READ "${PSFILE}" BBOXOUT)
if(NOT ${EXITCODE} EQUAL 0)
message(FATAL_ERROR "GhostScript exited with status ${EXITCODE}:\n${BBOXOUT}")
if (NOT BBOXOUT)
message(FATAL_ERROR "The input file is empty: ${PSFILE}")
endif()
string(REGEX MATCH "%%BoundingBox:[ ]+[0-9-]+[ ]+[0-9-]+[ ]+[0-9]+[ ]+[0-9]+"
BBOX ${BBOXOUT})
BBOX "${BBOXOUT}")
# If the metadata isn't provided, ask ghostscript to find out.
# Beware, GhostScript computes a tight bbox and treats white pixels as
# transparent, so the gs bbox is dependent on the contents of the image.
if(NOT BBOX)
message("No '%%BoundingBox <x> <y> <w> <h>' header found. Asking ghostscript...")
execute_process(COMMAND
"${GS_EXECUTABLE}" -sSAFER -sBATCH -sNOPAUSE -sDEVICE=bbox "${PSFILE}"
RESULT_VARIABLE EXITCODE
ERROR_VARIABLE BBOXOUT
)
if(NOT ${EXITCODE} EQUAL 0)
message(FATAL_ERROR "GhostScript exited with status ${EXITCODE}:\n${BBOXOUT}")
endif()
string(REGEX MATCH "%%BoundingBox:[ ]+[0-9-]+[ ]+[0-9-]+[ ]+[0-9]+[ ]+[0-9]+"
BBOX "${BBOXOUT}")
if(NOT BBOX)
message("Ghostscript couldn't figure it out either :(\nOutput:\n${BBOXOUT}")
endif()
endif()
string(REGEX REPLACE
"^%%BoundingBox:[ ]+[0-9-]+[ ]+[0-9-]+[ ]+([0-9]+)[ ]+([0-9]+)"
"\\1x\\2" BBOX ${BBOX})
"\\1x\\2" BBOX "${BBOX}")
execute_process(COMMAND "${GS_EXECUTABLE}" -sSAFER -sBATCH -sNOPAUSE -sDEVICE=png16m "-sOutputFile=${PNGFILE}" -g${BBOX} "${PSFILE}"
execute_process(
COMMAND "${GS_EXECUTABLE}"
-sSAFER -sBATCH -sNOPAUSE -sDEVICE=png16m "-sOutputFile=${PNGFILE}"
"-g${BBOX}" "${PSFILE}"
RESULT_VARIABLE EXITCODE OUTPUT_VARIABLE ERRORSTR)
if(NOT ${EXITCODE} EQUAL 0)
......
......@@ -59,4 +59,5 @@ if (VTK_RENDERING_BACKEND STREQUAL "None")
vtk_module(vtkRenderingNone )
vtk_module(vtkRenderingContextNone )
vtk_module(vtkRenderingVolumeNone )
vtk_module(vtkIOExportNone ) # GL2PSExporter differs on OGL backends
endif()
# vtk_add_gl2ps_test_cxx(<test> [<another test> <yet another test> ...])
#
# Takes a list of test source files as arguments and adds additional tests
# to convert a postscript output into png (RasterizePNG) and validates against a
# baseline (VerifyRasterizedPNG).
#
# This function does not replace vtk_add_test_cxx, but supplements it -- this
# only creates the rasterize/verify tests, vtk_add_test_cxx is needed to create
# the test that generates the original postscript.
function(vtk_add_gl2ps_test_cxx)
foreach(test ${ARGN})
string(REGEX REPLACE ",.*" "" testsrc "${test}")
get_filename_component(TName ${testsrc} NAME_WE)
# Convert ps to png
add_test(NAME ${vtk-module}Cxx-${TName}-RasterizePNG
COMMAND ${CMAKE_COMMAND}
"-DPSFILE=${VTK_TEST_OUTPUT_DIR}/${TName}.ps"
"-DPNGFILE=${VTK_TEST_OUTPUT_DIR}/${TName}-raster.png"
"-DGS_EXECUTABLE=${VTK_GHOSTSCRIPT_EXECUTABLE}"
-DREMOVEPS=1
-P "${VTK_CMAKE_DIR}/RasterizePostScript.cmake"
)
set_tests_properties("${vtk-module}Cxx-${TName}-RasterizePNG"
PROPERTIES
DEPENDS "${vtk-module}Cxx-${TName}"
REQUIRED_FILES
"${VTK_TEST_OUTPUT_DIR}/${TName}.ps"
LABELS "${${vtk-module}_TEST_LABELS}"
)
get_filename_component(TName ${test} NAME_WE)
if(${${TName}Error})
set(_error_threshold ${${TName}Error})
else()
set(_error_threshold 15)
endif()
# Unit test executable containing PNGCompare test:
if(VTK_RENDERING_BACKEND STREQUAL "OpenGL")
set(PNGCompareTest vtkRenderingGL2PSCxxTests)
elseif(VTK_RENDERING_BACKEND STREQUAL "OpenGL2")
set(PNGCompareTest vtkRenderingGL2PSOpenGL2CxxTests)
endif()
# Image diff rasterized png with baseline
ExternalData_add_test(VTKData
NAME ${vtk-module}Cxx-${TName}-VerifyRasterizedPNG
COMMAND "${PNGCompareTest}" PNGCompare
-D "${VTK_TEST_DATA_DIR}"
-T "${VTK_TEST_OUTPUT_DIR}"
-E "${_error_threshold}"
-V "DATA{../Data/Baseline/${TName}-rasterRef.png,:}"
--test-file "${VTK_TEST_OUTPUT_DIR}/${TName}-raster.png"
)
set_tests_properties("${vtk-module}Cxx-${TName}-VerifyRasterizedPNG"
PROPERTIES
DEPENDS "${vtk-module}Cxx-${TName}-RasterizePNG"
REQUIRED_FILES
"${VTK_TEST_OUTPUT_DIR}/${TName}-raster.png"
LABELS "${${vtk-module}_TEST_LABELS}"
)
endforeach()
endfunction()
......@@ -46,7 +46,8 @@ static vtkCleanUpObjectFactory vtkCleanUpObjectFactoryGlobal;
// Create an instance of a named vtk object using the loaded
// factories
vtkObject* vtkObjectFactory::CreateInstance(const char* vtkclassname)
vtkObject* vtkObjectFactory::CreateInstance(const char* vtkclassname,
bool isAbstract)
{
if(!vtkObjectFactory::RegisteredFactories)
{
......@@ -68,9 +69,12 @@ vtkObject* vtkObjectFactory::CreateInstance(const char* vtkclassname)
// if the factory does not create the object, then
// the object will be created with the name passed in,
// so register the construction
if (!isAbstract)
{
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::ConstructClass(vtkclassname);
vtkDebugLeaks::ConstructClass(vtkclassname);
#endif
}
return 0;
}
......
......@@ -52,7 +52,11 @@ public:
// Each loaded vtkObjectFactory will be asked in the order
// the factory was in the VTK_AUTOLOAD_PATH. After the
// first factory returns the object no other factories are asked.
static vtkObject* CreateInstance(const char* vtkclassname);
// If the requested class is abstract, set isAbstract to true. Otherwise
// it is assumed that an instance of 'vtkclassname' will be instantiated
// by the caller when no override is found.
static vtkObject* CreateInstance(const char* vtkclassname,
bool isAbstract = false);
// Description:
// Call vtkDebugLeaks::ConstructClass if necessary. Does not attempt
......@@ -284,7 +288,7 @@ vtkObjectFactory* vtkLoad() \
// Macro to implement the body of the object factory form of the New() method.
#define VTK_OBJECT_FACTORY_NEW_BODY(thisClass) \
vtkObject* ret = vtkObjectFactory::CreateInstance(#thisClass); \
vtkObject* ret = vtkObjectFactory::CreateInstance(#thisClass, false); \
if(ret) \
{ \
return static_cast<thisClass*>(ret); \
......@@ -295,7 +299,7 @@ vtkObjectFactory* vtkLoad() \
// method, i.e. an abstract base class that can only be instantiated if the
// object factory overrides it.
#define VTK_ABSTRACT_OBJECT_FACTORY_NEW_BODY(thisClass) \
vtkObject* ret = vtkObjectFactory::CreateInstance(#thisClass); \
vtkObject* ret = vtkObjectFactory::CreateInstance(#thisClass, true); \
if(ret) \
{ \
return static_cast<thisClass*>(ret); \
......
set(Module_SRCS
vtkExporter.cxx
vtkGL2PSExporter.cxx
vtkIVExporter.cxx
vtkOBJExporter.cxx
vtkOOGLExporter.cxx
......@@ -16,12 +17,6 @@ set(Module_SRCS
vtkX3DExporterXMLWriter.cxx
)
if(VTK_RENDERING_BACKEND STREQUAL "OpenGL")
list (APPEND Module_SRCS
vtkGL2PSExporter.cxx
)
endif()
set_source_files_properties(
vtkX3D
vtkX3DExporterWriter
......
include(vtkGhostscript)
# Only run GL2PS tests if GhostScript is available
if(VTK_GHOSTSCRIPT_EXECUTABLE AND (VTK_RENDERING_BACKEND STREQUAL "OpenGL"))
if(VTK_GHOSTSCRIPT_EXECUTABLE)
set(GL2PSTests
TestContextGL2PS.cxx
TestGL2PSExporterMultipleRenderers.cxx
TestGL2PSExporterRaster.cxx
TestGL2PSExporterRasterExclusion.cxx
TestGL2PSExporterVector.cxx
TestGL2PSExporterVolumeRaster.cxx
TestGL2PSScalarBar.cxx
TestGL2PSTextActor.cxx
TestGL2PSTextActor3D.cxx
TestGL2PSTextMapper.cxx
TestGL2PSLabeledDataMapper.cxx
TestLinePlotGL2PS.cxx
TestStackedPlotGL2PS.cxx
)
)
endif()
vtk_add_test_cxx(${vtk-module}CxxTests tests
......@@ -75,55 +74,7 @@ if(RMANTREE)
)
endif()
# The GL2PS tests produce postscript output, which cannot be compared using
# the built-in image regression framework. The tests added above will create the
# postscript, while the following tests will convert the postscript to a PNG and
# run the PNGCompare test target to do an image diff on the output against a
# baseline.
if(GL2PSTests)
set(TestGL2PSExporterVolumeRasterError 50)
foreach(test ${GL2PSTests})
string(REGEX REPLACE ",.*" "" testsrc "${test}")
get_filename_component(TName ${testsrc} NAME_WE)
add_test(NAME ${vtk-module}Cxx-${TName}-RasterizePNG
COMMAND ${CMAKE_COMMAND}
-DPSFILE=${VTK_TEST_OUTPUT_DIR}/${TName}.ps
-DPNGFILE=${VTK_TEST_OUTPUT_DIR}/${TName}-raster.png
-DGS_EXECUTABLE=${VTK_GHOSTSCRIPT_EXECUTABLE}
-DREMOVEPS=1
-P ${CMAKE_CURRENT_SOURCE_DIR}/../../../../CMake/RasterizePostScript.cmake
)
set_tests_properties("${vtk-module}Cxx-${TName}-RasterizePNG"
PROPERTIES
DEPENDS "${vtk-module}Cxx-${TName}"
REQUIRED_FILES
"${VTK_TEST_OUTPUT_DIR}/${TName}.ps"
LABELS "${${vtk-module}_TEST_LABELS}"
)
set(TestGL2PSExporterVolumeRasterError 50)
# Convert ps to png
get_filename_component(TName ${test} NAME_WE)
if(${${TName}Error})
set(_error_threshold ${${TName}Error})
else()
set(_error_threshold 15)
endif()
# Image diff rasterized png with baseline
ExternalData_add_test(VTKData
NAME ${vtk-module}Cxx-${TName}-VerifyRasterizedPNG
COMMAND vtkRenderingGL2PSCxxTests PNGCompare
-D ${VTK_TEST_DATA_DIR}
-T ${VTK_TEST_OUTPUT_DIR}
-E ${_error_threshold}
-V DATA{../Data/Baseline/${TName}-rasterRef.png,:}
--test-file ${VTK_TEST_OUTPUT_DIR}/${TName}-raster.png
)
set_tests_properties("${vtk-module}Cxx-${TName}-VerifyRasterizedPNG"
PROPERTIES
DEPENDS "${vtk-module}Cxx-${TName}-RasterizePNG"
REQUIRED_FILES
"${VTK_TEST_OUTPUT_DIR}/${TName}-raster.png"
LABELS "${${vtk-module}_TEST_LABELS}"
)
endforeach()
endif()
include(vtkTestingGL2PS)
vtk_add_gl2ps_test_cxx(${GL2PSTests})
/*=========================================================================
Program: Visualization Toolkit
Module: TestGL2PSScalarBarWidget.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.
=========================================================================*/
// .SECTION Thanks
// This test was written by Philippe Pebay, Kitware 2011-12
// This work was supported by Commissariat a l'Energie Atomique (CEA/DIF)
#include "vtkSmartPointer.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkGL2PSExporter.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiBlockPLOT3DReader.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty2D.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkScalarBarActor.h"
#include "vtkScalarsToColors.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredGridGeometryFilter.h"
#include "vtkTestingInteractor.h"
#include "vtkTestUtilities.h"
#include "vtkTextProperty.h"
int TestGL2PSScalarBar( int argc, char *argv[] )
{
char* fname =
vtkTestUtilities::ExpandDataFileName( argc, argv, "Data/combxyz.bin");
char* fname2 =
vtkTestUtilities::ExpandDataFileName( argc, argv, "Data/combq.bin");
// Start by loading some data.
vtkSmartPointer<vtkMultiBlockPLOT3DReader> pl3d =
vtkSmartPointer<vtkMultiBlockPLOT3DReader>::New();
pl3d->SetXYZFileName( fname );
pl3d->SetQFileName( fname2 );
pl3d->SetScalarFunctionNumber( 100 );
pl3d->SetVectorFunctionNumber( 202 );
pl3d->Update();
delete [] fname;
delete [] fname2;
// An outline is shown for context.
vtkSmartPointer<vtkStructuredGridGeometryFilter> outline =
vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
outline->SetInputData( pl3d->GetOutput()->GetBlock( 0 ));
outline->SetExtent( 0, 100, 0, 100, 9, 9 );
vtkSmartPointer<vtkPolyDataMapper> outlineMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
outlineMapper->SetInputConnection( outline->GetOutputPort());
vtkSmartPointer<vtkActor> outlineActor =
vtkSmartPointer<vtkActor>::New();
outlineActor->SetMapper( outlineMapper );
// Create the RenderWindow, Renderer and all Actors
vtkSmartPointer<vtkRenderer> ren1 =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer( ren1 );
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow( renWin );
vtkSmartPointer<vtkScalarBarActor> scalarBar1 =
vtkSmartPointer<vtkScalarBarActor>::New();
vtkScalarsToColors* lut = outlineMapper->GetLookupTable();
lut->SetAnnotation(0.0, "Zed");
lut->SetAnnotation(1.0, "Uno");
lut->SetAnnotation(0.1, "$\\frac{1}{10}$");
lut->SetAnnotation(0.125, "$\\frac{1}{8}$");
lut->SetAnnotation(0.5, "Half");
scalarBar1->SetTitle("Density");
scalarBar1->SetLookupTable(lut);
scalarBar1->DrawAnnotationsOn();
scalarBar1->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
scalarBar1->GetPositionCoordinate()->SetValue( .6, .05 );
scalarBar1->SetWidth( 0.15 );
scalarBar1->SetHeight( 0.5 );
scalarBar1->SetTextPositionToPrecedeScalarBar();
scalarBar1->GetTitleTextProperty()->SetColor( 0., 0., 1. );
scalarBar1->GetLabelTextProperty()->SetColor( 0., 0., 1. );
scalarBar1->SetDrawFrame( 1 );
scalarBar1->GetFrameProperty()->SetColor( 0., 0., 0. );
scalarBar1->SetDrawBackground( 1 );
scalarBar1->GetBackgroundProperty()->SetColor( 1., 1., 1. );
vtkSmartPointer<vtkScalarBarActor> scalarBar2 =
vtkSmartPointer<vtkScalarBarActor>::New();
scalarBar2->SetTitle("Density");
scalarBar2->SetLookupTable(lut);
scalarBar2->DrawAnnotationsOff();
scalarBar2->SetOrientationToHorizontal();
scalarBar2->SetWidth( 0.5 );
scalarBar2->SetHeight( 0.15 );
scalarBar2->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
scalarBar2->GetPositionCoordinate()->SetValue( 0.05, 0.05 );
scalarBar2->SetTextPositionToPrecedeScalarBar();
scalarBar2->GetTitleTextProperty()->SetColor( 1., 0., 0. );
scalarBar2->GetLabelTextProperty()->SetColor( .8, 0., 0. );
scalarBar2->SetDrawFrame( 1 );
scalarBar2->GetFrameProperty()->SetColor( 1., 0., 0. );
scalarBar2->SetDrawBackground( 1 );
scalarBar2->GetBackgroundProperty()->SetColor( .5, .5, .5 );
vtkSmartPointer<vtkScalarBarActor> scalarBar3 =
vtkSmartPointer<vtkScalarBarActor>::New();
scalarBar3->SetTitle("Density");
scalarBar3->SetLookupTable(lut);
scalarBar3->DrawAnnotationsOff();
scalarBar3->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
scalarBar3->GetPositionCoordinate()->SetValue( .8, .05 );
scalarBar3->SetWidth( 0.15 );
scalarBar3->SetHeight( 0.5 );
scalarBar3->SetTextPositionToSucceedScalarBar();
scalarBar3->GetTitleTextProperty()->SetColor( 0., 0., 1. );
scalarBar3->GetLabelTextProperty()->SetColor( 0., 0., 1. );
scalarBar3->SetDrawFrame( 1 );
scalarBar3->GetFrameProperty()->SetColor( 0., 0., 0. );
scalarBar3->SetDrawBackground( 0 );
vtkSmartPointer<vtkScalarBarActor> scalarBar4 =
vtkSmartPointer<vtkScalarBarActor>::New();
scalarBar4->SetTitle("Density");
scalarBar4->SetLookupTable(lut);
scalarBar4->DrawAnnotationsOff();
scalarBar4->SetOrientationToHorizontal();
scalarBar4->SetWidth( 0.5 );
scalarBar4->SetHeight( 0.15 );
scalarBar4->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
scalarBar4->GetPositionCoordinate()->SetValue( .05, .8 );
scalarBar4->SetTextPositionToSucceedScalarBar();
scalarBar4->GetTitleTextProperty()->SetColor( 0., 0., 1. );
scalarBar4->GetLabelTextProperty()->SetColor( 0., 0., 1. );
scalarBar4->SetDrawFrame( 1 );
scalarBar4->GetFrameProperty()->SetColor( 1., 1., 1. );
scalarBar4->SetDrawBackground( 0 );
vtkSmartPointer<vtkCamera> camera =
vtkSmartPointer<vtkCamera>::New();
camera->SetFocalPoint( 8, 0, 30 );
camera->SetPosition( 6, 0, 50 );
// Add the actors to the renderer, set the background and size
//
ren1->AddActor( outlineActor );
ren1->AddActor( scalarBar1 );
ren1->AddActor( scalarBar2 );
ren1->AddActor( scalarBar3 );
ren1->AddActor( scalarBar4 );
ren1->GradientBackgroundOn();
ren1->SetBackground( .5,.5,.5 );
ren1->SetBackground2( .0,.0,.0 );
ren1->SetActiveCamera( camera );
// render the image
renWin->SetWindowName( "VTK - Scalar Bar options" );
renWin->SetSize( 700, 500 );
renWin->SetMultiSamples( 0 );
renWin->Render();
vtkNew<vtkGL2PSExporter> exp;
exp->SetRenderWindow(renWin);
exp->SetFileFormatToPS();
exp->CompressOff();
exp->DrawBackgroundOn();
exp->TextAsPathOn();
exp->Write3DPropsAsRasterImageOn();
std::string fileprefix = vtkTestingInteractor::TempDirectory +
std::string("/TestGL2PSScalarBar");
exp->SetFilePrefix(fileprefix.c_str());
exp->Write();
//Finally render the scene and compare the image to a reference image
renWin->GetInteractor()->Initialize();
renWin->GetInteractor()->Start();
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestGL2PSTextMapper.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 "vtkTextMapper.h"
#include "vtkActor2D.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkGL2PSExporter.h"
#include "vtkNew.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkProperty2D.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkTestingInteractor.h"
#include "vtkTextProperty.h"
#include "vtkUnsignedCharArray.h"
#include <sstream>
namespace vtkTestGL2PSTextMapper {
void setupTextMapper(vtkTextMapper *mapper, vtkActor2D *actor,
vtkPolyData *anchor)
{
vtkTextProperty *p = mapper->GetTextProperty();
std::ostringstream label;
label << "Angle: " << p->GetOrientation() << "\n"
<< "HAlign: " << p->GetJustificationAsString() << "\n"
<< "VAlign: " << p->GetVerticalJustificationAsString();
mapper->SetInput(label.str().c_str());
// Add the anchor point:
double *pos = actor->GetPosition();
double *col = p->GetColor();
vtkIdType ptId = anchor->GetPoints()->InsertNextPoint(pos[0], pos[1], 0.);
anchor->GetVerts()->InsertNextCell(1, &ptId);
anchor->GetCellData()->GetScalars()->InsertNextTuple4(col[0] * 255,
col[1] * 255,
col[2] * 255, 255);
}
} // end namespace vtkTestGL2PSTextMapper
//----------------------------------------------------------------------------
int TestGL2PSTextMapper(int, char *[])
{
using namespace vtkTestGL2PSTextMapper;
vtkNew<vtkRenderer> ren;
int width = 600;
int height = 600;
int x[3] = {100, 300, 500};
int y[4] = {100, 233, 366, 500};
// Render the anchor points to check alignment:
vtkNew<vtkPolyData> anchors;
vtkNew<vtkPoints> points;
anchors->SetPoints(points.GetPointer());
vtkNew<vtkCellArray> verts;
anchors->SetVerts(verts.GetPointer());
vtkNew<vtkUnsignedCharArray> colors;
colors->SetNumberOfComponents(4);
anchors->GetCellData()->SetScalars(colors.GetPointer());
for (size_t row = 0; row < 4; ++row)
{
for (size_t col = 0; col < 3; ++col)
{
vtkNew<vtkTextMapper> mapper;
vtkNew<vtkActor2D> actor;
actor->SetMapper(mapper.GetPointer());
switch (row)
{
case 0:
mapper->GetTextProperty()->SetOrientation(45);
break;
case 1:
mapper->GetTextProperty()->SetOrientation(-45);
break;
case 2:
break;
case 3:
mapper->GetTextProperty()->SetOrientation(90);
break;
}
switch (col)
{
case 0:
mapper->GetTextProperty()->SetJustificationToRight();
mapper->GetTextProperty()->SetVerticalJustificationToTop();
break;
case 1:
mapper->GetTextProperty()->SetJustificationToCentered();
mapper->GetTextProperty()->SetVerticalJustificationToCentered();
break;
case 2:
mapper->GetTextProperty()->SetJustificationToLeft();
mapper->GetTextProperty()->SetVerticalJustificationToBottom();
break;
}
mapper->GetTextProperty()->SetColor(0.75, .2 + col * .26, .2 + row * .2);
mapper->GetTextProperty()->SetBackgroundColor(0.0,
0.8 - col * .26,
.8 - row * .2);
mapper->GetTextProperty()->SetBackgroundOpacity(0.25);
actor->SetPosition(x[col], y[row]);
setupTextMapper(mapper.GetPointer(), actor.GetPointer(),
anchors.GetPointer());
ren->AddActor2D(actor.GetPointer());
}
}
vtkNew<vtkPolyDataMapper2D> anchorMapper;
anchorMapper->SetInputData(anchors.GetPointer());
vtkNew<vtkActor2D> anchorActor;
anchorActor->SetMapper(anchorMapper.GetPointer());
anchorActor->GetProperty()->SetPointSize(5);
ren->AddActor2D(anchorActor.GetPointer());
vtkNew<vtkRenderWindow> win;
win->AddRenderer(ren.GetPointer());
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(win.GetPointer());
ren->SetBackground(0.0, 0.0, 0.0);
ren->GetActiveCamera()->SetPosition(0, 0, 400);
ren->GetActiveCamera()->SetFocalPoint(0, 0, 0);
ren->GetActiveCamera()->SetViewUp(0, 1, 0);
ren->ResetCameraClippingRange();
win->SetSize(width, height);
win->Render();
vtkNew<vtkGL2PSExporter> exp;
exp->SetRenderWindow(win.GetPointer());
exp->SetFileFormatToPS();
exp->CompressOff();
exp->SetSortToSimple();
exp->TextAsPathOn();
exp->DrawBackgroundOn();
std::string fileprefix = vtkTestingInteractor::TempDirectory +
std::string("/TestGL2PSTextMapper");
exp->SetFilePrefix(fileprefix.c_str());
exp->Write();
// Finally render the scene and compare the image to a reference image
win->SetMultiSamples(0);
win->GetInteractor()->Initialize();
win->GetInteractor()->Start();
return EXIT_SUCCESS;
}