Resample ofPolyline, adding points to a Polyline [SOLVED]

The doc for ofPolyline states that getResampledByCount and getResampledBySpacing will not add points to a polyline (only remove). I am looking for a method to resample a polyline and add points (evenly spaced around a shape, given a constant of spacing).

Does anyone know if a something like this exists, or a method which might work? I am trying to recreate the functionality which exists in Geomerative for processing (creating a resampled outline of a letterform).

Thanks!

[SOLUTION] EDIT:

I used ofPolyline methods getPerimeter() and getPointAtLength to generate a series of points around the length of the Polylines:

vector <ofTTFCharacter> paths = font.getStringAsPoints(type);

for (int i = 0; i < paths.size(); i++){
    vector <ofPolyline> polylines = paths[i].getOutline();
    
    for (int j = 0; j < polylines.size(); j++){
        float perim = polylines[j].getPerimeter();
        cout << perim << endl;
        for(int k = 0; k < perim; k +=10){
            ofPoint p = polylines[j].getPointAtLength(k);
            ofCircle(p, 3);
        }
    }
}

Further consideration:
This could be a really useful function to include. It’s the kind of functionality I would expect from “getResampledBySpacing.” Polyline also has a function to simplify, which seems to be very similar to the current functionality for the two Resample functions.

1 Like

@set_phen getResampledByCount and getResampledBySpacing do what you would expect them to, but do not apply to the line you are calling it from. For example:

ofPolyline origPoly;
    origPoly.addVertex( 0, 0 );
    origPoly.addVertex( 200, 0 );
    origPoly.addVertex( 400, 0);
    
    ofPolyline countPoly = origPoly.getResampledByCount( 100 );
    ofPolyline spacePoly = origPoly.getResampledBySpacing( 10 );
    
    cout << "origPoly.size(): " << origPoly.size() << " countPoly.size(): " << countPoly.size() << " spacePoly.size(): " << spacePoly.size() << endl; 

So the method you would want to use is the getResampledBySpacing(). You can just assign it to your polyline like so:

ofPolyline myPoly;
// add vertices here, however you please
myPoly = myPoly.getResampledBySpacing();
2 Likes

Aha, correct. I thought the methods were modifying the original polyline, not returning a new one. This was unclear to me in the documentation. I will make a comment.

Thank you!

+1 here that the docs on the site for the getResampledByCount are really misleading.

“This resamples the line based on the spacing passed in. The lower the
count passed in, the more points will be eliminated. This doesn’t add
new points to the line though.”

Especially that last sentence makes it seem like all this function does is remove points. I’m not even sure what it is trying to get across with that line? Is it trying to say that it won’t add points in place and needs to be a new polyline?

Can we either just lose the last line altogether or rewrite it to say something like “The higher the count passed in, the more points will be added.”?