def __init__(self): import PlayerPython self.fieldStorage=PlayerPython.FieldStorage() self.fieldWriter=PlayerPython.FieldWriter() self.fieldTypes={} self.outputFrequency=1 self.sim=None self.outputDirName="" self.outputFileCoreName="" self.outFileNumberOfDigits=0;
def step(self,mcs): invItr=CompuCell.STLPyIteratorCINV() invItr.initialize(self.inventory.getContainer()) invItr.setToBegin() cell=invItr.getCurrentRef() offset=10 PlayerPython.clearVectorCellLevelField(self.vectorField) while (1): if invItr.isEnd(): break cell=invItr.getCurrentRef() insertVector(self.vectorField,cell,mcs+offset+1,mcs+offset+2,mcs+offset+3) offset+=10 invItr.next()
def __init__(self): import PlayerPython # swig'd from core/pyinterface/PlayerPythonNew/PlayerPython.i self.fieldStorage = PlayerPython.FieldStorage() self.fieldWriter = PlayerPython.FieldWriter() self.fieldWriter.setFieldStorage(self.fieldStorage) # self.fieldWriter.setFileTypeToBinary(False) # not currently being used self.fieldTypes = {} self.outputFrequency = 1 self.sim = None self.outputDirName = "" self.outputFileCoreName = "Step" self.outFileNumberOfDigits = 0; self.doNotOutputFieldList=[] self.FIELD_TYPES = ("CellField", "ConField", "ScalarField", "ScalarFieldCellLevel" , "VectorField","VectorFieldCellLevel")
def drawScalarFieldData(self, bsd, fieldType,_fillScalarField): # rf. draw* functions preceding this import PlayerPython self.invisibleCellTypesVector=PlayerPython.vectorint() for type in self.invisibleCellTypes: self.invisibleCellTypesVector.append(type) self.drawModel.initScalarFieldDataActors((self.conActor,), self.invisibleCellTypesVector, _fillScalarField) self.hideAllActors() self.set3DInvisibleTypes() self.drawModel.prepareOutlineActors((self.outlineActor,)) self.showOutlineActor() self.showConActors() if Configuration.getSetting("LegendEnable",self.currentDrawingParameters.fieldName): # rwh: need to speed this up w/ local flag # if self.legendEnable: self.drawModel.prepareLegendActors((self.drawModel.conMapper,),(self.legendActor,)) self.showLegend(True) else: self.showLegend(False) self.Render()
def drawScalarFieldData(self, bsd, fieldType,_fillScalarField): # rf. draw* functions preceding this ''' Draws Scalar Field - this function actually performs drawing requested by other functions :param bsd: BasicSimulationData - contains field dim etc :param fieldType: field type - e.g. cellfield, concentration field etc... :return:None ''' import PlayerPython self.invisibleCellTypesVector=PlayerPython.vectorint() for type in self.invisibleCellTypes: self.invisibleCellTypesVector.append(type) self.drawModel.initScalarFieldDataActors((self.conActor,), self.invisibleCellTypesVector, _fillScalarField) self.hideAllActors() self.set3DInvisibleTypes() self.drawModel.prepareOutlineActors((self.outlineActor,)) self.drawPlotVisDecorations() self.showConActors() if Configuration.getSetting("LegendEnable",self.currentDrawingParameters.fieldName): # rwh: need to speed this up w/ local flag self.drawModel.prepareLegendActors((self.drawModel.conMapper,),(self.legendActor,)) self.showLegend(True) else: self.showLegend(False) self.Render()
def generatePIFFromVTK(self, _vtkFileName, _pifFileName): if self.__fileWriter is None: import PlayerPython self.__fileWriter = PlayerPython.FieldWriter() self.__fileWriter.generatePIFFileFromVTKOutput( _vtkFileName, _pifFileName, self.fieldDim.x, self.fieldDim.y, self.fieldDim.z, self.typeIdTypeNameCppMap)
def generatePIFFromRunningSimulation(self, _pifFileName): if self.__fileWriter is None: import PlayerPython self.__fileWriter = PlayerPython.FieldWriter() self.__fileWriter.init( self.sim() ) #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 self.__fileWriter.generatePIFFileFromCurrentStateOfSimulation( _pifFileName)
def drawScalarFieldData( self, bsd, fieldType, _fillScalarField): # rf. draw* functions preceding this ''' Draws Scalar Field - this function actually performs drawing requested by other functions :param bsd: BasicSimulationData - contains field dim etc :param fieldType: field type - e.g. cellfield, concentration field etc... :return:None ''' import PlayerPython self.invisibleCellTypesVector = PlayerPython.vectorint() for type in self.invisibleCellTypes: self.invisibleCellTypesVector.append(type) self.drawModel.initScalarFieldDataActors( (self.conActor, ), self.invisibleCellTypesVector, _fillScalarField) self.hideAllActors() self.set3DInvisibleTypes() self.drawModel.prepareOutlineActors((self.outlineActor, )) self.drawPlotVisDecorations() self.showConActors() if Configuration.getSetting( "LegendEnable", self.currentDrawingParameters.fieldName ): # rwh: need to speed this up w/ local flag self.drawModel.prepareLegendActors((self.drawModel.conMapper, ), (self.legendActor, )) self.showLegend(True) else: self.showLegend(False) self.Render()
import CompuCell #notice importing CompuCell to main script has to be done after call to getCoreSimulationObjects() #import CompuCellSetup CompuCellSetup.initializeSimulationObjects(sim, simthread) steppableRegistry = CompuCellSetup.getSteppableRegistry() CompuCellSetup.mainLoop( sim, simthread, steppableRegistry ) # main loop - simulation is invoked inside this function except IndentationError, e: if CompuCellSetup.simulationObjectsCreated: sim.finish() traceback_message = traceback.format_exc() print traceback_message import PlayerPython simthread = PlayerPython.getSimthreadBasePtr() simthread.handleErrorMessage("Python Indentation Error", traceback_message) except SyntaxError, e: if CompuCellSetup.simulationObjectsCreated: sim.finish() traceback_message = traceback.format_exc() print traceback_message import PlayerPython simthread = PlayerPython.getSimthreadBasePtr() simthread.handleErrorMessage("Python Syntax Error", traceback_message) except IOError, e: if CompuCellSetup.simulationObjectsCreated: sim.finish() traceback_message = traceback.format_exc() print traceback_message import PlayerPython
else: sim,simthread = CompuCellSetup.getCoreSimulationObjects() import CompuCell #notice importing CompuCell to main script has to be done after call to getCoreSimulationObjects() #import CompuCellSetup CompuCellSetup.initializeSimulationObjects(sim,simthread) steppableRegistry = CompuCellSetup.getSteppableRegistry() CompuCellSetup.mainLoop(sim,simthread,steppableRegistry) # main loop - simulation is invoked inside this function except IndentationError,e: if CompuCellSetup.simulationObjectsCreated: sim.finish() traceback_message=traceback.format_exc() print traceback_message import PlayerPython simthread=PlayerPython.getSimthreadBasePtr() simthread.handleErrorMessage("Python Indentation Error",traceback_message) except SyntaxError,e: if CompuCellSetup.simulationObjectsCreated: sim.finish() traceback_message=traceback.format_exc() print traceback_message import PlayerPython simthread=PlayerPython.getSimthreadBasePtr() simthread.handleErrorMessage("Python Syntax Error",traceback_message) except IOError,e: if CompuCellSetup.simulationObjectsCreated: sim.finish() traceback_message=traceback.format_exc() print traceback_message import PlayerPython
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(map(lambda x: float(x), 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 import PlayerPython 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(field_extractor=self.field_extractor, vtkObj=con_array) cell_type_con = vtk.vtkIntArray() cell_type_con.SetName("concelltype") cell_type_con_int_addr = extract_address_int_from_vtk_object(field_extractor=self.field_extractor, 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 xrange(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): print 'Enabling legend' self.init_legend_actors(actor_specs=actor_specs, drawing_params=drawing_params)