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])
RGBPoints=[0,0.6,0.88,1,100,1,0,0]) lutWGR = simple.CreateLookupTable( ColorSpace='RGB', \ NumberOfTableValues=256, \ RGBPoints=[0,0.9,0.9,0.9,\ 25,0.55,0.75,0.5,50,0.1,0.58,0.2,\ 75,0.54,0.31,0.17,100,0.78,0.2,0.15]) lutYGB = simple.CreateLookupTable( ColorSpace='RGB', \ NumberOfTableValues=256, \ RGBPoints=[0,1,1,0.8,25,0.63,0.86,0.71,50,0.26,0.71,0.77,75,0.17,0.5,0.72,100,0.15,0.2,0.58]) scalarbar = simple.CreateScalarBar(Title='', LabelFontSize=8, Enabled=0, TitleFontSize=10, NumberOfLabels=2, LookupTable=lutCR, Position=[0, 0.1], Position2=[0.2, 0.9], Visibility=0, Selectable=1, AutomaticLabelFormat=0, LabelFormat='%-#6.3g') view.Representations.append(scalarbar) # Update camera manipulator manipulatorsProperty = view.GetProperty('Camera3DManipulators') newList = [] for index in xrange(manipulatorsProperty.GetNumberOfProxies()): manipulator = servermanager._getPyProxy( manipulatorsProperty.GetProxy(index)) if manipulator.ManipulatorName != 'Rotation':
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"