(I’m not sure under which category to post this, but I post it here since I am a OF newbie.
I am trying to do several polygon-related things with openFrameworks, which I haven’t been able to figure out how to do using the built-in tools in OF.
Basically, I use ofxOpenCv to track shapes in a video stream, and want to do graphical things to the resulting blob polygons.
First, I want to stroke polygons (draw a polygon outline) using thick lines. Since openFrameworks uses OpenGL to implement drawing this doesn’t really work since OpenGL doesn’t really support stroking polygons, it just draw each segment as a separate line with no joins. I know of several graphics libraries that implement this by creating a new polygon containing the stroked outline and then filling that polygon, but I haven’t been able to find any easily isolated code to do that. I think there is code to do this in the Antigrain graphics library for example, but it’s not easily extractable, at least not for me.
Does anyone have any hints on how to stroke polygons with thick lines using openFrameworks? Preferable with controllable joins (miter/bevel/round) and line caps (round/butt/projecting square).
See the attached image for a visual description of what I want.
Also, I want to do binary/set operations on polygons like intersection (clipping), union and subtraction. This is for several purposes. One is simply to clip drawing to a polygon (so that all drawing while the clipping is in effect will be intersected with the clipping polygon). I guess you could use OpenGL’s stencil buffer to do this? I also would like to do hit testing of polygons against other shapes.
I have found a polygon clipping library called the Generic Polygon Clipper library (http://www.cs.manchester.ac.uk/~toby/gpc/), which can do polygon intersection/union and subtraction. I have written a small OF add-on that wraps this library (let me know if anyone would like a copy). This basically solves this part of my problem, but the GPC library is only free for non-profit uses, which could be problematic for me in the future, so I would prefer to find another solution, if possible.
Finally, I would like to perform polygon offsetting operations (expanding/shrinking a polygon) and be able to find the straight skeleton of polygons. The boost polygon library can expand/shrink polygons, but doesn’t support floating point coordinates + it’s a big complex system. Then there is the Computational Geometry Algorithms Library (http://www.cgal.org/) which implements these kinds of things, but as far as I can tell, the parts of CGAL that I’m interested in is licensed using the QPL license, which seems very problematic for me to use. (As far as I can tell it’s a “viral” license that would require me to release the full source of anything I do using CGAL under the QPL license. Since I don’t own all the source code I use (like openFrameworks for example), I guess I can’t do this.)
I hope I managed to explain what I mean. Thanks in advance for any help!
/Jesper
