Commit 2d0d08ea authored by lode_leroy's avatar lode_leroy

namespace cleanups

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@72 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 2e72bc67
......@@ -8,11 +8,11 @@ from pycam.Cutters.BaseCutter import BaseCutter
from math import sqrt
try:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import OpenGL.GL as GL
import OpenGL.GLU as GLU
GL_enabled = True
except:
pass
GL_enabled = False
class CylindricalCutter(BaseCutter):
......@@ -26,15 +26,17 @@ class CylindricalCutter(BaseCutter):
return "CylindricalCutter<%s,%s>" % (self.location,self.radius)
def to_OpenGL(self):
glPushMatrix()
glTranslate(self.center.x, self.center.y, self.center.z)
if not GL_enabled:
return
GL.glPushMatrix()
GL.glTranslate(self.center.x, self.center.y, self.center.z)
if not hasattr(self,"_cylinder"):
self._cylinder = gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
self._cylinder = GLU.gluNewQuadric()
GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
if not hasattr(self,"_disk"):
self._disk = gluNewQuadric()
gluDisk(self._disk, 0, self.radius, 10, 10)
glPopMatrix()
self._disk = GLU.gluNewQuadric()
GLU.gluDisk(self._disk, 0, self.radius, 10, 10)
GL.glPopMatrix()
def moveto(self, location):
BaseCutter.moveto(self, location)
......
......@@ -8,11 +8,11 @@ from pycam.Cutters.BaseCutter import BaseCutter
from math import sqrt
try:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import OpenGL.GL as GL
import OpenGL.GLU as GLU
GL_enabled = True
except:
pass
GL_enabled = False
class SphericalCutter(BaseCutter):
......@@ -26,15 +26,17 @@ class SphericalCutter(BaseCutter):
return "SphericalCutter<%s,%s>" % (self.location,self.radius)
def to_OpenGL(self):
glPushMatrix()
glTranslate(self.center.x, self.center.y, self.center.z)
if not GL_enabled:
return
GL.glPushMatrix()
GL.glTranslate(self.center.x, self.center.y, self.center.z)
if not hasattr(self,"_sphere"):
self._sphere = gluNewQuadric()
gluSphere(self._sphere, self.radius, 10, 10)
self._sphere = GLU.gluNewQuadric()
GLU.gluSphere(self._sphere, self.radius, 10, 10)
if not hasattr(self,"_cylinder"):
self._cylinder = gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
glPopMatrix()
self._cylinder = GLU.gluNewQuadric()
GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
GL.glPopMatrix()
def moveto(self, location):
BaseCutter.moveto(self, location)
......
......@@ -8,11 +8,12 @@ from pycam.Cutters.BaseCutter import BaseCutter
from math import sqrt
try:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import OpenGL.GL as GL
import OpenGL.GLU as GLU
import OpenGL.GLUT as GLUT
GL_enabled = True
except:
pass
GL_enabled = False
class ToroidalCutter(BaseCutter):
......@@ -30,19 +31,21 @@ class ToroidalCutter(BaseCutter):
return "ToroidalCutter<%s,%f,R=%f,r=%f>" % (self.location,self.radius,self.majorradius,self.minorradius)
def to_OpenGL(self):
glPushMatrix()
glTranslate(self.center.x, self.center.y, self.center.z)
glutSolidTorus(self.minorradius, self.majorradius, 10, 20)
if not GL_enabled:
return
GL.glPushMatrix()
GL.glTranslate(self.center.x, self.center.y, self.center.z)
GLUT.glutSolidTorus(self.minorradius, self.majorradius, 10, 20)
if not hasattr(self,"_cylinder"):
self._cylinder = gluNewQuadric()
gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 20)
glPopMatrix()
glPushMatrix()
glTranslate(self.location.x, self.location.y, self.location.z)
self._cylinder = GLU.gluNewQuadric()
GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 20)
GL.glPopMatrix()
GL.glPushMatrix()
GL.glTranslate(self.location.x, self.location.y, self.location.z)
if not hasattr(self,"_disk"):
self._disk = gluNewQuadric()
gluDisk(self._disk, 0, self.majorradius, 20, 10)
glPopMatrix()
self._disk = GLU.gluNewQuadric()
GLU.gluDisk(self._disk, 0, self.majorradius, 20, 10)
GL.glPopMatrix()
def moveto(self, location):
BaseCutter.moveto(self, location)
......
list = [ "SimpleGCodeExporter", "SVGExporter" ]
list = [ "SimpleGCodeExporter", "SVGExporter", "STLExporter" ]
__all__ = list
......@@ -4,11 +4,10 @@ from Line import *
from Triangle import *
try:
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import OpenGL.GL as GL
GL_enabled = True
except:
pass
GL_enabled = False
class Model:
id = 0
......@@ -21,12 +20,12 @@ class Model:
def to_OpenGL(self):
if True:
glBegin(GL_TRIANGLES)
GL.glBegin(GL.GL_TRIANGLES)
for t in self._triangles:
glVertex3f(t.p1.x, t.p1.y, t.p1.z)
glVertex3f(t.p2.x, t.p2.y, t.p2.z)
glVertex3f(t.p3.x, t.p3.y, t.p3.z)
glEnd()
GL.glVertex3f(t.p1.x, t.p1.y, t.p1.z)
GL.glVertex3f(t.p2.x, t.p2.y, t.p2.z)
GL.glVertex3f(t.p3.x, t.p3.y, t.p3.z)
GL.glEnd()
else:
for t in self._triangles:
t.to_OpenGL()
......
......@@ -3,15 +3,13 @@ from Plane import *
from utils import *
from Line import *
ORIENTATION_CCW = 2
ORIENTATION_CW = 3
try:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import OpenGL.GL as GL
import OpenGL.GLU as GLU
import OpenGL.GLUT as GLUT
GL_enabled = True
except:
pass
GL_enabled = False
class Triangle:
id = 0
......@@ -42,51 +40,53 @@ class Triangle:
return "triangle%d" % self.id
def to_OpenGL(self):
glBegin(GL_TRIANGLES)
glVertex3f(self.p1.x, self.p1.y, self.p1.z)
glVertex3f(self.p2.x, self.p2.y, self.p2.z)
glVertex3f(self.p3.x, self.p3.y, self.p3.z)
glEnd()
if not GL_enabled:
return
GL.glBegin(GL.GL_TRIANGLES)
GL.glVertex3f(self.p1.x, self.p1.y, self.p1.z)
GL.glVertex3f(self.p2.x, self.p2.y, self.p2.z)
GL.glVertex3f(self.p3.x, self.p3.y, self.p3.z)
GL.glEnd()
if False: # display surface normals
n = self.normal()
c = self.center()
d = 0.5
glBegin(GL_LINES)
glVertex3f(c.x, c.y, c.z)
glVertex3f(c.x+n.x*d, c.y+n.y*d, c.z+n.z*d)
glEnd()
GL.glBegin(GL.GL_LINES)
GL.glVertex3f(c.x, c.y, c.z)
GL.glVertex3f(c.x+n.x*d, c.y+n.y*d, c.z+n.z*d)
GL.glEnd()
if False and hasattr(self, "_middle"): # display bounding sphere
glPushMatrix()
glTranslate(self._middle.x, self._middle.y, self._middle.z)
GL.glPushMatrix()
GL.glTranslate(self._middle.x, self._middle.y, self._middle.z)
if not hasattr(self,"_sphere"):
self._sphere = gluNewQuadric()
gluSphere(self._sphere, self._radius, 10, 10)
glPopMatrix()
self._sphere = GLU.gluNewQuadric()
GLU.gluSphere(self._sphere, self._radius, 10, 10)
GL.glPopMatrix()
if True: # draw triangle id on triangle face
glPushMatrix()
cc = glGetFloatv(GL_CURRENT_COLOR)
GL.glPushMatrix()
cc = GL.glGetFloatv(GL.GL_CURRENT_COLOR)
c = self.center()
glTranslate(c.x,c.y,c.z)
GL.glTranslate(c.x,c.y,c.z)
p12=self.p1.add(self.p2).mul(0.5)
p3_12=self.p3.sub(p12).normalize()
p2_1=self.p1.sub(self.p2).normalize()
pn=p2_1.cross(p3_12)
glMultMatrixf((p2_1.x, p2_1.y, p2_1.z, 0, p3_12.x, p3_12.y, p3_12.z, 0, pn.x, pn.y, pn.z, 0, 0,0,0,1))
GL.glMultMatrixf((p2_1.x, p2_1.y, p2_1.z, 0, p3_12.x, p3_12.y, p3_12.z, 0, pn.x, pn.y, pn.z, 0, 0,0,0,1))
n = self.normal().mul(0.01)
glTranslatef(n.x,n.y,n.z)
glScalef(0.003,0.003,0.003)
GL.glTranslatef(n.x,n.y,n.z)
GL.glScalef(0.003,0.003,0.003)
w = 0
for ch in str(self.id):
w += glutStrokeWidth(GLUT_STROKE_ROMAN, ord(ch))
glTranslate(-w/2,0,0)
glColor4f(1,1,1,0)
w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch))
GL.glTranslate(-w/2,0,0)
GL.glColor4f(1,1,1,0)
for ch in str(self.id):
glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(ch))
glPopMatrix()
glColor4f(cc[0],cc[1],cc[2],cc[3])
GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch))
GL.glPopMatrix()
GL.glColor4f(cc[0],cc[1],cc[2],cc[3])
if False: # draw point id on triangle face
cc = glGetFloatv(GL_CURRENT_COLOR)
cc = GL.glGetFloatv(GL.GL_CURRENT_COLOR)
c = self.center()
p12=self.p1.add(self.p2).mul(0.5)
p3_12=self.p3.sub(p12).normalize()
......@@ -94,21 +94,21 @@ class Triangle:
pn=p2_1.cross(p3_12)
n = self.normal().mul(0.01)
for p in (self.p1,self.p2,self.p3):
glPushMatrix()
GL.glPushMatrix()
pp = p.sub(p.sub(c).mul(0.3))
glTranslate(pp.x,pp.y,pp.z)
glMultMatrixf((p2_1.x, p2_1.y, p2_1.z, 0, p3_12.x, p3_12.y, p3_12.z, 0, pn.x, pn.y, pn.z, 0, 0,0,0,1))
glTranslatef(n.x,n.y,n.z)
glScalef(0.001,0.001,0.001)
GL.glTranslate(pp.x,pp.y,pp.z)
GL.glMultMatrixf((p2_1.x, p2_1.y, p2_1.z, 0, p3_12.x, p3_12.y, p3_12.z, 0, pn.x, pn.y, pn.z, 0, 0,0,0,1))
GL.glTranslatef(n.x,n.y,n.z)
GL.glScalef(0.001,0.001,0.001)
w = 0
for ch in str(p.id):
w += glutStrokeWidth(GLUT_STROKE_ROMAN, ord(ch))
glTranslate(-w/2,0,0)
glColor4f(0.5,1,0.5,0)
w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch))
GL.glTranslate(-w/2,0,0)
GL.glColor4f(0.5,1,0.5,0)
for ch in str(p.id):
glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(ch))
glPopMatrix()
glColor4f(cc[0],cc[1],cc[2],cc[3])
GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch))
GL.glPopMatrix()
GL.glColor4f(cc[0],cc[1],cc[2],cc[3])
def normal(self):
if not hasattr(self, '_normal'):
......
......@@ -4,11 +4,10 @@ import math
import pycam
try:
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import OpenGL.GL as GL
GL_enabled = True
except:
pass
GL_enabled = False
class Node:
def __repr__(self):
......@@ -58,35 +57,37 @@ class kdtree:
return "(%s,%d:%g,%s)" % (self.lo,self.cutdim,self.cutval,self.hi)
def to_OpenGL(self,minx,maxx,miny,maxy,minz,maxz):
if not GL_enabled:
return
if self.bucket:
glBegin(GL_LINES)
glVertex3d(minx,miny,minz)
glVertex3d(minx,miny,maxz)
glVertex3d(minx,maxy,minz)
glVertex3d(minx,maxy,maxz)
glVertex3d(maxx,miny,minz)
glVertex3d(maxx,miny,maxz)
glVertex3d(maxx,maxy,minz)
glVertex3d(maxx,maxy,maxz)
glVertex3d(minx,miny,minz)
glVertex3d(maxx,miny,minz)
glVertex3d(minx,maxy,minz)
glVertex3d(maxx,maxy,minz)
glVertex3d(minx,miny,maxz)
glVertex3d(maxx,miny,maxz)
glVertex3d(minx,maxy,maxz)
glVertex3d(maxx,maxy,maxz)
glVertex3d(minx,miny,minz)
glVertex3d(minx,maxy,minz)
glVertex3d(maxx,miny,minz)
glVertex3d(maxx,maxy,minz)
glVertex3d(minx,miny,maxz)
glVertex3d(minx,maxy,maxz)
glVertex3d(maxx,miny,maxz)
glVertex3d(maxx,maxy,maxz)
glEnd()
GL.glBegin(GL.GL_LINES)
GL.glVertex3d(minx,miny,minz)
GL.glVertex3d(minx,miny,maxz)
GL.glVertex3d(minx,maxy,minz)
GL.glVertex3d(minx,maxy,maxz)
GL.glVertex3d(maxx,miny,minz)
GL.glVertex3d(maxx,miny,maxz)
GL.glVertex3d(maxx,maxy,minz)
GL.glVertex3d(maxx,maxy,maxz)
GL.glVertex3d(minx,miny,minz)
GL.glVertex3d(maxx,miny,minz)
GL.glVertex3d(minx,maxy,minz)
GL.glVertex3d(maxx,maxy,minz)
GL.glVertex3d(minx,miny,maxz)
GL.glVertex3d(maxx,miny,maxz)
GL.glVertex3d(minx,maxy,maxz)
GL.glVertex3d(maxx,maxy,maxz)
GL.glVertex3d(minx,miny,minz)
GL.glVertex3d(minx,maxy,minz)
GL.glVertex3d(maxx,miny,minz)
GL.glVertex3d(maxx,maxy,minz)
GL.glVertex3d(minx,miny,maxz)
GL.glVertex3d(minx,maxy,maxz)
GL.glVertex3d(maxx,miny,maxz)
GL.glVertex3d(maxx,maxy,maxz)
GL.glEnd()
elif self.dim==6:
if self.cutdim == 0 or self.cutdim == 2:
self.lo.to_OpenGL(minx,self.cutval,miny,maxy,minz,maxz)
......
#!/usr/bin/python
import sys
sys.path.insert(0,'.')
from ConfigParser import ConfigParser
from OpenGL.GL import *
from OpenGL.Tk import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import OpenGL.GL as GL
import OpenGL.Tk as Tk
import OpenGL.GLUT as GLUT
import tkFileDialog
from pycam import *
......@@ -22,56 +20,56 @@ from pycam.Exporters import *
# leave 10% margin around the model
DEFAULT_MARGIN = 0.1
class OpenglWidget(Opengl):
class OpenglWidget(Tk.Opengl):
def __init__(self, master=None, cnf={}, **kw):
Opengl.__init__(self, master, kw)
glutInit()
glShadeModel(GL_FLAT)
# glShadeModel(GL_SMOOTH)
Tk.Opengl.__init__(self, master, kw)
GLUT.glutInit()
GL.glShadeModel(GL.GL_FLAT)
# GL.glShadeModel(GL.GL_SMOOTH)
glMatrixMode(GL_MODELVIEW)
glMaterial(GL_FRONT_AND_BACK, GL_AMBIENT, (0.1, 0.1, 0.1, 1.0))
glMaterial(GL_FRONT_AND_BACK, GL_SPECULAR, (0.1, 0.1, 0.1, 1.0))
glMaterial(GL_FRONT_AND_BACK, GL_SHININESS, (0.5))
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, (0.1, 0.1, 0.1, 1.0))
GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, (0.1, 0.1, 0.1, 1.0))
GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, (0.5))
# glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
# GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL_LINE)
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
def basic_lighting(self):
Opengl.basic_lighting(self)
Tk.Opengl.basic_lighting(self)
# "Let There Be Light"
glPushMatrix()
glLoadIdentity()
glLightfv(GL_LIGHT0, GL_AMBIENT, (0.5, 0.5, 0.5, 1.0))
glLightfv(GL_LIGHT0, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0))
glLightfv(GL_LIGHT0, GL_SPECULAR, (1.0, 1.0, 1.0, 1.0))
glLightfv(GL_LIGHT0, GL_POSITION, (2, 2, +10, 1.0))
glEnable(GL_LIGHT0)
glDisable(GL_LIGHTING)
glPopMatrix()
GL.glPushMatrix()
GL.glLoadIdentity()
GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, (0.5, 0.5, 0.5, 1.0))
GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0))
GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, (1.0, 1.0, 1.0, 1.0))
GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, (2, 2, +10, 1.0))
GL.glEnable(GL.GL_LIGHT0)
GL.glDisable(GL.GL_LIGHTING)
GL.glPopMatrix()
self.master.resetView()
class SimpleGui(Frame):
class SimpleGui(Tk.Frame):
def draw_string(self, x, y, z, p, s, scale=.01):
glPushMatrix()
glTranslatef(x,y,z)
GL.glPushMatrix()
GL.glTranslatef(x,y,z)
if p == 'xy':
pass
elif p == 'yz':
glRotatef(90, 0, 1, 0)
glRotatef(90, 0, 0, 1)
GL.glRotatef(90, 0, 1, 0)
GL.glRotatef(90, 0, 0, 1)
elif p == 'xz':
glRotatef(90, 0, 1, 0)
glRotatef(90, 0, 0, 1)
glRotatef(-90, 0, 1, 0)
glScalef(scale,scale,scale)
GL.glRotatef(90, 0, 1, 0)
GL.glRotatef(90, 0, 0, 1)
GL.glRotatef(-90, 0, 1, 0)
GL.glScalef(scale,scale,scale)
for c in str(s):
glutStrokeCharacter(GLUT_STROKE_ROMAN, ord(c))
glPopMatrix()
GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(c))
GL.glPopMatrix()
def Redraw(self, event=None):
# default scale and orientation
glTranslatef(0,0,-2)
GL.glTranslatef(0,0,-2)
if self.Unit.get() == "mm":
size = 100
......@@ -79,23 +77,23 @@ class SimpleGui(Frame):
size = 5
# axes
glBegin(GL_LINES)
glColor3f(1,0,0)
glVertex3f(0,0,0)
glVertex3f(size,0,0)
glEnd()
GL.glBegin(GL.GL_LINES)
GL.glColor3f(1,0,0)
GL.glVertex3f(0,0,0)
GL.glVertex3f(size,0,0)
GL.glEnd()
self.draw_string(size,0,0,'xy',"X")
glBegin(GL_LINES)
glColor3f(0,1,0)
glVertex3f(0,0,0)
glVertex3f(0,size,0)
glEnd()
GL.glBegin(GL.GL_LINES)
GL.glColor3f(0,1,0)
GL.glVertex3f(0,0,0)
GL.glVertex3f(0,size,0)
GL.glEnd()
self.draw_string(0,size,0,'yz',"Y")
glBegin(GL_LINES)
glColor3f(0,0,1)
glVertex3f(0,0,0)
glVertex3f(0,0,size)
glEnd()
GL.glBegin(GL.GL_LINES)
GL.glColor3f(0,0,1)
GL.glVertex3f(0,0,0)
GL.glVertex3f(0,0,size)
GL.glEnd()
self.draw_string(0,0,size,'xz',"Z")
if True:
......@@ -106,68 +104,68 @@ class SimpleGui(Frame):
maxy = float(self.MaxY.get())
minz = float(self.MinZ.get())
maxz = float(self.MaxZ.get())
glBegin(GL_LINES)
glColor3f(0.3,0.3,0.3)
GL.glBegin(GL.GL_LINES)
GL.glColor3f(0.3,0.3,0.3)
glVertex3f(minx,miny,minz)
glVertex3f(maxx,miny,minz)
GL.glVertex3f(minx,miny,minz)
GL.glVertex3f(maxx,miny,minz)
glVertex3f(minx,maxy,minz)
glVertex3f(maxx,maxy,minz)
GL.glVertex3f(minx,maxy,minz)
GL.glVertex3f(maxx,maxy,minz)
glVertex3f(minx,miny,maxz)
glVertex3f(maxx,miny,maxz)
GL.glVertex3f(minx,miny,maxz)
GL.glVertex3f(maxx,miny,maxz)
glVertex3f(minx,maxy,maxz)
glVertex3f(maxx,maxy,maxz)
GL.glVertex3f(minx,maxy,maxz)
GL.glVertex3f(maxx,maxy,maxz)
glVertex3f(minx,miny,minz)
glVertex3f(minx,maxy,minz)
GL.glVertex3f(minx,miny,minz)
GL.glVertex3f(minx,maxy,minz)
glVertex3f(maxx,miny,minz)
glVertex3f(maxx,maxy,minz)
GL.glVertex3f(maxx,miny,minz)
GL.glVertex3f(maxx,maxy,minz)
glVertex3f(minx,miny,maxz)
glVertex3f(minx,maxy,maxz)
GL.glVertex3f(minx,miny,maxz)
GL.glVertex3f(minx,maxy,maxz)
glVertex3f(maxx,miny,maxz)
glVertex3f(maxx,maxy,maxz)
GL.glVertex3f(maxx,miny,maxz)
GL.glVertex3f(maxx,maxy,maxz)
glVertex3f(minx,miny,minz)
glVertex3f(minx,miny,maxz)
GL.glVertex3f(minx,miny,minz)
GL.glVertex3f(minx,miny,maxz)
glVertex3f(maxx,miny,minz)
glVertex3f(maxx,miny,maxz)
GL.glVertex3f(maxx,miny,minz)
GL.glVertex3f(maxx,miny,maxz)
glVertex3f(minx,maxy,minz)
glVertex3f(minx,maxy,maxz)
GL.glVertex3f(minx,maxy,minz)
GL.glVertex3f(minx,maxy,maxz)
glVertex3f(maxx,maxy,minz)
glVertex3f(maxx,maxy,maxz)
GL.glVertex3f(maxx,maxy,minz)
GL.glVertex3f(maxx,maxy,maxz)
glEnd()
GL.glEnd()
if self.model:
glColor3f(0.5,.5,1)
GL.glColor3f(0.5,.5,1)
self.model.to_OpenGL()
if self.toolpath:
last = None
for path in self.toolpath:
if last:
glColor3f(.5,1,.5)
glBegin(GL_LINES)
glVertex3f(last.x,last.y,last.z)
GL.glColor3f(.5,1,.5)
GL.glBegin(GL.GL_LINES)
GL.glVertex3f(last.x,last.y,last.z)
last = path.points[0]
glVertex3f(last.x,last.y,last.z)
glEnd()
glColor3f(1,.5,.5)
glBegin(GL_LINE_STRIP)
GL.glVertex3f(last.x,last.y,last.z)
GL.glEnd()
GL.glColor3f(1,.5,.5)
GL.glBegin(GL.GL_LINE_STRIP)
for point in path.points:
glVertex3f(point.x,point.y,point.z)
glEnd()
GL.glVertex3f(point.x,point.y,point.z)
GL.glEnd()
last = path.points[-1]
def browseOpen(self):
......@@ -339,142 +337,142 @@ class SimpleGui(Frame):
def createWidgets(self):
self.ogl = OpenglWidget(self, width=600, height=500, double=1)
self.TopFrame = Frame(self).pack(side=TOP, expand=0, fill=X)
self.TopFrame = Tk.Frame(self).pack(side=Tk.TOP, expand=0, fill=Tk.X)
self.InputFileFrame = Frame(self.TopFrame)
self.InputFileFrame.pack(side=TOP, anchor=W, expand=0, fill=X)
Label(self.InputFileFrame, text="Input File: ").pack(side=LEFT, anchor=W)
self.InputFileName = StringVar()
Entry(self.InputFileFrame, textvariable=self.InputFileName).pack(side=LEFT, expand=1, fill=X)
Button(self.InputFileFrame, text="Import...",command=self.browseOpen).pack(side=RIGHT)
self.InputFileFrame = Tk.Frame(self.TopFrame)
self.InputFileFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0, fill=Tk.X)
Tk.Label(self.InputFileFrame, text="Input File: ").pack(side=Tk.LEFT, anchor=Tk.W)
self.InputFileName = Tk.StringVar()
Tk.Entry(self.InputFileFrame, textvariable=self.InputFileName).pack(side=Tk.LEFT, expand=1, fill=Tk.X)
Tk.Button(self.InputFileFrame, text="Import...",command=self.browseOpen).pack(side=Tk.RIGHT)
self.CutterFrame = Frame(self.TopFrame)
self.CutterFrame.pack(side=TOP, anchor=W)
Label(self.CutterFrame, text="Tool: ").pack(side=LEFT)
self.CutterName = StringVar()
self.CutterFrame = Tk.Frame(self.TopFrame)
self.CutterFrame.pack(side=Tk.TOP, anchor=Tk.W)
Tk.Label(self.CutterFrame, text="Tool: ").pack(side=Tk.LEFT)
self.CutterName = Tk.StringVar()
self.CutterName.set(Cutters.list[0])
for cutter in Cutters.list:
Radiobutton(self.CutterFrame, text=cutter, variable=self.CutterName, value=cutter).pack(side=LEFT)
Tk.Radiobutton(self.CutterFrame, text=cutter, variable=self.CutterName, value=cutter).pack(side=Tk.LEFT)
self.PathGeneratorFrame = Frame(self.TopFrame)
self.PathGeneratorFrame.pack(side=TOP, expand=0, anchor=W)
Label(self.PathGeneratorFrame, text="PathGenerator: ").pack(side=LEFT)
self.PathGeneratorName = StringVar()
self.PathGeneratorFrame = Tk.Frame(self.TopFrame)
self.PathGeneratorFrame.pack(side=Tk.TOP, expand=0, anchor=Tk.W)
Tk.Label(self.PathGeneratorFrame, text="PathGenerator: ").pack(side=Tk.LEFT)
self.PathGeneratorName = Tk.StringVar()
self.PathGeneratorName.set(PathGenerators.list[0])
for PathGenerator in PathGenerators.list:
Radiobutton(self.PathGeneratorFrame, text=PathGenerator, variable=self.PathGeneratorName, value=PathGenerator).pack(side=LEFT)
Tk.Radiobutton(self.PathGeneratorFrame, text=PathGenerator, variable=self.PathGeneratorName, value=PathGenerator).pack(side=Tk.LEFT)
self.PathProcessorFrame = Frame(self.TopFrame)
self.PathProcessorFrame.pack(side=TOP, expand=0, anchor=W)
Label(self.PathProcessorFrame, text="Postprocessor: ").pack(side=LEFT)
self.PathProcessorName = StringVar()
self.PathProcessorFrame = Tk.Frame(self.TopFrame)
self.PathProcessorFrame.pack(side=Tk.TOP, expand=0, anchor=Tk.W)
Tk.Label(self.PathProcessorFrame, text="Postprocessor: ").pack(side=Tk.LEFT)
self.PathProcessorName = Tk.StringVar()
self.PathProcessorName.set(PathProcessors.list[0])
for option in PathProcessors.list:
Radiobutton(self.PathProcessorFrame, text=option, variable=self.PathProcessorName, value=option).pack(side=LEFT)
Tk.Radiobutton(self.PathProcessorFrame, text=option, variable=self.PathProcessorName, value=option).pack(side=Tk.LEFT)
self.ConfigurationFrame = Frame(self.TopFrame)
self.ConfigurationFrame.pack(side=TOP, anchor=W, expand=0, fill=X)
Label(self.ConfigurationFrame, text="Tool Radius: ").pack(side=LEFT)
self.ToolRadius = StringVar()
self.ConfigurationFrame = Tk.Frame(self.TopFrame)
self.ConfigurationFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0, fill=Tk.X)
Tk.Label(self.ConfigurationFrame, text="Tool Radius: ").pack(side=Tk.LEFT)
self.ToolRadius = Tk.StringVar()
self.ToolRadius.set("1.0")
s = Spinbox(self.ConfigurationFrame, width=5, text='Radius', from_=0.1, to=5.0, increment=0.1, format="%2.1f")
s.pack(side=LEFT)
s = Tk.Spinbox(self.ConfigurationFrame, width=5, text='Radius', from_=0.1, to=5.0, increment=0.1, format="%2.1f")
s.pack(side=Tk.LEFT)
s["textvariable"] = self.ToolRadius
Label(self.ConfigurationFrame, text="Torus Radius: ").pack(side=LEFT)
self.TorusRadius = StringVar()
Tk.Label(self.ConfigurationFrame, text="Torus Radius: ").pack(side=Tk.LEFT)
self.TorusRadius = Tk.StringVar()
self.TorusRadius.set("0.25")
s = Spinbox(self.ConfigurationFrame, width=5, text='Toroid', from_=0.1, to=5.0, increment=0.1, format="%2.1f")
s = Tk.Spinbox(self.ConfigurationFrame, width=5, text='Toroid', from_=0.1, to=5.0, increment=0.1, format="%2.1f")
s["textvariable"] = self.TorusRadius
s.pack(side=LEFT)
s.pack(side=Tk.LEFT)
Label(self.ConfigurationFrame, text="Unit: ").pack(side=LEFT)
self.Unit = StringVar()
Tk.Label(self.ConfigurationFrame, text="Unit: ").pack(side=Tk.LEFT)
self.Unit = Tk.StringVar()
self.Unit.set("mm")
Radiobutton(self.ConfigurationFrame, text="mm", variable=self.Unit, value="mm", command=self.ogl.tkRedraw).pack(side=LEFT)
Radiobutton(self.ConfigurationFrame, text="in", variable=self.Unit, value="in", command=self.ogl.tkRedraw).pack(side=LEFT)
Tk.Radiobutton(self.ConfigurationFrame, text="mm", variable=self.Unit, value="mm", command=self.ogl.tkRedraw).pack(side=Tk.LEFT)
Tk.Radiobutton(self.ConfigurationFrame, text="in", variable=self.Unit, value="in", command=self.ogl.tkRedraw).pack(side=Tk.LEFT)
Label(self.ConfigurationFrame, text="Dir: ").pack(side=LEFT)
self.Direction = StringVar()
Tk.Label(self.ConfigurationFrame, text="Dir: ").pack(side=Tk.LEFT)
self.Direction = Tk.StringVar()
self.Direction.set("x")
Radiobutton(self.ConfigurationFrame, text="x", variable=self.Direction, value="x", command=self.ogl.tkRedraw).pack(side=LEFT)
Radiobutton(self.ConfigurationFrame, text="y", variable=self.Direction, value="y", command=self.ogl.tkRedraw).pack(side=LEFT)
Radiobutton(self.ConfigurationFrame, text="xy", variable=self.Direction, value="xy", command=self.ogl.tkRedraw).pack(side=LEFT)
Tk.Radiobutton(self.ConfigurationFrame, text="x", variable=self.Direction, value="x", command=self.ogl.tkRedraw).pack(side=Tk.LEFT)
Tk.Radiobutton(self.ConfigurationFrame, text="y", variable=self.Direction, value="y", command=self.ogl.tkRedraw).pack(side=Tk.LEFT)
Tk.Radiobutton(self.ConfigurationFrame, text="xy", variable=self.Direction, value="xy", command=self.ogl.tkRedraw).pack(side=Tk.LEFT)
self.MinX = StringVar()
self.MinX = Tk.StringVar()
self.MinX.set("-7")
self.MinY = StringVar()
self.MinY = Tk.StringVar()
self.MinY.set("-7")
self.MinZ = StringVar()
self.MinZ = Tk.StringVar()
self.MinZ.set("0")
self.MaxX = StringVar()
self.MaxX = Tk.StringVar()
self.MaxX.set("+7")
self.MaxY = StringVar()
self.MaxY = Tk.StringVar()
self.MaxY.set("+7")
self.MaxZ = StringVar()
self.MaxZ = Tk.StringVar()
self.MaxZ.set("+3")
self.StockModelFrame = Frame(self.TopFrame)
self.StockModelFrame.pack(side=TOP, anchor=W, expand=0, fill=X)
Label(self.StockModelFrame, text="Min X").pack(side=LEFT)
Entry(self.StockModelFrame, textvariable=self.MinX, width=6).pack(side=LEFT)
Label(self.StockModelFrame, text="Min Y").pack(side=LEFT)
Entry(self.StockModelFrame, textvariable=self.MinY, width=6).pack(side=LEFT)
Label(self.StockModelFrame, text="Min Z").pack(side=LEFT)
Entry(self.StockModelFrame, textvariable=self.MinZ, width=6).pack(side=LEFT)
Label(self.StockModelFrame, text="Max X").pack(side=LEFT)
Entry(self.StockModelFrame, textvariable=self.MaxX, width=6).pack(side=LEFT)
Label(self.StockModelFrame, text="Max Y").pack(side=LEFT)
Entry(self.StockModelFrame, textvariable=self.MaxY, width=6).pack(side=LEFT)
Label(self.StockModelFrame, text="Max Z").pack(side=LEFT)
Entry(self.StockModelFrame, textvariable=self.MaxZ, width=6).pack(side=LEFT)
self.ConfigFrame = Frame(self.TopFrame)
self.ConfigFrame.pack(side=TOP, anchor=W, expand=0, fill=X)
self.Layers = StringVar()
self.StockModelFrame = Tk.Frame(self.TopFrame)
self.StockModelFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0, fill=Tk.X)
Tk.Label(self.StockModelFrame, text="Min X").pack(side=Tk.LEFT)
Tk.Entry(self.StockModelFrame, textvariable=self.MinX, width=6).pack(side=Tk.LEFT)
Tk.Label(self.StockModelFrame, text="Min Y").pack(side=Tk.LEFT)
Tk.Entry(self.StockModelFrame, textvariable=self.MinY, width=6).pack(side=Tk.LEFT)
Tk.Label(self.StockModelFrame, text="Min Z").pack(side=Tk.LEFT)
Tk.Entry(self.StockModelFrame, textvariable=self.MinZ, width=6).pack(side=Tk.LEFT)
Tk.Label(self.StockModelFrame, text="Max X").pack(side=Tk.LEFT)
Tk.Entry(self.StockModelFrame, textvariable=self.MaxX, width=6).pack(side=Tk.LEFT)
Tk.Label(self.StockModelFrame, text="Max Y").pack(side=Tk.LEFT)
Tk.Entry(self.StockModelFrame, textvariable=self.MaxY, width=6).pack(side=Tk.LEFT)
Tk.Label(self.StockModelFrame, text="Max Z").pack(side=Tk.LEFT)
Tk.Entry(self.StockModelFrame, textvariable=self.MaxZ, width=6).pack(side=Tk.LEFT)
self.ConfigFrame = Tk.Frame(self.TopFrame)
self.ConfigFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0, fill=Tk.X)
self.Layers = Tk.StringVar()
self.Layers.set("1")
Label(self.ConfigFrame, text="Layers").pack(side=LEFT)
Entry(self.ConfigFrame, textvariable=self.Layers, width=6).pack(side=LEFT)
self.Samples = StringVar()
Tk.Label(self.ConfigFrame, text="Layers").pack(side=Tk.LEFT)
Tk.Entry(self.ConfigFrame, textvariable=self.Layers, width=6).pack(side=Tk.LEFT)
self.Samples = Tk.StringVar()
self.Samples.set("50")
Label(self.ConfigFrame, text="Samples").pack(side=LEFT)
Entry(self.ConfigFrame, textvariable=self.Samples, width=6).pack(side=LEFT)
self.Lines = StringVar()
Tk.Label(self.ConfigFrame, text="Samples").pack(side=Tk.LEFT)
Tk.Entry(self.ConfigFrame, textvariable=self.Samples, width=6).pack(side=Tk.LEFT)
self.Lines = Tk.StringVar()
self.Lines.set("20")
Label(self.ConfigFrame, text="Lines").pack(side=LEFT)
Entry(self.ConfigFrame, textvariable=self.Lines, width=6).pack(side=LEFT)
Button(self.ConfigFrame, text="Generate Toolpath", command=self.generateToolpath).pack(side=RIGHT)
Tk.Label(self.ConfigFrame, text="Lines").pack(side=Tk.LEFT)
Tk.Entry(self.ConfigFrame, textvariable=self.Lines, width=6).pack(side=Tk.LEFT)
Tk.Button(self.ConfigFrame, text="Generate Toolpath", command=self.generateToolpath).pack(side=Tk.RIGHT)
self.OutputFileFrame = Frame(self.TopFrame)
self.OutputFileFrame.pack(side=TOP, anchor=W, expand=0, fill=X)
Label(self.OutputFileFrame, text= "Output File: ").pack(side=LEFT)
self.OutputFileName = StringVar()
self.OutputFileField = Entry(self.OutputFileFrame, textvariable=self.OutputFileName).pack(side=LEFT, expand=1, fill=X)
self.OutputFileFrame = Tk.Frame(self.TopFrame)
self.OutputFileFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0, fill=Tk.X)
Tk.Label(self.OutputFileFrame, text= "Output File: ").pack(side=Tk.LEFT)
self.OutputFileName = Tk.StringVar()
self.OutputFileField = Tk.Entry(self.OutputFileFrame, textvariable=self.OutputFileName).pack(side=Tk.LEFT, expand=1, fill=Tk.X)
self.FeedRate = StringVar()
self.FeedRate = Tk.StringVar()
self.FeedRate.set("200")
Label(self.OutputFileFrame, text="FeedRate").pack(side=LEFT)
Entry(self.OutputFileFrame, textvariable=self.FeedRate, width=6).pack(side=LEFT)
self.Speed = StringVar()
Tk.Label(self.OutputFileFrame, text="FeedRate").pack(side=Tk.LEFT)
Tk.Entry(self.OutputFileFrame, textvariable=self.FeedRate, width=6).pack(side=Tk.LEFT)
self.Speed = Tk.StringVar()
self.Speed.set("1000")
Label(self.OutputFileFrame, text="Speed").pack(side=LEFT)
Entry(self.OutputFileFrame, textvariable=self.Speed, width=6).pack(side=LEFT)
Tk.Label(self.OutputFileFrame, text="Speed").pack(side=Tk.LEFT)
Tk.Entry(self.OutputFileFrame, textvariable=self.Speed, width=6).pack(side=Tk.LEFT)
self.OutputFileBrowse = Button(self.OutputFileFrame, text="Export...", command=self.browseSaveAs).pack(side=RIGHT)
self.OutputFileBrowse = Tk.Button(self.OutputFileFrame, text="Export...", command=self.browseSaveAs).pack(side=Tk.RIGHT)
self.ViewFrame = Frame(self.TopFrame)
self.ViewFrame.pack(side=TOP, anchor=W, expand=0)
Label(self.ViewFrame, text="View: ").pack(side=LEFT)
Button(self.ViewFrame, text="Reset", command=self.resetView).pack(side=LEFT)
Button(self.ViewFrame, text="Front", command=self.frontView).pack(side=LEFT)
Button(self.ViewFrame, text="Back", command=self.backView).pack(side=LEFT)
Button(self.ViewFrame, text="Left", command=self.leftView).pack(side=LEFT)
Button(self.ViewFrame, text="Right", command=self.rightView).pack(side=LEFT)
Button(self.ViewFrame, text="Top", command=self.topView).pack(side=LEFT)
self.ViewFrame = Tk.Frame(self.TopFrame)
self.ViewFrame.pack(side=Tk.TOP, anchor=Tk.W, expand=0)
Tk.Label(self.ViewFrame, text="View: ").pack(side=Tk.LEFT)
Tk.Button(self.ViewFrame, text="Reset", command=self.resetView).pack(side=Tk.LEFT)
Tk.Button(self.ViewFrame, text="Front", command=self.frontView).pack(side=Tk.LEFT)
Tk.Button(self.ViewFrame, text="Back", command=self.backView).pack(side=Tk.LEFT)
Tk.Button(self.ViewFrame, text="Left", command=self.leftView).pack(side=Tk.LEFT)
Tk.Button(self.ViewFrame, text="Right", command=self.rightView).pack(side=Tk.LEFT)
Tk.Button(self.ViewFrame, text="Top", command=self.topView).pack(side=Tk.LEFT)
self.ogl.pack(side='bottom', expand=1, fill=BOTH)
self.ogl.pack(side='bottom', expand=1, fill=Tk.BOTH)
self.ogl.set_background(0,0,0)
self.ogl.bind('<Button-2>',self.ogl.tkRecordMouse)
self.ogl.bind('<B2-Motion>', self.ogl.tkTranslate)
......@@ -484,10 +482,10 @@ class SimpleGui(Frame):
self.ogl.bind('<B3-Motion>', self.ogl.tkScale)
self.ogl.redraw = self.Redraw
self.pack(expand=1, fill=BOTH)
self.pack(expand=1, fill=Tk.BOTH)
def __init__(self, master=None):
Frame.__init__(self, master)
Tk.Frame.__init__(self, master)
self.model = None
self.toolpath = None
self.createWidgets()
......@@ -517,49 +515,49 @@ class SimpleGui(Frame):
self.toolpath = pc.GenerateToolPath(x0,x1,y0,y1,z0,z1,dx,dy,dz)
def resetView(self):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glScalef(self.scale,self.scale,self.scale)
glRotatef(110,1.0,0.0,0.0)
glRotatef(180,0.0,1.0,0.0)
glRotatef(160,0.0,0.0,1.0)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glScalef(self.scale,self.scale,self.scale)
GL.glRotatef(110,1.0,0.0,0.0)
GL.glRotatef(180,0.0,1.0,0.0)
GL.glRotatef(160,0.0,0.0,1.0)
self.ogl.tkRedraw()
def frontView(self):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glScalef(self.scale,self.scale,self.scale)
glRotatef(-90,1.0,0,0)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glScalef(self.scale,self.scale,self.scale)
GL.glRotatef(-90,1.0,0,0)
self.ogl.tkRedraw()
def backView(self):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glScalef(self.scale,self.scale,self.scale)
glRotatef(-90,1.0,0,0)
glRotatef(180,0,0,1.0)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glScalef(self.scale,self.scale,self.scale)
GL.glRotatef(-90,1.0,0,0)
GL.glRotatef(180,0,0,1.0)
self.ogl.tkRedraw()
def leftView(self):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glScalef(self.scale,self.scale,self.scale)
glRotatef(-90,1.0,0,0)
glRotatef(90,0,0,1.0)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glScalef(self.scale,self.scale,self.scale)
GL.glRotatef(-90,1.0,0,0)
GL.glRotatef(90,0,0,1.0)
self.ogl.tkRedraw()
def rightView(self):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glScalef(self.scale,self.scale,self.scale)
glRotatef(-90,1.0,0,0)
glRotatef(-90,0,0,1.0)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glScalef(self.scale,self.scale,self.scale)
GL.glRotatef(-90,1.0,0,0)
GL.glRotatef(-90,0,0,1.0)
self.ogl.tkRedraw()
def topView(self):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glScalef(self.scale,self.scale,self.scale)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glScalef(self.scale,self.scale,self.scale)
self.ogl.tkRedraw()
......
......@@ -3,9 +3,10 @@ from pycam.Geometry.Point import Point
import ctypes
try:
from OpenGL.GL import *
import OpenGL.GL as GL
GL_enabled = True
except:
pass
GL_enabled = False
EPSILON=1e-8
......@@ -166,7 +167,8 @@ class ZBuffer:
self.changed = True
def to_OpenGL(self):
self.to_OpenGL_6()
if GL_enabled:
self.to_OpenGL_6()
self.changed = False
def normal(self, z0, z1, z2):
......@@ -177,17 +179,17 @@ class ZBuffer:
# the naive way (quads)
def to_OpenGL_1(self):
glBegin(GL_QUADS)
GL.glBegin(GL.GL_QUADS)
for y in range(0,self.yres-1):
for x in range(0,self.xres-1):
n = self.normal(self.buf[y+0][x+0].z,self.buf[y+0][x+1].z,self.buf[y+1][x+0].z)
glNormal3f(n[0],n[1],n[2])
glVertex3f(self.x[x+0], self.y[y+0], self.buf[y+0][x+0].z)
glVertex3f(self.x[x+1], self.y[y+0], self.buf[y+0][x+1].z)
glVertex3f(self.x[x+1], self.y[y+1], self.buf[y+1][x+1].z)
glVertex3f(self.x[x+0], self.y[y+1], self.buf[y+1][x+0].z)
GL.glNormal3f(n[0],n[1],n[2])
GL.glVertex3f(self.x[x+0], self.y[y+0], self.buf[y+0][x+0].z)
GL.glVertex3f(self.x[x+1], self.y[y+0], self.buf[y+0][x+1].z)
GL.glVertex3f(self.x[x+1], self.y[y+1], self.buf[y+1][x+1].z)
GL.glVertex3f(self.x[x+0], self.y[y+1], self.buf[y+1][x+0].z)
glEnd()
GL.glEnd()
# use display lists (per quad)
def to_OpenGL_2(self):
......@@ -199,23 +201,23 @@ class ZBuffer:
# print "z[%f][%f]=%f" % (self.y[y],self.x[x],self.buf[y][x])
if self.buf[y+0][x+0].changed or self.buf[y+0][x+1].changed or self.buf[y+1][x+0].changed or self.buf[y+1][x+1].changed:
if self.buf[y][x].list == -1:
self.buf[y][x].list = glGenLists(1)
self.buf[y][x].list = GL.glGenLists(1)
glNewList(self.buf[y][x].list, GL_COMPILE)
glBegin(GL_QUADS)
GL.glNewList(self.buf[y][x].list, GL.GL_COMPILE)
GL.glBegin(GL.GL_QUADS)
n = self.normal(self.buf[y+0][x+0].z,self.buf[y+0][x+1].z,self.buf[y+1][x+0].z)
glNormal3f(n[0],n[1],n[2])
glVertex3f(self.x[x+0], self.y[y+0], self.buf[y+0][x+0].z)
glVertex3f(self.x[x+1], self.y[y+0], self.buf[y+0][x+1].z)
glVertex3f(self.x[x+1], self.y[y+1], self.buf[y+1][x+1].z)
glVertex3f(self.x[x+0], self.y[y+1], self.buf[y+1][x+0].z)
glEnd()
glEndList()
GL.glNormal3f(n[0],n[1],n[2])
GL.glVertex3f(self.x[x+0], self.y[y+0], self.buf[y+0][x+0].z)
GL.glVertex3f(self.x[x+1], self.y[y+0], self.buf[y+0][x+1].z)
GL.glVertex3f(self.x[x+1], self.y[y+1], self.buf[y+1][x+1].z)
GL.glVertex3f(self.x[x+0], self.y[y+1], self.buf[y+1][x+0].z)
GL.glEnd()
GL.glEndList()
for y in range(0,self.yres-1):
for x in range(0,self.xres-1):
self.buf[y][x].changed = False
glCallList(self.buf[y][x].list)
GL.glCallList(self.buf[y][x].list)
# use display list per cell (cell = group of quads)
def to_OpenGL_3(self):
......@@ -244,43 +246,43 @@ class ZBuffer:
if changed:
if self.list[y][x] == -1:
self.list[y][x] = glGenLists(1)
self.list[y][x] = GL.glGenLists(1)
if False:
glNewList(self.list[y][x], GL_COMPILE)
GL.glNewList(self.list[y][x], GL.GL_COMPILE)
for yi in range(y0,y1-1):
glBegin(GL_TRIANGLES)
GL.glBegin(GL.GL_TRIANGLES)
for xi in range(x0,x1-1):
n = self.normal(self.buf[yi+0][xi+0].z,self.buf[yi+0][xi+1].z,self.buf[yi+1][xi+0].z)
glNormal3f(n[0],n[1],n[2])
glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z)
glVertex3f(self.x[xi+0], self.y[yi+1], self.buf[yi+1][xi+0].z)
glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z)
GL.glNormal3f(n[0],n[1],n[2])
GL.glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z)
GL.glVertex3f(self.x[xi+0], self.y[yi+1], self.buf[yi+1][xi+0].z)
GL.glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z)
n = self.normal(self.buf[y+1][x+1].z,self.buf[y+0][x+1].z,self.buf[y+1][x+0].z)
glNormal3f(n[0],n[1],n[2])
glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z)
glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z)
glVertex3f(self.x[xi+1], self.y[yi+0], self.buf[yi+0][xi+1].z)
GL.glNormal3f(n[0],n[1],n[2])
GL.glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z)
GL.glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z)
GL.glVertex3f(self.x[xi+1], self.y[yi+0], self.buf[yi+0][xi+1].z)
self.buf[yi][xi].changed = False
glEnd()
glEndList()
GL.glEnd()
GL.glEndList()
else:
glNewList(self.list[y][x], GL_COMPILE)
GL.glNewList(self.list[y][x], GL.GL_COMPILE)
for yi in range(y0,y1-1):
glBegin(GL_QUADS)
GL.glBegin(GL.GL_QUADS)
for xi in range(x0,x1-1):
n = self.normal(self.buf[yi+0][xi+0].z,self.buf[yi+0][xi+1].z,self.buf[yi+1][xi+0].z)
glNormal3f(n[0],n[1],n[2])
glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z)
glVertex3f(self.x[xi+0], self.y[yi+1], self.buf[yi+1][xi+0].z)
glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z)
glVertex3f(self.x[xi+1], self.y[yi+0], self.buf[yi+0][xi+1].z)
GL.glNormal3f(n[0],n[1],n[2])
GL.glVertex3f(self.x[xi+0], self.y[yi+0], self.buf[yi+0][xi+0].z)
GL.glVertex3f(self.x[xi+0], self.y[yi+1], self.buf[yi+1][xi+0].z)
GL.glVertex3f(self.x[xi+1], self.y[yi+1], self.buf[yi+1][xi+1].z)
GL.glVertex3f(self.x[xi+1], self.y[yi+0], self.buf[yi+0][xi+1].z)
self.buf[yi][xi].changed = False
glEnd()
glEndList()
GL.glEnd()
GL.glEndList()
glCallList(self.list[y][x])
GL.glCallList(self.list[y][x])
# use display list with vertex buffers per cell (cell = group of quads)
def to_OpenGL_4(self):
......@@ -319,12 +321,12 @@ class ZBuffer:
if changed:
# print "cell[",y,"][",x,"]=",self.cell[y][x].list
if self.cell[y][x].list == -1:
self.cell[y][x].list = glGenLists(1)
self.cell[y][x].list = GL.glGenLists(1)
self.cell[y][x].array = (ctypes.c_float*3*((y1-y0)*(x1-x0)*2))()
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointerf(self.cell[y][x].array)
glNewList(self.cell[y][x].list, GL_COMPILE)
GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
GL.glVertexPointerf(self.cell[y][x].array)
GL.glNewList(self.cell[y][x].list, GL.GL_COMPILE)
idx = 0
for yi in range(y0,y1-1):
lineidx = idx
......@@ -338,10 +340,10 @@ class ZBuffer:
self.cell[y][x].array[idx+1][1] = self.y[yi+1]
self.cell[y][x].array[idx+1][2] = self.buf[yi+1][xi+0].z
idx += 2
glDrawArrays(GL_QUAD_STRIP, lineidx, idx-lineidx+1)
glEndList()
GL.glDrawArrays(GL.GL_QUAD_STRIP, lineidx, idx-lineidx+1)
GL.glEndList()
glCallList(self.cell[y][x].list)
GL.glCallList(self.cell[y][x].list)
# use display list with vertex and normal buffers per cell (cell = group of quads)
def to_OpenGL_5(self):
......@@ -357,8 +359,8 @@ class ZBuffer:
num_cell_x = 1
dx = self.xres
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_NORMAL_ARRAY)
GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
GL.glEnableClientState(GL.GL_NORMAL_ARRAY)
for y in range(0,num_cell_y):
y0 = y*dy
......@@ -383,13 +385,13 @@ class ZBuffer:
if changed:
# print "cell[",y,"][",x,"]=",self.cell[y][x].list
if self.cell[y][x].list == -1:
self.cell[y][x].list = glGenLists(1)
self.cell[y][x].list = GL.glGenLists(1)
self.cell[y][x].vertex = (ctypes.c_float*3*((y1-y0)*(x1-x0)*4))()
self.cell[y][x].normal = (ctypes.c_float*3*((y1-y0)*(x1-x0)*4))()
glVertexPointerf(self.cell[y][x].vertex)
glNormalPointerf(self.cell[y][x].normal)
glNewList(self.cell[y][x].list, GL_COMPILE)
GL.glVertexPointerf(self.cell[y][x].vertex)
GL.glNormalPointerf(self.cell[y][x].normal)
GL.glNewList(self.cell[y][x].list, GL.GL_COMPILE)
idx = 0
for yi in range(y0,y1-1):
lineidx = idx
......@@ -424,13 +426,13 @@ class ZBuffer:
self.cell[y][x].normal[idx+3][2] = n[2]
idx += 4
glDrawArrays(GL_QUADS, lineidx, idx-lineidx+1)
glEndList()
GL.glDrawArrays(GL.GL_QUADS, lineidx, idx-lineidx+1)
GL.glEndList()
glCallList(self.cell[y][x].list)
GL.glCallList(self.cell[y][x].list)
glDisableClientState(GL_VERTEX_ARRAY)
glDisableClientState(GL_NORMAL_ARRAY)
GL.glDisableClientState(GL.GL_VERTEX_ARRAY)
GL.glDisableClientState(GL.GL_NORMAL_ARRAY)
# use display list with vertex and normal and index buffers per cell (cell = group of quads)
def to_OpenGL_6(self):
......@@ -446,9 +448,9 @@ class ZBuffer:
num_cell_x = 1
dx = self.xres
glEnableClientState(GL_INDEX_ARRAY)
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_NORMAL_ARRAY)
GL.glEnableClientState(GL.GL_INDEX_ARRAY)
GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
GL.glEnableClientState(GL.GL_NORMAL_ARRAY)
for y in range(0,num_cell_y):
y0 = y*dy
......@@ -473,15 +475,15 @@ class ZBuffer:
if changed:
#print "cell[",y,"][",x,"]=",self.cell[y][x].list
if self.cell[y][x].list == -1:
self.cell[y][x].list = glGenLists(1)
self.cell[y][x].list = GL.glGenLists(1)
self.cell[y][x].vertex = (ctypes.c_float*3*((y1-y0)*(x1-x0)))()
self.cell[y][x].normal = (ctypes.c_float*3*((y1-y0)*(x1-x0)))()
self.cell[y][x].index = (ctypes.c_ushort*(4*(y1-y0-1)*(x1-x0-1)))()
glIndexPointers(self.cell[y][x].index)
glVertexPointerf(self.cell[y][x].vertex)
glNormalPointerf(self.cell[y][x].normal)
GL.glIndexPointers(self.cell[y][x].index)
GL.glVertexPointerf(self.cell[y][x].vertex)
GL.glNormalPointerf(self.cell[y][x].normal)
glNewList(self.cell[y][x].list, GL_COMPILE)
GL.glNewList(self.cell[y][x].list, GL.GL_COMPILE)
idx = 0
for yi in range(y0,y1):
for xi in range(x0,x1):
......@@ -510,11 +512,11 @@ class ZBuffer:
self.cell[y][x].index[idx+3] = (yi-y0+0)*(x1-x0) + (xi-x0+1)
idx += 4
glDrawElements(GL_QUADS, idx, GL_UNSIGNED_SHORT, self.cell[y][x].index)
glEndList()
glCallList(self.cell[y][x].list)
GL.glDrawElements(GL.GL_QUADS, idx, GL.GL_UNSIGNED_SHORT, self.cell[y][x].index)
GL.glEndList()
GL.glCallList(self.cell[y][x].list)
glDisableClientState(GL_VERTEX_ARRAY)
glDisableClientState(GL_NORMAL_ARRAY)
glDisableClientState(GL_INDEX_ARRAY)
GL.glDisableClientState(GL.GL_VERTEX_ARRAY)
GL.glDisableClientState(GL.GL_NORMAL_ARRAY)
GL.glDisableClientState(GL.GL_INDEX_ARRAY)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment