<s> from vtk import vtkPropAssembly , vtkImplicitPlaneRepresentation , vtkPolyData , vtkPoints , vtkCellArray , vtkImplicitPlaneWidget2 , vtkTubeFilter , vtkPolyDataMapper , vtkActor , vtkPlane <EOL> class SlicingPlanesWidget ( vtkPropAssembly ) : <EOL> def SetPickable ( self , pickable ) : <EOL> props = self . GetParts ( ) <EOL> props . InitTraversal ( ) ; <EOL> for i in range ( props . GetNumberOfItems ( ) ) : <EOL> props . GetNextProp ( ) . SetPickable ( pickable ) <EOL> def __init__ ( self , dataShape ) : <EOL> self . dataShape = dataShape <EOL> self . planes = [ ] <EOL> self . coordinate = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> self . lastChangedAxis = - <NUM_LIT:1> <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> p = vtkImplicitPlaneRepresentation ( ) <EOL> p . SetPlaceFactor ( <NUM_LIT:1.0> ) <EOL> p . OutsideBoundsOn ( ) <EOL> p . ScaleEnabledOff ( ) <EOL> p . SetOrigin ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> p . PlaceWidget ( [ <NUM_LIT:0.1> , dataShape [ <NUM_LIT:0> ] , <NUM_LIT:0.1> , dataShape [ <NUM_LIT:1> ] , <NUM_LIT:0.1> , dataShape [ <NUM_LIT:2> ] ] ) <EOL> if i == <NUM_LIT:0> : <EOL> p . SetNormal ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> p . GetSelectedPlaneProperty ( ) . SetColor ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> p . GetEdgesProperty ( ) . SetColor ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> elif i == <NUM_LIT:1> : <EOL> p . SetNormal ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> p . GetSelectedPlaneProperty ( ) . SetColor ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> p . GetEdgesProperty ( ) . SetColor ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> else : <EOL> p . SetNormal ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> p . GetSelectedPlaneProperty ( ) . SetColor ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> p . GetEdgesProperty ( ) . SetColor ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> p . GetPlaneProperty ( ) . SetOpacity ( <NUM_LIT> ) <EOL> p . GetOutlineProperty ( ) . SetColor ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> p . GetOutlineProperty ( ) . SetOpacity ( <NUM_LIT:0.0> ) <EOL> p . GetSelectedNormalProperty ( ) . SetOpacity ( <NUM_LIT:0.0> ) <EOL> p . GetNormalProperty ( ) . SetOpacity ( <NUM_LIT:0.0> ) <EOL> p . OutlineTranslationOff ( ) <EOL> p . TubingOff ( ) <EOL> self . cross = vtkPolyData ( ) <EOL> points = vtkPoints ( ) <EOL> polys = vtkCellArray ( ) <EOL> points . SetNumberOfPoints ( <NUM_LIT:6> ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> polys . InsertNextCell ( <NUM_LIT:2> ) <EOL> polys . InsertCellPoint ( <NUM_LIT:2> * i ) ; polys . InsertCellPoint ( <NUM_LIT:2> * i + <NUM_LIT:1> ) <EOL> self . cross . SetPoints ( points ) <EOL> self . cross . SetLines ( polys ) <EOL> pw = vtkImplicitPlaneWidget2 ( ) <EOL> pw . SetRepresentation ( p ) <EOL> pw . AddObserver ( "<STR_LIT>" , self . __PlanePositionCallback ) <EOL> self . planes . append ( pw ) <EOL> tubes = vtkTubeFilter ( ) <EOL> tubes . SetNumberOfSides ( <NUM_LIT:16> ) <EOL> tubes . SetInput ( self . cross ) <EOL> tubes . SetRadius ( <NUM_LIT:1.0> ) <EOL> crossMapper = vtkPolyDataMapper ( ) <EOL> crossMapper . SetInput ( self . cross ) <EOL> crossActor = vtkActor ( ) <EOL> crossActor . SetMapper ( crossMapper ) <EOL> crossActor . GetProperty ( ) . SetColor ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . AddPart ( crossActor ) <EOL> self . InvokeEvent ( "<STR_LIT>" ) <EOL> def Plane ( self , axis ) : <EOL> p = vtkPlane ( ) <EOL> self . planes [ axis ] . GetRepresentation ( ) . GetPlane ( p ) <EOL> return p <EOL> def PlaneX ( self ) : <EOL> return self . Plane ( <NUM_LIT:0> ) <EOL> def PlaneY ( self ) : <EOL> return self . Plane ( <NUM_LIT:1> ) <EOL> def PlaneZ ( self ) : <EOL> return self . Plane ( <NUM_LIT:2> ) <EOL> def ShowPlaneWidget ( self , axis , show ) : <EOL> self . planes [ axis ] . SetEnabled ( show ) <EOL> def TogglePlaneWidget ( self , axis ) : <EOL> show = not self . planes [ axis ] . GetEnabled ( ) <EOL> self . planes [ axis ] . SetEnabled ( show ) <EOL> def SetInteractor ( self , interactor ) : <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> self . planes [ i ] . SetInteractor ( interactor ) <EOL> self . planes [ i ] . On ( ) <EOL> def GetCoordinate ( self ) : <EOL> return self . coordinate <EOL> def SetCoordinate ( self , coor ) : <EOL> self . coordinate = coor <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> self . planes [ i ] . GetRepresentation ( ) . SetOrigin ( coor [ <NUM_LIT:0> ] , coor [ <NUM_LIT:1> ] , coor [ <NUM_LIT:2> ] ) <EOL> self . __UpdateCross ( ) <EOL> def __UpdateCross ( self ) : <EOL> p = self . cross . GetPoints ( ) <EOL> x , y , z = self . coordinate [ <NUM_LIT:0> ] , self . coordinate [ <NUM_LIT:1> ] , self . coordinate [ <NUM_LIT:2> ] <EOL> X , Y , Z = self . dataShape [ <NUM_LIT:0> ] , self . dataShape [ <NUM_LIT:1> ] , self . dataShape [ <NUM_LIT:2> ] <EOL> p . SetPoint ( <NUM_LIT:0> , <NUM_LIT:0> , y , z ) <EOL> p . SetPoint ( <NUM_LIT:1> , X , y , z ) <EOL> p . SetPoint ( <NUM_LIT:2> , x , <NUM_LIT:0> , z ) <EOL> p . SetPoint ( <NUM_LIT:3> , x , Y , z ) <EOL> p . SetPoint ( <NUM_LIT:4> , x , y , <NUM_LIT:0> ) <EOL> p . SetPoint ( <NUM_LIT:5> , x , y , Z ) <EOL> self . cross . Modified ( ) <EOL> def __PlanePositionCallback ( self , obj , event ) : <EOL> newCoordinate = [ int ( self . planes [ i ] . GetRepresentation ( ) . GetOrigin ( ) [ i ] ) for i in range ( <NUM_LIT:3> ) ] <EOL> axis = - <NUM_LIT:1> <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> if newCoordinate [ i ] != self . coordinate [ i ] : axis = i ; break <EOL> if axis < <NUM_LIT:0> : return <EOL> if newCoordinate [ axis ] >= self . dataShape [ axis ] : newCoordinate [ axis ] = self . dataShape [ axis ] - <NUM_LIT:1> <EOL> self . __UpdateCross ( ) <EOL> self . lastChangedAxis = axis <EOL> self . coordinate = newCoordinate <EOL> self . InvokeEvent ( "<STR_LIT>" ) </s>
