コード例 #1
0
    def readFromPolyFile(self, filebase, flagsAdd="", verbose=0):
        """
        read triangle representation from filebase.poly file
        assumes the nbase data member is set appropriately
        """
        reader = TriangleUtils.TriangleInputFileReader()
        if verbose > 0:
            print 'readFromPolyFile filebase= ', filebase
        #end if

        polyDataInfo, polyData = reader.readPoly(filebase,
                                                 nbase=self.nbase,
                                                 verbose=verbose)

        if verbose > 3:
            for type in ['node', 'segment', 'hole', 'region']:
                print 'Poly: ', type, 'Info= \n', polyDataInfo[type], '\n'
            #end for
        #end if

        nodes, nodesA, nodesM = (polyData['node']['nodes'],
                                 polyData['node']['nodeAttributes'],
                                 polyData['node']['nodeMarkers'])
        segments, segmentsM = (polyData['segment']['segments'],
                               polyData['segment']['segmentMarkers'])
        holes = polyData['hole']['holes']
        regions = polyData['region']['regions']

        if verbose > 3:
            print """Poly file read:
            nodes   = \n%s\n nodeAttributes= \n%s\n nodeMarkers= \n%s\n
            segments= \n%s\n segmentMarkers= \n%s\n
            holes   = \n%s\n
            regions = \n%s\n
            """ % (nodes, nodesA, nodesM, segments, segmentsM, holes, regions)
        #end if
        tri0 = triangleWrappers.new()

        if nodesM == None:
            triangleWrappers.setPoints(tri0, nodes)
        else:
            nodesMtmp = numpy.zeros(nodesM.shape, 'i')
            nodesMtmp[:] = nodesM
            nodesM = nodesMtmp
            triangleWrappers.setPointsAndMarkers(tri0, nodes, nodesM)
        if not nodesA == None:
            triangleWrappers.setPointAttributes(tri0, nodesA)
        #end if
        if segmentsM == None:
            triangleWrappers.setSegments(tri0, segments)
        else:
            triangleWrappers.setSegmentsAndMarkers(tri0, segments, segmentsM)
        #end if
        if (not holes == None):
            triangleWrappers.setHoles(tri0, holes)
        #end if
        if (not regions == None):
            #print 'setting trin1 regions=\n',regions2
            triangleWrappers.setRegions(tri0, regions)
        #end if

        flags = flagsAdd + self.baseFlags
        if flags.find('p') == -1:
            print 'flags = ', flags, ' must have p, appending'
            flags += "p"
        #end
        if flags.find('v') >= 0:
            self.makeVoronoi = True
            if verbose > 0:
                print 'readNodeAndEle makeVoronoi= ', self.makeVoronoi, ' flags= ', flags
        #end if
        self.lastFlags = flags
        #reset data representations if necessary
        self.resetDefaultTrirep(index=0, verbose=verbose)
        if self.makeVoronoi:
            self.resetDefaultVorrep(index=0, verbose=verbose)
        #end vorrep initialized

        if self.makeVoronoi:
            triangleWrappers.applyTriangulate(flags, tri0, self.trirep[0],
                                              self.vorrep[0])
            #handles no longer contain trivial representations
            self.trirepDefaultInit[0] = False
            self.vorrepDefaultInit[0] = False
        else:
            triangleWrappers.applyTriangulateNoVoronoi(flags, tri0,
                                                       self.trirep[0])
            #handle no longer contains trivial representations
            self.trirepDefaultInit[0] = False
        #end if

        #clean up?
        del tri0
コード例 #2
0
ファイル: TriangleTools.py プロジェクト: arnsong/proteus
    def readFromPolyFile(self,filebase,flagsAdd="",verbose=0):
        """Reads in the triangle representation from filebase.poly file.

        Parameters
        ----------
        filebase : str
            The filename with the triangluation.
        flagsAdd : str
        verbose : int
            A flag indicating how much information to pipe to stdout.

        Notes
        -----
        Function assumes the nbase data member is set appropriately.
        """
        reader = TriangleUtils.TriangleInputFileReader()
        if verbose > 0:
            logEvent('readFromPolyFile filebase= ',filebase)
        #end if

        polyDataInfo,polyData = reader.readPoly(filebase,nbase=self.nbase,
                                                verbose=verbose)

        if verbose > 3:
            for type in ['node','segment','hole','region']:
                logEvent('Poly: ',type,'Info= \n',polyDataInfo[type],'\n')
            #end for
        #end if

        nodes,nodesA,nodesM = (polyData['node']['nodes'],
                               polyData['node']['nodeAttributes'],
                               polyData['node']['nodeMarkers'])
        segments,segmentsM   = (polyData['segment']['segments'],
                                polyData['segment']['segmentMarkers'])
        holes                 = polyData['hole']['holes']
        regions               = polyData['region']['regions']

        if verbose > 3:
            logEvent("""Poly file read:
            nodes   = \n%s\n nodeAttributes= \n%s\n nodeMarkers= \n%s\n
            segments= \n%s\n segmentMarkers= \n%s\n
            holes   = \n%s\n
            regions = \n%s\n
            """ % (nodes,nodesA,nodesM,segments,segmentsM,holes,regions))
        #end if
        tri0 = triangleWrappers.new()

        if nodesM is None:
            triangleWrappers.setPoints(tri0,nodes)
        else:
            nodesMtmp = numpy.zeros(nodesM.shape,'i')
            nodesMtmp[:] = nodesM
            nodesM = nodesMtmp
            triangleWrappers.setPointsAndMarkers(tri0,nodes,nodesM)
        if nodesA is not None:
            triangleWrappers.setPointAttributes(tri0,nodesA)
        #end if
        if segmentsM is None:
            triangleWrappers.setSegments(tri0,segments)
        else:
            triangleWrappers.setSegmentsAndMarkers(tri0,segments,segmentsM)
        #end if
        if (holes is not None):
            triangleWrappers.setHoles(tri0,holes)
        #end if
        if (regions is not None):
            #print 'setting trin1 regions=\n',regions2
            triangleWrappers.setRegions(tri0,regions)
        #end if

        flags = flagsAdd+self.baseFlags
        if flags.find('p') == -1:
            logEvent('flags = ',flags,' must have p, appending')
            flags += "p"
        #end
        if flags.find('v') >= 0:
            self.makeVoronoi = True
            if verbose > 0:
                logEvent('readNodeAndEle makeVoronoi= ',self.makeVoronoi,' flags= ',flags)
        #end if
        self.lastFlags = flags
        #reset data representations if necessary
        self.resetDefaultTrirep(index=0,verbose=verbose)
        if self.makeVoronoi:
            self.resetDefaultVorrep(index=0,verbose=verbose)
        #end vorrep initialized

        if self.makeVoronoi:
            triangleWrappers.applyTriangulate(flags,tri0,self.trirep[0],self.vorrep[0])
            #handles no longer contain trivial representations
            self.trirepDefaultInit[0] = False
            self.vorrepDefaultInit[0] = False
        else:
            triangleWrappers.applyTriangulateNoVoronoi(flags,tri0,self.trirep[0])
            #handle no longer contains trivial representations
            self.trirepDefaultInit[0] = False
        #end if

        #clean up?
        del tri0
コード例 #3
0
    def readFromNodeAndEleFiles(self, filebase, flagsAdd="", verbose=0):
        """
        read triangle representation from filebase.node and filebase.ele
        files. assumes the nbase data member is set appropriately
        """
        reader = TriangleUtils.TriangleInputFileReader()
        if verbose > 0:
            print 'readFromNodeAndEleFiles filebase= ', filebase
        #end if
        nodeDataInfo, nodeData = reader.readNodes(filebase, nbase=self.nbase)
        nodes, nodesA, nodesM = (nodeData['nodes'], nodeData['nodeAttributes'],
                                 nodeData['nodeMarkers'])

        if verbose > 3:
            print 'Nodes: nodeInfo= ', nodeDataInfo
            print """Nodes: nodes= \n%s\n nodeAttributes= \n%s\n nodeMarkers= \n%s
            """ % (nodes, nodesA, nodesM)
        #end if

        triDataInfo, triData = reader.readTriangles(filebase, nbase=self.nbase)
        triangles, trianglesA = triData['triangles'], triData[
            'triangleAttributes']

        if verbose > 3:
            print 'Triangles: triInfo= ', triDataInfo
            print """Triangles: elems= \n%s\n triAttributes= \n%s
            """ % (triangles, trianglesA)
        #end if

        #now create an initial representation
        tri0 = triangleWrappers.new()

        if nodesM == None:
            triangleWrappers.setPoints(tri0, nodes)
        else:
            triangleWrappers.setPointsAndMarkers(tri0, nodes, nodesM)
        if not nodesA == None:
            triangleWrappers.setPointAttributes(tri0, nodesA)
        #end if

        triangleWrappers.setTriangles(tri0, triangles)
        if not trianglesA == None:
            triangleWrappers.setTriangleAttributes(tri0, trianglesA)

        #run triangulate on it using the base flags and whatever else was
        #added
        flags = flagsAdd + self.baseFlags
        if flags.find('v') >= 0:
            self.makeVoronoi = True
            if verbose > 0:
                print 'readNodeAndEle makeVoronoi= ', self.makeVoronoi, ' flags= ', flags
        #end if
        self.lastFlags = flags

        #reset data representations if necessary
        self.resetDefaultTrirep(index=0, verbose=verbose)
        if self.makeVoronoi:
            self.resetDefaultVorrep(index=0, verbose=verbose)
        #end vorrep initialized

        if self.makeVoronoi:
            triangleWrappers.applyTriangulate(flags, tri0, self.trirep[0],
                                              self.vorrep[0])
            #handles no longer contain trivial representations
            self.trirepDefaultInit[0] = False
            self.vorrepDefaultInit[0] = False
        else:
            triangleWrappers.applyTriangulateNoVoronoi(flags, tri0,
                                                       self.trirep[0])
            #handle no longer contains trivial representations
            self.trirepDefaultInit[0] = False
        #end if

        #do I need to clean up explicitly?
        del tri0
コード例 #4
0
ファイル: TriangleTools.py プロジェクト: arnsong/proteus
    def readFromNodeAndEleFiles(self,filebase,flagsAdd="",verbose=0):
        """
        read triangle representation from filebase.node and filebase.ele
        files. assumes the nbase data member is set appropriately
        """
        reader = TriangleUtils.TriangleInputFileReader()
        if verbose > 0:
            logEvent('readFromNodeAndEleFiles filebase= ',filebase)
        #end if
        nodeDataInfo,nodeData = reader.readNodes(filebase,nbase=self.nbase)
        nodes,nodesA,nodesM = (nodeData['nodes'],
                               nodeData['nodeAttributes'],
                               nodeData['nodeMarkers'])

        if verbose > 3:
            logEvent('Nodes: nodeInfo= ',nodeDataInfo)
            logEvent("""Nodes: nodes= \n%s\n nodeAttributes= \n%s\n nodeMarkers= \n%s
            """ % (nodes,nodesA,nodesM))
        #end if

        triDataInfo,triData = reader.readTriangles(filebase,nbase=self.nbase)
        triangles,trianglesA = triData['triangles'],triData['triangleAttributes']

        if verbose > 3:
            logEvent('Triangles: triInfo= ',triDataInfo)
            logEvent("""Triangles: elems= \n%s\n triAttributes= \n%s
            """ % (triangles,trianglesA))
        #end if

        #now create an initial representation
        tri0 = triangleWrappers.new()

        if nodesM is None:
            triangleWrappers.setPoints(tri0,nodes)
        else:
            triangleWrappers.setPointsAndMarkers(tri0,nodes,nodesM)
        if nodesA is not None:
            triangleWrappers.setPointAttributes(tri0,nodesA)
        #end if

        triangleWrappers.setTriangles(tri0,triangles)
        if trianglesA is not None:
            triangleWrappers.setTriangleAttributes(tri0,trianglesA)

        #run triangulate on it using the base flags and whatever else was
        #added
        flags = flagsAdd+self.baseFlags
        if flags.find('v') >= 0:
            self.makeVoronoi = True
            if verbose > 0:
                logEvent('readNodeAndEle makeVoronoi= ',self.makeVoronoi,' flags= ',flags)
        #end if
        self.lastFlags = flags

        #reset data representations if necessary
        self.resetDefaultTrirep(index=0,verbose=verbose)
        if self.makeVoronoi:
            self.resetDefaultVorrep(index=0,verbose=verbose)
        #end vorrep initialized

        if self.makeVoronoi:
            triangleWrappers.applyTriangulate(flags,tri0,self.trirep[0],self.vorrep[0])
            #handles no longer contain trivial representations
            self.trirepDefaultInit[0] = False
            self.vorrepDefaultInit[0] = False
        else:
            triangleWrappers.applyTriangulateNoVoronoi(flags,tri0,self.trirep[0])
            #handle no longer contains trivial representations
            self.trirepDefaultInit[0] = False
        #end if

        #do I need to clean up explicitly?
        del tri0