def testUseCallDataType(self): """Test adding an observer associated with a callback expecting a CallData """ cb = callback() cb.CallDataType = svtk.SVTK_STRING lt = svtk.svtkLookupTable() lt.AddObserver(svtk.svtkCommand.ErrorEvent, cb) lt.SetTableRange(2, 1) self.assertEqual(cb.caller, lt) self.assertEqual(cb.event, "ErrorEvent") self.assertTrue(cb.calldata.startswith("ERROR: In"))
def testUseCallDataTypeWithDecorator(self): """Test adding an observer associated with a callback expecting a CallData """ self.onErrorCalldata = '' @svtk.calldata_type(svtk.SVTK_STRING) def onError(caller, event, calldata): self.onErrorCalldata = calldata lt = svtk.svtkLookupTable() lt.AddObserver(svtk.svtkCommand.ErrorEvent, onError) lt.SetTableRange(2, 1) self.assertTrue(self.onErrorCalldata.startswith("ERROR: In"))
def testUseCallDataTypeWithDecoratorAsString0(self): """Test adding an observer associated with a callback expecting a CallData. This test ensures backward compatibility checking the CallDataType can be set to the string 'string0'. """ self.onErrorCalldata = '' @svtk.calldata_type('string0') def onError(caller, event, calldata): self.onErrorCalldata = calldata lt = svtk.svtkLookupTable() lt.AddObserver(svtk.svtkCommand.ErrorEvent, onError) lt.SetTableRange(2, 1) self.assertTrue(self.onErrorCalldata.startswith("ERROR: In"))
geometry.SetInputData(reflection) print('With Geometry Filter (HTG to NS)') # Shrink Filter if True: print('With Shrink Filter (NS)') # En 3D, le shrink ne doit pas se faire sur la geometrie car elle ne represente que la peau shrink = svtk.svtkShrinkFilter() shrink.SetInputConnection(geometry.GetOutputPort()) shrink.SetShrinkFactor(.8) else: print('No Shrink Filter (NS)') shrink = geometry # LookupTable lut = svtk.svtkLookupTable() lut.SetHueRange(0.66, 0) lut.Build() # Mappers mapper = svtk.svtkDataSetMapper() mapper.SetInputConnection(shrink.GetOutputPort()) shrink.Update() dataRange = shrink.GetOutput().GetCellData().GetArray('scalar').GetRange() print('DataRange (after shrink): ', dataRange) mapper.SetLookupTable(lut) mapper.SetColorModeToMapScalars() mapper.SetScalarModeToUseCellFieldData() mapper.SelectColorArray('scalar')
#!/usr/bin/env python import svtk from svtk.util.misc import svtkGetDataRoot SVTK_DATA_ROOT = svtkGetDataRoot() # warp an image with a thin plate spline # first, create an image to warp imageGrid = svtk.svtkImageGridSource() imageGrid.SetGridSpacing(16, 16, 0) imageGrid.SetGridOrigin(0, 0, 0) imageGrid.SetDataExtent(0, 255, 0, 255, 0, 0) imageGrid.SetDataScalarTypeToUnsignedChar() table = svtk.svtkLookupTable() table.SetTableRange(0, 1) table.SetValueRange(1.0, 0.0) table.SetSaturationRange(0.0, 0.0) table.SetHueRange(0.0, 0.0) table.SetAlphaRange(0.0, 1.0) table.Build() alpha = svtk.svtkImageMapToColors() alpha.SetInputConnection(imageGrid.GetOutputPort()) alpha.SetLookupTable(table) reader1 = svtk.svtkBMPReader() reader1.SetFileName("" + str(SVTK_DATA_ROOT) + "/Data/masonry.bmp") blend = svtk.svtkImageBlend() blend.AddInputConnection(0, reader1.GetOutputPort()) blend.AddInputConnection(0, alpha.GetOutputPort()) # next, create a ThinPlateSpline transform p1 = svtk.svtkPoints() p1.SetNumberOfPoints(8) p1.SetPoint(0, 0, 0, 0)