My Octopress Blog

A blogging framework for hackers.

Git(1) - Your Kind of Version Control

I’ve been around the block a time or two (or more) with subversion, but until recently I had limited experience with git. Sure, every now and then I’ve used it to check out projects, but not for my personal use.

No longer. And as of right now, I don’t have any intention of using anything but git for personal development.

Last week, I held lecture for parallel programming and I talked about using subversion for versioning, and I began to suspect that something was horribly wrong. Questions started springing up - where does the repository live? Am I calling svnadmin on my own machine? Where do I check out the repository? Though there are answers to these questions, for many things, such a model just doesn’t make sense.

If I’m working on a project that I’m not syncing between several computers, but I just want to have different stable versions and to try different crazy ideas using branches. It mitigates the cost of reverting drastic changes to code.

Use Case: You’re showing someone your code, and want to show off a neat feature you’ve made, or a problem you’re encountering, something about the project, invariably you’ve run into a problem where it doesn’t compile at the moment. You type furiously, trying to find and undo the most recent changes, but to no avail - there is no hope of getting it to compile in the 5 minutes you have someone’s attention. Enter version control. Revert to the last working copy and victory is yours.

In fact, just today I was asked if I could pull up some code I had been working on to show to a professor. Unfortunately at the moment it wasn’t compiling but was able to switch versions in 20 seconds and show off some very recent work from earlier in the day, thus saving face.

Use Case: You’ve got some crazy idea for an implementation you’d like to try out, but are worried about reverting back all the massive changes you’ll have to make in the code. Worry not! Create a new branch and feel free to change your code in every way you can think of and not lose other branches under development.

Use Case: You’ve got multiple versions of code each implementing the same basic algorithm but with different mechanisms, techniques, etc. and have to turn it in as part of a project. Just archive the whole directory (in a tarball or zip) and the user who unpacks it has access to every version your code has been in. Each branch, each stage of development. And very light-weight to boot.

I can’t speak for others, but I will be using git for the foreseeable future as it’s incredibly easy to use and alleviates many of the problems I encounter regularly with development.

VTK and Volume Visualization

This week for Scientific Visualization, we’re talking about volume rendering and using VTK to explore some data. I got some datasets from The Volume Library and after a little tinkering, got VTK to render them. (And now a quick aside on how to do this as I didn’t find much information on the subject).

I used a tool (pvm2raw) available as part of the V^3 library to convert the pvm files to raw, but VTK requires its own simple header. I actually found that this particular header didn’t work (perhaps a VTK versioning problem?) and so taking guidance from this, checked the header of one of the VTK-included volumes:

1
head VTKData/ironProt.vk

This header more or less included a little information on the grid size, spacing and representation of the data:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# vtk DataFile Version 1.0
<Name of File>

BINARY

DATASET STRUCTURED_POINTS

DIMENSIONS <x> <y> <z>
ASPECT_RATIO 1 <y/x> <z/x>
ORIGIN 0 0 0

POINT_DATA <x * y * z>
SCALARS scalars <unsigned_char|unsigned_short>
LOOKUP_TABLE default
<remember to include a newline here>

Concatenating the header with the raw: <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 </pre></td><td class=’code’><pre>bash $> cat header CT-Head.raw > CT-Head.vtk </pre></td></tr></table></div>
</div>

At that point, I was in business and was able to move on to generating pretty pictures. Granted, these datasets are pretty sparse, but still VTK did a pretty reasonable job. Update: a comment asked for a little bit more detail on this assignment, and so I’m including my report for the project.

[gallery link=”file” orderby=”ID”]

I was amazed today that we can see inside of things… without taking them apart. What an age to live in. Especially the virtual autopsy table I read about recently. In 20 years, we’ll have Firefly-style real-time holographic body scans (ignore music, skip to 0:45):

OpenGLot - Scalar Fields

I’m working on OpenGLot (my OpenGL plotting library) for a class project, and two of the features I decided to implement were contour lines and scalar fields in 2D.

A few days ago I got decent-looking contour lines working and today I got scalar fields implemented with a fragment shader. The programmer using the library can specify a function in the form of a string and have it plotted as a scalar field. Quickly. Really quickly.

