示例#1
0
 def drawOneLine(self, x1, y1, x2, y2):
     GL.glBegin(GL.GL_LINES)
     try:
         GL.glVertex2f(x1, y1)
         GL.glVertex2f(x2, y2)
     finally:
         GL.glEnd()
示例#2
0
    def redraw(self):
        if __debug__:
            if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        self.tk.call(self._w, 'makecurrent')

        GL.glDisable(GL.GL_DEPTH_TEST)
        GL.glDisable(GL.GL_LIGHTING)
        #GL.glPolygonMode(GL.GL_FRONT, GL.GL_FILL)
        GL.glBegin(GL.GL_QUADS)
        GL.glColor3f(0., 0., 0.)
        GL.glVertex2f(0., 1.)
        GL.glVertex2f(0., 0.)
        GL.glColor3f(float(self.rgbMax[0]), float(self.rgbMax[1]),
                     float(self.rgbMax[2]))
        GL.glVertex2f(1., 0.)
        GL.glVertex2f(1., 1.)
        GL.glEnd()

        GL.glEnable(GL.GL_COLOR_LOGIC_OP)
        GL.glLogicOp(GL.GL_XOR)
        GL.glLineWidth(2)
        GL.glColor3f(.5, .5, .5)
        GL.glBegin(GL.GL_LINES)
        x1 = self.v - 0.01
        x2 = self.v + 0.01
        GL.glVertex2f(float(x1), 1.)
        GL.glVertex2f(float(x1), 0.)
        GL.glVertex2f(float(x2), 0.)
        GL.glVertex2f(float(x2), 1.)
        GL.glEnd()
        GL.glDisable(GL.GL_COLOR_LOGIC_OP)
 def drawOneLine(self, x1, y1, x2, y2):
     GL.glBegin( GL.GL_LINES)
     try:
         GL.glVertex2f( x1, y1)
         GL.glVertex2f( x2, y2)
     finally:
         GL.glEnd()
