Jump to content

searching for points avoiding id - then connecting them


Javier31

Recommended Posts

hi there,

I am trying to search for the closest points with different id and then connect them :-)

Basically, every single point should be able to connect with other 2 or 3 other points max but avoiding points with same id (so no connections with the points of the same curve)

see attached file and screenshot of what i got so far

many thanks!! :-)

3.JPG

connecting just to other lines.hipnc

Link to comment
Share on other sites

Hi @Javier, 
Here some idea how avoid the same @id and connect points with different @id using point clouds, 
I belive there are many other ways, this is just a quick one, 
Cheers!
Dam

float radius = chf('radius');
int maxpoints = chi('searchpoints');

int near_ptnum;
int new_prim;

int handle = pcopen(0,"P", @P, radius, maxpoints);
while(pciterate(handle))
{
    int cur_id;
    pcimport(handle, "id", cur_id);
    if(i@id != cur_id)
    {    
        pcimport(handle, "point.number", near_ptnum);
        new_prim = addprim(0,"polyline");
        addvertex(0,new_prim,@ptnum);
        addvertex(0,new_prim,near_ptnum);
    }
    
}
pcclose(handle);

connecting_just_to_other_lines.hipnc

Edited by Dam
  • Like 1
Link to comment
Share on other sites

I wondered the same thing recently and wrestled with the "group" parameter in nearpoints, but somehow did not grok how to write a group expression that does this.
Using pcopen feels much clearer there, although one will probably still have to have a large maxpoints number to be sure to hit something on the other curves and then maybe limit the result manually in the while loop.
I was searching for only one closest point on any curve different from the current, using the "class" attribute from the connectivity node...

Cheers!

Tom

Edited by Thomas Helzle
Link to comment
Share on other sites

Yeah pcopen needs a bit of adjustments on the radius at first place. for limiting the number of connections to 3 or less I found helpfull  "pcnumfound" function, It returns the number of points founded and with this information stored in an attribute can be possible trigger the connections. So even we found more than 10 points, we can filter from those only the three avaible for make connections, but for a more accurate selection I guess with an array of "nearpoint" will be easier taking the first 3 or less found points with a specific order :) 

 

int handle = pcopen(0,"P", @P, radius, maxpoints);
while(pciterate(handle))
{
    int cur_id;
    pcimport(handle, "id", cur_id);
    if(i@id != cur_id)
    {    
        pcimport(handle, "point.number", @near_ptnum);
        i@pt_found = pcnumfound(handle);
        if(@pt_found < 3){
           new_prim = addprim(0,"polyline");
           addvertex(0,new_prim,@ptnum);
           addvertex(0,new_prim,@near_ptnum);
        }
    }

 

Edited by Dam
Link to comment
Share on other sites

I ended up using this (with "@class" being the per-object attribute from the connectivity node):

float searchrad = chf("Searchradius");
int maxpts = chi("MaxPoints");

int nearpnts[] = nearpoints(0, @P, searchrad, maxpts);

int maxlines = chi('MaxLines');
int cnt = 0;

foreach(int pnt; nearpnts){
    if(@class != pointattrib(0, 'class', pnt, 1)) {
        if (cnt >= maxlines) {
            break;
        }
        int line = addprim(0, "polyline");
        addvertex(0, line, @ptnum);
        addvertex(0, line, pnt);
        cnt += 1;
    }
}

While this works fine, I still wonder if it wouldn't be faster to have a fitting group expression directly in nearpoints... ?

Cheers,

Tom

Link to comment
Share on other sites

This is cool

For the group stuff, should be something like this:

@group_pts = int(@P.y % 2);
@Cd.x = @group_pts;  //vizGroup

int maxpts = chi("MaxPoints");
int nearpnts[] = nearpoints(0, @P, @group_pts, maxpts);

int maxlines = chi('MaxLines');
int cnt = 0;

foreach(int pnt; nearpnts){
    if(@class != pointattrib(0, 'class', pnt, 1)){
        if (cnt >= maxlines){
            break;
        }
        int line = addprim(0, "polyline");
        addvertex(0, line, @ptnum);
        addvertex(0, line, pnt);
        cnt += 1;
    }
}

 

In this way only the points in the @group_pts will serch for the nearest. In a case were every point it's searched within the radius but we ask for the @group_pts before to make connection:

@group_pts = int(@P.y % 2);
@Cd.x = @group_pts;  //vizGroup

float searchrad = chf("Searchradius");
int maxpts = chi("MaxPoints");
int nearpnts[] = nearpoints(0, @P, searchrad, maxpts);

int maxlines = chi('MaxLines');
int cnt = 0;

foreach(int pnt; nearpnts){
    if(@class != pointattrib(0, 'class', pnt, 1)) {
        if (cnt >= maxlines || @group_pts == 1) {
            break;
        }
        int line = addprim(0, "polyline");
        addvertex(0, line, @ptnum);
        addvertex(0, line, pnt);
        cnt += 1;
    }
}

Cheers - Dam

group_expression_near_points.hipnc

Edited by Dam
  • 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...