# Environment for implementing/testing Computer Graphics algorithms

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?

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.

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.

Pros...

• 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.

Cons...

• 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.

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:

bpy.app.handlers.frame_change_pre.append(run_script_on_frame)


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