Thursday, August 20, 2015

GSoC 2015 wrap up

As time flies by, we are closer and closer to the end of this year's Google Summer of Code. I had a lot of fun and learned many things this summer thanks to the program. My main field of interest is computer graphics and rendering, so working on a project focused on this was a great challenge for me, that I think I barely - due to some unexpected events - but somehow, overcame.

Speaking of what I learned, there are just too many things to list, but if I have to name three things, I would say: Qt, the basic geography and the math related to it, but there are so many more beside those. For example I struggled during almost the entire summer to implement an acceptable form of street name labeling in real time, performance-wise and looks-wise. I realized that there is almost a whole field of study dealing with it. But more on that later.

Improvements made this summer


Implementing the decoration system for the GeoDataGraphicsItem class was my favourite task, because this class (and those derived from it) is responsible for the OSM Vector Tile rendering in Marble. This decoration system is responsible for the outlines of the streets and highways and for the - now even further improved - (fake) 3D building rendering.

Street and building decorations visible on a loaded .osm file in Marble.

A close-up from the previous picture.
The improved building decoration is visible more visible here
(top right corner, bottom left cornet)
The best thing about these decorations is that every GeoDataGraphicsItem can be improved this way. After some refactoring and improving the solution since midterms, a GeoDataGraphicsItem now can have multiple decoration, decorations can have decorations, which can have multiple decorations, so there is more potential for further improving the rendering of these items.

Street labels

As I mentioned above, getting the best results for the street name label placement was a pretty hard task. Not because it is hard to understand the principle, the math behind it is not that difficult, but because we needed it to work in real time with almost no performance impact on the rendering. This was further complicated by the fact that Qt doesn't provide a function to draw text along curved paths. Finally I came up with a solution, then another, then another, then ... , and now we have a pretty good looking (but in the future improvable) implementation. Additionally I had to implement some style setting functionality for these labels, like color and font settings.

Before my work on this project. Street labels are "just there".

The latest version. Text along curved paths is drawn now.
The funny thing is when your solution has 200 lines of code, but the results don't satisfy you in terms of performance, so while improving the same code several times you get a much better performance and result with only cca. 40 lines of code in the end. This happened to me with the task above :)

Better zoom with the mouse wheel

When I first tried out Marble, I was a little disappointed by the blurry zoom on the openstreetmap map theme. The program downloads the texture tiles used on the openstreetmap website and then projects them with the current projection (the one used by openstreetmap is the Mercator projection). In my project proposal I had an intention to fix this, so when I saw a comment on my first blog post requesting this fix I was sure that this is a pretty needed one.

After some work on it I completed the fix. I even made a little video demonstrating it, but in some days you will be able to try it out yourself. The second part of the video shows the rendering improvements on a new, empty map theme.

Improving printing support

Making Marble dpi-aware (and so preparing it for better printing)

I told you in my previous post that I will start to work on improving Marble's printing support, but this proved to be a pretty big task for the remaining time, because first we need to make Marble more dpi-independent. This is needed because if we just simply scale up the map to a higher resolution, then every icon and text will be much smaller in proportion to the original map. This could be overcome if we change Marble's internal dpi resolution before painting. Another argument along this task is the fact that this summer Marble was successfully ported to Android by Gábor Péterffy and developing an application for a smart-phone always comes with the struggle of the UI's dependenccy on the screen's dpi resolution (density).

I already made Marble recognize the current dpi resolution of the screen and to respond to it's change(e. g. when printing). Next step will be to supply Marble with icons and bitmaps for different dpi resolutions (ldpi, mdpi, hdpi at least). I look forward to working on this in the next months, and if we achieve more progress, I'll let you know in a next blogpost.

Other minor improvements

  • Several color style tweaks and changes in the OSM Vector Tile rendering, my goal was to match the default color style on the openstreetmap website.
  • When my time allowed I was looking for unincluded OSM map features, like highway=cycleway, highway=pedestrian, highway=road etc. and added them to the list with the right style.
  • I've created a simple empty map theme to load, view and edit these .osm files, though it's mainly for developer purposes.
  • Some bug fixes and refactoring in the source code.

  Some finishing words

Before I started, I was pretty confident in my programming skills, I had experience with Qt and C++, but looking back from now I see that there is a lot more to learn for me than I thought. And I think this is one of the most beautiful things to realize: to realize that you can learn new things as long as you are willing to.

I'm glad that I got such a great project to work on. If the Google Summer of Code program's goal is to encourage people (students) to work on open source projects in their free time even after the end of summer, then the Marble team is one which definitely achieved this goal with me. I look forward to work with them in the future, maybe I'll join some other KDE projects too :)

Friday, July 3, 2015

GSoC 2015 midterm update

I'm working on the project Improve Marble's OSM vector rendering and printing support. The first part of the project is to polish and improve the rendering of the OSM vector tiles in Marble. In my previous post you could see what it looks like without the improvements I have in my mind and now I want to share some pics and videos about the progress and results so far.

Adding outlines for OSM ways

