Writing software to write software

Since I started my PhD in September, 2015, I have been writing a lot of code. My research project contains its fair amount of theory, but it is significantly practical and applied science, so I need to write software to test things out.

A percentage of my coding was indeed targeted at creating original software that could do something related to my research. Another significant part, however, was about automation:

Obligatory xkcd strip about automation Source: xkcd: Automation

In my case, doing applied science means I need to iterate, test and evaluate a lot of things on a daily basis. I could do the analysis by hand, or by copying-and-pasting numbers back and forth in Excel. In the short term that works perfectly well, but things start to grow and become more and more error prone in the long run.

In February 2016 I conducted an experiment involving games, facial expressions and heart rate measurements. Each participant spent, on average, 25 minutes in a gaming session, which involved playing 3 different games (two coded from scratch by myself), resting and answering questionnaires. I could be there in the room, with a notebook frantically taking notes of things. Then I would need to transcribe all that information into a spreadsheet to perform further analysis. Again the chances of misplacing numbers here and there is very real (and dangerous), so I wrote a software to run the whole experiment for me.

During the development time, I even spent a few additional precious hours to create a very simple web interface, accessible from my mobile, to monitor the experiment. That was awesome! Even though I was not in the experiment room, I could just light up my phone and see what was happening. Was the participant playing game #2? Or maybe resting? I could enter the room at the precise moment the experiment was over.

Later on I needed to analyze all the data I collected. Solution? I wrote another piece of software to visualize the data (since everything was custom recorded):

Dashboard to visualize data

A few months after the experiment, I started a paper about it. I needed several different chunks of data and reports, so I distilled several command line utilities (e.g. analyze and hr2db) that helped me obtain what I wanted. As a side note and honest advice, don’t write crappy and/or undocumented software just because you are the sole user (at the moment). Doing a PhD often involves switching contexts pretty frequently, so at times I only re-used (or coded again) a utility 2 months after its creation. Despite being the author of the tool, it is fair to say I remembered nothing about it after 2 months doing other things. The tool might as well be considered to be written by someone else.

That’s the reason why I tried my best to make the tools at least UX-acceptable with a minimum amount of documentation:

Usage:
 php analyze.php [<subjectId>|<firstId>:<lastId>] [options]

Options:
 --report         Prints the processing as a report.

 --csv <file>     Saves the processing as a CSV file defined
                  by <file>.

 --export <file>  Exports all HR entries as a file defined
                  by <file>.

A few months ago, I had to analyze a database of 530 videos, all containing BDF files unsupported by my software. I needed only the HR from those BDF files. I found several different programs that could convert the files to me, but they required manual interaction with a GUI. Solution? I wrote BDFextractor to extract the HR from BDF files using the command line. Now I could run (another) little software on the database and export the HR from all those 530 files. Victory!

I have been writing lots of R code lately, to perform statistical analysis and plot some charts. I can confidently say I wrote more multi-use support software in the past year than I thought I would.

Writing that much software might be seen as a waste of time, after all there are plenty of solutions out there for virtually everything. Every move demands time, though, be it learning (or developing) a new tool. Time is an incredibly precious resource, so I always choose the option that better accounts for that. Every time I have to write a small tool, I remember the advice from an old saying about chopping off of a huge tree: if you have to do it, you better have the right tools and be sure they are as sharp as they could be. That’s a fact.

cvui 1.1.0 is out!

I am pleased to inform that version 1.1.0 of cvui is out! cvui is a simple UI lib built on top of OpenCV drawing primitives. Here is an image to show the new features:

cvui

This release is backward compatible, so users of the lib should be able to upgrade by just dropping the new files into their projects. There ara few bug fixes as well as some pretty cool new features.

One of the most annoying tasks when building UI is to calculate where each component should be placed on the screen. Version 1.1.0 brings a set of methods that abstract the process of positioning components, so you don’t have to think about assigning a X and Y coordinate. Instead you just add components and cvui will place them as you go.

An example is the beginRow() function to start a group of elements. After beginRow() has been called, all subsequent component calls don’t have to specify the frame where the component should be rendered nor its position. The position of the component will be automatically calculated by cvui based on the components within the group.

All components are placed side by side, from left to right. E.g.

beginRow(frame, x, y, width, height);

text("test");
button("btn");

endRow();

Rows and columns can be nested, so you can create columns/rows within columns/rows as much as you want:

beginRow(frame, x, y, width, height);

text("test");
button("btn");
	 
beginColumn();
text("column1");
text("column2");
endColumn();

endRow();

I am pretty happy with the new API and the possibilities it brings, specially because it means less code to achieve more things. That’s always a thing to celebrate =)

cvui - A very simple UI lib for OpenCV

I have been working a lot with OpenCV and C++ lately. After spending a great amount of time waiting for things to compile (so I could see my changes), I decided to improve my workflow. I decided to make changes in runtime, so I could tweak things without the need to recompile the whole project.

I immediately faced a problem: how to quickly and easily create GUI with OpenCV. The OpenCV lib has complete support for Qt (which is great for UI creation), but you need to compile OpenCV with such Qt support. If you don’t like that (or you have OpenCV compiled without Qt), you can enable OpenGL and use any of the awesome GUI out there, e.g. imgui. If you decide for that, you add the OpenGL dependency to your (probably already complex) project.

