Skip to content

Commit

Permalink
Move pipeline-related update_input logic to pipelines.
Browse files Browse the repository at this point in the history
Modified some pipelines to remove SetInputData calls to ensure than
an actual visualization pipeline exists.

It is no longer necessary to rebuild the pipeline between animation steps,
just update the inputs and reexecute it.

This removes a half-finished implementation of update_input for vector
animation. Since it wasn't working / tested, I'll push a separate branch
that contains the ported implementation and adds a test, though there is
still work to be done to get it working.
  • Loading branch information
David C. Lonie committed Jul 9, 2015
1 parent dd81ee3 commit fab23e8
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 100 deletions.
77 changes: 6 additions & 71 deletions Packages/vcs/Lib/VTKPlots.py
Expand Up @@ -459,6 +459,8 @@ def plot(self,data1,data2,template,gtype,gname,bg,*args,**kargs):
if pipeline is not None:
returned.update(pipeline.plot(data1, data2, tpl, gm,
vtk_backend_grid, vtk_backend_geo))
returned["vtk_backend_pipeline"] = pipeline

elif gtype in ["3d_scalar", "3d_dual_scalar", "3d_vector"]:
cdms_file = kargs.get( 'cdmsfile', None )
cdms_var = kargs.get( 'cdmsvar', None )
Expand Down Expand Up @@ -1114,77 +1116,10 @@ def fitToViewport(self,Actor,vp,wc=None,geo=None,priority=None):
return Renderer

def update_input(self,vtkobjects,array1,array2=None,update=True):
if vtkobjects.has_key("vtk_backend_grid"):
## Ok ths is where we update the input data
vg=vtkobjects["vtk_backend_grid"]
data = vcs2vtk.numpy_to_vtk_wrapper(array1.filled(0.).flat, deep=False)
pData= vg.GetPointData().GetScalars()
if pData is not None:
vg.GetPointData().SetScalars(data)
else:
vg.GetCellData().SetScalars(data)
if vtkobjects.has_key("vtk_backend_filter"):
vtkobjects["vtk_backend_filter"].Update()
if vtkobjects.has_key("vtk_backend_missing_mapper"):
missingMapper,color,cellData = vtkobjects["vtk_backend_missing_mapper"]
missingMapper2 = vcs2vtk.putMaskOnVTKGrid(array1,vg,color,cellData,deep=False)
else:
missingMapper = None
if vtkobjects.has_key("vtk_backend_contours"):
for c in vtkobjects["vtk_backend_contours"]:
c.Update()
ports=vtkobjects["vtk_backend_contours"]
elif vtkobjects.has_key("vtk_backend_geofilters"):
ports=vtkobjects["vtk_backend_geofilters"]
else:
# Vector plot
ports=vtkobjects["vtk_backend_glyphfilters"]
w = vcs2vtk.generateVectorArray(array1,array2,vg)
vg.GetPointData().AddArray(w)
ports[0].SetInputData(vg)

if vtkobjects.has_key("vtk_backend_actors"):
i=0
for a in vtkobjects["vtk_backend_actors"]:
act = a[0]
wrp = a[1]
if a[1] is missingMapper:
i-=1
mapper = missingMapper2
wrp = a[2]
else:
## Labeled contours are a different kind
if vtkobjects.has_key("vtk_backend_luts"):
lut,rg = vtkobjects["vtk_backend_luts"][i]
mapper = vtk.vtkPolyDataMapper()
elif vtkobjects.has_key("vtk_backend_labeled_luts"):
lut,rg = vtkobjects["vtk_backend_labeled_luts"][i]
mapper = vtk.vtkLabeledContourMapper()
if lut is None:
mapper.SetInputConnection(ports[i].GetOutputPort())
else:
if mapper.IsA("vtkPolyDataMapper"):
mapper.SetInputConnection(ports[i].GetOutputPort())
mapper.SetLookupTable(lut)
mapper.SetScalarModeToUsePointData()
else:
stripper = vtk.vtkStripper()
stripper.SetInputConnection(ports[i].GetOutputPort())
mapper.SetInputConnection(stripper.GetOutputPort())
stripper.Update()
tprops = vtkobjects["vtk_backend_contours_labels_text_properties"]
mapper.GetPolyDataMapper().SetLookupTable(lut)
mapper.GetPolyDataMapper().SetScalarModeToUsePointData()
mapper.GetPolyDataMapper().SetScalarRange(rg[0],rg[1])
mapper.SetLabelVisibility(1)
mapper.SetTextProperties(tprops)
if rg[2]:
mapper.SetScalarModeToUseCellData()
mapper.SetScalarRange(rg[0],rg[1])
act.SetMapper(mapper)
act = vcs2vtk.doWrap(a[0],wrp)
a[0].SetMapper(act.GetMapper())
i+=1
# Let the pipeline implementation update itself:
if "vtk_backend_pipeline" in vtkobjects:
pipeline = vtkobjects["vtk_backend_pipeline"]
pipeline.update_input(array1, array2)