示例#4
0
    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 redraw(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        self.tk.call(self._w, 'makecurrent')

        GL.glDisable( GL.GL_DEPTH_TEST )
        GL.glDisable( GL.GL_LIGHTING )
        #GL.glPolygonMode(GL.GL_FRONT, GL.GL_FILL)
        GL.glBegin(GL.GL_QUADS)
        GL.glColor3f(0.,0.,0.)
        GL.glVertex2f(0., 1.); GL.glVertex2f(0., 0.)
        GL.glColor3f(float(self.rgbMax[0]),float(self.rgbMax[1]),float(self.rgbMax[2]))
        GL.glVertex2f( 1., 0.); GL.glVertex2f( 1., 1.)
        GL.glEnd()

        GL.glEnable(GL.GL_COLOR_LOGIC_OP)
        GL.glLogicOp(GL.GL_XOR)
        GL.glLineWidth(2)
        GL.glColor3f(.5,.5,.5)
        GL.glBegin(GL.GL_LINES)
        x1 = self.v-0.01
        x2 = self.v+0.01
        GL.glVertex2f(float(x1), 1.); GL.glVertex2f(float(x1), 0.)
        GL.glVertex2f(float(x2), 0.); GL.glVertex2f(float(x2), 1.)
        GL.glEnd()
        GL.glDisable(GL.GL_COLOR_LOGIC_OP)
示例#6
0
    def pickDraw(self):
        """called by the picking process to operate the selection
"""
        #print "Insert2d.pickDraw", self
        if self.polygonContour is not None:
            # we draw just flat quad of the insert2d
            GL.glMatrixMode(GL.GL_PROJECTION)
            GL.glPushMatrix()       
            #GL.glLoadIdentity()
            GL.glLoadMatrixf(self.viewer.currentCamera.pickMatrix) 
            GL.glOrtho(0, float(self.viewer.currentCamera.width),
                       0, float(self.viewer.currentCamera.height), -1, 1)
            GL.glMatrixMode(GL.GL_MODELVIEW)
            GL.glPushMatrix()
            GL.glLoadIdentity()
            GL.glPolygonMode(GL.GL_FRONT, GL.GL_FILL)
            GL.glPushName(0)
            GL.glBegin(GL.GL_QUADS)
            GL.glVertex2fv(self.polygonContour[0])
            GL.glVertex2fv(self.polygonContour[1])
            GL.glVertex2fv(self.polygonContour[2])
            GL.glVertex2fv(self.polygonContour[3])
            GL.glEnd()
            GL.glPopName()
        
            GL.glMatrixMode(GL.GL_PROJECTION)
            GL.glPopMatrix()
            GL.glMatrixMode(GL.GL_MODELVIEW)
            GL.glPopMatrix()
示例#7
0
 def Draw(self):
     #print"Box.Draw"
     self.oldFPM = self.frontPolyMode
     if self.frontPolyMode == GL.GL_LINE:
         GL.glDisable(GL.GL_LIGHTING)
         #c is 8x3 array 
         c= self.vertexSet.vertices.array
         #lines parallel to x-axis should be red, y->blue and z->green
         col = ((1,0,0),(0,1,0),(0,0,1))
         #these groups of 4 pairs of points define lines parallel to x, y, and z axes
         alines=[[(c[0],c[1]),(c[2],c[3]),(c[4],c[5]),(c[6],c[7])],
             [(c[0],c[3]),(c[1],c[2]),(c[4],c[7]),(c[5],c[6])],
             [(c[0],c[4]),(c[1],c[5]),(c[3],c[7]),(c[2],c[6])]]
         namectr=0
         for i in range(3):
             if not self.inheritMaterial:
                 GL.glColor3fv(col[i])
             for vpairs in alines[i]:
                 GL.glPushName(namectr)
                 GL.glBegin(GL.GL_LINES)
                 GL.glVertex3dv(list(vpairs[0]))
                 GL.glVertex3dv(list(vpairs[1]))
                 GL.glEnd()
                 GL.glPopName()
                 namectr=namectr+1
         self.viewer.enableOpenglLighting()
         return 1
     else:
         return IndexedPolygons.Draw(self)
示例#8
0
文件: Box.py 项目: lisarosalina/App
 def Draw(self):
     #print"Box.Draw"
     self.oldFPM = self.frontPolyMode
     if self.frontPolyMode == GL.GL_LINE:
         GL.glDisable(GL.GL_LIGHTING)
         #c is 8x3 array
         c = self.vertexSet.vertices.array
         #lines parallel to x-axis should be red, y->blue and z->green
         col = ((1, 0, 0), (0, 1, 0), (0, 0, 1))
         #these groups of 4 pairs of points define lines parallel to x, y, and z axes
         alines = [[(c[0], c[1]), (c[2], c[3]), (c[4], c[5]), (c[6], c[7])],
                   [(c[0], c[3]), (c[1], c[2]), (c[4], c[7]), (c[5], c[6])],
                   [(c[0], c[4]), (c[1], c[5]), (c[3], c[7]), (c[2], c[6])]]
         namectr = 0
         for i in range(3):
             if not self.inheritMaterial:
                 GL.glColor3fv(col[i])
             for vpairs in alines[i]:
                 GL.glPushName(namectr)
                 GL.glBegin(GL.GL_LINES)
                 GL.glVertex3dv(list(vpairs[0]))
                 GL.glVertex3dv(list(vpairs[1]))
                 GL.glEnd()
                 GL.glPopName()
                 namectr = namectr + 1
         self.viewer.enableOpenglLighting()
         return 1
     else:
         return IndexedPolygons.Draw(self)
示例#9
0
    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()
示例#10
0
    def Draw(self):
        if __debug__:
            if hasattr(DejaVu, 'functionName'): DejaVu.functionName()

            GL.glEnable(GL.GL_AUTO_NORMAL)
            GL.glEnable(GL.GL_NORMALIZE)

            if self.theNurb is None:
                self.theNurb = GLU.gluNewNurbsRenderer()

                GLU.gluNurbsProperty(self.theNurb, GLU.GLU_SAMPLING_TOLERANCE,
                                     25.0)
                GLU.gluNurbsProperty(self.theNurb, GLU.GLU_DISPLAY_MODE,
                                     GLU.GLU_OUTLINE_POLYGON)
                GLU.gluNurbsCallback(self.theNurb, GLU.GLU_ERROR,
                                     self.nurbsError)

            GLU.gluBeginSurface(self.theNurb)
            _glulib.gluNurbsSurface(self.theNurb, 8, self.knots, 8, self.knots,
                                    4 * 3, 3, self.ctlpoints, 4, 4,
                                    GL.GL_MAP2_VERTEX_3)

            GLU.gluEndSurface(self.theNurb)

            GL.glPointSize(5.0)
            GL.glDisable(GL.GL_LIGHTING)
            GL.glColor3f(1.0, 1.0, 0.0)
            GL.glBegin(GL.GL_POINTS)
            for i in range(4):
                for j in range(4):
                    GL.glVertex3fv(self.ctlpoints[i][j])

            GL.glEnd()
            GL.glDisable(GL.GL_AUTO_NORMAL)
            GL.glDisable(GL.GL_NORMALIZE)
示例#11
0
    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()
示例#12
0
    def arrowdraw(self, x, y, colxf=None, colxb=None,
                  colyf=None, colyb=None,face=None):
        # draw a cylinder going from x to y
        # col for materials
        # 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)

        rx = -180.0*math.acos((y[2]-x[2])/sz)/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 arrow
        GL.glBegin(GL.GL_LINES)
        
        if colxf:
            
            for m in (0,1,2,3,4):
                if colxf[m] is not None:
                    glMaterialWithCheck( face, viewerConst.propConst[m],
                                         colxf[m] )
        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] )
                    
        GL.glVertex3f(float(self.v[0][0]), float(self.v[0][1]), float(self.v[0][2]*sz))
        GL.glVertex3f(float(self.v[1][0]), float(self.v[1][1]), float(self.v[1][2]*sz))
        for i in range(self.npoly):
            h = i+2
            vx = self.v[h]
            GL.glVertex3f(float(self.v[1][0]), float(self.v[1][1]),
                          float(self.v[1][2]*sz))
            GL.glVertex3f(float(vx[0]*sz), float(vx[1]*sz), float(vx[2]*sz))

        GL.glEnd()

        GL.glPopMatrix()             
