Macha Posted April 21, 2011 Share Posted April 21, 2011 (edited) I have some geometry with many points. Each point has an $ATTRIBUTE_SCALAR. I want to create another vector $ATTRIBUTE_VECTOR that points to the nearest $ATTRIBUTE_SCALAR with the same value. For example: -Point 12 has $ATTRIBUTE_SCALAR = 1 In it's neighbourhood we have Point 11 with $ATTRIBUTE_SCALAR = 0.5 Point 35 with $ATTRIBUTE_SCALAR = 1 Point 785 with $ATTRIBUTE_SCALAR = 0.3 Then we would draw a vector from point 12 to point 35, and store it in $ATTRIBUTE_VECTOR because they have equal $ATTRIBUTE_SCALAR value. Now, I thought this would be easy peasy with a point cloud and while loop but it turns out we cant write attributes inside such a loop. I get the error below. It's likely there are multiple possible values for each point's $ATTRIBUTE_VECTOR, but I am not concerned about that for now (although even better if somebody finds a solution for that too!). I just need one vector (any of them). So we don't need to worry about that. How can I do this? Edited April 21, 2011 by Macha Quote Link to comment Share on other sites More sharing options...
Macha Posted April 21, 2011 Author Share Posted April 21, 2011 Attached is a simplified hip file illustrating the problem. veccol.hip Quote Link to comment Share on other sites More sharing options...
Macha Posted April 21, 2011 Author Share Posted April 21, 2011 The file below contains a version of my failed attempt. veccol.hip Quote Link to comment Share on other sites More sharing options...
tjeeds Posted April 21, 2011 Share Posted April 21, 2011 I think this works veccol3.hip Quote Link to comment Share on other sites More sharing options...
~nature~ Posted April 21, 2011 Share Posted April 21, 2011 (edited) Hi, Macha, Here is the vex solution, I hate vops concerning point clouds. #pragma label filename "Lover File" #pragma label matchattrib "Lover Attribute" #pragma label direction "Lover Direction" #pragma label maxsearchlovers "Max Search Lovers" #pragma label tolerance "Lover Tolerance" sop nearest_lover(string filename="",matchattrib="",direction="";int maxsearchlovers = 30;float tolerance = 0.2) { int maxlovers = min(Npt,maxsearchlovers); int handle = pcopen(filename,"P",P,1e+9,maxlovers); vector dir = 0; if(pciterate(handle)) { float me; pcimport(handle,matchattrib,me); while(pciterate(handle)) { float lover; pcimport(handle,matchattrib,lover); if (abs(lover-me)<=tolerance) { vector loverpos; pcimport(handle,"P",loverpos); dir = loverpos - P; break; } } pcclose(handle); } addattribute(direction,dir); } As for multiple possible values, how about pcfiltering the position of the matched lovers(you need to specify how many similar lovers are tolerated) based on your actual need ? veccol_nature.hip nearest lover.otl Edited April 21, 2011 by ~nature~ Quote Link to comment Share on other sites More sharing options...
Macha Posted April 21, 2011 Author Share Posted April 21, 2011 Thanks to Jesse for wrapping his brain around so many nodes, and thanks to Nature for making it so simple with a few lines of code. Definitely the time for me to review my vex typing skills! 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.