How to plot multiple polygons using CGAL::draw - cgal

How to plot multiple polygons using CGAL::draw() ? I wish to draw multiple polygons on the same frame. Cannot repeat the command as it is blocking in nature.

The set of overloaded functions CGAL::draw is very simple and very limited - there are fourteen of them and none of them can plot multiple polygons in the same frame.
You can plot anything you want using Qt - there are many examples how to do that in the CGAL demo directory. However it's much more involved than the CGAL::draw functions - you'll need to understand how to develop interactive Qt-based applications.

CGAL seems to have added support for this since this question was asked.
Just use #include <CGAL/Polygon_set_2.h> and #include <CGAL/draw_polygon_set_2.h>, add your Polygon_2 or Polygon_with_holes_2 objects to a Polygon_set_2 via the Polygon_set_2::insert method and then call CGAL::draw on the resulting polygon set.
A full example can be seen in CGAL's documentation.
Note that your polygons must be disconnected for the drawing to work as expected in this case.

Related

CGAL cut cube with arbitrary surface

I'm new to CGAL and I'm trying to cut a cube with an arbitrary surface mesh in 3d (no self intersections, not closed/no volume). The goal is to get a volume which consists of one "side" of the cut cube, closed by the part of the surface inside the cube.
The surface itself consists of unordered triangles which should have the same winding order (consistent normal directions) but have no neighborhood information and could contain same points multiple times for different triangles.
I tried to use the clip function, like:
CGAL::Polygon_mesh_processing::clip(cube,surface,true);
Which of course does not work because the surface is not closed (as far as I understood). But It shows the idea on how the operation should work.
Boolean operations (https://doc.cgal.org/latest/Polygon_mesh_processing/index.html#title14)) cannot be used for this as well since they are calculated on volumes and the surface has no volume.
I also thought about extending the outside of the surface so that it is closed. This, however, does not seem like a good approach.
Sadly, my research on similar problems was not successful.
I'm pretty sure that there is a nice way to do this in CGAL. Maybe someone with more experience in CGAL knows how to do this.
What would be the best approach for getting this volume?
Regards
EDIT:
By removing redundant points in my surface mesh I was able to get clip to work. Nevertheless, I do not always get the right side of the volume, even though the winding order should yield normals which point to the outside.
Is it necessary to calculate the normals and pass them as an extra parameter (see here) of the surface before the cut in order to always get the same "inner" side of the volume?
Also, the clip function seems to be quite slow. I have to do this cut for a very high number of cubes and different surfaces.
I use CGAL as header only lib and without GMP and MPFR, since it crashed my other application. How big is the speedup using these libraries and are there any other tricks which can be used to speedup computation, e.g. using parallelization?
I saw that CGAL uses Intel's TBB which. But in the header files which are included by the clipping algorithm CGAL_LINKED_WITH_TBB is not tested.
Thanks
It was a problem with the clipping mesh. Clipping could not be done properly. I increased it size and now it always intersects the volume.

How to split a face in Surface_mesh

I am using the CGAL::Surface_mesh class to represent a 3d triangle mesh. I wanted to use this instead of the Polyhedral_3 mesh due to its simplicity and index structure and ease of use with OpenGL. I am trying to write a method to perform 1-4 subdivision of a triangle and cannot find how to do so in the documentation. Is there a way to split faces (1-4 splitting or barycentric splitting) in a Surface_mesh class similar to the create_center_vertex in Polyhedral_3?
There are a set of generic functions that are working both on Surface_mesh, Polyhedron and even OpenMesh. In the BGL package, see the Euler operations.
The one you are looking for is here.

Triangulated Surface Mesh Skeletonization Package - How to keep the skeleton inside the surface mesh?

I tried executing the example in http://doc.cgal.org/latest/Surface_mesh_skeletonization/index.html to get the skeleton of a surface mesh.
I tried using a mesh model of blood vessels with thin structures. However, no matter how refined my meshes are, parts of the skeletons seems to always be outside the mesh models.
In the sample code, there seems to be no parameters which I am able to play around with, so I am asking if there is anything i can do to make sure the skeleton stays within the mesh model.
I have tried to refined the meshes, till the program crashes. Thanks for any help provided. thanks!
I guess you have used the free function setting all parameters to their default. In case you want to tune the parameters you need to use the class Mean_curvature_flow_skeletonization.
It has 3 parameters that need to be fine tuned so that your skeleton lies within the mesh:
quality_speed_tradeoff
medially_centered_speed_tradeoff
is_medially_centered
Note that the polyhedron demo includes a plugin where you can try the effect of the different parameters.
If you can share the mesh with me, I can also have a look.

Given a pair of images, how to automatically create an animation sequence morphing one image into the other?

Is there a programmatic way to convert two images into an animation sequence (e.g., an animated GIF) like the following example?
This image sequence, taken from a http://memrise.com course, doesn't seem to have manually-edited frames, but seems automatically transformed using some kind shape morphing algorithm. Is there a common term used to describe such an animation or algorithm? Is there a feature in ImageMagick or Photoshop/Gimp that generates such animations, given a pair of images?
Ideally the technique could be scriptable so I could create animations for several pairs of start-end images.
Edit: I have just been told about Gimp's tool under Filters->Animation->Blend, which appears to do the same thing as jQuery morph: each frame i is start + (finish - start)/N*i. In other words, you're transitioning each pixel independently from the start value to the finish value, without any shape morphing. The example gives is more complicated, as it modifies the contours of both images to achieve its compelling effect.
Other examples:
http://static.memrise.com/uploads/mems/32000121024054535.gif
http://static.memrise.com/uploads/mems/225428000121109232837.gif
I have written a tool that doesn't require setting manual keypoints and is not restricted to a domain (like faces). Anyway, the images have to be similar (e.g. two faces or two cars from the same perspective).
https://github.com/kallaballa/Poppy
There is also a web-version created with emscripten.
I generated the above animation using following command line:
poppy flame.png glyph.png flame.png
Although this is an old question, since ImageMagick is mentioned, for anyone who comes here from google it may be worth looking at this imagemagick plugin called shapemorph.
GIMP can't do that directly, but over the years a series of (now poorly maintaind) plug-ins to do that where released by third parties. The keyword for searching for this is "morph" - you should find a bunch of stand alone programs to do that as well, from "gratis" to full fledged Free Software, such as xmorph
Given pairs of vector files (.wmf extension) it is possible to use linear interpolation of shapenodes in Visual Basic for Applications to create frames for GIF animations , though this would take along time to explain. For some examples see
http://www.giless.co.uk/animatorMorphGIFs.htm (it is like a slideshow)
I have made some improvements since then, as well!

Drawing cartograms with Matplotlib?

In case somebody doesn't know: A cartogram is a type of map where some country/region-dependent numeric property scales the respective regions so that that property's density is (close to) constant. An example is
from worldmapper.org. In this example, countries are scaled according to their population, resulting in near-constant population density.
Needless to say, this is really cool. Does anyone know of a Matplotlib-based library for drawing such maps? The method used at worldmapper.org is described in (1), so it would surprise me if no one has implemented this yet...
I'm also interested in hearing about other cartogram libraries, even if they're not made for Matplotlib.
(1) Michael T. Gastner and M. E. J. Newman,
Diffusion-based method for producing density-equalizing maps,
Proc. Nat. Acad. Sci. USA, 101, 7499-7504 (2004). Available at arXiv.
There's this, though it's based and a different algorithm (and though it's on the ESRI site, it doesn't require ArcGIS). Of course, once you have the cartogram you can plot it in matplotlib.
Here is a Javascript plugin to make cartograms using D3. It is a good, simple solution if you are not too concerned about the regions being sized accurately. If accuracy is important, there are other options available that give you more freedom to play with the algorithm's parameters to get to a more accurate result.
Here are two great standalone programs I know of:
Scapetoad
Carto3F
Scapetoad is very easy to use. Just give it a shapefile, tell it which attribute to use for the scaling, and set a few accuracy parameters. If there is any doubt, this post describes the process.
Carto3F is more complex and allows for greater accuracy, though it is a bit trickier to figure out - lots of parameter settings without much documentation explaining them.
There is also a QGIS cartogram plugin, written in Python. Though I have not been able to get it to work, so cannot comment on that one.
In short, no. But Newman has an excellent little implementation of his and Gastner's method on his website. Installing it is easy and it works from the command line. Here's an example of a workflow using this software that worked for me.
Compute a grid of density estimates over some region, e.g. in Python. Store it as a matrix of numbers.
Run the cart program with your density matrix as input from the command line or from as subprocess in Python.
The program returns a list of new coordinates for each grid point.
Pipe your shapefile points through the interp program and into a new shapefile to get the transformed map.
There are nice instructions on the main page.
The geoplot.cartogram function in
Geoplot: geospatial data visualization — geoplot 0.2.0
says it is a high-level Python geospatial plotting library, and an extension to cartopy and matplotlib.
Try this library if you are using geopandas, it is quick and doesnt require much customization. https://github.com/mthh/cartogram_geopandas