def add_filter_value(name, cs, userDefinedValues): source = paraview.simple.FindSource(name) # plane offset generator (for Slice or Clip) def generate_offset_values(): bounds = source.Input.GetDataInformation().DataInformation.GetBounds() minPoint = np.array([bounds[0], bounds[2], bounds[4]]) maxPoint = np.array([bounds[1], bounds[3], bounds[5]]) scaleVec = maxPoint - minPoint # adjust offset size depending on the plane orientation if hasattr(source, 'SliceType'): n = source.SliceType.Normal elif hasattr(source, 'ClipType'): n = source.ClipType.Normal sNormal = np.array([n[0] * scaleVec[0], n[1] * scaleVec[1], n[2] * scaleVec[2]]) steps = 3 # generate N slice offsets offsetStep = np.linalg.norm(sNormal) / steps values = np.arange(-(steps/2), steps/2) * offsetStep return values.tolist() # generate values depending on the type of filter if isinstance(source, paraview.simple.servermanager.filters.Clip): # grab values from ui or generate defaults values = userDefinedValues[name] if (name in userDefinedValues) else generate_offset_values() if len(values) == 0: values = generate_offset_values() # add sublayer and create the appropriate track cs.add_control(name, cinema_store.make_parameter(name, values, typechoice='hidden')) explorerDir[name] = pv_explorers.Clip(name, source) elif isinstance(source, paraview.simple.servermanager.filters.Slice): # grab values from ui or generate defaults values = userDefinedValues[name] if (name in userDefinedValues) else generate_offset_values() if len(values) == 0: values = generate_offset_values() # add sublayer and create the appropriate track cs.add_control(name, cinema_store.make_parameter(name, values, typechoice='hidden')) explorerDir[name] = pv_explorers.Slice(name, source) elif isinstance(source, paraview.simple.servermanager.filters.Contour): def generate_contour_values(): # grab values from ui or generate defaults vRange = source.Input.GetDataInformation().DataInformation.GetPointDataInformation().GetArrayInformation(0).GetComponentRange(0) return np.linspace(vRange[0], vRange[1], 5).tolist() # generate 5 contour values values = userDefinedValues[name] if (name in userDefinedValues) else generate_contour_values() if len(values) == 0: values = generate_contour_values() # add sublayer and create the appropriate track cs.add_control(name, cinema_store.make_parameter(name, values, typechoice='hidden')) explorerDir[name] = pv_explorers.Contour(name, source)
def add_filter_value(name, cs, userDefinedValues): """creates controls for the filters that we know how to manipulate""" source = paraview.simple.FindSource(name) # generate values depending on the type of filter if isinstance(source, paraview.simple.servermanager.filters.Clip): # grab values from ui values = [] if (source in userDefinedValues): if ("OffsetValues" in userDefinedValues[source]): values = userDefinedValues[source]["OffsetValues"] if len(values) == 0: #nothing asked for just leave as is return False # add sublayer and create the appropriate track cs.add_control( name, cinema_store.make_parameter(name, values, typechoice='hidden')) explorerDir[name] = pv_explorers.Clip(name, source) return True elif isinstance(source, paraview.simple.servermanager.filters.Slice): # grab values from ui values = [] if (source in userDefinedValues): if ("SliceOffsetValues" in userDefinedValues[source]): values = userDefinedValues[source]["SliceOffsetValues"] if len(values) == 0: #nothing asked for just leave as is return False # add sublayer and create the appropriate track cs.add_control( name, cinema_store.make_parameter(name, values, typechoice='hidden')) explorerDir[name] = pv_explorers.Slice(name, source) return True elif isinstance(source, paraview.simple.servermanager.filters.Contour): # grab values from ui values = [] if (source in userDefinedValues): if ("Isosurfaces" in userDefinedValues[source]): values = userDefinedValues[source]["Isosurfaces"] if len(values) == 0: #nothing asked for just leave as is return False # add sublayer and create the appropriate track cs.add_control( name, cinema_store.make_parameter(name, values, typechoice='hidden')) explorerDir[name] = pv_explorers.Contour(name, source) return True