예제 #1
0
def display_matrices(filenames, target, hemi, surface):
    from mayavi import mlab
    from surfer import Brain
    print '\n'.join(filenames)
    for name in filenames:
        try:
            corrmat = sio.loadmat(name)['corrmat']
        except:
            try:
                corrmat = np.load(name)['corrmat']
            except:
                try:
                    corrmat = np.load(name)['arr_0']
                except:
                    try:
                        corrmat = np.load(name)['avgcorr']
                    except:
                        h5file = openFile(name, 'r')
                        corrmat = h5file.root.corrmat
        corrmats.append(corrmat)
    for idx, name in enumerate(filenames):
        path, name = os.path.split(name)
        br = Brain(target, hemi, surface, title=name + '-%d' % idx)
        brains.append(br)
        for brain in brains[:-1]:
            mlab.sync_camera(br._f, brain._f)
            mlab.sync_camera(brain._f, br._f)
        br._f.on_mouse_pick(picker_callback)
    mlab.show()
def display_matrices(filenames, target, hemi, surface):
    from mayavi import mlab
    from surfer import Brain
    print '\n'.join(filenames)
    for name in filenames:
        try:
            corrmat = sio.loadmat(name)['corrmat']
        except:
            try:
                corrmat = np.load(name)['corrmat']
            except:
                try:
                    corrmat = np.load(name)['arr_0']
                except:
                    try:
                        corrmat = np.load(name)['avgcorr']
                    except:
                        h5file = openFile(name, 'r')
                        corrmat = h5file.root.corrmat
        corrmats.append(corrmat)
    for idx, name in enumerate(filenames):
        path, name = os.path.split(name)
        br = Brain(target, hemi, surface, title=name+'-%d' % idx)
        brains.append(br)
        for brain in brains[:-1]:
            mlab.sync_camera(br._f, brain._f)
            mlab.sync_camera(brain._f, br._f)
        br._f.on_mouse_pick(picker_callback)
    mlab.show()
예제 #3
0
 def reset_plane(self):
     self.slicer.ipw.plane_orientation = "z_axes"
     self.volume_scene.camera.position = [808.944540639155, 829.3458612118793, 775.2145331434656]
     self.volume_scene.camera.focal_point = [240.5, 180.5, 1.0]
     self.volume_scene.camera.view_angle = 30.0
     self.volume_scene.camera.view_up = [-0.4774879890979074, -0.468564520936391, 0.7432714914396268]
     self.volume_scene.camera.clipping_range = [712.7852412300919, 1723.7390002418533]
     self.volume_scene.camera.compute_view_plane_normal()
     self.volume_scene.render()
     mlab.sync_camera(self.volume_scene, self.scatter_scene)
예제 #4
0
파일: visualize.py 프로젝트: jgosmann/plume
    def init_camera(self):
        all_activated = self.prediction.scene.interactor is not None and \
            self.mse.scene.interactor is not None and \
            self.truth.scene.interactor is not None
        if not all_activated:
            return

        self.prediction.scene.interactor.interactor_style = \
            RotateAroundZInteractor()
        self.mse.scene.interactor.interactor_style = RotateAroundZInteractor()
        self.truth.scene.interactor.interactor_style = \
            RotateAroundZInteractor()

        self.truth.scene.anti_aliasing_frames = 2

        try:
            self._plot_fit()
        except:
            traceback.print_exc()
        self._plot_plume()
        extent = [-150, 140, -140, 150, -85, 0]
        #ax = mlab.axes(extent=extent, xlabel='', ylabel='', zlabel='')
        #ax.axes.number_of_labels = 3
        #ax.axes.corner_offset = 0.05
        #ax.axes.label_format = '%2.0f'
        #ax.label_text_property.italic = False
        #ax.label_text_property.bold = False
        #ax.axes.font_factor = 2
        #ax.axes.ranges = [-140, 140, -140, 140, -80, 0]
        #ax.axes.use_ranges = True

        x, y = np.meshgrid([-140, 140], [-140, 140], indexing='ij')
        mlab.surf(x, y, np.zeros_like(x, 'd'), color=(1.0, 1.0, 1.0))

        mlab.sync_camera(self.prediction.mayavi_scene, self.mse.mayavi_scene)
        mlab.sync_camera(self.mse.mayavi_scene, self.prediction.mayavi_scene)
        mlab.sync_camera(self.mse.mayavi_scene, self.truth.mayavi_scene)
        mlab.sync_camera(self.truth.mayavi_scene, self.mse.mayavi_scene)
        mlab.view(
            azimuth=135, elevation=135, distance=1200, roll=-120,
            figure=self.prediction.mayavi_scene)
        self.truth.scene.interactor.interactor_style.move(
            self.truth.camera, [0, -20])
        mlab.move(up=-30)
