VEX : array question.

   528   3   1
User Avatar
Member
5 posts
Joined: 5月 2024
Offline
Hello,

using an OSM file I am trying to get all intersection points in an array. "intersectionanalysis" does not work because the "Proximity tolerance" is or too high or not enough.

So I am trying to find all cross points like this :

int nc = neighbourcount(0, @ptnum);
i@nc = nc;

int ptid = @ptnum;
i@ptid = ptid;

int ptcount = @numpt;

i@ptcount = ptcount; // just to check

int intersectionList = array();

for(int i = 0; i < ptcount; i++)
{
if (nc > 2){
i@intersectionid = 1;
int intersectionid = @intersectionid;
}
append(intersectionList, ptid);
}


i@il = intersectionList;


...but of course i am not getting what i expect...i got something like this


Any good tutorial or help ?

Thanks !
User Avatar
Member
119 posts
Joined: 12月 2019
Offline
Hello,

Probably because the array variable is missing brackets []:

int intersectionList[] = array();

Same thing when you want to write into an attribute using @-syntaxe :

i[]@il = intersectionList;
Houdini Pipeline Supervisor @ TAT Studio
User Avatar
Member
5 posts
Joined: 5月 2024
Offline
ObeidaZakzak
Hello,

Probably because the array variable is missing brackets []:

]

Hello thanks but no... in fact when i copied the text i forgot to use the "vex" tag here and so it seems the system delete the brackets.

So here it is the full code now:

int nc = neighbourcount(0, @ptnum);
i@nc = nc;

int ptid = @ptnum;
i@ptid = ptid;
        
int ptcount = @numpt;

i@ptcount = ptcount; // just to check

int intersectionList[] = array();

for(int i = 0; i < ptcount; i++)
{
    if (nc > 2){
        i@intersectionid = 1;
        int intersectionid = @intersectionid;        
        }
        append(intersectionList, ptid);
}
    

i[]@il = intersectionList;
User Avatar
Member
119 posts
Joined: 12月 2019
Offline
All right I took a closer look at your script.

Are you running this over Points or Detail ?

If it's over Points, then you will get a long array on every point, due to the fact you are looping over points inside a Point Wrangle. Also when working with a huge data set you might encounter performance issues due to the for loop.

If it's over Detail, then it should not work at all because @ptnum does not have sense in a Detail Wrangle, it's only usefull when running over elements like Points/Vertices/Prims.

Now if I understand the problem you are trying to solve, you want to build an array of point IDs where they have more than 2 neighbours, right ? If it's so, I can suggest a couple of methods here, and you could adapt them to your problem :

1. Build everything with a Detail Wrangle :

i[]@intersectionList = array();
for (int pt = 0; pt < @numpt; pt++)
{
    int nc = neighbourcount(0, pt);
    int intersectionid = nc > 2;
    setpointattrib(0, "nc", pt, nc);
    setpointattrib(0, "intersectionid", pt, intersectionid);
    if (intersectionid)
    {
        append(i[]@intersectionList, pt);
    }
}

2. Assign point attributes with a Point Wrangle then build the list in a second time with a Detail Wrangle :

2a. Point Wrangle
i@ptid = @ptnum;
int nc = neighbourcount(0, @ptnum);
i@nc = nc;
i@intersectionid = nc > 2;

2b. Detail wrangle
i[]@intersectionList = array();
for (int pt = 0; pt < @numpt; pt++)
{
    int intersectionid = point(0, "intersectionid", pt);
    if (intersectionid)
    {
        append(i[]@intersectionList, pt);
    }
}

3. Same as 2. but instead of Detail Wrangle remove points where intersectionid == 0 and promote their ID to an array using Attribute Promote SOP (see in the hip file)

Attachments:
IntersectionList.hiplc (124.2 KB)
IntersectionList.png (2.2 MB)

Houdini Pipeline Supervisor @ TAT Studio
  • Quick Links