示例#13
0
 def triangle(self):
     GL.glBegin(GL.GL_TRIANGLES)
     try:
         GL.glColor3f(1.0, 0.0, 0.0)
         GL.glVertex2f(5.0, 5.0)
         GL.glColor3f(0.0, 1.0, 0.0)
         GL.glVertex2f(25.0, 5.0)
         GL.glColor3f(0.0, 0.0, 1.0)
         GL.glVertex2f(5.0, 25.0)
     finally:
         GL.glEnd()
 def triangle(self):
    GL.glBegin( GL.GL_TRIANGLES)
    try:
        GL.glColor3f( 1.0, 0.0, 0.0)
        GL.glVertex2f( 5.0, 5.0)
        GL.glColor3f( 0.0, 1.0, 0.0)
        GL.glVertex2f( 25.0, 5.0)
        GL.glColor3f( 0.0, 0.0, 1.0)
        GL.glVertex2f( 5.0, 25.0)
    finally:
        GL.glEnd()
示例#15
0
 def drawpolygons(self):
     g = self.geom
     vertices = g.getVertices()
     faces = g.getFaces()
     normals = g.getFNormals()
     GL.glDisable(GL.GL_CULL_FACE)
     for i, f in enumerate(faces):
         GL.glBegin(GL.GL_POLYGON)
         GL.glNormal3fv(normals[i])
         for vi in f:
             GL.glVertex3fv(vertices[vi])
         GL.glEnd()
         i += 1
