Grouping every Nth point

   9186   1   3
User Avatar
Member
3 posts
Joined: Oct. 2016
Offline
Hey guys,
Im new to houdini, Im trying to so something here but i dont really know if its possible so here goes.

I have the following mesh
https://www.dropbox.com/s/nuq8271lwn6bshw/chrys.jpg?dl=0 [dropbox.com]

I want to make 4 groups (can i use a pointWrangle to do it?)
I wanted these 4 groups procedurally: 1,6,11,16 // 2,7,12,17 // 3,8,13,18 // 4,9,14,19

IF its possible, I would do it like this (im not familiar with the variables yet so here is a pseudo-code)

int $numGroups = 4; // wanted the code to create the groups for me. is it possible?
int $n = 1;

while($n <= $numGroups){

if(($PT % $n) == 0){
condition = 1;
setpointgroup(geoself(), (groupNamePrefix + $n), @ptnum, condition);
}

$n = $n + 1;
}


Does it make sense? Im open to other ways to do it.
Edited by neil_math_comp - March 9, 2017 18:53:38
User Avatar
Member
1743 posts
Joined: March 2012
Offline
(Note: I edited your post to use a link instead of an img tag, because the img tag seemed not to be working. Sorry!)

In VEX, $ isn't a valid character for a variable name, as far as I know, (or at least in Attribute Wrangle, it will be interpreted as a global HScript variable, so it will probably evaluate to zero or empty-string, and you won't be able to modify it.)

The simplest way I can think of to do this is, with Run Over set to Points:

int numGroups = 4;
string groupNamePrefix = "mygroup_";
int group_number = @ptnum % numGroups; // remainder when dividing by numGroups
// Note: The default value for groups is always 0,
// so we only have to set the group that will be 1.
setpointgroup(geoself(), groupNamePrefix + itoa(group_number), @ptnum, 1);

However, for large numbers of points, (like thousands to millions), if you're only going to need 4 groups, it may be faster to do:

int group_number = @ptnum % 4; // remainder when dividing by 4
// This will automatically create groups named mygroup_0 through mygroup_3.
@group_mygroup_0 = (group_number == 0);
@group_mygroup_1 = (group_number == 1);
@group_mygroup_2 = (group_number == 2);
@group_mygroup_3 = (group_number == 3);

If you want to do it with Run Over set to “Detail (only once)”:

int numGroups = 4;
string groupNamePrefix = "mygroup_";
for (int pt = 0; pt < @numpt; ++pt) {
    int group_number = pt % numGroups; // remainder when dividing by numGroups
    setpointgroup(geoself(), groupNamePrefix + itoa(group_number), pt, 1);
}

Alternatively, (still with Run Over set to Detail), having an outer loop over the groups, we could do:

int numGroups = 4;
string groupNamePrefix = "mygroup_";
for (int group_number = 0; group_number < numGroups; ++group_number) {
    string group_name = groupNamePrefix + itoa(group_number);
    // From the starting point, skipping by numGroups points each time.
    for (int pt = group_number; pt < @numpt; pt += numGroups) {
        setpointgroup(geoself(), group_name, pt, 1);
    }
}

Hopefully these examples help a little. VEX is a powerful, but deep, rabbit hole if you want to really get into it. Thankfully a lot of simple things are relatively easy, so feel free to ask.
Edited by neil_math_comp - March 9, 2017 19:21:48
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
  • Quick Links