VTKExamples
VTKExamples copied to clipboard
Question about how to export scene as EPS
Firstly, I have found your examples very useful and my apologies if this is not the right place to ask such questions. I'm attempting to export a scene as an EPS using vtk.vtkGL2PSExporter() but I receive the following message: NotImplementedError: no concrete implementation exists for this class. I installed vtk for python3 from http://www.lfd.uci.edu/~gohlke/pythonlibs/ I realize the GL2PS program is separate from VTK but I'm not sure how to install it or whether it would be possible to get vtk to use it from the python interface.
Tom,
This works for me. Can you try it?
import vtk
This example uses a "glyph table" to change the shape of the 3d glyphs
according to a scalar value.
NOTE: The vtkGlyph3D filter doesn't copy over scalars to the glyphs
generated by a table like this for some reason...
The Wavelet Source is nice for generating a test vtkImageData set
rt = vtk.vtkRTAnalyticSource() rt.SetWholeExtent(-2,2,-2,2,0,0)
Take the gradient of the only scalar 'RTData' to get a vector attribute
grad = vtk.vtkImageGradient() grad.SetDimensionality(3) grad.SetInputConnection(rt.GetOutputPort())
Elevation just to generate another scalar attribute that varies nicely
over the data range elev = vtk.vtkElevationFilter()
Elevation values will range from 0 to 1 between the Low and High Points
elev.SetLowPoint(-2,-2,0) elev.SetHighPoint(2,2,0) elev.SetInputConnection(grad.GetOutputPort())
Create simple PolyData for glyph table
cs = vtk.vtkCubeSource() cs.SetXLength(0.5) cs.SetYLength(1) cs.SetZLength(2) ss = vtk.vtkSphereSource() ss.SetRadius(0.25) cs2 = vtk.vtkConeSource() cs2.SetRadius(0.25) cs2.SetHeight(0.5)
Set up the glyph filter
glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(elev.GetOutputPort())
Here is where we build the glyph table
that will be indexed into according to the IndexMode
glyph.SetSourceConnection(0,cs.GetOutputPort()) glyph.SetSourceConnection(1,ss.GetOutputPort()) glyph.SetSourceConnection(2,cs2.GetOutputPort())
glyph.ScalingOn() glyph.SetScaleModeToScaleByScalar() glyph.SetVectorModeToUseVector() glyph.OrientOn() glyph.SetScaleFactor(1) # Overall scaling factor glyph.SetRange(0, 1) # Default is (0,1)
Tell it to index into the glyph table according to scalars
glyph.SetIndexModeToScalar()
Tell glyph which attribute arrays to use for what
glyph.SetInputArrayToProcess(0,0,0,0,'Elevation') # scalars glyph.SetInputArrayToProcess(1,0,0,0,'RTDataGradient') # vectors
I would call Update if I could use the scalar range to set the color map
range
glyph.Update()
coloring_by = 'RTData' mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(glyph.GetOutputPort()) mapper.SetScalarModeToUsePointFieldData() mapper.SetColorModeToMapScalars() mapper.ScalarVisibilityOn()
GetRange() call doesn't work because attributes weren't copied to glyphs
as they should have been...
mapper.SetScalarRange(glyph.GetOutputDataObject(0).GetPointData().GetArray(coloring_by).GetRange())
mapper.SelectColorArray(coloring_by) actor = vtk.vtkActor() actor.SetMapper(mapper)
ren = vtk.vtkRenderer() ren.AddActor(actor) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() istyle = vtk.vtkInteractorStyleTrackballCamera() iren.SetInteractorStyle(istyle) iren.SetRenderWindow(renWin) ren.ResetCamera() renWin.Render()
iren.Start()
exporter=vtk.vtkGL2PSExporter() exporter.SetRenderWindow(renWin); exporter.SetFileFormatToPDF(); exporter.CompressOff(); exporter.SetSortToSimple(); exporter.DrawBackgroundOn(); exporter.SetFilePrefix("test"); exporter.Write();
On Tue, Aug 1, 2017 at 10:15 AM, Tom Tranter [email protected] wrote:
Firstly, I have found your examples very useful and my apologies if this is not the right place to ask such questions. I'm attempting to export a scene as an EPS using vtk.vtkGL2PSExporter() but I receive the following message: NotImplementedError: no concrete implementation exists for this class. I installed vtk for python3 from http://www.lfd.uci.edu/~ gohlke/pythonlibs/ I realize the GL2PS program is separate from VTK but I'm not sure how to install it or whether it would be possible to get vtk to use it from the python interface.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lorensen/VTKExamples/issues/15, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUFDAsYqzj6hXBYiHtYstBOZFHDng3pks5sTzLsgaJpZM4OpyxV .
-- Unpaid intern in BillsBasement at noware dot com
Hi @lorensen, thanks for the reply. The line setting the mapper range falls over but I commented it out and got the VTK window with all the glyphs. When I press 'Q' it closes and I get the following error message in another VTK window when this line is run 'exporter=vtk.vtkGL2PSExporter()' Generic Warning: In D:\Build\VTK\VTK-7.1.1\IO\Export\vtkGL2PSExporter.cxx, line 26 Error: no override found for 'vtkGL2PSExporter'. Perhaps the binary I downloaded does not have the correct compiler options - http://vtk.1045678.n5.nabble.com/GL2PSExporter-issue-td5738900.html
The binary probably does not have those settings. Perhaps oyu can check with the owner of the binary.
On Fri, Aug 4, 2017 at 11:23 AM, Tom Tranter [email protected] wrote:
Hi @lorensen https://github.com/lorensen, thanks for the reply. The line setting the mapper range falls over but I commented it out and got the VTK window with all the glyphs. When I press 'Q' it closes and I get the following error message in another VTK window when this line is run 'exporter=vtk.vtkGL2PSExporter()' Generic Warning: In D:\Build\VTK\VTK-7.1.1\IO\Export\vtkGL2PSExporter.cxx, line 26 Error: no override found for 'vtkGL2PSExporter'. Perhaps the binary I downloaded does not have the correct compiler options
- http://vtk.1045678.n5.nabble.com/GL2PSExporter-issue-td5738900.html
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lorensen/VTKExamples/issues/15#issuecomment-320277346, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUFDClfnnelAHGY8SQ5aEE6fwnvU9O9ks5sUzdrgaJpZM4OpyxV .
-- Unpaid intern in BillsBasement at noware dot com