Пример #1
0
    def __init__(self,baseFlags="zen",nbase=0,verbose=0):
        """
        initialize the triangulateio object,
        keep track of what numbering scheme it uses,
        create a base set of flags for triangulate (e.g., z if using base 0)

        does not create a Voronoi diagram by default
        """
        self.trirep = []
        self.trirep.append(triangulate.new())
        self.trirepDefaultInit = []
        self.trirepDefaultInit.append(True)
        self.vorrep = []
        self.vorrep.append(triangulate.new()) #don't create a Voronoi diagram by default
        self.makeVoronoi = False
        self.vorrepDefaultInit = []
        self.vorrepDefaultInit.append(True)
        assert(nbase in [0,1])
        self.nbase  = nbase 
        self.baseFlags = baseFlags
        if self.nbase == 0 and self.baseFlags.find('z') == -1:
            print """WARNING TriangleMesh base numbering= %d
            reqires z in baseFlags = %s, adding """ % (self.nbase,self.baseFlags)
            self.baseFlags += "z"
        #end if
        if self.baseFlags.find('v') >= 0:
            self.makeVoronoi = True
        if verbose > 0:
            print """TriangleBaseMesh nbase=%d baseFlags= %s """ % (self.nbase,
                                                                    self.baseFlags)
        #end if
        #keep track of last set of flags used to generate rep
        self.lastFlags = None
        #to make printing out info easier
        self.infoFormat = """triangulation:
Пример #2
0
    def triangulate(self, area=None, mode='pzq27eQ'):
        """
        Perform an initial triangulation.

        @param area is a max area constraint
        @param mode a string of TRIANGLE switches. Refer to the TRIANGLE doc for more info about mode:
        http://www.cs.cmu.edu/~quake/triangle.switch.html

        @note invoke this after setting the boundary points, segments, and optionally hole positions.
        """

        if not self.has_points and not self.has_segmts:
            print('%s: Error. Must set points, segments, and optionally holes prior to calling "triangulate"' \
                  % (__file__))
            return

        # mode string
        # z: start indexing with zero
        # q<angle>: quality mesh
        # e: edge
        # p: planar straight line graph
        # Q: quiet mode

        self.mode = mode
        if area:
            self.area = area
            mode += 'a%f' % area

        if len(self.hndls) <= 1: self.hndls.append(triangulate.new())
        triangulate.triangulate(mode, self.hndls[0], self.hndls[1], self.h_vor)
        self.has_trgltd = True
Пример #3
0
    def readFromNodeFile(self, filebase, flagsAdd="", verbose=0):
        """
        read triangle representation from filebase.node
        files. assumes the nbase data member is set appropriately
        """
        reader = triIfaceUtils.TriangleInputFileReader()
        if verbose > 0:
            print 'readFromNodeAndEleFiles filebase= ', filebase
        #end if
        #could specify comment character too
        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

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

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

        #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:
            triangulate.applyTriangulate(flags, tri0, self.trirep[0],
                                         self.vorrep[0])
            #handles no longer contain trivial representations
            self.trirepDefaultInit[0] = False
            self.vorrepDefaultInit[0] = False
        else:
            triangulate.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
    def triangulate(self, area=None, mode='pzq27eQ'):

        """
        Perform an initial triangulation. Invoke this after setting
        the boundary points, segments, and optionally hole positions.
        Here, area is a max area constraint and mode a string of TRIANGLE
        switches. Check the TRIANGLE doc for more info about mode:
        http://www.cs.cmu.edu/~quake/triangle.switch.html
        """

        if not self.has_points and not self.has_segmts:
            print('%s: Error. Must set points, segments, and optionally holes prior to calling "triangulate"' \
                  % (__file__))
            return

        # mode string
        # z: start indexing with zero
        # q<angle>: quality mesh
        # e: edge
        # p: planar straight line graph
        # Q: quiet mode

        self.mode = mode
        if area:
            self.area = area
            mode += 'a%f'% area

        if len(self.hndls) <= 1: self.hndls.append( triangulate.new() )
        triangulate.triangulate(mode, self.hndls[0], self.hndls[1], self.h_vor)
        self.has_trgltd = True
Пример #5
0
    def __init__(self):
        """
        Constructor
        """

        # create handles to hold the
        # triangulation structures
        self.hndls = [
            triangulate.new(),
        ]
        self.h_vor = triangulate.new()

        self.area = None
        self.mode = ''

        self.has_points = False
        self.has_segmts = False
        self.has_trgltd = False
Пример #6
0
    def __init__(self):

        """
        Constructor. 
        """

        # create handles to hold the
        # triangulation structures

        self.hndls = [triangulate.new(),]
        self.h_vor =  triangulate.new()
        
        self.area  = None
        self.mode  = ''

        self.has_points = False
        self.has_segmts = False
        self.has_trgltd = False
        self.has_atts   = False
Пример #7
0
    def convertFromAdhPyUtilMesh(self, meshin, verbose=0):
        """
        generate a Triangle mesh representation from an adhPyUtil mesh.
        This version will copy over the nodes and elements from the
        adhPyUtil mesh.

        Deletes the existing Triangle mesh and regenerates.
        """

        #first check that the input mesh has the correct dimensions and
        #minimal information necessary
        spaceDim = 2
        assert (meshin.nElementBoundaries_element == spaceDim + 1)
        assert (not meshin.nodeArray == None)
        assert (not meshin.elementNodesArray == None)

        #get a clean slate
        tri0 = triangulate.new()
        #don't set any markers for now
        #input array should be nNodes by spacedim
        nodesIn = meshin.nodeArray[:, :spaceDim]
        triangulate.setPoints(tri0, nodesIn)
        #triangle array should be nElements x 3
        triAin = meshin.elementNodesArray[:, :spaceDim + 1]
        triangulate.setTriangles(tri0, triAin)

        flagsAdd = "r"  #use element and node connections
        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:
            triangulate.applyTriangulate(flags, tri0, self.trirep[0],
                                         self.vorrep[0])
            #handles no longer contain trivial representations
            self.trirepDefaultInit[0] = False
            self.vorrepDefaultInit[0] = False

        else:
            triangulate.applyTriangulateNoVoronoi(flags, tri0, self.trirep[0])
            #handle no longer contains trivial representations
            self.trirepDefaultInit[0] = False
        #end if

        #clean up explicitly
        del tri0
Пример #8
0
    def convertFromAdhPyUtilMesh(self,meshin,verbose=0):
        """
        generate a Triangle mesh representation from an adhPyUtil mesh.
        This version will copy over the nodes and elements from the
        adhPyUtil mesh.

        Deletes the existing Triangle mesh and regenerates.
        """

        #first check that the input mesh has the correct dimensions and
        #minimal information necessary
        spaceDim = 2
        assert(meshin.nElementBoundaries_element == spaceDim+1)
        assert(not meshin.nodeArray == None)
        assert(not meshin.elementNodesArray == None)

        #get a clean slate
        tri0 = triangulate.new()
        #don't set any markers for now
        #input array should be nNodes by spacedim
        nodesIn = meshin.nodeArray[:,:spaceDim]
        triangulate.setPoints(tri0,nodesIn)
        #triangle array should be nElements x 3
        triAin  = meshin.elementNodesArray[:,:spaceDim+1]
        triangulate.setTriangles(tri0,triAin)

        flagsAdd = "r" #use element and node connections
        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:
            triangulate.applyTriangulate(flags,tri0,self.trirep[0],self.vorrep[0])
            #handles no longer contain trivial representations
            self.trirepDefaultInit[0] = False
            self.vorrepDefaultInit[0] = False
            
        else:
            triangulate.applyTriangulateNoVoronoi(flags,tri0,self.trirep[0])
            #handle no longer contains trivial representations
            self.trirepDefaultInit[0] = False
        #end if

        #clean up explicitly
        del tri0
Пример #9
0
    def __init__(self, baseFlags="zen", nbase=0, verbose=0):
        """
        initialize the triangulateio object,
        keep track of what numbering scheme it uses,
        create a base set of flags for triangulate (e.g., z if using base 0)

        does not create a Voronoi diagram by default
        """
        self.trirep = []
        self.trirep.append(triangulate.new())
        self.trirepDefaultInit = []
        self.trirepDefaultInit.append(True)
        self.vorrep = []
        self.vorrep.append(
            triangulate.new())  #don't create a Voronoi diagram by default
        self.makeVoronoi = False
        self.vorrepDefaultInit = []
        self.vorrepDefaultInit.append(True)
        assert (nbase in [0, 1])
        self.nbase = nbase
        self.baseFlags = baseFlags
        if self.nbase == 0 and self.baseFlags.find('z') == -1:
            print """WARNING TriangleMesh base numbering= %d
            reqires z in baseFlags = %s, adding """ % (self.nbase,
                                                       self.baseFlags)
            self.baseFlags += "z"
        #end if
        if self.baseFlags.find('v') >= 0:
            self.makeVoronoi = True
        if verbose > 0:
            print """TriangleBaseMesh nbase=%d baseFlags= %s """ % (
                self.nbase, self.baseFlags)
        #end if
        #keep track of last set of flags used to generate rep
        self.lastFlags = None
        #to make printing out info easier
        self.infoFormat = """triangulation:
