def __init__(self):

        self.field_storage = PlayerPython.FieldStorage()
        self.field_writer = PlayerPython.FieldWriter()
        self.field_writer.setFieldStorage(self.field_storage)

        # not being used currently
        # self.fieldWriter.setFileTypeToBinary(False)

        self.field_types = {}
        self.output_freq = 1
        self.sim = None
        self.output_dir_name = ""
        self.output_file_core_name = "Step"
        self.out_file_number_of_digits = 0
        self.do_not_output_field_list = []
        self.FIELD_TYPES = ("CellField", "ConField", "ScalarField",
                            "ScalarFieldCellLevel", "VectorField",
                            "VectorFieldCellLevel")
        self.__initialization_complete = False
Esempio n. 2
0
    def generatePIFFromRunningSimulation(self, _pifFileName):
        if self.__fileWriter is None:

            self.__fileWriter = PlayerPython.FieldWriter()
            # note self.sim is a weak reference so to pass underlying object to swigged-fcn
            # we need to derefernce it by using self.sim() expression
            pg = CompuCellSetup.persistent_globals

            self.__fileWriter.init(pg.simulator)
        self.__fileWriter.generatePIFFileFromCurrentStateOfSimulation(
            _pifFileName)
def initialize_field_extractor_objects():
    """
    Initialzies field storage and field extractor objects
    Stores references to them in persistent_globals.persistent_holder dictionary
    :return:
    """

    persistent_globals = CompuCellSetup.persistent_globals
    sim = persistent_globals.simulator
    dim = sim.getPotts().getCellFieldG().getDim()

    field_storage = PlayerPython.FieldStorage()
    field_extractor = PlayerPython.FieldExtractor()
    field_extractor.setFieldStorage(field_storage)

    persistent_globals.persistent_holder['field_storage'] = field_storage
    persistent_globals.persistent_holder['field_extractor'] = field_extractor

    field_storage.allocateCellField(dim)

    field_extractor.init(sim)
def generate_pif_from_vtk(_vtkFileName: str, _pifFileName: str, _lds_file_name: str) -> None:
    """
    generates PIFF from VTK file
    :param _vtkFileName:
    :param _pifFileName:
    :return:
    """
    lds_reader = LatticeDataSummaryReader(_lds_file_name)
    file_writer = PlayerPython.FieldWriter()
    file_writer.generatePIFFileFromVTKOutput(_vtkFileName, _pifFileName,
                                             lds_reader.field_dim.x, lds_reader.field_dim.y, lds_reader.field_dim.z,
                                             lds_reader.type_id_type_name_cpp_map)
    def generate_pif_from_vtk(self, _vtkFileName: str, _pifFileName: str) -> None:
        """
        generates PIFF from VTK file
        :param _vtkFileName:
        :param _pifFileName:
        :return:
        """

        if self.__fileWriter is None:
            self.__fileWriter = PlayerPython.FieldWriter()

        self.__fileWriter.generatePIFFileFromVTKOutput(_vtkFileName, _pifFileName, self.fieldDim.x, self.fieldDim.y,
                                                       self.fieldDim.z, self.typeIdTypeNameCppMap)
    def __init__(self, parent=None, file_name: str = None):
        # If initializing from file_name, field extractor is initialized here
        # Otherwise, a parent must be passed that, at some point before reading simulation data,
        # has a CML reader attached

        # Support pass when runnnig replay in Player
        if parent is None and file_name is None:
            return

        # Will extract fieldExtractor from parent or initialize new fieldExtractor from file_name
        assert file_name is not None or hasattr(parent, 'fieldExtractor')
        self._parent = parent
        self.field_extractor = None
        if parent is None:
            assert os.path.isfile(os.path.abspath(file_name))
            assert file_name.endswith('.dml'), 'file_name must specify a .dml file'
            self.field_extractor = PlayerPython.FieldExtractorCML()
            self.field_extractor.setFieldDim(LatticeDataSummaryReader.extract_lattice_dim_from_file_name(file_name))

        # data extracted from LDS file *.dml
        self.fieldDim = None
        self.fieldDimPrevious = None
        self.ldsCoreFileName = ""
        self.currentFileName = ""
        self.ldsDir = None

        # list of *.vtk files containing graphics lattice data
        self.ldsFileList = []
        self.fieldsUsed = {}
        self.sim = None
        self.simulationData = None
        self.simulationDataReader = None
        self.frequency = 0
        self.currentStep = 0
        self.latticeType = "Square"
        self.numberOfSteps = 0
        self.typeIdTypeNameDict = {}
        self.__fileWriter = None

        # C++ map<int,string> providing mapping from type id to type name
        self.typeIdTypeNameCppMap = None
        self.customVis = None
