magneto Posted August 15, 2012 Share Posted August 15, 2012 Hi, I know that there is pcfarthest function. But is there a way to find the closest? Something like pcclosest? Thanks Quote Link to comment Share on other sites More sharing options...
SpencerL Posted August 15, 2012 Share Posted August 15, 2012 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. Quote Link to comment Share on other sites More sharing options...
graham Posted August 15, 2012 Share Posted August 15, 2012 Can't you just only search for a single point when you open it? Quote Link to comment Share on other sites More sharing options...
Solitude Posted August 15, 2012 Share Posted August 15, 2012 Can't you just only search for a single point when you open it? Yeah I'm pretty sure when you set max points to 1 it returns the closest point. --Ian Quote Link to comment Share on other sites More sharing options...
magneto Posted August 15, 2012 Author Share Posted August 15, 2012 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 Quote Link to comment Share on other sites More sharing options...
anim Posted August 16, 2012 Share Posted August 16, 2012 ... 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) 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted August 16, 2012 Author Share Posted August 16, 2012 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 Quote Link to comment Share on other sites More sharing options...
ikarus Posted August 16, 2012 Share Posted August 16, 2012 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. Quote Link to comment Share on other sites More sharing options...
bhaveshpandey Posted August 16, 2012 Share Posted August 16, 2012 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. Quote Link to comment Share on other sites More sharing options...
anim Posted August 16, 2012 Share Posted August 16, 2012 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 ) Quote Link to comment Share on other sites More sharing options...
hopbin9 Posted August 16, 2012 Share Posted August 16, 2012 I know that there is pcfarthest function. But is there a way to find the closest? Something like pcclosest? You need one of these. THERE IT IS! 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted August 16, 2012 Author Share Posted August 16, 2012 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. Quote Link to comment Share on other sites More sharing options...
anim Posted August 16, 2012 Share Posted August 16, 2012 ... @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 Quote Link to comment Share on other sites More sharing options...
magneto Posted August 16, 2012 Author Share Posted August 16, 2012 (edited) 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 August 16, 2012 by magneto Quote Link to comment Share on other sites More sharing options...
magneto Posted August 16, 2012 Author Share Posted August 16, 2012 Further experiments show that this only happens when iterating. pcnumfound actually returns 4 so it includes the point itself. Using pcimportbyidxi with an index of 0, also returns the point itself. So this behavior is good. Quote Link to comment Share on other sites More sharing options...
anim Posted August 17, 2012 Share Posted August 17, 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 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted August 17, 2012 Author Share Posted August 17, 2012 Thanks anim, good catch. I didn't see that Now I want to experiment to see if the points are actually sorted from closest to furthest using the pc index function. Will post details. Quote Link to comment Share on other sites More sharing options...
petz Posted August 17, 2012 Share Posted August 17, 2012 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 2 Quote Link to comment Share on other sites More sharing options...
anim Posted August 17, 2012 Share Posted August 17, 2012 (edited) .. 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 August 17, 2012 by anim Quote Link to comment Share on other sites More sharing options...
petz Posted August 17, 2012 Share Posted August 17, 2012 (edited) 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 August 17, 2012 by petz 1 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.