edge between nearest pairs

   4836   5   0
User Avatar
Member
29 posts
Joined: 9月 2007
Offline
Hi!

I want to write an expression for drawing an edge between a point and its nearest neighbor using the Add SOP.

I have a POPnet as input.

Any help would be most welcome!
Thanks!
Gon
User Avatar
Member
874 posts
Joined: 10月 2008
Offline
Substract position vector of point one from point two. That gives you the line. To find the closest neighbor, there is a proximity attribute node in the popnet.

Edit: Sorry I didn't read your question carefully. I think you figured out what I said already. I'll see if I can come up with something that can group pairs of points.
--
Jobless
User Avatar
Member
874 posts
Joined: 10月 2008
Offline
Haven't tested it fully but how about something like this:


# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
points = geo.points()
# Add code to modify the contents of geo.

lst =
for i in points:
p1 = i.number()
p2 = i.attribValue(“nearest”)
pairs = (p1,p2)
curve = geo.createPolygon()
for j in pairs:
point = geo.createPoint()
point.setPosition(points.position())
curve.addVertex(point)
--
Jobless
User Avatar
Member
29 posts
Joined: 9月 2007
Offline
Soothsayer, thanks so much!

I'm not experienced enough — where to paste this code?
It looks like it should work on SOP level, so right after the POPnet outputting $NEAREST on each particle point, right?

Hope the sample file helps to figure this out!
Thanks for the code sweat!
Gon

Attachments:
Add_edges.hipnc (103.7 KB)

User Avatar
Member
874 posts
Joined: 10月 2008
Offline
Try this. I wanted to save the python sop in the file but I always forget how to do it. So you need to copy paste the code into it yourself (red node, right-click>TypeProperties>Code)


# Macha/Soothsayer June, 3, 2010
# drawing lines between pairs of neighbours

# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
points = geo.points()
# Add code to modify the contents of geo.

pairs =
for i in points:
p1 = i.number()
p2 = i.attribValue(“nearest”)
pair =
pairs.append(pair)
riap = [ pair, pair ]
if (riap in pairs) != 1:
curve = geo.createPolygon()
for j in pair:
point = geo.createPoint()
point.setPosition(points.position())
curve.addVertex(point)

Attachments:
nlines.jpg (31.9 KB)
edges.hipnc (86.2 KB)

--
Jobless
User Avatar
Member
29 posts
Joined: 9月 2007
Offline
WOW! I'm running some tests now, screenshot coming
Thanks so much!!
Gon
  • Quick Links