def test_fvtk_functions(): # Create a renderer r=fvtk.ren() # Create 2 lines with 2 different colors lines=[np.random.rand(10,3),np.random.rand(20,3)] colors=np.random.rand(2,3) c=fvtk.line(lines,colors) fvtk.add(r,c) # Create a volume and return a volumetric actor using volumetric rendering vol=100*np.random.rand(100,100,100) vol=vol.astype('uint8') r = fvtk.ren() v = fvtk.volume(vol) fvtk.add(r,v) # Remove all objects fvtk.rm_all(r) # Put some text l=fvtk.label(r,text='Yes Men') fvtk.add(r,l) # Show everything #fvtk.show(r)
def test_fvtk_functions(): # Create a renderer r = fvtk.ren() # Create 2 lines with 2 different colors lines = [np.random.rand(10, 3), np.random.rand(20, 3)] colors = np.random.rand(2, 3) c = fvtk.line(lines, colors) fvtk.add(r, c) # create streamtubes of the same lines and shift them a bit c2 = fvtk.streamtube(lines, colors) c2.SetPosition(2, 0, 0) fvtk.add(r, c2) # Create a volume and return a volumetric actor using volumetric rendering vol = 100 * np.random.rand(100, 100, 100) vol = vol.astype('uint8') r = fvtk.ren() v = fvtk.volume(vol) fvtk.add(r, v) # Remove all objects fvtk.rm_all(r) # Put some text l = fvtk.label(r, text='Yes Men') fvtk.add(r, l) # Slice the volume fvtk.add(r, fvtk.slicer(vol, plane_i=[50])) # Change the position of the active camera fvtk.camera(r, pos=(0.6, 0, 0), verbose=False)
def viz_vol(vol): ren = fvtk.ren() vl = 100*vol v = fvtk.volume(vl) fvtk.add(ren, v) fvtk.show(ren)
def test_fvtk_functions(): # This tests will fail if any of the given actors changed inputs or do # not exist # Create a renderer r = fvtk.ren() # Create 2 lines with 2 different colors lines = [np.random.rand(10, 3), np.random.rand(20, 3)] colors = np.random.rand(2, 3) c = fvtk.line(lines, colors) fvtk.add(r, c) # create streamtubes of the same lines and shift them a bit c2 = fvtk.streamtube(lines, colors) c2.SetPosition(2, 0, 0) fvtk.add(r, c2) # Create a volume and return a volumetric actor using volumetric rendering vol = 100 * np.random.rand(100, 100, 100) vol = vol.astype('uint8') r = fvtk.ren() v = fvtk.volume(vol) fvtk.add(r, v) # Remove all objects fvtk.rm_all(r) # Put some text l = fvtk.label(r, text='Yes Men') fvtk.add(r, l) # Slice the volume slicer = fvtk.slicer(vol) slicer.display(50, None, None) fvtk.add(r, slicer) # Change the position of the active camera fvtk.camera(r, pos=(0.6, 0, 0), verbose=False) fvtk.clear(r) # Peak directions p = fvtk.peaks(np.random.rand(3, 3, 3, 5, 3)) fvtk.add(r, p) p2 = fvtk.peaks(np.random.rand(3, 3, 3, 5, 3), np.random.rand(3, 3, 3, 5), colors=(0, 1, 0)) fvtk.add(r, p2)
def test_fvtk_functions(): # Create a renderer r = fvtk.ren() # Create 2 lines with 2 different colors lines = [np.random.rand(10, 3), np.random.rand(20, 3)] colors = np.random.rand(2, 3) c = fvtk.line(lines, colors) fvtk.add(r, c) # Create a volume and return a volumetric actor using volumetric rendering vol = 100 * np.random.rand(100, 100, 100) vol = vol.astype('uint8') r = fvtk.ren() v = fvtk.volume(vol) fvtk.add(r, v) # Remove all objects fvtk.rm_all(r) # Put some text l = fvtk.label(r, text='Yes Men') fvtk.add(r, l)
def test(): # img=nib.load('/home/eg309/Data/project01_dsi/connectome_0001/tp1/RAWDATA/OUT/mr000001.nii.gz') btable = np.loadtxt(get_data("dsi515btable")) # volume size sz = 16 # shifting origin = 8 # hanning width filter_width = 32.0 # number of signal sampling points n = 515 # odf radius radius = np.arange(2.1, 6, 0.2) # create q-table bv = btable[:, 0] bmin = np.sort(bv)[1] bv = np.sqrt(bv / bmin) qtable = np.vstack((bv, bv, bv)).T * btable[:, 1:] qtable = np.floor(qtable + 0.5) # copy bvals and bvecs bvals = btable[:, 0] bvecs = btable[:, 1:] # S=img.get_data()[38,50,20]#[96/2,96/2,20] S, stics = SticksAndBall( bvals, bvecs, d=0.0015, S0=100, angles=[(0, 0), (60, 0), (90, 90)], fractions=[0, 0, 0], snr=None ) S2 = S.copy() S2 = S2.reshape(1, len(S)) dn = DiffusionNabla(S2, bvals, bvecs, auto=False) pR = dn.equators odf = dn.odf(S) # Xs=dn.precompute_interp_coords() peaks, inds = peak_finding(odf.astype("f8"), dn.odf_faces.astype("uint16")) print peaks print peaks / peaks.min() # print dn.PK dn.fit() print dn.PK # """ ren = fvtk.ren() colors = fvtk.colors(odf, "jet") fvtk.add(ren, fvtk.point(dn.odf_vertices, colors, point_radius=0.05, theta=8, phi=8)) fvtk.show(ren) # """ stop # ds=DiffusionSpectrum(S2,bvals,bvecs) # tpr=ds.pdf(S) # todf=ds.odf(tpr) """ #show projected signal Bvecs=np.concatenate([bvecs[1:],-bvecs[1:]]) X0=np.dot(np.diag(np.concatenate([S[1:],S[1:]])),Bvecs) ren=fvtk.ren() fvtk.add(ren,fvtk.point(X0,fvtk.yellow,1,2,16,16)) fvtk.show(ren) """ # qtable=5*matrix[:,1:] # calculate radius for the hanning filter r = np.sqrt(qtable[:, 0] ** 2 + qtable[:, 1] ** 2 + qtable[:, 2] ** 2) # setting hanning filter width and hanning hanning = 0.5 * np.cos(2 * np.pi * r / filter_width) # center and index in q space volume q = qtable + origin q = q.astype("i8") # apply the hanning filter values = S * hanning """ #plot q-table ren=fvtk.ren() colors=fvtk.colors(values,'jet') fvtk.add(ren,fvtk.point(q,colors,1,0.1,6,6)) fvtk.show(ren) """ # create the signal volume Sq = np.zeros((sz, sz, sz)) for i in range(n): Sq[q[i][0], q[i][1], q[i][2]] += values[i] # apply fourier transform Pr = fftshift(np.abs(np.real(fftn(fftshift(Sq), (sz, sz, sz))))) # """ ren = fvtk.ren() vol = fvtk.volume(Pr) fvtk.add(ren, vol) fvtk.show(ren) # """ """ from enthought.mayavi import mlab mlab.pipeline.volume(mlab.pipeline.scalar_field(Sq)) mlab.show() """ # vertices, edges, faces = create_unit_sphere(5) vertices, faces = sphere_vf_from("symmetric362") odf = np.zeros(len(vertices)) for m in range(len(vertices)): xi = origin + radius * vertices[m, 0] yi = origin + radius * vertices[m, 1] zi = origin + radius * vertices[m, 2] PrI = map_coordinates(Pr, np.vstack((xi, yi, zi)), order=1) for i in range(len(radius)): odf[m] = odf[m] + PrI[i] * radius[i] ** 2 """ ren=fvtk.ren() colors=fvtk.colors(odf,'jet') fvtk.add(ren,fvtk.point(vertices,colors,point_radius=.05,theta=8,phi=8)) fvtk.show(ren) """ """ #Pr[Pr<500]=0 ren=fvtk.ren() #ren.SetBackground(1,1,1) fvtk.add(ren,fvtk.volume(Pr)) fvtk.show(ren) """ peaks, inds = peak_finding(odf.astype("f8"), faces.astype("uint16")) Eq = np.zeros((sz, sz, sz)) for i in range(n): Eq[q[i][0], q[i][1], q[i][2]] += S[i] / S[0] LEq = laplace(Eq) # Pr[Pr<500]=0 ren = fvtk.ren() # ren.SetBackground(1,1,1) fvtk.add(ren, fvtk.volume(Eq)) fvtk.show(ren) phis = np.linspace(0, 2 * np.pi, 100) planars = [] for phi in phis: planars.append(sphere2cart(1, np.pi / 2, phi)) planars = np.array(planars) planarsR = [] for v in vertices: R = vec2vec_rotmat(np.array([0, 0, 1]), v) planarsR.append(np.dot(R, planars.T).T) """ ren=fvtk.ren() fvtk.add(ren,fvtk.point(planarsR[0],fvtk.green,1,0.1,8,8)) fvtk.add(ren,fvtk.point(2*planarsR[1],fvtk.red,1,0.1,8,8)) fvtk.show(ren) """ azimsums = [] for disk in planarsR: diskshift = 4 * disk + origin # Sq0=map_coordinates(Sq,diskshift.T,order=1) # azimsums.append(np.sum(Sq0)) # Eq0=map_coordinates(Eq,diskshift.T,order=1) # azimsums.append(np.sum(Eq0)) LEq0 = map_coordinates(LEq, diskshift.T, order=1) azimsums.append(np.sum(LEq0)) azimsums = np.array(azimsums) # """ ren = fvtk.ren() colors = fvtk.colors(azimsums, "jet") fvtk.add(ren, fvtk.point(vertices, colors, point_radius=0.05, theta=8, phi=8)) fvtk.show(ren) # """ # for p in planarsR[0]: """
def viz_vol(vol, fname=None): ren = fvtk.ren() fvtk.add(ren, fvtk.volume(vol)) fvtk.show(ren) if fname is not None: fvtk.record(r, n_frames=1, out_path=fname, size=(900, 900))
def f2(t): x = -np.sin(t) y = np.linspace(-1, 1, len(x)) z = y return x, y, z def f3(t): x = np.linspace(-1, 1, len(t)) y = np.sin(t) z = x return x, y, z t = np.linspace(0, 2 * np.pi, 100) # kissing fibre #1 vol = orbital_phantom(func=f1, t=t) # kissing fibre #2 vol += orbital_phantom(func=f2, t=t) # kissing fibre #3 vol += orbital_phantom(func=f3, t=t) #vol = add_rician_noise(vol) r=fvtk.ren() fvtk.add(r, fvtk.volume(vol[...,0])) fvtk.show(r)