Welcome to od|forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

logix1390

Resample Lines by length

Hello,

I have some lines, and I want to add points to each line based on the length of the line. The longer the line, the fewer points I want to add , and the shorter the line , the more points I want to add. 
I have already calculated the perimeter of each line and stored the values in an attribute called " perm". 

After I isolated one line inside the foreach, I add the Resample node. I want to get the resample "length" parameter and divide it by the attribute "perm" to see what happens.

I have a point expression in the "Length" paramter of the resample to reference in the values of the perm attribute but it's not working...
point(opinputpath(“.”,0), $Ptnum, “perm”,0)

Is there something here I'm missing? I attached my file If anyone wants to take a look.

 

Thank you.

resample_by_length_Polylines.hip

Share this post


Link to post
Share on other sites

hm maybe this is not what you looking for because its not proportional to the segment length but you can use the ptdist to delete if the points are x units apart from each other? And ctrl the the resample size with the segments count...I attached the file. 

resample_by_length_Polylines.hip

 

resample_by_length.jpg

Edited by jon3de

Share this post


Link to post
Share on other sites

After calculating their length, you can use a primwrangle on the lines.

// user parameters
float cut    = chf('cut');
float change = chf('restlength');

// identify point positions
int vtx_0 = primvertex(0, @primnum, 0);
int vtx_1 = primvertex(0, @primnum, 1);
int pt_0 = vertexpoint(0, vtx_0);
int pt_1 = vertexpoint(0, vtx_1);
vector pos_0 = point(0, "P", pt_0);
vector pos_1 = point(0, "P", pt_1);

// define slices based on user parameters
@restlength = pow(@restlength, change);
int slice = int( ceil(cut / @restlength) );
slice = max(slice, 2);

// add new primitive with points and vertices
int add_prim = addprim(0, "polyline");

for(int i = 0; i < slice; i++) {
    float mix  = i / float(slice - 1); 
    vector pos = lerp(pos_0, pos_1, mix);
    int add_pt = addpoint(0, pos);
    addvertex(0, add_prim, add_pt);
}

// remove the old primitives
removeprim(0, @primnum, 1);

 

counter_resample.hipnc

1 person likes this

Share this post


Link to post
Share on other sites

with H16 what you can do is just rename your "perm" attribute to "segment_length" (or "num_segments" alternatively) and enable overriding attributes (should be enabled by default I think)

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now