taxis = array1.getTime()
if taxis is not None:
Expand Down
14 changes: 8 additions & 6 deletions Packages/vcs/Lib/vcsvtk/boxfillpipeline.py
@@ -1,4 +1,5 @@
from .pipeline2d import Pipeline2D
from .vcswrapfilter import VCSWrapFilter
from .. import vcs2vtk

import numpy
Expand Down Expand Up @@ -156,12 +157,6 @@ def _plotInternal(self):
act = vtk.vtkActor()
act.SetMapper(mapper)

if self._vtkGeoTransform is None:
# If using geofilter on wireframed does not get wrppaed not
# sure why so sticking to many mappers
act = vcs2vtk.doWrap(act, [x1, x2, y1, y2],
self._dataWrapModulo)

# TODO We shouldn't need this conditional branch, the 'else' body
# should be used and GetMapper called to get the mapper as needed.
# If this is needed for other reasons, we need a comment explaining
Expand All @@ -180,6 +175,13 @@ def _plotInternal(self):
wc=[x1, x2, y1, y2], geo=self._vtkGeoTransform,
priority=self._template.data.priority)

if self._vtkGeoTransform is None:
wrapFilter = VCSWrapFilter([x1, x2, y1, y2],
self._dataWrapModulo,
transform=act.GetMatrix())
wrapFilter.SetInputConnection(mapper.GetInputConnection(0, 0))
mapper.SetInputConnection(wrapFilter.GetOutputPort())

self._resultDict["vtk_backend_actors"] = actors

t = self._originalData1.getTime()
Expand Down
16 changes: 9 additions & 7 deletions Packages/vcs/Lib/vcsvtk/isofillpipeline.py
@@ -1,4 +1,5 @@
from .pipeline2d import Pipeline2D
from .vcswrapfilter import VCSWrapFilter
from .. import vcs2vtk

import numpy
Expand Down Expand Up @@ -141,7 +142,7 @@ def _plotInternal(self):
lut = vtk.vtkLookupTable()
cot = vtk.vtkBandedPolyDataContourFilter()
cot.ClippingOn()
cot.SetInputData(self._vtkPolyDataFilter.GetOutput())
cot.SetInputConnection(self._vtkPolyDataFilter.GetOutputPort())
cot.SetNumberOfContours(len(l))
cot.SetClipTolerance(0.)
for j, v in enumerate(l):
Expand Down Expand Up @@ -203,12 +204,6 @@ def _plotInternal(self):
act = vtk.vtkActor()
act.SetMapper(mapper)

if self._vtkGeoTransform is None:
# If using geofilter on wireframed does not get wrppaed not
# sure why so sticking to many mappers
act = vcs2vtk.doWrap(act, [x1, x2, y1, y2],
self._dataWrapModulo)

# TODO see comment in boxfill.
if mapper is self._maskedDataMapper:
actors.append([act, self._maskedDataMapper, [x1, x2, y1, y2]])
Expand All @@ -224,6 +219,13 @@ def _plotInternal(self):
wc=[x1, x2, y1, y2], geo=self._vtkGeoTransform,
priority=self._template.data.priority)

if self._vtkGeoTransform is None:
wrapFilter = VCSWrapFilter([x1, x2, y1, y2],
self._dataWrapModulo,
transform=act.GetMatrix())
wrapFilter.SetInputConnection(mapper.GetInputConnection(0, 0))
mapper.SetInputConnection(wrapFilter.GetOutputPort())

self._resultDict["vtk_backend_actors"] = actors

t = self._originalData1.getTime()
Expand Down
19 changes: 9 additions & 10 deletions Packages/vcs/Lib/vcsvtk/isolinepipeline.py
@@ -1,4 +1,5 @@
from .pipeline2d import Pipeline2D
from .vcswrapfilter import VCSWrapFilter
from .. import vcs2vtk

import numpy
Expand Down Expand Up @@ -77,8 +78,6 @@ def _plotInternal(self):
for i in range(numLevels):
cot.SetValue(i, self._contourLevels[i])
cot.SetValue(numLevels, self._contourLevels[-1])
# TODO remove update
cot.Update()

mappers = []

Expand Down Expand Up @@ -173,8 +172,6 @@ def _plotInternal(self):
stripper = vtk.vtkStripper()
stripper.SetInputConnection(cot.GetOutputPort())
mapper.SetInputConnection(stripper.GetOutputPort())
# TODO remove update, make pipeline
stripper.Update()
mappers.append(mapper)
self._resultDict["vtk_backend_contours"] = [cot]

Expand All @@ -191,12 +188,6 @@ def _plotInternal(self):
act = vtk.vtkActor()
act.SetMapper(mapper)

if self._vtkGeoTransform is None:
# If using geofilter on wireframed does not get wrppaed not
# sure why so sticking to many mappers
act = vcs2vtk.doWrap(act, [x1, x2, y1, y2],
self._dataWrapModulo)

