def edgesByVertices(vertices):
    edges = cppyy.gbl.std.list[Edge.Ptr]()
    for i in range(len(vertices)-1):
        v1 = vertices[i]
        v2 = vertices[i+1]
        e1 = Edge.ByStartVertexEndVertex(v1, v2)
        edges.push_back(e1)
    # connect the last vertex to the first one
    v1 = vertices[len(vertices)-1]
    v2 = vertices[0]
    e1 = Edge.ByStartVertexEndVertex(v1, v2)
    edges.push_back(e1)
    return edges
def edgesByVertices(vertices, topVerts):
    edges = []
    for i in range(len(vertices) - 1):
        v1 = vertices[i]
        v2 = vertices[i + 1]
        e1 = Edge.ByStartVertexEndVertex(topVerts[v1], topVerts[v2])
        edges.append(e1)
    # connect the last vertex to the first one
    v1 = vertices[-1]
    v2 = vertices[0]
    e1 = Edge.ByStartVertexEndVertex(topVerts[v1], topVerts[v2])
    edges.append(e1)
    return edges
Ejemplo n.º 3
0

def classByType(argument):
    switcher = {
        1: Vertex,
        2: Edge,
        4: Wire,
        8: Face,
        16: Shell,
        32: Cell,
        64: CellComplex,
        128: Cluster
    }
    return switcher.get(argument, Topology)


def fixTopologyClass(topology):
    topology.__class__ = classByType(topology.GetType())
    return topology


# driver code
v1 = Vertex.ByCoordinates(0, 0, 0)
v2 = Vertex.ByCoordinates(10, 10, 10)
e1 = Edge.ByStartVertexEndVertex(v1, v2)
e2 = TopologyUtility.Translate(e1, 5, 5, 5)
e2 = fixTopologyClass(e2)
verts = getVertices(e2)
for aVert in verts:
    print([aVert.X(), aVert.Y(), aVert.Z()])
def topologyByGeometry(vts, eds, fcs, tol):
	py_vertices = []
	vertices = cppyy.gbl.std.list[Vertex.Ptr]()

	for v in vts:
		vertex = Vertex.ByCoordinates(v[0], v[1], v[2])
		py_vertices.append(vertex)
		vertices.push_back(vertex)

	edges = cppyy.gbl.std.list[Edge.Ptr]()
	for e in eds:
		sv = py_vertices[e[0]]
		ev = py_vertices[e[1]]
		edge = Edge.ByStartVertexEndVertex(sv, ev)
		edges.push_back(edge)

	faces = cppyy.gbl.std.list[Face.Ptr]()
	for f in fcs:
		faceVertices = []
		for v in f:
			vertex = py_vertices[v]
			faceVertices.append(vertex)
		faceEdges = edgesByVertices(faceVertices)
		face = Face.ByEdges(faceEdges)
		faces.push_back(face)

	result = []
	if len(faces) > 0:
		try:
			cc = CellComplex.ByFaces(faces, tol)
			cells = cppyy.gbl.std.list[Cell.Ptr]()
			_ = cc.Cells(cells)
			if (len(cells) == 1):
				result.append(cells.front())
			else:
				result.append(cc)
		except:
			try:
				c = Cell.ByFaces(faces, tol)
				result.append(c)
			except:
				try:
					s = Shell.ByFaces(faces, tol)
					result.append(s)
				except:
					facesAsTopologies = cppyy.gbl.std.list[Topology.Ptr]()
					for aFace in faces:
						facesAsTopologies.push_back(aFace)
					faceCluster = Cluster.ByTopologies(facesAsTopologies)
					mergedTopology = Topology.SelfMerge(faceCluster)
					mergedTopology.__class__ = classByType(mergedTopology.GetType())
					result.append(mergedTopology)

	elif len(edges) > 1:
		edgesAsTopologies = cppyy.gbl.std.list[Topology.Ptr]()
		for anEdge in edges:
			edgesAsTopologies.push_back(anEdge)
		edgeCluster = Cluster.ByTopologies(edgesAsTopologies)
		mergedTopology = Topology.SelfMerge(edgeCluster)
		mergedTopology.__class__ = classByType(mergedTopology.GetType())
		result.append(mergedTopology)
	elif len(edges) == 1:
		result.append(edges.front())
	elif len(vertices) > 1:
		verticesAsTopologies = cppyy.gbl.std.list[Topology.Ptr]()
		for aVertex in vertices:
			verticesAsTopologies.push_back(aVertex)
		vertexCluster = Cluster.ByTopologies(verticesAsTopologies)
		result.append(vertexCluster)
	elif len(vertices) == 1:
		result.append(vertices.front())
	return result
