Esempio n. 1
0
    def readSimulationData(self, _i):

        # self.counter+=1
        # if self.counter>3:
        # return
        # print "self.drawMutex=",self.drawMutex
        self.drawMutex.lock()
        # print "self.readFileSem.available()=",self.readFileSem.available()
        self.readFileSem.acquire()

        self.newFileBeingLoaded = True  # this flag is used to prevent calling  draw function when new data is read from hard drive
        # print "LOCKED self.newFileBeingLoaded=",self.newFileBeingLoaded
        # self.drawMutex.lock()
        if _i >= len(self.ldsFileList):
            return

        fileName = self.ldsFileList[_i]

        self.simulationDataReader = vtk.vtkStructuredPointsReader()
        self.currentFileName = os.path.join(self.ldsDir, fileName)
        self.simulationDataReader.SetFileName(self.currentFileName)
        # print "path= ", os.path.join(self.ldsDir,fileName)
        self.simulationDataReader.Update()
        self.simulationData = self.simulationDataReader.GetOutput()
        # print "self.simulationData",self.simulationData
        # print 'dimensions=',self.simulationData.GetDimensions()

        #updating fieldDim each time we read data

        import CompuCell
        self.fieldDimPrevious = self.fieldDim
        # self.fieldDimPrevious=CompuCell.Dim3D()

        dimFromVTK = self.simulationData.GetDimensions()

        self.fieldDim = CompuCell.Dim3D(dimFromVTK[0], dimFromVTK[1],
                                        dimFromVTK[2])

        #
        # self.fieldDim.x=dimFromVTK[0]
        # self.fieldDim.y=dimFromVTK[1]
        # self.fieldDim.z=dimFromVTK[2]

        # print 'self.fieldDim=',self.fieldDim

        # print "vtkStructuredPointsReader ERROR CODE=",self.simulationDataReader.GetErrorCode()

        self.currentStep = self.frequency * _i
        self.setCurrentStep(self.currentStep)
        # print "self.frequency=",self.frequency," _i=",self.frequency

        # print "\n\n\n\n FINISHED RUNNING readSimulationData step ",self.currentStep," \n\n\n"
        self.drawMutex.unlock()
        self.readFileSem.release()
Esempio n. 2
0
    def readSimulationDataNonBlocking(self, _i):
        self.newFileBeingLoaded = True  # this flag is used to prevent calling  draw function when new data is read from hard drive
        # print "LOCKED self.newFileBeingLoaded=",self.newFileBeingLoaded
        # self.drawMutex.lock()
        if _i >= len(self.ldsFileList):
            return False

        fileName = self.ldsFileList[_i]

        self.simulationDataReader = vtk.vtkStructuredPointsReader()

        self.currentFileName = os.path.join(self.ldsDir, fileName)
        print 'self.currentFileName=', self.currentFileName

        extractedMCS = self.extractMCSNumberFromFileName(self.currentFileName)
        if extractedMCS < 0:
            extractedMCS = _i

        self.simulationDataReader.SetFileName(self.currentFileName)
        # print "path= ", os.path.join(self.ldsDir,fileName)

        dataReaderIntAddr = self.__ui.extractAddressIntFromVtkObject(
            self.simulationDataReader)
        self.__ui.fieldExtractor.readVtkStructuredPointsData(
            dataReaderIntAddr
        )  # swig wrapper  on top of     vtkStructuredPointsReader.Update()  - releases GIL, hence can be used in multithreaded program that does not block GUI
        # # # self.simulationDataReader.Update() # does not erlease GIL - VTK ISSUE - cannot be used in multithreaded program - blocks GUI
        self.simulationData = self.simulationDataReader.GetOutput()

        import CompuCell
        self.fieldDimPrevious = self.fieldDim
        # self.fieldDimPrevious=CompuCell.Dim3D()

        dimFromVTK = self.simulationData.GetDimensions()

        self.fieldDim = CompuCell.Dim3D(dimFromVTK[0], dimFromVTK[1],
                                        dimFromVTK[2])

        self.currentStep = extractedMCS
        # # # self.currentStep = self.frequency * _i # this is how we set CMS for CML reading before
        self.setCurrentStep(self.currentStep)

        return True
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