Modern graphics cards support shaders, which are programs that get run on the graphics card, and in parallel. This is great for algorithms that can be run in isolation (one pixel doesn’t need to know what the others are doing), which is the case here. OpenGLot generates a fragment shader that colors a single pixel based on the value of the function. Each of the dozens or hundreds of cores on a GPU runs the same code in parallel for their particular pixel.

[caption id=”attachment_696” align=”aligncenter” width=”289” caption=”Contouring for a sinusoidal function with the isovalue 0.”]Contouring for a sinusoidal function with the isovalue 0.[/caption]

[caption id=”attachment_703” align=”aligncenter” width=”300” caption=”Here’s a first look at the results (taken moments after this first worked for me). It’s the same sinusoidal function, and I will be improving upon the color mapping in the coming hours.”]Here's a first look at the results (taken moments after this first worked for me).  It's the same sinusoidal function, and I will be improving upon the color mapping in the coming hours.[/caption]

The graphing program I use, Grapher.app is rapidly showing its age. The results it gives for the same function (though using a much better coloring scheme) are either grainy or extremely slow (10 or more seconds). OpenGLot is generating these in less than 0.1 seconds. (Grapher.app implements its scalar fields on the CPU, so comparing times is a little like comparing apples and oranges. Still, responsiveness in this type of matter is important.)

[caption id=”attachment_697” align=”aligncenter” width=”300” caption=”The quick (and grainy) plot in Grapher.app”]The quick (and grainy) plot in Grapher.app[/caption]

[caption id=”attachment_698” align=”aligncenter” width=”300” caption=”The slow (but smooth) plot in Grapher.app”]The slow (but smooth) plot in Grapher.app[/caption]

Compustalgia

In the midst of a new school, having recently left my undergraduate institution, I’ve been relatively nostalgic. I remember my family getting its first computer. It was a Compaq, running just a few MHz, but when my father came home one night with it, it seemed positively magical. I had heard of computers, and seen them at school, but nothing beyond Oregon Trail.

You could change the text of the screen saver, and its font, color, etc. This, I was sure, was awesome.

I was in the fifth grade at this point, and several weeks later my parents were meeting with their accountant in the kitchen. I saw mysterious black box in front of the man that turned out to be a laptop. He was staring at it intently, but from where I was I could see nothing on the screen - viewing angles just weren’t what they are today. I slinked around and tried to catch a glimpse, but I was noticed and my parents remarked on my curiosity saying that I had never seen one before. Slightly embarrassed, I scurried off as children do.

By the time I was in high school, I had learned about Napster, and torrents, and had learned a small amount about the hardware. I bought my first hard drive (120 GB) for about US$100, and though it’s large compared to the 16MB disks of yore, looking back it still seems ridiculously tiny.

I eventually started playing with C++ my junior year, helped out by my friend Michael’s mother, Katja. She was a programmer (and perhaps she still is) at Ball Aerospace, and she helped me to install Cygwin and get a compiler running. At last, I could actually compile and run the code I had been reading about in the books I had picked up from the local library.

I was constantly aware of the differences between my programs and those of the system, an obvious difference in quality and found it easy to lose interest because of the lack of a GUI. All the same, the power was obvious, and it was then that I first became interested in mathematical curiosities like prime numbers and Fibonacci.

When I left for school, I imagined that I might end up in computer science, but I initially registered as an electrical engineer. When I found myself taking more CS courses than EE, I switched and embraced it. Still, I can’t help but wonder about nature vs. nurture and what along the way (besides the obvious) pushed me in that direction. Either way, I do not regret my career choice, and I can’t think of anything else I’d be so regularly inspired to work on.

Motion to the Rescue

For the last several weeks, things have been disappearing from my office area. First, a backpack I had left out. I had assumed that people in an academic building full of offices would be trustworthy, perhaps I had this one coming. A couple weeks after that, I went to use my camera only to find it gone. Funny, I thought I locked that drawer. I guess I must have been mistaken. A couple weeks after that, my iPhone gone. This time, I’m certain I locked the drawer, and there are marks on the cabinet that indicate it being forced open.

Fed up with the disappearing devices, my friend Tyler and I set out on a mission. We went into Jeddah, bought a webcam and using the popular (thank to Iain for the link) Linux package motion, we set up a hidden motion-detecting spy cam in our office. We have a Linux box sitting near our desk (we’ve locked it to the floor), and so we hid the camera, trained on the place where most of disappearances had taken place.