Ejemplo n.º 5
0
from topologic import Vertex, Edge, Wire, Topology, Dictionary, Attribute, AttributeManager, IntAttribute, DoubleAttribute, StringAttribute
import cppyy
from cppyy.gbl.std import string, list

# Create three vertices
v1 = Vertex.ByCoordinates(0, 0, 0)
v2 = Vertex.ByCoordinates(10, 0, 0)
v3 = Vertex.ByCoordinates(10, 10, 0)

# Create two edges in an L-shape
e1 = Edge.ByStartVertexEndVertex(v1, v2)
e2 = Edge.ByStartVertexEndVertex(v2, v3)

# Add the two edges to a list of edges
edges = cppyy.gbl.std.list[Edge.Ptr]()
edges.push_back(e1)
edges.push_back(e2)

# Create a wire from the list of edges
w1 = Wire.ByEdges(edges)

# Create an key called "number"
intKey = string("number")

# Create three integer attributes with values 1, 2, 3
intVal1 = IntAttribute(1)
intVal2 = IntAttribute(2)
intVal3 = IntAttribute(3)

# Create three dictionaries with different values (1, 2, 3)
keys = cppyy.gbl.std.list[str]()
def processVEF(item, tol, outputMode):
    vertices, edges, faces, color, id, name = item
    returnTopology = None
    topVerts = []
    topEdges = []
    topFaces = []
    if len(vertices) > 0:
        for aVertex in vertices:
            v = Vertex.ByCoordinates(aVertex[0], aVertex[1], aVertex[2])
            topVerts.append(v)
    else:
        return None
    if (outputMode == "Wire") and (len(edges) > 0):
        for anEdge in edges:
            topEdge = topologic.Edge.ByStartVertexEndVertex(
                topVerts[anEdge[0]], topVerts[anEdge[1]])
            topEdges.append(topEdge)
        returnTopology = topologyByEdges(topEdges)
    elif len(faces) > 0:
        for aFace in faces:
            faceEdges = edgesByVertices(aFace, topVerts)
            faceWire = Wire.ByEdges(faceEdges)
            topFace = Face.ByExternalBoundary(faceWire)
            topFaces.append(topFace)
        returnTopology = topologyByFaces(topFaces, tol, outputMode)
    elif len(edges) > 0:
        for anEdge in edges:
            topEdge = Edge.ByStartVertexEndVertex(topVerts[anEdge[0]],
                                                  topVerts[anEdge[1]])
            topEdges.append(topEdge)
        returnTopology = topologyByEdges(topEdges)
    else:
        returnTopology = Cluster.ByTopologies(topVerts)
    if returnTopology:
        keys = []
        values = []
        keys.append("TOPOLOGIC_color")
        keys.append("TOPOLOGIC_id")
        keys.append("TOPOLOGIC_name")
        keys.append("TOPOLOGIC_type")
        keys.append("TOPOLOGIC_length_unit")
        if color:
            if isinstance(color, tuple):
                color = list(color)
            elif isinstance(color, list):
                if isinstance(color[0], tuple):
                    color = list(color[0])
            print(color)
            values.append(color)
        else:
            values.append([1.0, 1.0, 1.0, 1.0])
        if id:
            values.append(id)
        else:
            values.append(str(uuid.uuid4()))
        if name:
            values.append(name)
        else:
            values.append("Topologic_" + returnTopology.GetTypeAsString())
        values.append(returnTopology.GetTypeAsString())
        values.append(bpy.context.scene.unit_settings.length_unit)
        topDict = DictionaryByKeysValues.processKeysValues(keys, values)
        _ = returnTopology.SetDictionary(topDict)
    return returnTopology