mirror of
https://github.com/stevenrobertson/cuburn.git
synced 2025-02-05 11:40:04 -05:00
Small fixups
This commit is contained in:
parent
44869cc9ea
commit
f3c2186137
@ -11,7 +11,7 @@ from scipy.ndimage.filters import gaussian_filter1d
|
||||
import spectypes
|
||||
import specs
|
||||
from use import Wrapper
|
||||
from util import get, json_encode, resolve_spec
|
||||
from util import get, json_encode, resolve_spec, flatten, unflatten
|
||||
import variations
|
||||
|
||||
def node_to_anim(node, half):
|
||||
@ -26,11 +26,11 @@ def node_to_anim(node, half):
|
||||
|
||||
def edge_to_anim(gdb, edge):
|
||||
edge = resolve(gdb, edge)
|
||||
src, osrc = _split_ref_id(edge.link.src)
|
||||
dst, odst = _split_ref_id(edge.link.dst)
|
||||
src = apply_temporal_offset(resolve(gdb, src), osrc)
|
||||
dst = apply_temporal_offset(resolve(gdb, dst), odst)
|
||||
return blend(src, dst, edit)
|
||||
src, osrc = _split_ref_id(edge['link']['src'])
|
||||
dst, odst = _split_ref_id(edge['link']['dst'])
|
||||
src = apply_temporal_offset(resolve(gdb, gdb.get(src)), osrc)
|
||||
dst = apply_temporal_offset(resolve(gdb, gdb.get(dst)), odst)
|
||||
return blend(src, dst, edge)
|
||||
|
||||
def resolve(gdb, item):
|
||||
"""
|
||||
@ -46,16 +46,16 @@ def resolve(gdb, item):
|
||||
items = map(flatten, go(item))
|
||||
out = {}
|
||||
|
||||
for k in set(ik for i in items for ik in i):
|
||||
sp = _resolve_spec(spec, k)
|
||||
for k in set(ik for i in items for ik in i.keys()):
|
||||
sp = resolve_spec(spec, k.split('.'))
|
||||
vs = [i.get(k) for i in items if k in i]
|
||||
# TODO: dict and list negation; early-stage removal of negated knots?
|
||||
if is_edge and isinstance(sp, (Spline, List)):
|
||||
if is_edge and isinstance(sp, (spectypes.Spline, spectypes.List)):
|
||||
r = sum(vs, [])
|
||||
else:
|
||||
r = vs[-1]
|
||||
out[k] = r
|
||||
return unflatten(out)
|
||||
return unflatten(out.items())
|
||||
|
||||
def _split_ref_id(s):
|
||||
sp = s.split('@')
|
||||
|
@ -105,7 +105,7 @@ def make_symm_xforms(kind, offset):
|
||||
def convert_xforms(flame):
|
||||
xfs = dict(enumerate(map(convert_xform, flame['xforms'])))
|
||||
if 'symmetry' in flame:
|
||||
xfs.update(make_symm_xforms(float(flame['symmetry']), len(xfs)))
|
||||
xfs.update(make_symm_xforms(flame['symmetry'], len(xfs)))
|
||||
return xfs
|
||||
|
||||
pair = lambda v: dict(zip('xy', map(float, v.split())))
|
||||
|
@ -14,7 +14,7 @@ def get(dct, default, *keys):
|
||||
return default
|
||||
return dct
|
||||
|
||||
def flatten(dct, ctx=()):
|
||||
def flatten(src):
|
||||
"""
|
||||
Given a nested dict, return a flattened dict with dot-separated string
|
||||
keys. Keys that have dots in them already are treated the same.
|
||||
@ -22,14 +22,15 @@ def flatten(dct, ctx=()):
|
||||
>>> flatten({'ab': {'xy.zw': 1}, 4: 5}) == {'ab.xy.zw': 1, '4': 5}
|
||||
True
|
||||
"""
|
||||
|
||||
def go(dct, ctx=()):
|
||||
for k, v in dct.items():
|
||||
k = str(k)
|
||||
if isinstance(v, dict):
|
||||
for sk, sv in flatten(v, ctx + (k,)):
|
||||
for sk, sv in go(v, ctx + (k,)):
|
||||
yield sk, sv
|
||||
else:
|
||||
yield '.'.join(ctx + (k,)), v
|
||||
return dict(go(src))
|
||||
|
||||
def unflatten(kvlist):
|
||||
"""
|
||||
|
8
main.py
8
main.py
@ -40,7 +40,7 @@ def save(out):
|
||||
def main(args, prof):
|
||||
import pycuda.autoinit
|
||||
|
||||
gdb = db.open(args.genomedb)
|
||||
gdb = db.connect(args.genomedb)
|
||||
if os.path.isfile(args.flame) and (args.flame.endswith('.flam3') or
|
||||
args.flame.endswith('.flame')):
|
||||
with open(args.flame) as fp:
|
||||
@ -50,7 +50,7 @@ def main(args, prof):
|
||||
warnings.warn('%d flames in file, only using one.' % len(flames))
|
||||
gnm = convert.flam3_to_node(flames[0])
|
||||
else:
|
||||
gnm = gdb.open(args.flame)
|
||||
gnm = gdb.get(args.flame)
|
||||
|
||||
if gnm['type'] == 'node':
|
||||
gnm = convert.node_to_anim(gnm, half=args.half)
|
||||
@ -69,7 +69,7 @@ def main(args, prof):
|
||||
for i, t in enumerate(times)]
|
||||
if args.end:
|
||||
frames = frames[:args.end]
|
||||
frames = frames[args.start::prof['skip']+1]
|
||||
frames = frames[args.start::gprof.skip+1]
|
||||
if args.resume:
|
||||
m = 0
|
||||
if args.flame.name != '-':
|
||||
@ -77,7 +77,7 @@ def main(args, prof):
|
||||
frames = (f for f in frames
|
||||
if not os.path.isfile(f[0]) or m > os.path.getmtime(f[0]))
|
||||
|
||||
w, h = prof['width'], prof['height']
|
||||
w, h = gprof.width, gprof.height
|
||||
gen = rmgr.render(gnm, gprof, frames)
|
||||
|
||||
if not args.gfx:
|
||||
|
Loading…
Reference in New Issue
Block a user