예제 #5
0
def create_graph(mesh, centroids, normals, robot_pos, traversal_tresh=35):

    print("Creating Graph... num faces:", mesh.num_faces)

    G = nx.Graph()

    for face_idx in xrange(mesh.num_faces):
        face_inclination = graph_search.MeshGraphSearch.calculate_traversal_angle(
            normals[face_idx])
        if traversal_tresh < face_inclination < 180 - traversal_tresh:
            continue

        G.add_node(face_idx)

    for face_idx in list(G.nodes()):
        face_vertexes = mesh.faces[face_idx]
        for v in face_vertexes:
            vertex_adj_faces = mesh.get_vertex_adjacent_faces(v)
            for face_adjacent in vertex_adj_faces:
                if face_adjacent != face_idx and G.has_node(face_adjacent):
                    G.add_edge(face_idx, face_adjacent, weight=1)

    # print "G node_list:", len(list(G.nodes())), sorted(list(G.nodes()))
    # print "G edge_list:", len(list(G.edges())), sorted(list(G.edges()))

    g_centroids = [(centroids[v][0], centroids[v][1], centroids[v][2])
                   for v in sorted(G.nodes())]
    centroid_g_dict = {i: v for i, v in enumerate(sorted(G.nodes()))}

    closer_centroid_idx = mesh_planner.mesh_helper.find_closer_centroid(
        g_centroids, robot_pos, force_return_closer=True)
    conn_nodes = nx.node_connected_component(
        G, centroid_g_dict[closer_centroid_idx])
    Gconn = G.subgraph(conn_nodes).copy()
    Gconn_original = Gconn.copy()

    # estimate borders of the remainder graph
    # border_nodes = [Gconn.info(v) for v in sorted(Gconn.nodes())]
    border_centroids = []
    for v in sorted(Gconn.nodes()):
        if nx.degree(G, v) <= 9:
            border_centroids.append(
                (centroids[v][0], centroids[v][1], centroids[v][2]))

    # remove nodes from graph that are near to the borders
    # given a distance treshold
    border_kdtree = spatial.KDTree(border_centroids)
    border_tresh = 0.4
    for v in list(Gconn.nodes()):
        point = centroids[v]
        distances, nearest_idx = border_kdtree.query([point])
        obstacle_d = distances[0]
        if obstacle_d <= border_tresh:
            Gconn.remove_node(v)

    # remove small connected components
    for component in list(nx.connected_components(G)):
        if len(component) < 3:
            for node in component:
                G.remove_node(node)

    f1 = mlab.figure("Borderless graph", bgcolor=(0, 0, 0))
    mlab.clf()
    plot_points(Gconn, centroids, border_centroids)

    f2 = mlab.figure("Original graph", bgcolor=(0, 0, 0))
    mlab.clf()
    plot_points(Gconn_original, centroids, border_centroids)

    mlab.sync_camera(f1, f2)
    mlab.show()
예제 #6
0
ctf = ColorTransferFunction()
ctf.add_rgb_point(0, 1, 1, 1)
ctf.add_rgb_point(1, 0, 0, 0.3)

vol._volume_property.set_color(ctf)
vol._ctf = ctf
vol.update_ctf = True
mlab.outline()

