def updateDisplayProperty(self, options): proxy = helper.idToProxy(options['proxy_id']) rep = simple.GetDisplayProperties(proxy) helper.updateProxyProperties(rep, options) # Try to bind the proper lookup table if need be if options.has_key('ColorArrayName') and len( options['ColorArrayName']) > 0: name = options['ColorArrayName'] type = options['ColorAttributeType'] nbComp = 1 if type == 'POINT_DATA': data = rep.GetRepresentedDataInformation( ).GetPointDataInformation() for i in range(data.GetNumberOfArrays()): array = data.GetArrayInformation(i) if array.GetName() == name: nbComp = array.GetNumberOfComponents() elif type == 'CELL_DATA': data = rep.GetRepresentedDataInformation( ).GetCellDataInformation() for i in range(data.GetNumberOfArrays()): array = data.GetArrayInformation(i) if array.GetName() == name: nbComp = array.GetNumberOfComponents() lut = self.lutManager.getLookupTable(name, nbComp) rep.LookupTable = lut simple.Render()
def loadData(self): global dataPath mainpath = os.path.join(dataPath, "main") if os.path.isdir(mainpath): files = os.listdir(mainpath) for file in files: fullpath = os.path.join(mainpath, file) if os.path.isfile(fullpath): self.srcObj = simple.OpenDataFile(fullpath) simple.SetActiveSource(self.srcObj) self.rep = simple.GetDisplayProperties() simple.Hide() print 'Loaded %s into scene' % fullpath else: print 'Error: ' + mainpath + ' does not exist\n' raise Exception("The main directory does not exist") surfacespath = os.path.join(dataPath, "surfaces") files = os.listdir(surfacespath) for file in files: fullpath = os.path.join(surfacespath, file) if os.path.isfile(fullpath): self._loadSurfaceWithProperties(fullpath) simple.SetActiveSource(self.srcObj) simple.ResetCamera() simple.Render()
def getProxyAsPipelineNode(id, lutManager=None): """ Create a representation for that proxy so it can be used within a pipeline browser. """ pxm = servermanager.ProxyManager() proxy = idToProxy(id) rep = simple.GetDisplayProperties(proxy) nbActiveComp = 1 pointData = [] searchArray = ('POINT_DATA' == rep.ColorAttributeType) and (len(rep.ColorArrayName) > 0) for array in proxy.GetPointDataInformation(): nbComponents = array.GetNumberOfComponents() if searchArray and array.Name == rep.ColorArrayName: nbActiveComp = nbComponents rangeOn = (nbComponents == 3 if -1 else 0) info = { \ 'lutId': array.Name + '_' + str(nbComponents), \ 'name': array.Name, \ 'size': nbComponents, \ 'range': array.GetRange(rangeOn) } pointData.append(info) cellData = [] searchArray = ('CELL_DATA' == rep.ColorAttributeType) and (len(rep.ColorArrayName) > 0) for array in proxy.GetCellDataInformation(): nbComponents = array.GetNumberOfComponents() if searchArray and array.Name == rep.ColorArrayName: nbActiveComp = nbComponents rangeOn = (nbComponents == 3 if -1 else 0) info = { \ 'lutId': array.Name + '_' + str(nbComponents), \ 'name': array.Name, \ 'size': nbComponents, \ 'range': array.GetRange(rangeOn) } cellData.append(info) state = getProxyAsState(proxy.GetGlobalID()) showScalarbar = 0 if lutManager and (len(rep.ColorArrayName) > 0): showScalarbar = lutManager.isScalarBarVisible(rep.ColorArrayName + '_' + str(nbActiveComp)) return { 'proxy_id' : proxy.GetGlobalID(), \ 'name' : pxm.GetProxyName("sources", proxy), \ 'pointData' : pointData, \ 'cellData' : cellData, \ 'activeData': rep.ColorAttributeType + ':' + rep.ColorArrayName, \ 'diffuseColor' : str(rep.DiffuseColor), \ 'showScalarBar' : showScalarbar, \ 'representation': rep.Representation, \ 'state' : state, \ 'children' : [] }
def setupCalculator(source, arrayName, color, fctString, renderView): calculator = smp.Calculator(Input=source) smp.RenameSource(getCalculatorName(arrayName), calculator) calculator.Function = '' calculator.ResultArrayName = arrayName calculator.Function = fctString calculatorDisplay = smp.GetDisplayProperties(calculator, view=renderView) calculatorDisplay.SetRepresentationType('3D Glyphs') calculatorDisplay.DiffuseColor = color calculatorDisplay.Orient = 1 calculatorDisplay.SelectOrientationVectors = 'Orientation(AxisAngle)' calculatorDisplay.SelectOrientationVectors = arrayName
def simpleColorBy(rep=None, value=None): """Set scalar color. This will automatically setup the color maps and others necessary state for the representations. 'rep' must be the display properties proxy i.e. the value returned by GetDisplayProperties() function. If none is provided the display properties for the active source will be used, if possible.""" rep = rep if rep else simple.GetDisplayProperties() if not rep: raise ValueError("No display properties can be determined.") association = rep.ColorArrayName.GetAssociation() arrayname = rep.ColorArrayName.GetArrayName() component = None if value == None: rep.SetScalarColoring( None, servermanager.GetAssociationFromString(association)) return if not isinstance(value, tuple) and not isinstance(value, list): value = (value, ) if len(value) == 1: arrayname = value[0] elif len(value) >= 2: association = value[0] arrayname = value[1] if len(value) == 3: # component name provided componentName = value[2] if componentName == "Magnitude": component = -1 else: if association == "POINTS": array = rep.Input.PointData.GetArray(arrayname) if association == "CELLS": array = rep.Input.CellData.GetArray(arrayname) if array: # looking for corresponding component name for i in range(0, array.GetNumberOfComponents()): if componentName == array.GetComponentName(i): component = i break # none have been found, try to use the name as an int if i == array.GetNumberOfComponents() - 1: try: component = int(componentName) except ValueError: pass if component is None: rep.SetScalarColoring( arrayname, servermanager.GetAssociationFromString(association)) else: rep.SetScalarColoring( arrayname, servermanager.GetAssociationFromString(association), component)
def scaleAxis(axis, scale): """Use to scale an axis visually""" import paraview.simple as pvs sc = [1, 1, 1] # Default Scale sc[axis] = scale for f in pvs.GetSources().values(): # get active view rv = pvs.GetActiveViewOrCreate('RenderView') # get display properties disp = pvs.GetDisplayProperties(f, view=rv) # Set the scale for the data axis disp.Scale = sc disp.DataAxesGrid.Scale = sc disp.PolarAxes.Scale = sc # Update the view pvs.RenderAllViews() pvs.ResetCamera() return None
def animate(fn): casefoam = pv.OpenFOAMReader(FileName=fn) pv.Show(casefoam) dp = pv.GetDisplayProperties(casefoam) dp.SetPropertyWithName('ColorArrayName', ['POINTS', 'U']) view = pv.GetActiveView() reader = pv.GetActiveSource() tsteps = reader.TimestepValues annTime = pv.AnnotateTimeFilter(reader) pv.Show(annTime) pv.Render() while True: try: for t in tsteps: view.ViewTime = t pv.Render() except KeyboardInterrupt: sys.exit(0)
def updateEventCb(self, obj, event): name = self._getSourceToExtractName(obj) if not self.source: self.source = simple.FindSource(name) simple.SetActiveSource(self.source) if self.source and not self.rep: self.outline = simple.Outline(self.source) self.rep = simple.Show(self.source) self.outline.UpdatePipeline() self.outlineRep = simple.Show(self.outline) # TODO: this is for the demo # TODO: what would be the best way to change sources and representations from the client ? # create a protocol for liveInsituLink.GetInsituProxyManager() ? # or setActiveSource endpoint ? # or is there a better way ? info = self.source.GetPointDataInformation() if info.GetNumberOfArrays() > 0: arrName = info.GetArray(0).Name self.rep.ColorArrayName = ['POINTS', arrName] simple.ColorBy(self.rep, arrName) # Point gaussian props = simple.GetDisplayProperties(self.source) props.SetRepresentationType('Point Gaussian') props.GaussianRadius = 0.01
# Make sure the test driver know that process has properly started print "Process started" errors = 0 #-------------------- Start testing -------------------------- print "Start TestPython2DRendering testing" # Create a 3D renderer view = simple.GetRenderView() view.Background = [0, 0, 0] view.CenterAxesVisibility = 0 legend = simple.Text(Text='Text annotation of 3D view') displayProperties = simple.GetDisplayProperties(legend) displayProperties.Bold = 0 displayProperties.FontFamily = 'Arial' displayProperties.FontSize = 9 displayProperties.Color = [1.0, 1.0, 1.0] simple.Show(legend) # Create preset lookup tables lutCR = simple.CreateLookupTable( ColorSpace='RGB', \ NumberOfTableValues=256, \ RGBPoints=[0,0.6,0.88,1,100,1,0,0]) lutWGR = simple.CreateLookupTable( ColorSpace='RGB', \ NumberOfTableValues=256, \ RGBPoints=[0,0.9,0.9,0.9,\ 25,0.55,0.75,0.5,50,0.1,0.58,0.2,\ 75,0.54,0.31,0.17,100,0.78,0.2,0.15])
def getProxyAsPipelineNode(id, view=None): """ Create a representation for that proxy so it can be used within a pipeline browser. """ pxm = servermanager.ProxyManager() proxy = idToProxy(id) rep = simple.GetDisplayProperties(proxy) nbActiveComp = 1 pointData = [] searchArray = ('POINTS' == rep.ColorArrayName[0]) and (len( rep.ColorArrayName[1]) > 0) if servermanager.ActiveConnection.GetNumberOfDataPartitions() > 1: info = { \ 'lutId': 'vtkProcessId_1', \ 'name': 'vtkProcessId', \ 'size': 1, \ 'range': [0, servermanager.ActiveConnection.GetNumberOfDataPartitions()-1] } pointData.append(info) # FIXME seb # dataInfo = rep.GetRepresentedDataInformation() # pointData = dataInfo.GetPointDataInformation() # cellData = dataInfo.GetCellDataInformation() # for idx in pointData.GetNumberOfArrays(): # info = pointData.GetArrayInformation(idx) # nbComponents = info.GetNumberOfComponents() # if searchArray and array.Name == rep.ColorArrayName: # nbActiveComp = nbComponents # rangeOn = (nbComponents == 3 if -1 else 0) # info = { \ # 'lutId': info.GetName() + '_' + str(nbComponents), \ # 'name': info.GetName, \ # 'size': nbComponents, \ # 'range': info.GetRange(rangeOn) } # pointData.append(info) for array in proxy.GetPointDataInformation(): nbComponents = array.GetNumberOfComponents() if searchArray and array.Name == rep.ColorArrayName[1]: nbActiveComp = nbComponents rangeOn = (nbComponents == 1 if 0 else -1) info = { \ 'lutId': array.Name + '_' + str(nbComponents), \ 'name': array.Name, \ 'size': nbComponents, \ 'range': array.GetRange(rangeOn) } pointData.append(info) cellData = [] searchArray = ('CELLS' == rep.ColorArrayName[0]) and (len( rep.ColorArrayName[1]) > 0) for array in proxy.GetCellDataInformation(): nbComponents = array.GetNumberOfComponents() if searchArray and array.Name == rep.ColorArrayName[1]: nbActiveComp = nbComponents rangeOn = (nbComponents == 1 if 0 else -1) info = { \ 'lutId': array.Name + '_' + str(nbComponents), \ 'name': array.Name, \ 'size': nbComponents, \ 'range': array.GetRange(rangeOn) } cellData.append(info) state = getProxyAsState(proxy.GetGlobalID()) showScalarbar = 1 if view and vtkSMPVRepresentationProxy.IsScalarBarVisible( rep.SMProxy, view.SMProxy) else 0 repName = 'Hide' if rep.Visibility == 1: repName = rep.Representation return { 'proxy_id' : proxy.GetGlobalID(), \ 'name' : pxm.GetProxyName("sources", proxy), \ 'bounds' : proxy.GetDataInformation().GetBounds(), \ 'pointData' : pointData, \ 'cellData' : cellData, \ 'activeData': str(rep.ColorArrayName[0]) + ':' + str(rep.ColorArrayName[1]), \ 'diffuseColor' : str(rep.DiffuseColor), \ 'showScalarBar' : showScalarbar, \ 'representation': repName, \ 'state' : state, \ 'children' : [] }
if args.images: print "Images will be saved in ./images dir" os.system('mkdir images') files = glob.glob(args.source_dir + "/*.vtk") files = natural_sort(files) jump = args.step count = 0 files = files[::jump] #some_list[start:stop:step] reader = simple.OpenDataFile(files) simple.Show(reader) dp = simple.GetDisplayProperties(reader) dp.Representation = 'Surface' simple.GetActiveView().GetRenderWindow().SetSize(800, 800) dp.LookupTable = simple.MakeBlueToRedLT(-86.2, 40.0) dp.ColorArrayName = 'Scalars_' camera = simple.GetActiveCamera() camera.Elevation(args.elevation) camera.Azimuth(args.azimuth) simple.Render() #simple.AnimateReader(reader, filename=video_file) simple.SaveAnimation(video_file)
fig1 = pl.figure() pl.plot(x,y) pl.xlabel("$B_{mirror}$ (nT)") pl.ylabel("$I(B_{mirror})$") pl.title("Field Line Geometry Integral $I$ with respect to $B_{mirror}$ \n For Field line that passes through (-40, 0, 0)") fig1.savefig("IwrtBm.png") # Create a paraview render view so we can see visual progress. # pv._DisableFirstRenderCameraReset() rv128 = pv.CreateRenderView() rv128.InteractionMode = '2D' rv128.CameraPosition = [0, -30, 0] rv128.CameraViewUp = [0, 0, 1] rv128.CameraParallelScale = 10 rv128.ViewSize = [1280, 1024] dipoleDisplay = pv.GetDisplayProperties(dipole128, view=rv128) # pv.Hide(dipole128, view=rv128) # create a new 'Sphere' sphere1 = pv.Sphere() sphere1.Radius = 1.0 sphere1.ThetaResolution = 64 sphere1.PhiResolution = 64 pv.Show(sphere1, rv128) # get field line forward = pv.Show(fline.fieldLineObj_f,rv128) backward = pv.Show(fline.fieldLineObj_b,rv128) forward.DiffuseColor = [0.6666666666666666, 0.0, 0.0] backward.DiffuseColor = [0., 0., 0.66]
def getProxyAsPipelineNode(id, view=None): """ Create a representation for that proxy so it can be used within a pipeline browser. """ pxm = servermanager.ProxyManager() proxy = idToProxy(id) rep = simple.GetDisplayProperties(proxy) nbActiveComp = 1 pointData = [] searchArray = ("POINTS" == rep.ColorArrayName[0]) and (len( rep.ColorArrayName[1]) > 0) if servermanager.ActiveConnection.GetNumberOfDataPartitions() > 1: info = { "lutId": "vtkProcessId_1", "name": "vtkProcessId", "size": 1, "range": [ 0, servermanager.ActiveConnection.GetNumberOfDataPartitions() - 1, ], } pointData.append(info) # FIXME seb # dataInfo = rep.GetRepresentedDataInformation() # pointData = dataInfo.GetPointDataInformation() # cellData = dataInfo.GetCellDataInformation() # for idx in pointData.GetNumberOfArrays(): # info = pointData.GetArrayInformation(idx) # nbComponents = info.GetNumberOfComponents() # if searchArray and array.Name == rep.ColorArrayName: # nbActiveComp = nbComponents # rangeOn = (nbComponents == 3 if -1 else 0) # info = { \ # 'lutId': info.GetName() + '_' + str(nbComponents), \ # 'name': info.GetName, \ # 'size': nbComponents, \ # 'range': info.GetRange(rangeOn) } # pointData.append(info) for array in proxy.GetPointDataInformation(): nbComponents = array.GetNumberOfComponents() if searchArray and array.Name == rep.ColorArrayName[1]: nbActiveComp = nbComponents rangeOn = nbComponents == 1 if 0 else -1 info = { "lutId": array.Name + "_" + str(nbComponents), "name": array.Name, "size": nbComponents, "range": array.GetRange(rangeOn), } pointData.append(info) cellData = [] searchArray = ("CELLS" == rep.ColorArrayName[0]) and (len( rep.ColorArrayName[1]) > 0) for array in proxy.GetCellDataInformation(): nbComponents = array.GetNumberOfComponents() if searchArray and array.Name == rep.ColorArrayName[1]: nbActiveComp = nbComponents rangeOn = nbComponents == 1 if 0 else -1 info = { "lutId": array.Name + "_" + str(nbComponents), "name": array.Name, "size": nbComponents, "range": array.GetRange(rangeOn), } cellData.append(info) state = getProxyAsState(proxy.GetGlobalID()) showScalarbar = (1 if view and vtkSMPVRepresentationProxy.IsScalarBarVisible( rep.SMProxy, view.SMProxy) else 0) repName = "Hide" if rep.Visibility == 1: repName = rep.Representation return { "proxy_id": proxy.GetGlobalID(), "name": pxm.GetProxyName("sources", proxy), "bounds": proxy.GetDataInformation().GetBounds(), "pointData": pointData, "cellData": cellData, "activeData": str(rep.ColorArrayName[0]) + ":" + str(rep.ColorArrayName[1]), "diffuseColor": str(rep.DiffuseColor), "showScalarBar": showScalarbar, "representation": repName, "state": state, "children": [], }