示例#16
0
 def drawpolygons(self):
     g = self.geom
     vertices = g.getVertices()
     faces = g.getFaces()
     normals = g.getFNormals()
     GL.glDisable(GL.GL_CULL_FACE)
     for i,f in enumerate(faces):
         GL.glBegin(GL.GL_POLYGON)
         GL.glNormal3fv(normals[i])
         for vi in f:
             GL.glVertex3fv(vertices[vi])
         GL.glEnd()
         i+=1
示例#17
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
示例#18
0
 def test_0032(self ):
     import Tkinter
     root = Tkinter.Tk()
     vi = OGLTkWidget(root)
     GL.glBegin( GL.GL_TRIANGLES)
     GL.glColor3f( 1.0, 0.0, 0.0)
     GL.glVertex2f( 5.0, 5.0)
     GL.glColor3f( 0.0, 1.0, 0.0)
     GL.glVertex2f( 25.0, 5.0)
     GL.glColor3f( 0.0, 0.0, 1.0)
     GL.glVertex2f( 5.0, 25.0)
     GL.glEnd()
     root.after(500, root.quit )
     root.mainloop()
     root.destroy()
示例#19
0
    def display(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT)

        # select white for all lines
        GL.glColor3f(1.0, 1.0, 1.0)

        # in 1st row, 3 lines, each with a different stipple
        GL.glEnable(GL.GL_LINE_STIPPLE)

        GL.glLineStipple(1, 0x0101)  #  dotted
        self.drawOneLine(50.0, 125.0, 150.0, 125.0)
        GL.glLineStipple(1, 0x00FF)  #  dashed
        self.drawOneLine(150.0, 125.0, 250.0, 125.0)
        GL.glLineStipple(1, 0x1C47)  #  dash/dot/dash
        self.drawOneLine(250.0, 125.0, 350.0, 125.0)

        # in 2nd row, 3 wide lines, each with different stipple
        GL.glLineWidth(5.0)
        GL.glLineStipple(1, 0x0101)  #  dotted
        self.drawOneLine(50.0, 100.0, 150.0, 100.0)
        GL.glLineStipple(1, 0x00FF)  #  dashed
        self.drawOneLine(150.0, 100.0, 250.0, 100.0)
        GL.glLineStipple(1, 0x1C47)  #  dash/dot/dash
        self.drawOneLine(250.0, 100.0, 350.0, 100.0)
        GL.glLineWidth(1.0)

        # in 3rd row, 6 lines, with dash/dot/dash stipple
        # as part of a single connected line strip
        GL.glLineStipple(1, 0x1C47)  # dash/dot/dash
        GL.glBegin(GL.GL_LINE_STRIP)
        try:
            for i in range(0, 7):
                GL.glVertex2f(50.0 + (i * 50.0), 75.0)
        finally:
            GL.glEnd()

        # in 4th row, 6 independent lines with same stipple  */
        for i in range(0, 6):
            self.drawOneLine(50.0 + (i * 50.0), 50.0, 50.0 + ((i + 1) * 50.0),
                             50.0)

        # in 5th row, 1 line, with dash/dot/dash stipple
        # and a stipple repeat factor of 5
        GL.glLineStipple(5, 0x1C47)  #  dash/dot/dash
        self.drawOneLine(50.0, 25.0, 350.0, 25.0)

        GL.glDisable(GL.GL_LINE_STIPPLE)
        GL.glFlush()
示例#20
0
    def display(self):
        GL.glClear( GL.GL_COLOR_BUFFER_BIT)

        # select white for all lines
        GL.glColor3f( 1.0, 1.0, 1.0)

        # in 1st row, 3 lines, each with a different stipple
        GL.glEnable( GL.GL_LINE_STIPPLE)

        GL.glLineStipple( 1, 0x0101)  #  dotted  
        self.drawOneLine( 50.0, 125.0, 150.0, 125.0)
        GL.glLineStipple( 1, 0x00FF)  #  dashed 
        self.drawOneLine( 150.0, 125.0, 250.0, 125.0);
        GL.glLineStipple( 1, 0x1C47)  #  dash/dot/dash
        self.drawOneLine( 250.0, 125.0, 350.0, 125.0)

        # in 2nd row, 3 wide lines, each with different stipple 
        GL.glLineWidth( 5.0)
        GL.glLineStipple( 1, 0x0101)  #  dotted 
        self.drawOneLine( 50.0, 100.0, 150.0, 100.0)
        GL.glLineStipple( 1, 0x00FF)  #  dashed
        self.drawOneLine( 150.0, 100.0, 250.0, 100.0)
        GL.glLineStipple( 1, 0x1C47)  #  dash/dot/dash
        self.drawOneLine( 250.0, 100.0, 350.0, 100.0)
        GL.glLineWidth( 1.0)

        # in 3rd row, 6 lines, with dash/dot/dash stipple  
        # as part of a single connected line strip        
        GL.glLineStipple( 1, 0x1C47)  # dash/dot/dash
        GL.glBegin( GL.GL_LINE_STRIP)
        try:
            for i in range( 0, 7):
                GL.glVertex2f( 50.0 + (i * 50.0), 75.0)
        finally:
            GL.glEnd()

        # in 4th row, 6 independent lines with same stipple  */
        for i in range( 0, 6):
            self.drawOneLine( 50.0 + (i * 50.0), 50.0, 50.0 + ((i+1) * 50.0), 50.0)

        # in 5th row, 1 line, with dash/dot/dash stipple 
        # and a stipple repeat factor of 5               
        GL.glLineStipple( 5, 0x1C47)  #  dash/dot/dash 
        self.drawOneLine( 50.0, 25.0, 350.0, 25.0)

        GL.glDisable( GL.GL_LINE_STIPPLE)
        GL.glFlush()
    def pickDraw(self):
        """called by the picking process to operate the selection
"""
        #print "colorMapLegend.pickDraw", self
        # we draw just flat quad of the insert2d
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glPushMatrix()       
        #GL.glLoadIdentity()
        GL.glLoadMatrixf(self.viewer.currentCamera.pickMatrix) 
        GL.glOrtho(0, float(self.viewer.currentCamera.width),
                   0, float(self.viewer.currentCamera.height), -1, 1)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        GL.glLoadIdentity()
        GL.glPolygonMode(GL.GL_FRONT, GL.GL_FILL)
        #GL.glColor3f(1,0,0)

        if self.resizeSpot is not None:
            GL.glPushName(1)
            GL.glBegin(GL.GL_QUADS)
            GL.glVertex2f(float(self.resizeSpot[0]+self.resizeSpotRadius),
                          float(self.resizeSpot[1]-self.resizeSpotRadius))
            GL.glVertex2f(float(self.resizeSpot[0]+self.resizeSpotRadius),
                          float(self.resizeSpot[1]+self.resizeSpotRadius))
            GL.glVertex2f(float(self.resizeSpot[0]-self.resizeSpotRadius),
                          float(self.resizeSpot[1]+self.resizeSpotRadius))
            GL.glVertex2f(float(self.resizeSpot[0]-self.resizeSpotRadius),
                          float(self.resizeSpot[1]-self.resizeSpotRadius))
            GL.glEnd()
            GL.glPopName()

        GL.glPushName(0)
        GL.glBegin(GL.GL_QUADS)
        GL.glVertex2fv(self.polygonContour[0])
        GL.glVertex2fv(self.polygonContour[1])
        GL.glVertex2fv(self.polygonContour[2])
        GL.glVertex2fv(self.polygonContour[3])
        GL.glEnd()
        GL.glPopName()

        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glPopMatrix()
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPopMatrix()
示例#22
0
    def redraw(self):
        """ redraw the Material editor opengl sphere that shows the effect
of the modifications
"""
        if __debug__:
            if hasattr(DejaVu, 'functionName'): DejaVu.functionName()

        self.tk.call(self._w, 'makecurrent')
        GL.glClearColor(0, 0, 0, 0)
        self.initProjection()
        self.Configure()
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        """ draw the black background squares """
        GL.glDisable(GL.GL_LIGHTING)
        GL.glColor3f(0.1, 0.1, 0.1)
        GL.glBegin(GL.GL_QUADS)
        GL.glVertex3f(-2, 0, 2)
        GL.glVertex3f(-2, 2, 2)
        GL.glVertex3f(0, 2, 2)
        GL.glVertex3f(0, 0, 2)
        GL.glEnd()
        GL.glBegin(GL.GL_QUADS)
        GL.glVertex3f(0, -2, 2)
        GL.glVertex3f(0, 0, 2)
        GL.glVertex3f(2, 0, 2)
        GL.glVertex3f(2, -2, 2)
        GL.glEnd()
        """ draw the grey background squares """
        GL.glColor3f(0.3, 0.3, 0.3)
        GL.glBegin(GL.GL_QUADS)
        GL.glVertex3f(-2, -2, 2)
        GL.glVertex3f(-2, 0, 2)
        GL.glVertex3f(0, 0, 2)
        GL.glVertex3f(0, -2, 2)
        GL.glEnd()
        GL.glBegin(GL.GL_QUADS)
        GL.glVertex3f(0, 0, 2)
        GL.glVertex3f(0, 2, 2)
        GL.glVertex3f(2, 2, 2)
        GL.glVertex3f(2, 0, 2)
        GL.glEnd()
        """ enable the sphere transparancy """
        GL.glEnable(GL.GL_BLEND)
        GL.glDepthMask(GL.GL_FALSE)
        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
        """ draw the sphere """
        #GL.glEnable(GL.GL_LIGHTING)
        if self.viewer is not None:
            self.viewer.enableOpenglLighting()
        self.setMaterial()
        extractedGlutSolidSphere(1.6, 30, 30, 0)
示例#23
0
    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()
示例#24
0
    def Draw(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()

         GL.glEnable(GL.GL_AUTO_NORMAL)
         GL.glEnable(GL.GL_NORMALIZE)
         
         if self.theNurb is None:         
             self.theNurb = GLU.gluNewNurbsRenderer()

             GLU.gluNurbsProperty(self.theNurb, GLU.GLU_SAMPLING_TOLERANCE,
                                  25.0)
             GLU.gluNurbsProperty(self.theNurb, GLU.GLU_DISPLAY_MODE,
                                  GLU.GLU_OUTLINE_POLYGON)
             GLU.gluNurbsCallback(self.theNurb, GLU.GLU_ERROR, self.nurbsError)

         GLU.gluBeginSurface(self.theNurb)
         _glulib.gluNurbsSurface( self.theNurb,
                                  8, self.knots,
                                  8, self.knots,
                                  4*3,
                                  3,
                                  self.ctlpoints,
                                  4, 4,
                                  GL.GL_MAP2_VERTEX_3)

         GLU.gluEndSurface(self.theNurb)

         
         GL.glPointSize(5.0)
         GL.glDisable(GL.GL_LIGHTING)
         GL.glColor3f(1.0, 1.0, 0.0)
         GL.glBegin(GL.GL_POINTS)
         for i in range(4):
             for j in range(4):
                 GL.glVertex3fv(self.ctlpoints[i][j]) 

         GL.glEnd()
         GL.glDisable(GL.GL_AUTO_NORMAL)
         GL.glDisable(GL.GL_NORMALIZE)
    def redraw(self):
        """ redraw the Material editor opengl sphere that shows the effect
of the modifications
"""
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()

        self.tk.call(self._w, 'makecurrent')
        GL.glClearColor(0,0,0,0)
        self.initProjection()
        self.Configure()
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        """ draw the black background squares """
        GL.glDisable( GL.GL_LIGHTING )
        GL.glColor3f( 0.1, 0.1, 0.1 )
        GL.glBegin(GL.GL_QUADS)
        GL.glVertex3f(-2, 0, 2); GL.glVertex3f(-2, 2, 2)
        GL.glVertex3f( 0, 2, 2); GL.glVertex3f( 0, 0, 2)
        GL.glEnd()
        GL.glBegin(GL.GL_QUADS)
        GL.glVertex3f( 0,-2, 2); GL.glVertex3f( 0, 0, 2)
        GL.glVertex3f( 2, 0, 2); GL.glVertex3f( 2,-2, 2)
        GL.glEnd()

        """ draw the grey background squares """
        GL.glColor3f( 0.3, 0.3, 0.3 )
        GL.glBegin(GL.GL_QUADS)
        GL.glVertex3f(-2,-2, 2); GL.glVertex3f(-2, 0, 2)
        GL.glVertex3f( 0, 0, 2); GL.glVertex3f( 0,-2, 2)
        GL.glEnd()
        GL.glBegin(GL.GL_QUADS)
        GL.glVertex3f( 0, 0, 2); GL.glVertex3f( 0, 2, 2)
        GL.glVertex3f( 2, 2, 2); GL.glVertex3f( 2, 0, 2)
        GL.glEnd()

        """ enable the sphere transparancy """
        GL.glEnable(GL.GL_BLEND)
        GL.glDepthMask(GL.GL_FALSE)
        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)

        """ draw the sphere """
        #GL.glEnable(GL.GL_LIGHTING)
        if self.viewer is not None:
            self.viewer.enableOpenglLighting()
        self.setMaterial()
        extractedGlutSolidSphere(1.6, 30, 30, 0)