[caption id=”attachment_680” align=”aligncenter” width=”300” caption=”A test shot of Tyler as we’re setting it up.”]A test shot of Tyler as we're setting it up.[/caption]

What motion does is that every time it detects the picture it sees changing, it takes pictures for five seconds (or until the motion stops - which ever takes longer). It’s supposed to be able to encode a video with ffmpeg on the fly, but as it wasn’t working right for us, we decided to just go ahead and throw it into a script. I wrote a short bash script that just took all the photos, archived them and then generated a video (when dealing with the tens of thousands of photos generated in an average day and night I learned about xargs). It also provides triggers for when motion is captured (for example, if you’d like to update Twitter (via Lifehacker) you can do this with curl).

One night, when bored and filled with anger about the situation, I decided to check the feed and found footage of someone clear-as-day breaking into my cabinet. I first saw it about 20 minutes after the fact, but I was sure the guy was still there. I called Tyler and we quickly deliberated (after getting the opinions of a couple officemates) and we decided to wait until the morning and talk to the security officer.

[caption id=”attachment_681” align=”aligncenter” width=”300” caption=”Looking for goodies. The man’s face is not visible in this shot nor is this frame alone incriminating. In the context of the video, you can see him gain entry, begin rummaging and removing items.”]Looking for goodies.  The man's face is not visible in this shot nor is this frame alone incriminating.  In the context of the video, you can see him gain entry, begin rummaging and removing items.[/caption]

We spent some time with them the next morning, giving them footage and printing key frames, and then they said they’d look into it. They assured us they would not involve the local authorities if they didn’t have to (the penalty for such crimes in Saudi Arabia can be quite stiff) and would take care of it discreetly. That night, they arrested four people and recovered a number of electronic devices. They held them as evidence for a bit, but today, I was given back my camera and iPhone (the only really big-ticket items I had stolen).

I am extremely relieved to have these back, especially my camera as I had been wanting to take photos of trips, events, etc. in its absence. Our next step was going to have off-site storage in case the bandits took off with our computer, but it would seem it wasn’t necessary.

Motion: 1, Thieves: 0

Of course, this was not a solo effort by any means. Some system admins and colleagues in the office park offered input, and the evidence wouldn’t have left our webcam if not for the security staff. Thanks, guys.

Movember @ KAUST

Apparently a tradition many places, Mines had an annual “No-Shave November” competition, with prizes. And beards.

This year, after seeing a post about “Movember” (Movember = Mustache + November) on The Art of Manliness, Tyler and I decided enough was enough. It was time to grow beards for charity.

We’re busy students, and we can’t be training to run marathons for testicular cancer, so why not turn something we already do on a daily basis into something useful. Plus, we won’t have to waste time shaving.

A shave on October 31st will be my last for a month. The trick is to push on through past the “pedo-stache” stage and into the manly beard stage. I’ve grown a beard before, but was displeased with it and enough time has passed that it’s time to test the waters again, for, how can one truly know one’s beard without having one?

Movember @ KAUST has a few rules:

There are varying levels of moustached/bearded-ness. Level 0: the Supporter. This means you support our cause, but are otherwise shaving regularly. Level 1: the Sophisticate. You allow the growth of the facial hair, but still trim it into a neat moustache or beard. Level 2: the Chuck Norris. Very minimal shaving. You are allowed to trim if there is unevenness, and do basic styling, but otherwise the amount of growth is way over the usual. Should be a complete beard and moustache if possible. Level 3: the Castaway. No shaving or facial grooming allowed. Let your facial hair grow wild and free. Wilson! Wilson! The rules for the month are that, in order to participate, you must increase at least one level from your current growth. Unfortunately, there aren’t that many ladies on campus to impress with your manliness. On the bright side, though, in Saudi your glorious beard will be more acceptable than in many western countries. And, being graduate students, you certainly won’t be persecuted at work for an “unkempt” appearance. But its not all about having fun and looking manly, we want some good to come from this event. Find friends and relatives willing to pledge money for your Movember month. Have them pledge a donation to one of the below listed mens-health related charities.

We’re still finalizing our chosen charity, but it looks at this point as if it will be Everyman, a group that helps to fund the Institution of Cancer Research.

UPDATE: We’ve settled on that group, and please feel free to donate!

Good luck, and good growing.

Book Review: Tufte’s “the Visual Display of Quantitative Information”

