Jump to content

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


Recommended Posts

  • 4 months later...

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

Sorry could you explain me this?

I think it's not really clear to me how the pc loop thing is working.

from pciterate documentation

This function can be used to iterate over all the points which were found in a pcopen query. The first argument is the handle returned by pcopen. The function returns 1 while there are points left in the iteration loop, or 0 when there are no further points. This lets you use the function as the condition in a while loop.

so pciterate onnly returns 1 or 0, and its output is not a handle. the handle of the point cloud is provided only by the pcopen, right?

using the magneto code as examnple


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");
}

[/CODE]

pcimport is using the handle of the pcopen, how does it knows wich point to import? how does it knows wich iteration is? shouldn't I provide also an index to it?

this thing is really confusing for me.

Link to comment
Share on other sites

pciterate() simply advances to next point and returns 1 if it exists or 0 if not

so 0 or 1 is only important for you to know if there is still some point left to import from

but it actually advanced to next point as well so next time you run pcimport() it will import from that point

nowadays it's much simpler and less confusing to use pcnumfound() and pcimportbyidx() with for loop, instead of pciterate() and pcimport() with while loop

there are examples lying on the forums for usage of both

Link to comment
Share on other sites

I want to understand how the while works with the pciterate also :) I can make it work but i'd like to understand WHY it works

The only way I can explain how the combination while+pciterate works is that houdini recognize at the compiling time that i want to iterate through the points (in some mysterious way) and it does it for me. It seems that it generate its own loop structure when i'm using the pciterate inside a while loop.

You say that if i call pciterate() twice it advance to the next point twice. This seems to me that it writes the iteration value in some hidden variable, and it always refer to that for eventual successive pciterate() calls.

Could you correct me please?

Link to comment
Share on other sites

well, yes it keeps track of the current point within each opened pchandle and pciterate() can advance to the next point, so calling it twice you will advance twice and therefore you can miss one point if you don't get data from it by pcimport()

you may need to read a bit about iterators in general, will this help?

http://en.wikipedia.org/wiki/Iterator

Link to comment
Share on other sites

Also if you know C#, it's basically the same as calling IEnumerator.MoveNext manually. That's why it might look confusing to you because you are advancing the collection yourself. It would be sweet if we could also iterate through a point cloud using foreach like this:


vector pos;
int handle = pcopen("op:/obj/grid/grid1", "P", P, 2, 99);
foreach(var index in handle)
import("P", pos, 0, index);
[/CODE]

Maybe for H13? :)

Link to comment
Share on other sites

I mean getting point count returned by pcopen using pcnumfound()

then in for loop 0-pcnumfound() importing by index using pcimportbyidx()

in VOPs is much simpler than while loop with all the safe tests, in VEX it doesn't really matter

  • Like 2
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...