示例#1
0
def writer(file, reader):
    "Reads mesh from a reader and write it into an OBJ file"
    if not reader.indexed:
        reader = generic.soup2indexed(reader)

    nodeIndices = {}
    nodes = reader.readNode()
    nodeCounter = 0
    try:
        while True:
            n = nodes.next()
            nodeCounter += 1
            nodeIndices[n.label] = str(nodeCounter)
            file.write("v " + n.x + " " + n.y + " " + n.z + "\n")
    except StopIteration:
        pass

    elements = reader.readElementIndexed()
    elementCounter = 0
    try:
        while True:
            e = elements.next()
            elementCounter += 1
            file.write("f " + " ".join([nodeIndices[i]
                                        for i in e.list]) + "\n")
    except StopIteration:
        pass
示例#2
0
def writer(file, reader):
	"Reads mesh from a reader and write it into a UNV file"
	if not reader.indexed:
		reader = generic.soup2indexed(reader)
	file.write("""    -1
  2411
""")
	nodeIndices = {}
	nodes = reader.readNode()
	nodeCounter = 0
	try:
		while True:
			n = nodes.next()
			nodeCounter += 1
			file.write("%10s         1         1%10s\n" % (n.label, n.color))
			c = [normFloat(i) for i in [n.x, n.y, n.z]]
			file.write("".join(c)+"\n")
			nodeIndices[n.label] = str(nodeCounter)
	except StopIteration:
		pass
	file.write("""    -1
    -1
  2412
""")
	elements = reader.readElementIndexed()
	elementCounter = 0
	try:
		while True:
			e = elements.next()
			file.write("%10s%10s         1         1         1%10d\n" % (e.label, fem2unv[e.type], len(e.list)))
			file.write("".join(["%10s" % (nodeIndices[i]) for i in e.list])+"\n")
			elementCounter += 1
	except StopIteration:
		pass
	file.write("    -1\n")
示例#3
0
def writer(file, reader):
    "Reads mesh from a reader and write it into a PLY file"
    if not reader.indexed:
        reader = generic.soup2indexed(reader)

    tempFiles = [tempfile.TemporaryFile(mode='w+') for i in range(2)]
    tempFiles[0].write(
        "ply\nformat ascii 1.0\ncomment generated by meshconvert\n")

    nodeIndices = {}
    nodes = reader.readNode()
    nodeCounter = 0
    try:
        while True:
            n = nodes.next()
            nodeIndices[n.label] = str(nodeCounter)
            tempFiles[1].write(n.x + " " + n.y + " " + n.z + "\n")
            nodeCounter += 1
    except StopIteration:
        pass

    tempFiles[0].write(
        "element vertex " + str(nodeCounter) +
        "\nproperty float x\nproperty float y\nproperty float z\n")

    elements = reader.readElementIndexed()
    elementCounter = 0
    try:
        while True:
            e = elements.next()
            tempFiles[1].write(
                str(len(e.list)) + " " +
                " ".join([nodeIndices[i] for i in e.list]) + "\n")
            elementCounter += 1
    except StopIteration:
        pass

    tempFiles[0].write(
        "element face " + str(elementCounter) +
        "\nproperty list uchar int vertex_indices\nend_header\n")

    for f in tempFiles:
        f.seek(0)
        while True:
            line = f.readline()
            if line == "":
                break
            file.write(line)
        f.close
示例#4
0
def writer(file, reader):
    "Reads mesh from a reader and write it into a OFF file"
    if not reader.indexed:
        reader = generic.soup2indexed(reader)

    tempFiles = [tempfile.TemporaryFile(mode='w+') for i in range(2)]
    tempFiles[0].write("OFF\n")

    nodeIndices = {}
    nodes = reader.readNode()
    nodeCounter = 0
    try:
        while True:
            n = nodes.next()
            nodeIndices[n.label] = str(nodeCounter)
            tempFiles[1].write(n.x + " " + n.y + " " + n.z + "\n")
            nodeCounter += 1
    except StopIteration:
        pass

    tempFiles[0].write(str(nodeCounter) + " ")

    elements = reader.readElementIndexed()
    elementCounter = 0
    try:
        while True:
            e = elements.next()
            tempFiles[1].write(
                str(len(e.list)) + " " +
                " ".join([nodeIndices[i] for i in e.list]) + "\n")
            elementCounter += 1
    except StopIteration:
        pass

    tempFiles[0].write(str(elementCounter) + " 0\n")

    for f in tempFiles:
        f.seek(0)
        while True:
            line = f.readline()
            if line == "":
                break
            file.write(line)
        f.close
