def test_picking_trajectories(): curves=[100*np.random.rand(10,3),100*np.random.rand(5,3),100*np.random.rand(3,3)] #curves=[100*np.array([[0,0,0],[1,0,0]]), 100*np.array([[0,1,0],[0,1,3]]),100*np.array([[0,2,0],[0,2,3]])] ''' from nibabel import trackvis as tv #fname='/home/eg309/Data/PROC_MR10032/subj_01/101/1312211075232351192010091419011391228126452ep2dadvdiffDSI25x25x25b4000s003a001_FA_warp.trk' fname='/home/eg309/Data/fibers.trk' streams,hdr=tv.read(fname) T=[s[0] for s in streams] curves=T[:200000] fname='/home/eg309/Data/PROC_MR10032/subj_02/101/1312211075232351192010091708112071055601107ep2dadvdiffDSI10125x25x25STs002a001_QA_native.dpy' from dipy.io.dpy import Dpy dpr=Dpy(fname,'r') T=dpr.read_indexed(range(20000)) from dipy.core.track_metrics import length curves=[t for t in T if length(t) > 20] dpr.close() ''' #colors=np.random.rand(len(curves),4).astype('f4') colors=0.5*np.ones((len(curves),4)).astype('f4') for (i,c) in enumerate(curves): orient=c[0]-c[-1] orient=np.abs(orient/np.linalg.norm(orient)) colors[i,:3]=orient c=InteractiveCurves(curves,colors=colors) w=World() w.add(c) wi=Window() wi.attach(w)
def show_tracks(tracks,alpha=1.,lw=2.,bg=(1.,1.,1.,1)): colors=compute_colors(tracks,alpha=alpha) ax = Line(tracks,colors,line_width=lw) w=World() w.add(ax) wi = Window(caption=" Curve plotting (fos.me)",\ bgcolor=bg,width=1200,height=1000) #(0,0.,0.2,1) wi.attach(w) wm = WindowManager() wm.add(wi) wm.run()
def load_tracks(method="pmt"): from nibabel import trackvis as tv dname = "/home/eg309/Data/orbital_phantoms/dwi_dir/subject1/" if method == "pmt": fname = "/home/eg309/Data/orbital_phantoms/dwi_dir/workflow/tractography/_subject_id_subject1/cam2trk_pico_twoten/data_fit_pdfs_tracked.trk" streams, hdr = tv.read(fname, points_space="voxel") tracks = [s[0] for s in streams] if method == "dti": fname = dname + "dti_tracks.dpy" if method == "dsi": fname = dname + "dsi_tracks.dpy" if method == "gqs": fname = dname + "gqi_tracks.dpy" if method == "eit": fname = dname + "eit_tracks.dpy" if method in ["dti", "dsi", "gqs", "eit"]: dpr_linear = Dpy(fname, "r") tracks = dpr_linear.read_tracks() dpr_linear.close() if method != "pmt": tracks = [t - np.array([96 / 2.0, 96 / 2.0, 55 / 2.0]) for t in tracks if track_range(t, 100 / 2.5, 150 / 2.5)] tracks = [t for t in tracks if track_range(t, 100 / 2.5, 150 / 2.5)] print "final no of tracks ", len(tracks) qb = QuickBundles(tracks, 25.0 / 2.5, 18) # from dipy.viz import fvtk # r=fvtk.ren() # fvtk.add(r,fvtk.line(qb.virtuals(),fvtk.red)) # fvtk.show(r) # show_tracks(tracks)#qb.exemplars()[0]) # qb.remove_small_clusters(40) del tracks # load tl = TrackLabeler(qb, qb.downsampled_tracks(), vol_shape=None, tracks_line_width=3.0, tracks_alpha=1) # return tracks w = World() w.add(tl) # create window wi = Window(caption="Fos", bgcolor=(1.0, 1.0, 1.0, 1.0), width=1600, height=900) wi.attach(w) # create window manager wm = WindowManager() wm.add(wi) wm.run()
def __init__(self, bgcolor=None, **kwargs): """ Create a FosWindow. All parameters are optional. Parameters ---------- `bgcolor` : tuple Specify the background color as 4-tuple with values between 0 and 1 `width` : int Width of the window, in pixels. Defaults to 640, or the screen width if `fullscreen` is True. `height` : int Height of the window, in pixels. Defaults to 480, or the screen height if `fullscreen` is True. `caption` : str or unicode Initial caption (title) of the window. Defaults to ``sys.argv[0]``. `fullscreen` : bool If True, the window will cover the entire screen rather than floating. Defaults to False. `visible` : bool Determines if the window is visible immediately after creation. Defaults to True. Set this to False if you would like to change attributes of the window before having it appear to the user. """ self.update_dt = 1.0/60 if bgcolor == None: self.bgcolor = color.black else: self.bgcolor = bgcolor self.mouse_x, self.mouse_y = 0,0 # create an empty world by default emptyworld = World("Zero-Point World") self.attach(emptyworld) # the frame rate display from fos.lib.pyglet #self.fps_display = FPSDisplay(self) #self.foslabel = WindowText(self, 'fos', x=10 , y=40) self.show_logos = False # pushing new event handlers foswinhandlers = FosWinEventHandler(self) self.push_handlers(foswinhandlers) # log handler # self.push_handlers(WindowEventLogger()) self.show_fps = True self.fps_display = ClockDisplay() super(SimpleWindow, self).__init__(**kwargs) print "init simple window"
def load_PX_tracks(): roi = "LH_premotor" dn = "/home/hadron/from_John_mon12thmarch" dname = "/extra_probtrackX_analyses/_subject_id_subj05_101_32/particle2trackvis_" + roi + "_native/" fname = dn + dname + "tract_samples.trk" from nibabel import trackvis as tv points_space = [None, "voxel", "rasmm"] streamlines, hdr = tv.read(fname, as_generator=True, points_space="voxel") tracks = [s[0] for s in streamlines] del streamlines # return tracks qb = QuickBundles(tracks, 25.0 / 2.5, 18) # tl=Line(qb.exemplars()[0],line_width=1) del tracks qb.remove_small_clusters(20) tl = TrackLabeler(qb, qb.downsampled_tracks(), vol_shape=None, tracks_line_width=3.0, tracks_alpha=1) # put the seeds together # seeds=np.vstack((seeds,seeds2)) # shif the seeds # seeds=np.dot(mat[:3,:3],seeds.T).T + mat[:3,3] # seeds=seeds-shift # seeds2=np.dot(mat[:3,:3],seeds2.T).T + mat[:3,3] # seeds2=seeds2-shift # msk = Point(seeds,colors=(1,0,0,1.),pointsize=2.) # msk2 = Point(seeds2,colors=(1,0,.ppppp2,1.),pointsize=2.) w = World() w.add(tl) # w.add(msk) # w.add(msk2) # w.add(sl) # create window wi = Window(caption="Fos", bgcolor=(0.3, 0.3, 0.6, 1.0), width=1600, height=900) wi.attach(w) # create window manager wm = WindowManager() wm.add(wi) wm.run()
def test_picking_trajectories(): curves = [ 100 * np.random.rand(10, 3), 100 * np.random.rand(5, 3), 100 * np.random.rand(3, 3) ] #curves=[100*np.array([[0,0,0],[1,0,0]]), 100*np.array([[0,1,0],[0,1,3]]),100*np.array([[0,2,0],[0,2,3]])] ''' from nibabel import trackvis as tv #fname='/home/eg309/Data/PROC_MR10032/subj_01/101/1312211075232351192010091419011391228126452ep2dadvdiffDSI25x25x25b4000s003a001_FA_warp.trk' fname='/home/eg309/Data/fibers.trk' streams,hdr=tv.read(fname) T=[s[0] for s in streams] curves=T[:200000] fname='/home/eg309/Data/PROC_MR10032/subj_02/101/1312211075232351192010091708112071055601107ep2dadvdiffDSI10125x25x25STs002a001_QA_native.dpy' from dipy.io.dpy import Dpy dpr=Dpy(fname,'r') T=dpr.read_indexed(range(20000)) from dipy.core.track_metrics import length curves=[t for t in T if length(t) > 20] dpr.close() ''' #colors=np.random.rand(len(curves),4).astype('f4') colors = 0.5 * np.ones((len(curves), 4)).astype('f4') for (i, c) in enumerate(curves): orient = c[0] - c[-1] orient = np.abs(orient / np.linalg.norm(orient)) colors[i, :3] = orient c = InteractiveCurves(curves, colors=colors) w = World() w.add(c) wi = Window() wi.attach(w)
except pyglet.window.NoSuchConfigException: # Fall back to no multisampling for old hardware window = Window(resizable=True, caption = mycpt) # sample tree data # #### vert = np.array( [ [0,0,0], [5,5,0], [5,10,0], [10,5,0]], dtype = np.float32 ) conn = np.array( [ 0, 1, 1, 2, 1, 3 ], dtype = np.uint32 ) cols = np.array( [ [0, 0, 1, 1], [1, 0, 1, 1], [0, 0, 1, 0.5] ] , dtype = np.float32 ) vert_width = np.array( [1, 5, 5, 1, 5, 1], dtype = np.float32 ) ax = Axes() act = TreeRegion(vertices = vert, connectivity = conn, colors = cols, radius = vert_width) w = World() w.add(ax) w.add(act) window.attach(w) wm = WindowManager() wm.add(window) wm.run()
import numpy as np import nibabel as nib import os.path as op from fos import World, Window, WindowManager from fos.actor.curve import InteractiveCurves from fos.core.data import get_track_filename # exmple track file streams, hdr = nib.trackvis.read(get_track_filename()) T = [s[0] for s in streams] Trk = np.array(T, dtype=np.object) print "loaded file" cu = InteractiveCurves(curves=T) w = World() w.add(cu) wi = Window(caption="Interactive Curves") wi.attach(w) wm = WindowManager() wm.add(wi) wm.run()
import scipy.ndimage as nd import nibabel as ni from fos.actor.volslicer import ConnectedSlices from fos import World, Window # your nifti volume f1 = 'raw_t1_image.nii.gz' img = ni.load(f1) data = img.get_data() affine = img.get_affine() cds = ConnectedSlices(affine, data) w = World() w.add(cds) wi = Window() wi.attach(w)
import numpy as np import nibabel as nib import os.path as op from fos import World, Window, WindowManager from fos.actor.curve import InteractiveCurves from fos.core.data import get_track_filename # exmple track file streams,hdr = nib.trackvis.read(get_track_filename()) T=[s[0] for s in streams] Trk=np.array(T, dtype=np.object) print "loaded file" cu = InteractiveCurves(curves = T) w=World() w.add(cu) wi = Window(caption="Interactive Curves") wi.attach(w) wm = WindowManager() wm.add(wi) wm.run()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) def unset_state(self): glDisable(GL_BLEND) glDisable(GL_DEPTH_TEST) if __name__=='__main__': pos1=100*np.random.rand(100,3) -50 cloud1 = Point(pos1,colors=(1,0,0,1.),pointsize=2.) pos2=100*np.random.rand(100,3) -50 cloud2 = Point(pos2,colors=np.random.rand(100,4),pointsize=5.) w=World() w.add(cloud1) w.add(cloud2) wi = Window(caption="Fos",\ bgcolor=(.3,.3,.6,1.),\ width=1600,\ height=900) wi.attach(w) wm = WindowManager() wm.add(wi) wm.run()
#qb=load_pickle(fpkl) qb.remove_small_clusters(1000) print len(qb.clustering) #create the interaction system for tracks tl = TrackLabeler(qb,qb.downsampled_tracks(),vol_shape=data.shape,tracks_line_width=3.,tracks_alpha=1.) #add a interactive slicing/masking tool sl = Slicer(affine,data) #add one way communication between tl and sl tl.slicer=sl #OpenGL coordinate system axes ax = Axes(100) x,y,z=data.shape #add the actors to the world w=World() w.add(tl) #w.add(sl) #w.add(ax) #create a window #wi = Window(caption="Interactive bundle selection using fos and QB",\ # bgcolor=(0.3,0.3,0.6,1),width=1600,height=1000) wi = Window(caption="Fos",bgcolor=(1.,1.,1.,1.),width=1600,height=900) #attach the world to the window wi.attach(w) #create a manager which can handle multiple windows wm = WindowManager() wm.add(wi) wm.run() print('Everything is running ;-)')
aff[:3,3] = [0,0,0] nlabs = {0 : { 'label' : 'Node 1', 'size' : 20, 'font' : 'Times New Roman', 'color' : ( 255, 0, 0, 255 ) }, 1 : { 'label' : 'Node 2'} } class DynNet(DynamicNetwork): def update(self, dt): super(DynNet,self).update(dt) dn = DynNet(affine = aff, node_position = pos, node_size = size, node_color = col, node_label = nlabs, edge_connectivity = edg, edge_color = edg_col, global_edge_width = 3.5 ) w = World() w.add(dn) wi = Window(caption = "Dynamic Network with Fos") wi.attach(w) dn.start() wm = WindowManager() wm.add(wi) wm.run()
""" Create an empty Fos world and attach a window to it """ from fos import World, Window, DefaultCamera, WindowManager # create the first window wi = Window(caption = "My Window 1", bgcolor = (1,1,1,1) ) # return the default empty world of this window w = World() # add a new camera to this world cam2 = DefaultCamera() w.add(cam2) # create the second window wi2 = Window(caption = "My Window 2", bgcolor = (0,0,0,1) ) # we want to look at the same world as window 1, thus drop # the default world and attach the window to our world with the second camera wi2.attach(w) # set the camera for the second window to the second camera wi2.set_current_camera(cam2) # Create the window manager, add the windows, and go! wm = WindowManager() wm.add(wi) wm.add(wi2) wm.run()
import numpy as np from fos import Window, WindowManager, World from fos.actor.spherecloud import SphereCloud n = 100 # the positions for the sphere positions = np.random.random( (n,3) ).astype( np.float32 ) * 500 # the radii for the spheres radii = np.random.random( (n,) ).astype( np.float32 ) * 10 # the color for the spheres colors = np.random.random( (n,4) ).astype( np.float32 ) * 10 colors[:,3] = 1.0 sc = SphereCloud( positions = positions, radii=radii, colors=colors ) wi = Window() w = World() w.add(sc) wi.attach(w) wm = WindowManager() wm.add(wi) wm.run()
aff2=aff.copy() aff2[:3,3]=[250,0,0] l2=Light(position=np.array((1, 0, .5, 0),'f4'),ambient=(.0,.5,.5,1.),diffuse=(.5,.5,.5,1),specular=(.5,.5,.5,1)) m2=Material(diffuse=red,emissive=None,specular=(.9,.9,.9,1.),shininess=100,color=False) s2=Surface(vertices,faces,colors,normals, material = m2, light = l2, affine=aff2) aff3=aff.copy() aff3[:3,3]=[500,0,0] l3=Light(position=np.array((1, 0, .5, 0),'f4'),ambient=(.0,.5,.5,1.),diffuse=(.5,.5,.5,1),specular=(.5,.5,.5,1)) m3=Material(diffuse=blue,emissive=(.4,.4,.4,1.),specular=(.9,.9,.9,1.),shininess=100,color=False) s3=Surface(vertices,faces,colors,normals, material = m3, light = l3, affine=aff3) w=World() w.add(s) w.add(s2) w.add(s3) cam=DefaultCamera() w.add(cam) wi=Window() wi.attach(w) wm = WindowManager() wm.add(wi) wm.run() """
font_size=26, dpi=100, # x=window.width//2, y=window.height//2, anchor_x='center', anchor_y='center', batch = self.batch) def update(self, dt): pass def draw(self): pass glPushMatrix() #glRotatef(5.0, 0, 1, 0) glTranslatef(-100,0,0) self.batch.draw() glPopMatrix() if __name__ == '__main__': w = World() wi = Window() act = Dummy() w.add(act) wm = WindowManager() wm.add(wi) wm.run()
print normals.min(), normals.max(), normals.mean() print vertices.dtype, faces.dtype, colors.dtype, normals.dtype from fos.actor.surf import Surface from fos import Window, World, DefaultCamera aff = np.eye(4, dtype=np.float32) #aff[0,3] = 30 s = Surface(vertices, faces, colors, normals=normals, affine=None, force_centering=True, add_lights=False) #vertices2=vertices+np.array([10,0,0],dtype=vertices.dtype) #s2=Surface(vertices2,faces,colors, affine = aff, normals=normals) w = World() w.add(s) #w.add(s2) cam = DefaultCamera() w.add(cam) wi = Window(bgcolor=(1., 0., 1., 1.), width=1000, height=1000) wi.attach(w)
caption=mycpt) # "vsync=False" to check the framerate except pyglet.window.NoSuchConfigException: # Fall back to no multisampling for old hardware window = Window(resizable=True, caption=mycpt) # sample tree data # #### vert = np.array([[0, 0, 0], [5, 5, 0], [5, 10, 0], [10, 5, 0]], dtype=np.float32) conn = np.array([0, 1, 1, 2, 1, 3], dtype=np.uint32) cols = np.array([[0, 0, 1, 1], [1, 0, 1, 1], [0, 0, 1, 0.5]], dtype=np.float32) vert_width = np.array([1, 5, 5, 1, 5, 1], dtype=np.float32) ax = Axes() act = TreeRegion(vertices=vert, connectivity=conn, colors=cols, radius=vert_width) w = World() w.add(ax) w.add(act) window.attach(w) wm = WindowManager() wm.add(window) wm.run()
dpr.close() #load initial QuickBundles with threshold 30mm fpkl = 'data/subj_'+("%02d" % subject)+'/101_32/DTI/qb_gqi_'+str(seeds)+'M_linear_'+str(qb_dist)+'.pkl' #qb=QuickBundles(T,30.,12) qb=load_pickle(fpkl) #create the interaction system for tracks tl = TrackLabeler(qb,qb.downsampled_tracks(),vol_shape=data.shape,tracks_alpha=1) #add a interactive slicing/masking tool sl = Slicer(affine,data) #add one way communication between tl and sl tl.slicer=sl #OpenGL coordinate system axes ax = Axes(100) x,y,z=data.shape #add the actors to the world w=World() w.add(tl) w.add(sl) #w.add(ax) #create a window wi = Window(caption="Interactive Spaghetti using Diffusion Imaging in Python (dipy.org) and Free On Shades (fos.me)",\ bgcolor=(0.3,0.3,0.6,1),width=1200,height=800) #attach the world to the window wi.attach(w) #create a manager which can handle multiple windows wm = WindowManager() wm.add(wi) wm.run() print('Everything is running ;-)')
def unset_state(self): glDisable(GL_BLEND) glDisable(GL_DEPTH_TEST) def update(self,dt): pass if __name__ =='__main__': ax = Axes(100) data=np.round(255*np.random.rand(182,218,4)).astype(np.ubyte) #data=np.round(255*np.ones((182,218,4))).astype(np.ubyte) data[70:120,:,:3]=100 data[:,:,3]=150 data=data.astype(np.ubyte) tex=Texture2D(data) w=World() w.add(ax) w.add(tex) wi = Window(caption="Texture by Free On Shades (fos.me)",\ bgcolor=(0,0.,0.2,1),width=800,height=600) wi.attach(w) wm = WindowManager() wm.add(wi) wm.run()
import scipy.ndimage as nd import nibabel as ni from fos.actor.volslicer import ConnectedSlices from fos import World,Window, WindowManager f1='/home/eg309/Data/regtest/fiac0/meanafunctional_01.nii' img=ni.load(f1) data =img.get_data() affine=img.get_affine() cds =ConnectedSlices(affine,data) #actors.append(cds) w=World() w.add(cds) wi=Window() wi.attach(w) wm = WindowManager() wm.add(wi) wm.run()
import numpy as np from fos import World, Window, WindowManager from fos.actor.network import AttributeNetwork w = World("myworld") # node positions s = 1000 pos = np.random.random((s, 3)).astype(np.float32) * 100 col = np.random.random_integers(0, 255, (s, 4)).astype(np.ubyte) col[:, 3] = 255 print pos.shape print col.shape size = np.array([1.0, 10.0], dtype=np.float32) size = np.random.random((s, 1)).astype(np.float32) print size.shape ss = 500 edg = np.array([[0, 1]], dtype=np.uint8) edg_weight = np.array([1.5], dtype=np.float32) edg_col = np.array([[255, 0, 0, 255]], dtype=np.ubyte) print edg.shape print edg_weight.shape print edg_col.shape edg = np.random.random_integers(0, s - 1, (ss, 2)).astype(np.uint32) edg_weight = np.random.random((ss, 1)).astype(np.float32) edg_col = np.random.random_integers(0, 255 - 1, (ss, 4)).astype(np.ubyte)
if __name__ == '__main__': tracks=[100*np.random.rand(100,3),100*np.random.rand(20,3)] colors=np.ones((120,4)) colors[0:100,:3]=np.array([1,0,0.]) colors[100:120,:3]=np.array([0,1,0]) import nibabel as nib from os import path as op a=nib.trackvis.read( op.join(op.dirname(fos.__file__), "data", "tracks300.trk") ) g=np.array(a[0], dtype=np.object) tracks = [tr[0] for tr in a[0]] #tracks = tracks-np.concatenate(tracks,axis=0) lentra = [len(t) for t in tracks] colors = np.ones((np.sum(lentra),4)) #colors[:,3]=0.9 ax = Line(tracks,colors,line_width=2) w=World() w.add(ax) wi = Window(caption=" Line plotting (fos.me)",\ bgcolor=(0,0.,0.2,1),width=800,height=600) wi.attach(w) wm = WindowManager() wm.add(wi) wm.run()
# fT1_ref = '/usr/share/fsl/data/standard/MNI152_T1_1mm_brain.nii.gz' img = nib.load(fT1) # img = nib.load(fT1) sl = Slicer(img.get_affine(), img.get_data()) tl.slicer = sl luigi = Line([t - shift for t in lT], line_width=2) # put the seeds together seeds = np.vstack((seeds, seeds2)) # shif the seeds seeds = np.dot(mat[:3, :3], seeds.T).T + mat[:3, 3] seeds = seeds - shift # seeds2=np.dot(mat[:3,:3],seeds2.T).T + mat[:3,3] # seeds2=seeds2-shift msk = Point(seeds, colors=(1, 0, 0, 1.0), pointsize=2.0) # msk2 = Point(seeds2,colors=(1,0,.ppppp2,1.),pointsize=2.) w = World() w.add(tl) w.add(msk) # w.add(msk2) w.add(sl) w.add(luigi) # create window wi = Window(caption="subj_" + subject + ".png", bgcolor=(0.3, 0.3, 0.6, 1.0), width=1600, height=900) wi.attach(w) # create window manager wm = WindowManager() wm.add(wi) wm.run()