From 860d7b2fadb901eea3a55c32d02b7870977943e2 Mon Sep 17 00:00:00 2001 From: Steven Robertson Date: Sat, 11 Sep 2010 13:10:41 -0400 Subject: [PATCH] Add xforms and variations. --- cuburn/render.py | 56 +++++++++++++++++- cuburn/variations.py | 133 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 cuburn/variations.py diff --git a/cuburn/render.py b/cuburn/render.py index 3682960..35357be 100644 --- a/cuburn/render.py +++ b/cuburn/render.py @@ -1,4 +1,6 @@ +import sys import math +import re from ctypes import * from cStringIO import StringIO import numpy as np @@ -9,12 +11,45 @@ from fr0stlib.pyflam3.constants import * from cuburn.cuda import LaunchContext from cuburn.device_code import * +from cuburn.variations import Variations Point = lambda x, y: np.array([x, y], dtype=np.double) class Genome(pyflam3.Genome): pass +class XForm(object): + """ + A Python structure (*not* a ctypes wrapper) storing an xform. There are + a few differences between the meaning of properties on this object and + those of the C version; they are noted below. + """ + def __init__(self, **kwargs): + read_affine = lambda c: [[c[0], c[1]], [c[2], c[3]], [c[4], c[5]]] + self.coefs = read_affine(map(float, kwargs.pop('coefs').split())) + if 'post' in kwargs: + self.post = read_affine(map(float, kwargs.pop('post').split())) + # TODO: more verification, detection of unknown variables, etc + for k, v in kwargs.items(): + setattr(self, k, float(v)) + + # ctypes was being a pain. just parse the string. + @classmethod + def parse(cls, cp): + flame_str = flam3_print_to_string(byref(cp)) + xforms = [] + for line in flame_str.split('\n'): + if not line.strip().startswith('