def setDrawMode(self, choice, **kwargs): """ helper for Color tracks so that they can cause Visocyte to render in the right mode.""" if choice == 'color': self.view.StopCaptureValues() if self.UsingGL2: self.view.StopCaptureLuminance() self.CaptureDepth = False self.CaptureLuminance = False self.CaptureValues = False if choice == 'luminance': self.view.StopCaptureValues() if self.UsingGL2: self.view.StartCaptureLuminance() self.CaptureDepth = False self.CaptureLuminance = True self.CaptureValues = False if choice == 'depth': self.view.StopCaptureValues() if self.UsingGL2: self.view.StopCaptureLuminance() self.CaptureDepth = True self.CaptureLuminance = False self.CaptureValues = False if choice == 'value': if self.UsingGL2: self.view.StopCaptureLuminance() if self.CaptureValues is not True: # this is a workaround for a bug in VTK # in valuepass, we need the arrays we will render, # but with CompositePolyDataMapper we need to render # to find out what arrays are needed self.view.StopCaptureValues() simple.Render() self.view.DrawCells = kwargs['field'] self.view.ArrayNameToDraw = kwargs['name'] self.view.ArrayComponentToDraw = kwargs['component'] self.view.ScalarRange = kwargs['range'] self.view.StartCaptureValues() self.view.SetValueRenderingMode(self.ValueMode) # Ensure context support if (self.CheckFloatSupport and self.ValueMode == ValueMode().FLOATING_POINT): # Force a proxy update to make sure the rendering mode is set self.view.UpdateVTKObjects() simple.Render() self.ValueMode = self.view.GetValueRenderingMode() self.CheckFloatSupport = False self.store.add_metadata({'value_mode': self.ValueMode}) self.CaptureDepth = False self.CaptureLuminance = False self.CaptureValues = True
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 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 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 update_camera(viewProxy, cameraData): viewProxy.CameraFocalPoint = cameraData['focalPoint'] viewProxy.CameraPosition = cameraData['position'] viewProxy.CameraViewUp = cameraData['viewUp'] simple.Render(viewProxy)
from visocyte import simple from visocyte import smtesting renderView = simple.CreateView('RenderView') renderView.AxesGrid = 'GridAxes3DActor' renderView.AxesGrid.Visibility = 1 renderView.AxesGrid.XTitleColor = [0.0, 0.0, 0.0] renderView.AxesGrid.YTitleColor = [0.0, 0.0, 0.0] renderView.AxesGrid.ZTitleColor = [0.0, 0.0, 0.0] renderView.AxesGrid.GridColor = [0.0, 0.0, 0.0] renderView.AxesGrid.ShowGrid = 1 renderView.AxesGrid.XLabelColor = [0.0, 0.0, 0.0] renderView.AxesGrid.YLabelColor = [0.0, 0.0, 0.0] renderView.AxesGrid.ZLabelColor = [0.0, 0.0, 0.0] renderView.AxesGrid.DataScale = [1, 1, 1] renderView.OrientationAxesVisibility = 0 renderView.Background = [1.0, 1.0, 1.0] simple.Render(renderView) if not smtesting.DoRegressionTesting(renderView.SMProxy): raise smtesting.TestError('Image comparison failed.')
def insert(self, document): """overridden to use visocyte to generate an image and create a the document for it""" if not self.view: return if self.CaptureDepth: # Depth capture rep = simple.GetRepresentation() wasVol = rep.Representation == 'Volume' if wasVol: rep.Representation = 'Surface' simple.Render() image = self.view.CaptureDepthBuffer() idata = numpy_support.vtk_to_numpy(image) * 256 rw = self.view.GetRenderWindow() width, height = rw.GetSize() try: imageslice = idata.reshape(height, width) except ValueError: imageslice = None if wasVol: rep.Representation = 'Volume' document.data = imageslice self.CaptureDepth = False # printView(self.view) else: imageslice = None if self.CaptureLuminance: if self.UsingGL2: # TODO: needs a fix for luminance pass imageslice = self.captureWindowRGB() else: # GL1 support try: rep = simple.GetRepresentation() if rep is not None: rep.DiffuseColor = [1, 1, 1] rep.ColorArrayName = None except ValueError: pass idata, width, height = self.captureWindowAsNumpy() idata = self.rgb2grey(idata, height, width) imageslice = np.dstack((idata, idata, idata)) document.data = imageslice elif self.CaptureValues: # Value capture if self.ValueMode is ValueMode().INVERTIBLE_LUT: imageslice = self.captureWindowRGB() elif self.ValueMode is ValueMode().FLOATING_POINT: simple.Render() image = self.view.GetValuesFloat() idata = numpy_support.vtk_to_numpy(image) idataMin = idata.min() if len(idata) > 0 else 0 idataMax = idata.max() if len(idata) > 0 else 0 self.updateRange(self.view.ArrayNameToDraw, self.view.ArrayComponentToDraw, [idataMin, idataMax]) rw = self.view.GetRenderWindow() width, height = rw.GetSize() try: imageslice = idata.reshape(height, width) except ValueError: imageslice = None document.data = imageslice else: # Capture color image imageslice = self.captureWindowRGB() document.data = imageslice if self.iSave: super(ImageExplorer, self).insert(document)
# 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())
opacityTransferFunction = simple.CreatePiecewiseFunction( Points=[0.0, 0.2, 0.5, 0.0, NUM_POINTS - 1, 1.0, 0.5, 0.0]) rep.OpacityTransferFunction = opacityTransferFunction rep.OpacityArray = 'Inverse Distance' rep.OpacityByArray = 1 # Now set a custom shader snippet rep.CustomShader = ''' //VTK::Color::Impl float dist = dot(offsetVCVSOutput.xy,offsetVCVSOutput.xy); if (dist > 9.0) { discard; } ''' rep.CustomTriangleScale = 3 rep.ShaderPreset = "Custom" # Now render, configure the view, and re-render renderView = simple.Render() renderView.CenterOfRotation = [(NUM_POINTS - 1) / 2.0, 0, 0] renderView.CameraPosition = [(NUM_POINTS - 1) / 2.0, 0, NUM_POINTS * 2] renderView.CameraFocalPoint = [(NUM_POINTS - 1) / 2.0, 0, 0] renderView.CameraViewAngle = 30.0 renderView.CameraParallelProjection = 0 simple.Render(renderView) if not smtesting.DoRegressionTesting(renderView.SMProxy): raise smtesting.TestError('Image comparison failed.')
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()