def _create_lookup_table(self, name, scalarRange, lutType): if lutType == 'blueToRed': return simple.GetLookupTableForArray( name, 1, RGBPoints=[ scalarRange[0], 0.231373, 0.298039, 0.752941, (scalarRange[0] + scalarRange[1]) / 2, 0.865003, 0.865003, 0.865003, scalarRange[1], 0.705882, 0.0156863, 0.14902 ], VectorMode='Magnitude', NanColor=[0.0, 0.0, 0.0], ColorSpace='Diverging', ScalarRangeInitialized=1.0, LockScalarRange=1) else: return simple.GetLookupTableForArray(name, 1, RGBPoints=[ scalarRange[0], 0.0, 0.0, 1.0, scalarRange[1], 1.0, 0.0, 0.0 ], VectorMode='Magnitude', NanColor=[0.0, 0.0, 0.0], ColorSpace='HSV', ScalarRangeInitialized=1.0, LockScalarRange=1)
def registerArray(self, name, number_of_components, range): key = self.getLutId(name, number_of_components) if self.range.has_key(key): minValue = min(range[0], self.luts[key].RGBPoints[0]) maxValue = max(range[1], self.luts[key].RGBPoints[-4]) self.range[key] = [minValue, maxValue] self.luts[key].RGBPoints = [minValue, 0, 0, 1, maxValue, 1, 0, 0] self.luts[key].VectorMode = 'Magnitude' self.luts[key].VectorComponent = 0 self.luts[key].ColorSpace = 'HSV' else: self.range[key] = range # ... fixme ... Create default lut with proper range/title/color scheme self.luts[key] = simple.GetLookupTableForArray( name, number_of_components) # Setup default config self.luts[key].RGBPoints = [range[0], 0, 0, 1, range[1], 1, 0, 0] self.luts[key].VectorMode = 'Magnitude' self.luts[key].VectorComponent = 0 self.luts[key].ColorSpace = 'HSV' self.scalarbars[key] = simple.CreateScalarBar( LookupTable=self.luts[key], TitleFontSize=6, LabelFontSize=6) self.scalarbars[key].Title = name self.scalarbars[key].Visibility = 0 self.scalarbars[key].Enabled = 0 # Add scalar bar to the view if self.view: self.view.Representations.append(self.scalarbars[key])
def test(): w = simple.Wavelet() dataRange = [40.0, 270.0] arrayName = ('POINT_DATA', 'RTData') fileGenerator = FileNameGenerator( '/tmp/iso', '{contourBy}_{contourValue}_{theta}_{phi}.jpg') cExplorer = ContourExplorer(fileGenerator, w, arrayName, dataRange, 25) proxy = cExplorer.getContour() rep = simple.Show(proxy) lut = simple.GetLookupTableForArray("RTData", 1, RGBPoints=[ 43.34006881713867, 0.23, 0.299, 0.754, 160.01158714294434, 0.865, 0.865, 0.865, 276.68310546875, 0.706, 0.016, 0.15 ]) rep.LookupTable = lut rep.ColorArrayName = arrayName view = simple.Render() exp = ThreeSixtyImageStackExporter(fileGenerator, view, [0, 0, 0], 100, [0, 0, 1], [30, 45]) for progress in cExplorer: exp.UpdatePipeline() print progress
def _absarg2png(filenames): """Create images of |psi|^2 and arg(psi). The 'filenames' arguments is a dictionary with key:value = array_name:file_name. """ data_representation = pv.Show() # Reset the camera here to get the whole object. view = pv.GetRenderView() view.ResetCamera() # create calculator filter that computes the Cooper pair density array_name = list(filenames.keys())[1] # make background green view.Background = [0.0, 1.0, 0.0] # data_representation.ScalarOpacityFunction = pv.CreatePiecewiseFunction() data_representation.ColorArrayName = array_name data_representation.LookupTable = pv.GetLookupTableForArray( array_name, 1, RGBPoints=[0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0], LockScalarRange=1, ) pv.WriteImage(list(filenames.values())[1]) # pv.Render() array_name = list(filenames.keys())[0] # make background gray view.Background = [0.5, 0.5, 0.5] # data_representation.ScalarOpacityFunction = pv.CreatePiecewiseFunction() data_representation.ColorArrayName = array_name data_representation.LookupTable = pv.GetLookupTableForArray( array_name, 1, RGBPoints=_create_circular_hsv_colormap(), LockScalarRange=1) # Don't interpolate scalars as otherwise, the circular HSV color map # gets messed up at the pi/-pi seam. data_representation.InterpolateScalarsBeforeMapping = 0 pv.WriteImage(list(filenames.values())[0]) return
def volumeRender(self): global view self._extractVolumeImageData() (lenx, leny, lenz) = (self.bounds[1] - self.bounds[0], self.bounds[3] - self.bounds[2], self.bounds[5] - self.bounds[4]) (midx, midy, midz) = (self.center[0], self.center[1], self.center[2]) maxDim = max(lenx, leny, lenz) # Adjust camera properties appropriately view.CameraFocalPoint = self.center view.CenterOfRotation = self.center view.CameraPosition = [ midx - self.DISTANCE_FACTOR * maxDim, midy, midz ] view.CameraViewUp = [0, 0, 1] # Create RGB transfer function rgbPoints = [ self.scalarRange[0], 0, 0, 0, self.scalarRange[1], 1, 1, 1 ] self.lookupTable = simple.GetLookupTableForArray( self.colorArrayName, 1) self.lookupTable.RGBPoints = rgbPoints self.lookupTable.ScalarRangeInitialized = 1.0 self.lookupTable.ColorSpace = 0 # 0 corresponds to RGB # Create opacity transfer function sofPoints = [ self.scalarRange[0], 0, 0.5, 0, self.scalarRange[1], 1, 0.5, 0 ] self.sof = simple.CreatePiecewiseFunction() self.sof.Points = sofPoints self.rep.ColorArrayName = self.colorArrayName self.rep.Representation = 'Volume' self.rep.ScalarOpacityFunction = self.sof self.rep.LookupTable = self.lookupTable simple.Show() simple.Render() return { 'scalarRange': self.scalarRange, 'bounds': self.bounds, 'extent': self.extent, 'sofPoints': sofPoints, 'rgbPoints': rgbPoints }
def sliceRender(self, sliceMode): global view self._extractVolumeImageData() (midx, midy, midz) = (self.center[0], self.center[1], self.center[2]) (lenx, leny, lenz) = (self.bounds[1] - self.bounds[0], self.bounds[3] - self.bounds[2], self.bounds[5] - self.bounds[4]) maxDim = max(lenx, leny, lenz) # Adjust camera properties appropriately view.Background = [0, 0, 0] view.CameraFocalPoint = self.center view.CenterOfRotation = self.center view.CenterAxesVisibility = False view.OrientationAxesVisibility = False view.CameraParallelProjection = True # Configure data representation rgbPoints = [ self.scalarRange[0], 0, 0, 0, self.scalarRange[1], 1, 1, 1 ] self.lookupTable = simple.GetLookupTableForArray( self.colorArrayName, 1) self.lookupTable.RGBPoints = rgbPoints self.lookupTable.ScalarRangeInitialized = 1.0 self.lookupTable.ColorSpace = 0 # 0 corresponds to RGB self.rep.ColorArrayName = self.colorArrayName self.rep.Representation = 'Slice' self.rep.LookupTable = self.lookupTable sliceInfo = self.setSliceMode(sliceMode) simple.Show() simple.Render() return { 'scalarRange': self.scalarRange, 'bounds': self.bounds, 'extent': self.extent, 'center': self.center, 'sliceInfo': sliceInfo }
def test2(): w = simple.Wavelet() c = simple.Contour(ComputeScalars=1, Isosurfaces=range(50, 250, 10)) r = simple.Show(c) lut = simple.GetLookupTableForArray("RTData", 1, RGBPoints=[ 43.34006881713867, 0.23, 0.299, 0.754, 160.01158714294434, 0.865, 0.865, 0.865, 276.68310546875, 0.706, 0.016, 0.15 ]) r.LookupTable = lut r.ColorArrayName = ('POINT_DATA', 'RTData') view = simple.Render() exp = ThreeSixtyImageStackExporter( FileNameGenerator('/tmp/z', 'w_{theta}_{phi}.jpg'), view, [0, 0, 0], 100, [0, 0, 1], [10, 20]) exp.UpdatePipeline() exp = ThreeSixtyImageStackExporter( FileNameGenerator('/tmp/y', 'cone_{theta}_{phi}.jpg'), view, [0, 0, 0], 100, [0, 1, 0], [10, 20]) exp.UpdatePipeline() exp = ThreeSixtyImageStackExporter( FileNameGenerator('/tmp/x', 'cone_{theta}_{phi}.jpg'), view, [0, 0, 0], 100, [1, 0, 0], [10, 20]) exp.UpdatePipeline() simple.ResetCamera() simple.Hide(c) slice = SliceExplorer( FileNameGenerator('/tmp/slice', 'w_{sliceColor}_{slicePosition}.jpg'), view, w, {"RTData": { "lut": lut, "type": 'POINT_DATA' }}, 50, [0, 1, 0]) slice.UpdatePipeline()
def main(): import paraview.simple as para version_major = para.servermanager.vtkSMProxyManager.GetVersionMajor() source = para.GetActiveSource() renderView1 = para.GetRenderView() atoms = para.Glyph( Input=source, GlyphType='Sphere', Scalars='radii', ScaleMode='scalar', ) para.RenameSource('Atoms', atoms) atomsDisplay = para.Show(atoms, renderView1) if version_major <= 4: atoms.SetScaleFactor = 0.8 atomicnumbers_PVLookupTable = para.GetLookupTableForArray( 'atomic numbers', 1) atomsDisplay.ColorArrayName = ('POINT_DATA', 'atomic numbers') atomsDisplay.LookupTable = atomicnumbers_PVLookupTable else: atoms.ScaleFactor = 0.8 para.ColorBy(atomsDisplay, 'atomic numbers') atomsDisplay.SetScalarBarVisibility(renderView1, True) para.Render()
has_rgbz_view = False # === Data to explore and configuration ======================================= data_to_explore = simple.Wavelet() min = 63.96153259277344 max = 250.22056579589844 center_of_rotation = [0.0, 0.0, 0.0] rotation_axis = [0.0, 0.0, 1.0] angle_steps = (72, 60) distance = 60 lut = simple.GetLookupTableForArray("RTData", 1, RGBPoints=[ min, 0.23, 0.299, 0.754, (min + max) * 0.5, 0.865, 0.865, 0.865, max, 0.706, 0.016, 0.15 ], ColorSpace='Diverging', ScalarRangeInitialized=1.0) iso_values = [((float(x) * (max - min) * 0.1) + min) for x in range(10)] # === Create analysis ========================================================= analysis = cinema.AnalysisManager(work_directory, "Cinema Test", "Test various cinema explorers.") analysis.begin() # === SliceExplorer =========================================================== analysis.register_analysis(
# This is how you can run this script: # mpiexec -n NUM_PROCS pvbatch Test_Parallel.py import paraview.simple as pv import paraview.servermanager as pvserver num_partitions = pvserver.ActiveConnection.GetNumberOfDataPartitions() print("Rendering {} data partitions".format(num_partitions)) sphere = pv.Sphere() pids = pv.ProcessIdScalars() rep = pv.Show() lut = pv.GetLookupTableForArray( "ProcessId", 1, RGBPoints=[0.0, 0.23, 0.3, 0.754, num_partitions, 0.706, 0.016, 0.15], ColorSpace='Diverging') rep.LookupTable = lut rep.ColorArrayName = 'ProcessId' pv.Render() pv.WriteImage('Parallel.png') print( "Rendering done. You should find an image file named `Parallel.png` that shows a sphere. The sphere should be divided into wedges that are color-coded by processor." )
def updateColorMap(self, rgbPoints): self.lookupTable = simple.GetLookupTableForArray( self.colorArrayName, 1) self.lookupTable.RGBPoints = rgbPoints self.rep.LookupTable = self.lookupTable
def execute(self): self.cdms_variables = self.forceGetInputListFromPort('cdms_variable') for cdms_var in self.cdms_variables: #// Get the min and max to draw default contours min = cdms_var.var.min() max = cdms_var.var.max() reader = PVCDMSReader() time_values = [None, 1, True] image_data = reader.convert(cdms_var, time=time_values) #// Make white box filter so we can work at proxy level ProgrammableSource1 = pvsp.ProgrammableSource() #// Get a hole of the vtk level filter it controls ps = ProgrammableSource1.GetClientSideObject() #// Give it some data (ie the imagedata) ps.myid = image_data ProgrammableSource1.OutputDataSetType = 'vtkImageData' ProgrammableSource1.PythonPath = '' #// Make the scripts that it runs in pipeline RI and RD passes ProgrammableSource1.ScriptRequestInformation = """ executive = self.GetExecutive() outInfo = executive.GetOutputInformation(0) extents = self.myid.GetExtent() spacing = self.myid.GetSpacing() outInfo.Set(executive.WHOLE_EXTENT(), extents[0], extents[1], extents[2], extents[3], extents[4], extents[5]) outInfo.Set(vtk.vtkDataObject.SPACING(), spacing[0], spacing[1], spacing[2]) dataType = 10 # VTK_FLOAT numberOfComponents = 1 vtk.vtkDataObject.SetPointDataActiveScalarInfo(outInfo, dataType, numberOfComponents)""" ProgrammableSource1.Script = """self.GetOutput().ShallowCopy(self.myid)""" ProgrammableSource1.UpdatePipeline() pvsp.SetActiveSource(ProgrammableSource1) self.contour_var_name = str(cdms_var.varname) #// If the data is three dimensional, then don't draw the background imagery #// since it may hide the contours if not reader.is_three_dimensional(cdms_var): data_rep = pvsp.Show(view=self.view) data_rep.LookupTable = pvsp.GetLookupTableForArray( self.contour_var_name, 1, NanColor=[0.25, 0.0, 0.0], RGBPoints=[ min, 0.23, 0.299, 0.754, max, 0.706, 0.016, 0.15 ], VectorMode='Magnitude', ColorSpace='Diverging', LockScalarRange=1) data_rep.ColorArrayName = self.contour_var_name try: contour = pvsp.Contour() pvsp.SetActiveSource(contour) contour.ContourBy = ['POINTS', self.contour_var_name] delta = (max - min) / 10.0 contours = self.forceGetInputListFromPort("contour_values") if (len(contours) and contours): self.contour_values = [ float(d) for d in contours[0].split(',') ] # if( (self.contour_values == None) or (len(self.contour_values) == 0) ): else: self.contour_values = [(x * delta + min) for x in range(10)] functions = [] functions.append(("contour_values", [str(self.contour_values).strip('[]')])) self.update_functions('PVContourRepresentation', functions) contour.Isosurfaces = self.contour_values contour.ComputeScalars = 1 contour.ComputeNormals = 0 contour.UpdatePipeline() #// @todo: Remove hard-coded values contour_rep = pvsp.Show(view=self.view) contour_rep.Representation = 'Surface' if reader.is_three_dimensional(cdms_var): contour_rep.LookupTable = pvsp.GetLookupTableForArray( self.contour_var_name, 1, NanColor=[0.25, 0.0, 0.0], RGBPoints=[ min, 0.23, 0.299, 0.754, max, 0.706, 0.016, 0.15 ], VectorMode='Magnitude', ColorSpace='Diverging', LockScalarRange=1) contour_rep.ColorArrayName = self.contour_var_name else: contour_rep.DiffuseColor = [0.0, 0.0, 0.0] contour_rep.ColorArrayName = '' #// Scalar bar ScalarBarWidgetRepresentation1 = pvsp.CreateScalarBar( Title=self.contour_var_name, LabelFontSize=12, Enabled=1, TitleFontSize=12) self.view.Representations.append( ScalarBarWidgetRepresentation1) if not reader.is_three_dimensional(cdms_var): ScalarBarWidgetRepresentation1.LookupTable = data_rep.LookupTable else: ScalarBarWidgetRepresentation1.LookupTable = contour_rep.LookupTable except ValueError: print "[ERROR] Unable to generate contours. Please check your input values" except (RuntimeError, TypeError, NameError): print "[ERROR] Unknown error" pass
def execute(self): self.cdms_variables = self.forceGetInputListFromPort('cdms_variable') for cdms_var in self.cdms_variables: #// @todo: hardcoded for now time_values = [None, 1, True] #// Get the min and max to draw default contours min = cdms_var.var.min() max = cdms_var.var.max() reader = PVCDMSReader() image_data = reader.convert(cdms_var, time=time_values) #// Make white box filter so we can work at proxy level programmable_source = pvsp.ProgrammableSource() #// Get a hole of the vtk level filter it controls ps = programmable_source.GetClientSideObject() #// Give it some data (ie the imagedata) ps.myid = image_data programmable_source.OutputDataSetType = 'vtkImageData' programmable_source.PythonPath = '' #// Make the scripts that it runs in pipeline RI and RD passes programmable_source.ScriptRequestInformation = """ executive = self.GetExecutive() outInfo = executive.GetOutputInformation(0) extents = self.myid.GetExtent() spacing = self.myid.GetSpacing() outInfo.Set(executive.WHOLE_EXTENT(), extents[0], extents[1], extents[2], extents[3], extents[4], extents[5]) outInfo.Set(vtk.vtkDataObject.SPACING(), spacing[0], spacing[1], spacing[2]) dataType = 10 # VTK_FLOAT numberOfComponents = 1 vtk.vtkDataObject.SetPointDataActiveScalarInfo(outInfo, dataType, numberOfComponents)""" programmable_source.Script = """self.GetOutput().ShallowCopy(self.myid)""" programmable_source.UpdatePipeline() pvsp.SetActiveSource(programmable_source) self.slice_by_var_name = cdms_var.varname self.slice_by_var_type = 'POINTS' if not reader.is_three_dimensional(cdms_var): data_rep = pvsp.Show(view=self.view) data_rep.LookupTable = pvsp.GetLookupTableForArray( self.slice_by_var_name, 1, NanColor=[0.25, 0.0, 0.0], RGBPoints=[ min, 0.23, 0.299, 0.754, max, 0.706, 0.016, 0.15 ], VectorMode='Magnitude', ColorSpace='Diverging', LockScalarRange=1) data_rep.ColorArrayName = self.slice_by_var_name continue functions = [] try: slice_origin = self.forceGetInputListFromPort("slice_origin") if (slice_origin == None) or len(slice_origin) == 0: bounds = image_data.GetBounds() self.slice_origin = [] self.slice_origin.append((bounds[1] + bounds[0]) / 2.0) self.slice_origin.append((bounds[3] + bounds[2]) / 2.0) self.slice_origin.append((bounds[5] + bounds[4]) / 2.0) functions.append( ('slice_origin', [str(self.slice_origin).strip('[]')])) else: self.slice_origin = [ float(d) for d in slice_origin[0].split(',') ] slice_normal = self.forceGetInputListFromPort("slice_normal") if slice_normal == None or len(slice_normal) == 0: self.slice_normal = [0.0, 0.0, 1.0] functions.append( ('slice_normal', [str(self.slice_normal).strip('[]')])) else: self.slice_normal = [ float(d) for d in slice_normal[0].split(',') ] slice_offset_values = self.forceGetInputListFromPort( "slice_offset_values") if (len(slice_offset_values) and slice_offset_values): self.slice_offset_values = [ float(d) for d in slice_offset_values[0].split(',') ] else: self.slice_offset_values = [0.0] functions.append( ('slice_offset_values', [str(self.slice_offset_values).strip('[]')])) if len(functions) > 0: self.update_functions('PVSliceRepresentation', functions) #// Create a slice representation plane_slice = pvsp.Slice(SliceType="Plane") pvsp.SetActiveSource(plane_slice) plane_slice.SliceType.Normal = self.slice_normal plane_slice.SliceType.Origin = self.slice_origin plane_slice.SliceOffsetValues = self.slice_offset_values slice_rep = pvsp.Show(view=self.view) slice_rep.LookupTable = pvsp.GetLookupTableForArray( self.slice_by_var_name, 1, NanColor=[0.25, 0.0, 0.0], RGBPoints=[ min, 0.23, 0.299, 0.754, max, 0.706, 0.016, 0.15 ], VectorMode='Magnitude', ColorSpace='Diverging', LockScalarRange=1) slice_rep.ColorArrayName = self.slice_by_var_name slice_rep.Representation = 'Surface' #// Scalar bar ScalarBarWidgetRepresentation1 = pvsp.CreateScalarBar( Title=self.slice_by_var_name, LabelFontSize=12, Enabled=1, TitleFontSize=12) self.view.Representations.append( ScalarBarWidgetRepresentation1) if not reader.is_three_dimensional(cdms_var): ScalarBarWidgetRepresentation1.LookupTable = data_rep.LookupTable else: ScalarBarWidgetRepresentation1.LookupTable = slice_rep.LookupTable except ValueError: print "[ERROR] Unable to generate slice. Please check your input values" except (RuntimeError, TypeError, NameError): print "[ERROR] Unknown error"