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)
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
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 segsin[3,:] = [2,3] #top segmarks = Numeric.zeros((nsegs,),Numeric.Int) segmarks[:] = [0,1,2,3] print 'setting segments=\n',segsin print 'segmarks=\n',segmarks triangulate.setSegments(trin,segsin,segmarks) segsout = triangulate.getSegments(trin) segmarksout= triangulate.getSegmentMarkers(trin) print 'segmentsOut=\n',segsout print 'segmarksout=\n',segmarksout ntatts = 2 nelem = elems1.shape[0] tatts = Numeric.zeros((nelem,ntatts),Numeric.Float) for i in range(nelem): tatts[i,:] = Numeric.ones(ntatts,)*float(i) #end i print 'try to set triangle attributes \n',tatts
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
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 segsin[3, :] = [2, 3] #top segmarks = Numeric.zeros((nsegs, ), Numeric.Int) segmarks[:] = [0, 1, 2, 3] print 'setting segments=\n', segsin print 'segmarks=\n', segmarks triangulate.setSegments(trin, segsin, segmarks) segsout = triangulate.getSegments(trin) segmarksout = triangulate.getSegmentMarkers(trin) print 'segmentsOut=\n', segsout print 'segmarksout=\n', segmarksout ntatts = 2 nelem = elems1.shape[0] tatts = Numeric.zeros((nelem, ntatts), Numeric.Float) for i in range(nelem): tatts[i, :] = Numeric.ones(ntatts, ) * float(i) #end i print 'try to set triangle attributes \n', tatts triangulate.setTriangleAttributes(trin, tatts)
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)