I didn’t have Qt available and I didn’t want to use OpenGL, so I distilled cvui. cvui is a (very) simple UI lib built on top of OpenCV drawing primitives. All the rendering is made using OpenCV, by calling cv::rectangle(), for instance. Here is a picture of it working:

cvui

The API is heavily inspired by imgui. The calls are all C-like, so no classes, objects nor OOP. I have nothing against that, I just wanted an extremely simple way of creating UI for my application (one line written, one thing on the screen).

At the moment, the API includes a small set of components: button, checkbox, window and counter. I will probably add more components in the near future. For more information, visit the cvui repository on Github. The code is MIT licensed.

Goodbye Wordpress, hello Github Pages!

It took a lot more than I wanted it to take, but I finally concluded the move from Wordpress to Github Pages! Finally my personal website (this one you are reading) runs in a static fashion, without PHP, databases and all that useful-but-not-for-my-personal-website stuff.

I enjoyed Wordpress from the very beginning, it has a nice set of features and helps you write and manage content. During the last year or so, however, it was standing in my way. The template I was using was already showing signs of aging, some things were breaking and, last but not least, I had to pay constant attention to security patches/updates. Not anymore! Now I can use my daily code editor to write content using Markdown and publish it to the magic clouds of Github with a git push command.

I hope the move will encourage me to blog more often, which is something I have being trying to do lately. Time will tell if that worked or not :)

My 2013 in review

Another years has gone by. I wrote my new year’s resolutions for 2013 almost a year ago, but it still feels like yesterday. The last days of 2013 seem the perfect time to review the year and check if I collected accomplishments or lame excuses.

Without further ado, down to the goals:

Improve my skills as an indie game developer. I already joined OneGameAMonth and will try to release 12 games in 2013. A pharaonic task, but the fun is proportional. It is not about working until faint, but learning how to avoid code bloat and feature creep (two of my most significant problems as a developer).

Depending on the point of view, this was completely or partially accomplished. I did not release 12 games in 2013, I did 6 instead. 1GAM was amazing and I’ve learned a lot from it. The “12 games” thing was just a guide, not a goal per se.

As I explained here, my gamedev year was awesome. I can say I improved as an indie game developer, a LOT.

Exercise! I stopped running with my friends (in 2011, I ran a 10km marathon, that felt great!). I want to start jogging at least. I also want to get back on track on my push-ups training. I will buy a dumbbell too.

Partially accomplished. I got on track on my push-ups and the jogging, but I didn’t follow a strict and regular routine.

I trained for a marathon, signed up for it and was ready to run. However I’m too dump to pay attention to the payment due date, so my registration was invalidated :(Damn! It was a fun and short 5km marathon that I will have to postpone to 2014.

I didn’t buy the dumbbell.

Regularly write tutorials about game development at As3GameGears. Since I started the blog, I just post about tools. It’s time to improve the content and write about game related stuff.

Again, depending on the point of view, I completely or partially accomplished this one. I did wrote several gamedev tutorials, but for the Game Development section of the Tuts+ network, not As3GameGears.

On the other hand, I kick started a new series named game dissection. It’s not a tutorial, but it’s a start.

Write a book about game development.

Not accomplished. Judging by my work in March and April, I thought I would accomplish this one. I wrote two chapters, then I totally dropped the work.

My university classes consumed a significant amount of time, so I was not able to write chapters. I was planning to write and use the texts in my gamedev classes, but that didn’t happen either. Too bad.

Contribute to an open source project.

Accomplished! I worked on Flixel Community, fixing bugs and planning new features. By the end of November we released version 2.56, the very first Flixel release under the community label.

We attracted more developers to the project, that was amazing! I will continue my efforts to make Flixel Community a great game engine.

Found a Jr tech company at UFFS.

Not quite there yet. I mentored students regarding the tech company, which was founded and named FronteiraTec. In the founding process, however, we skipped all legal and governamental steps, so the company exists, but in a “virtual”.

In that situation, the company is not able to sign any contract or sell anything, but it didn’t prevent the students from planning and working. They worked on several projects, covering subjects as games, mobile apps and hardware. They even made an arcade machine.

The only missing piece of this puzzle is the legal papers and the official registration in the government records.

Research. It’s been two years since I stopped working on my master’s dissertation. I want to start working on it again, researching and publishing papers.

Not accomplished. I didn’t have the time (nor the will) to keep this up. I co-authored a paper about procedural generation of canyons, though. The paper is in the works, but it will be published in 2014.

Find inner patience. Sometimes I get really upset by small things and it is not helping. I will try to keep myself calm and constant during 2013. It will make me a better husband, professor and person.

I don’t know how to classify this one. I made some great improvements, but I didn’t reach the point where I wanted to be.

Finding inner patience is harder than I thought. It requires a lot of energy to take a deep breath and ignore the things that upset you. The jogging helped keep things cool, so I think I’m on track for this goal in 2014.

Release at least one side project. I have lots of ideas, but I never manage to work on it and release something.

Not accomplished. I joined my friends on a project, we had some meetings, but we were not able to launch anything. I had some ideas too, but I was short on time to make them come true.

Ok, that was the review!

Looking back and checking all those accomplishments, I can say 2013 was an outstanding year! Goals keep me motivated, even if I’m not able to accomplish them all. I managed to accomplish much more than I expected, which was great!

A new year is just around the corner. It’s time to write some new goals again 😀