Exemplo n.º 1
0
def main():
    args = parseArguments(sys.argv[1:])
    if not os.path.isfile(args.fn_nifti):
        raise IOError('Could not find file: {0}'.format(args.fn_nifti))
    if not os.path.isfile(args.fn_mesh):
        raise IOError('Could not find file: {0}'.format(args.fn_mesh))
    image = nibabel.load(args.fn_nifti)
    mesh = mesh_io.read_msh(args.fn_mesh)
    vol = image.dataobj
    affine = image.affine
    if args.ev:
        logger.info('Creating tensor visualization')
        mesh = mesh.crop_mesh([1, 2, 1001, 1002])
        cond_list = [c.value for c in cond.standard_cond()]
        sigma = cond.cond2elmdata(mesh,
                                  cond_list,
                                  anisotropy_volume=vol,
                                  affine=affine,
                                  aniso_tissues=[1, 2])
        views = cond.TensorVisualization(sigma, mesh)
        mesh.nodedata = []
        mesh.elmdata = views
        mesh_io.write_msh(mesh, args.fn_out)
    else:
        logger.info('Interpolating data in NifTI file to mesh')
        if args.type == 'elements':
            ed = mesh_io.ElementData.from_data_grid(mesh, vol, affine,
                                                    'from_volume')
            mesh.elmdata.append(ed)
        if args.type == 'nodes':
            nd = mesh_io.NodeData.from_data_grid(mesh, vol, affine,
                                                 'from_volume')
            mesh.nodedata.append(nd)
        mesh_io.write_msh(mesh, args.fn_out)
Exemplo n.º 2
0

if __name__ == '__main__':
    args = parseArguments(sys.argv[1:])
    if not os.path.isfile(args.fn_nifti):
        raise IOError('Could not find file: {0}'.format(args.fn_nifti))
    if not os.path.isfile(args.fn_mesh):
        raise IOError('Could not find file: {0}'.format(args.fn_mesh))
    image = nibabel.load(args.fn_nifti)
    mesh = gmsh.read_msh(args.fn_mesh)
    vol = image.dataobj
    affine = image.affine
    if args.ev:
        logger.info('Creating tensor visualization')
        mesh = mesh.crop_mesh([1, 2, 1001, 1002])
        cond_list = [c.value for c in cond.standard_cond()]
        sigma = cond.cond2elmdata(mesh,
                                  cond_list,
                                  anisotropy_volume=vol,
                                  affine=affine,
                                  aniso_tissues=[1, 2])
        views = cond.TensorVisualization(sigma)
        mesh.nodedata = []
        mesh.elmdata = views
        gmsh.write_msh(mesh, args.fn_out)
    else:
        logger.info('Interpolating data in NifTI file to mesh')
        ed = gmsh.ElementData.from_data_grid(mesh,
                                             vol,
                                             affine,
                                             'from_volume',