CGAL versus VTK - vtk

What is the difference between the CGAL and the VTK libraries? Both incorporate a lot of the standard geometric algorithms. Can anyone list some application domains where the one is preferred over the other?

VTK is mostly targeted toward visualization (frontend). It includes some computational geometry functions out of convenience (e.g. Delaunay triangulation). It would be better suited for viewing MRI scans, visualizing large data sets, or converting point clouds / meshes from one format to another for example.
CGAL is targeted toward computational geometry (backend). It will require some type of frontend (e.g. OpenGL, VTK) to view the result. It would be better suited for molecular biology, astronomy, architectural design backends for example.

Among other differences license should be mentioned. VTK is licensed under BSD and could be used in commercial products for free. While CGAL is dual licensed under GPLv3 (most of it) and commercial license. And to use it in commercial products you should purchase commercial license or publish your sources under GPLv3 (unlikely way for commercial products).

VTK is good for scientific visualization (plotting values onto a mesh with a given colour scale), and all that goes with it (axes, filters and so on), it has quite a few tools for mesh processing and other things which paraview gives a front end to, if you want to experiment. It's no good for textures, dynamic meshes, particles and all manner of other game/VR related technologies.

Related

Which CAD / geometry library should I use: CGAL Open CASCADE or Boost::Geometry something else?

For a customizable laser-cut drawers project I would like to be able to create the connection between any two intersecting perpendicular "2D" objects (with width) programmatically. For this I need to:
load and save 2D objects in some standard format.
extrude 2D object, and make the standard manipulations on 2D objects (specifically subtraction of objects.)
intersect 2 object, and be able to determine the "line" of intersection.
Which library/tool you would suggest for that? Can you estimate how difficult it would be to master it to do the above tasks?
Thanks,
Ronen
I'm biased ( PythonOCC dev ), but I'd say OpenCasCade would best fit your needs. Its comes wit Step and Iges importers out of the box ( more formats are supported commercially ), where you'd have to parse and reconstruct the geometry from a file with Boost and CGAL. Finally, neither of those packages deal with nurbs / CAD geometry ( BRep, boundary representation ) but merely triangles ( polygon soup ). So, OCC fits the scope best IMHO.
I have experience with OPENCASCADE and CGAL . Boost Geometry is very limited / simple and does not provider support for topological structures , solids , brep etc. The purpose has been quite different from the rest. Certainly, its quality is higher than any of the other two.
Opencascade among the three is least preferable choice in terms of quality. For example, everything is defined in global namespace, there are multiple macro definitions on header files, and has bloated classes. It has quite some support for various algorithms and constructs but only up to some point; for the rest you have to pay. These are somehow understandable, since it has been developed as an in-house library not for public access, and therefore they did not care about such things. The community is quite small, therefore you will have to go searching through the documentation a lot and experiment on how to do things. Usually, there are more than one way to work, and it is common to write many adaptors in your code to interface between different algorithms.
On the other hand CGAL is quite the opposite, has support for almost anything you can imagine, it is quite modern, and there is dedicated community along with very good documentation and examples for most use cases. There are different classes and algorithms depending on trade-off of the problem at hand. There is support for different UI (WIN/QT) and it interfaces well with STL / BOOST containers structures. Comparing to opencascade that does not even have a proper STL compatible iterator class, that is a significant difference.
Therefore, I would strongly suggest to work with CGAL.
In case you are forced to work with OPENCASCADE and want to use CGAL at the same time you will probably have to include header files such that Handle macro is undefed e.g.
#include <TopoDS_Shape.h>
#undef Handle
#include <CGAL/Alpha_shape_3.h>
#define Handle(ClassName) Handle_##ClassName

Programming a 3d game without the use of a graphics API

As the title says, I'd like to program a 3d game (probably a BattleZone clone), but without the use of an API like OpenGL, DirectX, and the like. At the heart of the matter, I'd just like to learn how to draw basic 3d shapes to the screen and manipulate them. Don't care if it looks like crap. I've used OpenGL to achieve similar ends before, but really didn't learn about these topics.
The problem is, I have no idea where to start. I downloaded the Doom source code, but it's a bit over my head. Although I've programmed a bit, graphical matters are very much out of my depth.
I'd be very grateful if anyone could offer links or code (in any language) that would help me along in my purpose.
Sounds like an exciting project. I did something similar in the late 90's. Before OpenGL and DirectX became popular, there were a ton of great books on the subject.
Fundamentally you will have to learn how to
Represent 3D geometry
Transform that geometry (translate and rotate)
Project that geometry onto a 2D screen.
Each of those major topics has many sub-topics (for example, complex objects can be constructed from a number of polygons. You may want to limit polygons to being constructed of triangles only, or support other polygons. You may want to load common model formats e.g. .obj files so that you can create models with off the shelf tools).
The topics are way too broad for a detailed answer here. Whole books are written on the subject, including
Black Art of 3D Game Programming (Book, amazingly still available)
For a good introduction to the general topics, have a look at:
http://en.wikipedia.org/wiki/3D_projection
http://en.wikipedia.org/wiki/Orthographic_projection
http://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection
Doom, which you already looked at, used a special optimization called heightfield rendering and does not allow for rendering of arbitrary 3D shapes (e.g., you will not find a bridge in Doom that you can walk under).
I have the second edition of Computer Graphics: Principles and Practice in C and it uses SRGP (Simple Raster Graphics Programming) and SIGGRAPH which is a wrap-around SRGP, if you look up articles and papers on graphics research you'll see that both these libraries are used a lot, and they are way more direct and low level than the APIs you mentioned. I'm having a hard time locating them, so if you do, please give a link. Note that the third edition is in WPF, so I cannot guarantee much as to it's usefulness, and I don't know if the second edition is still in print, but I have found numerous references to the book, and it's got it's own page in Wikipedia.
Another solution would be the Win32 API which again does not provide much in terms of rendering, but it is trivial to draw dots and lines onto a window. I have written a few tutorials on it, but I didn't cover drawing pixels and lines, so they'll only be useful if you have trouble with the basics of setting up a window. Note that it is not intended for real-time rendering, so it may get slow.
Finally you can look at X11 programming, the foundation of most modern operating systems with a GUI. I haven't found the libraries for Windows, but again I didn't invest too much time on it. I know it is available for CIGWIN and for Linux in general though, and I believe it would be very interesting to look at the core of graphics since you're already looking under the hood of 3D graphics.

real-time water effects without shaders

Im looking for a way to render decent-looking water on non-PC based hardware.
The platform has following limitations:
absence of hw shaders
absence of hw z-buffer
Available primitives are:
gouraud shaded triangles (with alpha)
textured triangles (with alpha)
Effects that are wanted:
transparency
caustics
small waves/ripples
refraction
Ideas I came up with:
animated/semi-transparent texture
bump-map/normal map
reflections by projecting world on X-Z plane
Before I actually go off prototyping some of these points, I wanted to see if anyone else has had similar experience, better suggestions, links to code samples, etc.
There are a variety of tricks that used to be used on old fixed function 3D hardware on the PC. Does your hardware support fixed function environment mapping? Multi-texturing and programmable blend stages? With just single texturing and no support for more complicated fixed function effects your options are limited but pre-shader hardware with slightly more sophisticated fixed function pipelines gives you quite a few possibilities. Fixed function environment mapping can be used to get some nice basic water effects for example.
NVIDIA's developer site used to be a good resource for all kinds of effects on old fixed function hardware but many of those articles don't seem to be available any more. You might be able to track some of them down by looking at old versions of the site from the Internet Archive. Other places to look for ideas are old GDC presentations and old articles on Gamasutra.com as well as some of the older Game Programming Gems books.

How Scanline based 2d rendering engines works?

Will you please provide me a reference to help me understand how scanline based rendering engines works?
I want to implement a 2D rendering engine which can support region-based clipping, basic shape drawing and filling with anti aliasing, and basic transformations (Perspective, Rotation, Scaling). I need algorithms which give priority to performance rather than quality because I want to implement it for embedded systems with no fpu.
I'm probably showing my age, but I still love my copy of Foley, Feiner, van Dam, and Hughes (The White Book).
Jim Blinn had a great column that's available as a book called Jim Blinn's Corner: A Trip Down the Graphics Pipeline.
Both of these are quited dated now, and aside from the principles of 3D geometry, they're not very useful for programming today's powerful pixel pushers.
OTOH, they're probably just perfect for an embedded environment with no GPU or FPU!
Here is a good series of articles by Chris Hecker that covers software rasterization:
http://chrishecker.com/Miscellaneous_Technical_Articles
And here is a site that talks about and includes code for a software rasterizer. It was written for a system that does not have an FPU (the GP2X) and includes source for a fixed point math library.
http://www.trenki.net
I'm not sure about the rest, but I can help you with fast scaling and 2D rotation for ARM (written in assembly language). Check out a demo:
http://www.modaco.com/content/smartphone-software-games/291993/bbgfx-2d-graphics-library-beta/
L.B.

