def run(filename=None): """Create a dummy pipeline and save the coprocessing state in the filename specified, if any, else dumps it out on stdout.""" from visocyte import simple, servermanager wavelet = simple.Wavelet(registrationName="Wavelet1") contour = simple.Contour() display = simple.Show() view = simple.Render() # create a new 'Parallel PolyData Writer' parallelPolyDataWriter0 = simple.ParallelPolyDataWriter() viewname = servermanager.ProxyManager().GetProxyName("views", view.SMProxy) script = DumpPipeline( export_rendering=True, simulation_input_map={"Wavelet1": "input"}, screenshot_info={viewname: ['image.png', '1', '1', '2', '400', '400']}, cinema_tracks={}, cinema_arrays={}) if filename: f = open(filename, "w") f.write(script) f.close() else: print("# *** Generated Script Begin ***") print(script) print("# *** Generated Script End ***")
def testUserInput(): fileName = QtGui.QFileDialog.getOpenFileName(getMainWindow(), 'Open file',) if fileName: smp.OpenDataFile(fileName, guiName=os.path.basename(fileName)) smp.Show() smp.ResetCamera() smp.Render()
def writeLightArray(self, path, source): rep = simple.Show(source, self.view) rep.Representation = 'Surface' rep.DiffuseColor = [1, 1, 1] simple.ColorBy(rep, ('POINTS', None)) # Grab data tmpFileName = path + '__.png' self.view.LockBounds = 1 simple.SaveScreenshot(tmpFileName, self.view) self.view.LockBounds = 0 if self.canWrite: # Convert data self.reader.SetFileName(tmpFileName) self.reader.Update() rgbArray = self.reader.GetOutput().GetPointData().GetArray(0) arraySize = rgbArray.GetNumberOfTuples() rawArray = vtkUnsignedCharArray() rawArray.SetNumberOfTuples(arraySize) for idx in range(arraySize): light = rgbArray.GetTuple3(idx)[0] rawArray.SetTuple1(idx, light) with open(path, 'wb') as f: f.write(buffer(rawArray)) # Delete temporary file if self.cleanAfterMe: os.remove(tmpFileName) simple.Hide(source, self.view)
def finish(self): super(ImageExplorer, self).finish() # TODO: actually record state in init and restore here, for now just # make an assumption self.view.StopCaptureValues() if self.UsingGL2: self.view.StopCaptureLuminance() try: simple.Show() simple.Render() except RuntimeError: pass
def runTest(): options = servermanager.vtkProcessModule.GetProcessModule().GetOptions() 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 initialize(self): from visocyte import simple from visocyte.web import protocols as pv_protocols # Make sure Visocyte 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.VisocyteWebFileListing(IPythonProtocol.dataDir, "Home", IPythonProtocol.excludeRegex, IPythonProtocol.groupRegex)) self.registerVtkWebProtocol( pv_protocols.VisocyteWebPipelineManager( IPythonProtocol.dataDir, IPythonProtocol.fileToLoad)) self.registerVtkWebProtocol(pv_protocols.VisocyteWebMouseHandler()) self.registerVtkWebProtocol(pv_protocols.VisocyteWebViewPort()) self.registerVtkWebProtocol( pv_protocols.VisocyteWebViewPortImageDelivery()) self.registerVtkWebProtocol( pv_protocols.VisocyteWebViewPortGeometryDelivery()) self.registerVtkWebProtocol(pv_protocols.VisocyteWebTimeHandler()) self.registerVtkWebProtocol(pv_protocols.VisocyteWebRemoteConnection()) self.registerVtkWebProtocol( pv_protocols.VisocyteWebFileManager(IPythonProtocol.dataDir)) # Update authentication key to use self.updateSecret(IPythonProtocol.authKey)
def makeSphere(): smp.Sphere() smp.Show() smp.ResetCamera() smp.Render()
def writeArray(self, path, source, name, component=0): rep = simple.Show(source, self.view) rep.Representation = 'Surface' rep.DiffuseColor = [1, 1, 1] dataRange = [0.0, 1.0] fieldToColorBy = ['POINTS', name] self.view.ArrayNameToDraw = name self.view.ArrayComponentToDraw = component pdi = source.GetPointDataInformation() cdi = source.GetCellDataInformation() if pdi.GetArray(name): self.view.DrawCells = 0 dataRange = pdi.GetArray(name).GetRange(component) fieldToColorBy[0] = 'POINTS' elif cdi.GetArray(name): self.view.DrawCells = 1 dataRange = cdi.GetArray(name).GetRange(component) fieldToColorBy[0] = 'CELLS' else: print("No array with that name", name) return realRange = dataRange if dataRange[0] == dataRange[1]: dataRange = [dataRange[0] - 0.1, dataRange[1] + 0.1] simple.ColorBy(rep, fieldToColorBy) # Grab data tmpFileName = path + '__.png' self.view.ScalarRange = dataRange self.view.LockBounds = 1 self.view.StartCaptureValues() simple.SaveScreenshot(tmpFileName, self.view) self.view.StopCaptureValues() self.view.LockBounds = 0 if self.canWrite: # Convert data self.reader.SetFileName(tmpFileName) self.reader.Update() rgbArray = self.reader.GetOutput().GetPointData().GetArray(0) arraySize = rgbArray.GetNumberOfTuples() rawArray = vtkFloatArray() rawArray.SetNumberOfTuples(arraySize) minValue = 10000.0 maxValue = -100000.0 delta = (dataRange[1] - dataRange[0]) / 16777215.0 # 2^24 - 1 => 16,777,215 for idx in range(arraySize): rgb = rgbArray.GetTuple3(idx) if rgb[0] != 0 or rgb[1] != 0 or rgb[2] != 0: value = dataRange[0] + delta * float( rgb[0] * 65536 + rgb[1] * 256 + rgb[2] - 1) rawArray.SetTuple1(idx, value) minValue = min(value, minValue) maxValue = max(value, maxValue) else: rawArray.SetTuple1(idx, float('NaN')) # print ('Array bounds', minValue, maxValue, 'compare to', dataRange) with open(path, 'wb') as f: f.write(buffer(rawArray)) # Delete temporary file if self.cleanAfterMe: os.remove(tmpFileName) # Remove representation from view simple.Hide(source, self.view) return realRange
# in the state file can end up changing the active source to be different # than what it was when the state is being saved. trace.append_separated([\ "# ----------------------------------------------------------------", "# finally, restore active source", "SetActiveSource(%s)" % smtrace.Trace.get_accessor(simple.GetActiveSource()), "# ----------------------------------------------------------------"]) del trace_config smtrace.stop_trace() #print (trace) return str(trace) if not raw else trace.raw_data() if __name__ == "__main__": print ( "Running test") simple.Mandelbrot() simple.Show() simple.Hide() simple.Shrink().ShrinkFactor = 0.4 simple.UpdatePipeline() simple.Clip().ClipType.Normal[1] = 1 rep = simple.Show() view = simple.Render() view.ViewSize=[500, 500] rep.SetScalarBarVisibility(view, True) simple.Render() # rep.SetScalarBarVisibility(view, False) print ("====================================================================") print (get_state())
source = simple.TrivialProducer() source.GetClientSideObject().SetOutput(polyData) # create a calculator to compute distance calculator1 = simple.Calculator(Input=source) calculator1.ResultArrayName = 'Distance' calculator1.Function = 'mag(coords)' # create another calculator to compute inverse distance calculator2 = simple.Calculator(Input=calculator1) calculator2.ResultArrayName = 'Inverse Distance' calculator2.Function = '%s-Distance' % str(NUM_POINTS - 1) # Get the representation rep = simple.Show(calculator2) # Set up coloring by one array rep.Representation = 'Point Gaussian' simple.ColorBy(rep, ('POINTS', 'Ordinal')) vtkSMPVRepresentationProxy.RescaleTransferFunctionToDataRange( rep.SMProxy, 'Ordinal', 0, False) # Set up sizing by another array scaleTransferFunction = simple.CreatePiecewiseFunction( Points=[0.0, 0.05, 0.5, 0.0, NUM_POINTS - 1, 0.15, 0.5, 0.0]) rep.ScaleTransferFunction = scaleTransferFunction rep.SetScaleArray = 'Distance' rep.ScaleByArray = 1 rep.GaussianRadius = 1
print("Timestep %d" % step) wavelet = pvsimple.Wavelet() wavelet.Maximum = 300 + 50 * math.sin(step * 2 * 3.1415927 / 10) wavelet.YMag = yMag wavelet.ZMag = zMag contour = pvsimple.Contour(guiName="Contour", Isosurfaces=[230.0], ContourBy=['RTData'], PointMergeMethod="Uniform Binning") fileName = currentDir + "/wavelet_{:0d}_{:0d}_{:0d}.vtp".format( yMag, zMag, step) writer = pvsimple.XMLPolyDataWriter(Input=contour, FileName=fileName) writer.UpdatePipeline() pvsimple.Show() pvsimple.Render() pvsimple.Delete(wavelet) pvsimple.Delete(contour) pvsimple.Delete(writer) wavelet = None contour = None writer = None fTime.write(fileName) fTime.write("\n") fTime.close() fEnsemble.close()