Jump to content

Is there a way to lookup points by attribute values?


magneto

Recommended Posts

Hi,

I looked at the help but couldn't find it. Is there a way to find a point based on attribute values? Either in VEX or just in expressions. Something like:

findpoint("../grid1", "weight", 16, #FIRST)

16 is the value to look up

#FIRST or 0, means first match

I know I can use the Group SOP, but I need this in code and run it inside a loop, instead of multiple nodes inside a foreach.

Can this be done?

Thanks :)

Link to comment
Share on other sites

Hi,

I looked at the help but couldn't find it. Is there a way to find a point based on attribute values? Either in VEX or just in expressions. Something like:

findpoint("../grid1", "weight", 16, #FIRST)

16 is the value to look up

#FIRST or 0, means first match

I know I can use the Group SOP, but I need this in code and run it inside a loop, instead of multiple nodes inside a foreach.

Can this be done?

Thanks :)

#

# getPtFromId

#

# returns pointnumber of point with given id value

#

def getPtFromId(node, id):

nodeGeo = node.geometry()

idList = nodeGeo.pointFloatAttribValues("id")

idListAsInt = [int(i) for i in idList]

return idListAsInt.index(id)

this will work but it's slow.. it's looking specifically for the attribute "id", but you can change that or add it as a parameter.

I'm not sure the point cloud answer will work exactly .. won't that return the closest result ? Maybe a combination of the 2 would be faster if you have a lot of points .. use the point cloud to return a list of possible close matches and the python to return the exact match or an error if there is no point with the given attribute.

-G

  • Like 1
Link to comment
Share on other sites

Thanks Dan, I didn't know of that trick. When I use the pcopen like you said, will be an exact match or closest match possible? Also I assume it will give me multiple points, right?

The match will be as close as the size of your search radius. I do this for id look ups often and just leave the search radius at .1 for an exact match. If multiple points have the same id you can get all of them if you want. I usually Use Point Cloud Num Found to see if there was any match, then Point Cloud Import By Index with the index left at zero to grab the first one.

  • Like 1
Link to comment
Share on other sites

Thanks guys.

@ranxerox: I was hoping for a built-in function for this, because like you said python will be slow and if you need this for prims, etc then you can't use the pcopen in combination with your python function.

@Dan: So if you are doing integer lookups, then having values like {0,0,0}, {1,0,0}, {2,0,0}, {3,0,0}, etc, you should keep the radius at 1?

But for floats, you need the know the smallest difference between values that's greater than 0, right? Otherwise if you have 0.00001 and 0.000012, and you use 0.001, you will get both, but the first point won't necessarily be the one with the closest value?

Link to comment
Share on other sites

cool trick. It's too bad there isn't a 1d version of point cloud open etc to get around creating/deleting an extra vector attribute.

-G

The match will be as close as the size of your search radius. I do this for id look ups often and just leave the search radius at .1 for an exact match. If multiple points have the same id you can get all of them if you want. I usually Use Point Cloud Num Found to see if there was any match, then Point Cloud Import By Index with the index left at zero to grab the first one.

Link to comment
Share on other sites

Store "P" in attribute, zero out it, replace for example X with float attrib. Do the PC search, get "P" back.

this is equivalent to Dan's suggestion of putting the attribute as a parameter to the pcopen, except for the extra steps.

another way to do this as a friend suggested is to store $PT in an attribute, delete non selected by expression $ID == x, then the remaining points have the pointnumbers of the points which have the attribute value you are looking for. That's gonna run an expression on every point so not as fast as the pcopen, but it's extremely simple.

-G

Link to comment
Share on other sites

the point sop has an option "match by attribute", which works fine - but you need to have the same attribute on both pointclouds, have only used it with id attributes so far, though (so I'm not sure how/if it deals with inprecisions )

"When there are two inputs the standard behaviour is to match according to point number. However, if the inputs are particle systems, this might not match properly as one wants to match the same particle even if particles are deleted or created. Match By Attribute will have $TX2 refer to the point on the second input whose attribute matches the attribute of the currently evaluated point.

If more than one point on the second input matches, the point with the greatest point number will be used. "

http://www.sidefx.com/docs/houdini12.1/nodes/sop/point

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...