Concave hulls/contours with opencv? - image

Does opencv feature the capability of extracting concave hulls/contours from a set of 2D points?
Also, is there a possibility to extract all possible hulls satisfying a certain criterion; let say all hulls must have their areas bounded (min<area<max) ?

I would look at the excellent Point Cloud Library which (by its very nature) has to handle concave hulls in both 2D and 3D. As a library, it can integrate quite nicely with OpenCV (if that's what you need).
In particular, this example which show-cases the pcl::ConcaveHull class. The cropHull operation might prove useful, in response to your second question.
(Notice that in fact this is actually underpinned by the "grand-daddy" of hull libraries - qhull).

Related

CGAL - Is it possible to compute the NFP of polygons with holes

I'm considering to use the library CGAL for the calculation of the No-Fit Polygon (NFP). I've seen that the package of 2D Minkowski Sums in CGAL is a great tool for this. However, I would need to compute the NFP for very different types of polygons, and I'm not sure whether CGAL is going to cover my needs when polygons include holes. My doubts are motivated by the following statement found in their documentation website, in the Chapter 2D Minkowski Sums:
"(...)Applications of some of the operations in this package are restricted to polygons that do not contain holes. (Resulting sums may contain holes though.)"
Does anyone know which are those operations that are restricted to polygons without holes? Beyond that, I would appreciate any piece of advice from anybody who used CGAL to calculate the NFP for non-convex polygons. Thanks a lot.
As of release 4.9 of CGAL the "2D Minkowski Sum" package supports the construction of Minkowski sums of polygons with holes. This construction can be done with either the convex decomposition or the reduced-convolution methods. The latter is the default and the most efficient in most cases. We have retained all older methods, because they do exhibit better performance in some less frequent cases. You shouldn't have any problem computing the NFP of polygons with holes using the package.

Best nesting algorithm

I have spent time looking for information on the best algorithm to create a nesting of irregular polygons in 2D using manual and automatic positioning. I need to use such an algorithm in the context of CAD/CAM software. Here are the real possibilities I've found so far:
Separating Axis Theorem: is a fairly quick and simple algorithm to implement, but the drawback I find with it is that it only works with convex polygons. To work with concave polygons, a convex decomposition would need to be done first. This implies an increase in the run-time and the implementation of a new algorithm that decomposes the concave polygon into convex polygons.
Nesting by a power function: calculating the partial derivatives in the X and Y axes, you could get the escape direction you should take a polygon so that there is a collision between the two polygons. This function of energy and I tested and the three major problems that I have encountered are: first obtaining local minima , second nesting when the collision occurs over a piece and finally the execution time is very high.
Using no-fit polygon: use the no-fit polygon to the nesting can be somewhat interesting. I have read several papers on the subject although there are very few online documentation on it. Not sure if it can really be a useful choice. I still have several doubts on the details of this approach.
Any idea which of these algorithms to choose? Or if you know any other options that can be used? I'm a little confused :-) .
Thank you very much.

Remeshing algorithm

I need an algorithm to re-triangulate a given 3D solid object.
Input: A triangular mesh
Output: A new triangular mesh where the triangles - as far as possible - have equal edge lengths. Some tolerance is allowed.
Currently I reflect on a clustering algorithm in order to distribute points
equally over the surface. Then I could use a 2D Delaunay triangulation and
project the triangles to the surface. But this is just a vague idea, not an
algorithm. It would be great if somebody could suggest an algorithm or a
reference to related scientific work.
CGAL provides a surface meshing algorithm that can be used for remeshing.
The documentation page is here.
You can directly try it in the demo. On windows precompiled demo is available here. You'll also need the following dll's.
References to scientific publications are available on the aforementioned page.

What algorithms exist for finding a bounding surface to a set of points?

Suppose you have a point cloud, and you want a surface that wraps those points to enclose them all, and wrap them fairly tightly so it intersects with the outer points in the cloud - how do you generate this wrapped surface? That is, where some or many points may be inside the volume and so the surface does not need to intersect them, only enclose them, but the surface should be a good fit for the "outside" layer of points.
(I'm aware of triangulation algorithms (such as Delaunay) for fitting a mesh through - I think - all points in a set, but I don't think that algorithm will work unless there's a good way to discard all but the outer shell of points. Feel free to point out approaches I'm missing here, too!)
What algorithms (or even search keywords beyond "mesh", "fit", "wrap" "point cloud" etc) should I look for?
I think that you're looking for a convex hull algorithm. The convex hull is the shape you get if you were to wrap a set of points in some sort of wrapping paper, leaving the outermost boundary. I may be misinterpreting your question, but this sounds like exactly what you're looking for.
Hope this helps!
I think, what you are searching for is a convex hull.
For algorithms to compute it, take a look here.
You can use TetGen to compute the convex hull or, if needed, a surface triangulation in the case your point set is not convex.
I am not sure this is useful to you, Mathematica has a TetGenLink interface to TetGen.

Mesh to mesh intersections

I'm looking for a library or a paper that describes how to determine if one triangular mesh intersects another.
Interestingly I am coming up empty. If there is some way to do it in CGAL, it is eluding me.
It seems like it clearly should be possible, because triangle intersection is possible and because each mesh contains a finite number of triangles. But I assume there must be a better way to do it than the obvious O(n*m) approach where one mesh has n triangles and the other has m triangles.
The way we usually do it using CGAL is with CGAL::box_intersection_d.
You can make it by mixing this example with this one.
EDIT:
Since CGAL 4.12 there is now the function CGAL::Polygon_mesh_processing::do_intersect().
The book Real-Time Collision Detection has some good suggestions for implementing such algorithms. The basic approach is to use spatial partitioning or bounding volumes to reduce the number of tri-tri intersection tests that you need to perform.
There are a number of good academic packages that address this problem including the Proximity Query Package, and the other work of the GAMMA research group at University of North Carolina, SWIFT, I-COLLIDE, and RAPID are all well known. Check that the licenses on these libraries are acceptable.
The Open Dynamics Engine (ODE), is a physics engine that contains optimized implementations of a large number of intersection primitives. You can check out the documentation for the triangle-triangle intersection test on their wiki.
While it isn't exactly what you're looking for, I believe that this is also possible with CGAL - Tree of Triangles, for Intersection and Distance Queries
I think the search term you are missing is overlay. For example, here is a web page on Surface Mesh Overlay. That site has a short bibliography, all by the same authors.
Here is another paper on the topic: "Overlay mesh construction using interleaved spanning trees,"
INFOCOM 2004: Twenty-third Annual Joint Conference of the IEEE Computer and Communications Societies.
See also the GIS SE question, "Performing Overlay of Two Triangulated Irregular Networks (TIN)."
To add to the other answers, there are also techniques involving the 3D Minkowski sum of convex polyhedra - concave polyhedra can be decomposed into convex parts. Check out this.
In libigl, we wrap up cgal's CGAL::box_intersection_dto intersect a mesh with vertices V and faces F with another mesh with vertices U and faces G, storing pairs of intersecting facets as rows in IF:
igl::intersect_other(V,F,U,G,false,IF);
This will ignore self-intersections. For completeness, I'll mention that we also support self-intersections in a separate function:
igl::self_intersect(V,F,...,IF);
One of the approaches is to construct a bounding volume hierarchy BVH (e.g. AABB-tree) for each mesh.
Then one will need to find whether there is a pair of intersecting triangles from two meshes, and it will be much faster (at best logarithmic time complexity) using constructed hierarchies than checking every possible pair of triangles from two meshes.
For example, you can look at open-source library MeshLib where this algorithm is implemented in findCollidingTriangles function, which must be called with firstIntersectionOnly=true argument to find just the fact of collision instead of all colliding triangle pairs.

Resources