Esempio n. 7
0
    def init_concentration_field_actors(self,
                                        actor_specs,
                                        drawing_params=None):
        """
        initializes concentration field actors
        :param actor_specs:
        :param drawing_params:
        :return: None
        """

        actors_dict = actor_specs.actors_dict

        field_dim = self.currentDrawingParameters.bsd.fieldDim
        # dim_order = self.dimOrder(self.currentDrawingParameters.plane)
        # dim = self.planeMapper(dim_order, (field_dim.x, field_dim.y, field_dim.z))# [fieldDim.x, fieldDim.y, fieldDim.z]
        dim = [field_dim.x, field_dim.y, field_dim.z]
        field_name = drawing_params.fieldName
        scene_metadata = drawing_params.screenshot_data.metadata
        mdata = MetadataHandler(mdata=scene_metadata)

        try:
            isovalues = mdata.get('ScalarIsoValues', default=[])
            isovalues = list([float(x) for x in isovalues])
        except:
            print('Could not process isovalue list ')
            isovalues = []

        try:
            numIsos = mdata.get('NumberOfContourLines', default=3)
        except:
            print('could not process NumberOfContourLines setting')
            numIsos = 0

        hex_flag = False
        lattice_type_str = self.get_lattice_type_str()
        if lattice_type_str.lower() == 'hexagonal':
            hex_flag = True

        types_invisible = PlayerPython.vectorint()
        for type_label in drawing_params.screenshot_data.invisible_types:
            types_invisible.append(int(type_label))

        # self.isovalStr = Configuration.getSetting("ScalarIsoValues", field_name)
        # if type(self.isovalStr) == QVariant:
        #     self.isovalStr = str(self.isovalStr.toString())
        # else:
        #     self.isovalStr = str(self.isovalStr)

        con_array = vtk.vtkDoubleArray()
        con_array.SetName("concentration")
        con_array_int_addr = extract_address_int_from_vtk_object(
            vtkObj=con_array)

        cell_type_con = vtk.vtkIntArray()
        cell_type_con.SetName("concelltype")
        cell_type_con_int_addr = extract_address_int_from_vtk_object(
            vtkObj=cell_type_con)

        field_type = drawing_params.fieldType.lower()
        if field_type == 'confield':
            fill_successful = self.field_extractor.fillConFieldData3D(
                con_array_int_addr, cell_type_con_int_addr, field_name,
                types_invisible)
        elif field_type == 'scalarfield':
            fill_successful = self.field_extractor.fillScalarFieldData3D(
                con_array_int_addr, cell_type_con_int_addr, field_name,
                types_invisible)
        elif field_type == 'scalarfieldcelllevel':
            fill_successful = self.field_extractor.fillScalarFieldCellLevelData3D(
                con_array_int_addr, cell_type_con_int_addr, field_name,
                types_invisible)

        if not fill_successful:
            return

        range_array = con_array.GetRange()
        min_con = range_array[0]
        max_con = range_array[1]
        field_max = range_array[1]
        #        print MODULENAME, '  initScalarFieldDataActors(): min,maxCon=',self.minCon,self.maxCon

        min_max_dict = self.get_min_max_metadata(scene_metadata=scene_metadata,
                                                 field_name=field_name)
        min_range_fixed = min_max_dict['MinRangeFixed']
        max_range_fixed = min_max_dict['MaxRangeFixed']
        min_range = min_max_dict['MinRange']
        max_range = min_max_dict['MaxRange']

        # Note! should really avoid doing a getSetting with each step to speed up the rendering;
        # only update when changed in Prefs
        if min_range_fixed:
            min_con = min_range

        if max_range_fixed:
            max_con = max_range

        uGrid = vtk.vtkStructuredPoints()
        uGrid.SetDimensions(
            dim[0] + 2, dim[1] + 2, dim[2] + 2
        )  # only add 2 if we're filling in an extra boundary (rf. FieldExtractor.cpp)
        #        uGrid.SetDimensions(self.dim[0],self.dim[1],self.dim[2])
        #        uGrid.GetPointData().SetScalars(self.cellTypeCon)   # cellType scalar field
        uGrid.GetPointData().SetScalars(con_array)
        #        uGrid.GetPointData().AddArray(self.conArray)        # additional scalar field

        voi = vtk.vtkExtractVOI()
        ##        voi.SetInputConnection(uGrid.GetOutputPort())
        #        voi.SetInput(uGrid.GetOutput())

        if VTK_MAJOR_VERSION >= 6:
            voi.SetInputData(uGrid)
        else:
            voi.SetInput(uGrid)

        voi.SetVOI(1, dim[0] - 1, 1, dim[1] - 1, 1, dim[2] -
                   1)  # crop out the artificial boundary layer that we created

        isoContour = vtk.vtkContourFilter()
        # skinExtractorColor = vtk.vtkDiscreteMarchingCubes()
        # skinExtractorColor = vtk.vtkMarchingCubes()
        #        isoContour.SetInput(uGrid)
        isoContour.SetInputConnection(voi.GetOutputPort())

        isoNum = 0
        for isoNum, isoVal in enumerate(isovalues):
            try:
                isoContour.SetValue(isoNum, isoVal)
            except:
                print(
                    MODULENAME,
                    '  initScalarFieldDataActors(): cannot convert to float: ',
                    self.isovalStr[idx])

        if isoNum > 0:
            isoNum += 1

        delIso = (max_con - min_con) / (numIsos + 1
                                        )  # exclude the min,max for isovalues
        isoVal = min_con + delIso
        for idx in range(numIsos):
            isoContour.SetValue(isoNum, isoVal)
            isoNum += 1
            isoVal += delIso

        # UGLY hack to NOT display anything since our attempt to RemoveActor (below) don't seem to work
        if isoNum == 0:
            isoVal = field_max + 1.0  # go just outside valid range
            isoContour.SetValue(isoNum, isoVal)

        #        concLut = vtk.vtkLookupTable()
        # concLut.SetTableRange(conc_vol.GetScalarRange())
        #        concLut.SetTableRange([self.minCon,self.maxCon])
        self.scalarLUT.SetTableRange([min_con, max_con])
        #        concLut.SetNumberOfColors(256)
        #        concLut.Build()
        # concLut.SetTableValue(39,0,0,0,0)

        #        skinColorMapper = vtk.vtkPolyDataMapper()
        # skinColorMapper.SetInputConnection(skinNormals.GetOutputPort())
        #        self.conMapper.SetInputConnection(skinExtractorColor.GetOutputPort())
        self.conMapper.SetInputConnection(isoContour.GetOutputPort())
        self.conMapper.ScalarVisibilityOn()
        self.conMapper.SetLookupTable(self.scalarLUT)
        # # # print " this is conc_vol.GetScalarRange()=",conc_vol.GetScalarRange()
        # self.conMapper.SetScalarRange(conc_vol.GetScalarRange())
        self.conMapper.SetScalarRange([min_con, max_con])
        # self.conMapper.SetScalarRange(0,1500)

        # rwh - what does this do?
        #        self.conMapper.SetScalarModeToUsePointFieldData()
        #        self.conMapper.ColorByArrayComponent("concentration",0)

        #        print MODULENAME,"initScalarFieldDataActors():  Plotting 3D Scalar field"
        # self.conMapper      = vtk.vtkPolyDataMapper()
        # self.conActor       = vtk.vtkActor()

        concentration_actor = actors_dict['concentration_actor']

        concentration_actor.SetMapper(self.conMapper)

        self.init_min_max_actor(
            min_max_actor=actors_dict['min_max_text_actor'],
            range_array=range_array)

        if hex_flag:
            concentration_actor.SetScale(self.xScaleHex, self.yScaleHex,
                                         self.zScaleHex)

        if actor_specs.metadata is None:
            actor_specs.metadata = {'mapper': self.conMapper}
        else:
            actor_specs.metadata['mapper'] = self.conMapper

        if mdata.get('LegendEnable', default=False):
            self.init_legend_actors(actor_specs=actor_specs,
                                    drawing_params=drawing_params)
Esempio n. 8
0
 def __init__(self, field_dim: Dim3D):
     super().__init__()
     self.fieldExtractor = PlayerPython.FieldExtractorCML()
     self.fieldExtractor.setFieldDim(field_dim)