Camouflage class in New York University, where men and women are preparing for jobs in the Army or in industry, New York, N.Y. They make models from aerial photographs, re-photograph them, then work out a camouflage scheme and make a final photograph (LOC
Creative Commons License photo credit: The Library of Congress

No, I’m not going to Egypt. Cairo I’m referring to is an open source 2D graphics library, used by GTK+, Mono, Mozilla Firefox and many others.

As part of my source code spring cleaning effort I started modeling Kosmos mapping library from scratch. The idea is to separate pure map-rendering stuff from the Kosmos application and infrastructure logic. Then this map rendering code could be reused in other applications.

The effort already bore some fruit: the new model has a much cleaner separation of the drawing engine from the rest of the code:

public interface IPainter : IDisposable
{
    void BeginPainting ();
    void Clear ();
    void DrawLines (int[] coords);
    void DrawPoint (int x, int y);
    void EndPainting ();
    void PaintCurve (PaintOperation operation, int[] coords);
    void PaintPolygon (PaintOperation operation, int[] coords);
    void PaintRectangle (PaintOperation operation, int x, int y, int width, int height);
    void SetHighQualityLevel (bool highQuality);
    void SetStyle (PaintingStyle style);
}
 

This is all there is to the drawing (well maybe a few methods like drawing text are missing, but you get the idea). So there are no GDI+ primitives (like Points, Colors, Pens etc) in the interface. Which means I can start playing with other drawing libraries, like Cairo:

mapgdimapcairo

The two images represent a collection of GPS traces: the left one was drawing using GDI+ implementation of the IPainter interface, the right one using Cairo. Alpha-transparency is used to get the effect of area most covered by traces (the dark color) against those only visited once (the lightest color).  As you can see, there are some differences in the coloring between GDI+ and Cairo’s renderings – these are probably because of the quality settings I specified for GDI+, which could not be replicated in Cairo. Also, Cairo is on average twice as slow in rendering compared to GDI+. I’m not sure why, but I’ll try to improve this.

All in all, I’m very pleased with the result, especially considering that I only started this redesign few days ago. And the main point why I’m playing with Cairo is the fact that you can produce SVG output using the same code. This means that Kosmos will be able to produce vector maps in the future, which can then be manually post-processed to fix any rendering problems (like label-placing).

The main issue I always have in my mind is to keep the performance of map rendering the same with this new design. This was a big concern for me before starting, but now I think the new design is so much better that it will actually be a performance improvement, at least memory-wise, if not speed-wise.