A professor of mine recently criticized some graphs I submitted on a paper and handed me a book by Edward Tufte called The Visual Display of Quantitative Information. It shreds on graphs made in order to show four numbers, or obvious flaws in design giving misleading impressions of numbers.

He talks about the misconception that graphics lie. Of course some do, but his attitude encapsulates well what I think is great about visualization - good representations convey understanding. Graphics can be the most effective way to get a handle on data, or a trend, and they should reveal what underlies the numbers. But in a world of Excel and every insignificant and meaningless piece interrelationship being plotted in an impressive-looking format, it’s easy to forget this.

A quote I heard recently in my Scientific Visualization course (thanks, Thomas!) puts it well:

Visualize to inform, not to impress. If you really inform, you will impress. - Fred Brooks. SIGGRAPH 2003

Although a child can understand a time series, it wasn’t until a couple hundred years ago that they were actually used, as Tufte points out, but its power to convey is obvious. Similarly, just from glancing at a map like this one from the census bureau, one can almost instantly understand the distribution of income across the United States - literally tens of thousands of pieces of data.

[caption id=”attachment_657” align=”aligncenter” width=”231” caption=”A US Census Bureau graphic depicting the income of the 3000+ counties of the United States.”]A US Census Bureau graphic depicting the income of the 3000+ counties of the United States.[/caption]

In this vein of conveying understanding, I remember several years ago now watching a TED Talk that immediately captivated me with visualization. Hans Rosling talks about how often when we see the rows about rows and tables upon tables of the massive amounts of census data, not only do our eyes glaze over but it becomes very difficult to keep it all in one’s head at any one time. Visualizing the data is thus a key tool for gaining the insight we seek.

The book is full of tremendous insight about how ink should be used as efficiently as possible (within reason - Tufte is quick to emphasize this point) and that the human eye has a great capacity for handling dense data sets if presented efficiently. It is an entirely necessary resource for anyone who intends to pursue any science, nay, anyone intends to pursue any discipline dealing with numbers.

He has several other books, all of which I intend to read as I was virtually unable to put down the book; I was constantly floored by the myriad examples of strong and weak graphics alike. He also published a book by his mother that I happened to encounter recently via Cool Tools.

I’ll close with a brief excerpt from his book with which I was taken:

Words and pictures belong together. Viewers need the help that words can provide. Words on graphics are data-ink, making effective use of the space freed up by erasing redundant and non-data-ink. It is nearly always helpful to write little messages on the plotting field to explain the data, to label outliers and interesting data points, to write equations and sometimes table son the graphic itself, and to integrate the caption and legend into the design so that the eye is not required to dart back and fort between textual material and the graphic.

Play

The various dailies I read have all been covering a VW program called The Fun Theory. It’s a contest and entries are supposed to provide evidence that making things fun can influence peoples’ behavior (presumably they mean to influence it positively).

For example, to encourage people to recycle bottles and cans more, a group turned a recycling receptacle into a “Whack-A-Mole” game of sorts. Or mounting giant piano keys (like in the movie Big) on stairs to encourage people to walk up the stairs rather than use the adjacent escalator. The site provides a lot of great videos and statistics:

I’ve mentioned Luis von Ahn before (incidentally he’s the man behind CAPTCHAs - the distorted text websites sometimes ask you to type in). His area of research is human computation, which generally takes the form of turning a repetitive or boring task into a really truly enjoyable game. Sure, it’s advice one’s mother has given them a hundred times, but how many times have you washed the floor with scrub-brush-shoes like in Pipi Longstocking? It’s non-trivial to turn something into a game, but still not a new idea, strictly speaking.

Not only is making monotonous tasks fun a great motivator, but many indicate that play is important. I’ve been watching a lot of TED Talks lately for our upcoming TEDx event, and these Fun Theory projects remind me of one I watched recently:

Projection Mapping

Projectors these days are not uncommon. People are buying projectors for their own homes, schools have projectors to plug computers into - they’re pretty widespread.

An application for them I hadn’t seen until a few weeks ago was projection mapping. I’ve run across a couple of posts about them on MAKE. Where traditionally you project onto a flat screen or wall, you can equally project onto any other geometry. If you have a representation of that geometry, one can create all manner of optical illusions. Perhaps some videos will make this clear:

