def getComponentName(actor): global componentIndex srcs = simple.GetSources() duplicates = {} errs = [] for key, val in srcs.items(): # Prevent name duplication nameToUse = key[0] if nameToUse in duplicates: count = 1 newName = '%s (%d)' % (nameToUse, count) while newName in duplicates: count += 1 newName = '%s (%d)' % (nameToUse, count) nameToUse = newName duplicates[nameToUse] = True try: actorRep = simple.GetRepresentation(val).GetClientSideObject().GetActiveRepresentation().GetActor() if actor == actorRep: return nameToUse except AttributeError as err: errs.append(err) #print("Handling error: ", err) nameToUse = '%d' % componentIndex componentIndex += 1 return nameToUse
def getComponentName(actor): global componentIndex srcs = simple.GetSources() duplicates = {} for key, val in srcs.items(): # Prevent name duplication nameToUse = key[0] if nameToUse in duplicates: count = 1 newName = '%s (%d)' % (nameToUse, count) while newName in duplicates: count += 1 newName = '%s (%d)' % (nameToUse, count) nameToUse = newName duplicates[nameToUse] = True actorRep = simple.GetRepresentation( val).GetClientSideObject().GetActiveRepresentation().GetActor() if actor == actorRep: return nameToUse nameToUse = '%d' % componentIndex componentIndex += 1 return nameToUse
def insert(self, document): if not self.view: return if self.CaptureDepth: simple.Render() image = self.view.CaptureDepthBuffer() idata = numpy_support.vtk_to_numpy(image) rw = self.view.GetRenderWindow() width, height = rw.GetSize() try: imageslice = idata.reshape(height, width) except ValueError: imageslice = None #import Image #img = Image.fromarray(imageslice) #img.show() #try: # input("Press enter to continue ") #except NameError: # pass document.data = imageslice self.CaptureDepth = False else: imageslice = None if self.CaptureLuminance and not self.UsingGL2: try: rep = simple.GetRepresentation() if rep != None: rep.DiffuseColor = [1, 1, 1] rep.ColorArrayName = None except ValueError: pass image = self.view.CaptureWindow(1) ext = image.GetExtent() width = ext[1] - ext[0] + 1 height = ext[3] - ext[2] + 1 imagescalars = image.GetPointData().GetScalars() idata = numpy_support.vtk_to_numpy(imagescalars) idata = self.rgb2grey(idata, height, width) imageslice = np.dstack((idata, idata, idata)) image.UnRegister(None) else: image = self.view.CaptureWindow(1) ext = image.GetExtent() width = ext[1] - ext[0] + 1 height = ext[3] - ext[2] + 1 imagescalars = image.GetPointData().GetScalars() idata = numpy_support.vtk_to_numpy(imagescalars) imageslice = idata.reshape(height, width, 3) image.UnRegister(None) #import Image #img = Image.fromarray(imageslice) #img.show() #try: # input("Press enter to continue ") #except NameError: # pass document.data = imageslice if self.iSave: super(ImageExplorer, self).insert(document)
def add_scene_item(scene, name, proxy, view): hasNormal = False hasColor = False colors = {} representation = {} rep = simple.GetRepresentation(proxy, view) # Skip hidden object or volume if not rep.Visibility or rep.Representation == 'Volume': return for prop in ['Representation']: representation[prop] = rep.GetProperty(prop).GetData() pdInfo = proxy.GetPointDataInformation() numberOfPointArrays = pdInfo.GetNumberOfArrays() for idx in range(numberOfPointArrays): array = pdInfo.GetArray(idx) rangeValues = array.GetRange(-1) if array.Name == 'Normals': hasNormal = True if array.Name not in ['vtkValidPointMask', 'Normals']: hasColor = True if rangeValues[0] == rangeValues[1]: colors[array.Name] = {'constant': rangeValues[0]} else: colors[array.Name] = { 'location': 'POINT_DATA', 'range': [i for i in rangeValues] } # Get information about cell data arrays cdInfo = proxy.GetCellDataInformation() numberOfCellArrays = cdInfo.GetNumberOfArrays() for idx in range(numberOfCellArrays): array = cdInfo.GetArray(idx) hasColor = True colors[array.Name] = { 'location': 'CELL_DATA', 'range': array.GetRange(-1) } # Make sure Normals are available if lighting by normals source = proxy if not hasColor or rep.Representation == 'Outline': colors = {'solid': {'constant': 0}} elif 'normal' in scene['light'] and not hasNormal: rep.Visibility = 0 surface = simple.ExtractSurface(Input=proxy) surfaceWithNormals = simple.GenerateSurfaceNormals(Input=surface) source = surfaceWithNormals scene['scene'].append({ 'name': name, 'source': source, 'colors': colors, 'representation': representation })
def get_source_lookuptable_section(source): luts = {} rep = simple.GetRepresentation(source) name = rep.ColorArrayName[1] lut = rep.LookupTable if lut: controlpoints = build_control_points(lut.RGBPoints) luts[name] = {'controlpoints': controlpoints} return luts
def export_contour_exploration_geometry(destinationPath, **kwargs): values = [int(v) for v in kwargs['multiValue'].split(',')] contour = None for key, value in py2to3.iteritems(simple.GetSources()): if key[0] == 'Contour': contour = value if contour: sections = {'LookupTables': get_source_lookuptable_section(contour)} scalarName = simple.GetRepresentation(contour).ColorArrayName[1] originalValue = [v for v in contour.Value] sceneDescription = { 'scene': [{ 'name': 'Contour', 'source': contour, 'colors': { scalarName: { 'constant': 0, 'location': 'POINT_DATA' } } }] } dsb = VTKGeometryDataSetBuilder(destinationPath, sceneDescription, {}, sections) dsb.getDataHandler().registerArgument(priority=1, name='contour', values=values, ui='slider', loop='modulo') dsb.start() scalarContainer = sceneDescription['scene'][0]['colors'][scalarName] for contourValue in dsb.getDataHandler().contour: contour.Value = [contourValue] scalarContainer['constant'] = contourValue dsb.writeData() dsb.stop() # Patch data range patch_data_range(destinationPath) # Reset to original state contour.Value = originalValue else: print('Can not export Contour geometry without Contour(s)')
def getAllNames(): actorNameMapping = {} srcs = simple.GetSources() duplicates = {} for key, val in srcs.items(): # Prevent name duplication nameToUse = key[0] if nameToUse in duplicates: count = 1 newName = '%s (%d)' % (nameToUse, count) while newName in duplicates: count += 1 newName = '%s (%d)' % (nameToUse, count) nameToUse = newName duplicates[nameToUse] = True actorRep = simple.GetRepresentation(val).GetClientSideObject().GetActiveRepresentation().GetActor() actorNameMapping[nameToUse] = actorRep return actorNameMapping
def getAllNames(): actorNameMapping = {} srcs = simple.GetSources() duplicates = {} for key, val in srcs.items(): # Prevent name duplication nameToUse = key[0] if nameToUse in duplicates: count = 1 newName = "%s (%d)" % (nameToUse, count) while newName in duplicates: count += 1 newName = "%s (%d)" % (nameToUse, count) nameToUse = newName duplicates[nameToUse] = True representation = simple.GetRepresentation(val) if representation: vtkRepInstance = representation.GetClientSideObject() if "GetActiveRepresentation" in dir(vtkRepInstance): actorRep = vtkRepInstance.GetActiveRepresentation().GetActor() actorNameMapping[nameToUse] = actorRep return actorNameMapping
def insert(self, document): """overridden to use paraview to generate an image and create a the document for it""" if not self.view: return if self.CaptureDepth: # Depth capture 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 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 != 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)
def updateScatterPlot(self, config): updateAxes = False updateColormap = False sprites = config['usePointSprites'] showMesh = config['showMesh'] if not self.dataTable: # initialize everything self.dataTable = self.divvyProtocol.getDataWithSelection() if self.divvyProtocol.getMesh(): self.dataMesh = simple.TrivialProducer() self.dataMesh.GetClientSideObject().SetOutput( self.divvyProtocol.getMesh()) # copy data from the main protocol, and set up pipelilne self.trivProducer = simple.TrivialProducer() self.trivProducer.GetClientSideObject().SetOutput(self.dataTable) self.tableToPoints = simple.TableToPoints(Input=self.trivProducer) self.tableToPoints.XColumn = config['x'] self.tableToPoints.YColumn = config['y'] self.tableToPoints.ZColumn = config['z'] self.tableToPoints.KeepAllDataArrays = 1 self.tableToPoints.UpdatePipeline() self.outlineFilter = simple.Outline(Input=self.tableToPoints) self.outlineRepresentation = simple.GetRepresentation( self.outlineFilter, self.renderView) self.outlineRepresentation.DiffuseColor = [0.0, 0.0, 0.0] self.outlineRepresentation.Visibility = 0 self.representation = simple.GetRepresentation( self.tableToPoints, self.renderView) self.representation.Representation = 'Surface' self.representation.PointSize = 5 self.representation.Opacity = 1.0 self.representation.InterpolateScalarsBeforeMapping = 0 self.representation.Visibility = 1 self.renderView.AxesGrid = 'GridAxes3DActor' self.renderView.AxesGrid.Visibility = 1 self.renderView.AxesGrid.XTitleColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.YTitleColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.ZTitleColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.GridColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.ShowGrid = 1 self.renderView.AxesGrid.XLabelColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.YLabelColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.ZLabelColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.DataScale = [1, 1, 1] self.renderView.OrientationAxesVisibility = 0 self.renderView.Background = [1.0, 1.0, 1.0] self.renderView.BackgroundColorMode = 0 # PV 5.10 self.renderView.UseColorPaletteForBackground = 0 # create a LUT, if needed if 'colorBy' in config: vtkSMPVRepresentationProxy.SetScalarColoring( self.representation.SMProxy, config['colorBy'], 0) vtkSMPVRepresentationProxy.RescaleTransferFunctionToDataRange( self.representation.SMProxy, config['colorBy'], 0, False, True) updateAxes = True updateColormap = True else: # update if self.arrays['x'] != config['x'] or \ self.arrays['y'] != config['y'] or \ self.arrays['z'] != config['z']: self.tableToPoints.XColumn = config['x'] self.tableToPoints.YColumn = config['y'] self.tableToPoints.ZColumn = config['z'] self.dataTable.Modified() updateAxes = True if 'colorBy' in config and ( config['colorBy'] == USER_SELECTION or \ config['colorBy'] != \ vtkSMPVRepresentationProxy.GetArrayInformationForColorArray(self.representation.SMProxy).GetName() or config['colorMapName'] != self._colorMapName) : updateColormap = True if updateAxes: self.arrays['x'] = config['x'] self.arrays['y'] = config['y'] self.arrays['z'] = config['z'] self.renderView.AxesGrid.XTitle = config['x'] self.renderView.AxesGrid.YTitle = config['y'] self.renderView.AxesGrid.ZTitle = config['z'] self.updateAxis(showMesh and self.dataMesh) if updateColormap: vtkSMPVRepresentationProxy.SetScalarColoring( self.representation.SMProxy, config['colorBy'], 0) if config['colorBy'] == USER_SELECTION: # Coloring by the user selection needs special handling if not self._selectionLutInitialized: self.updateUserSelectionLutProperties() else: vtkSMPVRepresentationProxy.RescaleTransferFunctionToDataRange( self.representation.SMProxy, config['colorBy'], 0, False, True) self.colorManager.selectColorMap( self.representation.GetGlobalIDAsString(), config['colorMapName']) sizeRange = [1.0, 3.0] constPointSize = 3.0 pointSize = 2.0 try: sizeRange = [ float(config['pointSizeMin']), float(config['pointSizeMax']) ] constPointSize = float(config['constantPointSize']) pointSize = float(config['pointSize']) except: print('Failed conversion', config['pointSizeMin'], config['pointSizeMax'], config['constantPointSize'], config['pointSize']) pass # Sprites are the ParaView Point Gaussian representation, and allow shader-based point drawing. if sprites: self.representation.Visibility = 0 self.representation.Representation = 'Point Gaussian' # Needed for ParaView 5.4 - not sure if it'll mess up older ones. self.representation.ShaderPreset = 'Custom' reprInfo = self.representationMap['Black-edged circle'] if config['pointRepresentation'] and config[ 'pointRepresentation'] is not '': reprInfo = self.representationMap[ config['pointRepresentation']] self.representation.GaussianRadius = reprInfo['radius'] self.representation.CustomShader = reprInfo['shader'] # vary point size with array, maybe. if config['pointSizeBy'] and config['pointSizeBy'] != '': # sizeRange = [float(config['pointSizeMin']), float(config['pointSizeMax']) ] dataRange = self.dataTable.GetColumnByName( config['pointSizeBy']).GetRange() scaleFunction = str(config['pointSizeFunction']) if config['pointSizeBy'] == USER_SELECTION: if sizeRange[0] != self.userSelPointSizeRange[ 0] or sizeRange[1] != self.userSelPointSizeRange[1]: self.userSelPointSizeRange[0] = sizeRange[0] self.userSelPointSizeRange[1] = sizeRange[1] self.updateUserSelectionLutProperties() self.scaleTransferFunction.Points = self.userSelScalePoints else: self.scaleTransferFunction.Points = buildLinearPiecewiseFunctionPoints( dataRange, sizeRange, scaleFunction) self.representation.ScaleTransferFunction = self.scaleTransferFunction self.representation.SetScaleArray = config['pointSizeBy'] self.representation.ScaleByArray = 1 else: self.representation.GaussianRadius = constPointSize / 3.0 self.representation.ScaleByArray = 0 # vary opacity with array, maybe. if config['opacityBy'] and config['opacityBy'] != '' and config['opacityBy'] != USER_SELECTION \ and (config['colorBy'] != USER_SELECTION): dataRange = self.dataTable.GetColumnByName( config['opacityBy']).GetRange() opacityFunction = str(config['opacityFunction']) self.opacityTransferFunction.Points = buildLinearPiecewiseFunctionPoints( dataRange, [0.0, 1.0], opacityFunction) self.representation.OpacityTransferFunction = self.opacityTransferFunction self.representation.OpacityArray = config['opacityBy'] self.representation.OpacityByArray = 1 else: self.representation.OpacityByArray = 0 self.representation.Opacity = 1.0 else: self.representation.Representation = 'Surface' self.representation.PointSize = pointSize self.representation.Opacity = 1.0 self.representation.Visibility = 1 # Mesh handling if self.dataMesh: if showMesh: if not self.meshRepresentation: self.meshRepresentation = simple.Show( self.dataMesh, self.renderView) self.meshRepresentation.Opacity = 0.5 self.meshRepresentation.Visibility = 1 self.updateAxis(True) elif self.meshRepresentation: self.meshRepresentation.Visibility = 0 self.getApplication().InvokeEvent('UpdateEvent') return {'success': True}
def updateScatterPlot(self, config): updateAxes = False updateColormap = False if not self.dataTable: # initialize everything self.dataTable = vtk.vtkTable() self.dataTable.ShallowCopy(self.divvyProtocol.getData()) # copy data from the main protocol, and set up pipelilne trivProducer = simple.TrivialProducer() trivProducer.GetClientSideObject().SetOutput(self.dataTable) self.tableToPoints = simple.TableToPoints(Input=trivProducer) self.tableToPoints.XColumn = config['x'] self.tableToPoints.YColumn = config['y'] self.tableToPoints.ZColumn = config['z'] self.tableToPoints.KeepAllDataArrays = 1 self.tableToPoints.UpdatePipeline() self.representation = simple.GetRepresentation( self.tableToPoints, self.renderView) self.representation.Representation = 'Surface' self.representation.PointSize = 5 self.representation.Opacity = 1.0 self.representation.Visibility = 1 self.renderView.AxesGrid = 'GridAxes3DActor' self.renderView.AxesGrid.Visibility = 1 self.renderView.AxesGrid.XTitleColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.YTitleColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.ZTitleColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.GridColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.ShowGrid = 1 self.renderView.AxesGrid.XLabelColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.YLabelColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.ZLabelColor = [0.0, 0.0, 0.0] self.renderView.AxesGrid.DataScale = [1, 1, 1] self.renderView.OrientationAxesVisibility = 0 self.renderView.Background = [1.0, 1.0, 1.0] # create a LUT, if needed if 'colorBy' in config: vtkSMPVRepresentationProxy.SetScalarColoring( self.representation.SMProxy, config['colorBy'], 0) vtkSMPVRepresentationProxy.RescaleTransferFunctionToDataRange( self.representation.SMProxy, config['colorBy'], 0, False, True) updateAxes = True updateColormap = True else: # update if self.arrays['x'] != config['x'] or \ self.arrays['y'] != config['y'] or \ self.arrays['z'] != config['z']: self.tableToPoints.XColumn = config['x'] self.tableToPoints.YColumn = config['y'] self.tableToPoints.ZColumn = config['z'] self.dataTable.Modified() updateAxes = True if 'colorBy' in config and ( config['colorBy'] == USER_SELECTION or \ config['colorBy'] != \ vtkSMPVRepresentationProxy.GetArrayInformationForColorArray(self.representation.SMProxy).GetName() or config['colorMapName'] != self._colorMapName) : updateColormap = True if updateAxes: self.arrays['x'] = config['x'] self.arrays['y'] = config['y'] self.arrays['z'] = config['z'] self.renderView.AxesGrid.XTitle = config['x'] self.renderView.AxesGrid.YTitle = config['y'] self.renderView.AxesGrid.ZTitle = config['z'] self.updateAxis() if updateColormap: vtkSMPVRepresentationProxy.SetScalarColoring( self.representation.SMProxy, config['colorBy'], 0) if config['colorBy'] == USER_SELECTION: # Coloring by the user selection needs special handling # if not self._selectionLutInitialized: # self.updateUserSelectionLutProperties() pass else: vtkSMPVRepresentationProxy.RescaleTransferFunctionToDataRange( self.representation.SMProxy, config['colorBy'], 0, False, True) self.colorManager.selectColorMap( self.representation.GetGlobalIDAsString(), config['colorMapName']) return {'success': True}