Skip to content

Instantly share code, notes, and snippets.

@onionmk2
Last active December 27, 2018 15:52

Revisions

  1. onionmk2 revised this gist Dec 27, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion edge.py
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,6 @@
    def get_point_pair_for_edge(ptnum_attr_name, neighbours_attr_name):
    # type: (str, str) -> List[List[int]]
    import hou
    from typing import List, Tuple
    from itertools import chain

    node = hou.pwd()
  2. onionmk2 created this gist Dec 27, 2018.
    52 changes: 52 additions & 0 deletions edge.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    # VEXで下記のコードが事前に必要です。
    # i[]@neighbours = neighbours(0, @ptnum);
    # i@point_number = @ptnum;

    # [ [0, 1], [0, 3] ...] というように、edgeとなるpointの組を返します。
    # get_point_pair_for_edge("point_number", "neighbours")
    def get_point_pair_for_edge(ptnum_attr_name, neighbours_attr_name):
    # type: (str, str) -> List[List[int]]
    import hou
    from typing import List, Tuple
    from itertools import chain

    node = hou.pwd()
    geo = node.geometry()

    result = [] # type: List[List[List[int]]]

    for point in geo.points(): # type: hou.Point
    neighbours = point.intListAttribValue(neighbours_attr_name) # type: Tuple[int]

    point_pairs = [] # type: List[List[int]]
    ptnum = point.attribValue(ptnum_attr_name)

    for neighbour in neighbours: # type: int
    point_pair = [ptnum, neighbour]
    point_pairs.append(point_pair)

    result.append(point_pairs)

    # http://d.hatena.ne.jp/xef/20121027/p2
    duplicated_point_pairs = list(chain.from_iterable(result))

    # https://stackoverflow.com/questions/3724551/python-uniqueness-for-list-of-lists
    edges = [list(x) for x in set(tuple(x) for x in duplicated_point_pairs)]

    return edges


    import hou
    pwd = hou.pwd()
    geo = pwd.geometry()
    point_pairs = get_point_pair_for_edge("point_number", "neighbours")

    edges = []
    for point_pair in point_pairs:
    p0 = geo.point(point_pair[0])
    p1 = geo.point(point_pair[1])

    edges.append(geo.findEdge(p0, p1))

    print len(edges)