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)
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()
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()
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])
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
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())
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() )
def DrawDirectionalLight(self, camera): """Draw a directional light as a line""" # if self.antialiased is 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.diffuse) GL.glLineWidth(self.lineWidth) GL.glBegin (GL.GL_LINES) GL.glVertex3f ( float(camera.lookAt[0]),float(camera.lookAt[1]),float(camera.lookAt[2]) ) v = camera.lookAt + self.direction[:3] nv = sqrt(Numeric.add.reduce(v*v)) v = (v/nv)*self.length GL.glVertex3f ( float(v[0]), float(v[1]), float(v[2]) ) GL.glEnd() GL.glPushMatrix() GL.glTranslatef(float(v[0]),float(v[1]),float(v[2])) GL.glPushAttrib(GL.GL_ALPHA_TEST); # GL.glDisable(GL.GL_LIGHTING); GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); pObj = GLU.gluNewQuadric() GLU.gluQuadricDrawStyle(pObj, GLU.GLU_FILL) GLU.gluQuadricNormals(pObj, GLU.GLU_SMOOTH) GL.glColor4ub(255,255,255,10); GLU.gluDisk(pObj, 0.0, 0.5, 20, 20); for light_color in range(100): GL.glColor4ub(255-light_color,255-light_color,255-light_color,10) GLU.gluCylinder(pObj, 0.5 - 2.*light_color/255.,0.5 - 2.*(light_color+1)/255. , light_color/255., 20, 20) GL.glTranslatef(0.0, 0.0, float(light_color)/255.); #GL.glColor4ub(255,255,255,200) #GLU.gluDisk(pObj, 0,0.5 - 2.*(light_color+1)/255. , 20, 20) GL.glPopAttrib() GL.glPopMatrix()
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
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: ## fpProp = None #print 'FUGU OVERWRITE COLOR', fpProp #import numpy #GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, numpy.array((.6,.6,.6,1), 'f')) #GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, numpy.array((1.,1.,1.,1), 'f')) #GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, numpy.array((.4,.4,.4,1), 'f')) #GL.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, numpy.array((0,0,0,1), 'f')) #GL.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 1.) status = glDrawSphereSet( self.templateDSPL[0], coords.astype('f'), fpProp, #self.materials[GL.GL_FRONT].prop, highlight=self.highlight, ) #print "Spheres, status: ", status return status else: resetMaterialMemory() #print "SLOW Spheres" if self.oneRadius == viewerConst.NO: radii = self.vertexSet.radii.array else: radii = Numeric.ones(centers.shape[0]) * self.radius if len(self.vertexSet.vertices) != len(radii): return 0 for i in xrange(centers.shape[0]): GL.glPushName(i) GL.glPushMatrix() GL.glTranslatef(float(centers[i][0]), float(centers[i][1]), float(centers[i][2])) if not self.oneRadius: GL.glScalef(float(radii[i]), float(radii[i]), float(radii[i])) else: GL.glScalef(float(self.radius), float(self.radius), float(self.radius)) #print '#%d'%self.templateDSPL[0], "glCallList Spheres0" if fp: for m in (0, 1, 2, 3, 4): if fp.binding[m] != viewerConst.OVERALL: glMaterialWithCheck(face, viewerConst.propConst[m], fp.prop[m][0], geom=self) GL.glCallList(self.templateDSPL[0]) GL.glPopMatrix() GL.glPopName() return 1
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]) # loop over each vertex in a strip i = 0 for ind in range(sB[stripNum], sE[stripNum]): if ind >= len(vert): print 'ERROR', ind v = vert[ind] # normals for flat or smooth shading if n is not None: if self.shading == GL.GL_FLAT: if i > 1: GL.glNormal3dv(n[sB[stripNum] + i - (2 * (stripNum + 1))]) elif self.shading == GL.GL_SMOOTH: GL.glNormal3fv(n[ind]) else: pass # per face (per triangle) material properties if n is None: if frontMat: if frontMatBind[noCol] == PER_FACE: if i > 1: if self.isNewColor( c=frontMat[noCol][sB[stripNum] + i - (2 * (stripNum + 1))]): GL.glColor4fv( frontMat[noCol][sB[stripNum] + i - (2 * (stripNum + 1))]) else: if frontMat: for k in range(5): if frontMatBind[k] == PER_FACE: if i > 1: glMaterialWithCheck( face, propConst[k], frontMat[k][sB[stripNum] + i - (2 * (stripNum + 1))]) if backMat and not self.frontAndBack: for k in range(5): if backMatBind[k] == PER_FACE: if i > 1 and i % 2 == 0: glMaterialWithCheck( GL.GL_BACK, propConst[k], backMat[k][sB[stripNum] + i - (2 * (stripNum + 1))]) # per vertex material properties if n is None: if frontMat: if frontMatBind[noCol] == PER_VERTEX: if self.isNewColor(c=frontMat[noCol][sB[stripNum] + i]): GL.glColor4fv(frontMat[noCol][sB[stripNum] + i]) else: if frontMat: for k in range(5): if frontMatBind[k] == PER_VERTEX: glMaterialWithCheck( face, propConst[k], frontMat[k][sB[stripNum] + i]) if backMat and not self.frontAndBack: for k in range(5): if backMatBind[k] == PER_VERTEX: glMaterialWithCheck( GL.GL_BACK, propConst[k], backMat[k][sB[stripNum] + i]) # draw vertex #GL.glVertex3dv(v) gllib.glVertex3fv(v) i = i + 1 GL.glEnd() GL.glPopName() return 1
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], backMat[j][stripNum-1] ) # loop over each vertex in a strip i = 0 for v in c: if n: if self.shading==GL.GL_FLAT: if i > 1 and i%2==0: GL.glNormal3dv(n[(self.stripBegin[stripNum-1]+i-(2*stripNum))/2]) elif self.shading==GL.GL_SMOOTH: GL.glNormal3dv(n[self.stripBegin[stripNum-1]+i]) else: pass # per face (per triangle) material properties if not n: if frontMat: if frontMatBind[noCol] == PER_FACE: if i > 1 and i%2==0: if self.isNewColor(c=frontMat[noCol][(self.stripBegin[stripNum-1]+i-(2*stripNum))/2]): GL.glColor4fv(frontMat[noCol][(self.stripBegin[stripNum-1]+i-(2*stripNum))/2]) else: if frontMat: for k in range(5): if frontMatBind[k] == PER_FACE: if i > 1 and i%2==0: glMaterialWithCheck( face, propConst[k], frontMat[k][(self.stripBegin[stripNum-1]+i-(2*stripNum))/2] ) if backMat and not self.frontAndBack: for k in range(5): if backMatBind[k] == PER_FACE: if i > 1 and i%2==0: glMaterialWithCheck( GL.GL_BACK, propConst[k], backMat[k][(self.stripBegin[stripNum-1]+i-(2*stripNum))/2] ) # per vertex material properties if not n: if frontMat: if frontMatBind[noCol] == PER_VERTEX: if self.isNewColor(c=frontMat[noCol][self.stripBegin[stripNum-1]+i]): GL.glColor4fv(frontMat[noCol][self.stripBegin[stripNum-1]+i]) else: if frontMat: for k in range(5): if frontMatBind[k] == PER_VERTEX: glMaterialWithCheck( face, propConst[k], frontMat[k][self.stripBegin[stripNum-1]+i] ) if backMat and not self.frontAndBack: for k in range(5): if backMatBind[k] == PER_VERTEX: glMaterialWithCheck( GL.GL_BACK, propConst[k], backMat[k][self.stripBegin[stripNum-1]+i] ) # draw vertex GL.glVertex3dv(v) i = i + 1 GL.glEnd() GL.glPopName() return 1
def drawLegendOnly( fullWidth, fullHeight, ramp, verticalLegend=True, roomLeftToLegend=0, roomBelowLegend=50, legendShortSide=10, legendLongSide=150, interpolate=True, selected=False, tile=None, ): if ramp is None or len(ramp) == 0: return if tile is not None and selected is True: selected = False # deducted values if verticalLegend is True: lRoomToLegendCloseLongSide = roomLeftToLegend lRoomToLegendCloseShortSide = roomBelowLegend if legendShortSide < 1: legendShortSide = 1 if legendLongSide < 1: legendLongSide = 1 else: lRoomToLegendCloseLongSide = roomBelowLegend lRoomToLegendCloseShortSide = roomLeftToLegend if legendShortSide < 1: legendShortSide = 1 if legendLongSide < 1: legendLongSide = 1 lRoomToLegendFarLongSide = lRoomToLegendCloseLongSide + legendShortSide 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) GL.glDisable(GL.GL_DEPTH_TEST) GL.glDepthMask(GL.GL_FALSE) if len(ramp[0]) == 4: # there are alpha values, draw checkered bg GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) #draw a bunch of quads as background lCheckerSquareSize = legendShortSide * .5 if lCheckerSquareSize != 0: nbquads = int(legendLongSide / lCheckerSquareSize) else: nbquads = 1 c1 = (0.1, 0.1, 0.1) c2 = (0.3, 0.3, 0.3) c = c1 x2 = None for i in range(nbquads + 1): GL.glColor3fv(c) if i == nbquads and nbquads != 0: x1 = x2 x2 = legendLongSide else: x1 = i * lCheckerSquareSize x2 = min(x1 + lCheckerSquareSize, legendLongSide) GL.glBegin(GL.GL_QUADS) if verticalLegend is True: GL.glVertex2f(float(lRoomToLegendCloseLongSide), float(lRoomToLegendCloseShortSide + x1)) GL.glVertex2f( float(lRoomToLegendCloseLongSide + lCheckerSquareSize), float(lRoomToLegendCloseShortSide + x1)) GL.glVertex2f( float(lRoomToLegendCloseLongSide + lCheckerSquareSize), float(lRoomToLegendCloseShortSide + x2)) GL.glVertex2f(float(lRoomToLegendCloseLongSide), float(lRoomToLegendCloseShortSide + x2)) else: GL.glVertex2f(float(lRoomToLegendCloseShortSide + x2), float(lRoomToLegendCloseLongSide)) GL.glVertex2f( float(lRoomToLegendCloseShortSide + x2), float(lRoomToLegendCloseLongSide + lCheckerSquareSize)) GL.glVertex2f( float(lRoomToLegendCloseShortSide + x1), float(lRoomToLegendCloseLongSide + lCheckerSquareSize)) GL.glVertex2f(float(lRoomToLegendCloseShortSide + x1), float(lRoomToLegendCloseLongSide)) GL.glEnd() if c == c1: c = c2 else: 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)
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
def drawLegendLabelName( fullWidth, fullHeight, ramp, mini, maxi, name='', unit='', labelValues=[], verticalLegend=True, leftOrBelowLabels=False, roomLeftToLegend=0, roomBelowLegend=50, legendShortSide=10, legendLongSide=150, significantDigits=3, backgroundColor=(0,0,0,.8), labelColor=(1,1,1), interpolate=True, frame=True, selected=False, numOfLabels=None, resizeSpotRadius=5, fontScale=8, glfFontID=0, tile=None, ): if ramp is None or len(ramp) == 0: return if tile is not None and selected is True: selected = False # some glf font initialisation glf.glfSetCurrentFont(glfFontID) glf.glfStringCentering(GL.GL_FALSE) glf.glfStringDirection(glf.GLF_LEFT) # calculate name and unit size lNameMinAndMax = glf.glfGetStringBounds(name) lNameMinAndMax = ( lNameMinAndMax[0]*fontScale, lNameMinAndMax[1]*fontScale, lNameMinAndMax[2]*fontScale, lNameMinAndMax[3]*fontScale ) lNameWidth = lNameMinAndMax[2]-lNameMinAndMax[0] lNameHeight = lNameMinAndMax[3]-lNameMinAndMax[1] if lNameWidth == 0: lNameWidth = fontScale if unit is not None and (len(unit) > 0): lUnitMinAndMax = glf.glfGetStringBounds(unit) lUnitMinAndMax = ( lUnitMinAndMax[0]*fontScale, lUnitMinAndMax[1]*fontScale, lUnitMinAndMax[2]*fontScale, lUnitMinAndMax[3]*fontScale ) lUnitWidth = lUnitMinAndMax[2]-lUnitMinAndMax[0] lUnitHeight = lUnitMinAndMax[3]-lUnitMinAndMax[1] else: lUnitWidth = fontScale lUnitHeight = 0 lMaxNameUnitHeight = max(lNameHeight, lUnitHeight) lMaxNameUnitWidth = max(lNameWidth, lUnitWidth) # deducted values fontScaleHalf = fontScale/2 if verticalLegend is True: lRoomToLegendCloseLongSide = roomLeftToLegend lRoomToLegendCloseShortSide = roomBelowLegend if legendShortSide < 1: legendShortSide = 1 if legendLongSide < 1: legendLongSide = 1 else: lRoomToLegendCloseLongSide = roomBelowLegend lRoomToLegendCloseShortSide = roomLeftToLegend if legendShortSide < lMaxNameUnitHeight + fontScaleHalf: legendShortSide = lMaxNameUnitHeight + fontScaleHalf if legendLongSide < 1: legendLongSide = 1 lRoomToLegendFarLongSide = lRoomToLegendCloseLongSide + legendShortSide lRoomToLegendFarShortSide = lRoomToLegendCloseShortSide + legendLongSide # prepare the legend labels if len(labelValues) > 0: lOnScreenLabelValues = labelValues else: if numOfLabels == None or numOfLabels < 0: if verticalLegend is True: numOfLabels = 6 else: numOfLabels = 4 if ( numOfLabels == 0 ) or maxi is None or mini is None: lOnScreenLabelValues = [] elif numOfLabels == 1: lOnScreenLabelValues = [(mini+maxi)*0.5] else: delta = (maxi - mini) / float(numOfLabels-1) lOnScreenLabelValues = [] for i in range(numOfLabels): lOnScreenLabelValues.append(mini+i*delta) lMaxLabelDigits = 0 for v in lOnScreenLabelValues: lLabel = "%.*g" % (significantDigits,v) if lMaxLabelDigits < len(lLabel): lMaxLabelDigits = len(lLabel) # calculate labels size lLabelsMinAndMax = [] lLabelsWidth = [] lLabelsHeight = [] lMaxLabelsWidth = 0 lMaxLabelsHeight = 0 for v in lOnScreenLabelValues: lLabel = "%.*g" % (significantDigits,v) lLabelsMinAndMax.append( glf.glfGetStringBounds(lLabel) ) lLabelsMinAndMax[-1] = ( lLabelsMinAndMax[-1][0]*fontScale, lLabelsMinAndMax[-1][1]*fontScale, lLabelsMinAndMax[-1][2]*fontScale, lLabelsMinAndMax[-1][3]*fontScale ) lLabelsWidth.append( lLabelsMinAndMax[-1][2]-lLabelsMinAndMax[-1][0] ) lLabelsHeight.append( lLabelsMinAndMax[-1][3]-lLabelsMinAndMax[-1][1] ) if lLabelsWidth[-1] > lMaxLabelsWidth: lMaxLabelsWidth = lLabelsWidth[-1] if lLabelsHeight[-1] > lMaxLabelsHeight: lMaxLabelsHeight = lLabelsHeight[-1] # calculate frame size lMaxWidth = max(lMaxLabelsWidth + legendShortSide, lMaxNameUnitWidth) lMaxNameUnitHeightHalf = lMaxNameUnitHeight/2 legendShortSideHalf = legendShortSide/2 if verticalLegend is True: if leftOrBelowLabels is False: lPt1 = (lRoomToLegendCloseLongSide, -fontScale+lRoomToLegendCloseShortSide-lMaxLabelsHeight-lNameHeight,0) lPt2 = (fontScale+lRoomToLegendCloseLongSide+lMaxWidth, -fontScale+lRoomToLegendCloseShortSide-lMaxLabelsHeight-lNameHeight,0) lPt3 = (fontScale+lRoomToLegendCloseLongSide+lMaxWidth, fontScale+lRoomToLegendFarShortSide+lMaxLabelsHeight+lUnitHeight,0) lPt4 = (lRoomToLegendCloseLongSide, fontScale+lRoomToLegendFarShortSide+lMaxLabelsHeight+lUnitHeight,0) else: lPt1 = (-fontScale+lRoomToLegendFarLongSide-lMaxWidth, -fontScale+lRoomToLegendCloseShortSide-lMaxLabelsHeight-lNameHeight,0) lPt2 = (lRoomToLegendCloseLongSide+legendShortSide, -fontScale+lRoomToLegendCloseShortSide-lMaxLabelsHeight-lNameHeight,0) lPt3 = (lRoomToLegendCloseLongSide+legendShortSide, fontScale+lRoomToLegendFarShortSide+lMaxLabelsHeight+lUnitHeight,0) lPt4 = (-fontScale+lRoomToLegendFarLongSide-lMaxWidth, fontScale+lRoomToLegendFarShortSide+lMaxLabelsHeight+lUnitHeight,0) else: if leftOrBelowLabels is False: lPt1 = (-fontScale+lRoomToLegendCloseShortSide-lNameWidth, lRoomToLegendCloseLongSide,0) lPt2 = (fontScale+lRoomToLegendFarShortSide+lUnitWidth, lRoomToLegendCloseLongSide,0) lPt3 = (fontScale+lRoomToLegendFarShortSide+lUnitWidth, fontScale+lRoomToLegendCloseLongSide \ + legendShortSide \ + lMaxLabelsHeight, 0) lPt4 = (-fontScale+lRoomToLegendCloseShortSide-lNameWidth, fontScale+lRoomToLegendCloseLongSide \ + legendShortSide \ + lMaxLabelsHeight, 0) else: lPt1 = (-fontScale+lRoomToLegendCloseShortSide-lNameWidth, -fontScale+lRoomToLegendCloseLongSide-lMaxLabelsHeight, 0) lPt2 = (fontScale+lRoomToLegendFarShortSide+lUnitWidth, -fontScale+lRoomToLegendCloseLongSide-lMaxLabelsHeight, 0) lPt3 = (fontScale+lRoomToLegendFarShortSide+lUnitWidth, lRoomToLegendFarLongSide,0) lPt4 = (-fontScale+lRoomToLegendCloseShortSide-lNameWidth, lRoomToLegendFarLongSide,0) 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 lRoomLeftToUnit = -fontScaleHalf + lRoomToLegendFarLongSide - lUnitWidth lRoomBelowName = -fontScaleHalf + roomBelowLegend - lMaxLabelsHeight - lNameHeight lRoomBelowUnit = fontScaleHalf + roomBelowLegend + legendLongSide + lMaxLabelsHeight else: lRoomLeftToLabel = fontScaleHalf + lRoomToLegendFarLongSide lRoomLeftToName = fontScaleHalf + lRoomToLegendCloseLongSide lRoomLeftToUnit = lRoomLeftToName lRoomBelowName = -fontScaleHalf + roomBelowLegend - lMaxLabelsHeight - lNameHeight lRoomBelowUnit = fontScaleHalf + roomBelowLegend + legendLongSide + lMaxLabelsHeight else: if leftOrBelowLabels is True: lRoomBelowLabel = -fontScaleHalf + lRoomToLegendFarLongSide \ - legendShortSide - lMaxLabelsHeight lRoomBelowName = lRoomToLegendCloseLongSide + legendShortSideHalf \ - lMaxNameUnitHeightHalf else: lRoomBelowLabel = fontScaleHalf + lRoomToLegendCloseLongSide \ + legendShortSide lRoomBelowName = lRoomToLegendCloseLongSide + legendShortSideHalf \ - lMaxNameUnitHeightHalf lRoomBelowUnit = lRoomBelowName lRoomLeftToName = -fontScaleHalf + lRoomToLegendCloseShortSide - lNameWidth lRoomLeftToUnit = fontScaleHalf + lRoomToLegendFarShortSide # set the color of the text GL.glColor3fv(labelColor2) # print the legend name GL.glPushMatrix() GL.glTranslatef( float(lRoomLeftToName+fontScale), float(lRoomBelowName-lNameMinAndMax[1]), 0) GL.glScalef(float(fontScale), float(fontScale), 0); glf.glfDrawSolidString(name) GL.glPopMatrix() if unit is not None and (len(unit) > 0): GL.glPushMatrix() GL.glTranslatef( float(lRoomLeftToUnit+fontScale), float(lRoomBelowUnit-lUnitMinAndMax[1]), 0) GL.glScalef(float(fontScale), float(fontScale), 1); glf.glfDrawSolidString(unit) GL.glPopMatrix() if mini is not None and maxi is not None: i = 0 for v in lOnScreenLabelValues: #calculate label position lLabel = "%.*g" % (significantDigits,v) lStep = (v - mini) * lUnitStep GL.glPushMatrix() if verticalLegend: if leftOrBelowLabels: GL.glTranslatef( float(lRoomLeftToLabel+fontScale-lLabelsWidth[i]), float(roomBelowLegend-(lLabelsHeight[i]/2+lLabelsMinAndMax[i][1])+lStep), 0) else: GL.glTranslatef( float(lRoomLeftToLabel+fontScale), float(roomBelowLegend-(lLabelsHeight[i]/2+lLabelsMinAndMax[i][1])+lStep), 0) else: GL.glTranslatef( float(roomLeftToLegend-(lLabelsWidth[i]/2)+fontScale+lStep), float(lRoomBelowLabel-lLabelsMinAndMax[i][1]), 0) GL.glScalef(float(fontScale), float(fontScale), 1); glf.glfDrawSolidString("%s" % lLabel) GL.glPopMatrix() i += 1 if len(backgroundColor) == 4: GL.glDisable(GL.GL_BLEND) # GL.glEnable(GL.GL_LIGHTING) GL.glPopMatrix() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() GL.glMatrixMode(GL.GL_MODELVIEW) drawLegendOnly( fullWidth=fullWidth, fullHeight=fullHeight, ramp=ramp, verticalLegend=verticalLegend, roomLeftToLegend=roomLeftToLegend, roomBelowLegend=roomBelowLegend, legendShortSide=legendShortSide, legendLongSide=legendLongSide, interpolate=interpolate, selected=selected, tile=tile, ) if selected is True: GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glLoadIdentity() GL.glOrtho(0, float(fullWidth), 0, float(fullHeight), -1, 1) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glLoadIdentity() GL.glDisable( GL.GL_LIGHTING ) GL.glPolygonMode(GL.GL_FRONT, GL.GL_FILL ) GL.glDisable(GL.GL_DEPTH_TEST) GL.glDepthMask(GL.GL_FALSE) GL.glDisable(GL.GL_LIGHTING) resizeSpot = [] if verticalLegend: resizeSpot= [ roomLeftToLegend + legendShortSide, roomBelowLegend + legendLongSide ] else: resizeSpot = [ roomLeftToLegend + legendLongSide, roomBelowLegend + legendShortSide ] GL.glColor3fv(labelColor) GL.glBegin(GL.GL_QUADS) GL.glVertex2f(float(resizeSpot[0]+resizeSpotRadius),float(resizeSpot[1]-resizeSpotRadius)) GL.glVertex2f(float(resizeSpot[0]+resizeSpotRadius),float(resizeSpot[1]+resizeSpotRadius)) GL.glVertex2f(float(resizeSpot[0]-resizeSpotRadius),float(resizeSpot[1]+resizeSpotRadius)) GL.glVertex2f(float(resizeSpot[0]-resizeSpotRadius),float(resizeSpot[1]-resizeSpotRadius)) GL.glEnd() 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) else: resizeSpot = None return [(lPt1[0], lPt1[1]), (lPt2[0], lPt2[1]), (lPt3[0], lPt3[1]), (lPt4[0], lPt4[1]) ] , resizeSpot , verticalLegend
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()
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: solidCylinder(midRadius, float(radx), sz2, quality, 1, self.invertNormals) GL.glTranslatef(0, 0, float(sz2)) if colxf: for m in (0,1,2,3,4): if colxf[m] is not None: 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 ) if highlightY != 0: GL.glStencilFunc(GL.GL_ALWAYS, 1, 1) solidCylinder(float(rady), midRadius, sz2, quality, 1, self.invertNormals) GL.glStencilFunc(GL.GL_ALWAYS, 0, 1) else: solidCylinder(float(rady), midRadius, sz2, quality, 1, self.invertNormals) GL.glPopMatrix()
def Draw(self): #print "Cylinders.Draw" #import traceback;traceback.print_stack() # for some reason if I do not set this always on MacOSX only the first # cylinder gets the right color if sys.platform=='darwin' \ or DejaVu.preventIntelBug_BlackTriangles is True: self.checkMat = False else: self.checkMat = True if len(self.vertexSet.vertices)==0 or len(self.faceSet.faces)==0: return if self.inheritMaterial: fp = None bp = None face = None else: mat = self.materials[GL.GL_FRONT] rmat = self.realFMat bind = [10,10,10,10] for pInd in range(4): bind[pInd], rmat.prop[pInd] = mat.GetProperty(pInd) if rmat.binding[pInd] == viewerConst.OVERALL: glMaterialWithCheck( GL.GL_FRONT, viewerConst.propConst[pInd], rmat.prop[pInd][0]) if pInd==1: GL.glColor4fv(rmat.prop[pInd][0]) pInd = 4 # FIXME mat.GetProperty does not handle shininess if rmat.binding[pInd] == viewerConst.OVERALL: glMaterialWithCheck( GL.GL_FRONT, viewerConst.propConst[pInd], rmat.prop[pInd][0]) rmat.prop[4] = mat.prop[4] rmat.prop[5] = mat.prop[5] rmat.binding[:4] = bind rmat.binding[4:] = rmat.binding[4:] fp = rmat # fp = self.materials[GL.GL_FRONT] if fp: if self.frontAndBack: face = GL.GL_FRONT_AND_BACK bp = None else: face = GL.GL_FRONT mat = self.materials[GL.GL_BACK] rmat = self.realBMat bind = [10,10,10,10] for pInd in range(4): bind[pInd], rmat.prop[pInd]=mat.GetProperty(pInd) if rmat.binding[pInd] == viewerConst.OVERALL: glMaterialWithCheck( GL.GL_BACK, viewerConst.propConst[pInd], rmat.prop[pInd][0]) rmat.prop[4] = mat.prop[4] rmat.prop[5] = mat.prop[5] rmat.binding[:4] = bind rmat.binding[4:] = rmat.binding[4:] bp = rmat c = self.vertexSet.vertices.array if glDrawCylinderSet: radii = self.vertexSet.radii.array fmat = None fbind = None bmat = None bbind = None if fp: fmat = fp.prop[0:5] fbind = fp.binding[0:5] if bp: bmat = bp.prop[0:5] bbind = bp.binding[0:5] highlight = None if len(self.highlight) > 0: highlight = self.highlight if self.getSharpColorBoundaries() in [True, 1]: return glDrawCylinderSet(c, self.faceSet.faces.array, radii, fmat, bmat, fbind, bbind, self.frontAndBack, self.quality, self.invertNormals, highlight=highlight, sharpColorBoundaries=1) else: v1 = self.v[:,0,:].astype("f") v2 = self.v[:,1,:].astype("f") return glDrawCylinderSet(c, self.faceSet.faces.array, radii, fmat, bmat, fbind, bbind, self.frontAndBack, self.quality, self.invertNormals, sharpColorBoundaries=0, npoly = self.npoly, vertx = v1, verty=v2, norms = self.n) if self.getSharpColorBoundaries() in [True, 1]: self.cyldraw = self.cyldrawWithSharpColorBoundaries else: self.cyldraw = self.cyldrawWithInterpolatedColors if self.oneRadius == viewerConst.NO: radii = self.vertexSet.radii.array else: radius = self.vertexSet.radii.array[0] pickName = 0 for i in xrange(len(self.faceSet.faces.array)): #print 'CYLINDERS', i, '********************************', for j in xrange(len(self.faceSet.faces.array[i])-1): vi1 = self.faceSet.faces.array[i][j] vi2 = self.faceSet.faces.array[i][j+1] if fp: fpp1 = [None,None,None,None,None] fpp2 = [None,None,None,None,None] for m in (0,1,2,3,4): if fp.binding[m] == viewerConst.PER_VERTEX: fpp1[m] = fp.prop[m][vi2] fpp1[m] = array(fpp1[m],copy=1) fpp2[m] = fp.prop[m][vi1] fpp2[m] = array(fpp2[m],copy=1) elif fp.binding[m] == viewerConst.PER_PART: fpp2[m] = fpp1[m] = fp.prop[m][i] fpp1[m] = array(fpp1[m],copy=1) fpp2[m] = array(fpp2[m],copy=1) else: fpp1 = fpp2 = None if bp and not self.frontAndBack: bpp1 = [None,None,None,None,None] bpp2 = [None,None,None,None,None] for m in (0,1,2,3,4): if bp.binding[m] == viewerConst.PER_VERTEX: bpp1[m] = bp.prop[m][vi2] bpp1[m] = array(bpp1[m],copy=1) bpp2[m] = bp.prop[m][vi1] bpp2[m] = array(bpp2[m],copy=1) elif bp.binding[m] == viewerConst.PER_PART: bpp2[m] = bpp1[m] = bp.prop[m][i] bpp1[m] = array(bpp1[m],copy=1) bpp2[m] = array(bpp2[m],copy=1) else: bpp1 = bpp2 = None GL.glPushName(pickName) if len(self.highlight) > 0: if self.oneRadius: self.cyldraw(c[vi1], c[vi2], radius, radius, fpp1, bpp1, fpp2, bpp2, face, highlightX=self.highlight[vi1], highlightY=self.highlight[vi2]) else: if vi1 < vi2: self.cyldraw(c[vi1], c[vi2], radii[vi2], radii[vi1], fpp1, bpp1, fpp2, bpp2, face, highlightX=self.highlight[vi1], highlightY=self.highlight[vi2]) else: self.cyldraw(c[vi1], c[vi2], radii[vi1], radii[vi2], fpp1, bpp1, fpp2, bpp2, face, highlightX=self.highlight[vi1], highlightY=self.highlight[vi2]) else: if self.oneRadius: self.cyldraw(c[vi1], c[vi2], radius, radius, fpp1, bpp1, fpp2, bpp2, face) else: if vi1 < vi2: self.cyldraw(c[vi1], c[vi2], radii[vi2], radii[vi1], fpp1, bpp1, fpp2, bpp2, face) else: self.cyldraw(c[vi1], c[vi2], radii[vi1], radii[vi2], fpp1, bpp1, fpp2, bpp2, face) GL.glPopName() pickName = pickName +1 #print 'CYLINDERS done' return 1
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)
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()
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] ) # loop over each vertex in a strip i = 0 for ind in range(sB[stripNum],sE[stripNum]): if ind >= len(vert): print 'ERROR',ind v = vert[ind] # normals for flat or smooth shading if n is not None: if self.shading==GL.GL_FLAT: if i > 1: GL.glNormal3dv(n[sB[stripNum]+i-(2*(stripNum+1))]) elif self.shading==GL.GL_SMOOTH: GL.glNormal3fv(n[ind]) else: pass # per face (per triangle) material properties if n is None: if frontMat: if frontMatBind[noCol] == PER_FACE: if i > 1: if self.isNewColor(c=frontMat[noCol][sB[stripNum]+i-(2*(stripNum+1))]): GL.glColor4fv(frontMat[noCol][sB[stripNum]+i-(2*(stripNum+1))]) else: if frontMat: for k in range(5): if frontMatBind[k] == PER_FACE: if i > 1: glMaterialWithCheck( face, propConst[k], frontMat[k][sB[stripNum]+i-(2*(stripNum+1))] ) if backMat and not self.frontAndBack: for k in range(5): if backMatBind[k] == PER_FACE: if i > 1 and i%2==0: glMaterialWithCheck( GL.GL_BACK, propConst[k], backMat[k][sB[stripNum]+i-(2*(stripNum+1))] ) # per vertex material properties if n is None: if frontMat: if frontMatBind[noCol] == PER_VERTEX: if self.isNewColor(c=frontMat[noCol][sB[stripNum]+i]): GL.glColor4fv(frontMat[noCol][sB[stripNum]+i]) else: if frontMat: for k in range(5): if frontMatBind[k] == PER_VERTEX: glMaterialWithCheck( face, propConst[k], frontMat[k][sB[stripNum]+i] ) if backMat and not self.frontAndBack: for k in range(5): if backMatBind[k] == PER_VERTEX: glMaterialWithCheck( GL.GL_BACK, propConst[k], backMat[k][sB[stripNum]+i] ) # draw vertex #GL.glVertex3dv(v) gllib.glVertex3fv(v) i = i + 1 GL.glEnd() GL.glPopName() return 1
def Draw(self): for i in xrange(len(self.vertexSet)): if len(self.radii)==1: rad = self.radii[0] else: rad = self.radii[i] if len(self.angles)==1: ang = self.angles[0] else: ang = self.angles[i] vx, vy, vz = norm = self.vertexSet.normals.array[i] if self.vectors is None: # get orthogonal vector dx, dy, dz = fabs(vx), fabs(vy), fabs(vz) mini= min( [dx, dy, dz] ) if mini==dx: nov = 1./sqrt( vz*vz+ vy*vy ) ovx = 0. ovy = -vz*nov ovz = vy*nov elif mini==dy: nov = 1./sqrt( vz*vz+ vx*vx ) ovx = -vz*nov ovy = 0. ovz = vx*nov else: nov = 1./sqrt( vy*vy+ vx*vx ) ovx = -vy*nov ovy = vx*nov ovz = 0. vec = [ovx, ovy, ovz] elif len(self.vectors)==1: vec = self.vectors[0] else: vec = self.vectors[i] angRad = ang*pi*0.00555555555556 nsegments = int(ang/self.degreesPerSegment) + 1 d = angRad / nsegments # increment a = 0 # starting angle GL.glNormal3fv(norm.astype('f')) GL.glPushName(i) GL.glBegin(GL.GL_TRIANGLE_FAN) if self.materials[GL.GL_FRONT].binding[0]==viewerConst.PER_VERTEX: col = self.materials[GL.GL_FRONT].prop[0] GL.glColor4fv(col[i]) center = Numeric.array(self.vertexSet.vertices.array[i]) vec = Numeric.array(vec).astype('f') #vec = vec/sqrt(Numeric.sum(vec*vec)) vec2 = Numeric.zeros(3, 'f') vec2[0] = vec[1]*norm[2] - vec[2]*norm[1] vec2[1] = vec[2]*norm[0] - vec[0]*norm[2] vec2[2] = vec[0]*norm[1] - vec[1]*norm[0] GL.glVertex3fv(center) for j in range(nsegments+1): p = center + cos(a)*vec*rad + sin(a)*vec2*rad GL.glVertex3fv(p.astype('f')) a = a+d GL.glEnd() GL.glPopName() return 1
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], backMat[j][stripNum - 1]) # loop over each vertex in a strip i = 0 for v in c: if n: if self.shading == GL.GL_FLAT: if i > 1 and i % 2 == 0: GL.glNormal3dv( n[(self.stripBegin[stripNum - 1] + i - (2 * stripNum)) / 2]) elif self.shading == GL.GL_SMOOTH: GL.glNormal3dv(n[self.stripBegin[stripNum - 1] + i]) else: pass # per face (per triangle) material properties if not n: if frontMat: if frontMatBind[noCol] == PER_FACE: if i > 1 and i % 2 == 0: if self.isNewColor(c=frontMat[noCol][ (self.stripBegin[stripNum - 1] + i - (2 * stripNum)) / 2]): GL.glColor4fv(frontMat[noCol][ (self.stripBegin[stripNum - 1] + i - (2 * stripNum)) / 2]) else: if frontMat: for k in range(5): if frontMatBind[k] == PER_FACE: if i > 1 and i % 2 == 0: glMaterialWithCheck( face, propConst[k], frontMat[k] [(self.stripBegin[stripNum - 1] + i - (2 * stripNum)) / 2]) if backMat and not self.frontAndBack: for k in range(5): if backMatBind[k] == PER_FACE: if i > 1 and i % 2 == 0: glMaterialWithCheck( GL.GL_BACK, propConst[k], backMat[k] [(self.stripBegin[stripNum - 1] + i - (2 * stripNum)) / 2]) # per vertex material properties if not n: if frontMat: if frontMatBind[noCol] == PER_VERTEX: if self.isNewColor(c=frontMat[noCol][ self.stripBegin[stripNum - 1] + i]): GL.glColor4fv( frontMat[noCol][self.stripBegin[stripNum - 1] + i]) else: if frontMat: for k in range(5): if frontMatBind[k] == PER_VERTEX: glMaterialWithCheck( face, propConst[k], frontMat[k][self.stripBegin[stripNum - 1] + i]) if backMat and not self.frontAndBack: for k in range(5): if backMatBind[k] == PER_VERTEX: glMaterialWithCheck( GL.GL_BACK, propConst[k], backMat[k][self.stripBegin[stripNum - 1] + i]) # draw vertex GL.glVertex3dv(v) i = i + 1 GL.glEnd() GL.glPopName() return 1
def Draw(self): #print "Cylinders.Draw" #import traceback;traceback.print_stack() # for some reason if I do not set this always on MacOSX only the first # cylinder gets the right color if sys.platform=='darwin' \ or DejaVu.preventIntelBug_BlackTriangles is True: self.checkMat = False else: self.checkMat = True if len(self.vertexSet.vertices) == 0 or len(self.faceSet.faces) == 0: return if self.inheritMaterial: fp = None bp = None face = None else: mat = self.materials[GL.GL_FRONT] rmat = self.realFMat bind = [10, 10, 10, 10] for pInd in range(4): bind[pInd], rmat.prop[pInd] = mat.GetProperty(pInd) if rmat.binding[pInd] == viewerConst.OVERALL: glMaterialWithCheck(GL.GL_FRONT, viewerConst.propConst[pInd], rmat.prop[pInd][0]) if pInd == 1: GL.glColor4fv(rmat.prop[pInd][0]) pInd = 4 # FIXME mat.GetProperty does not handle shininess if rmat.binding[pInd] == viewerConst.OVERALL: glMaterialWithCheck(GL.GL_FRONT, viewerConst.propConst[pInd], rmat.prop[pInd][0]) rmat.prop[4] = mat.prop[4] rmat.prop[5] = mat.prop[5] rmat.binding[:4] = bind rmat.binding[4:] = rmat.binding[4:] fp = rmat # fp = self.materials[GL.GL_FRONT] if fp: if self.frontAndBack: face = GL.GL_FRONT_AND_BACK bp = None else: face = GL.GL_FRONT mat = self.materials[GL.GL_BACK] rmat = self.realBMat bind = [10, 10, 10, 10] for pInd in range(4): bind[pInd], rmat.prop[pInd] = mat.GetProperty(pInd) if rmat.binding[pInd] == viewerConst.OVERALL: glMaterialWithCheck(GL.GL_BACK, viewerConst.propConst[pInd], rmat.prop[pInd][0]) rmat.prop[4] = mat.prop[4] rmat.prop[5] = mat.prop[5] rmat.binding[:4] = bind rmat.binding[4:] = rmat.binding[4:] bp = rmat c = self.vertexSet.vertices.array if glDrawCylinderSet: radii = self.vertexSet.radii.array fmat = None fbind = None bmat = None bbind = None if fp: fmat = fp.prop[0:5] fbind = fp.binding[0:5] if bp: bmat = bp.prop[0:5] bbind = bp.binding[0:5] highlight = None if len(self.highlight) > 0: highlight = self.highlight if self.getSharpColorBoundaries() in [True, 1]: return glDrawCylinderSet(c, self.faceSet.faces.array, radii, fmat, bmat, fbind, bbind, self.frontAndBack, self.quality, self.invertNormals, highlight=highlight, sharpColorBoundaries=1) else: v1 = self.v[:, 0, :].astype("f") v2 = self.v[:, 1, :].astype("f") return glDrawCylinderSet(c, self.faceSet.faces.array, radii, fmat, bmat, fbind, bbind, self.frontAndBack, self.quality, self.invertNormals, sharpColorBoundaries=0, npoly=self.npoly, vertx=v1, verty=v2, norms=self.n) if self.getSharpColorBoundaries() in [True, 1]: self.cyldraw = self.cyldrawWithSharpColorBoundaries else: self.cyldraw = self.cyldrawWithInterpolatedColors if self.oneRadius == viewerConst.NO: radii = self.vertexSet.radii.array else: radius = self.vertexSet.radii.array[0] pickName = 0 for i in xrange(len(self.faceSet.faces.array)): #print 'CYLINDERS', i, '********************************', for j in xrange(len(self.faceSet.faces.array[i]) - 1): vi1 = self.faceSet.faces.array[i][j] vi2 = self.faceSet.faces.array[i][j + 1] if fp: fpp1 = [None, None, None, None, None] fpp2 = [None, None, None, None, None] for m in (0, 1, 2, 3, 4): if fp.binding[m] == viewerConst.PER_VERTEX: fpp1[m] = fp.prop[m][vi2] fpp1[m] = array(fpp1[m], copy=1) fpp2[m] = fp.prop[m][vi1] fpp2[m] = array(fpp2[m], copy=1) elif fp.binding[m] == viewerConst.PER_PART: fpp2[m] = fpp1[m] = fp.prop[m][i] fpp1[m] = array(fpp1[m], copy=1) fpp2[m] = array(fpp2[m], copy=1) else: fpp1 = fpp2 = None if bp and not self.frontAndBack: bpp1 = [None, None, None, None, None] bpp2 = [None, None, None, None, None] for m in (0, 1, 2, 3, 4): if bp.binding[m] == viewerConst.PER_VERTEX: bpp1[m] = bp.prop[m][vi2] bpp1[m] = array(bpp1[m], copy=1) bpp2[m] = bp.prop[m][vi1] bpp2[m] = array(bpp2[m], copy=1) elif bp.binding[m] == viewerConst.PER_PART: bpp2[m] = bpp1[m] = bp.prop[m][i] bpp1[m] = array(bpp1[m], copy=1) bpp2[m] = array(bpp2[m], copy=1) else: bpp1 = bpp2 = None GL.glPushName(pickName) if len(self.highlight) > 0: if self.oneRadius: self.cyldraw(c[vi1], c[vi2], radius, radius, fpp1, bpp1, fpp2, bpp2, face, highlightX=self.highlight[vi1], highlightY=self.highlight[vi2]) else: if vi1 < vi2: self.cyldraw(c[vi1], c[vi2], radii[vi2], radii[vi1], fpp1, bpp1, fpp2, bpp2, face, highlightX=self.highlight[vi1], highlightY=self.highlight[vi2]) else: self.cyldraw(c[vi1], c[vi2], radii[vi1], radii[vi2], fpp1, bpp1, fpp2, bpp2, face, highlightX=self.highlight[vi1], highlightY=self.highlight[vi2]) else: if self.oneRadius: self.cyldraw(c[vi1], c[vi2], radius, radius, fpp1, bpp1, fpp2, bpp2, face) else: if vi1 < vi2: self.cyldraw(c[vi1], c[vi2], radii[vi2], radii[vi1], fpp1, bpp1, fpp2, bpp2, face) else: self.cyldraw(c[vi1], c[vi2], radii[vi1], radii[vi2], fpp1, bpp1, fpp2, bpp2, face) GL.glPopName() pickName = pickName + 1 #print 'CYLINDERS done' return 1
def drawLegendOnly( fullWidth, fullHeight, ramp, verticalLegend=True, roomLeftToLegend=0, roomBelowLegend=50, legendShortSide=10, legendLongSide=150, interpolate=True, selected=False, tile=None, ): if ramp is None or len(ramp) == 0: return if tile is not None and selected is True: selected = False # deducted values if verticalLegend is True: lRoomToLegendCloseLongSide = roomLeftToLegend lRoomToLegendCloseShortSide = roomBelowLegend if legendShortSide < 1: legendShortSide = 1 if legendLongSide < 1: legendLongSide = 1 else: lRoomToLegendCloseLongSide = roomBelowLegend lRoomToLegendCloseShortSide = roomLeftToLegend if legendShortSide < 1: legendShortSide = 1 if legendLongSide < 1: legendLongSide = 1 lRoomToLegendFarLongSide = lRoomToLegendCloseLongSide + legendShortSide 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) GL.glDisable(GL.GL_DEPTH_TEST) GL.glDepthMask(GL.GL_FALSE) if len(ramp[0]) == 4: # there are alpha values, draw checkered bg GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) #draw a bunch of quads as background lCheckerSquareSize = legendShortSide * .5 if lCheckerSquareSize != 0: nbquads = int(legendLongSide / lCheckerSquareSize) else: nbquads = 1 c1 = ( 0.1, 0.1, 0.1 ) c2 = ( 0.3, 0.3, 0.3 ) c = c1 x2 = None for i in range(nbquads+1): GL.glColor3fv(c) if i==nbquads and nbquads != 0: x1=x2 x2=legendLongSide else: x1 = i*lCheckerSquareSize x2 = min (x1+lCheckerSquareSize, legendLongSide) GL.glBegin(GL.GL_QUADS) if verticalLegend is True: GL.glVertex2f(float(lRoomToLegendCloseLongSide), float(lRoomToLegendCloseShortSide + x1)) GL.glVertex2f(float(lRoomToLegendCloseLongSide+lCheckerSquareSize), float(lRoomToLegendCloseShortSide + x1)) GL.glVertex2f(float(lRoomToLegendCloseLongSide+lCheckerSquareSize), float(lRoomToLegendCloseShortSide + x2)) GL.glVertex2f(float(lRoomToLegendCloseLongSide), float(lRoomToLegendCloseShortSide + x2)) else: GL.glVertex2f(float(lRoomToLegendCloseShortSide + x2), float(lRoomToLegendCloseLongSide)) GL.glVertex2f(float(lRoomToLegendCloseShortSide + x2), float(lRoomToLegendCloseLongSide+lCheckerSquareSize)) GL.glVertex2f(float(lRoomToLegendCloseShortSide + x1), float(lRoomToLegendCloseLongSide+lCheckerSquareSize)) GL.glVertex2f(float(lRoomToLegendCloseShortSide + x1), float(lRoomToLegendCloseLongSide)) GL.glEnd() if c==c1: c=c2 else: 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)
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: solidCylinder(midRadius, float(radx), sz2, quality, 1, self.invertNormals) GL.glTranslatef(0, 0, float(sz2)) if colxf: for m in (0, 1, 2, 3, 4): if colxf[m] is not None: 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) if highlightY != 0: GL.glStencilFunc(GL.GL_ALWAYS, 1, 1) solidCylinder(float(rady), midRadius, sz2, quality, 1, self.invertNormals) GL.glStencilFunc(GL.GL_ALWAYS, 0, 1) else: solidCylinder(float(rady), midRadius, sz2, quality, 1, self.invertNormals) GL.glPopMatrix()
def drawLegendLabelName( fullWidth, fullHeight, ramp, mini, maxi, name='', unit='', labelValues=[], verticalLegend=True, leftOrBelowLabels=False, roomLeftToLegend=0, roomBelowLegend=50, legendShortSide=10, legendLongSide=150, significantDigits=3, backgroundColor=(0, 0, 0, .8), labelColor=(1, 1, 1), interpolate=True, frame=True, selected=False, numOfLabels=None, resizeSpotRadius=5, fontScale=8, glfFontID=0, tile=None, ): if ramp is None or len(ramp) == 0: return if tile is not None and selected is True: selected = False # some glf font initialisation glf.glfSetCurrentFont(glfFontID) glf.glfStringCentering(GL.GL_FALSE) glf.glfStringDirection(glf.GLF_LEFT) # calculate name and unit size lNameMinAndMax = glf.glfGetStringBounds(name) lNameMinAndMax = (lNameMinAndMax[0] * fontScale, lNameMinAndMax[1] * fontScale, lNameMinAndMax[2] * fontScale, lNameMinAndMax[3] * fontScale) lNameWidth = lNameMinAndMax[2] - lNameMinAndMax[0] lNameHeight = lNameMinAndMax[3] - lNameMinAndMax[1] if lNameWidth == 0: lNameWidth = fontScale if unit is not None and (len(unit) > 0): lUnitMinAndMax = glf.glfGetStringBounds(unit) lUnitMinAndMax = (lUnitMinAndMax[0] * fontScale, lUnitMinAndMax[1] * fontScale, lUnitMinAndMax[2] * fontScale, lUnitMinAndMax[3] * fontScale) lUnitWidth = lUnitMinAndMax[2] - lUnitMinAndMax[0] lUnitHeight = lUnitMinAndMax[3] - lUnitMinAndMax[1] else: lUnitWidth = fontScale lUnitHeight = 0 lMaxNameUnitHeight = max(lNameHeight, lUnitHeight) lMaxNameUnitWidth = max(lNameWidth, lUnitWidth) # deducted values fontScaleHalf = fontScale / 2 if verticalLegend is True: lRoomToLegendCloseLongSide = roomLeftToLegend lRoomToLegendCloseShortSide = roomBelowLegend if legendShortSide < 1: legendShortSide = 1 if legendLongSide < 1: legendLongSide = 1 else: lRoomToLegendCloseLongSide = roomBelowLegend lRoomToLegendCloseShortSide = roomLeftToLegend if legendShortSide < lMaxNameUnitHeight + fontScaleHalf: legendShortSide = lMaxNameUnitHeight + fontScaleHalf if legendLongSide < 1: legendLongSide = 1 lRoomToLegendFarLongSide = lRoomToLegendCloseLongSide + legendShortSide lRoomToLegendFarShortSide = lRoomToLegendCloseShortSide + legendLongSide # prepare the legend labels if len(labelValues) > 0: lOnScreenLabelValues = labelValues else: if numOfLabels == None or numOfLabels < 0: if verticalLegend is True: numOfLabels = 6 else: numOfLabels = 4 if (numOfLabels == 0) or maxi is None or mini is None: lOnScreenLabelValues = [] elif numOfLabels == 1: lOnScreenLabelValues = [(mini + maxi) * 0.5] else: delta = (maxi - mini) / float(numOfLabels - 1) lOnScreenLabelValues = [] for i in range(numOfLabels): lOnScreenLabelValues.append(mini + i * delta) lMaxLabelDigits = 0 for v in lOnScreenLabelValues: lLabel = "%.*g" % (significantDigits, v) if lMaxLabelDigits < len(lLabel): lMaxLabelDigits = len(lLabel) # calculate labels size lLabelsMinAndMax = [] lLabelsWidth = [] lLabelsHeight = [] lMaxLabelsWidth = 0 lMaxLabelsHeight = 0 for v in lOnScreenLabelValues: lLabel = "%.*g" % (significantDigits, v) lLabelsMinAndMax.append(glf.glfGetStringBounds(lLabel)) lLabelsMinAndMax[-1] = (lLabelsMinAndMax[-1][0] * fontScale, lLabelsMinAndMax[-1][1] * fontScale, lLabelsMinAndMax[-1][2] * fontScale, lLabelsMinAndMax[-1][3] * fontScale) lLabelsWidth.append(lLabelsMinAndMax[-1][2] - lLabelsMinAndMax[-1][0]) lLabelsHeight.append(lLabelsMinAndMax[-1][3] - lLabelsMinAndMax[-1][1]) if lLabelsWidth[-1] > lMaxLabelsWidth: lMaxLabelsWidth = lLabelsWidth[-1] if lLabelsHeight[-1] > lMaxLabelsHeight: lMaxLabelsHeight = lLabelsHeight[-1] # calculate frame size lMaxWidth = max(lMaxLabelsWidth + legendShortSide, lMaxNameUnitWidth) lMaxNameUnitHeightHalf = lMaxNameUnitHeight / 2 legendShortSideHalf = legendShortSide / 2 if verticalLegend is True: if leftOrBelowLabels is False: lPt1 = (lRoomToLegendCloseLongSide, -fontScale + lRoomToLegendCloseShortSide - lMaxLabelsHeight - lNameHeight, 0) lPt2 = (fontScale + lRoomToLegendCloseLongSide + lMaxWidth, -fontScale + lRoomToLegendCloseShortSide - lMaxLabelsHeight - lNameHeight, 0) lPt3 = (fontScale + lRoomToLegendCloseLongSide + lMaxWidth, fontScale + lRoomToLegendFarShortSide + lMaxLabelsHeight + lUnitHeight, 0) lPt4 = (lRoomToLegendCloseLongSide, fontScale + lRoomToLegendFarShortSide + lMaxLabelsHeight + lUnitHeight, 0) else: lPt1 = (-fontScale + lRoomToLegendFarLongSide - lMaxWidth, -fontScale + lRoomToLegendCloseShortSide - lMaxLabelsHeight - lNameHeight, 0) lPt2 = (lRoomToLegendCloseLongSide + legendShortSide, -fontScale + lRoomToLegendCloseShortSide - lMaxLabelsHeight - lNameHeight, 0) lPt3 = (lRoomToLegendCloseLongSide + legendShortSide, fontScale + lRoomToLegendFarShortSide + lMaxLabelsHeight + lUnitHeight, 0) lPt4 = (-fontScale + lRoomToLegendFarLongSide - lMaxWidth, fontScale + lRoomToLegendFarShortSide + lMaxLabelsHeight + lUnitHeight, 0) else: if leftOrBelowLabels is False: lPt1 = (-fontScale + lRoomToLegendCloseShortSide - lNameWidth, lRoomToLegendCloseLongSide, 0) lPt2 = (fontScale + lRoomToLegendFarShortSide + lUnitWidth, lRoomToLegendCloseLongSide, 0) lPt3 = (fontScale+lRoomToLegendFarShortSide+lUnitWidth, fontScale+lRoomToLegendCloseLongSide \ + legendShortSide \ + lMaxLabelsHeight, 0) lPt4 = (-fontScale+lRoomToLegendCloseShortSide-lNameWidth, fontScale+lRoomToLegendCloseLongSide \ + legendShortSide \ + lMaxLabelsHeight, 0) else: lPt1 = (-fontScale + lRoomToLegendCloseShortSide - lNameWidth, -fontScale + lRoomToLegendCloseLongSide - lMaxLabelsHeight, 0) lPt2 = (fontScale + lRoomToLegendFarShortSide + lUnitWidth, -fontScale + lRoomToLegendCloseLongSide - lMaxLabelsHeight, 0) lPt3 = (fontScale + lRoomToLegendFarShortSide + lUnitWidth, lRoomToLegendFarLongSide, 0) lPt4 = (-fontScale + lRoomToLegendCloseShortSide - lNameWidth, lRoomToLegendFarLongSide, 0) 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 lRoomLeftToUnit = -fontScaleHalf + lRoomToLegendFarLongSide - lUnitWidth lRoomBelowName = -fontScaleHalf + roomBelowLegend - lMaxLabelsHeight - lNameHeight lRoomBelowUnit = fontScaleHalf + roomBelowLegend + legendLongSide + lMaxLabelsHeight else: lRoomLeftToLabel = fontScaleHalf + lRoomToLegendFarLongSide lRoomLeftToName = fontScaleHalf + lRoomToLegendCloseLongSide lRoomLeftToUnit = lRoomLeftToName lRoomBelowName = -fontScaleHalf + roomBelowLegend - lMaxLabelsHeight - lNameHeight lRoomBelowUnit = fontScaleHalf + roomBelowLegend + legendLongSide + lMaxLabelsHeight else: if leftOrBelowLabels is True: lRoomBelowLabel = -fontScaleHalf + lRoomToLegendFarLongSide \ - legendShortSide - lMaxLabelsHeight lRoomBelowName = lRoomToLegendCloseLongSide + legendShortSideHalf \ - lMaxNameUnitHeightHalf else: lRoomBelowLabel = fontScaleHalf + lRoomToLegendCloseLongSide \ + legendShortSide lRoomBelowName = lRoomToLegendCloseLongSide + legendShortSideHalf \ - lMaxNameUnitHeightHalf lRoomBelowUnit = lRoomBelowName lRoomLeftToName = -fontScaleHalf + lRoomToLegendCloseShortSide - lNameWidth lRoomLeftToUnit = fontScaleHalf + lRoomToLegendFarShortSide # set the color of the text GL.glColor3fv(labelColor2) # print the legend name GL.glPushMatrix() GL.glTranslatef(float(lRoomLeftToName + fontScale), float(lRoomBelowName - lNameMinAndMax[1]), 0) GL.glScalef(float(fontScale), float(fontScale), 0) glf.glfDrawSolidString(name) GL.glPopMatrix() if unit is not None and (len(unit) > 0): GL.glPushMatrix() GL.glTranslatef(float(lRoomLeftToUnit + fontScale), float(lRoomBelowUnit - lUnitMinAndMax[1]), 0) GL.glScalef(float(fontScale), float(fontScale), 1) glf.glfDrawSolidString(unit) GL.glPopMatrix() if mini is not None and maxi is not None: i = 0 for v in lOnScreenLabelValues: #calculate label position lLabel = "%.*g" % (significantDigits, v) lStep = (v - mini) * lUnitStep GL.glPushMatrix() if verticalLegend: if leftOrBelowLabels: GL.glTranslatef( float(lRoomLeftToLabel + fontScale - lLabelsWidth[i]), float(roomBelowLegend - (lLabelsHeight[i] / 2 + lLabelsMinAndMax[i][1]) + lStep), 0) else: GL.glTranslatef( float(lRoomLeftToLabel + fontScale), float(roomBelowLegend - (lLabelsHeight[i] / 2 + lLabelsMinAndMax[i][1]) + lStep), 0) else: GL.glTranslatef( float(roomLeftToLegend - (lLabelsWidth[i] / 2) + fontScale + lStep), float(lRoomBelowLabel - lLabelsMinAndMax[i][1]), 0) GL.glScalef(float(fontScale), float(fontScale), 1) glf.glfDrawSolidString("%s" % lLabel) GL.glPopMatrix() i += 1 if len(backgroundColor) == 4: GL.glDisable(GL.GL_BLEND) # GL.glEnable(GL.GL_LIGHTING) GL.glPopMatrix() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() GL.glMatrixMode(GL.GL_MODELVIEW) drawLegendOnly( fullWidth=fullWidth, fullHeight=fullHeight, ramp=ramp, verticalLegend=verticalLegend, roomLeftToLegend=roomLeftToLegend, roomBelowLegend=roomBelowLegend, legendShortSide=legendShortSide, legendLongSide=legendLongSide, interpolate=interpolate, selected=selected, tile=tile, ) if selected is True: GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glLoadIdentity() GL.glOrtho(0, float(fullWidth), 0, float(fullHeight), -1, 1) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glLoadIdentity() GL.glDisable(GL.GL_LIGHTING) GL.glPolygonMode(GL.GL_FRONT, GL.GL_FILL) GL.glDisable(GL.GL_DEPTH_TEST) GL.glDepthMask(GL.GL_FALSE) GL.glDisable(GL.GL_LIGHTING) resizeSpot = [] if verticalLegend: resizeSpot = [ roomLeftToLegend + legendShortSide, roomBelowLegend + legendLongSide ] else: resizeSpot = [ roomLeftToLegend + legendLongSide, roomBelowLegend + legendShortSide ] GL.glColor3fv(labelColor) GL.glBegin(GL.GL_QUADS) GL.glVertex2f(float(resizeSpot[0] + resizeSpotRadius), float(resizeSpot[1] - resizeSpotRadius)) GL.glVertex2f(float(resizeSpot[0] + resizeSpotRadius), float(resizeSpot[1] + resizeSpotRadius)) GL.glVertex2f(float(resizeSpot[0] - resizeSpotRadius), float(resizeSpot[1] + resizeSpotRadius)) GL.glVertex2f(float(resizeSpot[0] - resizeSpotRadius), float(resizeSpot[1] - resizeSpotRadius)) GL.glEnd() 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) else: resizeSpot = None return [(lPt1[0], lPt1[1]), (lPt2[0], lPt2[1]), (lPt3[0], lPt3[1]), (lPt4[0], lPt4[1])], resizeSpot, verticalLegend
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()
def Draw(self): for i in xrange(len(self.vertexSet)): if len(self.radii) == 1: rad = self.radii[0] else: rad = self.radii[i] if len(self.angles) == 1: ang = self.angles[0] else: ang = self.angles[i] vx, vy, vz = norm = self.vertexSet.normals.array[i] if self.vectors is None: # get orthogonal vector dx, dy, dz = fabs(vx), fabs(vy), fabs(vz) mini = min([dx, dy, dz]) if mini == dx: nov = 1. / sqrt(vz * vz + vy * vy) ovx = 0. ovy = -vz * nov ovz = vy * nov elif mini == dy: nov = 1. / sqrt(vz * vz + vx * vx) ovx = -vz * nov ovy = 0. ovz = vx * nov else: nov = 1. / sqrt(vy * vy + vx * vx) ovx = -vy * nov ovy = vx * nov ovz = 0. vec = [ovx, ovy, ovz] elif len(self.vectors) == 1: vec = self.vectors[0] else: vec = self.vectors[i] angRad = ang * pi * 0.00555555555556 nsegments = int(ang / self.degreesPerSegment) + 1 d = angRad / nsegments # increment a = 0 # starting angle GL.glNormal3fv(norm.astype('f')) GL.glPushName(i) GL.glBegin(GL.GL_TRIANGLE_FAN) if self.materials[ GL.GL_FRONT].binding[0] == viewerConst.PER_VERTEX: col = self.materials[GL.GL_FRONT].prop[0] GL.glColor4fv(col[i]) center = Numeric.array(self.vertexSet.vertices.array[i]) vec = Numeric.array(vec).astype('f') #vec = vec/sqrt(Numeric.sum(vec*vec)) vec2 = Numeric.zeros(3, 'f') vec2[0] = vec[1] * norm[2] - vec[2] * norm[1] vec2[1] = vec[2] * norm[0] - vec[0] * norm[2] vec2[2] = vec[0] * norm[1] - vec[1] * norm[0] GL.glVertex3fv(center) for j in range(nsegments + 1): p = center + cos(a) * vec * rad + sin(a) * vec2 * rad GL.glVertex3fv(p.astype('f')) a = a + d GL.glEnd() GL.glPopName() return 1
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: ## fpProp = None #print 'FUGU OVERWRITE COLOR', fpProp #import numpy #GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, numpy.array((.6,.6,.6,1), 'f')) #GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, numpy.array((1.,1.,1.,1), 'f')) #GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, numpy.array((.4,.4,.4,1), 'f')) #GL.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, numpy.array((0,0,0,1), 'f')) #GL.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 1.) status = glDrawSphereSet( self.templateDSPL[0], coords.astype('f'), fpProp, #self.materials[GL.GL_FRONT].prop, highlight=self.highlight, ) #print "Spheres, status: ", status return status else: resetMaterialMemory() #print "SLOW Spheres" if self.oneRadius == viewerConst.NO: radii = self.vertexSet.radii.array else: radii = Numeric.ones( centers.shape[0] ) * self.radius if len(self.vertexSet.vertices) != len(radii): return 0 for i in xrange(centers.shape[0]): GL.glPushName(i) GL.glPushMatrix() GL.glTranslatef(float(centers[i][0]), float(centers[i][1]), float(centers[i][2])) if not self.oneRadius: GL.glScalef(float(radii[i]),float(radii[i]),float(radii[i])) else: GL.glScalef(float(self.radius), float(self.radius), float(self.radius)) #print '#%d'%self.templateDSPL[0], "glCallList Spheres0" if fp: for m in (0,1,2,3,4): if fp.binding[m] != viewerConst.OVERALL: glMaterialWithCheck( face, viewerConst.propConst[m], fp.prop[m][0], geom=self) GL.glCallList(self.templateDSPL[0]) GL.glPopMatrix() GL.glPopName() return 1
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()
def Draw(self): #print "GlfLabels.Draw", self centers = self.vertexSet.vertices.array if len(centers) == 0: return labels = self.labels if labels is None or len(labels) == 0: return elif len(labels) == centers.shape[0]: txt = None else: txt = labels[0] if type(txt) != types.StringType: txt = str(txt) self.prepareBillboardAndNormalForAllTextLines() glf.glfSetSymbolSpace(self.fontSpacing) if self.fontTypeIsVector: font = self.vectorFonts[self.font] glf.glfSetCurrentFont(font) else: font = self.bitmapFonts[self.font] glf.glfSetCurrentBMFFont(font) glf.glfStartBitmapDrawing() resetMaterialMemory() if self.inheritMaterial: fp = None bp = None else: fp = self.materials[GL.GL_FRONT] colorFront = Numeric.array(self.materials[GL.GL_FRONT].prop[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], fp.prop[m][0]) if fp.binding[1] == viewerConst.OVERALL: GL.glColor4fv(colorFront[0]) for i in xrange(centers.shape[0]): if fp: for m in (0, 1, 2, 3, 4): if fp.binding[m] == viewerConst.PER_VERTEX: glMaterialWithCheck(face, viewerConst.propConst[m], fp.prop[m][i]) if fp.binding[1] != viewerConst.OVERALL: GL.glColor4fv(colorFront[i]) if bp: for m in (0, 1, 2, 3, 4): if bp.binding[m] == viewerConst.PER_VERTEX: glMaterialWithCheck(face, viewerConst.propConst[m], bp.prop[m][i]) #GL.glPushName(i) if txt is None: txt2 = self.labels[i] if type(txt2) != types.StringType: txt2 = str(txt2) self.drawOne3dTextLine(txt2, i) else: self.drawOne3dTextLine(txt, i) #GL.glPopName() if self.fontTypeIsVector is False: glf.glfStopBitmapDrawing() return 1