if args.show_cut:
    cut_figure = mlab.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0))
    mlab.pipeline.image_plane_widget(mlab.pipeline.scalar_field(data),
                                     plane_orientation='x_axes',
                                     slice_index=data.shape[0] / 2,
                                     figure=cut_figure)
    mlab.sync_camera(volume_figure, cut_figure)
    mlab.outline()

if args.show_iso:
    # downsample to get a somewhat smoother surface
    downscaled = scipy.ndimage.zoom(data, 256.0 / data.shape[0])

    # do some blurring to get smoother contours
    scipy.ndimage.gaussian_filter(downscaled, 2.0, output=downscaled)
    iso_figure = mlab.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0))
    iso_surface = mlab.pipeline.iso_surface(
        mlab.pipeline.scalar_field(downscaled),
        contours=[args.show_iso],
        figure=iso_figure)
    iso_surface.compute_normals = False  # seems to look better this way
    mlab.outline(extent=(0, 255, 0, 255, 0, 255))
예제 #7
0
    def update_plot(self):
        
        print "-----------------------------------------------------------"
        # Disable rendering for the duration of the update
        self.scenea.disable_render = True
        self.sceneb.disable_render = True
        self.scenec.disable_render = True

        # Read parameters from the UI
        self.me.pars.phi1 = self._phi
        self.me.pars.phi2 = self._phi
        self.me.pars.varphi = self._varphi
        self.me.pars.k0_1 = self._k0
        self.me.pars.k0_2 = self._k0
        self.me.pars.c0_A = self._c0
        self.me.pars.c0_B = self._c0
        self.me.pars.L0_A = self._L0_A
        self.me.pars.L0_B = self._L0_B
        self.me.pars.rho = self._rho
        self.me.pars.xi = self._xi
        self.me.pars.mu = self._mu
        self.me.pars.zeta = self._zeta
        self.me.pars.psi = self._psi
        self.me.pars.chi = self._chi
        self.me.pars.gamma0 = self._gamma0
        self.me.pars.gamma1 = self._gamma1
        self.me.pars.gamma2 = self._gamma2
        self.me.pars.q0 = self._q0
        self.me.pars.q1 = self._q1
        self.me.pars.c_bar = self._c_bar;
        self.me.pars.X1 = self._X1

        k_fcl_ubound = self.me.find_k_fcl_global_ubound()
        print "k_fcl_ubound = ", k_fcl_ubound,
        print " => max fcl-% = ", self.me.N_star(k_fcl_ubound), 
        print "(baseline ", self.me.N_star(self.me.pars.k0_1), ")"

        k_max = self.me.pars.k0_1

        xdata, ydata, kAdata, kBdata, z0data, z1data = self.me.compute_Omega_data(self._mesh_d)
        z2data = z1data + z0data

        z0min = z0data.min()
        z0max = z0data.max()
        z0data = (z0data - z0min) / (z0max - z0min)

        z1min = z1data.min()
        z1max = z1data.max()
        z1data = (z1data - z1min) / (z1max - z1min)

        z2min = z2data.min()
        z2max = z2data.max()
        z2data = (z2data - z2min) / (z2max - z2min)

        if self.first:
            self.first = False
            self.surfa = self.scenea.mlab.surf(xdata, ydata, z0data, figure=self.scenea.mayavi_scene)
            self.surfb = self.sceneb.mlab.surf(xdata, ydata, z1data, figure=self.sceneb.mayavi_scene)
            self.surfc = self.scenec.mlab.surf(xdata, ydata, z2data, figure=self.scenec.mayavi_scene)

            self.axa = my.axes(self.surfa, nb_labels=5, 
                               xlabel="%-A forecl.", ylabel="%-B forecl.", zlabel="Omega A", 
                               ranges = [0, 1, 0, 1, z0min, z0max],
                               figure=self.scenea.mayavi_scene)
            self.axb = my.axes(self.surfb, nb_labels=5, 
                               xlabel="%-A forecl.", ylabel="%-B forecl.", zlabel="Omega B", 
                               ranges = [0, 1, 0, 1, z1min, z1max],
                               figure=self.sceneb.mayavi_scene)
            self.axc = my.axes(self.surfc, nb_labels=5, 
                               xlabel="%-A forecl.", ylabel="%-B forecl.", zlabel="Omega A+B", 
                               ranges = [0, 1, 0, 1, z2min, z2max],
                               figure=self.scenec.mayavi_scene)

            my.sync_camera(self.scenea.mayavi_scene, self.sceneb.mayavi_scene)
            my.sync_camera(self.scenea.mayavi_scene, self.scenec.mayavi_scene)

        else:
            self.surfa.mlab_source.set(x=xdata, y=ydata, scalars=z0data)
            self.surfb.mlab_source.set(x=xdata, y=ydata, scalars=z1data)
            self.surfc.mlab_source.set(x=xdata, y=ydata, scalars=z2data)

            self.axa.axes.ranges = [0, 1, 0, 1, z0min, z0max]
            self.axb.axes.ranges = [0, 1, 0, 1, z1min, z1max]
            self.axc.axes.ranges = [0, 1, 0, 1, z2min, z2max]


        # Resume rendering
        self.scenea.disable_render = False
        self.sceneb.disable_render = False
        self.scenec.disable_render = False

        print "."
 def sync(self):
     print 'sync'
     for scene in self.sceneL:
         mlab.sync_camera(self.sceneL[0],scene)