The amazing thing about these is that something so impressive is going on that you don’t even notice it. You might think that the same illusion can be accomplished on a flat screen, but making use of the fact that your brain uses context to build a picture means that this can be much more impressive.

Beau Lotto talks about this in a really interesting TED Talk I saw recently. What I have in mind particularly is when he talks about the tiles in light and shadow and how we perceive their color. The buildings the above videos project onto are the tiles in this analogy, and by projecting varying levels of light onto them, we perceive a different situation from what’s actually happening, and what’s so amazing to me is that it’s so compelling and convincing, you don’t it didn’t quite soak in at first just how impressive it is.

I hope to be able to have a project like one of these projection mappings at KAUST.

Game Review: “Resistance: Fall of Man”

A couple of weeks ago, I bought my first real gaming console - PS3. Well, I had an XBox, but I traded something to a friend for it.

The reasons for getting it are complex, and maybe not great: I wanted to do some gaming, and have a dedicated piece of a equipment for all my media playback. I finally have the space and equipment such that I don’t have to watch movies and TV shows on my computer anymore, and so I wanted to make us of actually having a television.

With the box came two games of my choosing, and I chose the goriest-looking titles of those available, Killzone 2 and Resistance: Fall Of Man. I beat the game about 10 minutes ago, and here are some thoughts on it.

Background: An invading species (the Chimera - MI2 anybody? Also Greek mythology anybody?) utterly obliterated Russia and then Europe in the mid 1940’s, and now, in 1951 it looks as if Britain will suffer the same fate. An US army sergeant Hale turns out to be Britain’s only hope at destroying once and for all the Chimeran forces.

The graphics seemed pretty impressive - 720p and not laggy at any point. It’s been a while since I played any real games, so I may be easy to impress, but all the same, given the complexity if the scenes and actors, it seems very well-made.

The fights are mostly urban combat with traditional projectiles, missiles and explosives in addition to a few futuristic Chimeran weapons. The Chimeran Auger can not be stopped by hard cover, and so the gamer has to develop new skills to actively defend against enemies carrying it. There are a few types of large enemies that can be pretty challenging to take down and in the later levels, they are usually used in conjunction with smaller bogies.

For example, there’s a large flying enemy that fires explosive rounds and packets of poisonous gas while about 6-12 infantrymen take up various positions and begin firing upon you. I found it pretty challenging to combat two types of attackers simultaneously but the only thing that makes it remotely feasible is that the standard issue rifle for the Chimera (the Bullseye) has rounds that take non-negligible time to arrive. That is, they can be dodged.

An interesting weapon of Chimeran design is the Hailstorm, which releases bolts at a high rate of fire that bounce off of surfaces. In sections where Chimeran forces are contained to a small room, or better yet, a short ways down a tunnel, this weapon really shines.

I really appreciate a game that forces you to consider the strengths and weaknesses of your weapons. Resistance does this by limiting ammunition at times (although I found it pretty feasible to stay stocked up except for in some of the larger firefights). When the ammo runs low on your rifles, you’re confronted with limited tools and are forced to efficiently apply those you have. By the end, having been forced to use each weapon, you find yourself switching back and forth between all your arms for specific tasks - the sniper rifle for long approaches, the ironically named “Bullseye” for short-range dynamic fights, traditional rifle for mid to far-ranged combat, this type of grenade for this type of cover and that type for another.

I used to play a new game first on easy, then on medium and lastly on hard, but an acquaintance of mine said that he just plays them on hard right out of the box, and this is what I did. I’m not a super-experienced gamer, and the last real combat games I played were the Splinter Cell series on XBox, but even on hard I found it very manageable. There were a few sections I had to try 3-4 times to beat, but not more than that. In terms of total gameplay hours, I would estimate it took 10-15 hours.

I’m usually a fan of the slow-going tactical games like Splinter Cell where you are encouraged to not rely on your skill with firearms in order to win - you’re encouraged to gain tactical advantage and put yourself in a position that doesn’t demand a lot of skill. With each of the games in the series, after beating the games once, I made it my goal to engage as few enemies as possible and use the cover of darkness, speed, and patience to get through. While Resistance requires the same strategical placement and maneuvering, it also requires quick thinking and a quick trigger finger. Though I disliked it at the beginning, by the end, I was just hoping for the huge battles and firefights.

All in all, it was worth playing, and probably worth, say, US$40.