Skip to content

Instantly share code, notes, and snippets.

@onionmk2
Last active December 27, 2018 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onionmk2/1ec894611dbcc067dbefbe2ac3049de1 to your computer and use it in GitHub Desktop.
Save onionmk2/1ec894611dbcc067dbefbe2ac3049de1 to your computer and use it in GitHub Desktop.
# 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 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment