def scalars(self, name_or_idx=None, datatype="point"):
        """
        Retrieve point or cell scalars using array name or index number.
        If no ``name`` is given return the list of names of existing arrays.

        .. hint:: |mesh_coloring.py|_
        """
        poly = self.polydata(False)

        if name_or_idx is None:  # get mode behaviour
            ncd = poly.GetCellData().GetNumberOfArrays()
            npd = poly.GetPointData().GetNumberOfArrays()
            nfd = poly.GetFieldData().GetNumberOfArrays()
            arrs = []
            for i in range(npd):
                print(i, "PointData", poly.GetPointData().GetArrayName(i))
                arrs.append(["PointData", poly.GetPointData().GetArrayName(i)])
            for i in range(ncd):
                print(i, "CellData", poly.GetCellData().GetArrayName(i))
                arrs.append(["CellData", poly.GetCellData().GetArrayName(i)])
            for i in range(nfd):
                print(i, "FieldData", poly.GetFieldData().GetArrayName(i))
                arrs.append(["FieldData", poly.GetFieldData().GetArrayName(i)])
            return arrs
        else:  # set mode
            if "point" in datatype.lower():
                data = poly.GetPointData()
            elif "cell" in datatype.lower():
                data = poly.GetCellData()
            elif "field" in datatype.lower():
                data = poly.GetFieldData()
            else:
                colors.printc("~times Error in scalars(): unknown datatype", datatype, c=1)
                exit()

            if isinstance(name_or_idx, int):
                name = data.GetArrayName(name_or_idx)
                if name is None:
                    return None
                data.SetActiveScalars(name)
                return vtk_to_numpy(data.GetArray(name))
            elif isinstance(name_or_idx, str):
                arr = data.GetArray(name_or_idx)
                if arr is None:
                    return None
                data.SetActiveScalars(name_or_idx)
                return vtk_to_numpy(arr)

            return None
def scalars ( self , name_or_idx = None , datatype = "point" ) : poly = self . polydata ( False ) if name_or_idx is None : ncd = poly . GetCellData ( ) . GetNumberOfArrays ( ) npd = poly . GetPointData ( ) . GetNumberOfArrays ( ) nfd = poly . GetFieldData ( ) . GetNumberOfArrays ( ) arrs = [ ] for i in range ( npd ) : print ( i , "PointData" , poly . GetPointData ( ) . GetArrayName ( i ) ) arrs . append ( [ "PointData" , poly . GetPointData ( ) . GetArrayName ( i ) ] ) for i in range ( ncd ) : print ( i , "CellData" , poly . GetCellData ( ) . GetArrayName ( i ) ) arrs . append ( [ "CellData" , poly . GetCellData ( ) . GetArrayName ( i ) ] ) for i in range ( nfd ) : print ( i , "FieldData" , poly . GetFieldData ( ) . GetArrayName ( i ) ) arrs . append ( [ "FieldData" , poly . GetFieldData ( ) . GetArrayName ( i ) ] ) return arrs else : if "point" in datatype . lower ( ) : data = poly . GetPointData ( ) elif "cell" in datatype . lower ( ) : data = poly . GetCellData ( ) elif "field" in datatype . lower ( ) : data = poly . GetFieldData ( ) else : colors . printc ( "~times Error in scalars(): unknown datatype" , datatype , c = 1 ) exit ( ) if isinstance ( name_or_idx , int ) : name = data . GetArrayName ( name_or_idx ) if name is None : return None data . SetActiveScalars ( name ) return vtk_to_numpy ( data . GetArray ( name ) ) elif isinstance ( name_or_idx , str ) : arr = data . GetArray ( name_or_idx ) if arr is None : return None data . SetActiveScalars ( name_or_idx ) return vtk_to_numpy ( arr ) return None
Retrieve point or cell scalars using array name or index number.
        If no ``name`` is given return the list of names of existing arrays.

        .. hint:: |mesh_coloring.py|_