Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
CGAL seems to do just about everything I need and a little more for my upcoming project. It can create polygons out of arc line segments and run boolean operations on them. It has spatial sorting packages already that would save me a lot of time regarding a few things and the whole library seems quite standardized and well planned.
There's just the issue with the license being QPL (GPL for the upcoming version 4.0) for most of the packages (except the very basic ones). I've got a meager budget and can likely not gather funds to buy the commercial licenses for those specific packages in CGAL that require it.
My specific needs of such a library would be:
Exact precision 2D euclidean space
Complex polygons
Polygons able to have curved line (arc) segments
Boolean operations on those polygons
Polygon offsetting
Polygon partitioning or effective triangulation
Inscribed area and polygon fitting algorithms
Possibly some spatial sorting structures with circular range searches
All in all, I'm looking for a well rounded 2D geometry C++ library with exact precision.
Preferably with MIT, LGPL at a stretch, or a low cost one-time royalty-free license below $500.
Boost got some basic structures down, but from what I can tell they lack a lot of the higher level functionality. Any libraries that has expanded on this? I would consider doing it myself, but I lack the expertise to do it well and it'd prolong my project by quite a bit.
Just to be clear, I'm not looking for a 2D graphics library, just pure geometry structures.
Have a look at Wykobi.
It is a templated library and you can template the dimension as 2D.
It is distributed under the MIT License.
Take a look at Geometric Tools for Computer Graphics.
Refined over a decade
Unbelievably good documentation, both in hard bound and extensively in PDF form
Boost license
It meets all your requirements:
Exact precision 2D euclidean space: Yes
Complex polygons : Yes
Polygons able to have curved line (arc) segments : Nonsensical. By
definition, polygons are composed of line segments. If you are
looking for splines and NURBS, the library has them.
Boolean operations on those polygons : Yes
Polygon offsetting : Unclear what you mean. The library certainly supports translation.
Polygon partitioning or effective triangulation: Yes, Delaunay triangulation
and Voronoi regions
Inscribed area and polygon fitting algorithms :Yes
Possibly some spatial sorting structures with circular range searches : Yes, spatial sorting and a whole bushel of intersection functions.
All this comes from the book Geomtric Tools for Computer Graphics by Schneider and Eberly. The book is outstanding, with clear presentation of how the algorithms work and what their limitations are. The authors have made the code available online under the Boost license and include most (all?) of the book online as a PDF to accompany each code module. They maintain an very useful website that is indexed in various ways.
I have no connection to the authors nor any monetary interest. I used their book in my thesis and it was extremely pleased with it as an easy to use reference and a powerful library.
Have you looked at Boost.Geometry library? It's nowhere near CGAL in terms of functionality, but it might help you.
You could try GeoLib www.geolib.co.uk. Not as much functionality but does offer boolean operations and is very easy to use.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I've recently encountered a need for a library or set of libraries to handle operations on 2D polygons. I need to be able to perform boolean/clipping operations (difference and union) and triangulation.
So far the libraries I've found are poly2tri, CGAL, and GPC. Poly2tri looks good for triangulation but I'm still left with boolean operations, and I'm unsure about its maturity.
CGAL and GPC are only free if my own project is free. My particular project isn't commercial, so I'm hesitant to pay or request for any licenses. But I may want to use my code for a future commercial project, so I'm hesitant about CGAL's open source licenses and GPC's freeware-only restriction. There doesn't seem to be any polygon clipping libraries with nice BSD-style licenses.
Oh, and C/C++ is preferred.
Clipper is an open source freeware polygon clipping library (written in Delphi and C++)^ that does exactly what you're asking (except for triangulation) - http://sourceforge.net/projects/polyclipping/
In my testing, Clipper is both significantly faster and far less prone to error than GPC (see more detailed comparisons here - http://www.angusj.com/delphi/clipper.php#features).
Re: Anti-grain Geometry (AGG) graphics library - it doesn't do polygon clipping, but simply uses GPC (which isn't free for commercial applications). However, Clipper does have AGG units to make clipping in AGG just as easy as GPC.
^ Edit: Clipper is now written in C# too (together with Perl, Ruby, Haskell and Flash modules written by third-parties).
PolygonLib is a new polygon clipping library written in С++ and already used in two projects. It is numerically robust, uses double coordinates, and is optimized for polygons with large numbers of vertices. See http://www.ulybin.de/products/polygonlib.php?lang=en for more details and comparison of performance and memory utilization with GPC and PolyBoolean.
The restricted evaluation version of the library is free for not commercial use and supports the operations you need (except for triangulation).
How about boost? http://www.boost.org/doc/libs/1_47_0/libs/polygon/doc/index.htm
If you're fine with the heavy use of generics in the interface, I suspect this will serve your purposes well. I'm not sure if it contains triangulation, but you can implement one of the many available triangulation algorithms if it does not.
Check out Liszt a Scala DSL
http://www.antigrain.com/license/index.html is the closest I can find, you may have to spend a buck if it does go commercial, but you can use it for free for now, and get consent later on.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I have the need to replicate GPU tessellation on the CPU (ie get the same uvw coordinates on the CPU side as I will get on the GPU from the tessellator).
The reason for this is rather complicated, but simply put I have an algorithm that stores data per tessellation point, and to calculate it in the first place I need the uvw coordinates on the CPU.
I have googled a lot for the exact details of the tessellation pattern, but I only find very vague texts speaking about it in a general nature, the best one being this one: http://fgiesen.wordpress.com/2011/09/06/a-trip-through-the-graphics-pipeline-2011-part-12/
Is the reason for the lack of texts on this that it's vendor dependent, or have I simply not found the not found the right page?
I'm interested in texts both on the OpenGL and DX11 implementation, if they differ.
I was also very interested by tessellation, and specifically subdivision surfaces some time ago. This is a very complicated topic. It was researched from early 70th and it's still in research.
It isn't clear if you want to re-implement whole shader tessellation pipeline (which I think will take years for a single programmer) or just a single subdivision algorithm (or even algorith that isn't subdivision).
Anyway, there is some links about subdivision:
Theory
Typically we implement subdivision surfaces in tessellation shaders using Catmull–Clark subdivision surface algorithm. You can find some papers from original authors in Google. There is main one:
"Recursively generated B-spline surfaces on arbitrary topological meshes" (year 1978, PDF)
Closer to code
Check papers of those cool guys from Microsoft Research:
Charles Loop - (BTW, author of another subdiv algorithm), purely mathematical stuff
Hugues Hoppe - Look for "progressive meshes", much more close to software
Even more closer to code.
You can find some libraries on the web. When I searched a while ago, there was a dozen of libs, that implemented subdivision on CPU. I didn't look they much, because I was interested in GPU implementation. The keyword for search is "subdivision lib" =)
The most interesting one is Pixar's OpenSubdiv. Take a look at their code.
Also look at "NVIDIA Instanced Tessellation" Sample (DirectX, OpenGL). They've implemented tessellation pipelne in Vertex and Geometry shaders.
Hope it helps!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I am a developer of the open-source game, Bitfighter. As per the following SO post, we have used the excellent 'Triangle' library for mesh-zone generation for use with our in-game AI (robots):
Polygon Triangulation with Holes
However, we ran into a small snag when wanting to package our game for Debian - the use of the 'Triangle' library will make our game be considered as 'non-free'.
We have been extremely pleased with the performance of the 'Triangle' library, and don't really want to give it up; however, we don't like dealing with license issues either. Therefore we have embarked upon a quest to find a suitable, permissively-licensed replacement that can match 'Triangle' in its robustness and speed.
We're looking for a C or C++ library for dividing large, complex, areas into triangles, that can handle any type of irregular polygons placed together in any manner, as well as holes. Robustness is our primary need, with speed almost as important.
I have found poly2tri, but it suffers from a bug in which it cannot handle polygons with coincident edges.
We have found several libraries, but all seem to suffer from one thing or another: either too slow, or don't handle holes, or suffer from some bug. Currently we are testing out polypartition and we have high hopes.
What are the best alternatives to the great 'Triangle' library, but have a permissive license?
I found a solution. It was poly2tri after all, with the use of the excellent Clipper library, and some minor algorithmic additions to the inputs.
Our process is as follows:
Run all our holes through Clipper using a union with NonZero winding (this means that inner holes are wound the opposite direction as outer ones). Clipper also guarantees nice clean input points with no repeats within epsilon.
Filter our holes into ones that are wound counter-clockwise and clockwise. Clockwise holes meant the hole was circuitous and that there was another concentric area inside that needed to be triangulated
Using poly2tri, triangulate the outer bounds and each clockwise polygon found, using the rest of the holes as inputs to poly2tri if they were found within one of the bounds.
Result: poly2tri seems to triangulate just about as fast as Triangle and has so far been very robust with everything we've thrown at it.
For those interested, here are our code changes.
Update
I have attempted to pull out our clipper-to-poly2tri code, with our robustness additions, into a separate library which I started here: clip2tri
You can have a look at the 2D Triangulations package of CGAL. An example to triangulate a polygon with holes is given here.
The license of the package is GPLv3+.
Note that it should not be too hard to extract only this package if needed.
As a small side-note:
I recently had to implement a complex polygon clipper & triangulator for cutting window frames into house walls.
While I was happy with the Vatti clipper results, the Delaunay triangulation used in poly2tri was too heavy to allow smooth dragging of the window frame along the barycentric coordinates of the wall face. After scratching my head a little bit, I ended up tricking this much simpler triangular to work with holes:
http://wiki.unity3d.com/index.php?title=Triangulator
What I did was horizontally subdivide the wall face by the height of the shortest clipping poly. In my case they are always rectangles, but they needn't be. Anyway, it forces the clipper to only work with regular or concave polys, and hence enables you to get away with a cheaper triangulation method.
Here are some screenshots showing it working:
https://www.dropbox.com/sh/zbzpvlkwj8b9gl3/sIBYCqa8ak
Hope this helps.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What are some recommended frameworks for manipulating spatial data in C++?
I'm looking for a polygon object, point object, and some operations like union, intersection, distance, and area. I need to enter coordinates in WGS84 (lon,lat) and get area in square km.
I would prefer a free/open source framework, but am open to suggestions.
Edit: Unfortunately I need a non-GPL solution. LGPL is alright.
GEOS is an open source (LGPL) C++ geometry / topology engine. Might suit you?
Useful places to look for this stuff are this useful article on the O'Reilly website and also OSGeo which is a collaboration to support open source geospatial stuff.
I also recommend Generic Geometry Library which recently has been reviewed and eventually accepted to the collection of Boost C++ Libraries. As included in Boost, the GGL is now called Boost.Geometry, more precisely Boost.Geometry aka GGL, Generic Geometry Library.
Other useful tools
ORFEO Toolbox (aka OTB) - a library of image processing algorithm
MetaCRS - a project encompassing several projections, and coordinate system related technologies.
libgeotiff for sole GeoTIFF manipulation
The CGAL Open Source Project
provides easy access to efficient and
reliable geometric algorithms in the
form of a C++ library. CGAL is used
in various areas needing geometric
computation, such as: computer
graphics, scientific visualization,
computer aided design and modeling,
geographic information systems,
molecular biology, medical imaging,
robotics and motion planning, mesh
generation, numerical methods.
The Generic Geometry Library (geometrylibrary.geodan.nl, currently in "preview 4") provides a generic implementation of geometry algorithms, working with user-defined geometries. The algorithms include some well-known and often needed algorithms as point-in-polygon, polygon area, point-to-point distance, point-to-line distance, line clipping and polygon clipping, convex hulls. It also contains transformation algorithms, map projections and selection algorithms. Besides algorithms the library provides geometry classes which might be used, but the generic algorithms do not depend on them. (Proposed to be included in Boost)
GEOS for the Geometry model, and GDAL/OGR for a spatial data abstraction library which supports Rasters and Vectors.
By using these libraries, you will also be able to handle different coordinate systems (like transforming from/to WGS84) since both of them use Proj.4 under the hood. To find distances in meters you can transform from WGS84 to something that uses meters like UTM.
Depending on how complex these calculations are going to be you might want to consider writing your own. If you are just doing area that might be your best option for speed and lack of bloat.
otherwise the Geographic Foundation Class (GFC) library is your best bet.
It's not comprehensive and high-level enough for what you asked, but for doing geodetic transforms you can use the NGA's excellent GEOTRANS library:
http://earth-info.nga.mil/GandG/geotrans/
That will let you convert between things like WGS84 lat/long and a local cartesian coordinate system. The C code is well tested, documented, and is public domain.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm interested in creating a game that uses fractal maps for more realistic geography. However, the only fractal map programs I have found are Windows-only, for example Fractal Mapper. Needless to say, they are also not open-sourced.
Are there any open-sourced fractal map creators available, preferably in Python or C/C++? Ideally I would like something that can be "plugged into" a program, rather then being standalone.
Fracplanet may be of use.
Basic terrain generation involves creating a height map (an image) and rendering it using the pixel colour as height. So you may find image or texture generation code useful. This is a good tutorial.
For the terrain aspect take a look at libnoise.
It's packaged for Debian, and has excellent documentation with a chapter on terrain generation with example C++ code.
Of course there's a lot more to "maps" than slapping some colours on a height field (for example Fracplanet adds rivers and lakes). And the sort of terrain you get from these methods isn't actually that realistic; continents don't generally ramp up from the coast into a rocky hinterland, so maybe simulating continental drift and mountain building and erosion processes would help (alternatively, fake it). And then if you want vegetation, or the artefacts of lifeforms (roads and towns, say) to populate your map you might want to look at cellular automata or other "artificial life" tools. Finally, the Virtual Terrain Project is well worth a browse for more links and ideas.
I'd highly recommend purchasing a copy of
Texturing & Modeling: A Procedural Approach
I see it's now in it's third edition (I only have the second) but it's packed full of useful articles about the use of procedural texturing including several chapters on their use in fractal terrains. It starts out with extensive discussion of noise algorithms too - so you have everything from the basics upwards. The authors include Musgrave, Perlin and Worley, so you really can't do better.
If you want truely realistic geography, you could use NASA's SRTM dataset, perhaps combined with OpenStreetMap features. :-)
A very simple implementation would be to use the midpoint displacement fractal, http://en.wikipedia.org/wiki/Diamond-square_algorithm, or the somewhat more complicated Diamond-Squares algorithm.
http://www.gameprogrammer.com/fractal.html#diamond
These are similar algorithms to the "Difference cloud" in Photoshop.