示例#26
0
    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)
示例#27
0
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
示例#28
0
    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
示例#29
0
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)
示例#30
0
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
示例#31
0
    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):

        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
示例#33
0
    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
示例#34
0
    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()
示例#35
0
    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
示例#36
0
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)
示例#37
0
    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
示例#38
0
文件: Clip.py 项目: lisarosalina/App
    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()
示例#39
0
    def arrowdraw(self,
                  x,
                  y,
                  colxf=None,
                  colxb=None,
                  colyf=None,
                  colyb=None,
                  face=None):
        # draw a cylinder going from x to y
        # col for materials
        # 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)

        rx = -180.0 * math.acos((y[2] - x[2]) / sz) / 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 arrow
        GL.glBegin(GL.GL_LINES)

        if colxf:

            for m in (0, 1, 2, 3, 4):
                if colxf[m] is not None:
                    glMaterialWithCheck(face, viewerConst.propConst[m],
                                        colxf[m])
        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])

        GL.glVertex3f(float(self.v[0][0]), float(self.v[0][1]),
                      float(self.v[0][2] * sz))
        GL.glVertex3f(float(self.v[1][0]), float(self.v[1][1]),
                      float(self.v[1][2] * sz))
        for i in range(self.npoly):
            h = i + 2
            vx = self.v[h]
            GL.glVertex3f(float(self.v[1][0]), float(self.v[1][1]),
                          float(self.v[1][2] * sz))
            GL.glVertex3f(float(vx[0] * sz), float(vx[1] * sz),
                          float(vx[2] * sz))

        GL.glEnd()

        GL.glPopMatrix()
示例#40
0
    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
示例#41
0
    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()
示例#42
0
    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()
示例#43
0
    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