One of the most outstanding issue was the lack of the outlines for streets and highways. My first task was to somehow overcome this problem. These lines are drawn as a QPainter line and thus they don't have style settings for outlines, so the best that I could do is to draw these lines twice: first draw a bit thicker (with 2 pixels) line with the outline color, then a second over top of it with the fill color. This approach of course is not enough, because the streets are not rendered in the order in which we want them. This results in something like this (which I showed you in my previous blogpost):

The solution is to sort the lines (and every object) depending on their z-value, so they are rendered in the correct order. As this sorting is a little bit resource-hungry, the outlines (and further on the decorations) are not rendered below Normal quality setings.
I even changed the style of almost every OSM item and added some new, unimplemented items to the list(like cycle ways or pedestrian ways), so they would match even better the standard color theme of the openstreetmap website. The end result looks good I think.

After the improvements

Before the improvements

Decoration and "Fake3D"

Implementing this feature led us to the idea to create a more robust API for creating such decorations for the GeoGraphicsItem classes which are used in the rendering process (e.g. the class used to describe the streets is the GeoLineStringGraphicsItem class). With overriding a simple virtual function, one can create custom decorations for every GeoGraphicsItem-derived class. To demonstarte this functionality, the outlines are implemented this way and I added a simple 3D effect (shadow) for the buildings. This takes almost the same approach as the outline rendering, but now this shadow is rendered with a little offset, based on the focuspoint of the map (the little cross at the center). I think this is a pretty good example to demonstrate the capability of such a decoration system.

Struggle with the street labels

As you can see on the first pictures, the street labels aren't aligned to the streets at all, even if this is a crucial point of urban maps. I thought that this would be an easier task than the decorations, but I was wrong. The proper alignment of the street labels with the right color, right size, right font, right direction etc. it's more like an art, than a simple task. One of the problem is that the program needs this to be done in realtime, so I can't use a "complex algorithm" to calculate these properties. And on top of that, Qt doesn't provide a proper way to draw a text along a (curved) path. The best thing I could do is to try to avoid the curvatures of the streets when drawing the labels, so they will be rendered properly most of the times. A quick demonstration of what I achived this far:


Due to my exams, I couldn't give a 100% priority to GSoC, but the progress this far meets my expectations and from now on, I can even double the time spent working, programming, experimenting.
I'll post a smaller status-update when I start working on the printing support improvement, until then I'm going to polish the work I had done this far.

In the end, here is a video demonstrating these improvements:

Sunday, May 31, 2015

GSoC 2015 with Marble

Great news! I've got selected to this years GSoC. From now on, I'll be posting here frequent status updates about my progress while working on the project "Improve Marble's OSM vector rendering and printing support".

KDE and Marble

One of the reasons why I choose KDE as my mentoring organization is that I already used their Plasma desktop for quite a while now, thus I'm a little familiar with KDE Applications, but the main reason is that my programming skills and knowledge was best matched with KDE's Marble project.

Application to GSoC

During the application period I had a lot of fun while getting started. My introductory tasks revolved around Marble's Ground overlay feature in the Edit(Annotation) plugin. I had to use git-bisect to find a commit in which a regression occured. Then I had to implement manual resizing and rotating for the GroundOverlay, and correcting some bugs. These were great tasks to get me started working as a developer for Marble. Frequently speaking with my mentor about the changes and ideas that I wanted to implement was one of the best and most memorable part of it.

About my project

Marble has a great rendering engine, which is fast (Marble starts up in 2-5 seconds), reliable and allows developers to easily improve some of its features. My projects main goals are to improve the following parts of the program: the rendering of the .osm file based vector tiles, the picking of the texture tiles, improving printing support. I also intend to fix any bugs that I may encounter in the process. This would improve Marble's rendering and maturity too, so the end-user should be more satisfied with the application.

Let's start coding!

Though the coding period started a week ago, I've only got time from now to work on GSoC, because I didn't want to throw my school projects aside, those are important too.

So now that I've completed my school project(a simple tile-based rouge-like rpg), I can begin to work on my GSoC project. The not-so-good thing is that we have a quite early mid-term evaluation period(June 26. - July 3.), so we need to get some of our work done by that time.

I've started to work on the OSM vector tile rendering part, so the polishing of the rendering will be my main task for this month. I'm currently working on the outlines of the streets and highways. Just to get you the idea, I'll show some pictures about it.

This is how is it now in Marble:
An .osm file loaded with into Marble.

The rendering performance is good, but it needs a little polishing in order to achive something similar to the one that's on the OpenStreetMap website. This is what it should look like:
Same region, but from the openstreetmap website.

And finally this is my progress for now:
It's a little cartoon-like.
The streets now clearly have outlines, but it's not the best result we can get. For now, this is just an experiment of what can be done. I'm only drawing the lines twice, first the outline color, then the fill color, but it's done par ways, this is why it gets outlines were it shouldn't. To be honest, it took me quite some time to find the files in which I need to work, but as you can see, it's working now, so my next task will be to get it to an acceptable state.

That's it for now. Next time I want to share my progress on this task, possibly the completed version then.