Group nearby points with VEX
1357
4
1
albinioni
Member
69 posts
Joined: 9月 2018
Offline
2020年6月22日 6:35
I'm trying to group nearby points into different groups using VEX.
I have an attribcreate (i) initialized to 1 plugged into a point wrangle with the following code:
float dist = ch ("dist" );
int nearestPoints [] = nearpoints (0 , point (0 , "P" , @ptnum ), dist );
string groupName = concat (“ group_ ” , itoa (i@i ));
foreach (int point ; nearestPoints ) {
if (point (0 , "grouped" , point ) != 1 )
{
setpointgroup (0 , groupName , point , 1 , "set" );
setpointattrib (0 , "grouped" , point , 1 , "set" );
}
}
if (len (nearestPoints ) > 0 )
{
nearestPoints = int [](array ());
i@i ++;
}
Why doesn't this work?
My behaviour: All points gets the “grouped” attibute set to 1 and gets added to the group “group_1”, and “i” only gets to 2.
Edited by albinioni - 2020年6月22日 06:54:45
albinioni
Member
69 posts
Joined: 9月 2018
Offline
2020年6月22日 7:41
I was able to get closer to what I want to achieve by by wrapping all the points of the geometry into a foreach. Contrary to my belief, it seems like a point wrangle doesn't work as a for each loop from the start?
Can someone then please educate me on the behaviour of a point wrangle? Does every line of code loop over every point before jumping onto the next one?
What I changed my code to:
vector allPos [];
resize (allPos , npoints (0 ));
for (int i = 0 ; i < npoints (0 ); i ++) {
allPos [i ] = point (0 , "P" , i );
}
float dist = ch ("dist" );
foreach (vector p ; allPos )
{
int nearestPoints [] = nearpoints (0 , p , dist );
string groupName = concat (“ group_ ” , itoa (i@i ));
foreach (int point ; nearestPoints ) {
if (point (0 , "grouped" , point ) != 1 ) {
setpointgroup (0 , groupName , point , 1 , "set" );
setpointattrib (0 , "grouped" , point , 1 , "set" );
}
}
if (len (nearestPoints ) > 1 ) {
nearestPoints = int [](array ());
i@i ++;
}
}
Edited by albinioni - 2020年6月22日 10:33:56
2020年6月22日 7:55
Just a post a file please. Saves time = Makes more people help you.