Jump to content

Inpointgroup VEX function issue


Mellek

Recommended Posts

Hi all, first post as I have been using the forum passively up until now by searching for existing queries, but on this one I've hit a wall.  I'm newly getting started so this may be a simple / facepalm type issue!

I have the following code in a wrangle node with the intention of grouping points by whichever of the RGB values is highest.  It mostly works as is, but I want for any point that didn't get included in the first two groups (grp_redbin grp_greenbin) to be automatically added into the third group (grp_bluebin).  I'm using the inpointgroup function to test if the current point is already a member of one of the existing groups (at this point just the red one for testing purposes) but it always stays at zero meaning all points get assigned to the last group regardless of their existing memberships.
 

int grpCount = 0;

i@group_grp_redbin = (@Cd.r > @Cd.g && @Cd.r > @Cd.b);
i@group_grp_greenbin = (@Cd.g > @Cd.r && @Cd.g > @Cd.b);

grpCount += inpointgroup(0, "grp_redbin", @ptnum);

if (grpCount == 0) i@group_grp_bluebin = 1;

Can anyone see why this might be happening, or suggest a more logical way to go about this process?  Many thanks.

Link to comment
Share on other sites

int inpointgroup(int input, string groupname, int pointnum)

All geometry lookup functions take geometry argument, where to perform search. It may be file/operator paths, or input number if integer value was used. Input means geometry on the upstream node plugged into the wrangle. So, if there is no such group with this point member on this node, result will be false.

 

Instead, use variables you just created, since they exist in the current scope and already initialized with proper values.

@group_a = expression1;
@group_b = expression2;
@group_c = !(@group_a || @group_b);

While it may work in general, in case you simplified your real example to such snippet, it seems, in this particular case the code will mark all green colors as both green and blue. If we check for both red and green groups membership, it will mark yellow color {1.0, 1.0, 0.0} as blue. Since there is no groups for 3 intermediate colors, grayscale, black and white values, this code snippets may work better:

@group_r = @Cd.r == max(@Cd);
@group_g = @Cd.g == max(@Cd);
@group_b = @Cd.b == max(@Cd);
if      (@Cd.r == max(@Cd)) @group_r = true;
else if (@Cd.g == max(@Cd)) @group_g = true;
else                        @group_b = true;

First one will set r, g, b groups based on value, and it is possible for point with colors like {1.0, 1.0, 0.0} to be in red and green groups at the same time. Grayscale values will be placed into all three groups. If you need to divide everything into three exclusive groups, use second one, it will mark {1.0, 1.0, 0.0} {1.0, 0.0, 1.0} {0.0, 1.0, 1.0} as red, red and green, preferring the first occurrence of the maximum value, so, grayscales will be placed into red.

  • Like 1
Link to comment
Share on other sites

Wow, you really went above and beyond on that one!  I really appreciate the extra explanations and suggestions and am going to have a play with these tomorrow.  I didn't know about the max function which seems to be a much better way of doing what I need to do, and you also picked up on the issue with greyscales where there is no highest value.  I may afterwards try and set it up so these points are placed randomly into one of the existing groups, but that's for later!

Thank you very much for the time you took to reply here, it's really appreciated and is a huge help.  :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...