Quadspheres and Spherical Cubes

quadsphereRecently a reader wrote in regarding my earlier Quadrilateralized Spherical Cubes post, however I had neglected to update the original post with some added corrections. I initially wrote about this topic for my first dip into 3D visualization, and unfortunately at the time I conflated QuadSpheres and Quadrilateralized Spherical Cubes as a single concept. Both are a popular topic for visualization, game making and scientific research so I’m going to expand a little bit further on the differences between the two and hopefully that will make it a little bit clearer.

First let me preface this by saying that there’s more than one way to generate a mesh for a sphere. Since my intention was to reduce visual distortion on the earth texture I was using, I chose to map my textures to a QuadSphere, rather than the common method of using ECP tesselation which causes pinching at the north and south poles of the spheroid. A QuadSphere is composed of 6 faces which correlate to the 6 sides of a cube. These faces are called quads because they are essentially squares before you begin any transformations on them. Each of these 6 faces can be subdivided further into smaller quads to increase detail when the camera is closer to the mesh, and each of those resultant quads are tessellated into tris and rendered. In a modern graphics engine this will take place in the vertex shader stage of the rendering pipeline, so you will just feed in the heightmaps and shaders to shape your terrain.

For an older OpenGL 2.0-style pipeline, you can create a QuadSphere by projecting equidistant rays starting from your origin of the sphere to the surface and pushing those vertices into a buffer. This can start out as a 32 x 32 curved grid or something; 1 grid for each side; 6 grids in total to form the spherical shape. You can further subdivide these grids to get more detail when your camera is closer. That’s a QuadSphere in a nutshell.

My work never used the QLSC agorithm. A QLSC ensures that all virtual points on your map take up an equal area of space, decreasing the amount of distortion. Not necessarily texture distortion, but aberration from your virtual model to the real life thing. Distortion occurs naturally when projecting flat data onto a spheroid, so Doctor Kenneth Chan worked extensively on the QLSC algorithm to make it extremely accurate at mapping points and data. This is great for scientific research and that is why it was used in the Cosmic Background Explorer project at NASA.

There are a lot of little caveats to this, but the big takeaway is there’s not a huge need for QLSC in real-time visualization and games. You’ll likely need it for data processing, geomapping spatial data, or other areas of scientific interest.

One last term to take note of is cube mapping. That is how a texture is mapped onto a shape consisting of quads, but not necessarily how that texture will be projected. For instance, skyboxes are meant to be projected on a cube, not a QuadSphere. Though both of these are cube mapped, you will need properly projected textures to suit your needs to minimize the amount of texture distortion.

Have any questions or corrections? Please leave it in the comments below and I’ll be glad to elaborate more.

Pictures of my Arduino

I soldered a couple of 7-segment displays into a protoboard and programmed some look up tables for demos and scrolling text. Nothing fancy, just for fun. I have it running on a loop on my desk now.

Breaking free of the constraints of the Qt data model

I decided to drop the Qt data model altogether in a project. There are certain circumstances that may call for this, and I will outline my reasoning below.


Qt has view components that make it easy to tie into a local data model, even from a SQLite source. The widget handles all of the basic functionality for you—for a QListView, this will yield a component that automatically draws, highlights and edits data. This takes a lot of the burden off of you when building a cross-platform product where you’d normally have to manage data, drawing, layout, and native events like flicking to scroll on touch screens. There’s a lot of accessible customization, especially if you’re going the QML route. The drawing is even hardware accelerated where available.

If you want to make a custom component you have to handle each event, drawing and low-level logic for the component manually. You’ll generally need an extraordinary reason to not use the widgets.


If you have a particularly complex set of data that needs to be displayed there are alternatives to the standard list view; QTableView can display tabular data, QTreeView for hierarchical data sets. For any of these, the items’ paint methods can be overridden to customize the look.

Under nuclear conditions, you can use the non-databound widgets like QListWidget and use its setItemWidget method to convert any list item into a widget of your choosing, including a custom one containing its own child widgets.

The Exceptions

The reasons to not use the Qt model-view ecosystem in a Qt-based application may be pretty obvious in some cases. At some point you’ll cross the very fuzzy threshold of “yes this needs to be completely custom,” and here is a very good combination of reasons why:

  • You have to custom draw every list item,
  • There are multiple or irregularly-shaped hotspots on list items for mouse tracking,
  • There are multiple fields that need to be edited within each list item,
  • There will be a profound number of list items which will trigger many resize events if using custom widgets for your list items,
  • Your data model and view may need to be changed frequently,
  • Your data is asynchronously updated, and you need to ensure scrolling and selection is consistent,
  • Your data is relational or needs to referenced with hashes, and
  • You would have to override a majority of the built-in data model’s methods in order to work with a view anyway.

