def connect(self, options): """ Creates a connection to a remote pvserver. Expect an option argument which should override any of those default properties:: { 'host': 'localhost', 'port': 11111, 'rs_host': None, 'rs_port': 11111 } """ ds_host = "localhost" ds_port = 11111 rs_host = None rs_port = 11111 if options: if options.has_key("host"): ds_host = options["host"] if options.has_key("port"): ds_port = options["port"] if options.has_key("rs_host"): rs_host = options["rs_host"] if options.has_key("rs_port"): rs_host = options["rs_port"] simple.Connect(ds_host, ds_port, rs_host, rs_port)
def initialize(self): from paraview import simple from paraview.web import protocols as pv_protocols # Make sure ParaView is initialized if not simple.servermanager.ActiveConnection: simple.Connect() if not IPythonProtocol.producer: IPythonProtocol.producer = simple.DistributedTrivialProducer() IPythonProtocol.ActivateDataSet('iPython-demo') simple.Show(IPythonProtocol.producer) simple.Render() # Bring used components self.registerVtkWebProtocol(pv_protocols.ParaViewWebFileListing(IPythonProtocol.dataDir, "Home", IPythonProtocol.excludeRegex, IPythonProtocol.groupRegex)) self.registerVtkWebProtocol(pv_protocols.ParaViewWebPipelineManager(IPythonProtocol.dataDir, IPythonProtocol.fileToLoad)) self.registerVtkWebProtocol(pv_protocols.ParaViewWebMouseHandler()) self.registerVtkWebProtocol(pv_protocols.ParaViewWebViewPort()) self.registerVtkWebProtocol(pv_protocols.ParaViewWebViewPortImageDelivery()) self.registerVtkWebProtocol(pv_protocols.ParaViewWebViewPortGeometryDelivery()) self.registerVtkWebProtocol(pv_protocols.ParaViewWebTimeHandler()) self.registerVtkWebProtocol(pv_protocols.ParaViewWebRemoteConnection()) self.registerVtkWebProtocol(pv_protocols.ParaViewWebFileManager(IPythonProtocol.dataDir)) # Update authentication key to use self.updateSecret(IPythonProtocol.authKey)
def __init__( self, hostname=None, stream_fn="~/camerastream.npy", timestep=0.2, state_fn=None, view_size=None, measurement_compensation_factor=1.25, debug_rotation=False ): """ :param hostname: :param stream_fn: .npy file with saved numpy array with rotation vector :param timestep: Refresh time :param state_fn: .pvsm file with saved paraview state """ # threading.Thread.__init__(self) self.prev_angle_deg = None self.stream_fn = op.expanduser(stream_fn) # hostname = "localhost" self.view_size = view_size self.hostname = hostname self.debug_rotation = debug_rotation self.measurement_compensation_factor = measurement_compensation_factor if self.hostname is not None: self.connect = pasi.Connect(self.hostname) print("Success binding") self.timestep = timestep if state_fn is not None: self.load_state(state_fn) self.init_view()
def __init__(self, port, serverHost=None, serverPort=11111): self.tcpServer = QtNetwork.QTcpServer() if not self.tcpServer.listen(QtNetwork.QHostAddress.Any, port): print 'Could not list on port %d' % port return self.tcpServer.newConnection.connect(self.acceptClient) self.timer = QtCore.QTimer() self.timer.setSingleShot(True) self.timer.timeout.connect(self.render) if serverHost: pvsimple.Connect(serverHost, serverPort) self.createPipeline() self.setupManipulators() self.widget = \ QVTKRenderWindowInteractor.QVTKRenderWindowInteractor(\ rw=self.renderView.GetRenderWindow(), iren=self.renderView.GetInteractor()) self.widget.Initialize() self.widget.Start() self.widget.show() pvsimple.Render(self.renderView)
def extractParaviewLineData(caseDir, varList, coords, calcDict, csvOutputVar, time): try: reader = ps.OpenFOAMReader(FileName=caseDir + '/case.foam') except: ps.Connect() reader = ps.OpenFOAMReader(FileName=caseDir + '/case.foam') try: reader.CellArrays = varList except: print("Variables {} were not found in results. Exiting ...".format( varList)) reader.MeshRegions = ['internalMesh'] if (time in reader.TimestepValues): reader.SMProxy.UpdatePipeline(time) reader.UpdatePipelineInformation() #view = ps.CreateRenderView() #view.ViewTime = time else: print("Time-directory {} does not exist. Exiting ...".format(time)) sys.exit(1) if (calcDict): calc = ps.Calculator(reader) calc.Function = calcDict["Function"] calc.ResultArrayName = calcDict["ResultArrayName"] plotLine = ps.PlotOverLine(Source="High Resolution Line Source") plotLine.Source.Resolution = 450 plotLine.Source.Point1 = coords[0] # [0.0, 0.0008, 0.0] plotLine.Source.Point2 = coords[1] # [0.59, 0.0008, 0.0] filePath = caseDir + "/tmp.csv" writer = ps.CreateWriter(filePath, plotLine) writer.WriteAllTimeSteps = False writer.UseScientificNotation = 1 #print("Writing file tmp.csv ... ") writer.UpdatePipeline() #print("Done!") ps.Delete(reader) ps.Delete(calc) #; ps.Delete(writer) ps.Delete(plotLine) reader = None del reader calc = None del calc plotLine = None del plotLine del writer if (np.mod((100. * time), 1) == 0): print("Disconnecting ... ") ps.Disconnect() # Clear memory occasionally. data = extractFromCSV("tmp.csv", csvOutputVar) return data
def remove(self): """ Reset ParaView and Vizard stuff to default. """ self.origin_node.remove() for filter in reversed(self._filters): pv.Delete(filter) pv.servermanager.ProxyManager().UnRegisterProxies() pv.Disconnect() pv.Connect()
def runTest(): options = servermanager.vtkProcessModule.GetProcessModule().GetOptions() url = options.GetServerURL() smp.Connect(getHost(url), getPort(url)) sphere = smp.Sphere() f = smp.ProgrammableFilter(sphere) # test that vtk is imported automatically and contains the name vtkPolyData script = 'assert vtk.vtkPolyData' assert testScript(f, script) # test that variables can be passed using the Parameters property script = 'assert foo == "bar"' f.SetPropertyWithName('Parameters', ['foo', '"bar"']) assert testScript(f, script) smp.Disconnect()
def runTest(): options = servermanager.vtkRemotingCoreConfiguration.GetInstance() url = options.GetServerURL() smp.Connect(getHost(url), getPort(url)) r = smp.CreateRenderView() r.RemoteRenderThreshold = 20 s = smp.Sphere() s.PhiResolution = 80 s.ThetaResolution = 80 d = smp.Show() d.Representation = "Wireframe" smp.Render() r.RemoteRenderThreshold = 0 smp.Render() s.PhiResolution = 8 s.ThetaResolution = 8 smp.Render() smtesting.ProcessCommandLineArguments() if not smtesting.DoRegressionTesting(r.SMProxy): raise smtesting.TestError ("Test failed!!!") print ("Test Passed")
def test_contour(self): pv.Connect() # using a dedicated server state for each test print "\nTEST_CONTOUR" # set up some processing task view_proxy = pv.CreateRenderView() view_proxy.OrientationAxesVisibility = 0 view_proxy.ViewSize = [1024, 768] s = pv.Wavelet() contour = pv.Contour(Input=s, ContourBy='RTData', ComputeScalars=1) sliceRep = pv.Show(contour) # make or open a cinema data store to put results in fname = "/tmp/test_pv_contour/info.json" cs = file_store.FileStore(fname) cs.add_metadata({'type': 'parametric-image-stack'}) cs.add_metadata({'store_type': 'FS'}) cs.add_metadata({'version': '0.0'}) cs.filename_pattern = "{phi}_{theta}_{contour}_{color}_contour.png" cs.add_parameter( "phi", store.make_parameter('phi', [90, 120, 140])) cs.add_parameter( "theta", store.make_parameter('theta', [-90, -30, 30, 90])) cs.add_parameter( "contour", store.make_parameter('contour', [50, 100, 150, 200])) cs.add_parameter( "color", store.make_parameter( 'color', ['white', 'RTData_1'], typechoice='list')) # associate control points with parameters of the data store cam = pv_explorers.Camera( [0, 0, 0], [0, 1, 0], 75.0, view_proxy) filt = pv_explorers.Contour("contour", contour) colorChoice = pv_explorers.ColorList() colorChoice.AddSolidColor('white', [1, 1, 1]) colorChoice.AddLUT('POINTS', 'RTData_1', 'X') col = pv_explorers.Color("color", colorChoice, sliceRep) params = ["phi", "theta", "contour", "color"] e = pv_explorers.ImageExplorer( cs, params, [cam, filt, col], view_proxy) # run through all parameter combinations and put data into the store e.explore() # Reproduce an entry and compare vs. loaded # First set the parameters to reproduce cam.execute(store.Document({'theta': 30, 'phi': 140})) filt.execute(store.Document({'contour': 100})) col.execute(store.Document({'color': 'RTData_1'})) imageslice = ch.pvRenderToArray(view_proxy) # Now load the corresponding cs2 = file_store.FileStore(fname) cs2.load() docs = [] for doc in cs2.find( {'theta': 30, 'phi': 140, 'contour': 100, 'color': 'RTData_1'}): docs.append(doc.data) # compare the two l2error = ch.compare_l2(imageslice, docs[0]) ncc = ch.compare_ncc(imageslice, docs[0]) success = (l2error < 1.0) and (ncc > 0.99) if not success: print "\n l2-error = ", l2error, " ; ncc = ", ncc, "\n" self.assertTrue(success) pv.Disconnect() # using a dedicated server state for each test
def test_composite(self): pv.Connect() # get a new context like a normal script would print "\nTEST_COMPOSITE" # set up some processing task view_proxy = pv.CreateRenderView() view_proxy.OrientationAxesVisibility = 0 s = pv.Wavelet() contour = pv.Contour(Input=s, ContourBy='RTData', ComputeScalars=1) sliceRep = pv.Show(contour) # make or open a cinema data store to put results in fname = "/tmp/test_pv_composite/info.json" cs = file_store.FileStore(fname) cs.add_metadata({'type': 'composite-image-stack'}) cs.add_metadata({'store_type': 'FS'}) cs.add_metadata({'version': '0.1'}) cs.filename_pattern = "results.png" cs.add_parameter( "phi", store.make_parameter('phi', [90, 120, 140])) cs.add_parameter( "theta", store.make_parameter('theta', [-90, -30, 30, 90])) cs.add_layer( "vis", store.make_parameter("vis", ['contour'])) contours = [50, 100, 150, 200] cs.add_control("isoval", store.make_parameter('isoval', contours)) cs.assign_parameter_dependence("isoval", "vis", ['contour']) cs.add_field("color", store.make_field('color', {'white': 'rgb', 'depth': 'depth', 'lum': 'luminance', 'RTData_1': 'lut'},), "isoval", contours) # associate control points with parameters of the data store cam = pv_explorers.Camera([0, 0, 0], [0, 1, 0], 75.0, view_proxy) showcontour = pv_explorers.SourceProxyInLayer("contour", sliceRep, contour) layertrack = explorers.Layer("vis", [showcontour]) filt = pv_explorers.Contour("isoval", contour) # additional specification necessary for the color field colorChoice = pv_explorers.ColorList() colorChoice.AddSolidColor('white', [1, 1, 1]) colorChoice.AddLUT('POINTS', 'RTData_1', 'X') colorChoice.AddDepth('depth') colorChoice.AddLuminance('lum') col = pv_explorers.Color("color", colorChoice, sliceRep) paramNames = ["phi", "theta", "vis", "isoval", "color"] trackList = [cam, layertrack, filt, col] e = pv_explorers.ImageExplorer(cs, paramNames, trackList, view_proxy) # run through all parameter combinations and put data into the store e.explore() # Reproduce an entry and compare vs. loaded # First set the parameters to reproduce cam.execute(store.Document({'theta': 30, 'phi': 140})) filt.execute(store.Document({'isoval': 100})) col.execute(store.Document({'color': 'RTData_1'})) imageslice = ch.pvRenderToArray(view_proxy) # Now load the corresponding cs2 = file_store.FileStore(fname) cs2.load() docs = [] for doc in cs2.find({'theta': 30, 'phi': 140, 'isoval': 100, 'color': 'RTData_1'}): docs.append(doc.data) # compare the two l2error = ch.compare_l2(imageslice, docs[0]) ncc = ch.compare_ncc(imageslice, docs[0]) success = (l2error < 1.0) and (ncc > 0.99) if not success: print "\n l2-error = ", l2error, " ; ncc = ", ncc, "\n" self.assertTrue(success) pv.Disconnect() # using a dedicated server state for each test
def test_slice(self): pv.Connect() # using a dedicated server state for each test print "\nTEST_SLICE" # set up some processing task view_proxy = pv.CreateRenderView() view_proxy.OrientationAxesVisibility = 0 s = pv.Sphere() sliceFilt = pv.Slice( SliceType="Plane", Input=s, SliceOffsetValues=[0.0]) sliceFilt.SliceType.Normal = [0, 1, 0] sliceRep = pv.Show(sliceFilt) # make or open a cinema data store to put results in fname = "/tmp/test_pv_slice/info.json" cs = file_store.FileStore(fname) cs.add_metadata({'type': 'parametric-image-stack'}) cs.add_metadata({'store_type': 'FS'}) cs.add_metadata({'version': '0.0'}) cs.filename_pattern = "{phi}_{theta}_{offset}_{color}_slice.png" cs.add_parameter( "phi", store.make_parameter('phi', [90, 120, 140])) cs.add_parameter( "theta", store.make_parameter('theta', [-90, -30, 30, 90])) cs.add_parameter( "offset", store.make_parameter('offset', [-.4, -.2, 0, .2, .4])) cs.add_parameter( "color", store.make_parameter( 'color', ['yellow', 'cyan', "purple"], typechoice='list')) colorChoice = pv_explorers.ColorList() colorChoice.AddSolidColor('yellow', [1, 1, 0]) colorChoice.AddSolidColor('cyan', [0, 1, 1]) colorChoice.AddSolidColor('purple', [1, 0, 1]) # associate control points with parameters of the data store cam = pv_explorers.Camera([0, 0, 0], [0, 1, 0], 10.0, view_proxy) filt = pv_explorers.Slice("offset", sliceFilt) col = pv_explorers.Color("color", colorChoice, sliceRep) params = ["phi", "theta", "offset", "color"] e = pv_explorers.ImageExplorer( cs, params, [cam, filt, col], view_proxy) # run through all parameter combinations and put data into the store e.explore() # Reproduce an entry and compare vs. loaded # First set the parameters to reproduce cam.execute(store.Document({'theta': -30, 'phi': 120})) filt.execute(store.Document({'offset': -.4})) col.execute(store.Document({'color': 'cyan'})) imageslice = ch.pvRenderToArray(view_proxy) # Now load the corresponding entry cs2 = file_store.FileStore(fname) cs2.load() docs = [] for doc in cs2.find( {'theta': -30, 'phi': 120, 'offset': -.4, 'color': 'cyan'}): docs.append(doc.data) # print "gen entry: \n", # imageslice, "\n", # imageslice.shape,"\n", # "loaded: \n", # docs[0], "\n", # docs[0].shape # compare the two l2error = ch.compare_l2(imageslice, docs[0]) ncc = ch.compare_ncc(imageslice, docs[0]) self.assertTrue((l2error < 1.0) and (ncc > 0.99)) pv.Disconnect() # using a dedicated server state for each test
def __init__(self, dsHost=None, dsPort=11111, rsHost=None, rsPort=22222): super(ParaViewWebStartupRemoteConnection, self).__init__() if not ParaViewWebStartupRemoteConnection.connected and dsHost: ParaViewWebStartupRemoteConnection.connected = True simple.Connect(dsHost, dsPort, rsHost, rsPort)