# TODO See comment in boxfill.
if mapper is self._maskedDataMapper:
actors.append([act, self._maskedDataMapper, [x1, x2, y1, y2]])
Expand All @@ -212,6 +203,14 @@ def _plotInternal(self):
wc=[x1, x2, y1, y2], geo=self._vtkGeoTransform,
priority=self._template.data.priority)

if self._vtkGeoTransform is None:
wrapFilter = VCSWrapFilter([x1, x2, y1, y2],
self._dataWrapModulo,
transform=act.GetMatrix())
wrapFilter.SetInputConnection(mapper.GetInputConnection(0, 0))
mapper.SetInputConnection(wrapFilter.GetOutputPort())
mapper.Update()

self._resultDict["vtk_backend_actors"] = actors

t = self._originalData1.getTime()
Expand Down
14 changes: 8 additions & 6 deletions Packages/vcs/Lib/vcsvtk/meshfillpipeline.py
@@ -1,4 +1,5 @@
from .pipeline2d import Pipeline2D
from .vcswrapfilter import VCSWrapFilter
from .. import vcs2vtk

import numpy
Expand Down Expand Up @@ -225,12 +226,6 @@ def _plotInternal(self):
prop = act.GetProperty()
prop.SetRepresentationToWireframe()

if self._vtkGeoTransform is None:
# If using geofilter on wireframed does not get wrppaed not
# sure why so sticking to many mappers
act = vcs2vtk.doWrap(act, [x1, x2, y1, y2],
self._dataWrapModulo)

# create a new renderer for this mapper
# (we need one for each mapper because of cmaera flips)
ren = self._context().fitToViewport(
Expand All @@ -241,6 +236,13 @@ def _plotInternal(self):
wc=[x1, x2, y1, y2], geo=self._vtkGeoTransform,
priority=self._template.data.priority)

if self._vtkGeoTransform is None:
wrapFilter = VCSWrapFilter([x1, x2, y1, y2],
self._dataWrapModulo,
transform=act.GetMatrix())
wrapFilter.SetInputConnection(mapper.GetInputConnection(0, 0))
mapper.SetInputConnection(wrapFilter.GetOutputPort())

# TODO See comment in boxfill.
if mapper is self._maskedDataMapper:
actors.append([act, self._maskedDataMapper, [x1, x2, y1, y2]])
Expand Down
4 changes: 4 additions & 0 deletions Packages/vcs/Lib/vcsvtk/pipeline.py
Expand Up @@ -20,3 +20,7 @@ def __init__(self, context_):
# broken up into set_data, set_template, etc methods...
def plot(self, data1, data2, template, graphics_method, grid, transform):
raise NotImplementedError("Missing override.")

def update_input(self, data1, data2):
"""Update the input to this pipeline."""
raise NotImplementedError("Missing override.")
27 changes: 27 additions & 0 deletions Packages/vcs/Lib/vcsvtk/pipeline2d.py
Expand Up @@ -202,3 +202,30 @@ def _createMaskedDataMapper(self):
self._resultDict["vtk_backend_missing_mapper"] = (self._maskedDataMapper,
self._maskedDataColor,
self._useCellScalars)

def update_input(self, array1, array2):
"""Reimplemented from base class."""

# Update the scalar array:
data = vcs2vtk.numpy_to_vtk_wrapper(array1.filled(0.).flat, deep=False)
if self._useCellScalars:
self._vtkDataSet.GetCellData().SetScalars(data)
else:
self._vtkDataSet.GetPointData().SetScalars(data)

# Regenerate the mask data mapper for the new array:
# TODO It'd be ideal to rework this function to preserve the pipeline.
# Then we won't need to regenerate all of this and just reexecute the
# existing pipeline.
self._maskedDataMapper = vcs2vtk.putMaskOnVTKGrid(
array1, self._vtkDataSet, self._maskedDataColor,
self._useCellScalars, deep=False)

# Connect or disconnect the actor depending on whether the masked
# mapper was generated.
if self._maskedDataMapper is not None:
if self._maskedDataActor is None:
self._maskedDataActor = vtk.vtkActor()
self._maskedDataActor.SetMapper(self._maskedDataMapper)
elif self._maskedDataActor is not None:
self._maskedDataActor.SetMapper(0)
1 change: 1 addition & 0 deletions testing/vcs/test_animate_boxfill.py
Expand Up @@ -31,4 +31,5 @@
if ret == 0:
os.removedirs(os.path.split(p)[0])
os.remove("%s.mp4" % prefix)
x.close()
sys.exit(ret)
1 change: 1 addition & 0 deletions testing/vcs/test_animate_meshfill.py
Expand Up @@ -43,4 +43,5 @@
if ret == 0:
os.removedirs(os.path.split(p)[0])
os.remove("%s.mp4" % prefix)
x.close()
sys.exit(ret)

0 comments on commit fab23e8

Please sign in to comment.