magneto Posted August 18, 2012 Author Share Posted August 18, 2012 Thanks petz. I did some simple experiments and also found out the same, but it's good to confirm the points are ordered by distance Quote Link to comment Share on other sites More sharing options...
MENOZ Posted December 29, 2012 Share Posted December 29, 2012 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. Quote Link to comment Share on other sites More sharing options...
anim Posted December 29, 2012 Share Posted December 29, 2012 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 Quote Link to comment Share on other sites More sharing options...
MENOZ Posted December 29, 2012 Share Posted December 29, 2012 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? Quote Link to comment Share on other sites More sharing options...
anim Posted December 29, 2012 Share Posted December 29, 2012 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 Quote Link to comment Share on other sites More sharing options...
magneto Posted December 30, 2012 Author Share Posted December 30, 2012 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? Quote Link to comment Share on other sites More sharing options...
anim Posted December 30, 2012 Share Posted December 30, 2012 you can iterate by index using for loop, I think that's sweet enough for now, there is plenty of other areas that need fixing for 13 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted December 30, 2012 Author Share Posted December 30, 2012 You mean by using pcimport? Or a different technique? I agree true edge support is sorely missed in H13 Quote Link to comment Share on other sites More sharing options...
anim Posted December 30, 2012 Share Posted December 30, 2012 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 2 Quote Link to comment Share on other sites More sharing options...
magneto Posted December 30, 2012 Author Share Posted December 30, 2012 Gotcha, yeah that looks good enough Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.