Пример #10
0
 def resetDefaultVorrep(self, index=0, verbose=0):
     """
     reset the Triangle mesh Voronoi representation if it has
     been set to something nontrivial
     """
     assert (index in range(0, len(self.vorrep)))
     #delete the existing representation if it has been initialized
     if not self.vorrepDefaultInit[index]:
         if verbose > -1:
             print 'TriangleIface deleting current vorrep[', index, ']'
         #end verbose
         del self.vorrep[index]
         #get a new represenation
         self.vorrep[index] = triangulate.new()
         selt.vorrepDefaultInit[index] = True
Пример #11
0
 def resetDefaultVorrep(self,index=0,verbose=0):
     """
     reset the Triangle mesh Voronoi representation if it has
     been set to something nontrivial
     """
     assert(index in range(0,len(self.vorrep)))
     #delete the existing representation if it has been initialized
     if not self.vorrepDefaultInit[index]:
         if verbose > -1:
             print 'TriangleIface deleting current vorrep[',index,']'
         #end verbose
         del self.vorrep[index]
         #get a new represenation
         self.vorrep[index] = triangulate.new()
         selt.vorrepDefaultInit[index] = True
Пример #12
0
    def refine(self, area_ratio=2.0):
        """
        Apply a refinement to the triangulation. Should be called after
        performing an initial triangulation. Here, area_ratio represents
        the max triangle area reduction factor.
        """

        if not self.has_trgltd:
            print('%s: Error. Must triangulate prior to calling "refine"' \
                  % (__file__))
            return

        self.hndls.append(triangulate.new())

        mode = self.mode + 'cr'
        if self.area:
            self.area /= area_ratio
            mode += 'a%f' % self.area

        triangulate.triangulate(mode, self.hndls[-2], self.hndls[-1],
                                self.h_vor)
Пример #13
0
    def refine(self, area_ratio=2.0):

        """
        Apply a refinement to the triangulation. Should be called after
        performing an initial triangulation. Here, area_ratio represents
        the max triangle area reduction factor.
        """

        if not self.has_trgltd:
            print('%s: Error. Must triangulate prior to calling "refine"' \
                  % (__file__))
            return

        self.hndls.append( triangulate.new() )

        mode = self.mode + 'cr'
        if self.area:
            self.area /= area_ratio
            mode += 'a%f' % self.area

        triangulate.triangulate(mode, self.hndls[-2],
                                self.hndls[-1], self.h_vor)
Пример #14
0
def tricall0():
    import triIfaceUtils
    import triIfaceFileUtils
    #define some flags for how the script will run
    verbose = 2   #level of output
    tinfo = """triangulation:
number of points        = %d
attributes per point    = %d
number of triangles     = %d
nodes per triangle      = %d
attributes per triangle = %d
number of segments      = %d
number of holes         = %d
number of regions       = %d
number of edges         = %d
"""

    trin = triangulate.new()
    pointsin = Numeric.array([[0.0, 0.0],
                              [1.0,0.0],
                              [1.0,10.0],
                              [0.0,10.0]])
    npoints = pointsin.shape[0]
    pattsin = Numeric.array([0.0, 1.0, 11.0, 10.0])
    pmarkin = Numeric.zeros((npoints,),Numeric.Int)
    pmarkin[1] = 2
    pregion =  Numeric.array([[0.5,5.0,7.0,0.1]])
    if verbose > 3:
        print 'pregion shape=',pregion.shape
    #end verbose
    triangulate.setPointsAndMarkers(trin,pointsin,pmarkin)
    triangulate.setPointAttributes(trin,pattsin)
    triangulate.setRegions(trin,pregion)
    
    tiInfo = triangulate.getInfo(trin)

    print 'trin info says'
    print tinfo % tiInfo

    #create a simple flag list
    flags = "pczAevn"
    
    trimid = triangulate.new()
    vorout = triangulate.new()
    
    triangulate.applyTriangulate(flags,trin,trimid,vorout)

    tmInfo = triangulate.getInfo(trimid)

    print 'trimid info says'
    print tinfo % tmInfo

    if verbose > 1:
        points0 = triangulate.getPoints(trin)
        print 'in points=\n',points0
        elems0 = triangulate.getTriangles(trin)
        print 'in elems=\n',elems0
        elems1 = triangulate.getTriangles(trimid)
        print 'out elems=\n',elems1
    #end verbose
    if verbose > 1:
        print 'calling printReport for input'
        triangulate.printReport(trin)
        print 'calling printReport for output'
        triangulate.printReport(trimid)
    #end verbose
    triIfaceUtils.writeOutTriangulation(trimid,"trimesh")

    #now refine intermediate triangle
    nelmsmid = tmInfo[2]
    midArea = Numeric.zeros((nelmsmid,),Numeric.Float)
    midArea[0] = 3.0
    midArea[1] = 1.0

    triangulate.setTriangleAreas(trimid,midArea)
    
    triout = triangulate.new()
    flags  = "prazBP"
    triangulate.applyTriangulateNoVoronoi(flags,trimid,triout)
    
    triIfaceUtils.writeOutTriangulation(triout,"trimesh.1")


    #now view with showme
    showme = "../bin/showme"
    showmecmd = showme+" trimesh"

    failure = 0
    failure = triIfaceFileUtils.checkFileExists(showme)
    failure = os.system(showmecmd)
    
    #manually delete things for debugging
    print 'deleting trin'
    del trin
    print 'deleting trimid'
    del trimid
    print 'deleting vor'
    del vorout
    print 'deleting triout'
    del triout

    return failure
Пример #15
0
def tricall2():
    """
    test reading Triangle file utilities
    """
    import triIfaceUtils
    import triIfaceFileUtils

    reader = triIfaceUtils.TriangleInputFileReader()
    filebase = 'trimesh'
    
    nodeDataInfo,nodeData = reader.readNodes(filebase)
    nodes,nodesA,nodesM = (nodeData['nodes'],
                           nodeData['nodeAttributes'],
                           nodeData['nodeMarkers'])
    
    print 'Nodes: nodeInfo= ',nodeDataInfo
    print """Nodes: nodes= \n%s\n nodeAttributes= \n%s\n nodeMarkers= \n%s\n """ % (nodes,
                                                                                    nodesA,
                                                                                    nodesM)
    
    triDataInfo,triData = reader.readTriangles(filebase)
    triangles,trianglesA = triData['triangles'],triData['triangleAttributes']
    
    print 'Triangles: triInfo= ',triDataInfo
    print """Triangles: elems= \n%s\n triAttributes= \n%s\n""" % (triangles,
                                                                  trianglesA)

    #write out assuming just read in node and ele files
    filebaseout = filebase+'-out-0'
    tri0 = triangulate.new()

    
    if nodesM == None:
        triangulate.setPoints(tri0,nodes)
    else:
        triangulate.setPointsAndMarkers(tri0,nodes,nodesM)
    if not nodesA == None: 
        triangulate.setPointAttributes(tri0,nodesA)
    #end if
    
    triangulate.setTriangles(tri0,triangles)
    if not trianglesA == None: 
        triangulate.setTriangleAttributes(tri0,trianglesA)
    #end if
    triIfaceUtils.writeOutTriangulation(tri0,filebaseout,nbase=0,verbose=0)

    #now view with showme
    showme = "../bin/showme"
    showmecmd = """showme %s """ % filebaseout

    failure = 0
    failure = triIfaceFileUtils.checkFileExists(showme)
    failure = os.system(showmecmd)
    
    ##now read from .poly file
    polyDataInfo,polyData = reader.readPoly(filebase)

    
    for type in ['node','segment','hole','region']:
        print 'Poly: ',type,'Info= \n',polyDataInfo[type],'\n'
    #
    nodes2,nodesA2,nodesM2 = (polyData['node']['nodes'],
                              polyData['node']['nodeAttributes'],
                              polyData['node']['nodeMarkers'])
    segments2,segmentsM2   = (polyData['segment']['segments'],
                              polyData['segment']['segmentMarkers'])
    holes2                 = polyData['hole']['holes']
    regions2               = polyData['region']['regions']
    
    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
    """ % (nodes2,nodesA2,nodesM2,segments2,segmentsM2,holes2,regions2)

    ### now create a triangulation and write out the data arrays?
    trin1 = triangulate.new()
    
    filebaseout1 = filebase+"-out-1"

    if nodesM2 == None:
        triangulate.setPoints(trin1,nodes2,nodesM2)
    else:
        triangulate.setPointsAndMarkers(trin1,nodes2,nodesM2)
    if not nodesA2 == None:
        triangulate.setPointAttributes(trin1,nodesA2)
    #end if

    if segmentsM2 == None:
        triangulate.setSegments(trin1,segments2)
    else:
        triangulate.setSegmentsAndMarkers(trin1,segments2,segmentsM2)
    if not holes2 == None:
        triangulate.setHoles(trin1,holes2)
    #end if
    if not regions2 == None:
        #print 'setting trin1 regions=\n',regions2
        triangulate.setRegions(trin1,regions2)
    #end if
    trout1 = triangulate.new()
    flags = "zpne" #needs to be base 0 if Input was that way (and nbase=0)
    triangulate.applyTriangulateNoVoronoi(flags,trin1,trout1)

    triIfaceUtils.writeOutTriangulation(trout1,filebaseout1,nbase=0,verbose=0)

    #now view with showme
    showmecmd = """showme %s """ % filebaseout1

    failure = 0
    failure = triIfaceFileUtils.checkFileExists(showme)
    failure = os.system(showmecmd)
Пример #16
0
def tricall0():
    import triIfaceUtils
    import triIfaceFileUtils
    #define some flags for how the script will run
    verbose = 2  #level of output
    tinfo = """triangulation:
number of points        = %d
attributes per point    = %d
number of triangles     = %d
nodes per triangle      = %d
attributes per triangle = %d
number of segments      = %d
number of holes         = %d
number of regions       = %d
number of edges         = %d
"""

    trin = triangulate.new()
    pointsin = Numeric.array([[0.0, 0.0], [1.0, 0.0], [1.0, 10.0], [0.0,
                                                                    10.0]])
    npoints = pointsin.shape[0]
    pattsin = Numeric.array([0.0, 1.0, 11.0, 10.0])
    pmarkin = Numeric.zeros((npoints, ), Numeric.Int)
    pmarkin[1] = 2
    pregion = Numeric.array([[0.5, 5.0, 7.0, 0.1]])
    if verbose > 3:
        print 'pregion shape=', pregion.shape
    #end verbose
    triangulate.setPointsAndMarkers(trin, pointsin, pmarkin)
    triangulate.setPointAttributes(trin, pattsin)
    triangulate.setRegions(trin, pregion)

    tiInfo = triangulate.getInfo(trin)

    print 'trin info says'
    print tinfo % tiInfo

    #create a simple flag list
    flags = "pczAevn"

    trimid = triangulate.new()
    vorout = triangulate.new()

    triangulate.applyTriangulate(flags, trin, trimid, vorout)

    tmInfo = triangulate.getInfo(trimid)

    print 'trimid info says'
    print tinfo % tmInfo

    if verbose > 1:
        points0 = triangulate.getPoints(trin)
        print 'in points=\n', points0
        elems0 = triangulate.getTriangles(trin)
        print 'in elems=\n', elems0
        elems1 = triangulate.getTriangles(trimid)
        print 'out elems=\n', elems1
    #end verbose
    if verbose > 1:
        print 'calling printReport for input'
        triangulate.printReport(trin)
        print 'calling printReport for output'
        triangulate.printReport(trimid)
    #end verbose
    triIfaceUtils.writeOutTriangulation(trimid, "trimesh")

    #now refine intermediate triangle
    nelmsmid = tmInfo[2]
    midArea = Numeric.zeros((nelmsmid, ), Numeric.Float)
    midArea[0] = 3.0
    midArea[1] = 1.0

    triangulate.setTriangleAreas(trimid, midArea)

    triout = triangulate.new()
    flags = "prazBP"
    triangulate.applyTriangulateNoVoronoi(flags, trimid, triout)

    triIfaceUtils.writeOutTriangulation(triout, "trimesh.1")

    #now view with showme
    showme = "../bin/showme"
    showmecmd = showme + " trimesh"

    failure = 0
    failure = triIfaceFileUtils.checkFileExists(showme)
    failure = os.system(showmecmd)

    #manually delete things for debugging
    print 'deleting trin'
    del trin
    print 'deleting trimid'
    del trimid
    print 'deleting vor'
    del vorout
    print 'deleting triout'
    del triout

    return failure
Пример #17
0
    def readFromPolyFile(self, filebase, flagsAdd="", verbose=0):
        """
        read triangle representation from filebase.poly file
        assumes the nbase data member is set appropriately
        """
        reader = triIfaceUtils.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 = triangulate.new()

        if nodesM == None:
            triangulate.setPoints(tri0, nodes)
        else:
            triangulate.setPointsAndMarkers(tri0, nodes, nodesM)
        if not nodesA == None:
            triangulate.setPointAttributes(tri0, nodesA)
        #end if
        if segmentsM == None:
            triangulate.setSegments(tri0, segments)
        else:
            triangulate.setSegmentsAndMarkers(tri0, segments, segmentsM)
        #end if
        if (not holes == None):
            triangulate.setHoles(tri0, holes)
        #end if
        if (not regions == None):
            #print 'setting trin1 regions=\n',regions2
            triangulate.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:
            triangulate.applyTriangulate(flags, tri0, self.trirep[0],
                                         self.vorrep[0])
            #handles no longer contain trivial representations
            self.trirepDefaultInit[0] = False
            self.vorrepDefaultInit[0] = False
        else:
            triangulate.applyTriangulateNoVoronoi(flags, tri0, self.trirep[0])
            #handle no longer contains trivial representations
            self.trirepDefaultInit[0] = False
        #end if

        #clean up?
        del tri0
Пример #18
0
#!/usr/bin/env python
#import standard Python modules
import sys, os
#module for triangle
import triangulate
import Numeric
#define some flags for how the script will run
verbose = 2  #level of output

trin = triangulate.new()
print 'trin= ', trin
pointsin = Numeric.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
marksin = Numeric.ones((4, ), Numeric.Int)

triangulate.setPoints(trin, pointsin, marksin)

pointsout = triangulate.getPoints(trin)
pointsout2 = triangulate.getPointsCopy(trin)
marksout = triangulate.getPointMarkers(trin)
print 'pointsin= ', pointsin
print 'pointsout= ', pointsout
print 'pointsoutCopy= ', pointsout2
print 'pointmarksin= ', marksin
print 'pointmarksout= ', marksout

#create some point attributes,
npts = pointsout.shape[0]
natts = 1
patts = Numeric.zeros((npts, natts), Numeric.Float)
for i in range(npts):
    patts[i, :] = pointsout[i, 0]**2 + pointsout[i, 1]**2
Пример #19
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 = triIfaceUtils.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 = triangulate.new()
        
        if nodesM == None:
            triangulate.setPoints(tri0,nodes)
        else:
            triangulate.setPointsAndMarkers(tri0,nodes,nodesM)
        if not nodesA == None: 
            triangulate.setPointAttributes(tri0,nodesA)
        #end if
        
        triangulate.setTriangles(tri0,triangles)
        if not trianglesA == None: 
            triangulate.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:
            triangulate.applyTriangulate(flags,tri0,self.trirep[0],self.vorrep[0])
            #handles no longer contain trivial representations
            self.trirepDefaultInit[0] = False
            self.vorrepDefaultInit[0] = False
        else:
            triangulate.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
Пример #20
0
#!/usr/bin/env python
#import standard Python modules
import sys,os
#module for triangle
import triangulate
import Numeric
#define some flags for how the script will run
verbose = 2   #level of output

trin = triangulate.new()
print 'trin= ',trin
pointsin =  Numeric.array([[0.0, 0.0],
                        [1.0,0.0],
                        [1.0,1.0],
                        [0.0,1.0]])
marksin  = Numeric.ones((4,),Numeric.Int)

triangulate.setPoints(trin,pointsin,marksin)

pointsout = triangulate.getPoints(trin)
pointsout2 = triangulate.getPointsCopy(trin)
marksout = triangulate.getPointMarkers(trin)
print 'pointsin= ',pointsin
print 'pointsout= ',pointsout
print 'pointsoutCopy= ',pointsout2
print 'pointmarksin= ',marksin
print 'pointmarksout= ',marksout

#create some point attributes,
npts  = pointsout.shape[0]
natts = 1
Пример #21
0
    def readFromPolyFile(self,filebase,flagsAdd="",verbose=0):
        """
        read triangle representation from filebase.poly file
        assumes the nbase data member is set appropriately
        """
        reader = triIfaceUtils.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 = triangulate.new()
    
        if nodesM == None:
            triangulate.setPoints(tri0,nodes)
        else:
            triangulate.setPointsAndMarkers(tri0,nodes,nodesM)
        if not nodesA == None: 
            triangulate.setPointAttributes(tri0,nodesA)
        #end if
        if segmentsM == None:
            triangulate.setSegments(tri0,segments)
        else:
            triangulate.setSegmentsAndMarkers(tri0,segments,segmentsM)
        #end if
        if (not holes == None):
            triangulate.setHoles(tri0,holes)
        #end if
        if (not regions == None):
            #print 'setting trin1 regions=\n',regions2
            triangulate.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:
            triangulate.applyTriangulate(flags,tri0,self.trirep[0],self.vorrep[0])
            #handles no longer contain trivial representations
            self.trirepDefaultInit[0] = False
            self.vorrepDefaultInit[0] = False
        else:
            triangulate.applyTriangulateNoVoronoi(flags,tri0,self.trirep[0])
            #handle no longer contains trivial representations
            self.trirepDefaultInit[0] = False
        #end if

        #clean up?
        del tri0
Пример #22
0
def tricall2():
    """
    test reading Triangle file utilities
    """
    import triIfaceUtils
    import triIfaceFileUtils

    reader = triIfaceUtils.TriangleInputFileReader()
    filebase = 'trimesh'

    nodeDataInfo, nodeData = reader.readNodes(filebase)
    nodes, nodesA, nodesM = (nodeData['nodes'], nodeData['nodeAttributes'],
                             nodeData['nodeMarkers'])

    print 'Nodes: nodeInfo= ', nodeDataInfo
    print """Nodes: nodes= \n%s\n nodeAttributes= \n%s\n nodeMarkers= \n%s\n """ % (
        nodes, nodesA, nodesM)

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

    print 'Triangles: triInfo= ', triDataInfo
    print """Triangles: elems= \n%s\n triAttributes= \n%s\n""" % (triangles,
                                                                  trianglesA)

    #write out assuming just read in node and ele files
    filebaseout = filebase + '-out-0'
    tri0 = triangulate.new()

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

    triangulate.setTriangles(tri0, triangles)
    if not trianglesA == None:
        triangulate.setTriangleAttributes(tri0, trianglesA)
    #end if
    triIfaceUtils.writeOutTriangulation(tri0, filebaseout, nbase=0, verbose=0)

    #now view with showme
    showme = "../bin/showme"
    showmecmd = """showme %s """ % filebaseout

    failure = 0
    failure = triIfaceFileUtils.checkFileExists(showme)
    failure = os.system(showmecmd)

    ##now read from .poly file
    polyDataInfo, polyData = reader.readPoly(filebase)

    for type in ['node', 'segment', 'hole', 'region']:
        print 'Poly: ', type, 'Info= \n', polyDataInfo[type], '\n'
    #
    nodes2, nodesA2, nodesM2 = (polyData['node']['nodes'],
                                polyData['node']['nodeAttributes'],
                                polyData['node']['nodeMarkers'])
    segments2, segmentsM2 = (polyData['segment']['segments'],
                             polyData['segment']['segmentMarkers'])
    holes2 = polyData['hole']['holes']
    regions2 = polyData['region']['regions']

    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
    """ % (nodes2, nodesA2, nodesM2, segments2, segmentsM2, holes2, regions2)

    ### now create a triangulation and write out the data arrays?
    trin1 = triangulate.new()

    filebaseout1 = filebase + "-out-1"

    if nodesM2 == None:
        triangulate.setPoints(trin1, nodes2, nodesM2)
    else:
        triangulate.setPointsAndMarkers(trin1, nodes2, nodesM2)
    if not nodesA2 == None:
        triangulate.setPointAttributes(trin1, nodesA2)
    #end if

    if segmentsM2 == None:
        triangulate.setSegments(trin1, segments2)
    else:
        triangulate.setSegmentsAndMarkers(trin1, segments2, segmentsM2)
    if not holes2 == None:
        triangulate.setHoles(trin1, holes2)
    #end if
    if not regions2 == None:
        #print 'setting trin1 regions=\n',regions2
        triangulate.setRegions(trin1, regions2)
    #end if
    trout1 = triangulate.new()
    flags = "zpne"  #needs to be base 0 if Input was that way (and nbase=0)
    triangulate.applyTriangulateNoVoronoi(flags, trin1, trout1)

    triIfaceUtils.writeOutTriangulation(trout1,
                                        filebaseout1,
                                        nbase=0,
                                        verbose=0)

    #now view with showme
    showmecmd = """showme %s """ % filebaseout1

    failure = 0
    failure = triIfaceFileUtils.checkFileExists(showme)
    failure = os.system(showmecmd)