示例#1
0
def set_tri_corners(mesh):

    dots = {}
    rs.EnableRedraw(False)

    for fkey in mesh.faces():
        c_pts = mesh.face_coordinates(fkey)
        # reverse oder to make the flags match with the corners
        c_pts.reverse()
        if len(c_pts) != 3:
            continue

        cent = mesh.face_centroid(fkey)

        for i, c_pt in enumerate(c_pts):
            pt = centroid_points([cent, c_pt])
            dot = rs.AddTextDot('', pt)
            rs.TextDotHeight(dot, 6)
            dots[str(dot)] = (fkey, i)

    rs.EnableRedraw(True)
    if not dots:
        return None

    dot_ids = dots.keys()

    data = rs.GetObjectsEx(message="Select face dot",
                           filter=0,
                           preselect=False,
                           select=False,
                           objects=dot_ids)

    rs.DeleteObjects(dot_ids)
    if not data:
        return None

    for datum in data:
        dot = datum[0]
        fkey, flag = dots[str(dot)]
        if flag == None:
            return None
        mesh.set_face_attribute(fkey, 'corner', flag)

    return True
def set_openings(mesh):

    rs.EnableRedraw(False)

    dots = {}
    for fkey in mesh.faces():

        cent = mesh.face_centroid(fkey)
        if mesh.get_face_attribute(fkey, 'opening'):
            dot = rs.AddTextDot(fkey, cent)
            rs.ObjectColor(dot, [255, 0, 0])
        else:
            dot = rs.AddTextDot(fkey, cent)
            rs.ObjectColor(dot, [0, 255, 0])

        rs.TextDotHeight(dot, 12)
        dots[str(dot)] = fkey
    rs.EnableRedraw(True)
    if not dots:
        return None

    dot_ids = dots.keys()

    data = rs.GetObjectsEx(message="Select face for toggle openings",
                           filter=0,
                           preselect=False,
                           select=False,
                           objects=dot_ids)

    rs.DeleteObjects(dot_ids)

    if data:
        for datum in data:
            dot = datum[0]
            fkey = dots[str(dot)]
            if mesh.get_face_attribute(fkey, 'opening'):
                mesh.set_face_attribute(fkey, 'opening', 0)
            else:
                mesh.set_face_attribute(fkey, 'opening', 1)
示例#3
0
def get_initial_mesh(precision):

    crvs = rs.GetObjects("Select boundary curves",
                         4,
                         group=True,
                         preselect=False,
                         select=False,
                         objects=None,
                         minimum_count=3,
                         maximum_count=0)
    lines = get_line_coordinates(crvs)
    geo_lines = [(geometric_key(pt_u,
                                precision), geometric_key(pt_v, precision))
                 for pt_u, pt_v in lines]
    network = Network.from_lines(lines, precision)

    if network.leaves():
        return None

    adjacency = {
        key: network.vertex_neighbours(key)
        for key in network.vertices()
    }
    root = network.get_any_vertex()
    ordering, predecessors, paths = depth_first_tree(adjacency, root)
    if len(ordering) != network.number_of_vertices():
        return None

    mesh = Mesh.from_lines(lines,
                           delete_boundary_face=True,
                           precision=precision)

    rs.EnableRedraw(False)

    dots = {}
    for fkey in mesh.faces():
        cent = mesh.face_centroid(fkey)

        dot = rs.AddTextDot('', cent)
        rs.TextDotHeight(dot, 6)
        dots[str(dot)] = fkey
    rs.EnableRedraw(True)
    if not dots:
        return None

    dot_ids = dots.keys()

    data = rs.GetObjectsEx(message="Select face for openings",
                           filter=0,
                           preselect=False,
                           select=False,
                           objects=dot_ids)

    rs.DeleteObjects(dot_ids)

    if data:
        for datum in data:
            dot = datum[0]
            fkey = dots[str(dot)]
            mesh.delete_face(fkey)

    geo_edges = []
    for u, v, attr in mesh.edges(True):
        pt_u, pt_v = mesh.edge_coordinates(u, v)
        geo_u, geo_v = geometric_key(pt_u, precision), geometric_key(
            pt_v, precision)
        for i, geo_l_uv in enumerate(geo_lines):
            geo_l_u, geo_l_v = geo_l_uv[0], geo_l_uv[1]
            if (geo_l_u == geo_u) and (geo_l_v == geo_v):
                attr['dir'] = True
            elif (geo_l_u == geo_v) and (geo_l_v == geo_u):
                attr['dir'] = False
            else:
                continue
            attr['guid'] = str(crvs[i])
            attr['length'] = rs.CurveLength(crvs[i])

    # initiate flag for corners
    for fkey, attr in mesh.faces(True):
        mesh.set_face_attribute(fkey, 'corner', 0)

    return mesh, crvs
示例#4
0
def set_boundary_cond(mesh, coons_mesh, precision):

    # set attribute 'fixed' as default to False
    for key, attr in coons_mesh.vertices(True):
        attr['fixed'] = False

    # get all boundary curves
    crvs = get_boundary_crvs(mesh)

    # select optional open curves
    data = rs.GetObjectsEx(message="Select open edges (optinal)",
                           filter=0,
                           preselect=False,
                           select=False,
                           objects=crvs)
    #create list of open and
    if data:
        crvs_o = [str(datum[0]) for datum in data]
    else:
        crvs_o = []

    crvs_c = [crv for crv in crvs if crv not in crvs_o]

    # identify intersection points between open curves
    fixed = {}
    crvs_dict = {}
    for crv in crvs:
        pt_s = rs.CurveEndPoint(crv)
        pt_e = rs.CurveStartPoint(crv)
        geo_s = geometric_key(pt_s, precision)
        geo_e = geometric_key(pt_e, precision)
        fixed[geo_s] = pt_s
        fixed[geo_e] = pt_e
        crvs_dict[crv] = set([geo_s, geo_e])

    optional_fixed = {}
    for a, b in itertools.combinations(crvs_o, 2):
        geo_int = crvs_dict[str(a)] & crvs_dict[str(b)]
        if geo_int:
            for key in list(geo_int):
                optional_fixed[key] = fixed[key]

    # select optional supports (alter optional_fixed)
    rs.EnableRedraw(False)
    dots = {}
    for key, pt in optional_fixed.iteritems():
        dot = rs.AddTextDot('', pt)
        rs.TextDotHeight(dot, 6)
        dots[str(dot)] = key

    rs.EnableRedraw(True)
    if dots:
        dot_ids = dots.keys()
        data = rs.GetObjectsEx(message="Select additional supports (optional)",
                               filter=0,
                               preselect=False,
                               select=False,
                               objects=dot_ids)

        rs.DeleteObjects(dot_ids)
        if data:
            point_fixed = {}
            for datum in data:
                dot = datum[0]
                point_fixed[dots[str(dot)]] = optional_fixed[dots[str(dot)]]
            optional_fixed = point_fixed
        else:
            optional_fixed = {}

    # fix all vertices that are on the origianl boundary of the coons patches and
    # that are in the optinal fixed dict
    coon_bound = {}
    for key, attr in coons_mesh.vertices(True):
        if attr['coon_bound']:
            pt = coons_mesh.vertex_coordinates(key)
            coon_bound[key] = pt
            if geometric_key(pt, precision) in optional_fixed:
                attr['fixed'] = True

    # fix all vertices that are on the closed curve boundaries
    for key, pt in coon_bound.iteritems():
        for crv in crvs_c:
            if rs.IsPointOnCurve(crv, pt):
                coons_mesh.set_vertex_attribute(key, 'fixed', True)
                break