class PatientDataLoader:
    def __init__(self, directory=None, case=None):
        self.directory = directory
        self.case = os.path.join(self.directory, case)
        self.acpc = os.path.join(self.case, 'acpc')
        self.mni_aff = os.path.join(self.case, 'mniE')
        self.mni_f3d = os.path.join(self.case, 'f3dE')
        self.medicalImages = MedicalImages.MedicalImages(main=self.case,
                                                         acpc=self.acpc,
                                                         mni_aff=self.mni_aff,
                                                         mni_f3d=self.mni_f3d)
        self.electrodes = Electrodes.Electrodes(main=self.case,
                                                acpc=self.acpc,
                                                mni_aff=self.mni_aff,
                                                mni_f3d=self.mni_f3d)
        self.templates = TemplateImageLoader.TemplateImageLoader(
            datasets=self.directory)
Example #2
0
class PatientDataGenerator:
    def __init__(self, directory=None, case=None):
        self.directory = directory
        self.case = os.path.join(self.directory, case)
        self.acpc = os.path.join(self.case, 'acpc')
        self.mni_aff = os.path.join(self.case, 'mniE')
        self.mni_f3d = os.path.join(self.case, 'f3dE')
        self.medicalImages = MedicalImages.MedicalImages(main=self.case,
                                                         acpc=self.acpc,
                                                         mni_aff=self.mni_aff,
                                                         mni_f3d=self.mni_f3d)
        self.electrodes = Electrodes.Electrodes(main=self.case,
                                                acpc=self.acpc,
                                                mni_aff=self.mni_aff,
                                                mni_f3d=self.mni_f3d)
        self.templates = TemplateImageLoader.TemplateImageLoader(
            datasets=self.directory)
        self.surfaces = Surfaces.Surfaces()
        self.filesystem = FileSystem.FileSystem()

        # load electrodes
        plan = self.electrodes.load(type='plan', suffix='i', space='patient')
        impl = self.electrodes.load(type='impl', suffix='i', space='patient')
Example #3
0
from Framework.Preprocessing import TemplateImageLoader
from Framework.Visualisation import VTKRenderer

datasets = 'E:\\UCL\\Backup\\medic-biomechanics\\Datasets\\BendingJournal\\datasets'
space = 'mni_aff'  # 'patient', 'mni_f3d'

''' Pre-processed patient data '''
pickle_file = open('../Data/data_'+space+'.npy', "rb")
predata = pickle.load(pickle_file)
pickle_file.close()
# cases_generator = CaseGenerator.CaseGenerator()
# cases = cases_generator.get_all()

''' Surfaces '''
gif_ep, gif_tp = [], []
templates = TemplateImageLoader.TemplateLoader(datasets=datasets)
templates.open_mni_images()
surfaces = Surfaces.Surfaces()

''' Visualisation'''
renderer = VTKRenderer.VTKRenderer()
renderer.create_vtk_renderer()

# iterate through cases
N = 0
N_da = 0
for i in range(len(predata['case'])):
    ''' Pre-computed data '''
    plan = predata['plan'][i]
    impl = predata['impl'][i]
    local_delta = predata['local_delta'][i]
class SyntheticDataGenerator:
    
    def __init__(self, directory=None, case=None):
        self.directory = directory
        self.case = os.path.join(self.directory, case)
        self.templates = TemplateImageLoader.TemplateImageLoader(datasets=self.directory)
Example #5
0
def main():

    # select regions of interest
    plangen = PlanGenerator.PlanGenerator()
    # plangen.ep_superior_frontal_gyrus()
    # plangen.ep_middle_frontal_gyrus()
    # plangen.ep_inferior_frontal_orbital_gyrus()

    # plangen.ep_temporal_gyrus()
    # plangen.ep_inferior_medial_temporal_gyrus()
    # plangen.ep_superior_temporal_gyrus()

    # plangen.ep_anterior_posterior_central_gyrus()

    plangen.ep_parietal_occipital()
    # plangen.ep_parietal_lobule()
    # plangen.ep_occipital()

    print('filter: filename={} ep={} tp={}'.format(plangen.filename, plangen.ep, plangen.tp))

    # open data
    input_data = InputData.InputData(directory=data_dir, file=data_file)
    selection = input_data.search_by_region(ep=plangen.ep, tp=plangen.tp)
    print('selection', selection)

    # save selection
    pickle_file = open(os.path.join(data_dir, plangen.filename), "wb")
    pickle.dump(selection, pickle_file)
    pickle_file.close()

    ''' Visualisation '''
    renderer = VTKRenderer.VTKRenderer()
    renderer.create_vtk_renderer()

    ''' Surfaces '''
    templates = TemplateImageLoader.TemplateImageLoader(datasets=datasets)
    templates.open_mni_images()
    surfaces = Surfaces.Surfaces()
    for s in plangen.ep + plangen.tp:
        surfaces.load(directory=templates.templates_dir, image=templates.mni['GIF'], gif=s)

    # iterate through selection
    print('Selection:')
    N = 0
    for case in selection.keys():
        # index of case
        c = input_data.data['case'].index(case)
        N += len(selection[case])
        print('case={} electrodes={}'.format(case, selection[case]))

        # Pre-computed data
        plan = input_data.data['plan'][c]
        impl = input_data.data['impl'][c]
        local_delta = input_data.data['local_delta'][c]
        delta = input_data.data['delta'][c]

        # Visualisation
        if space is not 'mni_f3d':
            renderer.render_trajectories(data=plan, filter=selection[case], colour=[1.0, 1.0, 1.0], radius=0.4, opacity=0.4)
            renderer.render_trajectories(data=impl, filter=selection[case], colour=[], radius=0.4, opacity=0.4)
        renderer.render_vectorfield(data=delta, source='from', vector='u', filter=selection[case], colour=[])
        renderer.render_vectorfield(data=local_delta, source='from', vector='u', filter=selection[case], colour=[1.0, 0.0, 0.0])
        renderer.render_vectorfield(data=local_delta, source='from_dir', vector='dir', filter=selection[case], colour=[0.0, 1.0, 0.0])

    for s in list(np.unique(plangen.ep + list(np.asarray(plangen.tp)[np.isin(plangen.tp, plangen.all_eps)]))):
        if s not in list(MedicalImages.wmGif):
            renderer.render_surface(polydata=surfaces.polydata[s], colour=[1.,1.,1.], opacity=0.2)
    for s in list(np.asarray(plangen.tp)[np.isin(plangen.tp, plangen.all_eps, invert=True)]):
        if s not in list(MedicalImages.wmGif):
            renderer.render_surface(polydata=surfaces.polydata[s], colour=[0.,0.95,0.95], opacity=0.2)

    print('filter={} num_cases={} num_electrodes={}'.format(plangen.filename, len(selection.keys()), N))

    # render
    renderer.execute()