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


Python Mesh.add_vertex方法代码示例

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


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

示例1: combine

# 需要导入模块: from mesh import Mesh [as 别名]
# 或者: from mesh.Mesh import add_vertex [as 别名]
def combine(mesh1, inverted1, mesh2, inverted2, tolerance = 0.000001):
    class FaceRemoveException(Exception):
        pass
    possible_overlaps = list(mesh1.possible_face_collisions(mesh2))
    
    replaced_faces1 = {}
    replaced_faces2 = {}
    print "Mesh1", mesh1.vertices
    print "Mesh2", mesh2.vertices
    print len(possible_overlaps)
    n=40
    m=300
    while possible_overlaps:
        face1, face2 = possible_overlaps.pop()
        assert n > 0
        assert m > 0
        try:
            if replaced_faces1.has_key(face1):
                for new_face1 in replaced_faces1[face1]:
                    possible_overlaps.append((new_face1, face2))
                raise FaceRemoveException
            if replaced_faces2.has_key(face2):
                for new_face in replaced_faces2[face2]:
                    possible_overlaps.append((face1, new_face))
                raise FaceRemoveException
            if face1.normal.cross(face2.normal).magnitude() < tolerance and abs(face1.normal.dot(face1.vertices[0]) - face1.normal.dot(face2.vertices[0])) < tolerance: 
                for vertex1 in face1.vertices:
                    if point_in_face(vertex1, face2, tolerance) and vertex1 not in mesh2.vertices:
                        vertex2 = mesh2.add_vertex(vertex1.x, vertex1.y, vertex1.z)
                        possible_overlaps.append((face1, face2)) #There may be more than one face intersection for this pair of points
                        replaced_faces2[face2] = mesh2.split_face(vertex2, face2)
                        raise FaceRemoveException
                for vertex2 in face2.vertices:
                    if point_in_face(vertex2, face1, tolerance) and vertex2 not in mesh1.vertices:
                        vertex1 = mesh1.add_vertex(vertex2.x, vertex2.y, vertex2.z)
                        possible_overlaps.append((face1, face2)) #There may be more than one face intersection for this pair of points
                        replaced_faces1[face1] = mesh1.split_face(vertex1, face1)
                        raise FaceRemoveException      
        except FaceRemoveException:
            m = m - 1
    possible_overlaps = list(mesh1.possible_face_collisions(mesh2))
    replaced_faces1 = {}
    replaced_faces2 = {}
    print "Mesh1", mesh1.vertices
    print "Mesh2", mesh2.vertices
    print len(possible_overlaps)
    fileio.write_ply(mesh1, "/home/martin/m1.ply")
    fileio.write_ply(mesh2, "/home/martin/m2.ply")
    n=40
    m=300
    while possible_overlaps:
        face1, face2 = possible_overlaps.pop()
        fileio.write_ply(mesh1, "/home/martin/m1.ply")
        fileio.write_ply(mesh2, "/home/martin/m2.ply")
        assert n > 0
        assert m > 0
        try:
            if replaced_faces1.has_key(face1):
                for new_face1 in replaced_faces1[face1]:
                    if replaced_faces2.has_key(face2):
                        for new_face2 in replaced_faces2[face2]:
                            possible_overlaps.append((new_face1, new_face2))
                    else:
                        possible_overlaps.append((new_face1, face2))
                raise FaceRemoveException
            if replaced_faces2.has_key(face2):
                for new_face in replaced_faces2[face2]:
                    possible_overlaps.append((face1, new_face))
                raise FaceRemoveException
            if face1.normal.cross(face2.normal).magnitude() < tolerance and abs(face1.normal.dot(face1.vertices[0]) - face1.normal.dot(face2.vertices[0])) < tolerance: 
              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))
                        #print "Lines Cross?", edge1.v1, edge1.v2, edge2.v1, edge2.v2, ip, s1, s2
                        if s1 > tolerance and 1-s1 > tolerance and s2 > tolerance and 1- s2 > tolerance:
                            n = n -1
                            #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 = {}
#.........这里部分代码省略.........
开发者ID:brachyprint,项目名称:brachyprint,代码行数:103,代码来源:intersect4.py


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