Esempio n. 1
0
def carp2Gmsh (carpMesh, outputMesh):

    ptsFile  = carpMesh + '.pts'
    elemFile = carpMesh + '.elem'
    
    pts  = read_array_pts (ptsFile)
    elem = read_array_elem (elemFile)

    numPts  = np.shape(pts)[0]
    numElem = np.shape(elem)[0]

    pdb.set_trace()

    outputFile = file(outputMesh, 'w')
    outputFile.write('$MeshFormat\n2.0 0 8\n$EndMeshFormat\n')
    outputFile.write('$Nodes\n')
    outputFile.write('%d\n' % numPts)
    for i in xrange(numPts):
        outputFile.write('%d %f %f %f\n' % (i+1,pts[i,0],pts[i,1],pts[i,2]))
    outputFile.write('$EndNodes\n')
    outputFile.write('$Elements\n')
    outputFile.write('%d\n' % numElem)

#    print elem

    # triangles only
    for i in xrange(numElem):
        outputFile.write('%d 2 2 99 2 %d %d %d\n' % (i+1, int(elem[i][1])+1, int(elem[i][2])+1, int(elem[i][3])+1 ) )

    outputFile.write('$EndElements\n')
    outputFile.close()
Esempio n. 2
0
def carp2vtk (carpMesh, outputMesh):

    ptsFile  = carpMesh + '.pts'
    elemFile = carpMesh + '.elem'
    
    pts  = read_array_pts (ptsFile)
    elem = read_array_elem (elemFile)

    numPts  = np.shape(pts)[0]
    numElem = np.shape(elem)[0]

    outputFile = file(outputMesh, 'w')
    outputFile.write('# vtk DataFile Version 2.0\n')
    outputFile.write('CT scan data of human heart, courtesy by Henk Mastenbroek RuG\n')
    outputFile.write('ASCII\n')

    outputFile.write('UNSTRUCTURED_GRID\n')

    outputFile.write('POINT_DATA %d\n' % numPts)
    for i in xrange(numPts):
        outputFile.write('%f %f %f\n' % (pts[i,0],pts[i,1],pts[i,2]))

    outputFile.close()
Esempio n. 3
0
 def getElements(self):
     """
     Reads in the element file and return an array/list of elements
     """
     if os.path.isfile(self.elements):
         return read_array_elem(self.elements)