How to use getApplication method in pyatom

Best Python code snippet using pyatom_python

light_viz_protocols.py

Source:light_viz_protocols.py Github

copy

Full Screen

...214 # reset the camera215 simple.ResetCamera(self.view)216 self.view.CenterOfRotation = self.view.CameraFocalPoint217 simple.Render(self.view)218 self.getApplication().InvokeEvent('PushRender')219 self.anim = simple.GetAnimationScene()220 # Notify listeners221 for l in self.dataListeners:222 l.dataChanged()223 # When loading new dataset, rescale colormaps to full range by default224 for array in self.activeMeta['data']['arrays']:225 arrRange = array['range']226 arrName = array['name']227 self.setColormapRange(arrName, arrRange)228 simple.Render(self.view)229 self.getApplication().InvokeEvent('PushRender')230 return self.activeMeta231 @exportRpc("light.viz.dataset.setblock.visibility")232 def setBlockVisibility(self, visible):233 # 0 block is always presumed to be needed since everything is under it234 if self.extractBlocks is None:235 return236 self.extractBlocks.BlockIndices = visible237 self.getApplication().InvokeEvent('PushRender')238 @exportRpc("light.viz.dataset.getblockstructure")239 def getBlockStructure(self):240 dataInfo = self.reader.GetDataInformation().DataInformation.GetCompositeDataInformation()241 if dataInfo.GetDataIsComposite() == 0:242 return []243 index = 0;244 def processInfo(info, index):245 output = []246 if info.GetNumberOfChildren() == 0:247 return output, index248 for i in xrange(info.GetNumberOfChildren()):249 name = info.GetName(i)250 childOutput = []251 index += 1252 myIndex = index253 if info.GetDataInformation(i) is not None:254 childInfo = info.GetDataInformation(i).GetCompositeDataInformation()255 childOutput, index = processInfo(childInfo, index)256 output.append({'name': name, 'children': childOutput, 'flatindex': myIndex})257 return output, index258 a, index = processInfo(dataInfo, index)259 return a260 def checkArrayInMap(self, array):261 if array not in self.colormaps:262 self.colormaps[array] = { 'preset': 'Cool to Warm', 'range': [0, 1] }263 @exportRpc("light.viz.colormap.setpreset")264 def setColormapPreset(self, array, presetName):265 if (array is None):266 return267 self.checkArrayInMap(array)268 self.colormaps[array]['preset'] = presetName269 rtDataLUT = simple.GetColorTransferFunction(array);270 rtDataLUT.ApplyPreset(presetName, True)271 simple.Render()272 self.getApplication().InvokeEvent('PushRender')273 @exportRpc("light.viz.colormap.setrange")274 def setColormapRange(self, array, newRange):275 if (array is None):276 return277 self.checkArrayInMap(array)278 self.colormaps[array]['range'] = newRange279 rtDataLUT = simple.GetColorTransferFunction(array)280 rtDataLUT.RescaleTransferFunction(newRange[0], newRange[1])281 opacityLUT = simple.GetOpacityTransferFunction(array)282 opacityLUT.RescaleTransferFunction(newRange[0], newRange[1])283 self.getApplication().InvokeEvent('PushRender')284 @exportRpc("light.viz.colormap.rescale.todatarange")285 def setColormapRangeToDataRange(self, array):286 if (array is None):287 return288 self.checkArrayInMap(array)289 rtDataLUT = simple.GetColorTransferFunction(array)290 self.datasetRep.RescaleTransferFunctionToDataRange(False)291 self.colormaps[array]['range'] = [rtDataLUT.RGBPoints[0], rtDataLUT.RGBPoints[-4]]292 rtDataOpacityTF = simple.GetOpacityTransferFunction(array)293 rtDataOpacityTF.RescaleTransferFunction(self.colormaps[array]['range'])294 self.getApplication().InvokeEvent('PushRender')295 return self.colormaps[array]['range']296 @exportRpc("light.viz.colormap.get")297 def getColorMap(self, array):298 if (array is None):299 return { 'preset': 'Cool to Warm', 'range': [0, 1] }300 self.checkArrayInMap(array)301 return self.colormaps[array]302 @exportRpc("light.viz.opacitymap.set")303 def setOpacityMap(self, array, controlPoints):304 if (array is None):305 return306 points = []307 r = self.colormaps[array]['range']308 for p in controlPoints:309 points.append(p["x"] * (r[1] - r[0]) + r[0])310 points.append(p["y"])311 points.append(0.5)312 points.append(0.0)313 rtDataLUT = simple.GetOpacityTransferFunction(array);314 rtDataLUT.Points = points315 self.getApplication().InvokeEvent('PushRender')316 @exportRpc("light.viz.opacitymap.get")317 def getOpacityMap(self, array):318 if (array is None):319 return320 points = []321 rtDataLUT = simple.GetOpacityTransferFunction(array);322 r = self.colormaps[array]['range']323 for i in xrange(len(rtDataLUT.Points) / 4):324 points.append((rtDataLUT.Points[i * 4] - r[0]) / (r[1] - r[0]))325 points.append(rtDataLUT.Points[i * 4 + 1])326 return points327 @exportRpc("light.viz.foreground.color")328 def setForegroundColor(self, foreground):329 self.foreground = [ float(x) for x in foreground.split(' ')]330 for obs in self.dataListeners:331 obs.setForegroundColor(self.foreground)332 if self.datasetRep:333 self.datasetRep.DiffuseColor = self.foreground334 self.getApplication().InvokeEvent('PushRender')335 @exportRpc("light.viz.background.color")336 def setBackgroundColor(self, background):337 self.background = [ float(x) for x in background.split(' ')]338 if self.view:339 self.view.Background = self.background340 self.getApplication().InvokeEvent('PushRender')341 @exportRpc("light.viz.dataset.getstate")342 def getState(self):343 tmp = {344 "opacity": self.datasetRep.Opacity,345 "representation": self.datasetRep.Representation,346 "color": self.colorBy,347 "enabled": self.datasetRep.Visibility == 1,348 }349 if not isinstance(tmp["enabled"], bool):350 tmp["enabled"] = tmp["enabled"][0]351 return tmp352 @exportRpc("light.viz.dataset.opacity")353 def updateOpacity(self, opacity):354 if self.datasetRep:355 self.datasetRep.Opacity = opacity356 self.getApplication().InvokeEvent('PushRender')357 return opacity358 @exportRpc("light.viz.dataset.time")359 def updateTime(self, timeIdx):360 if len(self.anim.TimeKeeper.TimestepValues) > 0:361 self.anim.TimeKeeper.Time = self.anim.TimeKeeper.TimestepValues[timeIdx]362 self.getApplication().InvokeEvent('PushRender')363 return self.anim.TimeKeeper.Time364 @exportRpc("light.viz.dataset.representation")365 def updateRepresentation(self, mode):366 if self.datasetRep:367 self.datasetRep.Representation = mode368 self.getApplication().InvokeEvent('PushRender')369 @exportRpc("light.viz.dataset.color")370 def updateColorBy(self, field, location):371 self.colorBy = (location, field)372 if field == '__SOLID__':373 self.datasetRep.ColorArrayName = ''374 else:375 # Select data array376 simpleColorBy(self.datasetRep, (location, field))377 lutProxy = self.datasetRep.LookupTable378 pwfProxy = self.datasetRep.ScalarOpacityFunction379 for array in self.activeMeta['data']['arrays']:380 if array['name'] == field and array['location'] == location:381 if lutProxy:382 vtkSMTransferFunctionProxy.RescaleTransferFunction(lutProxy.SMProxy, array['range'][0], array['range'][1], False)383 if pwfProxy:384 vtkSMTransferFunctionProxy.RescaleTransferFunction(pwfProxy.SMProxy, array['range'][0], array['range'][1], False)385 simple.Render()386 self.getApplication().InvokeEvent('PushRender')387 @exportRpc("light.viz.dataset.enable")388 def enableDataset(self, enable):389 self.datasetRep.Visibility = 1 if enable else 0390 simple.Render()391 self.getApplication().InvokeEvent('PushRender')392# =============================================================================393#394# Clip management395#396# =============================================================================397class LightVizClip(pv_protocols.ParaViewWebProtocol):398 def __init__(self, dataset_manager):399 super(LightVizClip, self).__init__()400 self.ds = dataset_manager401 self.clipX = None402 self.clipY = None403 self.clipZ = None404 self.representation = None405 self.box = None406 self.boxRepr = None407 self.reprMode = 'Surface'408 self.colorBy = ('__SOLID__', '__SOLID__')409 dataset_manager.addListener(self)410 def dataChanged(self):411 self.updateRepresentation('Surface')412 self.updateColorBy('__SOLID__', '__SOLID__')413 if self.clipX:414 self.clipX.Input = self.ds.getInput()415 bounds = self.ds.activeMeta['data']['bounds']416 self.updatePosition((bounds[1] + bounds[0])/2.0,417 (bounds[3] + bounds[2])/2.0,418 (bounds[5] + bounds[4])/2.0)419 self.updateInsideOut(False, False, False)420 if self.representation:421 self.representation.Visibility = 0422 def setForegroundColor(self, foreground):423 if self.representation:424 self.representation.DiffuseColor = foreground425 @exportRpc("light.viz.clip.box.position")426 def updatePositionForBox(self, x, y, z):427 newClipCenter = [x, y, z]428 boundsPoint = [self.ds.activeMeta['data']['bounds'][2 * i] for i in range(3)]429 if not self.clipX.InsideOut:430 boundsPoint[0] = self.ds.activeMeta['data']['bounds'][1]431 if not self.clipY.InsideOut:432 boundsPoint[1] = self.ds.activeMeta['data']['bounds'][3]433 if not self.clipZ.InsideOut:434 boundsPoint[2] = self.ds.activeMeta['data']['bounds'][5]435 if self.box:436 self.box.Center = [(newClipCenter[i] + boundsPoint[i]) * 0.5 for i in range(3)]437 self.box.XLength = abs(boundsPoint[0] - newClipCenter[0])438 self.box.YLength = abs(boundsPoint[1] - newClipCenter[1])439 self.box.ZLength = abs(boundsPoint[2] - newClipCenter[2])440 self.getApplication().InvokeEvent('PushRender')441 @exportRpc("light.viz.clip.box.show")442 def showBox(self, enable):443 if enable and self.ds.getInput():444 bounds = self.ds.activeMeta['data']['bounds']445 if not self.box:446 self.box = simple.Box()447 self.updatePositionForBox((bounds[1] + bounds[0])/2.0,448 (bounds[3] + bounds[2])/2.0,449 (bounds[5] + bounds[4])/2.0)450 self.boxRepr = simple.Show(Input=self.box)451 self.boxRepr.Representation = 'Outline'452 self.boxRepr.DiffuseColor = [1, 0, 0]453 self.boxRepr.Visibility = 1454 elif (not enable) and self.boxRepr:455 self.boxRepr.Visibility = 0456 self.getApplication().InvokeEvent('PushRender')457 @exportRpc("light.viz.clip.getstate")458 def getState(self):459 ret = {460 "representation": self.reprMode,461 "color": self.colorBy,462 "enabled": False,463 "xPosition": 0,464 "yPosition": 0,465 "zPosition": 0,466 "xInsideOut": False,467 "yInsideOut": False,468 "zInsideOut": False,469 }470 if self.representation:471 ret["enabled"] = self.representation.Visibility == 1,472 if self.clipX:473 ret["xPosition"] = self.clipX.ClipType.Origin[0]474 ret["yPosition"] = self.clipY.ClipType.Origin[1]475 ret["zPosition"] = self.clipZ.ClipType.Origin[2]476 ret["xInsideOut"] = self.clipX.InsideOut == 1477 ret["yInsideOut"] = self.clipY.InsideOut == 1478 ret["zInsideOut"] = self.clipZ.InsideOut == 1479 if not isinstance(ret["enabled"], bool):480 ret["enabled"] = ret["enabled"][0]481 return ret482 @exportRpc("light.viz.clip.position")483 def updatePosition(self, x, y, z):484 if self.clipX:485 self.clipX.ClipType.Origin = [float(x), 0.0, 0.0]486 if self.clipY:487 self.clipY.ClipType.Origin = [0.0, float(y), 0.0]488 if self.clipZ:489 self.clipZ.ClipType.Origin = [0.0, 0.0, float(z)]490 self.getApplication().InvokeEvent('PushRender')491 @exportRpc("light.viz.clip.insideout")492 def updateInsideOut(self, x, y, z):493 if self.clipX:494 self.clipX.InsideOut = 1 if x else 0495 if self.clipY:496 self.clipY.InsideOut = 1 if y else 0497 if self.clipZ:498 self.clipZ.InsideOut = 1 if z else 0499 self.getApplication().InvokeEvent('PushRender')500 @exportRpc("light.viz.clip.representation")501 def updateRepresentation(self, mode):502 self.reprMode = mode503 if self.representation:504 self.representation.Representation = mode505 self.getApplication().InvokeEvent('PushRender')506 @exportRpc("light.viz.clip.color")507 def updateColorBy(self, field, location):508 self.colorBy = (location, field)509 if self.representation:510 if field == '__SOLID__':511 self.representation.ColorArrayName = ''512 else:513 simpleColorBy(self.representation, (location, field))514 lutProxy = self.representation.LookupTable515 pwfProxy = self.representation.ScalarOpacityFunction516 for array in self.ds.activeMeta['data']['arrays']:517 if array['name'] == field and array['location'] == location:518 vtkSMTransferFunctionProxy.RescaleTransferFunction(lutProxy.SMProxy, array['range'][0], array['range'][1], False)519 if pwfProxy:520 vtkSMTransferFunctionProxy.RescaleTransferFunction(pwfProxy.SMProxy, array['range'][0], array['range'][1], False)521 simple.Render()522 self.getApplication().InvokeEvent('PushRender')523 @exportRpc("light.viz.clip.enable")524 def enableClip(self, enable):525 if enable and self.ds.getInput():526 if not self.clipX:527 bounds = self.ds.activeMeta['data']['bounds']528 center = [(bounds[i*2] + bounds[i*2+1])*0.5 for i in range(3)]529 self.clipX = simple.Clip(Input=self.ds.getInput())530 self.clipY = simple.Clip(Input=self.clipX)531 self.clipZ = simple.Clip(Input=self.clipY)532 self.clipX.ClipType.Origin = center533 self.clipX.ClipType.Normal = [1, 0, 0]534 self.clipY.ClipType.Origin = center535 self.clipY.ClipType.Normal = [0, 1, 0]536 self.clipZ.ClipType.Origin = center537 self.clipZ.ClipType.Normal = [0, 0, 1]538 else:539 self.clipX.Input = self.ds.getInput()540 if not self.representation:541 self.representation = simple.Show(self.clipZ)542 self.representation.Representation = self.reprMode543 self.representation.DiffuseColor = self.ds.foreground544 self.updateColorBy(self.colorBy[1], self.colorBy[0])545 self.representation.Visibility = 1546 if not enable and self.representation:547 self.representation.Visibility = 0548 simple.Render()549 self.getApplication().InvokeEvent('PushRender')550 def getOutput(self):551 if not self.clipX:552 bounds = self.ds.activeMeta['data']['bounds']553 center = [(bounds[i*2] + bounds[i*2+1])*0.5 for i in range(3)]554 self.clipX = simple.Clip(Input=self.ds.getInput())555 self.clipY = simple.Clip(Input=self.clipX)556 self.clipZ = simple.Clip(Input=self.clipY)557 self.clipX.ClipType.Origin = center558 self.clipX.ClipType.Normal = [1, 0, 0]559 self.clipY.ClipType.Origin = center560 self.clipY.ClipType.Normal = [0, 1, 0]561 self.clipZ.ClipType.Origin = center562 self.clipZ.ClipType.Normal = [0, 0, 1]563 return self.clipZ564# =============================================================================565#566# Contours management567#568# =============================================================================569class LightVizContour(pv_protocols.ParaViewWebProtocol):570 def __init__(self, dataset_manager, clip):571 super(LightVizContour, self).__init__()572 self.ds = dataset_manager573 self.clip = clip574 self.contour = None575 self.contourByField = None576 self.representation = None577 self.reprMode = 'Surface'578 self.colorBy = ('__SOLID__', '__SOLID__')579 self.useClippedInput = False580 dataset_manager.addListener(self)581 def dataChanged(self):582 self.updateRepresentation('Surface')583 self.updateColorBy(self.ds.activeMeta["data"]["arrays"][0]["name"], self.ds.activeMeta["data"]["arrays"][0]["location"])584 if self.contour:585 self.contour.Input = self.ds.getInput()586 self.contour.Isosurfaces = [ sum(self.ds.activeMeta["data"]["arrays"][0]["range"]) * 0.5, ]587 self.representation.Visibility = 0588 def setForegroundColor(self, foreground):589 if self.representation:590 self.representation.DiffuseColor = foreground591 self.getApplication().InvokeEvent('PushRender')592 @exportRpc("light.viz.contour.useclipped")593 def setUseClipped(self, useClipped):594 if self.contour:595 if not self.useClippedInput and useClipped:596 self.contour.Input = self.clip.getOutput()597 elif self.useClippedInput and not useClipped:598 self.contour.Input = self.ds.getInput()599 self.useClippedInput = useClipped600 self.getApplication().InvokeEvent('PushRender')601 @exportRpc("light.viz.contour.getstate")602 def getState(self):603 ret = {604 "representation": "Surface",605 "color": self.colorBy,606 "enabled": False,607 "field": '',608 "use_clipped": self.useClippedInput,609 "values": [],610 }611 if self.contour:612 ret["representation"] = self.representation.Representation613 ret["color"] = self.colorBy614 ret["enabled"] = self.representation.Visibility == 1,615 ret["field"] = self.contour.ContourBy[1]616 ret["values"] = [i for i in self.contour.Isosurfaces]617 if not isinstance(ret["enabled"], bool):618 ret["enabled"] = ret["enabled"][0]619 return ret620 @exportRpc("light.viz.contour.values")621 def updateValues(self, values):622 if self.contour:623 self.contour.Isosurfaces = values624 self.getApplication().InvokeEvent('PushRender')625 @exportRpc("light.viz.contour.by")626 def updateContourBy(self, field):627 if self.contour:628 self.contourByField = None629 self.contour.ContourBy = field630 self.getApplication().InvokeEvent('PushRender')631 else:632 self.contourByField = field633 @exportRpc("light.viz.contour.representation")634 def updateRepresentation(self, mode):635 self.reprMode = mode636 if self.representation:637 self.representation.Representation = mode638 self.getApplication().InvokeEvent('PushRender')639 @exportRpc("light.viz.contour.color")640 def updateColorBy(self, field, location):641 self.colorBy = (location, field)642 if self.representation:643 if field == '__SOLID__':644 self.representation.ColorArrayName = ''645 else:646 simpleColorBy(self.representation, (location, field))647 lutProxy = self.representation.LookupTable648 for array in self.ds.activeMeta['data']['arrays']:649 if array['name'] == field and array['location'] == location:650 vtkSMTransferFunctionProxy.RescaleTransferFunction(lutProxy.SMProxy, array['range'][0], array['range'][1], False)651 simple.Render()652 self.getApplication().InvokeEvent('PushRender')653 @exportRpc("light.viz.contour.enable")654 def enableContour(self, enable):655 if enable and self.ds.getInput():656 inpt = self.ds.getInput() if not self.useClippedInput else self.clip.getOutput()657 if not self.contour:658 self.contour = simple.Contour(Input=inpt, ComputeScalars=1, ComputeNormals=1)659 self.representation = simple.Show(self.contour)660 self.representation.Representation = self.reprMode661 self.representation.DiffuseColor = self.ds.foreground662 self.updateColorBy(self.colorBy[1], self.colorBy[0])663 if self.contourByField:664 self.updateContourBy(self.contourByField)665 else:666 self.contour.Input = inpt667 self.representation.Visibility = 1668 if not enable and self.representation:669 self.representation.Visibility = 0670 simple.Render()671 self.getApplication().InvokeEvent('PushRender')672# =============================================================================673#674# Slice management675#676# =============================================================================677class LightVizSlice(pv_protocols.ParaViewWebProtocol):678 def __init__(self, dataset_manager, clip):679 super(LightVizSlice, self).__init__()680 self.ds = dataset_manager681 self.clip = clip682 self.sliceX = None683 self.sliceY = None684 self.sliceZ = None685 self.representationX = None686 self.representationY = None687 self.representationZ = None688 self.center = None689 self.visible = [1, 1, 1]690 self.enabled = False691 self.reprMode = 'Surface'692 self.colorBy = ('__SOLID__', '__SOLID__')693 self.useClippedInput = False694 dataset_manager.addListener(self)695 def dataChanged(self):696 self.updateRepresentation('Surface')697 self.updateColorBy('__SOLID__', '__SOLID__')698 if self.sliceX:699 bounds = self.ds.activeMeta['data']['bounds']700 center = [(bounds[i*2] + bounds[i*2+1])*0.5 for i in range(3)]701 self.sliceX.Input = self.ds.getInput()702 self.sliceY.Input = self.ds.getInput()703 self.sliceZ.Input = self.ds.getInput()704 self.updatePosition(center[0], center[1], center[2])705 self.representationX.Representation = 'Surface'706 self.representationY.Representation = 'Surface'707 self.representationZ.Representation = 'Surface'708 self.representationX.Visibility = 0709 self.representationY.Visibility = 0710 self.representationZ.Visibility = 0711 self.enabled = False712 def setForegroundColor(self, foreground):713 if self.representationX:714 self.representationX.DiffuseColor = foreground715 self.representationY.DiffuseColor = foreground716 self.representationZ.DiffuseColor = foreground717 @exportRpc("light.viz.slice.useclipped")718 def setUseClipped(self, useClipped):719 if self.sliceX:720 if not self.useClippedInput and useClipped:721 for slice in [self.sliceX, self.sliceY, self.sliceZ]:722 slice.Input = self.clip.getOutput()723 elif self.useClippedInput and not useClipped:724 for slice in [self.sliceX, self.sliceY, self.sliceZ]:725 slice.Input = self.ds.getInput()726 self.useClippedInput = useClipped727 self.getApplication().InvokeEvent('PushRender')728 @exportRpc("light.viz.slice.getstate")729 def getState(self):730 ret = {731 "representation": self.reprMode,732 "color": self.colorBy,733 "enabled": self.enabled,734 "xPosition": 0,735 "yPosition": 0,736 "zPosition": 0,737 "xVisible": self.visible[0] == 1,738 "yVisible": self.visible[1] == 1,739 "zVisible": self.visible[2] == 1,740 "use_clipped": self.useClippedInput,741 }742 if self.center:743 ret['xPosition'] = self.center[0]744 ret['yPosition'] = self.center[1]745 ret['zPosition'] = self.center[2]746 if not isinstance(ret["enabled"], bool):747 ret["enabled"] = ret["enabled"][0]748 return ret749 @exportRpc("light.viz.slice.position")750 def updatePosition(self, x, y, z):751 self.center = [x, y, z]752 if self.sliceX:753 self.sliceX.SliceType.Origin = self.center754 if self.sliceY:755 self.sliceY.SliceType.Origin = self.center756 if self.sliceZ:757 self.sliceZ.SliceType.Origin = self.center758 self.getApplication().InvokeEvent('PushRender')759 @exportRpc("light.viz.slice.visibility")760 def updateVisibility(self, x, y, z):761 self.visible = [ 1 if x else 0, 1 if y else 0, 1 if z else 0]762 if self.representationX:763 self.representationX.Visibility = self.visible[0] and self.enabled764 if self.representationY:765 self.representationY.Visibility = self.visible[1] and self.enabled766 if self.representationZ:767 self.representationZ.Visibility = self.visible[2] and self.enabled768 self.getApplication().InvokeEvent('PushRender')769 @exportRpc("light.viz.slice.representation")770 def updateRepresentation(self, mode):771 self.reprMode = mode772 if self.representationX:773 self.representationX.Representation = mode774 self.representationY.Representation = mode775 self.representationZ.Representation = mode776 self.getApplication().InvokeEvent('PushRender')777 @exportRpc("light.viz.slice.color")778 def updateColorBy(self, field, location):779 self.colorBy = (location, field)780 if self.representationX:781 if field == '__SOLID__':782 self.representationX.ColorArrayName = ''783 self.representationY.ColorArrayName = ''784 self.representationZ.ColorArrayName = ''785 else:786 simpleColorBy(self.representationX, self.colorBy)787 simpleColorBy(self.representationY, self.colorBy)788 simpleColorBy(self.representationZ, self.colorBy)789 # Update data array range790 for rep in [self.representationX, self.representationY, self.representationZ]:791 lutProxy = rep.LookupTable792 for array in self.ds.activeMeta['data']['arrays']:793 if array['name'] == field and array['location'] == location:794 vtkSMTransferFunctionProxy.RescaleTransferFunction(lutProxy.SMProxy, array['range'][0], array['range'][1], False)795 simple.Render()796 self.getApplication().InvokeEvent('PushRender')797 @exportRpc("light.viz.slice.enable")798 def enableSlice(self, enable):799 if enable and self.ds.getInput():800 inpt = self.ds.getInput() if not self.useClippedInput else self.clip.getOutput()801 if not self.sliceX:802 bounds = self.ds.activeMeta['data']['bounds']803 center = self.center804 if center is None:805 center = [(bounds[i*2] + bounds[i*2+1])*0.5 for i in range(3)]806 self.sliceX = simple.Slice(Input=inpt)807 self.sliceY = simple.Slice(Input=inpt)808 self.sliceZ = simple.Slice(Input=inpt)809 self.sliceX.SliceType.Origin = center810 self.sliceX.SliceType.Normal = [1, 0, 0]811 self.sliceY.SliceType.Origin = center812 self.sliceY.SliceType.Normal = [0, 1, 0]813 self.sliceZ.SliceType.Origin = center814 self.sliceZ.SliceType.Normal = [0, 0, 1]815 self.representationX = simple.Show(self.sliceX)816 self.representationY = simple.Show(self.sliceY)817 self.representationZ = simple.Show(self.sliceZ)818 self.representationX.DiffuseColor = self.ds.foreground819 self.representationY.DiffuseColor = self.ds.foreground820 self.representationZ.DiffuseColor = self.ds.foreground821 self.updateRepresentation(self.reprMode)822 self.updateColorBy(self.colorBy[1], self.colorBy[0])823 else:824 self.sliceX.Input = inpt825 self.sliceY.Input = inpt826 self.sliceZ.Input = inpt827 self.representationX.Visibility = self.visible[0]828 self.representationY.Visibility = self.visible[1]829 self.representationZ.Visibility = self.visible[2]830 if not enable and self.representationX:831 self.representationX.Visibility = 0832 self.representationY.Visibility = 0833 self.representationZ.Visibility = 0834 self.enabled = enable835 simple.Render()836 self.getApplication().InvokeEvent('PushRender')837# =============================================================================838#839# Multi-Slice management840#841# =============================================================================842class LightVizMultiSlice(pv_protocols.ParaViewWebProtocol):843 def __init__(self, dataset_manager, clip):844 super(LightVizMultiSlice, self).__init__()845 self.ds = dataset_manager846 self.clip = clip847 self.slice = None848 self.representation = None849 self.normal = 0850 self.slicePositions = []851 self.reprMode = "Surface"852 self.colorBy = ('__SOLID__', '__SOLID__')853 self.useClippedInput = False854 dataset_manager.addListener(self)855 def dataChanged(self):856 self.updateRepresentation('Surface')857 self.updateColorBy(self.ds.activeMeta["data"]["arrays"][0]["name"], self.ds.activeMeta["data"]["arrays"][0]["location"])858 bounds = self.ds.activeMeta['data']['bounds']859 center = [(bounds[i*2] + bounds[i*2+1])*0.5 for i in range(3)]860 self.updateNormal(0)861 self.updateSlicePositions([center[0]])862 if self.slice:863 self.slice.Input = self.ds.getInput()864 self.representation.Visibility = 0865 def setForegroundColor(self, foreground):866 if self.representation:867 self.representation.DiffuseColor = foreground868 @exportRpc("light.viz.mslice.useclipped")869 def setUseClipped(self, useClipped):870 if self.slice:871 if not self.useClippedInput and useClipped:872 self.slice.Input = self.clip.getOutput()873 elif self.useClippedInput and not useClipped:874 self.slice.Input = self.ds.getInput()875 self.useClippedInput = useClipped876 self.getApplication().InvokeEvent('PushRender')877 @exportRpc("light.viz.mslice.getstate")878 def getState(self):879 ret = {880 'enabled': False,881 'representation': self.reprMode,882 'color': self.colorBy,883 'positions': self.slicePositions,884 'normal': str(self.normal),885 "use_clipped": self.useClippedInput,886 }887 if self.representation:888 ret["enabled"] = True if self.representation.Visibility else False889 return ret890 @exportRpc("light.viz.mslice.normal")891 def updateNormal(self, normalAxis):892 self.normal = int(normalAxis)893 if self.slice:894 normal = [0, 0, 0]895 normal[self.normal] = 1896 self.slice.SliceType.Normal = normal897 self.getApplication().InvokeEvent('PushRender')898 @exportRpc("light.viz.mslice.positions")899 def updateSlicePositions(self, positions):900 self.slicePositions = positions;901 if self.slice:902 self.slice.SliceOffsetValues = positions903 self.getApplication().InvokeEvent('PushRender')904 @exportRpc("light.viz.mslice.representation")905 def updateRepresentation(self, mode):906 self.reprMode = mode907 if self.representation:908 self.representation.Representation = mode909 self.getApplication().InvokeEvent('PushRender')910 @exportRpc("light.viz.mslice.color")911 def updateColorBy(self, field, location):912 self.colorBy = (location, field)913 if self.representation:914 if field == '__SOLID__':915 self.representation.ColorArrayName = ''916 else:917 simpleColorBy(self.representation, self.colorBy)918 # Update data array range919 lutProxy = self.representation.LookupTable920 for array in self.ds.activeMeta['data']['arrays']:921 if array['name'] == field and array['location'] == location:922 vtkSMTransferFunctionProxy.RescaleTransferFunction(lutProxy.SMProxy, array['range'][0], array['range'][1], False)923 simple.Render()924 self.getApplication().InvokeEvent('PushRender')925 @exportRpc("light.viz.mslice.enable")926 def enableSlice(self, enable):927 if enable and self.ds.getInput():928 inpt = self.ds.getInput() if not self.useClippedInput else self.clip.getOutput()929 if not self.slice:930 self.slice = simple.Slice(Input=inpt)931 normal = [0, 0, 0]932 normal[self.normal] = 1933 self.slice.SliceType.Normal = normal934 self.slice.SliceOffsetValues = self.slicePositions935 self.representation = simple.Show(self.slice)936 self.representation.Representation = self.reprMode937 self.representation.DiffuseColor = self.ds.foreground938 self.updateColorBy(self.colorBy[1], self.colorBy[0])939 else:940 self.slice.Input = inpt941 self.representation.Visibility = 1942 if not enable and self.representation:943 self.representation.Visibility = 0944 simple.Render()945 self.getApplication().InvokeEvent('PushRender')946# =============================================================================947#948# Streamline management949#950# =============================================================================951class LightVizStreamline(pv_protocols.ParaViewWebProtocol):952 def __init__(self, dataset_manager):953 super(LightVizStreamline, self).__init__()954 self.ds = dataset_manager955 self.streamline = None956 self.tube = None957 self.seed = None958 self.seedRep = None959 self.position = [ 0.0, 0.0, 0.0 ]960 self.representation = None961 self.reprMode = 'Surface'962 self.colorBy = ('__SOLID__', '__SOLID__')963 self.vector = None964 self.numPoints = 50965 self.radius = 1.0966 dataset_manager.addListener(self)967 def dataChanged(self):968 bounds = self.ds.activeMeta['data']['bounds']969 length = [bounds[i*2+1] - bounds[i*2] for i in range(3)]970 self.updateRepresentation('Surface')971 self.updateColorBy('__SOLID__', '__SOLID__')972 self.vector = None973 self.updateRadius(min(length) / 8.0)974 self.updatePosition((bounds[1] + bounds[0])/2.0,975 (bounds[3] + bounds[2])/2.0,976 (bounds[5] + bounds[4])/2.0)977 for array in self.ds.activeMeta['data']['arrays']:978 if array['dimension'] == 3:979 self.vector = array['name']980 break981 if self.streamline:982 self.streamline.Input = self.ds.getInput()983 if self.representation:984 self.representation.Visibility = 0985 def setForegroundColor(self, foreground):986 if self.representation:987 self.representation.DiffuseColor = foreground988 @exportRpc("light.viz.streamline.getstate")989 def getState(self):990 ret = {991 "representation": self.reprMode,992 "color": self.colorBy,993 "enabled": False,994 "xPosition": self.position[0],995 "yPosition": self.position[1],996 "zPosition": self.position[2],997 "vector": self.vector,998 "numPoints": self.numPoints,999 "radius": self.radius,1000 }1001 if self.representation:1002 ret["enabled"] = self.representation.Visibility == 1,1003 if not isinstance(ret["enabled"], bool):1004 ret["enabled"] = ret["enabled"][0]1005 return ret1006 @exportRpc("light.viz.streamline.position")1007 def updatePosition(self, x, y, z):1008 self.position = [x, y, z]1009 if self.streamline:1010 self.seed.Center = self.position1011 self.streamline.SeedType.Center = self.position1012 self.getApplication().InvokeEvent('PushRender')1013 @exportRpc("light.viz.streamline.vector")1014 def updateVector(self, vectorName):1015 self.vector = vectorName1016 if self.streamline:1017 self.streamline.Vectors = ['POINTS', self.vector]1018 self.getApplication().InvokeEvent('PushRender')1019 @exportRpc("light.viz.streamline.numpoints")1020 def updateNumPoints(self, num):1021 self.numPoints = int(num)1022 if self.streamline:1023 self.streamline.SeedType.NumberOfPoints = self.numPoints1024 self.getApplication().InvokeEvent('PushRender')1025 @exportRpc("light.viz.streamline.radius")1026 def updateRadius(self, rad):1027 self.radius = float(rad)1028 if self.streamline:1029 self.seed.Radius = self.radius1030 self.streamline.SeedType.Radius = self.radius1031 self.getApplication().InvokeEvent('PushRender')1032 @exportRpc("light.viz.streamline.representation")1033 def updateRepresentation(self, mode):1034 self.reprMode = mode1035 if self.representation:1036 self.representation.Representation = mode1037 self.getApplication().InvokeEvent('PushRender')1038 @exportRpc("light.viz.streamline.color")1039 def updateColorBy(self, field, location):1040 self.colorBy = (location, field)1041 if self.representation:1042 if field == '__SOLID__':1043 self.representation.ColorArrayName = ''1044 else:1045 simpleColorBy(self.representation, self.colorBy)1046 # Update data array range1047 lutProxy = self.representation.LookupTable1048 for array in self.ds.activeMeta['data']['arrays']:1049 if array['name'] == field and array['location'] == location:1050 vtkSMTransferFunctionProxy.RescaleTransferFunction(lutProxy.SMProxy, array['range'][0], array['range'][1], False)1051 simple.Render()1052 self.getApplication().InvokeEvent('PushRender')1053 @exportRpc("light.viz.streamline.enable")1054 def enableStreamline(self, enable):1055 if enable and self.ds.getInput():1056 if not self.streamline:1057 bounds = self.ds.activeMeta['data']['bounds']1058 length = [bounds[i*2+1] - bounds[i*2] for i in range(3)]1059 self.streamline = simple.StreamTracer(Input=self.ds.getInput(), SeedType='Point Source')1060 self.streamline.Vectors = ['POINTS', self.vector]1061 self.streamline.MaximumStreamlineLength = 2 * max(length)1062 self.streamline.SeedType.Center = self.position1063 self.streamline.SeedType.Radius = self.radius1064 self.streamline.SeedType.NumberOfPoints = self.numPoints1065 if not self.seed:1066 self.seed = simple.Sphere()1067 self.seed.Center = self.position1068 self.seed.Radius = self.radius1069 self.seedRep = simple.Show(Input=self.seed)1070 self.seedRep.Representation = 'Wireframe'1071 self.seedRep.DiffuseColor = [1, 1, 1]1072 self.seedRep.Visibility = 01073 self.tube = simple.Tube(Input=self.streamline)1074 self.tube.Capping = 11075 self.tube.Radius = min(length) / 100.01076 else:1077 self.streamline.Input = self.ds.getInput()1078 if not self.representation:1079 self.representation = simple.Show(self.tube)1080 self.representation.Representation = self.reprMode1081 self.representation.DiffuseColor = self.ds.foreground1082 self.updateColorBy(self.colorBy[1], self.colorBy[0])1083 self.representation.Visibility = 11084 if not enable and self.representation:1085 self.representation.Visibility = 01086 simple.Render()1087 self.getApplication().InvokeEvent('PushRender')1088 @exportRpc("light.viz.streamline.seed.show")1089 def showSeed(self, enable):1090 if enable and self.ds.getInput():1091 self.seedRep.Visibility = 11092 elif (not enable) and self.seedRep:1093 self.seedRep.Visibility = 01094 self.getApplication().InvokeEvent('PushRender')1095 @exportRpc("light.viz.streamline.seed.update")1096 def updateSeed(self, position, radius):1097 if self.seed:1098 self.seed.Center = position1099 self.seed.Radius = radius1100 self.getApplication().InvokeEvent('PushRender')1101# =============================================================================1102#1103# Volume management1104#1105# =============================================================================1106class LightVizVolume(pv_protocols.ParaViewWebProtocol):1107 def __init__(self, dataset_manager, clip):1108 super(LightVizVolume, self).__init__()1109 self.ds = dataset_manager1110 self.clip = clip1111 self.passThrough = None1112 self.representation = None1113 self.colorBy = ('__SOLID__', '__SOLID__')1114 self.useClippedInput = False1115 dataset_manager.addListener(self)1116 def dataChanged(self):1117 self.updateColorBy(self.ds.activeMeta["data"]["arrays"][0]["name"], self.ds.activeMeta["data"]["arrays"][0]["location"])1118 if self.passThrough:1119 simple.Delete(self.passThrough)1120 self.passThrough = None1121 simple.Delete(self.representation)1122 self.representation = None1123 def setForegroundColor(self, foreground):1124 pass1125 @exportRpc("light.viz.volume.useclipped")1126 def setUseClipped(self, useClipped):1127 if self.useClippedInput != useClipped:1128 self.useClippedInput = useClipped1129 if self.passThrough:1130 oldVisibility = self.representation.Visibility1131 simple.Delete(self.representation);1132 self.representation = None1133 simple.Delete(self.passThrough);1134 self.passThrough = None1135 self.enableVolume(oldVisibility)1136 self.getApplication().InvokeEvent('PushRender')1137 @exportRpc("light.viz.volume.getstate")1138 def getState(self):1139 ret = {1140 'enabled': False,1141 'color': self.colorBy,1142 "use_clipped": self.useClippedInput,1143 }1144 if self.representation:1145 ret["enabled"] = True if self.representation.Visibility else False1146 return ret1147 @exportRpc("light.viz.volume.representation")1148 def updateRepresentation(self, mode):1149 pass # It is a volume rendering, so that is the only valid representation1150 @exportRpc("light.viz.volume.color")1151 def updateColorBy(self, field, location):1152 self.colorBy = (location, field)1153 if self.representation:1154 if field == '__SOLID__':1155 self.representation.ColorArrayName = ''1156 else:1157 simpleColorBy(self.representation, self.colorBy)1158 # Update data array range1159 lutProxy = self.representation.LookupTable1160 pwfProxy = self.representation.ScalarOpacityFunction1161 for array in self.ds.activeMeta['data']['arrays']:1162 if array['name'] == field and array['location'] == location:1163 vtkSMTransferFunctionProxy.RescaleTransferFunction(lutProxy.SMProxy, array['range'][0], array['range'][1], False)1164 if pwfProxy:1165 vtkSMTransferFunctionProxy.RescaleTransferFunction(pwfProxy.SMProxy, array['range'][0], array['range'][1], False)1166 simple.Render()1167 self.getApplication().InvokeEvent('PushRender')1168 @exportRpc("light.viz.volume.enable")1169 def enableVolume(self, enable):1170 if enable and self.ds.getInput():1171 inpt = self.ds.getInput() if not self.useClippedInput else self.clip.getOutput()1172 if not self.passThrough:1173 self.passThrough = simple.Calculator(Input=inpt)1174 else:1175 self.passThrough.Input = inpt1176 if not self.representation:1177 self.representation = simple.Show(self.passThrough)1178 self.representation.Representation = 'Volume'1179 self.updateColorBy(self.colorBy[1], self.colorBy[0])1180 self.representation.Visibility = 11181 if not enable and self.representation:1182 self.representation.Visibility = 01183 simple.Render()1184 self.getApplication().InvokeEvent('PushRender')1185# =============================================================================1186#1187# Threshold management1188#1189# =============================================================================1190class LightVizThreshold(pv_protocols.ParaViewWebProtocol):1191 def __init__(self, dataset_manager, clip):1192 super(LightVizThreshold, self).__init__()1193 self.ds = dataset_manager1194 self.clip = clip1195 self.thresh = None1196 self.representation = None1197 self.colorBy = ('__SOLID__', '__SOLID__')1198 self.useClippedInput = False1199 self.rangeMin = 01200 self.rangeMax = 11201 self.thresholdBy = None1202 dataset_manager.addListener(self)1203 def dataChanged(self):1204 self.rangeMin = self.ds.activeMeta['data']['arrays'][0]['range'][0]1205 self.rangeMax = self.ds.activeMeta['data']['arrays'][0]['range'][1]1206 self.thresholdBy = self.ds.activeMeta['data']['arrays'][0]['name']1207 if self.thresh:1208 simple.Delete(self.thresh)1209 self.thresh = None1210 if self.representation:1211 simple.Delete(self.representation)1212 self.representation = None1213 self.updateColorBy('__SOLID__', '__SOLID__')1214 def setForegroundColor(self, foreground):1215 if self.representation:1216 self.representation.DiffuseColor = foreground1217 @exportRpc("light.viz.threshold.useclipped")1218 def setUseClipped(self, useClipped):1219 if self.useClippedInput != useClipped:1220 self.useClippedInput = useClipped1221 self.getApplication().InvokeEvent('PushRender')1222 @exportRpc("light.viz.threshold.getstate")1223 def getState(self):1224 ret = {1225 'enabled': False,1226 'color': self.colorBy,1227 'rangeMin': self.rangeMin,1228 'rangeMax': self.rangeMax,1229 'thresholdBy': self.thresholdBy,1230 'use_clipped': self.useClippedInput,1231 }1232 if self.representation:1233 ret["enabled"] = True if self.representation.Visibility else False1234 return ret1235 @exportRpc("light.viz.threshold.representation")1236 def updateRepresentation(self, mode):1237 self.reprMode = mode1238 if self.representation:1239 self.representation.Representation = mode1240 self.getApplication().InvokeEvent('PushRender')1241 @exportRpc("light.viz.threshold.range")1242 def updateRange(self, rangeMin, rangeMax):1243 self.rangeMin = rangeMin1244 self.rangeMax = rangeMax1245 if self.thresh:1246 self.thresh.ThresholdRange = [self.rangeMin, self.rangeMax]1247 self.getApplication().InvokeEvent('PushRender')1248 @exportRpc("light.viz.threshold.color")1249 def updateColorBy(self, field, location):1250 self.colorBy = (location, field)1251 if self.representation:1252 if field == '__SOLID__':1253 self.representation.ColorArrayName = ''1254 else:1255 simpleColorBy(self.representation, self.colorBy)1256 # Update data array range1257 lutProxy = self.representation.LookupTable1258 pwfProxy = self.representation.ScalarOpacityFunction1259 for array in self.ds.activeMeta['data']['arrays']:1260 if array['name'] == field and array['location'] == location:1261 vtkSMTransferFunctionProxy.RescaleTransferFunction(lutProxy.SMProxy, array['range'][0], array['range'][1], False)1262 if pwfProxy:1263 vtkSMTransferFunctionProxy.RescaleTransferFunction(pwfProxy.SMProxy, array['range'][0], array['range'][1], False)1264 simple.Render()1265 self.getApplication().InvokeEvent('PushRender')1266 @exportRpc("light.viz.threshold.by")1267 def updateThresholdBy(self, field):1268 self.thresholdBy = field1269 if self.thresh:1270 self.thresh.Scalars = ['POINTS', field]1271 # simple.SaveState('/tmp/myteststate.pvsm')1272 self.getApplication().InvokeEvent('PushRender')1273 @exportRpc("light.viz.threshold.enable")1274 def enableThreshold(self, enable):1275 if enable and self.ds.getInput():1276 inpt = self.ds.getInput() if not self.useClippedInput else self.clip.getOutput()1277 if not self.thresh:1278 self.thresh = simple.Threshold(Input=inpt)1279 self.thresh.ThresholdRange = [ self.rangeMin, self.rangeMax ]1280 self.thresh.Scalars = ['POINTS', self.thresholdBy]1281 self.representation = simple.Show(self.thresh)1282 self.representation.Visibility = 11283 if not enable and self.representation:1284 self.representation.Visibility = 01285 simple.Render()...

