Kami 2 Solver

I love the game Kami on my iPhone, by State Of Play games. When they brought out the sequel, Kami 2, I was very excited! But it proved to be a lot harder than the original, and before no time I was stuck and had run out of hints. So I wondered if it was possible to solve this puzzle with a program. I’d written myself a solver for Soduku in C# using the algorithms I used in my head to solve the problems. I figured I could do something similar with Kami. The first solver I found was by…
Read more →

Dependency Injection via Constructor Injection

The most common way of implementing Dependency Injection (DI) is to use Constructor Injection with classes. Let’s suppose we have a Customer class defined as follows:

We can create a service to fetch customer records and define an interface for this service:

An actual implementation of the DataService class could look like this:

Obviously the real thing would fetch the real records from somewhere, e.g. a database. When we fetch these records we’d like to put them in a Customer repository. Whenever we create an instance of the CustomerRepository class we’ll pass in the dependency to the…
Read more →

Unity – Constructors with Parameters

Microsoft Unity is a great library to use for a dependency injection container. It has support for constructor, property, and method call injection. Typically you’ll use constructor injection. I wanted to use it for a class whose constructor took parameters. Here’s an example I’ve created to show what I wanted to do: First I have an interface for logging – ILogger:

Then I have an actual class that implements this interface – FileLogger:

In my program I create the Unity container. I then want to register my FileLogger class as an implementation of the ILogger interface. This part…
Read more →

Kinect Point Cloud Normals Rendering – Part 4

In this post I’ll create a WPF front-end to the C++ template code I’ve been using so far. I’ll use a CLR wrapper to achieve this. The first step is to create a WPF project. I like to use MVVM Light Toolkit for my WPF projects. I’ve installed the Visual Studio plugin so it comes up as on option when I’m creating a new project. I started by created a project called DepthViewer2D: Once I created this project I added a new project to the solution called DepthImageRenderer. This is a C++/CLR class library project. You’ll find it under “Other…
Read more →

Kinect Point Cloud Normals Rendering – Part 3

In this post I’ll add to further methods for calculating the normals of the depth point cloud. In the previous point I showed how to calculate the normal of a point using the point directly above and the point directly to the left. We can obtain smoother normals by looking at 4 points that surround – those that are above, below, to the left, to the right. Here’s a picture showing the grid of the points that surround our current point. I’ve labelled the points we’ll be considering as A, B, C and D: We calculate the normals of each…
Read more →

Kinect Point Cloud Normals Rendering – Part 2

Having shown you how to create a 3D point cloud from a Kinect depth map in Part 1 I will now go on to explain how to calculate the normals for that point cloud and then render that in 2D by mapping the (x,y,z) normal vector values to R-G-B channel values. To calculate the normal for a given 3D point in the point cloud we will use the point directly to the left of it (i.e. at the point (x-1,y)) and the point directly above it (i.e. at the point (x,y-1)). We will create a triangle of the 3 points…
Read more →

Kinect Point Cloud Normals Rendering – Part 1

That’s a bit of a mouthfull as a title – but it encapsulates all the things I’m hoping to cover in this post and the end goal. The first step is to create a point cloud using the depth data that we get from the Kinect camera. To do this we’ll need the calibration details we obtained previously (see ) and the geometry of the “Pinhole Camera”. If you look up the Wikipedia article on the Pinhole camera model you will find that this model describes the mathematical relationship between the coordinates of a 3D point and its projection onto…
Read more →

Kinect V2 Depth Camera Calibration

I wanted to calibrate my Kinect V2 Depth Camera in order to obtain it’s intrinsics. With those I can then create point clouds, normals, etc.. It’s the starting place for a lot of interesting computer vision things. We can calibrate the Kinect V2 Depth Camera in a similar way to how we would calibrate the Colour Camera. There’s an excellent program called GML C++ Camera Calibration Toolbox which is just what you need to do the calibration. It’s produced by the Graphics and Media Lab at Lomonosov Moscow State University. Once you’ve downloaded and installed the toolkit it needs a…
Read more →

Polymorphism and Abstract in C#

Let’s say you want to define a base class that other classes will inherit from:

We want to make sure that everything that inherits from this class will implement its own version of the CreateBrushes() method. If this method isn’t implemented then we will get a runtime exception every time our inherited class is instantiated. This is one way of ensuring that inherited classes provide an implementation of a method. However, we only find out the problem at runtime. A better solution would be to get an error at compile time. This is where the abstract keyword comes in….
Read more →

Parallel Processing and Lambda expressions in C++11 – Part 2

If you’ve made the changes to the code from Part 1 then you already have code that should be working dramatically faster. In the next steps I’m going to use C++ templates to further enhance the code. I love C++ templates! I try and use them whenever I can. One of the great things about them is that only the code that is actually used gets generated and compiled. And with C++11 you’ve got the ability to use lambda functions in templates. This is useful if you’re using STL. It’s also useful for us here. Before I do that I…
Read more →

1 2