Esempio n. 1
0
class GraphVTKVisSteppable(SteppableBasePy):
    def __init__(self, _simulator, _frequency=10):
        SteppableBasePy.__init__(self, _simulator, _frequency)

    def start(self):
        try:
            import networkx
        except ImportError, e:
            return

        self.visData = CompuCellSetup.createCustomVisPy("CustomGraph")
        self.visData.registerVisCallbackFunction(self.visualize)
        self.visData.addActor("glyph", "vtkActor")
        self.visData.addActor("profile", "vtkActor")
        self.visData.addActor("nodeColorBar", "vtkScalarBarActor")
        self.visData.addActor("nodeSizeText", "vtkTextActor")
        self.visData.addActor("edgeColorBar", "vtkScalarBarActor")
        self.visData.addActor("edgeSizeText", "vtkTextActor")

        self.cellIdDict = {}
        self.cellPosDict = {}

        self.cellContactNetwork = nx.Graph()

        self.updateCellIdDict()
        self.makeContactNetwork(self.cellContactNetwork, fillDegrees=True)
Esempio n. 2
0
    def extractLatticeDescriptionInfo(self,_fileName):
        import os
        import os.path
        import CompuCell
        import CompuCellSetup
        
        ldsFile = os.path.abspath(_fileName)
        self.ldsDir = os.path.dirname(ldsFile)        
        
        import XMLUtils
        from XMLUtils import CC3DXMLListPy
        xml2ObjConverter = XMLUtils.Xml2Obj()
        root_element=xml2ObjConverter.Parse(ldsFile)
        dimElement=root_element.getFirstElement("Dimensions")
        self.fieldDim = CompuCell.Dim3D()
        self.fieldDim.x = int(dimElement.getAttribute("x"))
        self.fieldDim.y = int(dimElement.getAttribute("y"))
        self.fieldDim.z = int(dimElement.getAttribute("z"))       
        outputElement = root_element.getFirstElement("Output")
        self.ldsCoreFileName = outputElement.getAttribute("CoreFileName")
        self.frequency = int(outputElement.getAttribute("Frequency"))
        self.numberOfSteps = int(outputElement.getAttribute("NumberOfSteps"))
        
        # obtaining list of files in the ldsDir
        latticeElement = root_element.getFirstElement("Lattice")
        self.latticeType = latticeElement.getAttribute("Type")
        
        #getting information about cell type names and cell ids. It is necessary during generation of the PIF files from VTK output
        cellTypesElements = root_element.getElements("CellType")
        listCellTypeElements = CC3DXMLListPy(cellTypesElements)
        for cellTypeElement in listCellTypeElements:
            typeName=""
            typeId=0
            typeName = cellTypeElement.getAttribute("TypeName")
            typeId = cellTypeElement.getAttributeAsInt("TypeId")
            self.typeIdTypeNameDict[typeId] = typeName
        # now will convert python dictionary into C++ map<int, string>     
        import CC3DXML
        self.typeIdTypeNameCppMap = CC3DXML.MapIntStr()
        for typeId in self.typeIdTypeNameDict.keys():
            self.typeIdTypeNameCppMap[int(typeId)] = self.typeIdTypeNameDict[typeId]
#        print "self.typeIdTypeNameCppMap=",self.typeIdTypeNameCppMap
        
        
        ldsFileList = os.listdir(self.ldsDir)
        import re
        for fName in ldsFileList:
            if re.match(".*\.vtk$", fName):
                self.ldsFileList.append(fName)
        self.ldsFileList.sort()                
        # print " got those files: ",self.ldsFileList
        

        # extracting information about fields in the lds file
        fieldsElement = root_element.getFirstElement("Fields")
        if fieldsElement:
            fieldList = XMLUtils.CC3DXMLListPy(fieldsElement.getElements("Field"))
#            print MODULENAME,"   fieldList=",fieldList
#            print MODULENAME,"   dir(fieldList)=",dir(fieldList)  # ['__doc__', '__init__', '__iter__', '__module__', 'elementList', 'getBaseClass']
##            print MODULENAME,"   fieldList.getAttributes()=",fieldList.getAttributes()   # doesnt exist
#            print MODULENAME,"   fieldList.elementList=",fieldList.elementList
            
            for fieldElem in fieldList:
#                print MODULENAME,"  dir(fieldElem) = ",dir(fieldElem)
#                print MODULENAME,"  fieldElem.getAttributes() = ",fieldElem.getAttributes() # <CC3DXML.MapStrStr; proxy of <Swig Object of type 'std::map< std::string,std::string,std::less< std::string >,std::allocator< std::pair< std::string const,std::string > > > *' at 0x1258e0b70> > 
                fieldName = fieldElem.getAttribute("Name")
#                print MODULENAME,"  fieldsUsed key = fieldElem.getAttribute('Name') =",fieldName   # e.g. 'my_field1' w/ a script
#                print MODULENAME,"  fieldsUsed value = fieldElem.getAttribute('Type') =",fieldElem.getAttribute("Type")
                self.fieldsUsed[fieldElem.getAttribute("Name")] = fieldElem.getAttribute("Type")    
                if fieldElem.findAttribute("Script"):     # True or False if present
                    # ToDo:  if a "CustomVis" Type was provided, require that a "Script" was also provided; else warn user
                    customVisScript = fieldElem.getAttribute("Script")
#                    print MODULENAME,"  fieldElem.getAttribute('Script') =",customVisScript
#                    self.fieldsUsed['Script'] = fieldElem.getAttribute("Script")    
#                    self.customVisScriptDict[fieldName] = customVisScript
                    
                    self.customVis = CompuCellSetup.createCustomVisPy(fieldName)
                    self.customVis.registerVisCallbackFunction(CompuCellSetup.vtkScriptCallback)
#                    print MODULENAME,' customVis.addActor:  fieldName (->vtkActor) =',fieldName
                    self.customVis.addActor(fieldName,"vtkActor")
#                    self.customVis.addActor(customVisScript,"customVTKScript")
                    self.customVis.addActor("customVTKScript",customVisScript)  # we'll piggyback off the actorsDict
Esempio n. 3
0
    def extractLatticeDescriptionInfo(self, _fileName):
        import os
        import os.path
        import CompuCell
        import CompuCellSetup

        ldsFile = os.path.abspath(_fileName)
        self.ldsDir = os.path.dirname(ldsFile)

        import XMLUtils
        from XMLUtils import CC3DXMLListPy
        xml2ObjConverter = XMLUtils.Xml2Obj()
        root_element = xml2ObjConverter.Parse(ldsFile)
        dimElement = root_element.getFirstElement("Dimensions")
        self.fieldDim = CompuCell.Dim3D()
        self.fieldDim.x = int(dimElement.getAttribute("x"))
        self.fieldDim.y = int(dimElement.getAttribute("y"))
        self.fieldDim.z = int(dimElement.getAttribute("z"))
        outputElement = root_element.getFirstElement("Output")
        self.ldsCoreFileName = outputElement.getAttribute("CoreFileName")
        self.frequency = int(outputElement.getAttribute("Frequency"))
        self.numberOfSteps = int(outputElement.getAttribute("NumberOfSteps"))

        # obtaining list of files in the ldsDir
        latticeElement = root_element.getFirstElement("Lattice")
        self.latticeType = latticeElement.getAttribute("Type")

        #getting information about cell type names and cell ids. It is necessary during generation of the PIF files from VTK output
        cellTypesElements = root_element.getElements("CellType")
        listCellTypeElements = CC3DXMLListPy(cellTypesElements)
        for cellTypeElement in listCellTypeElements:
            typeName = ""
            typeId = 0
            typeName = cellTypeElement.getAttribute("TypeName")
            typeId = cellTypeElement.getAttributeAsInt("TypeId")
            self.typeIdTypeNameDict[typeId] = typeName
        # now will convert python dictionary into C++ map<int, string>
        import CC3DXML
        self.typeIdTypeNameCppMap = CC3DXML.MapIntStr()
        for typeId in self.typeIdTypeNameDict.keys():
            self.typeIdTypeNameCppMap[int(
                typeId)] = self.typeIdTypeNameDict[typeId]
