Jump to content

Is there a way to find the closest found point in a point cloud?


Recommended Posts

Hi,

I know that there is pcfarthest function. But is there a way to find the closest? Something like pcclosest?

Thanks :)

If you are using H12, you can use the Point Cloud By Index VOP. The other way would be inside a while loop and when pciterate is equal to 0, thats your closest point.

Link to comment
Share on other sites

Thanks alot guys.

@Spencer:

So the first indexed point will always be the closest? I thought the order was random?

@Graham, and Solitude:

I could do that, but right now I am getting all the points within the radius, and need to find the closest and the furthest points.

If I use the pcopen function twice (one for all points and one for the closest), , would it not incur the pcopen overhead twice? It would be cool if I could get all this info from my single pcopen function, just like pcfarthest allows :)

Link to comment
Share on other sites

...

So the first indexed point will always be the closest?

...

I wouldn't bet on that, I rather never consider them ordered, but I would like to hear from some developer if that really the case

...

I could do that, but right now I am getting all the points within the radius, and need to find the closest and the furthest points.

...

if you query more than one point you usually loop through them in For or While loop, therefore it is easy to store maximum and minimum distance within the same loop (remember you can import point.distance directly, then just compare to previous minimum/maximum and store if it's smaller/larger)

  • Like 1
Link to comment
Share on other sites

Thanks anim. I will have to do something like you mentioned. Reason I didn't do it is because I want to use the closest and farthest points right off the bat for each found point.

So I will either loop the pc result twice, or find the closest and store the points as I loop, and then loop this collection and use my closest and farthest points.

Not saying it's involved, just wanted to make sure I am not doing something unnecessary since I am still new to point clouds :)

Link to comment
Share on other sites

if your looking up the nearest neighbour within the input point cloud then using 1 as max num of points will always return the original point.

so you need to query 2 max points.

if you need to check nearest point in another point cloud or collection of points then setting it to 1 will work.

Link to comment
Share on other sites

Pretty sure pc samples points based on distance from the reference position.

Try sampling a cloud where you have more samples than the max points, itll return the closest points to the lookup position.

I think you are right, I tested this on simple pointcloud and it seems that they are ordered from closest to furthest (but I am pretty sure somebody was saying to be careful about this assumption)

in that case you can use pcimportbyidx() to get any point by index within found points, first will be closest(or itself as Bhavesh mentioned) last furthest (idx = pcnumfound()-1 )

Link to comment
Share on other sites

Thanks guys.

@bhavesh: How do you check the nearest point in another point cloud? You use pcopen ( handleToAnotherPCloud )?

@anim: Is there a function called pcimportbyidx? I couldn't find anything other than pcimport. There is a VOP to index, but didn't see a function to index into a point cloud.

Link to comment
Share on other sites

...

@anim: Is there a function called pcimportbyidx? I couldn't find anything other than pcimport. There is a VOP to index, but didn't see a function to index into a point cloud.

VOP is called Point Cloud Import By Index

VEX function depends on type of the channel you want to return:

int pcimportbyidxi(handle, channel, index);

float pcimportbyidxf(handle, channel, index);

vector pcimportbyidxv(handle, channel, index);

vector4 pcimportbyidxp(handle, channel, index);

matrix3 pcimportbyidx3(handle, channel, index;

matrix4 pcimportbyidx4(handle, channel, index);

string pcimportbyidxs(handle, channel, index);

Thanks guys.

@bhavesh: How do you check the nearest point in another point cloud? You use pcopen ( handleToAnotherPCloud )?

...

he meant like sampling pointcloud from file or geometry other than first input (simply different one to geometry being processed by vop sop), since first input pointcloud will always query for each point the same point as a closest point so you may want to exclude first point

Link to comment
Share on other sites

Thanks anim, great info. Where did you get the info of pcimportbyidxi? I couldn't find it in the help. Don't need to look at the help as your info is enough, but just wondering :)

Also I wanted to see if the first point of the point cloud search includes the point itself, but I couldn't see that.

So this is what I did.

Create a grid of 1x1 with 2x2 divisions. Add a VOP SOP and use this code inside an Inline VOP:

int handle = pcopen("op:/obj/grid/grid1", "P", P, 2, 99);
if (pciterate(handle))
{
    int pt = ptnum;
    while (pciterate(handle))
    {
        int index;
        pcimport(handle, "point.number", index);
        printf("%s : %s\n", pt, index);
    }
    printf("-----------------------------\n");
}

Doing this prints this:

0 : 1
1 : 0
2 : 3
3 : 2
0 : 2
1 : 3
2 : 0
3 : 1
0 : 3
1 : 2
2 : 1
3 : 0
-----------------------------

Should it not have:

0 : 0
1 : 1
2 : 2
3 : 3

in the results too if the current point is also included in the PC query results?

Edited by magneto
Link to comment
Share on other sites

the iterating in while loop returns correct values as well, but note that your line

if (pciterate(handle))

actually iterates over first point

and then calling: while (pciterate(handle)) straight afterwards without importing anything from that point first, you are actually ignoring it completely and importing values from second point on

so that's why it returns just 3 values per point

  • Like 1
Link to comment
Share on other sites

I think you are right, I tested this on simple pointcloud and it seems that they are ordered from closest to furthest (but I am pretty sure somebody was saying to be careful about this assumption)

in that case you can use pcimportbyidx() to get any point by index within found points, first will be closest(or itself as Bhavesh mentioned) last furthest (idx = pcnumfound()-1 )

pcopen returns all found points ordered by distance. but due to its SIMD structure and particularly with pointcounts above 256, vex doesn´t necessarily process the points in order (above 256 points vex starts splitting them up into parts for better threading). afaik that's how it was for houdini 11. i have no idea if it's the same with H12.

hth. petz

  • Like 2
Link to comment
Share on other sites

.. but due to its SIMD structure and particularly with pointcounts above 256, vex doesn´t necessarily process the points in order (above 256 points vex starts splitting them up into parts for better threading)

...

true, but doesn't this apply to source points only?

if I have only 1 point from which I sample 512 points of surrounding pointcloud will this be still split to 2 cores? it doesn't seem to be so likely for me, since we always loop through it one by one and not in parallel

so as the ordering works for small point numbers I think the order will still be kept in higher pointcounts opened by pcopen, unless there is other catch to it

Edited by anim
Link to comment
Share on other sites

so as the ordering works for small point numbers I think the order will still be kept in higher pointcounts opened by pcopen, unless there is other catch to it

these are two different things. the points which are being returned by pcopen are always sorted by distance no matter what the pointcount is.

but let´s suppose you have 1000 points. you can't be completely sure that point 500 will be processed after point 499. still this doesn't change the order of queued points in pcopen.

true, but doesn't this apply to source points only?

if I have only 1 point from which I sample 512 points of surrounding pointcloud will this be still split to 2 cores? it doesn't seem to be so likely for me, since we always loop through it one by one and not in parallel

that's true but since pcopen relys on building a search-tree (kd-tree) it won't be multithreaded anyway. at least not for generating the structure (accessing the tree is threadsafe afaik).

but as i said before, this might have been changed in houdini 12.

petz

Edited by petz
  • Like 1
Link to comment
Share on other sites

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...