[Paraview] GL2PS for Paraview - Plugin Problems

Sven Buijssen sven.buijssen at uni-dortmund.de
Sat Mar 1 10:24:54 EST 2008


Hi Enkelejda,

> VTK provides the class vtkGL2PSExporter to export a scene as a 
> PostScript file using GL2PS. This is also very nice to have in Paraview, 
> as it writes vector PostScript (PS/EPS), and is thus very nice for 
> publication pics.

In August 2007 I posted a patch for the ParaView 3.1.0 source tree adding vector 
postscript output to Paraview by means of GL2PS. There were no follow-ups to 
this post on the mailing list, I received a few reactions via personal e-mail. I 
assume the point of view of the ParaView developers is to not support vector 
postscript output as many things one can visualise with ParaView can simply not 
be exported to Postscript with GL2PS. I perfectly understand this argument, in 
particular as it prevents a lot of bug reports concerning the seemingly broken 
vector postscript support.

Nonetheless, I find vector postscript output very useful to have in ParaView 
(eps format requirements for publications). I ported my patch to the current 
development distribution (3.3.0, cvs version as of today, QT 4.3.4). It is less 
well integrated into the code than previously (as the export routines moved from 
Qt/Core/pqRenderView.cxx to Qt/Core/pqImageUtil.cxx since 3.1.0 and the patch 
still applies mainly to Qt/Core/pqRenderView.cxx), but it does the job.

It is not the Plugin approach you pursued, but I hope it helps.

It is probably a bit too perky to ask for, but it would be great if the patch 
would make it into the CVS repository, as then there would be a chance that 
someone with more VTK experience than me would keep it up to date, automatically 
would disable conflicting drawing options (e.g. "Interpolate Colors") and 
possibly even add some kind of error handling.

Sven
-------------- next part --------------
diff -Nau -r ParaView3.orig/CMake/ParaViewCommon.cmake ParaView3/CMake/ParaViewCommon.cmake
--- ParaView3.orig/CMake/ParaViewCommon.cmake	2008-03-01 15:58:31.000000000 +0100
+++ ParaView3/CMake/ParaViewCommon.cmake	2008-01-14 13:49:03.000000000 +0100
@@ -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	2008-03-01 15:58:31.000000000 +0100
+++ ParaView3/Qt/Components/pqMainWindowCore.cxx	2008-03-01 11:16:00.000000000 +0100
@@ -1687,6 +1687,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);
diff -Nau -r ParaView3.orig/Qt/Core/pqRenderView.cxx ParaView3/Qt/Core/pqRenderView.cxx
--- ParaView3.orig/Qt/Core/pqRenderView.cxx	2008-03-01 15:58:31.000000000 +0100
+++ ParaView3/Qt/Core/pqRenderView.cxx	2008-01-14 17:53:50.000000000 +0100
@@ -54,6 +54,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>
@@ -567,6 +573,72 @@
 
   int error_code = vtkErrorCode::UnknownError;
   vtkImageData* vtkimage = this->getRenderViewProxy()->CaptureWindow(magnification);
+#ifdef VTK_USE_GL2PS
+  const QFileInfo file(filename);
+  if (file.suffix() == "ps" || file.suffix() == "eps" || file.suffix() == "svg")
+  {
+      // ParaView 3.1.0 - Variant 1 (works!)
+//    vtkGL2PSExporter* psExporter = vtkGL2PSExporter::New();
+//    psExporter->SetRenderWindow(this->Internal->RenderModuleProxy->GetRenderWindow());
+
+      // ParaView 3.1.0 - Variant 2 (works!)
+//    vtkSmartPointer< vtkGL2PSExporter > psExporter( vtkGL2PSExporter::New() );
+//    psExporter->SetRenderWindow(this->Internal->Viewport->GetRenderWindow());
+
+      // ParaView 3.3.0
+      vtkSmartPointer< vtkGL2PSExporter > psExporter( vtkGL2PSExporter::New() );
+      // works, but does not respect magnification requests. Does not make
+      // a difference anyway as increasing magnification does not improve
+      // rendering resolution in ParaView right now.
+      psExporter->SetRenderWindow(this->getRenderViewProxy()->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 filename2 = filename;
+      if( filename2.endsWith( ".ps" ) || filename2.endsWith( ".PS" ) )
+      {
+         filename2.chop( 3 );
+	 psExporter->SetFileFormatToPS();
+      }
+      if( filename2.endsWith( ".eps" ) || filename2.endsWith( ".EPS" ) )
+      {
+	 filename2.chop( 4 );
+	 psExporter->SetFileFormatToEPS();
+      }
+      if( filename2.endsWith( ".svg" ) || filename2.endsWith( ".SVG" ) )
+      {
+	 filename2.chop( 4 );
+         psExporter->SetFileFormatToSVG();
+      }
+
+      // Variant 1 (works! Difference to second variant unclear.)
+//    psExporter->SetFilePrefix(qPrintable(filename2));
+
+      // Variant 2 (works! support for unicode?)
+      psExporter->SetFilePrefix( filename2.toStdString().c_str() );
+
+      psExporter->CompressOff();
+      psExporter->DrawBackgroundOff();
+      psExporter->TextOn();
+      psExporter->PS3ShadingOn();
+      psExporter->OcclusionCullOn();
+      psExporter->SetSortToBSP();
+
+      psExporter->Write();
+      psExporter->Delete();
+
+      // TODO: add some error checking.
+      error_code = vtkErrorCode::NoError;
+  }
+  else
+#endif
   if (vtkimage)
     {
     error_code = pqImageUtil::saveImage(vtkimage, filename);


More information about the ParaView mailing list