groblus Posted August 24, 2018 Share Posted August 24, 2018 Hi, I'm trying to find a couple of nearest points, the problem is I want to avoid duplicates - so let's say point no.1 finds their nearest points (lets say no. 17, and no. 39) I don't want them to be included into nearest search anymore. To be honest I can't tell what am I doing wrong ( I suspect some stupid error or groups not updating until code is finished). No matter what I do - I still have points included in my search. Here is my piece of code - that I use in "Detail Wrangle". Then it's used inside a for loop (node based) to control number of iterations (it simulates growth). Scene file also included. Any clues on that? int branches = 2; int seeds[] = expandpointgroup(0,"seed"); foreach( int seed; seeds) { setpointgroup(0,"seed", seed, 0); //remove point from seeds setpointgroup(0,"used", seed, 1); //mark point as used vector pos = pointattrib(0,"P",seed,1); //get seed position int nearpts[] = nearpoints(0,"!used !seed",pos,2,branches); //search within not used points, //this should prevent finding duplicates foreach (int nearpt; nearpts) { addprim(0,"polyline",seed,nearpt); //draw a line setpointgroup(0,"seed", nearpt, 1);//make new point as a seed } } duplicates.hipnc Quote Link to comment Share on other sites More sharing options...
groblus Posted August 24, 2018 Author Share Posted August 24, 2018 Hi, I'll reply to my own topic so that the solution stays. I'm not really sure if groups were not updating and nearpoints() failed to give proper results, but filtering results on my own managed to solve the problem: New code, that works looks like this int branches = chi("branches"); float radius = chf("radius"); int seeds[] = expandpointgroup(0,"seed"); int taken[]= {}; foreach(int s_ptnum; seeds) { vector s_P = point(0,"P",s_ptnum); int nearpts[] = nearpoints(0,"!used !seed",s_P,radius,branches); setpointgroup(0,"seed", s_ptnum, 0); setpointgroup(0,"used", s_ptnum, 1); int dests[] = {}; int index = -1; foreach (int n_pt; nearpts) { index = find(taken,n_pt); if (index<0) { push(taken,n_pt); addprim(0,"polyline",s_ptnum,n_pt); setpointgroup(0,"seed", n_pt, 1); } } } Quote Link to comment Share on other sites More sharing options...
anim Posted August 24, 2018 Share Posted August 24, 2018 1 hour ago, groblus said: ... int nearpts[] = nearpoints(0,"!used !seed",s_P,radius,branches); ... so for this line your group is saying: !used !seed which means: "all points that are not used OR all points that are not seed" so in other words it will include all points that are not seed whether used or not and also all points that are not used whether seed or not, so the only not included points will be the ones that are used but also seed so what you probably wanted is !used ^seed which would be: all not used points except for seed points 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.