[Simnibs-discuss] Skull transparency in gmsh

Axel Thielscher axelt at drcmr.dk
Fri Feb 12 21:56:07 CET 2021


SimNIBS already shows the electrodes transparently for each simulation 
result. Attached is a script that adds the transparent skin to that. To 
run it, open a SimNIBS prompt and start python there. You need to update 
the filename of the mesh in the script.



On 2/8/2021 12:25 PM, DXA869 at student.bham.ac.uk wrote:
> Dear users,
> Is there a way to set the skull to transparent in GMSH?
> I would like to be able to show electrodes and the brain under the 
> skull, in a similar way as in the photo I’ve attached.
> Thank you a lot!
> Davide Aloi,
> Doctoral Researcher,
> Centre for Human Brain Health – University of Birmingham
> _______________________________________________
> Simnibs-discuss mailing list
> Simnibs-discuss at drcmr.dk
> https://mailman.drcmr.dk/mailman/listinfo/simnibs-discuss

Dr. Axel Thielscher
Associate Professor
Danish Research Center for Magnetic Resonance
Copenhagen University Hospital Hvidovre
DK-2650 Hvidovre, Denmark
Department of Health Technology
Technical University of Denmark
DK-2800 Kgs. Lyngby

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.drcmr.dk/pipermail/simnibs-discuss/attachments/20210212/481913b2/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fpddepomkmnahjol.png
Type: image/png
Size: 347244 bytes
Desc: not available
URL: <https://mailman.drcmr.dk/pipermail/simnibs-discuss/attachments/20210212/481913b2/attachment-0001.png>
-------------- next part --------------
# -*- coding: utf-8 -*-
Created on Fri Feb 12 20:53:27 2021

@author: axthi

from simnibs import mesh_io

fname_msh = 'ernie_TDCS_1_scalar.msh'

# extract skin from mesh and write as .geo-file
m = mesh_io.read_msh(fname_msh)
m = m.crop_mesh(tags=1005)
fname_geo = fname_msh[:fname_msh.rfind('_')]+'_skin.geo'
mesh_io.write_geo_triangles(m.elm[:,:3]-1, m.nodes[:], fname_geo, name='skin')
# add skin-geo file to .opt-file so that is is auto-loaded and displayed
last_view_nr = 2 # for standard simulation of E and normE; otherwise adapt
fname_opt = fname_msh+'.opt'
with open(fname_opt, 'r+') as fp:
    content = fp.read()  

    content = "Merge \""+fname_geo+"\";\n"+content
    content = content.replace('View['+str(last_view_nr)+']',
    content += "View["+str(last_view_nr)+"].Visible = 1;\n"
    content += "View["+str(last_view_nr)+"].ShowScale = 0;\n"
    content += "View["+str(last_view_nr)+"].ColormapNumber = 8;\n"
    content += "View["+str(last_view_nr)+"].ColormapAlpha = 0.3;\n"
    fp.seek(0, 0)

More information about the Simnibs-discuss mailing list