Skip to content

Commit

Permalink
Compatibility with new version of vtk
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienRietteMTO committed Nov 27, 2024
1 parent 3b68245 commit 7c1b67a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
34 changes: 18 additions & 16 deletions bin/epy_plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# This software is governed by the CeCILL-C license under French law.
# http://www.cecill.info

from __future__ import print_function, absolute_import, unicode_literals, division
from __future__ import (print_function, absolute_import, unicode_literals,
division)
import six

import os
Expand All @@ -30,7 +31,7 @@
extraction_options)
from epygram.base import FieldSet
from epygram.geometries import VGeometry
from usevtk import Usevtk
from epygram.extra.usevtk import Usevtk

import numpy

Expand Down Expand Up @@ -200,7 +201,7 @@ def _do_plot(field, plotmode,
except ValueError:
M = ff.max()
minmax = (m, M)

colorequal = colormin == colormax
if isinstance(colormin, six.string_types):
colormin = vtk.vtkNamedColors().GetColor3d(colormin)
Expand All @@ -213,7 +214,7 @@ def _do_plot(field, plotmode,
opacity = vtk.vtkPiecewiseFunction()
opacity.AddPoint(minmax[0], float(opacitymin))
opacity.AddPoint(minmax[1], float(opacitymax))

if plotmode == 'contour':
levels = numpy.linspace(minmax[0], minmax[1], levelsnumber)
field.plot3DContour(rendering,
Expand Down Expand Up @@ -394,13 +395,13 @@ def main(plotmode,
else:
assert len(fieldseed) == 2
(Ufid, Vfid) = fieldseed

U, subzone, academic = _get_field(resource, Ufid, subzone, zoom, operation,
None, False, global_shift_center,
Yconvert, cheap_height, empty_value)
V, subzone, academic = _get_field(resource, Vfid, subzone, zoom, operation,
None, False, global_shift_center,
Yconvert, cheap_height, empty_value)
V, subzone, academic = _get_field(resource, Vfid, subzone, zoom, operation,
None, False, global_shift_center,
Yconvert, cheap_height, empty_value)
field = epygram.fields.make_vector_field(U, V)
if legend is not None:
title = legend
Expand Down Expand Up @@ -543,8 +544,9 @@ def cameraMove(*args):
print(" Clipping range (vtk coordinates) :", cam.GetClippingRange())
for ren in rendering:
ren.window.Render()
for ren in rendering:
ren.interactor.AddObserver("EndInteractionEvent", cameraMove)
if not output:
for ren in rendering:
ren.interactor.AddObserver("EndInteractionEvent", cameraMove)
cameraMove() #for printing position

# Output
Expand Down Expand Up @@ -674,22 +676,22 @@ def cameraMove(*args):
zoom = None
if args.operation is not None:
_operation = args.operation.split(',')
operation = {'operation':_operation.pop(0).strip()}
operation = {'operation': _operation.pop(0).strip()}
if len(_operation) > 0:
operation['operand'] = float(_operation.pop(0).strip())
else:
operation = None
if args.diffoperation is not None:
_diffoperation = args.diffoperation.split(',')
diffoperation = {'operation':_diffoperation.pop(0).strip()}
diffoperation = {'operation': _diffoperation.pop(0).strip()}
if len(_diffoperation) > 0:
diffoperation['operand'] = float(_diffoperation.pop(0).strip())
else:
diffoperation = None
if args.compose_with is not None:
_composition = args.compose_with.split(',')
composition = {'fid':_composition.pop(0).strip(),
'operation':_composition.pop(0).strip()}
composition = {'fid': _composition.pop(0).strip(),
'operation': _composition.pop(0).strip()}
while len(_composition) > 0:
composition.update(str2dict(_composition.pop(0).strip()))
else:
Expand Down Expand Up @@ -730,11 +732,11 @@ def cameraMove(*args):
if args.vectors_verticalsubsampling is not None:
vectors_subsampling['z'] = int(args.vectors_verticalsubsampling)
if args.focal_point is not None:
focal_point =[float(s) for s in args.focal_point.split(',')]
focal_point = [float(s) for s in args.focal_point.split(',')]
else:
focal_point = None
if args.camera is not None:
camera =[float(s) for s in args.camera.split(',')]
camera = [float(s) for s in args.camera.split(',')]
else:
camera = None

Expand Down
28 changes: 17 additions & 11 deletions src/epygram/_plugins/with_vtk/_D3CommonField.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,28 @@ def plot3DVolume(self, rendering,

fil = vtk.vtkThreshold()
fil.SetInputConnection(grid.GetOutputPort())
if maxval is None:
fil.ThresholdByUpper(minval)
elif minval is None:
fil.ThresholdByLower(maxval)
elif minval is None and maxval is None:
pass
if hasattr(fil, 'ThresholdByUpper'):
if maxval is None:
fil.ThresholdByUpper(minval)
elif minval is None:
fil.ThresholdByLower(maxval)
elif minval is None and maxval is None:
pass
else:
fil.ThresholdBetween(minval, maxval)
else:
fil.ThresholdBetween(minval, maxval)
if minval is not None:
fil.SetLowerThreshold(minval)
if maxval is not None:
fil.SetUpperThreshold(maxval)

tri = vtk.vtkDataSetTriangleFilter()
tri.SetInputConnection(fil.GetOutputPort())

volumeMapper = {'RayCast':vtk.vtkUnstructuredGridVolumeRayCastMapper,
'ZSweep':vtk.vtkUnstructuredGridVolumeZSweepMapper,
'ProjectedTetrahedra':vtk.vtkProjectedTetrahedraMapper,
'OpenGLProjectedTetrahedra':vtk.vtkOpenGLProjectedTetrahedraMapper}[algo]()
volumeMapper = {'RayCast': vtk.vtkUnstructuredGridVolumeRayCastMapper,
'ZSweep': vtk.vtkUnstructuredGridVolumeZSweepMapper,
'ProjectedTetrahedra': vtk.vtkProjectedTetrahedraMapper,
'OpenGLProjectedTetrahedra': vtk.vtkOpenGLProjectedTetrahedraMapper}[algo]()
volumeMapper.SetInputConnection(tri.GetOutputPort())

volumeProperty = vtk.vtkVolumeProperty()
Expand Down
5 changes: 4 additions & 1 deletion src/epygram/extra/usevtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def modify_grid(grid, grid_type, datamin=None):
if datamin is None:
raise epygramError("datamin must be provided for unstructured grid types")
minScalar = datamin
fil.ThresholdByUpper(minScalar - 1.)
if hasattr(fil, 'ThresholdByUpper'):
fil.ThresholdByUpper(minScalar - 1.)
else:
fil.SetLowerThreshold(minScalar - 1.)
grid = fil
# Grid is now unstructured

Expand Down

0 comments on commit 7c1b67a

Please sign in to comment.