Full Screen

Full Screen

api.py

Source:api.py Github

copy

Full Screen

...17 return self.flowEngine.getState()18 @exportRpc("flow.zoom.wheel")19 def zoom(self, event):20 if 'Start' in event["type"]:21 self.getApplication().InvokeEvent('StartInteractionEvent')22 view = self.getView(event['view'])23 if view and 'spinY' in event:24 view.GetActiveCamera().Zoom(1.0 - event['spinY'] / 10.0)25 if 'End' in event["type"]:26 self.getApplication().InvokeEvent('EndInteractionEvent')27 @exportRpc("flow.reset.camera")28 def resetCamera(self, view_id):29 view = self.getView(view_id)30 simple.ResetCamera(view)31 view.CenterOfRotation = view.CameraFocalPoint32 self.getApplication().InvokeEvent('UpdateEvent')33 @exportRpc("flow.color.by")34 def colorBy(self, repId, field):35 proxy = self.mapIdToProxy(repId)36 self.flowEngine.colorBy(proxy, field)37 self.getApplication().InvokeEvent('UpdateEvent')38 return str(proxy.ColorArrayName[1])39 @exportRpc("flow.time.update")40 def updateTime(self, time):41 t = self.flowEngine.setTime(time)42 self.getApplication().InvokeEvent('UpdateEvent')43 return t44 @exportRpc("flow.subsurface.slice.update")45 def sliceSubSurface(self, sliceIdx):46 self.flowEngine.updateSubSurfaceSlice(sliceIdx)47 self.getApplication().InvokeEvent('UpdateEvent')48 @exportRpc("flow.color.mode.update")49 def updateColorMode(self, name, value):50 self.flowEngine.updateColorMode(name, value)51 self.getApplication().InvokeEvent('UpdateEvent')52 @exportRpc("flow.color.rescale")53 def rescaleColor(self, name):54 self.flowEngine.rescaleColorRange(name)55 self.getApplication().InvokeEvent('UpdateEvent')56 @exportRpc("flow.water.table.show")57 def showWaterTableDepth(self, visibility):58 self.flowEngine.showWaterTableDepth(visibility)59 self.getApplication().InvokeEvent('UpdateEvent')60 @exportRpc("flow.water.table.scale")61 def updateWaterTableDepthScaling(self, scale):62 self.flowEngine.updateWaterTableDepthScaling(scale)63 self.getApplication().InvokeEvent('UpdateEvent')64 def nextTime(self):65 if not self.playing:66 return67 currentTime = self.flowEngine.time68 newTime = self.flowEngine.goToNextTime()69 self.playing = currentTime != newTime70 if self.playing:71 self.flowEngine.render()72 reactor.callLater(0.1, lambda: self.nextTime())73 self.publish('flow.animation.state', {74 'time': newTime,75 'playing': self.playing,76 })77 if not self.playing:78 self.updateTimeAnimation(False)79 @exportRpc("flow.time.animation.set")80 def updateTimeAnimation(self, playing):81 self.playing = playing82 if playing:83 self.getApplication().InvokeEvent('StartInteractionEvent')84 self.nextTime()85 else:86 self.getApplication().InvokeEvent('EndInteractionEvent')87 @exportRpc("flow.water.balance.get")88 def getGlobalTimeWaterBalance(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful