Exemple #1
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
    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
Exemple #3
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)
Exemple #4
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
Exemple #5
0
triangulate.setPointAttributes(trin,patts)

pattsout = triangulate.getPointAttributes(trin)
pattsoutCopy = triangulate.getPointAttributesCopy(trin)
print 'pattsin=\n',patts
print 'pattsout=\n',pattsout
print 'pattsoutCopy=\n',pattsoutCopy

#manually construct triangles
ntri = 2;
ncorn= 3;
elems0  = Numeric.zeros((ntri,ncorn),Numeric.Int)
elems0[0,:] = [0,1,2]
elems0[1,:] = [0,2,3]

triangulate.setTriangles(trin,elems0)

#shallow copy
elems1 = triangulate.getTriangles(trin)
#deep copy
elems1Copy = triangulate.getTrianglesCopy(trin)

print 'elems0=\n',elems0
print 'elems1=\n',elems1

#construct boundary segments
nsegs = 4
segsin= Numeric.zeros((nsegs,2),Numeric.Int)
segsin[0,:] = [3,0]  #left
segsin[1,:] = [1,2]  #right
segsin[2,:] = [0,1]  #bottom
    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
Exemple #7
0
triangulate.setPointAttributes(trin, patts)

pattsout = triangulate.getPointAttributes(trin)
pattsoutCopy = triangulate.getPointAttributesCopy(trin)
print 'pattsin=\n', patts
print 'pattsout=\n', pattsout
print 'pattsoutCopy=\n', pattsoutCopy

#manually construct triangles
ntri = 2
ncorn = 3
elems0 = Numeric.zeros((ntri, ncorn), Numeric.Int)
elems0[0, :] = [0, 1, 2]
elems0[1, :] = [0, 2, 3]

triangulate.setTriangles(trin, elems0)

#shallow copy
elems1 = triangulate.getTriangles(trin)
#deep copy
elems1Copy = triangulate.getTrianglesCopy(trin)

print 'elems0=\n', elems0
print 'elems1=\n', elems1

#construct boundary segments
nsegs = 4
segsin = Numeric.zeros((nsegs, 2), Numeric.Int)
segsin[0, :] = [3, 0]  #left
segsin[1, :] = [1, 2]  #right
segsin[2, :] = [0, 1]  #bottom
Exemple #8
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)