Qt can of course handle all of these cases so if you’re already neck-deep in using a QListView it wouldn’t make sense to refactor that and write a widget from scratch. However in my case adhering to the Qt convention would take more work for myself, since I need to override all the default functionality anyway.

Ubuntu 14.04 Memory Issues Disappear on Intel CPU

The system I was futzing with last week has an 4-core AMD APU. However I found a desktop with similar specifications, albeit in a 4-core Intel CPU package and it has less trouble with memory management and responsiveness. This could of course be a bug with some module or other hardware, but I’m beginning to notice that low-end laptops that use a combined CPU with GPU package will yield a less responsive experience especially when memory is stressed. Has anyone else noticed this?


tmux configuration

If you spend about 20 minutes reading the manual and configuring tmux (and tmux sessions for each of your projects) it’ll save you 20 minutes every day that you use the command line.

tmux attach_035

Ubuntu 14.04’s constant memory struggles

Looking at htop I notice that most of my memory is sucked up in graphics-intensive desktop applications (surprise). Here are the big memory killers I’m going to address:

  1. Browser* – 1.2GiB
  2. compiz – 225MiB
  3. X – 175MiB
  4. spotify – 113MiB

*I’ve recently switched to Opera Developer for performance reasons.

4 gibibytes of RAM depleted within an hour of using Ubuntu

The window manager & graphics server take up 400 MiB of RAM combined just by themselves. Reducing the use of windowed applications kills two birds with one stone: less load on the window and composition manager and lower # of SO’s in memory interfacing with X.

The alternative command line work flow

  • tmux – Rather than opening multiple terminal windows. I use Guake as an omni-present terminal.
  • gcalcli – Instead of leaving the Google Calendar tab open. ccal and pal are good alternatives.
  • despotify – Replaces the resource-hungry Linux Spotify client.
  • vim/emacs – RedNotebook is a great lightweight desktop journaling application, but I still find it preferable to maintain a personal journal using vim.
  • mutt with offlineimap – Mutt and offlineimap for email make a great team. Backing up and archiving all your email using this configuration can be automated with one or two line scripts. Side note: Linus himself uses pine for email.
  • bitlbee & weechat – Bitlbee acts as an IRC server, fully managing all of your chat accounts including Google talk (hangouts), Facebook and Twitter. weechat is then used to connect to your bitlbee server. I found this combination yields the smallest returns on performance but it is an important part of my work flow.
  • elinks – Lightweight cli browser.
  • sc – Great for doing simple spreadsheets and calculations without having to load LibreOffice.


There was an order of magnitude gains in memory usage here. I can run all of these at once and the system’s overall response is still much snappier. If you’re comfortable using the command line I will always suggest test-driving CLI alternatives for your favorite applications.

Recovering ecryptfs-encrypted home files from a LUKS encrypted drive in Ubuntu

I did this in Ubuntu 14.04.

This is a bit of a niche situation and it took a really long time so this guide is incomplete. If you run into the situation and need extra help just comment below and I’ll try to give some guidance.

Restoring with rsync

Restoring with rsync

Recently I ran into problems trying to update to the 14.10 release. I lost my video drivers, x11 fallback drivers, and window manager.

Rather than mess with all that I swapped out my laptop’s drive with a fresh one, enabled logical volume management (which the Ubuntu installation disk says is easier to manage) and then installed Ubuntu 14.04 on the new drive. The old one is now a bodged external drive, but it took some finagling to get it to mount.

The first problem I ran into is both of these drives are now boot drives and the logical volume names are both the same. As much as you try, you cannot mount the logical volumes simultaneously without renaming them. Also when you do run sudo lvscan it will show both conflicting logical volume names (ubuntu-vg/root).

I removed my primary boot drive–that’s the important part–then rebooted into a Ubuntu live disc. You should always make a live disk for convenience. Finally I ran lvrename to change the logical volume name of my external. Once I was done with that I rebooted to my primary drive again.

Bingo! Now when I use the disks utility I can mount both logical volumes. You can’t mount it from nautilus, but don’t bother with it. Next is the harder part: You have to mount your home folder that is encrypted with ecryptfs. Look at the post by idallen for a script to mount your private folders at a new mount point. You will have to make modifications to the script. I also manually set the USER variable in the beginning of the script so that I could sudo the script. Make sure you’re pointing to a place on the old drive where your .Private folder is. AND BE CAREFUL WITH THIS. I made the mistake of creating some recursive directory structures in my destination through symbolic links and I could have just as easily deleted the encrypted home folders the same way.

Once the home folder is mounted, you can rsync -r the contents to a new folder. Do not use cp!

That is all. Like I said, if you run into issues let me know in the comments and I’ll try to help.

October Atomic update

