Vector shape rasterization in C++ - c++

I am looking for an efficient algorithm or library capable of rasterizing 2d shape defined by a set of lines and curves. So far, what I found do the reverse from what I need ,others are overkill (ImageMagic ,Cairo) .I am interested in a compact utility. Anyone can point out to the right direction?

Rasterization of 2d shapes is not a trivial matter, especially if it includes Bézier curves. Here are some libraries you may want to try:
Cairo
skia
Anti-Grain Geometry, also here
Poppler
mupdf
Ghostscript
libxmi (does not handle Bézier curves)
See also
Good SVG renderer for Linux?

You're looking for "vectorization," and you can find quite a bit of it around by googling:
potrace is probably what you want:
http://potrace.sourceforge.net/
http://en.wikipedia.org/wiki/Vectorization_(image_tracing)
http://autotrace.sourceforge.net/
http://inkscape.org/

Related

Library on simplifying a tetrahedral mesh

I am wondering whether there is any existing library or software which is on tetrahedral mesh simplification and written in C/C++. You may know that there is a famous algorithm on triangular mesh based on Quadric Error Metrics, called Surface Simplification Using Quadric Error Metrics. I reckon there should be something similar but applied to tetrahedral mesh. Thanks!
You should probably search in CGAL library CGAL. Its the best for computational geometry algorithms. I am sure that someone should have already implemented mesh simplification in CGAL.
The closest I can find to what you are looking for exists here it allows tetrahedral volumetric rendering.
Not sure if this is what you are looking for, as the original question and the comments seem to differ slightly in the end aim.
Let me know if you need any further info:)

Using mesh gradients in Cairo for coloring a path

I'm a newbie in this type of approach to programming since I really doesn't care for hardcore graphics generation. I design, write, run, and study parametrized climate models with python. But, at last, I have encountered myself with a visualization issue.
I was looking for something in Cairo library that allows me to map a linear gradient onto an arbitrary curve (not necessarily a circumference) such that there is a more or less smooth variation of colour (or shade) across my path. Then I have been looking for some pattern and I finally found that maybe mesh gradients in Cairo are the solution.
However, I can't create a new mesh gradient from my python script with cairo.pattern_create_mesh()!
Therefore, my questions are: How I use mesh gradients in Cairo? Is there any other simple way to do what I want with Cairo (I don't know, like a simple mapping from a line segment to a curve via parametrization, I know I ask too much)?
Mesh patterns were added in cairo 1.12 which is the latest release. Thus, most language bindings likely don't support them yet. I don't know anything about the combination of python and cairo and thus don't know any workaround.
I don't know any simple way to simulate what you need with other patterns, sorry. (Although I am not really sure how you want to do your mapping via mesh gradients either...)

C++: Creating Polygons from images' transparency

Alright guys..
I'm at a loss here. I've been trying to code an image to polygon converter to no avail, it's really bugging me. It's supposed to create a polygon from the transparency of an image (the non transparent part is the polygon). I've seen programs that do it, but they were closed-source and really expensive. It's not just edge-detection, it's polygon generalization and hole-detection as well, all this in a Box2D compatible, triangulated polygon.
Please hand me some tips on this, or a library name, or an algorithm or something..
Thanks!
I suggest looking at the openCV library. It has several useful algorithms and tools for
image processing. I think you can accomplish your goal with it.
Good luck.

Draw an anti aliased rounded rectangle in c++

As written in the title, i would like to draw anti aliased rounded rectangles in c++ and in a linux context (ubuntu). I already tried SDL_gfx but anti aliasing is not available on roundedBox shapes. I also read about SDL_Draw but I think it does neither provide anti aliasing.
That's why I am asking if anybody knows a framework providing this kind of shapes or if anybody knows a (light) anti aliasing algorithm (I need this for real time video processing).
Thank you Vjo, but I don't really want to use openGL in my soft ... And by the way, I think I figured out another way to draw anti aliased rounded rectangles !
What I did not explain in the first post is that i am already using SDL and opencv in my program. So I had an idea :
draw a 1 channel rounded rectangle with SDL_gfx
smooth it with cvSmooth to get the antialiasing alpha
use the result as the alpha channel of a simple rectangle
What do you think about that ? I'll try it this evening !
The only parts of the shape that need to be antialiased are the corners. draw four antialiased quater circles, one at each corner (Xiaolin Wu's circle algrithm is your best bet here), and bridge the gaps with simple lines. If the shapes will not be rotated (that is, all straight lines will be either vertical or horizontal, use Bresenham's non-antialiased line algorithm, otherwise use Wu's line algorithm. Wu's antialiasing algorithms are typically the fastest and give very good results.
If you really want to optimize your result, and are familiar with x86 assembly programming, I suggest writing the drawing routines using inline assembly language. Properly tuned, wu's line algorithm can be written in as few as 15 instructions, and his circle algorithm around 40-50 instructions.

OpenGL rotating textured planes in 3D space

I'm wondering if anyone could point me to any resources that would deal in rotating one or several 2D textured planes in 3D space. Something like this but with openGL (preferably C++):
I'm attempting to do pretty much the exact same thing but no matter how I order my operations I'm getting right-screwy results. So I figure asking for some resources on the subject is better than posting tons of code and asking for people to fix my problems for me. :)
If you havent already, do a search for 'NeHe tutorials'. An excellent set of OpenGL tutorials.
Here is a link to the rotation tutorial, includes all the source code in downloadable format and the tutorial walks you through each relevant line.
http://nehe.gamedev.net/tutorial/rotation/14001/
I believe this is working in a 2D space, the step up to 3D probably involves a bit more matrix math but...doable
The NeHe tutorials are a very popular place to learn the basics of OpenGL. In particular, the tutorial about texture mapping should help you:
http://nehe.gamedev.net/tutorial/texture_mapping/12038/
Mind you though that these tutorials are written for older OpenGL versions which are more beginner friendly IMHO.
You should look into scene graphs. Basically it is a way to define a bunch of objects (2D textured planes) and their transforms in 3D space. This allows you to define transforms that work on multiple nodes (objects) as well as single nodes. You can make a pretty simple one in C++ with little effort, or use one such as OpenSG or OSG (slight learning curve needed).
Wikipedia - http://en.wikipedia.org/wiki/Scene_graph