Jump to content

Attribute wrangle: connect points only vertically


Recommended Posts

I'm having troubles with connecting close points, but only if they are not on the same y coordinate.

int pts[] = nearpoints(0, @P, chf("maxDist"));

printf("POINT " + itoa(@ptnum) + "\n");

foreach (int pt; pts) {
    float coord[] = point(0, "P", pt);
    printf("   " + itoa(@ptnum) + "   NEARPOINT " + itoa(pt) + "\n");

    // don't connect horizontally
    if(abs(coord[1] - @P.y) < 0.001) {
        return;
    }
    
    int prim = addprim(geoself(), "polyline", @ptnum, pt);
}

 

Also I think I might not really understand the order in which things are executed. If I run the above code over points I expect a nested debug output like 

POINT 1
   1   NEARPOINT 1
   1   NEARPOINT 2
POINT 2
   2   NEARPOINT 1
   2   NEARPOINT 2

etc...

Instead I get the output of line 3 for every point first. How come? (Pretty new to Houdini.)

filter.hipnc
 

Link to comment
Share on other sites

It's a bit confusing but nearpoint also returns the source point, i.e. it finds itself. So you have to exclude this entry.
It' probably why you get three lines when you excpect two.

This is a try for what you try to do. It run in detail mode. For this kind of  stuff, It's more easy to debug IMO.

 

filter F.hipnc

Filter.jpg

Edited by flcc
Link to comment
Share on other sites

@flcc : Thanks!

(1) May I ask why you run it in detail mode and then manually iterate through the points? Wouldn't running it over the Points do that for you?

(2) The part about nearpoint returning the source: I was aware of that and initially tried something like this (in my code above):

foreach (int pt; pts) {
  if(pt == @ptnum) { return; }

I thought it would skip the loop for those cases where the nearpoint is the current point. But somehow this condition was always true and the the code always returned. That's quite confusing to me.

Link to comment
Share on other sites

When creating geometry I prefer run in detail Mode if possible. Can sometime be tricky in point mode.
But you can easily convert it in point mode after if needed. If primitive number is the same, It's that there is no problem.

Probably more experimented guys don't do that :)

Link to comment
Share on other sites

Hi,

You are doing it correctly but instead of return you have to use "continue":

int pts[] = nearpoints(0, @P, chf("maxDist"));
removevalue ( pts, @ptnum );

foreach (int pt; pts) {
    vector coord = point(0, "P", pt);
    if(abs(coord.y - @P.y) < 0.001)
        continue;
    
    if ( @ptnum < pt )
        int prim = addprim(geoself(), "polyline", @ptnum, pt);
   
}

I would also recommend removing the point itself from the array. The point itself is generally the first element but it's not guaranteed if you have overlapping points.

Also you can avoid duplicate polygons by comparing point numbers.

As for the print messages, it's related to how Houdini executes the given VEX code.

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