Skip to content

Commit

Permalink
made changes to fix issues gallantlab#398 gallantlab#400
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiyaabdi committed Sep 16, 2021
1 parent af36f2f commit 41f00ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions cortex/blender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _call_blender(filename, code, blender_path=default_blender):
tf.flush()
sp.check_call([w.encode() for w in shlex.split(cmd)],)

def add_cutdata(fname, braindata, name="retinotopy", projection="nearest", mesh="hemi"):
def add_cutdata(fname, braindata, hemi, name="retinotopy", projection="nearest", mesh="hemi"):
"""Add data as vertex colors to blender mesh
Useful to add localizer data for help in placing flatmap cuts
Expand All @@ -62,11 +62,11 @@ def add_cutdata(fname, braindata, name="retinotopy", projection="nearest", mesh=
"""
if isinstance(braindata, dataset.Dataset):
for view_name, data in braindata.views.items():
add_cutdata(fname, data, name=view_name, projection=projection, mesh=mesh)
add_cutdata(fname, data, hemi,name=view_name, projection=projection, mesh=mesh)
return
from matplotlib import cm
braindata = dataset.normalize(braindata)
mapped = braindata.map(projection)
mapped = braindata.map(briandata.subject)
left = mapped.left
right = mapped.right

Expand All @@ -83,22 +83,27 @@ def add_cutdata(fname, braindata, name="retinotopy", projection="nearest", mesh=

p.pack_string(mesh)
p.pack_string(name)
p.pack_array(lcolor.ravel(), p.pack_double)
p.pack_array(rcolor.ravel(), p.pack_double)

if hemi=='lh':
dat2add=lcolor
else:
dat2add=rcolor

p.pack_array(dat2add.ravel(), p.pack_double)

with tempfile.NamedTemporaryFile() as tf:
tf.write(p.get_buffer())
tf.flush()
code = """with open('{tfname}', 'rb') as fp:
u = xdrlib.Unpacker(fp.read())
mesh = u.unpack_string().decode('utf-8')
name = u.unpack_string().decode('utf-8')
left = u.unpack_array(u.unpack_double)
right = u.unpack_array(u.unpack_double)
lcolor = blendlib._repack(left)
rcolor = blendlib._repack(right)
print(len(lcolor), len(rcolor))
blendlib.add_vcolor((lcolor, rcolor), mesh, name)
hemdat= u.unpack_array(u.unpack_double)
ccolor = blendlib._repack(hemdat)
blendlib.add_vcolor(ccolor, mesh, name)
""".format(tfname=tf.name)

print(code)
_call_blender(fname, code)

return
Expand Down
2 changes: 1 addition & 1 deletion cortex/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def cut_surface(cx_subject, hemi, name='flatten', fs_subject=None, data=None,
blender.fs_cut(fname, fs_subject, hemi, freesurfer_subject_dir)
# Add localizer data to facilitate cutting
if data is not None:
blender.add_cutdata(fname, data, name=data.description)
blender.add_cutdata(fname, data, hemi,name=data.description)
blender_cmd = options.config.get('dependency_paths', 'blender')
sp.call([blender_cmd, fname])
patchpath = freesurfer.get_paths(fs_subject, hemi,
Expand Down

0 comments on commit 41f00ef

Please sign in to comment.