Jump to content

Basic question about loop behavior at Vex


Recommended Posts

Hi,

I have a point cloud with 2 different colors. If at least 2 red dots come too close, one of them should turn green. I work with pcfind. However, both become green in the process. Well, they are also within the mutual selection radius.
I tried to filter in my script, but I'm stuck.

It should be the case that the points and arrays are processed one after the other? Finally, one point of the “dense point group” should remain, since the others have already turned green and can no longer select it…
 

the structure should be:

In the first loop, based on the first array (the points that the surrounding search and store in another array).

In the second loop, the second array is used. On the basis of the second array, the points are examined and checked whether they are red. If so, they turn green.

Finally, another if statement should ensure that all points that turn green lose their arrays (and are therefore no longer able to recolor other points).

This should leave the last red dot of an intersecting group of dots.
But he doesn't. The wrangler doesn't realize the new green points.

However, it works again when the last 2 if statements appears in a new wrangler.
But that's the problem. Then it is outside the loop.


Is all this normal? And how can I achieve my desired effect?

 

Help would be great.

 

// wrangler 1

@Cd = 0;

float seed = chf("seed");
float prob = chf("prob");
float r = rand(seed+@ptnum);
@Cd = set( prob > r, prob < r,0 );

float rad = 0.5;

if (@Cd.r == 1) {
    setpointgroup(0,"a",@ptnum,1);
    
    i[]@pclouds = pcfind(0,"P",@P,rad,15);
    removeindex(i[]@pclouds,0);
    i[]@pclouds = sort(i[]@pclouds);
    
}

// wrangler 2 - I must set up a new one, because the point group can only be read in a new wrangler. Is this normal?

i[]@reds = expandpointgroup(0,"a");

for (int j = 0; j < chi("iter"); j++) {
    int i = i[]@reds[j];

    if (@ptnum == i) { 
       
        for (int k = 0; k < chi("iter2"); k++) {
                int l = i[]@pclouds[k];
                
                if (@Cd.r == 1) {
                    
                    setpointattrib(0,"Cd",l,set(0,1,0));
                }
                
                if (@Cd.g == 1) {
                    
                    resize(i[]@pclouds,0);
                }
         }
    }
}

 

is a weird situation because this loop works:

 

for (int i = 0; i < chi("iter"); i++) {
    
    if (@Cd.r == 1) {
    
        if (@P.y == 2) {
            @P.y += 1;
        }
    
        if (@P.y == 1) {
            @P.y += 1;
        }
    
        if (@P.y == 0) {
            @P.y += 1;
        }
    }
}

 

So the problem is the function setpointattrib():
It just doesn't work.

for (int i = 0; i < chi("iter"); i++) {
    
    if  (@Cd.g == 1) {
        @P.y ++;    
    }

    if (@Cd.r == 1) {
        setpointattrib(0,"Cd",@ptnum,set(0,1,0));  
    }
    
}

But I need that when each point has its own array.

What works: All points have the same array:
@ptnum == a;  a can be read.

Which doesn't work: All points have different arrays:
@ptnum == b;  b cannot be read. there is no result. probably because of different values.
Unless you use setpointattrib().

- - - - - - - -

I just remembered something else:
if i use a maximum iteration with the function len() it seems to use only the points which store the arrays (in this case from i[]@pclouds). So not the value for all points.

If I just enter the value by hand, all points go up.
Is that normal? There is nothing of this in the function documentation.
 

int len2 = len(i[]@pclouds);
i@len2 = len2;

for (int k = 0; k < len2 /* or 14 */; k++) {
      int l = i[]@pclouds[k];
      i@l = l;
                
      @P.y = @P.y + .5;
}

Edited by Christoph_H
Link to comment
Share on other sites

usually what I do, when I have to do a pointcloud search and I only want to have one point affect the other (but not vice versa)
is to check the pointnumber.

basically, I usually do the following check:

if(otherPtNum <= @ptnum)
   continue; //inside your loop, or whatever other logic you want/need to use to skip the code execution for this point

 

  • Like 1
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...