Code extracted from: http://public.kitware.com/KWSys.git at commit cdcf4c4753d8e90895f1fb2cb6ab622342bcaaa8 (master).