I’ve worked on Atomic for months and months now. I’m closing in on an MVPHowever. HOWEVER: I’ve coded an entire working TO-DO manager and I cannot stand to use it. Yes, I know other people can so I will continue to polish it and then release it.

There’s a simple reason why though. To-do lists have to stay out of your way by being minimalist, but if they are too minimalist they will hinder you further. Take these assertions:

  • Pen and paper is very minimalist: pen and paper are always available to you.
  • If you want a to-do list, a pen and scratch paper works great!
  • If you want something with archives and deadlines, a notebook or planner system works great!
  • If you need to share a lot, web can be considered, but eh you can also take pictures of your notes and pass them along.

Ok it starts to get yucky:

  • If  you want to keep track of links, store photos and documents, or collaborate with large teams a web task management system is better.
  • If you need to manually sort these tasks before a deadline approaches (priorities shift all the time!) you’re way screwed. Get ready to drag and drop a lot of crap.
  • If you want to type notes inline with your tasks to work out other stuff you need to do, wow, maybe you should use evernote or something? Clicking back and forth between similar tasks to compare notes will just drive you insane.
  • And what happens if one task turns into a bunch of other smaller tasks?
  • What if the one task should actually be a whole project that someone on your team needs to take time for?
  • We didn’t really have time to go through these little details in the planning phase. Hm.
  • Your big tasks really should be split into smaller chunks. Good luck!
  • If you want to collaborate AND feel free using your task list online there’s really nothing you can use.

The whole problem about atomic is that it treats tasks like–well Atomic units. But tasks behave more like quantum particles; they’re discrete reminders that larger things exist, but when you begin to examine them they start to change and take shape.

Here’s a solid example of something that I ended up doing yesterday:

  • I just wanted to install an application on my linux computer. Initial task: install application.
  • Oh, the build is outdated. I’ll have to compile from source. Task now becomes: compile and install application
  • That depends on other libraries. I’ll have to install those too. Task: install dependencies, compile and install application
  • Ok, all dependencies for my distribution are out of date too! Task: compile dependencies from source, install them, compile and install application
  • You think I’m even close to finish? Nope. Task: update core os libraries, fix circular dependencies, […]
  • Three hours later I’m reinstalling my OS from scratch and cursing.

Very quickly one simple task can turn into hundreds of smaller ones. I would’ve liked to document some parts of this process, but wrestling with a task manager at the same time would’ve been futile.

I’ll let your imagination run with that. I think Atomic has the potential to fill a much bigger gap while still synchronizing with online services such as Producteev.

New format coming soon

It takes too much time to keep up with long form post format I’ve maintained over the years. It’s also really boring.


Ok. Things I’m working on:

  1. New site (maybe)
  2. New posts (maybe)
  3. Atomic
  4. Probably 100 other things

Going to update in more detail with another post here shortly.

Ubuntu 14.04 LTS (trusty) peculiarities and how to fix them

A small guide to big frustrations.

Shutter (for screenshots) goes slow

This is a problem with your video driver. Run “Additional Drivers” from the unity dashboard and snag the non-generic video drivers. You’ll notice an overall speed boost for everything else too.

Additional Drivers

No swap file with LVM / Locking up in Ubuntu 14.04 LTS

This has to be one of the wackiest things with 14.04 LTS. Check htop or free. Do you even have any swap? If you chose to encrypt your home folder then probably not.  This guide explains how to set up a swap file. Give yourself a few GB (I have 8.) Otherwise if you run out of free memory processes will begin to halt. If you lock up entirely, remember REISUB. Important to note: swap files in the root file system are going to be unencrypted unless you are using full volume encryption. This gives you faster swap speed but leaves the swap vulnerable if someone gets physical access to the drive.

Ah, that's better.

Ah, that’s better.

Takes a long time to mount the swap partition (Press S to Skip…)

If you see this message every time you boot:

The disk drive for ubuntu–vg-swap is not ready yet or not present.

Continue to wait, or Press S to skip mounting or M for manual recovery

This is the same issue as above. Set up a swap file, and also comment 2 lines out of /etc/fstab:

vim /etc/fstab

vim /etc/fstab

Make sure you edit the 2 that start with /dev/mapper at the bottom, but leave the top ubuntu–vg-root volume alone! Unfortunately I’m guessing this is an issue with the guided Ubuntu setup for 14.04. I know the volumes are being created for swap and root but they never mount!

Visual Stutter, lag, slowness with full volume encryption

Unfortunately I resorted to completely nuking my installation and reinstalling without full volume encryption. It would be nice to know if there’s a solution to this aside from getting an SSD.

My personal experience here is that running without full encryption is so much faster that I’m not concerned with it.


Update 10/7/2014:

Print screen doesn’t work

I used Compiz Config Settings Manager (CCSM) to bind the printscreen key to Shutter. Unfortunately this introduces a small delay.