示例#5
0
def writer(file, reader):
	"Reads mesh from a reader and write it into a PLY file"
	if not reader.indexed:
		reader = generic.soup2indexed(reader)

	tempFiles = [tempfile.TemporaryFile(mode='w+') for i in range(2)]
	tempFiles[0].write("ply\nformat ascii 1.0\ncomment generated by meshconvert\n")

	nodeIndices = {}
	nodes = reader.readNode()
	nodeCounter = 0
	try:
		while True:
			n = nodes.next()
			nodeIndices[n.label] = str(nodeCounter)
			tempFiles[1].write(n.x+" "+n.y+" "+n.z+"\n")
			nodeCounter += 1
	except StopIteration:
		pass

	tempFiles[0].write("element vertex "+str(nodeCounter)+"\nproperty float x\nproperty float y\nproperty float z\n")

	elements = reader.readElementIndexed()
	elementCounter = 0
	try:
		while True:
			e = elements.next()
			tempFiles[1].write(str(len(e.list))+" "+" ".join([nodeIndices[i] for i in e.list])+"\n")
			elementCounter += 1
	except StopIteration:
		pass

	tempFiles[0].write("element face "+str(elementCounter)+"\nproperty list uchar int vertex_indices\nend_header\n")

	for f in tempFiles:
		f.seek(0)
		while True:
			line = f.readline()
			if line == "":
				break
			file.write(line)
		f.close
示例#6
0
def writer(file, reader):
	"Reads mesh from a reader and write it into a OFF file"
	if not reader.indexed:
		reader = generic.soup2indexed(reader)

	tempFiles = [tempfile.TemporaryFile(mode='w+') for i in range(2)]
	tempFiles[0].write("OFF\n")

	nodeIndices = {}
	nodes = reader.readNode()
	nodeCounter = 0
	try:
		while True:
			n = nodes.next()
			nodeIndices[n.label] = str(nodeCounter)
			tempFiles[1].write(n.x+" "+n.y+" "+n.z+"\n")
			nodeCounter += 1
	except StopIteration:
		pass

	tempFiles[0].write(str(nodeCounter)+" ")

	elements = reader.readElementIndexed()
	elementCounter = 0
	try:
		while True:
			e = elements.next()
			tempFiles[1].write(str(len(e.list))+" "+" ".join([nodeIndices[i] for i in e.list])+"\n")
			elementCounter += 1
	except StopIteration:
		pass

	tempFiles[0].write(str(elementCounter)+" 0\n")

	for f in tempFiles:
		f.seek(0)
		while True:
			line = f.readline()
			if line == "":
				break
			file.write(line)
		f.close
示例#7
0
def writer(file, reader):
    "Reads mesh from a reader and write it into a UNV file"
    if not reader.indexed:
        reader = generic.soup2indexed(reader)
    file.write("""    -1
  2411
""")
    nodeIndices = {}
    nodes = reader.readNode()
    nodeCounter = 0
    try:
        while True:
            n = nodes.next()
            nodeCounter += 1
            file.write("%10s         1         1%10s\n" % (n.label, n.color))
            c = [normFloat(i) for i in [n.x, n.y, n.z]]
            file.write("".join(c) + "\n")
            nodeIndices[n.label] = str(nodeCounter)
    except StopIteration:
        pass
    file.write("""    -1
    -1
  2412
""")
    elements = reader.readElementIndexed()
    elementCounter = 0
    try:
        while True:
            e = elements.next()
            file.write("%10s%10s         1         1         1%10d\n" %
                       (e.label, fem2unv[e.type], len(e.list)))
            file.write("".join(["%10s" % (nodeIndices[i])
                                for i in e.list]) + "\n")
            elementCounter += 1
    except StopIteration:
        pass
    file.write("    -1\n")
示例#8
0
def writer(file, reader):
	"Reads mesh from a reader and write it into a MESH file"
	if not reader.indexed:
		reader = generic.soup2indexed(reader)

	try:
		name = file.name
	except AttributeError:
		name = ""

	tempFiles = [tempfile.TemporaryFile(mode='w+') for i in range(5)]
	tempFiles[0].write("""
MeshVersionFormatted 1

Dimension
3

Geometry
"""+'"'+name+'"'+"""

""")

	nodeIndices = {}
	nodes = reader.readNode()
	nodeCounter = 0
	try:
		while True:
			n = nodes.next()
			nodeCounter += 1
			nodeIndices[n.label] = str(nodeCounter)
			tempFiles[2].write(n.x+" "+n.y+" "+n.z+" "+n.color+"\n")
	except StopIteration:
		pass

	tempFiles[1].write("\nVertices\n"+str(nodeCounter)+"\n")

	elements = reader.readElementIndexed()
	elementCounter = 0
	try:
		while True:
			e = elements.next()
			assert e.type == "Tri3"
			tempFiles[4].write(" ".join([nodeIndices[i] for i in e.list])+" "+e.color+"\n")
			elementCounter += 1
	except StopIteration:
		pass

	tempFiles[4].write("""
SubDomainFromMesh
1
3 1 1 1

End
""")

	tempFiles[3].write("\nTriangles\n"+str(elementCounter)+"\n")

	for f in tempFiles:
		f.seek(0)
		while True:
			line = f.readline()
			if line == "":
				break
			file.write(line)
		f.close