from OpenGL.GL import glGenLists, glNewList, GL_COMPILE, glEndList, glCallList, \
glBegin, glEnd, GL_LINES, glVertex3f, glColor3f, \
glEnable, glDisable, GL_LIGHTING
from points import Point, centerMinMax
from ViewerItem import ViewerItem
from os.path import basename
from itertools import izip
from io import line_blocks
class Edges(ViewerItem):
def __init__(self, filename, parent = None):
super(Edges, self).__init__(basename(filename), parent, color = (0,0,255))
self.read_edges(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_edges()
glEndList()
def draw_edges(self):
glBegin(GL_LINES)
for (u,v) in self.edges:
glVertex3f(u.x, u.y, u.z)
glVertex3f(v.x, v.y, v.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 (u,v) in self.edges:
yield u
yield v
def __iter__(self):
return self.edges
def read_edges(self, filename):
self.edges = []
for block in line_blocks(filename, 2):
u = Point(map(float, block[0].split()))
v = Point(map(float, block[1].split()))
self.edges.append((u,v))