当前位置: 首页>>代码示例>>Python>>正文


Python Mesh.add_triangle_face方法代码示例

本文整理汇总了Python中mesh.Mesh.add_triangle_face方法的典型用法代码示例。如果您正苦于以下问题:Python Mesh.add_triangle_face方法的具体用法?Python Mesh.add_triangle_face怎么用?Python Mesh.add_triangle_face使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mesh.Mesh的用法示例。


在下文中一共展示了Mesh.add_triangle_face方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: combine

# 需要导入模块: from mesh import Mesh [as 别名]
# 或者: from mesh.Mesh import add_triangle_face [as 别名]

#.........这里部分代码省略.........
                            #print "Crossed", edge1, edge2, s1, s2, ip
                            faces1_to_be_replaced = edge1.faces()
                            new_vertex1 = mesh1.add_vertex(ip)
                            new_faces1 = mesh1.split_edge(new_vertex1, edge1)
                            for face1_to_be_replaced in faces1_to_be_replaced:
                                replaced_faces1[face1_to_be_replaced] = new_faces1
                            faces2_to_be_replaced = edge2.faces()
                            new_vertex2 = mesh2.add_vertex(ip)
                            origvol = mesh2.volume()
                            new_faces2 = mesh2.split_edge(new_vertex2, edge2)
                            if abs(origvol - mesh2.volume()) > tolerance:
                                #print ip, s1, s2
                                assert False
                            for face2_to_be_replaced in faces2_to_be_replaced:
                                replaced_faces2[face2_to_be_replaced] = new_faces2
                            print "EDGE SPLIT"
                            raise FaceRemoveException
                    except (ParallelLinesException, LinesDoNotCrossException): 
                        pass  
        except FaceRemoveException:
            m = m - 1
#    possible_overlaps = list(mesh1.possible_face_collisions(mesh2))
#    replaced_faces1 = {}
#    replaced_faces2 = {}
#    while possible_overlaps:
 #       face1, face2 = possible_overlaps.pop()
#        try:
#            if replaced_faces1.has_key(face1):
#                for new_face in replaced_faces1[face1]:
#                    possible_overlaps.append((new_face, face2))
#                raise FaceRemoveException
#            if replaced_faces2.has_key(face2):
#                for new_face in replaced_faces2[face2]:
#                    possible_overlaps.append((face1, new_face))
#                raise FaceRemoveException
#            for edge1 in face1.edges:
#                for edge2 in face2.edges:
#                    try:
#                        ip, s1, s2 = line_intersection_and_proportion((edge1.v1, edge1.v2), (edge2.v1, edge2.v2))
#                        if s1 > tolerance and 1-s1 > tolerance and s2 > tolerance and 1-s2 > tolerance:
#                            print edge1, edge2, s1, s2
#                            faces1_to_be_replaced = edge1.faces()
#                            new_vertex1 = mesh1.add_vertex(ip)
#                            new_faces1 = mesh1.split_edge(new_vertex1, edge1)
#                            for face1_to_be_replaced in faces1_to_be_replaced:
#                                replaced_faces1[face1_to_be_replaced] = new_faces1
#                            faces2_to_be_replaced = edge2.faces()
#                            new_vertex2 = mesh2.add_vertex(ip)
#                            new_faces2 = mesh2.split_edge(new_vertex2, edge2)
#                            for face2_to_be_replaced in faces2_to_be_replaced:
#                                replaced_faces2[face2_to_be_replaced] = new_faces2
#                            raise FaceRemoveException
#                    except ValueError:
#                        pass    
#        except FaceRemoveException:
#            pass
    #fileio.write_stl(mesh1, "/home/martin/m1.ply")
    #fileio.write_stl(mesh2, "/home/martin/m2.ply")
    print "M1V", mesh1.vertices
    print "M1V", mesh1.vertices
    print "M1F", len(mesh1.faces)
    print "M2F", len(mesh2.faces)
    print "M1Vol", mesh1.volume()#Check mesh is closed
    print "M2Vol", mesh2.volume()#Check mesh is closed
    m = Mesh()
    vertex1_map = {}
    for v in mesh1.vertices:
        new_vertex = m.get_vertex(v)
        if new_vertex is None: #Vertex does not exist
            new_vertex = m.add_vertex(v.x, v.y, v.z)
        vertex1_map[v] = new_vertex
    for face in mesh1.faces:
        vertices = [vertex1_map[vertex] for vertex in face.vertices]
        if mesh2.contains_point(face.centroid() + face.normal * tolerance * {True: -1, False: 1}[inverted1]) != (not inverted2):
            if inverted1:
                m.add_triangle_face(vertices[0], vertices[2], vertices[1])
            else:
                m.add_triangle_face(vertices[0], vertices[1], vertices[2])
    vertex2_map = {}
    for v in mesh2.vertices:
        new_vertex = m.get_vertex(v)
        #print "?", m.get_vertex(v), m.get_vertex(v.x, v.y, v.z), v.x, v.y, v.z	
        if new_vertex is None: #Vertex does not exist
            #print "Adding"
            new_vertex = m.add_vertex(v.x, v.y, v.z)
            #print "added"
        vertex2_map[v] = new_vertex
    edge_splits = {}
    for face in mesh2.faces:
        vertices = [vertex2_map[vertex] for vertex in face.vertices]
        if mesh1.contains_point(face.centroid() + face.normal * tolerance * {True: -1, False: 1}[inverted2]) != (not inverted1):
            if inverted2:
                add_splits_and_face(m, vertices[0], vertices[2], vertices[1], edge_splits)      
            else:
                add_splits_and_face(m, vertices[0], vertices[1], vertices[2], edge_splits)
    #clean up verticies
    m.clean()
    
    fileio.write_ply(m, "/home/martin/m3.ply")
    return m
开发者ID:brachyprint,项目名称:brachyprint,代码行数:104,代码来源:intersect4.py


注:本文中的mesh.Mesh.add_triangle_face方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。