I need to code up a computer graphics algorithm for Surface Registration.

Briefly surface registration is the process of finding "optimal" one-one correspondence between surfaces, where the meaning of optimal depends on the specific problem.

I do not have much experience with Computer Graphics software, and so I was looking around the web for a good software environment to code my algorithm up in.

One promising option I hit upon was Blender, which to my delight also has a Python interface to it.

My questions are

  1. Is Blender + Python a good software environment for implementing and testing computer graphics algorithms?

  2. If not, are there better alternatives to it (hopefully using a Pythonic interface)?

  3. Are there any particular points from your experience which I should keep in mind while using Blender (or whatever package you recommend) while implementing/testing my algorithm?


Brief Answer

  1. Yes (but it depends, read on...)
  2. Not that I know of, you can use PyOpenGL, NumPy etc together though.
  3. Yes, automate testing your algorithm. while interactive tools like blender are nice, try to setup your workflow so you can spend most of your time programming (rather then pressing buttons in blender), This is well supported but not necessarily obvious at first.

Longer Answer

There are pros and cons with using Blender for testing cg algorithms,

Of course it depends entirely on what you try to solve however I've found it very useful in some cases, even developing Blender its self I sometimes test algorithms in blender-python first before porting to C.


  • the viewport for navigation and inspecting results.
  • meshes can be created to visualize data without having to write drawing code, they have vertex colors UV's and any number of weight's per vertex, so you can store useful data here.
  • mathutils python module, handy modules for graphics math, written in C...
  • other modules (you're not limited to blender modules), see NumPy.
  • realtime updates, I don't want to over emphasize this since it can encourage not thinking enough and just guessing, BUT - it can still be valuable.
  • the power of a full 3d application at your disposal, so you can spit out ray-traced images, run operations like convex-hull or booleans on and see the result.
  • format support, this may seem uninteresting but being able to load data from all sorts of sources can save you time writing your own loaders, with support for animation, mesh formats, image formats, even sound.


  • Python is slow, for algorithms that require speed such as image manipulation or very large data-sets, I wouldn't recommend it, though for testing, speed can sometimes be overlooked so its not useless either for this task and if you are clever you could use NumPy to load in larger datasets.
  • Blender has limited data support, so for example, colored-point-clouds and user-defined-voxel structures are not supported, and nurbs only have limited support. If you want to display data that happens not to fit well into a mesh, meta-balls, curve ... etc, then using blender becomes less of an advantage Note that Python can call OpenGL directly, but its not that convenient.

Listed some example usage...

Console for fast feedback

You have access to the python console which can manipulate data and get fast feedback, for testing small snippets I find it quite handy, There is also the MathVis addon you can use to show points, lines, matrix types etc in the viewport.

If you come up with something useful you can Copy as Script from the menu, which strips out the '>>> ' prefix to make the input useful as a script to further develop elsewhere.

Realtime Updates

Blender can easily be setup to run your code in a loop, and update the viewport.

Here is an example, After running this script, play the animation.

import bpy
import os

filepath = "/path/to/my_script.py"

def run_script_on_frame(scene):
    global_namespace = {"__file__": filepath, "__name__": "__main__"}
    with open(filepath, 'rb') as file:
        exec(compile(file.read(), filepath, 'exec'), global_namespace)


Ability "Use" Your Algorithm

Again, this is only useful in some cases but you may want to make some testing code that uses mouse input for example, maybe to change the values the algorithm (to check for jitter) for example and to get a feel for how the algorithm works.

For example in the case you give, you could have 2 meshes and move them, drawing a line between the 2, constantly updating.

This can be done by writing an Operator, or a Modal Operator, see templates from the text editor.

Run outside of Blender

Having to use Blender can be a hassle and you may want to stay in your python editor, in some cases I've setup Blender to render output, used with an image viewer that auto-refreshes, it can be quite quick to execute the script and see the result without touching blenders UI. See Tip: Don't Use Blender


ideasman42's answer is great. I'd also add that you could look at the Visualization Toolkit (VTK) as an alternative. It also has Python bindings, and has more of a pipeline approach to data processing, which might make it faster for certain things. It supports many data types, including point clouds and 3D grids. The downside is that, while it has support for manipulating the view and you can probably build tools with it, it doesn't have the rich interactive toolset that Blender does.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.