forked from thechargedneutron/GSoC-Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLow_Resolution_Sphere.py
56 lines (39 loc) · 1.39 KB
/
Low_Resolution_Sphere.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import numpy as np
import dipy.io.vtk as io_vtk
import dipy.viz.utils as ut_vtk
from dipy.viz import window
import vtk
my_polydata = vtk.vtkPolyData()
a = 1.0
b = 1.0
c = 1.0
v_range = [30.0, 60.0, 90.0, 120.0, 150.0, 180.0]
edge_list = []
vert_list = [[0, 0, c], [0, 0, c], [0, 0, c], [0, 0, c]]
for v in v_range:
z_new = c*np.cos(np.deg2rad(v))
n = len(vert_list)
vert_list.append([a*np.sin(np.deg2rad(v)), 0.0, z_new])
vert_list.append([0.0, b*np.sin(np.deg2rad(v)), z_new])
vert_list.append([-1*a*np.sin(np.deg2rad(v)), 0.0, z_new])
vert_list.append([0.0, -1*b*np.sin(np.deg2rad(v)), z_new])
edge_list.append([n-4, n, n-3])
edge_list.append([n, n+1, n-3])
edge_list.append([n-3, n+1, n-2])
edge_list.append([n+1, n+2, n-2])
edge_list.append([n-2, n+2, n-1])
edge_list.append([n+2, n+3, n-1])
edge_list.append([n-1, n+3, n-4])
edge_list.append([n+3, n, n-4])
my_vertices = np.array(vert_list)
my_triangles = np.array(edge_list)
ut_vtk.set_polydata_vertices(my_polydata, my_vertices)
ut_vtk.set_polydata_triangles(my_polydata, my_triangles.astype('i8'))
sphere_vertices = ut_vtk.get_polydata_vertices(my_polydata)
colors = sphere_vertices * 255
ut_vtk.set_polydata_colors(my_polydata, colors)
sphere_actor = ut_vtk.get_actor_from_polydata(my_polydata)
# renderer and scene
renderer = window.Renderer()
renderer.add(sphere_actor)
window.show(renderer, size=(600, 600), reset_camera=False)