def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkExtractTensorComponents(), 'Processing.', ('vtkDataSet',), ('vtkDataSet',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def initialize (self): debug ("In ExtractTensorComponents::initialize ()") self.fil = vtk.vtkExtractTensorComponents () self.fil.SetInput (self.prev_fil.GetOutput ()) self.comp_var = Tkinter.IntVar () self.comp_var.set (9) # 0..8 tensor components, 9 effective stress, 10 determinant self.fil.ScalarIsEffectiveStress () self.fil.PassTensorsToOutputOn () self.fil.ExtractScalarsOn () self.fil.Update ()
pts.SetPoint(i, math.Random(-1, 1), math.Random(-1, 1), 0.0) conn = [i] verts.InsertNextCell(1, conn) scalars.SetTuple1(i, math.Random(2, 5)) tensors.SetTuple6(i, math.Random(1, 3), math.Random(-1, 1), math.Random(-1, 1), math.Random(1, 3), math.Random(-1, 1), 1) pdata = vtk.vtkPolyData() pdata.SetPoints(pts) pdata.SetVerts(verts) pdata.GetPointData().SetScalars(scalars) pdata.GetPointData().SetTensors(tensors) # Extract some tensor information textract = vtk.vtkExtractTensorComponents() textract.SetInputData(pdata) textract.ExtractScalarsOn() textract.ScalarIsDeterminant() textract.PassTensorsToOutputOn() textract.Update() # Now smooth/pack the points in a variety of ways. # We'll glyph with a transformed sphere sph = vtk.vtkSphereSource() sph.SetRadius(0.5) sph.SetCenter(0.0, 0.0, 0.0) sph.SetThetaResolution(16) sph.SetPhiResolution(8) sph.Update()
VTK_DATA_ROOT = vtkGetDataRoot() # create tensor ellipsoids # Create the RenderWindow, Renderer and interactive renderer # ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ptLoad = vtk.vtkPointLoad() ptLoad.SetLoadValue(100.0) ptLoad.SetSampleDimensions(30,30,30) ptLoad.ComputeEffectiveStressOn() ptLoad.SetModelBounds(-10,10,-10,10,-10,10) extractTensor = vtk.vtkExtractTensorComponents() extractTensor.SetInputConnection(ptLoad.GetOutputPort()) extractTensor.ScalarIsEffectiveStress() extractTensor.ScalarIsComponent() extractTensor.ExtractScalarsOn() extractTensor.ExtractVectorsOn() extractTensor.ExtractNormalsOff() extractTensor.ExtractTCoordsOn() contour = vtk.vtkContourFilter() contour.SetInputConnection(extractTensor.GetOutputPort()) contour.SetValue(0,0) probe = vtk.vtkProbeFilter() probe.SetInputConnection(contour.GetOutputPort()) probe.SetSourceConnection(ptLoad.GetOutputPort()) su = vtk.vtkLoopSubdivisionFilter() su.SetInputConnection(probe.GetOutputPort())
def __init__(self,dti): self.print_counter=0 ren = vtk.vtkRenderer() self.dti_reader = vtk.vtkStructuredPointsReader() self.dti_reader.SetFileName(dti) """ self.geo_Mapper=vtk.vtkPolyDataMapper() self.geo_Mapper.SetInputConnection(self.dti_reader.GetOutputPort()) """ tensor_extractor = vtk.vtkExtractTensorComponents() tensor_extractor.SetInputConnection(self.dti_reader.GetOutputPort()) tensor_extractor.ExtractScalarsOn() tensor_extractor.Update() self.dti_reader.GetOutput().GetPointData().SetScalars(tensor_extractor.GetOutput().GetPointData().GetScalars()) self.dti_reader.Update() self.arrowColor = vtk.vtkColorTransferFunction() self.update_look_up_table() #------------NEW CODE BEGINS HERE---------- [xposc, yposc, zposc] = self.dti_reader.GetOutput().GetCenter() for k in range(20, 30,2): for i in range(10, 20): ren.AddActor(self.create_hyper_stream_line(xposc+i, yposc+k, zposc)) #------------NEW CODE ENDS HERE------------ #Add renderer to renderwindow and render self.renWin = vtk.vtkRenderWindow() self.renWin.AddRenderer(ren) self.renWin.SetSize(1920, 1080) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(self.renWin) iren.AddObserver('RightButtonPressEvent', self.capture_image, 1.0) # Scalar Bar actor scalar_bar = vtk.vtkScalarBarActor() scalar_bar.SetOrientationToHorizontal() scalar_bar.SetLookupTable(self.arrowColor) scalar_bar.SetTitle("Color map") scalar_bar.SetLabelFormat("%5.5f") scalar_bar.SetMaximumHeightInPixels(300) scalar_bar.SetMaximumWidthInPixels(100) # Scalar Bar Widget scalar_bar_widget = vtk.vtkScalarBarWidget() scalar_bar_widget.SetInteractor(iren) scalar_bar_widget.SetScalarBarActor(scalar_bar) scalar_bar_widget.On() ren.SetBackground(0,0,0) self.renWin.Render() iren.Start()
# Read in datafile specified in program call, open as .vtk. filename = sys.argv[1] #Tensor Field reader = vtk.vtkDataSetReader() reader.SetFileName(HMWK_DATA_ROOT + "/" + filename) reader.Update() data_range = reader.GetOutput().GetScalarRange() [centerx, centery, centerz] = reader.GetOutput().GetCenter() length = reader.GetOutput().GetLength() #[minVelocity,maxVelocity] =reader.GetOutput().GetPointData().GetVectors().GetRange() maxTime = 1000 #35.0*length/maxVelocity #making a float array by extracting the determinant dets = vtk.vtkExtractTensorComponents() dets.SetInputConnection(reader.GetOutputPort()) dets.SetScalarModeToEffectiveStress() dets.ExtractScalarsOn() dets.ExtractVectorsOff() dets.Update() #Dummy Array for Scalars dummyarray = dets.GetOutput().GetPointData().GetScalars() mindet, maxdet = dets.GetOutput().GetScalarRange() pd = reader.GetOutput() pd.GetPointData().SetScalars(dummyarray) plane2 = vtk.vtkPlane() plane2.SetOrigin([centerx, centery, 80]) plane2.SetNormal(0, 0, 1)