#        print "self.typeIdTypeNameCppMap=",self.typeIdTypeNameCppMap

        ldsFileList = os.listdir(self.ldsDir)
        import re
        for fName in ldsFileList:
            if re.match(".*\.vtk$", fName):
                self.ldsFileList.append(fName)
        self.ldsFileList.sort()
        # print " got those files: ",self.ldsFileList

        # extracting information about fields in the lds file
        fieldsElement = root_element.getFirstElement("Fields")
        if fieldsElement:
            fieldList = XMLUtils.CC3DXMLListPy(
                fieldsElement.getElements("Field"))
            #            print MODULENAME,"   fieldList=",fieldList
            #            print MODULENAME,"   dir(fieldList)=",dir(fieldList)  # ['__doc__', '__init__', '__iter__', '__module__', 'elementList', 'getBaseClass']
            ##            print MODULENAME,"   fieldList.getAttributes()=",fieldList.getAttributes()   # doesnt exist
            #            print MODULENAME,"   fieldList.elementList=",fieldList.elementList

            for fieldElem in fieldList:
                #                print MODULENAME,"  dir(fieldElem) = ",dir(fieldElem)
                #                print MODULENAME,"  fieldElem.getAttributes() = ",fieldElem.getAttributes() # <CC3DXML.MapStrStr; proxy of <Swig Object of type 'std::map< std::string,std::string,std::less< std::string >,std::allocator< std::pair< std::string const,std::string > > > *' at 0x1258e0b70> >
                fieldName = fieldElem.getAttribute("Name")
                #                print MODULENAME,"  fieldsUsed key = fieldElem.getAttribute('Name') =",fieldName   # e.g. 'my_field1' w/ a script
                #                print MODULENAME,"  fieldsUsed value = fieldElem.getAttribute('Type') =",fieldElem.getAttribute("Type")
                self.fieldsUsed[fieldElem.getAttribute(
                    "Name")] = fieldElem.getAttribute("Type")
                if fieldElem.findAttribute(
                        "Script"):  # True or False if present
                    # ToDo:  if a "CustomVis" Type was provided, require that a "Script" was also provided; else warn user
                    customVisScript = fieldElem.getAttribute("Script")
                    #                    print MODULENAME,"  fieldElem.getAttribute('Script') =",customVisScript
                    #                    self.fieldsUsed['Script'] = fieldElem.getAttribute("Script")
                    #                    self.customVisScriptDict[fieldName] = customVisScript

                    self.customVis = CompuCellSetup.createCustomVisPy(
                        fieldName)
                    self.customVis.registerVisCallbackFunction(
                        CompuCellSetup.vtkScriptCallback)
                    #                    print MODULENAME,' customVis.addActor:  fieldName (->vtkActor) =',fieldName
                    self.customVis.addActor(fieldName, "vtkActor")
                    #                    self.customVis.addActor(customVisScript,"customVTKScript")
                    self.customVis.addActor(
                        "customVTKScript",
                        customVisScript)  # we'll piggyback off the actorsDict
Esempio n. 4
0
    def start(self):

        self.visData = CompuCellSetup.createCustomVisPy("CustomCone")
        self.visData.registerVisCallbackFunction(self.visualize)
        self.visData.addActor("cone", "vtkActor")
 def start(self):
     
     self.visData=CompuCellSetup.createCustomVisPy("CustomCone")                
     self.visData.registerVisCallbackFunction(self.visualize)
     self.visData.addActor("cone","vtkActor")