예제 #9
0
파일: display_images.py 프로젝트: satra/sad
from mayavi import mlab
from surfer import Brain, io
subject = 'fsaverage' # SAD_017
surface = 'pial'

br1 = Brain(subject, 'rh', surface, title='lgroup')
l_surf_data = io.project_volume_data('/mindhive/scratch/satra/sadfigures/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/cf535c8b3e6380c2c8512307f3c294ad/spmT_0001.img',
                                     'rh', subject_id='fsaverage',
                                     target_subject=subject)
br1.add_overlay(l_surf_data, min=2, max=3.7, sign='pos', name='lgroup')

br2 = Brain(subject, 'rh', surface, title='hgroup')
h_surf_data = io.project_volume_data('/mindhive/scratch/satra/sadfigures/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/d1fbe9c9d24038d7d1e16b16936f52ed/spmT_0001.img',
                                     'rh', subject_id='fsaverage',
                                     target_subject=subject)
br2.add_overlay(h_surf_data, min=2, max=3.7, sign='pos', name='hgroup')
mlab.sync_camera(br1._f, br2._f)
mlab.sync_camera(br2._f, br1._f)

"""
br1.save_image('lgroup.png')
br2.save_image('hgroup.png')
"""
예제 #10
0
    def update_plot(self):
        
        print "-----------------------------------------------------------"
        # Disable rendering for the duration of the update
        self.scenea.disable_render = True
        self.sceneb.disable_render = True

        # Read parameters from the UI
        self.me.pars.phi1 = self._phi
        self.me.pars.phi2 = self._phi
        self.me.pars.varphi = self._varphi
        self.me.pars.k0_1 = self._k0
        self.me.pars.k0_2 = self._k0
        self.me.pars.c0_A = self._c0
        self.me.pars.c0_B = self._c0
        self.me.pars.L0_A = self._L0_A
        self.me.pars.L0_B = self._L0_B
        self.me.pars.rho = self._rho
        self.me.pars.xi = self._xi
        self.me.pars.mu = self._mu
        self.me.pars.zeta = self._zeta
        self.me.pars.psi = self._psi
        self.me.pars.chi = self._chi
        self.me.pars.gamma0 = self._gamma0
        self.me.pars.gamma1 = self._gamma1
        self.me.pars.gamma2 = self._gamma2
        self.me.pars.q0 = self._q0
        self.me.pars.q1 = self._q1
        self.me.pars.c_bar = self._c_bar;
        self.me.pars.X1 = self._X1

        k_fcl_ubound = self.me.find_k_fcl_global_ubound()
        print "k_fcl_ubound = ", k_fcl_ubound,
        print " => max fcl-% = ", self.me.N_star(k_fcl_ubound), 
        print "(baseline ", self.me.N_star(self.me.pars.k0_1), ")"

        d = self._mesh_d*1j
        
        self.F = np.vectorize(lambda x, y, b, f, n: 
                              self.me.cap2_pdf_cdf_p(b, f, x, y, self._ptilde_B)[n])

        c2min = self.me.pars.c_bar - 0.01
        c2max = self.me.pars.c0_A

        C2min = c2min*self.me.pars.L0_A
        C2max = c2max*self.me.pars.L0_A

        x0data, y0data = np.mgrid[C2min:C2max:d, 0.01:0.99:d]
        z0data = self.F(x0data, y0data, 0, 0, 0)

        x1data, y1data = np.mgrid[c2min:c2max:d, 0.01:0.99:d]
        z1data = self.F(x1data, y1data, 0, 1, 0)

        xdata, ydata = np.mgrid[0.0:1.0:d, 0.0:1.0:d]

        z0min = z0data.min()
        z0max = z0data.max()
        z0data = (z0data - z0min) / (z0max - z0min)

        z1min = z1data.min()
        z1max = z1data.max()
        z1data = (z1data - z1min) / (z1max - z1min)

        if self.first:
            self.first = False
            self.surfa = self.scenea.mlab.surf(xdata, ydata, z0data, figure=self.scenea.mayavi_scene)
            self.surfb = self.sceneb.mlab.surf(xdata, ydata, z1data, figure=self.sceneb.mayavi_scene)

            self.axa = my.axes(self.surfa, nb_labels=5, 
                               xlabel="Level C2", ylabel="%-A forecl.", zlabel="Cap pdf.", 
                               ranges=[C2min, C2max, 0, 1, 0, 1], 
                               figure=self.scenea.mayavi_scene)
            self.axb = my.axes(self.surfb, nb_labels=5, 
                               xlabel="Ratio c2", ylabel="%-A forecl.", zlabel="Ratio pdf.", 
                               ranges=[c2min, c2max, 0, 1, 0, 1], 
                               figure=self.sceneb.mayavi_scene)

            my.sync_camera(self.scenea.mayavi_scene, self.sceneb.mayavi_scene)
            my.sync_camera(self.sceneb.mayavi_scene, self.scenea.mayavi_scene)

        else:
            self.surfa.mlab_source.set(x=xdata, y=ydata, scalars=z0data)
            self.surfb.mlab_source.set(x=xdata, y=ydata, scalars=z1data)

            self.axa.axes.ranges = [C2min, C2max, 0, 1, 0, 1]
            self.axb.axes.ranges = [c2min, c2max, 0, 1, 0, 1]

        # Resume rendering
        self.scenea.disable_render = False
        self.sceneb.disable_render = False


        print "."
