from OpenGL.GL import glGenLists, glNewList, GL_COMPILE, glEndList, glCallList, \
glBegin, glEnd, GL_LINES, glVertex3f, glColor3f, \
glEnable, glDisable, GL_LIGHTING, GL_POINTS
from points import Point, centerMinMax
from ViewerItem import ViewerItem
from os.path import basename
from itertools import izip
from io import line_blocks
class Spheres(ViewerItem):
def __init__(self, filename, parent = None):
super(Spheres, self).__init__(basename(filename), parent, color = (0,0,255))
self.read_spheres(filename)
self.create_display_list()
self.center, self.min, self.max = centerMinMax(self.vertices())
def create_display_list(self):
self.display_list = glGenLists(1)
glNewList(self.display_list, GL_COMPILE)
self.draw_spheres()
glEndList()
def draw_spheres(self):
# TODO
glBegin(GL_POINTS)
for (c,r) in self.spheres:
glVertex3f(c.x, c.y, c.z)
glEnd()
def draw(self):
if not self.visible: return
r,g,b,a = self.color.getRgb()
glColor3f(r,g,b)
glCallList(self.display_list)
def vertices(self):
for (c,r) in self.spheres:
yield c
def __iter__(self):
return self.spheres
def read_spheres(self, filename):
self.spheres = []
for block in line_blocks(filename, 1):
block = block[0].split()
c = Point(map(float, block[:3]))
r = float(block[3])
self.spheres.append((c,r))