本文整理汇总了Python中opengltk.OpenGL.GL.glColor4fv方法的典型用法代码示例。如果您正苦于以下问题:Python GL.glColor4fv方法的具体用法?Python GL.glColor4fv怎么用?Python GL.glColor4fv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opengltk.OpenGL.GL
的用法示例。
在下文中一共展示了GL.glColor4fv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: arcdraw
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def arcdraw(self, x, n, radius, colxf=None):
# determine scale and rotation of template
import math
sz=0.0
y = [0, 0, 0]
for i in (0,1,2):
y[i] = x[i]+n[i]
for i in (0,1,2):
sz=sz+(x[i]-y[i])*(x[i]-y[i])
sz = sqrt(sz)
if sz==0.0:
return
rx = -180.0*acos((y[2]-x[2])/sz)/pi
rz = -180.0*atan2(y[0]-x[0],y[1]-x[1])/pi
GL.glPushMatrix()
GL.glTranslatef(float(x[0]),float(x[1]),float(x[2]))
if rz<=180.0 and rz >=-180.0:
GL.glRotatef(float(rz), 0., 0., 1.)
GL.glRotatef(float(rx), 1., 0., 0.)
GL.glScalef(float(radius),float(radius),float(sz))
# draw circle
GL.glColor4fv(colxf)
GL.glBegin(GL.GL_LINE_STRIP)
for i in range(self.nsegments+1):
GL.glVertex3fv(self.v[i])
GL.glEnd()
GL.glPopMatrix()
示例2: setMaterial
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def setMaterial(self):
if __debug__:
if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
mat = self.material
GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, mat[self.ambi][0])
diff = mat[self.diff][0]
diff[3] = mat[self.opac][0]
GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, mat[self.diff][0])
GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, mat[self.spec][0])
GL.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, mat[self.emis][0])
GL.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, float(mat[self.shini][0]))
GL.glColor4fv(mat[self.diff][0])
示例3: Draw
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def Draw(self):
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glPushMatrix()
GL.glLoadIdentity()
Insert2d.Draw(self)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glPushMatrix()
GL.glLoadIdentity()
GL.glDisable(GL.GL_DEPTH_TEST)
GL.glDisable(GL.GL_LIGHTING);
width = self.size[0]
height = self.size[1]
fullWidth = self.viewer.currentCamera.width
fullHeight = self.viewer.currentCamera.height
# we want the anchor of the image to be at the given position
posxFromLeft = self.position[0] * fullWidth - self.anchor[0] * width
posyFrombottom = (1.-self.position[1]) * fullHeight - (1.-self.anchor[1]) * height
#print "posxFromLeft, posyFrombottom", posxFromLeft, posyFrombottom
GL.glColor4fv(self.color)
xo, yo = self.position
dx, dy = self.size
GL.glBegin(GL.GL_QUADS);
GL.glVertex2f(xo, yo)
GL.glVertex2f(xo+dx, yo)
GL.glVertex2f(xo+dx, yo+dy)
GL.glVertex2f(xo, yo+dy)
GL.glEnd()
# used for picking
# self.polygonContour = [ (posxFromLeft, posyFrombottom),
# (posxFromLeft+width, posyFrombottom),
# (posxFromLeft+width, posyFrombottom+height),
# (posxFromLeft, posyFrombottom+height)
# ]
GL.glEnable(GL.GL_DEPTH_TEST)
GL.glEnable(GL.GL_LIGHTING);
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glPopMatrix()
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glPopMatrix()
return 1
示例4: InitColor
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def InitColor(self, num=0):
if __debug__:
if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
"""Setup GL color (used when lighting is turned off)
only sets the color if binding mode is OVERALL or PER_INSTANCE (i.e. per
instance matrix) which are the 2 only colors which are not set in the
display list"""
prop = self.materials[GL.GL_FRONT]
if prop.binding[1] == viewerConst.OVERALL:
material = prop.prop[prop.diff][0]
if not material.flags.contiguous:
material = Numeric.array(material,copy=1)
GL.glColor4fv ( material.tolist() )
elif prop.binding[1] == viewerConst.PER_INSTANCE:
material = prop.prop[prop.diff][num]
if not material.flags.contiguous:
material = Numeric.array(material,copy=1)
GL.glColor4fv ( material.tolist() )
示例5: drawSticker
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def drawSticker(self, lLabelbounds):
if self.framePolygonMode != GL.GL_NONE:
lenFrameColor = len(self.frameColor)
if lenFrameColor == 4:
GL.glColor4fv(self.frameColor)
elif lenFrameColor == 3:
GL.glColor3fv(self.frameColor)
GL.glPolygonMode(GL.GL_FRONT, self.framePolygonMode)
GL.glBegin(GL.GL_QUADS)
GL.glVertex2f(0, 0)
GL.glVertex2f(float(self.size[0]), 0)
GL.glVertex2f(float(self.size[0]), float(self.size[1]))
GL.glVertex2f(0, float(self.size[1]))
GL.glEnd()
GL.glScalef(float(self.fontScales[0]),
float(self.fontScales[1]),
0)
GL.glTranslatef(float(self.frameSpace[0]),
float(self.frameSpace[1]),
0)
# this corrects the glf draw function to start the label at the proper position
GL.glTranslatef(1, float(-lLabelbounds[1]), 0)
lenFontColor = len(self.fontColor)
if lenFontColor == 4:
GL.glColor4fv(self.fontColor)
elif lenFontColor == 3:
GL.glColor3fv(self.fontColor)
GL.glPolygonMode(GL.GL_FRONT, GL.GL_FILL)
if self.wireFont in [0, False]:
glf.glfDrawSolidString(self.label)
else:
glf.glfDrawWiredString(self.label)
示例6: drawLegendLabelName
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
#.........这里部分代码省略.........
if selected is True:
labelColor2 = (.5, .5, .5)
else:
labelColor2 = labelColor
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glPushMatrix()
GL.glLoadIdentity()
if tile is None:
GL.glOrtho(0, float(fullWidth), 0, float(fullHeight), -1, 1)
else:
GL.glOrtho(float(tile[0]), float(tile[1]), float(tile[2]), float(tile[3]), -1, 1)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glPushMatrix()
GL.glLoadIdentity()
GL.glDisable( GL.GL_LIGHTING )
GL.glPolygonMode(GL.GL_FRONT, GL.GL_FILL )
if len(backgroundColor) == 4:
GL.glEnable(GL.GL_BLEND)
GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
#because of an unexplained bug on michel's laptop,
#we don't draw the background when there is no frame
#(so michel has a way to manage the legend)
if frame is True:
#draw transparent background
GL.glDepthMask(GL.GL_FALSE)
if len(backgroundColor) == 3:
GL.glColor3fv(backgroundColor)
else:
GL.glColor4fv(backgroundColor)
GL.glBegin(GL.GL_QUADS)
GL.glVertex3fv(lPt1)
GL.glVertex3fv(lPt2)
GL.glVertex3fv(lPt3)
GL.glVertex3fv(lPt4)
GL.glEnd()
GL.glDepthMask(GL.GL_TRUE)
#draw frame
if frame is True:
GL.glPolygonMode(GL.GL_FRONT, GL.GL_LINE )
GL.glLineWidth(1)
GL.glColor3fv(labelColor2)
GL.glBegin(GL.GL_QUADS)
GL.glVertex3fv(lPt1)
GL.glVertex3fv(lPt2)
GL.glVertex3fv(lPt3)
GL.glVertex3fv(lPt4)
GL.glEnd()
GL.glPolygonMode(GL.GL_FRONT, GL.GL_FILL)
if mini is not None and maxi is not None and maxi > mini:
lUnitStep = legendLongSide/float(maxi-mini)
else:
lUnitStep = legendLongSide
GL.glDisable( GL.GL_LIGHTING )
if verticalLegend is True:
if leftOrBelowLabels is True:
lRoomLeftToLabel = -fontScaleHalf + lRoomToLegendCloseLongSide
lRoomLeftToName = -fontScaleHalf + lRoomToLegendFarLongSide - lNameWidth
示例7: Draw
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def Draw(self):
OVERALL, PER_VERTEX, PER_PART, PER_FACE = 10, 11, 12, 13
#NONE, OVERALL, PER_VERTEX, PER_PART, PER_FACE = -1, 10, 11, 12, 13
propConst = DejaVu.viewerConst.propConst
noCol = 1
vert = self.vertexSet.vertices.array
if len(vert)==0: return
if not self.stripBegin or len(self.stripBegin)==0: return
if self.materials[GL.GL_FRONT] and not self.inheritMaterial:
frontMat = fpProp = []
frontMatBind = fpBind = []
mat = self.materials[GL.GL_FRONT]
for propInd in range(4):
b, p = mat.GetProperty(propInd)
fpProp.append(p)
fpBind.append(b)
fpProp.append(mat.prop[4])
fpBind.append(mat.binding[4])
else:
frontMat = None
frontMatBind = None
if self.materials[GL.GL_BACK] and not self.inheritMaterial:
backMat = bpProp = []
backMatBind = bpBind = []
mat = self.materials[GL.GL_BACK]
for propInd in range(4):
b, p = mat.GetProperty(propInd)
bpProp.append(p)
bpBind.append(b)
bpProp.append(mat.prop[4])
bpBind.append(mat.binding[4])
else:
backMat = None
backMatBind = None
if not self.frontAndBack is None:
face = GL.GL_FRONT
else:
face = GL.GL_FRONT_AND_BACK
n = self.normals
if self.normals is None: # overall color for no normals or lighting
if frontMat:
if frontMatBind[noCol] == OVERALL:
GL.glColor4fv( frontMat[noCol][0] )
else:
if len(self.normals)==1: # overall normal
GL.glNormal3dv(n[0])
if frontMat:
for j in range(5): # overall materials
if frontMatBind[j] == OVERALL:
glMaterialWithCheck( face, propConst[j],
frontMat[j][0] )
if backMat and not self.frontAndBack:
for j in range(5):
if backMatBind[j] == OVERALL:
glMaterialWithCheck( GL.GL_BACK, propConst[j],
backMat[j][0] )
self.isNewColor()
#self.isNewMaterial(0,0,0)
# loop over each strip
sB = self.stripBegin
sE = self.stripEnd
self.sE = sE
self.sB= sB
for stripNum in range(len(sB)):
#print 'stripNum',stripNum
GL.glPushName(stripNum)
GL.glBegin(GL.GL_TRIANGLE_STRIP)
# per part material properties
if frontMat:
if frontMatBind[noCol] == PER_PART:
if self.isNewColor(c=frontMat[noCol][stripNum]):
GL.glColor4fv(frontMat[noCol][stripNum])
if n is not None:
if frontMat:
for j in range(5):
if frontMatBind[j]==PER_PART:
glMaterialWithCheck( face,
propConst[j],
frontMat[j][stripNum] )
if backMat and not self.frontAndBack:
for j in range(5):
if backMatBind[j] == PER_PART:
glMaterialWithCheck( GL.GL_BACK,
propConst[j],
backMat[j][stripNum] )
#.........这里部分代码省略.........
示例8: Draw
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def Draw(self):
c = self.vertexSet.vertices.array
if len(c)==0: return
GL.glDisable(GL.GL_LIGHTING)
if self.materials[GL.GL_FRONT]:
mat = self.materials[GL.GL_FRONT]
binding = self.materials[GL.GL_FRONT].binding[mat.diff]
else:
binding = viewerConst.OVERALL
if binding == viewerConst.INHERIT:
for i in xrange(c.shape[0]): #loop over lines
GL.glPushName(i)
GL.glBegin(self.primitiveType)
for v in c[i]:
#GL.glVertex3dv(v.tolist())
#gllib.glVertex3dv(v)
gllib.glVertex3fv(v)
GL.glEnd()
GL.glPopName()
elif binding == viewerConst.OVERALL:
if self.materials[GL.GL_FRONT]:
col = mat.prop[mat.diff][0]
GL.glColor4fv(col)
for i in xrange(c.shape[0]): #loop over lines
GL.glPushName(i)
GL.glBegin(self.primitiveType)
for v in c[i]:
#GL.glVertex3dv(v.tolist())
#gllib.glVertex3dv(v)
gllib.glVertex3fv(v)
GL.glEnd()
GL.glPopName()
elif binding == viewerConst.PER_VERTEX:
if self.materials[GL.GL_FRONT]:
col = mat.prop[mat.diff]
vi = 0
for i in xrange(c.shape[0]):
GL.glPushName(i)
GL.glBegin(self.primitiveType)
for v in c[i]:
GL.glColor4fv(col[vi])
vi = vi + 1
#GL.glVertex3dv(v.tolist())
#gllib.glVertex3dv(v)
gllib.glVertex3fv(v)
GL.glEnd()
GL.glPopName()
elif binding == viewerConst.PER_PART: # i.e. line
if self.materials[GL.GL_FRONT]:
col = mat.prop[mat.diff]
for i in xrange(c.shape[0]):
GL.glColor4fv(col[i])
GL.glPushName(i)
GL.glBegin(self.primitiveType)
for v in c[i]:
#GL.glVertex3dv(v.tolist())
#gllib.glVertex3dv(v)
gllib.glVertex3fv(v)
GL.glEnd()
GL.glPopName()
#glEnable(GL_LIGHTING)
if self.viewer is not None:
self.viewer.enableOpenglLighting()
return True
示例9: cyldrawWithInterpolatedColors
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def cyldrawWithInterpolatedColors(self,
x, y, radx, rady, colxf=None, colxb=None,
colyf=None, colyb=None, face=None, **kw):
# draw a cylinder going from x to y with radii rx, and ry and materials
# colxf and colxb for front and back mterial in x
# colyf and colyb for front and back mterial in y
# face can be GL_FRONT_AND_BACK or something else
# determine scale and rotation of template
import math
sz=0.0
for i in (0,1,2): sz=sz+(x[i]-y[i])*(x[i]-y[i])
if sz <= 0.0: return
sz = math.sqrt(sz)
valueCos = (y[2]-x[2])/sz
valueCos = min(valueCos, 1)
valueCos = max(valueCos, -1)
rx = -180.0*math.acos(valueCos)/math.pi
dx = y[0]-x[0]
dy = y[1]-x[1]
if math.fabs(dx) < 0.00001 and math.fabs(dy) < 0.00001:
rz = 0.0
else:
rz = -180.0*math.atan2(dx,dy)/math.pi
GL.glPushMatrix()
GL.glTranslatef(float(x[0]),float(x[1]),float(x[2]))
if rz<=180.0 and rz >=-180.0: GL.glRotatef(float(rz), 0., 0., 1.)
GL.glRotatef(float(rx), 1., 0., 0.)
# draw cylinder
GL.glBegin(GL.GL_QUAD_STRIP)
for i in range(self.npoly+1):
if self.invertNormals:
GL.glNormal3fv(-self.n[i])
else:
GL.glNormal3fv(self.n[i])
if colxf:
for m in (0,1,2,3,4):
if colxf[m] is not None:
#print "colxf[m]",type(colxf[m])
#print 'AAAAA', colxf[m]
glMaterialWithCheck( face, viewerConst.propConst[m],
colxf[m], check=self.checkMat )
if colxf[1] is not None:
GL.glColor4fv(colxf[1])
if colxb and face!=GL.GL_FRONT_AND_BACK:
for m in (0,1,2,3,4):
if colxb[m] is not None:
glMaterialWithCheck( GL.GL_BACK,
viewerConst.propConst[m],
colxb[m], check=self.checkMat )
vx = self.v[i][0]
GL.glVertex3f(float(vx[0]*radx), float(vx[1]*radx), float(vx[2]*sz))
if colyf:
for m in (0,1,2,3,4):
if colyf[m] is not None:
#print 'BBBBB', colyf[m]
glMaterialWithCheck( face, viewerConst.propConst[m],
colyf[m], check=self.checkMat )
if colyf[1] is not None:
GL.glColor4fv(colyf[1])
if colyb and face!=GL.GL_FRONT_AND_BACK:
for m in (0,1,2,3,4):
if colyb[m] is not None:
glMaterialWithCheck( GL.GL_BACK,
viewerConst.propConst[m],
colyb[m], check=self.checkMat )
vy = self.v[i][1]
GL.glVertex3f(float(vy[0]*rady), float(vy[1]*rady), float(vy[2]*sz))
GL.glEnd()
GL.glPopMatrix()
示例10: cyldrawWithSharpColorBoundaries
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def cyldrawWithSharpColorBoundaries(self,
x, y, radx, rady,
colxf=None, colxb=None,
colyf=None, colyb=None, face=None,
highlightX=0, highlightY=0):
# determine scale and rotation of template
import math
sz=0.0
for i in (0,1,2):
sz=sz+(x[i]-y[i])*(x[i]-y[i])
if sz <= 0.0: return
sz = math.sqrt(sz)
sz2 = sz * .5
valueCos = (y[2]-x[2])/sz
valueCos = min(valueCos, 1)
valueCos = max(valueCos, -1)
rx = -180.0*math.acos(valueCos)/math.pi
dx = y[0]-x[0]
dy = y[1]-x[1]
if math.fabs(dx) < 0.00001 and math.fabs(dy) < 0.00001:
rz = 0.0
else:
rz = -180.0*math.atan2(dx,dy)/math.pi
GL.glPushMatrix()
GL.glTranslatef(float(x[0]),float(x[1]),float(x[2]))
if rz<=180.0 and rz >=-180.0:
GL.glRotatef(float(rz), 0., 0., 1.)
GL.glRotatef(float(rx), 1., 0., 0.)
if colyf:
for m in (0,1,2,3,4):
if colyf[m] is not None:
glMaterialWithCheck( face, viewerConst.propConst[m],
colyf[m], check=self.checkMat)
if colyf[1] is not None:
GL.glColor4fv(colyf[1])
if colyb and face!=GL.GL_FRONT_AND_BACK:
for m in (0,1,2,3,4):
if colyb[m] is not None:
self.checkMat = 0
glMaterialWithCheck( GL.GL_BACK,
viewerConst.propConst[m],
colyb[m], check=self.checkMat)
# this tests (colxf==colyf)
self.checkMat = 1
idem = (highlightX == highlightY)
if idem is True:
if colxf is None:
if colyf is not None:
idem = False
else:
if colyf is None:
idem = False
else:
lencol = len(colxf)
if lencol != len(colyf):
idem = False
else:
for i in range(lencol):
if colxf[i] is not None:
if bool(numpy.alltrue(colxf[i] == colyf[i])) is False:
idem = False
break
if idem is True:
if colxb is None:
if colyb is not None:
idem = False
else:
if colyb is None:
idem = False
else:
lencol = len(colxb)
if lencol != len(colyb):
idem = False
else:
for i in range(lencol):
if colxb[i] is not None:
if bool(numpy.alltrue(colxb[i] == colyb[i])) is False:
idem = False
break
quality = self.quality * 5
if idem is True:
if highlightX != 0:
GL.glStencilFunc(GL.GL_ALWAYS, 1, 1)
solidCylinder(float(rady), float(radx), sz, quality, 1, self.invertNormals)
GL.glStencilFunc(GL.GL_ALWAYS, 0, 1)
else:
solidCylinder(float(rady), float(radx), sz, quality, 1, self.invertNormals)
else:
midRadius = (radx + rady) * .5
if highlightX != 0:
GL.glStencilFunc(GL.GL_ALWAYS, 1, 1)
solidCylinder(midRadius, float(radx), sz2, quality, 1, self.invertNormals)
GL.glStencilFunc(GL.GL_ALWAYS, 0, 1)
else:
#.........这里部分代码省略.........
示例11: DisplayFunction
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def DisplayFunction(self):
if __debug__:
if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
"""display a set of indexed geometric primitives"""
if self.dpyList:
# print "DisplayFunction", self.dpyList, self.fullName
lDrawOutline = (self.getDrawOutlineMode('front'), self.getDrawOutlineMode('back'))
if (lDrawOutline[0] or lDrawOutline[1]) and self.viewer.hasOffsetExt:
outl = self.outline
if self.GetPolyMode('front') == GL.GL_FILL \
or self.GetPolyMode('back') == GL.GL_FILL:
mode = GL.GL_POLYGON_OFFSET_FILL
GL.glEnable(mode)
self.viewer.polyOffset( outl.factor, outl.unit)
Geom.DisplayFunction(self)
GL.glDisable(mode)
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
if not outl.colorAsMaterial:
if outl.lighting:
GL.glMaterialfv( GL.GL_FRONT_AND_BACK,
GL.GL_EMISSION,
outl.color )
else:
GL.glDisable(GL.GL_LIGHTING)
GL.glColor4fv (outl.color)
GL.glLineWidth(outl.lineWidth)
if lDrawOutline[0] is False or lDrawOutline[1] is False:
GL.glEnable(GL.GL_CULL_FACE)
if lDrawOutline[0]:
GL.glCullFace(GL.GL_BACK)
elif lDrawOutline[1]:
GL.glCullFace(GL.GL_FRONT)
else:
GL.glDisable(GL.GL_CULL_FACE)
if outl.dpyList:
currentcontext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
if currentcontext != outl.dpyList[1]:
warnings.warn("""DisplayFunction failed because the current context is the wrong one""")
#print "currentcontext != outl.dpyList[1]", currentcontext, outl.dpyList[1]
else:
#print '#%d'%outl.dpyList[0], currentcontext, "glCallList IndexedGeom"
GL.glCallList(outl.dpyList[0])
GL.glEnable(GL.GL_CULL_FACE)
GL.glEnable(GL.GL_LIGHTING)
else:
Geom.DisplayFunction(self)
else:
Geom.DisplayFunction(self)
示例12: DisplayFunction
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def DisplayFunction(self):
"""Draw a square with diagonals to represent the clipping plane
"""
#print "ClippingPlane.DisplayFunction"
#trans = self.eqn[3]*(self.eqn[:3]*self.n)
resetMaterialMemory()
trans = self.translation
GL.glPushMatrix()
#GL.glTranslatef(-trans[0],-trans[1],-trans[2])
GL.glTranslatef(float(trans[0]),
float(trans[1]),
float(trans[2]))
GL.glMultMatrixf(self.rotation)
GL.glScalef(float(self.scale[0]),
float(self.scale[1]),
float(self.scale[2]))
if self.polyMode == GL.GL_QUADS:
GL.glPushAttrib(GL.GL_CURRENT_BIT | GL.GL_LIGHTING_BIT |
GL.GL_POLYGON_BIT)
GL.glDisable(GL.GL_LIGHTING)
GL.glMaterialWithCheck(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT,
self.color)
if self.viewer is not None:
self.viewer.enableOpenglLighting()
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
GL.glPushMatrix()
GL.glMultMatrixf(self.planeRot)
GL.glBegin (GL.GL_QUADS)
GL.glVertex3f (0.0, -5.0, -5.0)
GL.glVertex3f (0.0, -5.0, 5.0)
GL.glVertex3f (0.0, 5.0, 5.0)
GL.glVertex3f (0.0, 5.0, -5.0)
GL.glVertex3f (0.0, -5.0, -5.0)
GL.glEnd ()
GL.glPopMatrix()
GL.glPopAttrib()
else:
# MS disabling GL.GL_BLEND breaks display of transparent surfaces
## if self.antialiased==True:
## GL.glEnable(GL.GL_LINE_SMOOTH)
## GL.glEnable(GL.GL_BLEND)
## else:
## GL.glDisable(GL.GL_LINE_SMOOTH)
## GL.glDisable(GL.GL_BLEND)
GL.glColor4fv (self.color)
GL.glLineWidth(self.lineWidth)
GL.glPushMatrix()
GL.glMultMatrixf(self.planeRot)
# could and should be a display list made once for all planes
GL.glBegin (GL.GL_LINE_STRIP)
GL.glVertex3f (0.0, -5.0, -5.0)
GL.glVertex3f (0.0, -5.0, 5.0)
GL.glVertex3f (0.0, 5.0, 5.0)
GL.glVertex3f (0.0, 5.0, -5.0)
GL.glVertex3f (0.0, -5.0, -5.0)
GL.glVertex3f (0.0, 5.0, 5.0)
GL.glVertex3f (0.0, -5.0, 5.0)
GL.glVertex3f (0.0, 5.0, -5.0)
GL.glEnd ()
GL.glPopMatrix()
GL.glPopMatrix()
示例13: Draw
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def Draw(self):
OVERALL, PER_VERTEX, PER_PART, PER_FACE = -1, 10, 11, 12, 13
#NONE, OVERALL, PER_VERTEX, PER_PART, PER_FACE = -1, 10, 11, 12, 13
propConst = DejaVu.viewerConst.propConst
noCol = 1
vert = self.vertexSet.vertices.array
if len(vert)==0: return
if self.materials[GL.GL_FRONT] and not self.inheritMaterial:
mat = self.materials[GL.GL_FRONT]
frontMat = fpProp = []
frontMatBind = fpBind = []
for propInd in range(4):
b, p = mat.GetProperty(propInd)
fpProp.append(p)
fpBind.append(b)
fpProp.append(mat.prop[4])
fpBind.append(mat.binding[4])
# frontMat = self.materials[GL.GL_FRONT].prop
# frontMatBind = self.materials[GL.GL_FRONT].binding
else:
frontMat = None
frontMatBind = None
if self.materials[GL.GL_BACK] and not self.inheritMaterial:
mat = self.materials[GL.GL_BACK]
backMat = bpProp = []
backMatBind = bpBind = []
for propInd in range(4):
b, p = mat.GetProperty(propInd)
bpProp.append(p)
bpBind.append(b)
bpProp.append(mat.prop[4])
bpBind.append(mat.binding[4])
# backMat = self.materials[GL.GL_BACK].prop
# backMatBind = self.materials[GL.GL_BACK].binding
else:
backMat = None
backMatBind = None
## texCoords = None
## if hasattr(self.vertexSet, "texCoords"):
## if self.vertexSet.texCoords.status >= viewerConst.COMPUTED:
## texCoords = self.vertexSet.texCoords.array
if not self.frontAndBack is None:
face = GL.GL_FRONT
else:
face = GL.GL_FRONT_AND_BACK
if not self.normals: # overall color for no normals or lighting
if frontMat:
if frontMatBind[noCol] == OVERALL:
GL.glColor4fv( frontMat[noCol][0] )
else:
if len(self.normals)==1: # overall normal
n = self.normals
GL.glNormal3dv(n[0])
if frontMat:
for j in range(5): # overall materials
if frontMatBind[j] == OVERALL:
glMaterialWithCheck( face, propConst[j],
frontMat[j][0] )
if backMat and not self.frontAndBack:
for j in range(5):
if backMatBind[j] == OVERALL:
glMaterialWithCheck( GL.GL_BACK, propConst[j],
backMat[j][0] )
self.isNewColor()
#self.isNewMaterial(0,0,0)
n = self.normals
# loop over each strip
for stripNum in range(1,len(self.stripBegin)):
c = vert[self.stripBegin[stripNum-1]:self.stripBegin[stripNum]]
GL.glPushName(stripNum)
GL.glBegin(GL.GL_QUAD_STRIP)
# per part material properties
if frontMat:
if frontMatBind[noCol] == PER_PART:
if self.isNewColor(c=frontMat[noCol][stripNum-1]):
GL.glColor4fv(frontMat[noCol][stripNum-1])
if n:
if frontMat:
for j in range(5):
if frontMatBind[j]==PER_PART:
glMaterialWithCheck( face,
propConst[j],
frontMat[j][stripNum-1] )
if backMat and not self.frontAndBack:
for j in range(5):
if backMatBind[j] == PER_PART:
glMaterialWithCheck( GL.GL_BACK,
propConst[j],
#.........这里部分代码省略.........
示例14: Draw
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
def Draw(self):
if __debug__:
if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
"""Draw function of the geom
return status 0 or 1
If you want fast rendering, you need to set self.templateDSPL
using MakeTemplate.
"""
#print "Spheres.Draw", self.name
assert self.templateDSPL is not None
currentcontext = self.viewer.currentCamera.tk.call(
self.viewer.currentCamera._w, 'contexttag')
if currentcontext != self.templateDSPL[1]:
import traceback;traceback.print_stack()
warnings.warn("""draw failed because the current context is the wrong one""")
#print "currentcontext != self.templateDSPL[1]", currentcontext, self.templateDSPL[1]
return 0
centers = self.vertexSet.vertices.array
if len(centers) == 0:
return 0
# handle overall binding of material
if self.inheritMaterial:
fp = None
fpProp = None
bp = None
else:
mat = self.materials[GL.GL_FRONT]
fpProp = []
for propInd in range(4):
b, p = mat.GetProperty(propInd)
fpProp.append(p)
fpProp.append(mat.prop[4])
fp = self.materials[GL.GL_FRONT]
#colorFront = Numeric.array(self.materials[GL.GL_FRONT].prop[1], copy=1)
colorFront = Numeric.array(fpProp[1], copy=1)
if self.frontAndBack:
bp = None
face = GL.GL_FRONT_AND_BACK
else:
bp = self.materials[GL.GL_BACK]
face = GL.GL_FRONT
if fp:
for m in (0,1,2,3,4):
if fp.binding[m] == viewerConst.OVERALL:
glMaterialWithCheck( face,
viewerConst.propConst[m],
fpProp[m][0])
if fp.binding[1] == viewerConst.OVERALL:
GL.glColor4fv(colorFront[0])
if fp:
for m in (0,1,2,3,4):
if fp.binding[m] != viewerConst.OVERALL:
glMaterialWithCheck( face,
viewerConst.propConst[m],
fpProp[m][0])
if fp.binding[1] != viewerConst.OVERALL:
GL.glColor4fv(colorFront[0])
if bp:
for m in (0,1,2,3,4):
if bp.binding[m] != viewerConst.OVERALL:
glMaterialWithCheck( GL.GL_BACK,
viewerConst.propConst[m],
bp.prop[m][0])
#print self.name
#if fp: print fp.prop[1], fp.binding
#else: print
if self.fastSpheres:
#print "self.fastSpheres", self.fastSpheres
if self.oneRadius == viewerConst.NO:
radii = self.vertexSet.radii.array
#FIXME: quick fix because can be called from base class Set
# method after centers have been set BUT before radii have been
# set
if len(self.vertexSet.vertices) != len(radii):
return 0
else:
radii = Numeric.ones( centers.shape[0] ) * self.radius
radii.shape = (-1,1)
coords = Numeric.concatenate ( (centers, radii), 1 )
## if not self.inheritMaterial:
## mat = self.materials[GL.GL_FRONT]
## fpProp = []
## for propInd in range(4):
## b, p = mat.GetProperty(propInd)
## fpProp.append(p)
## fpProp.append(mat.prop[4])
## #fpProp = self.materials[GL.GL_FRONT].prop[:5]
## else:
#.........这里部分代码省略.........
示例15: drawLegendOnly
# 需要导入模块: from opengltk.OpenGL import GL [as 别名]
# 或者: from opengltk.OpenGL.GL import glColor4fv [as 别名]
#.........这里部分代码省略.........
c=c1
GL.glColor3fv(c)
GL.glBegin(GL.GL_QUADS)
if verticalLegend is True:
GL.glVertex2f(float(lRoomToLegendCloseLongSide+lCheckerSquareSize),
float(lRoomToLegendCloseShortSide + x1))
GL.glVertex2f(float(lRoomToLegendFarLongSide),
float(lRoomToLegendCloseShortSide + x1))
GL.glVertex2f(float(lRoomToLegendFarLongSide),
float(lRoomToLegendCloseShortSide + x2))
GL.glVertex2f(float(lRoomToLegendCloseLongSide+lCheckerSquareSize),
float(lRoomToLegendCloseShortSide + x2))
else:
GL.glVertex2f(float(lRoomToLegendCloseShortSide + x2),
float(lRoomToLegendCloseLongSide+lCheckerSquareSize))
GL.glVertex2f(float(lRoomToLegendCloseShortSide + x2),
float(lRoomToLegendFarLongSide))
GL.glVertex2f(float(lRoomToLegendCloseShortSide + x1),
float(lRoomToLegendFarLongSide))
GL.glVertex2f(float(lRoomToLegendCloseShortSide + x1),
float(lRoomToLegendCloseLongSide+lCheckerSquareSize))
GL.glEnd()
#interp = False
if interpolate and (len(ramp) > 1): # we interpolate colors
# draw a quad strip for the color map
lDelta = legendLongSide/float(len(ramp)-1)
GL.glBegin(GL.GL_QUAD_STRIP)
for i in range(len(ramp)):
if selected is True:
c = deepcopy(ramp[i])
for j in range(3):
c[j] = .35 + c[j]*.3
else:
c = ramp[i]
if len(c)==3:
GL.glColor3fv(c)
elif len(c)==4:
GL.glColor4fv(c)
lStep = i*lDelta
if verticalLegend is True:
GL.glVertex2f(float(lRoomToLegendCloseLongSide),
float(lRoomToLegendCloseShortSide + lStep))
GL.glVertex2f(float(lRoomToLegendFarLongSide),
float(lRoomToLegendCloseShortSide + lStep))
else:
GL.glVertex2f(float(lRoomToLegendCloseShortSide + lStep),
float(lRoomToLegendFarLongSide))
GL.glVertex2f(float(lRoomToLegendCloseShortSide + lStep),
float(lRoomToLegendCloseLongSide))
GL.glEnd()
else:
# we draw a quad for each color
lDelta = legendLongSide/float(len(ramp))
for i in range(len(ramp)):
if selected is True:
c = deepcopy(ramp[i])
for j in range(3):
c[j] = .35 + c[j]*.3
else:
c = ramp[i]
if len(c)==3:
GL.glColor3fv(c)
elif len(c)==4:
GL.glColor4fv(c)
x1 = i*lDelta
x2 = x1+lDelta
GL.glBegin(GL.GL_QUADS)
if verticalLegend is True:
GL.glVertex2f(float(lRoomToLegendCloseLongSide),
float(lRoomToLegendCloseShortSide + x1))
GL.glVertex2f(float(lRoomToLegendFarLongSide),
float(lRoomToLegendCloseShortSide + x1))
GL.glVertex2f(float(lRoomToLegendFarLongSide),
float(lRoomToLegendCloseShortSide + x2))
GL.glVertex2f(float(lRoomToLegendCloseLongSide),
float(lRoomToLegendCloseShortSide + x2))
else:
GL.glVertex2f(float(lRoomToLegendCloseShortSide + x2),
float(lRoomToLegendCloseLongSide))
GL.glVertex2f(float(lRoomToLegendCloseShortSide + x2),
float(lRoomToLegendFarLongSide))
GL.glVertex2f(float(lRoomToLegendCloseShortSide + x1),
float(lRoomToLegendFarLongSide))
GL.glVertex2f(float(lRoomToLegendCloseShortSide + x1),
float(lRoomToLegendCloseLongSide))
GL.glEnd()
if len(ramp[0])==4:
GL.glDisable(GL.GL_BLEND)
GL.glEnable(GL.GL_DEPTH_TEST)
GL.glDepthMask(GL.GL_TRUE)
# GL.glEnable(GL.GL_LIGHTING)
GL.glPopMatrix()
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glPopMatrix()
GL.glMatrixMode(GL.GL_MODELVIEW)