Skip to content

Commit

Permalink
Change deprecated than removed APIs in VTK. (#20)
Browse files Browse the repository at this point in the history
* Change deprecated than removed APIs in VTK.

* Fix difference between python 2 and 3.

* Not used (and unavailable) in OpenGL2

* ast.literal_eval needs strings.

* Fix hiding widgets.

* Fix buttons show only when active.

* Not a Button class so there is no active.

* Fix lighting.

1. Remove ambient lighting that made colors washed out.
2. add vtkLightKit

* WIP: use danlipsa channel for vtk and vcs.

* removed dan channel

* correct vtk?

* fix travis to not use dan channels
  • Loading branch information
danlipsa authored and doutriaux1 committed Dec 15, 2018
1 parent 4afbd51 commit 215c720
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -22,7 +22,7 @@ aliases:
name: create_conda_env
environment:
CHANNELS: "-c cdat/label/nightly -c conda-forge -c cdat"
PKGS: cdms2 cdat_info udunits2 testsrunner matplotlib numpy=1.14 genutil vtk-cdat cdutil vcs "proj4<5" mesalib
PKGS: cdms2 cdat_info udunits2 testsrunner matplotlib numpy=1.14 genutil 'vtk-cdat>8.1' cdutil vcs "proj4<5" mesalib
command: |
export PATH=$WORKDIR/miniconda/bin:$PATH
conda config --set always_yes yes --set changeps1 no
Expand Down
24 changes: 19 additions & 5 deletions DV3D/ButtonBarWidget.py
Expand Up @@ -137,7 +137,7 @@ def addObserver(self, observer, **args ):
event = args.get( 'event', 'StateChangedEvent' )
self.buttonWidget.AddObserver( event, observer )

def setToggleProps(self, state = None ):
def setToggleProps(self):
if self.toggle:
prop = self.buttonRepresentation.GetProperty()
opacity = 0.4 if ( self.getState() == 0 ) else 1.0
Expand Down Expand Up @@ -209,14 +209,22 @@ def Off(self):
# print " Button %s off " % self.id

def activate(self):
'''
Activates the button and shows it.
'''
if self.visible:
self.active = True
self.buttonWidget.On()
self.buttonRepresentation.SetVisibility(1)
# print " Button %s on " % self.id

def deactivate(self):
'''
Deativates the button and hides it.
'''
self.active = False
self.Off()
self.buttonRepresentation.SetVisibility(0)

class ButtonBarHandler:

Expand Down Expand Up @@ -414,7 +422,10 @@ def computeBounds( self, pos, size ):

def show( self, **args ):
self.visible = True
for button in self.buttons: button.On()
for button in self.buttons:
button.On()
if button.active:
button.buttonRepresentation.SetVisibility(1)

def setVisibility( self, isVisible ):
for button in self.buttons:
Expand All @@ -435,6 +446,7 @@ def hide(self):
self.visible = False
for button in self.buttons:
button.Off()
button.buttonRepresentation.SetVisibility(0)

def toggleVisibility(self):
if self.visible:
Expand Down Expand Up @@ -482,11 +494,13 @@ def changeButtonActivation(self, button_name, activate, state = None ):
if button:
if activate: button.activate()
else: button.deactivate()
if state != None:
button.setToggleState( state )
if state != None:
button.setToggleState( state )
else:
print("No button {}".format(button_name))

def addButton( self, bspec, **args ):
if hasattr(bspec, "__iter__"):
if hasattr(bspec, "__iter__") and type(bspec) is not str:
bnames = bspec
else: bnames = [ bspec ]
toggle = args.get( 'toggle', False )
Expand Down
6 changes: 5 additions & 1 deletion DV3D/DV3DPlot.py
Expand Up @@ -610,7 +610,7 @@ def updateAnimationControlBar(self, state, config_function ):
bbar.hide()

def processAnimationCommand( self, args, config_function = None ):
# print " processAnimationCommand, args = ", str( args ), ", animating = ", str(self.animating)
# print(" processAnimationCommand, args = ", str( args ), ", animating = ", str(self.animating))
runSpeed = config_function.value
if args and args[0] == "StartConfig":
pass
Expand Down Expand Up @@ -1156,6 +1156,10 @@ def createRenderWindow( self, **args ):
self.renderer = vtk.vtkRenderer()
renWin.AddRenderer( self.renderer )

self.renderer.RemoveAllLights()
kit = vtk.vtkLightKit()
kit.AddLightsToRenderer(self.renderer)

self.interactorStyle = vtk.vtkInteractorStyleTrackballCamera( )
self.renderWindowInteractor.SetInteractorStyle( self.interactorStyle )
self.interactorStyle.KeyPressActivationOff( )
Expand Down
2 changes: 1 addition & 1 deletion DV3D/ImagePlaneAxisAlignedWidget.py
@@ -1,4 +1,3 @@

from __future__ import print_function, division
import vtk, sys, gc

Expand Down Expand Up @@ -606,6 +605,7 @@ def CreateDefaultProperties(self):

if ( not self.TexturePlaneProperty ):
self.TexturePlaneProperty = vtk.vtkProperty()
self.TexturePlaneProperty.SetDiffuse(0)
self.TexturePlaneProperty.SetAmbient(1)
self.TexturePlaneProperty.SetInterpolationToFlat()

Expand Down
6 changes: 2 additions & 4 deletions DV3D/ImagePlaneWidget.py
@@ -1,4 +1,3 @@

from __future__ import print_function, division
import vtk, sys, gc

Expand Down Expand Up @@ -624,6 +623,7 @@ def CreateDefaultProperties(self):

if ( not self.TexturePlaneProperty ):
self.TexturePlaneProperty = vtk.vtkProperty()
self.TexturePlaneProperty.SetDiffuse(0)
self.TexturePlaneProperty.SetAmbient(1)
self.TexturePlaneProperty.SetInterpolationToFlat()

Expand Down Expand Up @@ -1408,7 +1408,7 @@ def GenerateTexturePlane(self):
else: texturePlaneMapper.SetInputData( self.PlaneSource.GetOutput() )

self.Texture.SetQualityTo32Bit()
self.Texture.MapColorScalarsThroughLookupTableOff()
self.Texture.SetColorModeToDefault()
self.Texture.SetInterpolate(self.TextureInterpolate)
self.Texture.RepeatOff()
self.Texture.SetLookupTable(self.LookupTable)
Expand Down Expand Up @@ -1747,7 +1747,6 @@ def initGlyphMapper(self):
self.glyphMapper.OrientOn ()
# self.glyphMapper.ClampingOn()
self.glyphMapper.SourceIndexingOff()
self.glyphMapper.NestedDisplayListsOff()
self.glyphMapper.UseSelectionIdsOff()
self.glyphMapper.SetInputConnection( self.cutter.GetOutputPort() )
self.glyphMapper.SetLookupTable( self.LookupTable )
Expand Down Expand Up @@ -2046,4 +2045,3 @@ def processLICDensityCommand( self, args, config_function = None ):
def updateScaling( self, render = False ):
if render:
self.Interactor.Render()

3 changes: 2 additions & 1 deletion DV3D/ListWidget.py
Expand Up @@ -70,12 +70,13 @@ def show(self):
self.visible = True
for button in list(self.buttons.keys()):
button.On()
# button.Render()
button.GetRepresentation().SetVisibility(1)

def hide(self):
self.visible = False
for button in list(self.buttons.keys()):
button.Off()
button.GetRepresentation().SetVisibility(0)

def toggleVisibility( self, **args ):
state = args.get( 'state', None )
Expand Down
22 changes: 12 additions & 10 deletions DV3D/RectilinearGridPlot.py
Expand Up @@ -501,6 +501,8 @@ def clipOff(self):
self.clipper.Off()

def toggleClipping( self, enableClipping ):
if (self.volume == None):
self.buildVolumePipeline()
self.clipping_enabled = enableClipping
if self.clipping_enabled:
self.volumeMapper.CroppingOn()
Expand All @@ -512,15 +514,16 @@ def getVolRenderCfg( self ):
return [ ';'.join( self.volRenderConfig ) ]

def setVolRenderCfg( self, config_str, doRender = True ):
print("setVolRenderCfg")
if config_str:
self.volRenderConfig = getItem( config_str ).strip('[]').split(';')
renderMode = vtk.vtkSmartVolumeMapper.TextureRenderMode
if self.volRenderConfig[0] == 'RayCastAndTexture':
renderMode = vtk.vtkSmartVolumeMapper.RayCastAndTextureRenderMode
elif self.volRenderConfig[0] == 'RayCast':
renderMode = vtk.vtkSmartVolumeMapper.DefaultRenderMode
if self.volRenderConfig[0] == 'RayCast':
renderMode = vtk.vtkSmartVolumeMapper.RayCastRenderMode
elif self.volRenderConfig[0] == 'Texture3D':
renderMode = vtk.vtkSmartVolumeMapper.TextureRenderMode
elif self.volRenderConfig[0] == 'GPU':
renderMode = vtk.vtkSmartVolumeMapper.GPURenderMode
elif self.volRenderConfig[0] == 'OSPray':
renderMode = vtk.vtkSmartVolumeMapper.OSPRayRenderMode
self.volumeMapper.SetRequestedRenderMode( renderMode )
self.volumeProperty.SetShade( self.volRenderConfig[1] == str(True) )
if doRender: self.render()
Expand Down Expand Up @@ -1018,7 +1021,7 @@ def buildPipeline(self):
else:
self.planeWidgetZ = ScalarSliceWidget( self, picker, 0 )
self.planeWidgetZ.SetRenderer( self.renderer )
self.planeWidgetZ.SetRenderer( self.renderer )

# self.observerTargets.add( self.planeWidgetZ )
prop3 = self.planeWidgetZ.GetPlaneProperty()
prop3.SetColor(0, 0, 1)
Expand Down Expand Up @@ -1253,7 +1256,8 @@ def rebuildColorTransferFunction( self, constituent, imageRange ):
# lut_index = (nc-i-1) if self.invert else i
color = lut.GetTableValue( i )
self.colorTransferFunction.AddRGBPoint( data_value, color[0], color[1], color[2] )
# if i % 20 == 0: print " --- ctf[%d] -- %.2e: ( %.2f %.2f %.2f ) " % ( i, data_value, color[0], color[1], color[2] )
# if i % 20 == 0:
# print(" --- ctf[%d] -- %.2e: ( %.2f %.2f %.2f ) " % ( i, data_value, color[0], color[1], color[2]))


# def PrintStats(self):
Expand Down Expand Up @@ -1847,5 +1851,3 @@ def updateColorScale( self, caller, event ):
wsize = self.renderer.GetSize()
range = self.ColorLeveler.windowLevel( x, y, wsize )
return range


5 changes: 3 additions & 2 deletions tests/TestManager.py
Expand Up @@ -42,7 +42,7 @@ def writeCMakeLists(self):
test.writeCMakeDef( f )
f.close()

def runTest(self, testName, interactive=False, baselinedir=None ):
def runTest(self, testName, interactive='False', baselinedir=None ):
test = TestManager.DefinedTests.get( testName, None )
if test is None:
print("Can't find test named '%s'" % testName, file=sys.stderr)
Expand All @@ -54,7 +54,8 @@ def runTest(self, testName, interactive=False, baselinedir=None ):
'.'.join( [ test.name, 'png' ] ) )
print("Running test %s, interactive= %s, baselinedir= %s" % ( testName,\
str(interactive), str(baselinedir) ))
img = test.test( ast.literal_eval(interactive) )
r = ast.literal_eval(interactive)
img = test.test(r)
print("TEST RETURNED IMG:",img[0], img[1])


Expand Down
2 changes: 1 addition & 1 deletion tests/dv3d_execute_test.py
@@ -1,6 +1,6 @@
import sys
from TestDefinitions import testManager
test_name = sys.argv[1].strip("' \"")
interactive = sys.argv[2].strip("' \"") if ( len( sys.argv ) > 2 ) else False
interactive = sys.argv[2].strip("' \"") if ( len( sys.argv ) > 2 ) else 'False'
baseline_dir = sys.argv[3].strip("' \"") if ( len( sys.argv ) > 3 ) else None
testManager.runTest( test_name, interactive, baseline_dir )

0 comments on commit 215c720

Please sign in to comment.