예제 #11
0
    def update_plot(self):

        print "-----------------------------------------------------------"
        # Disable rendering for the duration of the update
        self.scenea.disable_render = True
        self.sceneb.disable_render = True
        self.scenec.disable_render = True

        # Read parameters from the UI
        self.me.pars.phi1 = self._phi
        self.me.pars.phi2 = self._phi
        self.me.pars.varphi = self._varphi
        self.me.pars.k0_1 = self._k0
        self.me.pars.k0_2 = self._k0
        self.me.pars.c0_A = self._c0
        self.me.pars.c0_B = self._c0
        self.me.pars.L0_A = self._L0_A
        self.me.pars.L0_B = self._L0_B
        self.me.pars.rho = self._rho
        self.me.pars.xi = self._xi
        self.me.pars.mu = self._mu
        self.me.pars.zeta = self._zeta
        self.me.pars.psi = self._psi
        self.me.pars.chi = self._chi
        self.me.pars.gamma0 = self._gamma0
        self.me.pars.gamma1 = self._gamma1
        self.me.pars.gamma2 = self._gamma2
        self.me.pars.q0 = self._q0
        self.me.pars.q1 = self._q1
        self.me.pars.c_bar = self._c_bar
        self.me.pars.X1 = self._X1

        k_fcl_ubound = self.me.find_k_fcl_global_ubound()
        print "k_fcl_ubound = ", k_fcl_ubound,
        print " => max fcl-% = ", self.me.N_star(k_fcl_ubound),
        print "(baseline ", self.me.N_star(self.me.pars.k0_1), ")"

        k_max = self.me.pars.k0_1

        xdata, ydata, kAdata, kBdata, z0data, z1data = self.me.compute_Omega_data(
            self._mesh_d)
        z2data = z1data + z0data

        z0min = z0data.min()
        z0max = z0data.max()
        z0data = (z0data - z0min) / (z0max - z0min)

        z1min = z1data.min()
        z1max = z1data.max()
        z1data = (z1data - z1min) / (z1max - z1min)

        z2min = z2data.min()
        z2max = z2data.max()
        z2data = (z2data - z2min) / (z2max - z2min)

        if self.first:
            self.first = False
            self.surfa = self.scenea.mlab.surf(xdata,
                                               ydata,
                                               z0data,
                                               figure=self.scenea.mayavi_scene)
            self.surfb = self.sceneb.mlab.surf(xdata,
                                               ydata,
                                               z1data,
                                               figure=self.sceneb.mayavi_scene)
            self.surfc = self.scenec.mlab.surf(xdata,
                                               ydata,
                                               z2data,
                                               figure=self.scenec.mayavi_scene)

            self.axa = my.axes(self.surfa,
                               nb_labels=5,
                               xlabel="%-A forecl.",
                               ylabel="%-B forecl.",
                               zlabel="Omega A",
                               ranges=[0, 1, 0, 1, z0min, z0max],
                               figure=self.scenea.mayavi_scene)
            self.axb = my.axes(self.surfb,
                               nb_labels=5,
                               xlabel="%-A forecl.",
                               ylabel="%-B forecl.",
                               zlabel="Omega B",
                               ranges=[0, 1, 0, 1, z1min, z1max],
                               figure=self.sceneb.mayavi_scene)
            self.axc = my.axes(self.surfc,
                               nb_labels=5,
                               xlabel="%-A forecl.",
                               ylabel="%-B forecl.",
                               zlabel="Omega A+B",
                               ranges=[0, 1, 0, 1, z2min, z2max],
                               figure=self.scenec.mayavi_scene)

            my.sync_camera(self.scenea.mayavi_scene, self.sceneb.mayavi_scene)
            my.sync_camera(self.scenea.mayavi_scene, self.scenec.mayavi_scene)

        else:
            self.surfa.mlab_source.set(x=xdata, y=ydata, scalars=z0data)
            self.surfb.mlab_source.set(x=xdata, y=ydata, scalars=z1data)
            self.surfc.mlab_source.set(x=xdata, y=ydata, scalars=z2data)

            self.axa.axes.ranges = [0, 1, 0, 1, z0min, z0max]
            self.axb.axes.ranges = [0, 1, 0, 1, z1min, z1max]
            self.axc.axes.ranges = [0, 1, 0, 1, z2min, z2max]

        # Resume rendering
        self.scenea.disable_render = False
        self.sceneb.disable_render = False
        self.scenec.disable_render = False

        print "."
                    tag_buf.append(float(all_units[i + 2]))

                tag_buf.append(float(all_units[8]))

                for i in range(3):
                    tag_buf.append(float(all_units[i + 5]))
                pass

    pos_array = np.frombuffer(pos_buf, dtype=np.float).reshape([-1, 7])
    tag_array = np.frombuffer(tag_buf, dtype=np.float).reshape([-1, 7])

    from PythoTools.TrajectoryVisualization3D import *

    visualize_trajectory(pos_array, 'pos array', 1, 1)
    visualize_trajectory(tag_array, 'tag', 2, 1)
    mlab.sync_camera(mlab.figure(1), mlab.figure(2))
    # mlab.draw()
    from mpl_toolkits.mplot3d import Axes3D

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.plot(
        pos_array[:, 0],
        pos_array[:, 1],
        pos_array[:, 2],
    )

    plt.figure()
    plt.title('trace')
    for i in range(3):
        plt.plot(pos_array[:, i], label=str(i))
예제 #13
0
 def sync(self):
     print 'sync'
     for scene in self.sceneL:
         mlab.sync_camera(self.sceneL[0], scene)