Jump to content
Prabu

How to connect points?

Recommended Posts

Hello everybody,

I have a set of points( static particles). their pt numbers are not ordered one But it has unique id and nearest point id stored in an attribute and their distance to nearest point stored in an attribute.

How to connect those pts with their nearest pt. All the suggestions are welcome. Is there any simple solution?

Thanks

-Prabu

Edited by Prabu

Share this post


Link to post
Share on other sites

Hello everybody,

I have a set of points( static particles). their pt numbers are not ordered one But it has unique id and nearest point id stored in an attribute and their distance to nearest point stored in an attribute.

Thanks

-Prabu

You can sort points using any existing attribute.

Use sort by expression and supply the variable.

Quick hip is attached.

Cheers,

sort.hipnc

Share this post


Link to post
Share on other sites

I think the point was to create a line from each point to it's nearest neighbor.

Maybe ForEach?

Or create as many lines as you have points, and for each line move vertex 0 to the point that has the same number as the line primitive, and vertex 1 to the point that the previous point's nearest-attribute points to.

(contrieved? naah.)

Share this post


Link to post
Share on other sites

I think the point was to create a line from each point to it's nearest neighbor.

Exactly...

Maybe ForEach?

Yes, But how? could you please elaborate it.

Edited by Prabu

Share this post


Link to post
Share on other sites

Ah.. sorry prabhu looks i have misread the question

Could you post the hip ? i dont know why i still find it little confusing.

Share this post


Link to post
Share on other sites

Ah.. sorry prabhu looks i have misread the question

Could you post the hip ? i dont know why i still find it little confusing.

Sure...

I have attached the file.

Thanks

-prabu

hipFile.zip

Share this post


Link to post
Share on other sites

Sure...

I have attached the file.

Your file is one level of redirection harder - the nearest neighbor does not refer to the point numbers but the particle IDs.

If you click on the "Use Point Numbers Instead of Particle IDs" in your Proximity POP you will have it a bit easier.

Share this post


Link to post
Share on other sites

Ive been using pythonSop to generate geometry. for connecting every point to each other(limited with maxDist) would be something like this in pythonSop:

geo = hou.pwd().geometry()

maxDist = 5.0
points = geo.points()

pointNum = 0

for p1 in points:
    for p2 in points:
        if p1.number() != p2.number():
            if p2.number() >= pointNum:
                pos1 = p1.position()
                pos2 = p2.position()
                line = pos1 - pos2
                length = line.length()
                if length < maxDist:
                    poly = geo.createPolygon()
                    poly.setIsClosed(False)
                    posMid = (pos1+pos2)*0.5

                    iter = 0.0
                    for pos in pos1, posMid, pos2:
                        point = geo.createPoint()
                        point.setPosition(pos)
                        poly.addVertex(point)
                        iter += 1
    pointNum = pointNum+1 

Kustaa

Share this post


Link to post
Share on other sites

Ive been using pythonSop to generate geometry. for connecting every point to each other(limited with maxDist) would be something like this in pythonSop:

Kustaa

If you would want to speed this up a lot, then you could do the length and closest points calculation in vex/vops (multithreaded) beforehand and in your python code, you would read the attribute values and only create the geometry.

Share this post


Link to post
Share on other sites

If you would want to speed this up a lot, then you could do the length and closest points calculation in vex/vops (multithreaded) beforehand and in your python code, you would read the attribute values and only create the geometry.

thats true, on top of being multithreaded im sure that the pc functions are slightly more efficient than my approach =)

Share this post


Link to post
Share on other sites

what about just using forEachSOP in point mode and bring another point in according to nearest attribute and join them together?

connectPts_fix.hipnc

Share this post


Link to post
Share on other sites

Cant you just use a vopsop, import nearest att (make it points instead of id) and then use it to import another att (P) with that id, substract both positions, make it a vector, and then copy stamp lines. Or do I miss something obvious?

Edited by Macha

Share this post


Link to post
Share on other sites

Cant you just use a vopsop, import nearest att (make it points instead of id) and then use it to import another att (P) with that id, substract both positions, make it a vector, and then copy stamp lines. Or do I miss something obvious?

I think at some point I did that too, but I found it is more accurate to create a line, set both points of the line to the actual values, rather than have the line be scaled and oriented by the copy sop in the direction between the two points. On a pure theorethical level the resutl should be the same, in practice there are numerical errors that cause inaccuracies (which can cause problems later on if you are planning to fuse the lines, perform connectivity based partitioning, pathfinding algorithms,..). Also the copy sop or the foreach are slow, much rather create all the lines first and then perform the position adjustment in vops.

It is the same kind of per primitive id lookup that is performed on the points in vops as if you were to transform entire '$CLASS' based groups of primitves (with 'class' at the point level).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×