PathFitter Block for Cinder

May 31, 2012

PathFitter Screenshot

I created and released my first cinder block and wanted to put it out there to see if it’s useful to anyone else.
https://github.com/gregkepler/CinderPathFitter

What it does is simplifies and returns a smoothed out, simplified Path2d object based on a vector of Vec2fs that you pass to it. It uses the same algorithm that paperjs uses, but c++-ified. It’s a slightly modified version of An Algorithm for Automatically Fitting Digitized Curves from “Graphic Gems.”

There are 2 samples in there.

  • PathSimplification: Drag to draw a line on the screen. Once the line is finished, it analyzes and smooths out the line, letting you know how many lines you saved. It’s based on this paperjs example.
  • ContinuousPath: Analyzes and smooths a path as you draw it. Could be good for making a drawing application.

To use it, all you have to do is collect a vector of Vec2f and then call FitCurve on PathFitter and pass along that vector.

PathFitter::FitCurve(mPoints, startIndex, endIndex, 2.0);
  • mPoints is the Vec2f vector.
  • startIndex is the starting index of the points that you want to smooth out.
  • Likewise, endIndex is the index of the point that you want to smooth the points out to.
  • The last parameter refers to the error value, meaning how close to the points you want the curves to stick to. A greater number looks a bit more organic, but is less accurate.
  • What will be returned is a Path2d object that you can go on and draw immediately.

I took this as far as I could for the time being, but being a c++ and cinder noob, I’m open to any suggestions to make this better. Feel free to let me know where my c++ could be improved too.

My next entry will be a more detailed account of what I’ve learned to be able to drawn smooth lines on screen. So look out for that exciting post. Is that a cliffhanger or what?

  • http://amnonp5.wordpress.com/ Amnon Owed

    In january you wrote about making the jump from processing to cinder/c++. Now it’s a few months later and it seems you’ve settled in and made your first cinder block (congrats ;-) . Please consider writing a blog post about this first phase of learning cinder. What did you encounter? What did you need to learn? What resources did you use such as books, sites, etc.? Basically what can you share with others making the same transition. Thanks!

  • http://www.gregkepler.com Greg Kepler

    Thanks Amnon. It was quite a feat for me to get over the initial c++ learning hump. But it’s just the beginning. There’s so much more to learn.
    And thanks for that suggestion. I’ll be sure to write a post soon mentioning any helpful resources and any other tips that I can think of to help other people make this jump.