Polygon Triangulation with Holes

I am looking for an algorithm or library (better) to break down a polygon into triangles. I will be using these triangles in a Direct3D application. What are the best available options?
Here is what I have found so far:
Ben Discoe's notes
FIST: Fast Industrial-Strength Triangulation of Polygons
I know that CGAL provides triangulation but am not sure if it supports holes.
I would really appreciate some opinions from people with prior experience in this area.
Edit: This is a 2D polygon.
To give you some more choices of libraries out there:
Polyboolean. I never tried this one, but it looks promising: http://www.complex-a5.ru/polyboolean/index.html
General Polygon Clipper. This one works very well in practice and does triangulation as well as clipping and holes holes: http://www.cs.man.ac.uk/~toby/alan/software/
My personal recommendation: Use the tesselation from the GLU (OpenGL Utility Library). The code is rock solid, faster than GPC and generates less triangles. You don't need an initialized OpenGL-Handle or anything like this to use the lib.
If you don't like the idea to include OpenGL system libs in a DirectX application there is a solution as well: Just download the SGI OpenGL reference implementation code and lift the triangulator from it. It just uses the OpenGL-Typedef names and a hand full of enums. That's it. You can extract the code and make a stand alone lib in an hour or two.
In general my advice would be to use something that alreay works and don't start to write your own triangulation.
It is tempting to roll your own if you have read about the ear-clipping or sweep-line algorithm, but fact is that computational geometry algorithms are incredible hard to write in a way that they work stable, never crash and always return a meaningful result. Numerical roundoff errors will accumulate and kill you in the end.
I wrote a triangulation algorithm in C for the company I work with. Getting the core algorithm working took two days. Getting it working with all kinds of degenerated inputs took another two years (I wasn't working fulltime on it, but trust me - I spent more time on it than I should have).
Jonathan Shewchuk's Triangle library is phenomenal; I've used it for automating triangulation in the past. You can ask it to attempt to avoid small/narrow triangles, etc., so you come up with "good" triangulations instead of just any triangulation.
CGAL has the tool you need:
Constrained Triangulations
You can simply provide boundaries of your polygon (incuding the boundaries of the holes) as constraints (the best would be that you insert all vertices, and then specify the constraints as pairs of Vertex_handles).
You can then tag the triangles of the triangulation by any traversal algorithm: start with a triangle incident to the infinite vertex and tag it as being outside, and each time you cross a constraint, switch to the opposite tag (inside if you were previously tagging the triangles as outsider, outside if you were tagging triangles as insider before).
I have found the poly2tri library to be exactly what I needed for triangulation. It produces a much cleaner mesh than other libraries I've tried (including libtess), and it does support holes as well. It's been converted to a bunch of languages. The license is New BSD, so you can use it in any project.
Poly2tri library on Google Code
try libtess2
https://code.google.com/p/libtess2/downloads/list
based on the original SGI GLU tesselator (with liberal licensing). Solves some memory management issues around lots of small mallocs.
You can add the holes relatively easily yourself. Basically triangulate to the convex hull of the input points, as per CGAL, and then delete any triangle whose incentre lies inside any of the hole polygons (or outside any of the external boundaries). When dealing with lots of holes in a large dataset, masking techniques may be used to significantly speed this process up.
edit: A common extension to this technique is to weed weak triangles on the hull, where the longest edge or smallest internal angle exceeds a given value. This will form a better concave hull.
I have implemented a 3D polygon triangulator in C# using the ear clipping method. It is easy to use, supports holes, is numerically robust, and supports aribtrary (not self-intersecting) convex/non-convex polygons.
This is a common problem in finite element analysis. It's called "automatic mesh generation". Google found this site with links to commercial and open source software. They usually presume some kind of CAD representation of the geometry to start.
Another option (with a very flexible license) is to port the algorithm from VTK:
vtkDelaunay2D
This algorithm works fairly well. Using it directly is possible, but requires links to VTK, which may have more overhead than you want (although it has many other nice features, as well).
It supports constraints (holes/boundaries/etc), as well as triangulating a surface that isn't necessarily in the XY plane. It also supports some features I haven't seen elsewhere (see the notes on Alpha values).

Resources