Related Question:
An algorithm for inflating/deflating (offsetting, buffering) polygons
The difference is that I'm searching for a way to inflate a given polyline into a polygon:
I've got the following input:
List of 2D Points which form the polyline (bright green in the sketch)
Width of the line
The output should be a polygon which shows how the line looks expanded by the width.
I originally thought I could use Boost::Geometry::buffer for that, unfortunately it just seems to support boxes for now. A solution using Boost::Geometry or GDAL/OGR would be preffered.
UPDATE:
I chose to use the Clipper Library and its OffsetPolyLines function. As soon as Boost Geometry is released with Polyline-Buffer support I'll switch to Boost (as everything else runs with Boost in my software).
I understand that the OP was preferring a solution in Boost::Geometry or GDAL/OGR but, in case others are following this thread, my Clipper library can also do polyline offsetting. (The soon to be released version 6 that's already in the SourceForge repository simplifies this and it now supports open path (polyline) clipping too.)
Boost.Geometry extension (from Trunk) can do this. It is not yet released. It can buffer around polygons, polygons, points, and multi-geometries. You can specify sharp corners (miter) or rounded corners. It is not yet perfect, but lines as your sample above should not give any problems.
The released version (1.54) does not have this yet, and also the next one will not have it yet. So for now you have to use the Trunk (from SVN)
Related
This is my terminal(result) after running the .exe file. Click the link for the terminal.
It doesn't stop or gives an error. It's stuck like this for hours.
I got my code from here code, but this is the data (.off) I used.
You are probably trying to fill a hole that is too large or that cannot be filled using the 3D Delaunay triangulation search space (which can happen also if you have pinched holes). In CGAL 5.5 (not yet released but available in master), we added the option do_not_use_cubic_algorithm() (doc here) to not use the cubic search space to fill such holes.
I used PCL (Point-cloud library) to triangulate a 3D point cloud. But the triangulation I got is not consistent. I get a similar situation as at question: How to unify normal orientation.
But this code does not work well, I can't compile it. I get an exception within a function call:
vcg::tri::UpdateNormal<MyMesh>::PerFace(m)
Beside,VCG has been updated to a newer edition, and the original author edited the source code, so it won't work now.
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/
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...)
I am currently attempting to use OpenCV 2.3 and c++ to detect a hand (wearing a green glove), and distinguish between different hand gestures.
At this very moment, my next step is to acquire specific features of the hand (convex defects).
So far I've used these functions in my process:
mixChannels(); //to subtract non-green channels from green.
threshold(); //to convert to binary
erode(); dialate(); //to get rid of any excess noise
findContours(); //to find contours of course
these have worked splendidly and I have been able to output findContours() through the use of drawContours().
Next step, and this is where I'm at, is using convexHull(), which also works in OpenCV 2.3. I have however yet to find out how the vector results of convexHull() actually look (what features they contains).
But this is where the tricky part comes.
I found that the older version of OpenCV (using c which uses IplImage), has a neat little function called cvConvexityDefects() which can give a set of deficiencies on the convex hull. These are what I need, but there seems to be no such function for the OpenCV 2.3 and I don't see how I can use the old syntax to get these results.
Here's a link to Open CV documentation on cvConvextDefects.
What I'm asking for, is either a similar OpenCV 2.3 function, or a selfwritten piece of code or algorithm for finding these defects. Or a method to use the old 2.1 syntax for a vector result or something like that.
(I know that I can use other features, rectangular bounding boxes, and fitted circles. But I'm sure that convex defects yield the most distinguishable features.)
Solution - I ended up using a c++ wrapper from this post
The only thing not working for this wrapper seems to be a leek of the defects vector, which should be easily solvable.
Next step is getting some usable data from these defects. (At first glance. the data seems to be single points on the convexHull or the Contour or the count of these. I had at first expected a set of two points, or a single point and a length, which it does not seem to be. If I'm hitting 'brick wall' with this, I'll make another post)
The new C++ interface does not (yet) support all the functions in C. And the opposite is true, also (not everything in cpp is in c). The reasons are various, but the good news is that you can easily use whatever function you want. By example, here you have to convert contours to sequences (CvSeq) and send them to your function.
Moreover, the FindContours method is a wrapper over cvFindContours. You can call it
cvFindContours((IplImage*)matImage, ...);
and then use directly the result.
Another way would be to create a nice, clean C++ wrapper over cvConvexDefects() and submit it to OpenCV. In the findContours source you will find some help for that (the opposite transform)
I would like to attempt to convert my convexHull vector from the c++ syntax to the sequence which you mentioned, but I don't know where to start. Could you perhaps shed some light on this?
Check out this question here, I beleive it goes into it.
Convexity defects C++ OpenCv