[Paraview] Patch to add vector postscript output to Paraview

Sven Buijssen sven.buijssen at uni-dortmund.de
Fri Aug 10 10:13:07 EDT 2007


Hello,

Without too much knowledge of VTK or Paraview I have added at least basic
support for high quality vector PostScript output (PS/EPS/SVG) using the
vtkGL2PSExporter. It requires Paraview / VTK to be compiled with GL2PS support.

The patch attached below does not allow for everything that can be exported to
an image format. In particular, one should uncheck "Interpolate Colors" in
Object Inspector - Display for every object. Otherwise an object's colors will
get lost, it will simply be colored white in the vector graphics format.

TextSource objects (Sources - Text) are not treated properly neither, the
outline of the text is filled with white masking all objects behind.
VectorText objects (Sources - 3D Text), however, work. A color legend's text, too.

A configuration dialog for vtkGL2PSExporter - like MayaVi offers - is still
missing, by the way. Those settings I considered useful are hard-coded.

I do hope others will find this enhancement useful.

Included is also a small patch that fixes a compile error if
VTK_USE_MPEG2_ENCODER is set.

The patches are against the sources of Paraview 3.1.0, but it should easily be
possible to backport them to earlier versions.


Sven
-------------- next part --------------
diff -Nau -r ParaView3.orig/CMake/ParaViewCommon.cmake ParaView3/CMake/ParaViewCommon.cmake
--- ParaView3.orig/CMake/ParaViewCommon.cmake	2007-05-30 16:03:54.000000000 +0200
+++ ParaView3/CMake/ParaViewCommon.cmake	2007-08-08 11:27:14.000000000 +0200
@@ -28,7 +28,7 @@
 SET(VTK_USE_HYBRID_ISSET ON)
 SET(VTK_USE_PARALLEL_ISSET ON)
 SET(VTK_USE_VOLUMERENDERING_ISSET ON)
-SET(VTK_USE_GL2PS_ISSET OFF)
+SET(VTK_USE_GL2PS_ISSET ON)
 SET(VTK_USE_ANSI_STDLIB ${PARAVIEW_USE_ANSI_STDLIB})
 SET(VTK_HEADER_TESTING_PY "${ParaView_SOURCE_DIR}/VTK/Common/Testing/HeaderTesting.py")
 SET(VTK_PRINT_SELF_CHECK_TCL "${ParaView_SOURCE_DIR}/VTK/Common/Testing/Tcl/PrintSelfCheck.tcl")
diff -Nau -r ParaView3.orig/Qt/Components/pqMainWindowCore.cxx ParaView3/Qt/Components/pqMainWindowCore.cxx
--- ParaView3.orig/Qt/Components/pqMainWindowCore.cxx	2007-06-29 20:44:59.000000000 +0200
+++ ParaView3/Qt/Components/pqMainWindowCore.cxx	2007-08-10 14:44:01.000000000 +0200
@@ -2026,6 +2026,11 @@
   filters += ";;PPM image (*.ppm)";
   filters += ";;JPG image (*.jpg)";
   filters += ";;PDF file (*.pdf)";
+#ifdef VTK_USE_GL2PS
+  filters += ";;Postscript file (*.ps)";
+  filters += ";;Encapsulated Postscript file (*.eps)";
+  filters += ";;Scalable Vector Graphics file (*.svg)";
+#endif
   filters += ";;All files (*)";
   pqFileDialog* const file_dialog = new pqFileDialog(NULL,
     this->Implementation->Parent, tr("Save Screenshot:"), QString(), filters);
@@ -2068,7 +2073,7 @@
   QString filters = "";
 
 #ifdef VTK_USE_MPEG2_ENCODER
-  filter += "MPEG files (*.mpg);;";
+  filters += "MPEG files (*.mpg);;";
 #endif
 #ifdef _WIN32
   filters += "AVI files (*.avi);;";
diff -Nau -r ParaView3.orig/Qt/Core/pqRenderView.cxx ParaView3/Qt/Core/pqRenderView.cxx
--- ParaView3.orig/Qt/Core/pqRenderView.cxx	2007-06-26 21:30:35.000000000 +0200
+++ ParaView3/Qt/Core/pqRenderView.cxx	2007-08-10 15:13:09.000000000 +0200
@@ -51,6 +51,12 @@
 #include "vtkSMUndoStack.h"
 #include "vtkTrackballPan.h"
 
+#include <vtkToolkits.h>
+#ifdef VTK_USE_GL2PS
+#include "vtkGL2PSExporter.h"
+#include "vtkRenderWindow.h"
+#endif
+
 // Qt includes.
 #include <QFileInfo>
 #include <QList>
@@ -596,6 +602,63 @@
 
     return true;
     }
+#ifdef VTK_USE_GL2PS
+  else if(file.completeSuffix() == "ps" || file.completeSuffix() == "eps" || file.completeSuffix() == "svg")
+    {
+	// Variant 1 (works!)
+//	vtkGL2PSExporter* psExporter = vtkGL2PSExporter::New();
+//	psExporter->SetRenderWindow(this->Internal->RenderModuleProxy->GetRenderWindow());
+
+	// Variant 2 (works!)
+        vtkSmartPointer< vtkGL2PSExporter > psExporter( vtkGL2PSExporter::New() );
+	psExporter->SetRenderWindow(this->Internal->Viewport->GetRenderWindow());
+
+	// Enforce maximal smoothing. Not sure whether this makes a difference or
+	// is needed at all.
+	vtkRenderWindow *smoothing = vtkRenderWindow::New();
+	smoothing = this->Internal->Viewport->GetRenderWindow();
+	smoothing->LineSmoothingOn();
+	smoothing->PointSmoothingOn ();
+	smoothing->PolygonSmoothingOn ();
+
+
+	// Treat filename, it already contains a suffix which needs to be cut off
+	QString fileName = filename;
+        if( fileName.endsWith( ".ps" ) || fileName.endsWith( ".PS" ) )
+        {
+           fileName.chop( 3 );
+	   psExporter->SetFileFormatToPS();
+        }
+        if( fileName.endsWith( ".eps" ) || fileName.endsWith( ".EPS" ) )
+        {
+           fileName.chop( 4 );
+	   psExporter->SetFileFormatToEPS();
+        }
+        if( fileName.endsWith( ".svg" ) || fileName.endsWith( ".SVG" ) )
+        {
+           fileName.chop( 4 );
+	   psExporter->SetFileFormatToSVG();
+        }
+
+	// Variant 1 (works! Difference to second variant unclear.)
+//	psExporter->SetFilePrefix(qPrintable(fileName));
+
+	// Variant 2 (works! support for unicode?)
+        psExporter->SetFilePrefix( fileName.toStdString().c_str() );
+
+	psExporter->CompressOff();
+	psExporter->DrawBackgroundOff();
+	psExporter->TextOn();
+	psExporter->PS3ShadingOn();
+	psExporter->OcclusionCullOn();
+	psExporter->SetSortToBSP();
+
+	psExporter->Write();
+	psExporter->Delete();
+
+	return true;
+    }
+#endif
   else
     {
     qCritical() << "Failed to determine file type for file:" 


More information about the ParaView mailing list