forked from thechargedneutron/GSoC-Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
High_Resolution_Sphere.py
61 lines (43 loc) · 1.65 KB
/
High_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
57
58
59
60
61
import numpy as np
resolution = 50;
a = 1.0
b = 1.0
c = 1.0
v_range = []
for i in range(0, resolution+1):
v_range.append((180.0 * 2.0)/(resolution) * i);
edge_list = []
vert_list = []
for v in v_range:
z_new = c*np.cos(np.deg2rad(v))
for i in range(0, resolution+1):
ang = (180.0 * 2.0)/(resolution) * i;
vert_list.append([a*np.sin(np.deg2rad(v))*np.cos(np.deg2rad(ang)),
b*np.sin(np.deg2rad(v))*np.sin(np.deg2rad(ang)),
c*np.cos(np.deg2rad(v))])
for hor in range(0, resolution):
for ver in range(0, resolution):
vert1 = (resolution+1)*hor + ver
vert2 = (resolution+1)*(hor+1) + ver
vert3 = (resolution+1)*hor + (ver+1)
vert4 = (resolution+1)*(hor+1) + (ver+1)
edge_list.append([vert1, vert2, vert3])
edge_list.append([vert2, vert4, vert3])
#four points are (hor, ver) (hor+1, ver) (hor, ver+1) (hor+1, ver+1)
# make_quad(11*hor + ver, 11*(hor+1) + ver, 11*hor + (ver+1), 11*(hor+1) + (ver+1))
my_vertices = np.array(vert_list)
my_triangles = np.array(edge_list)
import dipy.viz.utils as ut_vtk
from dipy.viz import window
import vtk
my_polydata = vtk.vtkPolyData()
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)