Пример #1
0
 def paintGL(self):
     #This function uses shape objects, such as cube() or meshSector(). Shape objects require the following:
     #a list named 'vertices' - This list is a list of points, from which edges and faces are drawn.
     #a list named 'wires'    - This list is a list of tuples which refer to vertices, dictating where to draw wires.
     #a list named 'facets'   - This list is a list of tuples which refer to vertices, ditating where to draw facets.
     #a bool named 'render'   - This bool is used to dictate whether or not to draw the shape.
     #a bool named 'drawWires' - This bool is used to dictate whether wires should be drawn.
     #a bool named 'drawFaces' - This bool is used to dictate whether facets should be drawn.
     
     glLoadIdentity()
     gluPerspective(45, self.width / self.height, 0.1, 110.0)    #set perspective?
     glTranslatef(0, 0, self.zoomLevel)    #I used -10 instead of -2 in the PyGame version.
     glRotatef(self.rotateDegreeV, 1, 0, 0)    #I used 2 instead of 1 in the PyGame version.
     glRotatef(self.rotateDegreeH, 0, 0, 1)
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
     
     if len(self.shapes) != 0:
         glBegin(GL_LINES)
         for s in self.shapes:
             glColor3fv(s.color)
             if s.render and s.drawWires:
                 for w in s.wires:
                     for v in w:
                         glVertex3fv(s.vertices[v])
         glEnd()
     
         glBegin(GL_QUADS)
         for s in self.shapes:
             glColor3fv(s.color)
             if s.render and s.drawFaces:
                 for f in s.facets:
                     for v in f:
                         glVertex3fv(s.vertices[v])
         glEnd()
Пример #2
0
 def draw_surface(self, surface: list):
     assert surface is not None, "No surface data!"
     glBegin(GL_POLYGON)
     for vertex in surface:
         glVertex3fv(self.vertices[vertex])
     glColor3fv(self.color)
     glEnd()
Пример #3
0
def drawArrowHead(color, 
                  basePoint, 
                  drawingScale, 
                  unitBaseVector, 
                  unitHeightVector):



    arrowBase = drawingScale * 0.08
    arrowHeight = drawingScale * 0.12
    glDisable(GL_LIGHTING)
    glPushMatrix()
    glTranslatef(basePoint[0],basePoint[1],basePoint[2])
    point1 = V(0, 0, 0)
    point1 = point1 + unitHeightVector * arrowHeight    
    point2 = unitBaseVector * arrowBase    
    point3 = - unitBaseVector * arrowBase
    #Draw the arrowheads as filled triangles
    glColor3fv(color)
    glBegin(GL_POLYGON)
    glVertex3fv(point1)
    glVertex3fv(point2)
    glVertex3fv(point3)
    glEnd()    
    glPopMatrix()
    glEnable(GL_LIGHTING)
Пример #4
0
    def draw_sorted(sorted_by_color):  #russ 080320: factored out of finish().
        """
        Traverse color-sorted lists, invoking worker procedures.
        """
        objects_drawn = 0  # Keep track and return.
        glEnable(GL_LIGHTING)

        for color, funcs in sorted_by_color.iteritems():

            opacity = color[3]
            if opacity == -1:
                #piotr 080429: Opacity == -1 signals the "unshaded color".
                # Also, see my comment in "schedule".
                glDisable(GL_LIGHTING)  # Don't forget to re-enable it!
                glColor3fv(color[:3])
            else:
                apply_material(color)
                pass

            for func, params, name in funcs:
                objects_drawn += 1
                if name != 0:
                    glPushName(name)
                func(params)
                if name != 0:
                    glPopName()
                    pass
                continue

            if opacity == -1:
                glEnable(GL_LIGHTING)

            continue
        return objects_drawn
Пример #5
0
    def draw_lines(self):
        """
        draw our line segments, using our current style attrs [which are partly nim]
        """
        # find variables which determine our GL state
        color = self.fix_color(self.linecolor)
        dashEnabled = self.dashed
        width = self.linewidth

        # set temporary GL state (code copied from drawer.drawline)
        glDisable(GL_LIGHTING)
        glColor3fv(color)
        if dashEnabled:
            glLineStipple(1, 0xAAAA)
            glEnable(GL_LINE_STIPPLE)
        if width != 1:
            glLineWidth(width)
        # draw the lines
        if self._closed_state:
            glBegin(GL_LINE_LOOP)
        else:
            glBegin(GL_LINE_STRIP)
        for pos in self.points:
            glVertex3fv(pos) # [note from old code: could be pos + origin if that can matter]
        glEnd()
        # restore default GL state [some of this might be moved up to callers]
        if width != 1:
            glLineWidth(1.0)
        if dashEnabled:
            glDisable(GL_LINE_STIPPLE)
        glEnable(GL_LIGHTING)
        return
Пример #6
0
    def draw_lines(self):
        "draw our line segments, using our current style attrs [which are partly nim]"
        # find variables which determine our GL state
        color = self.fix_color(self.linecolor)
        dashEnabled = self.dashed
        width = self.linewidth

        # set temporary GL state (code copied from drawer.drawline)
        glDisable(GL_LIGHTING)
        glColor3fv(color)
        if dashEnabled:
            glLineStipple(1, 0xAAAA)
            glEnable(GL_LINE_STIPPLE)
        if width != 1:
            glLineWidth(width)
        # draw the lines
        if self._closed_state:
            glBegin(GL_LINE_LOOP)
        else:
            glBegin(GL_LINE_STRIP)
        for pos in self.points:
            glVertex3fv(
                pos
            )  # [note from old code: could be pos + origin if that can matter]
        glEnd()
        # restore default GL state [some of this might be moved up to callers]
        if width != 1:
            glLineWidth(1.0)
        if dashEnabled:
            glDisable(GL_LINE_STIPPLE)
        glEnable(GL_LIGHTING)
        return
Пример #7
0
def draw_vertex_terrain(vertex):
    """ Draws point with terrain height color """
    z = vertex[2]
    if (z < 0 and z <= (MIN_HEIGHT / 2)):
        color = TERRAIN_COLOR_LOW
    elif (z > 0 and z >= (MAX_HEIGHT / 2)):
        color = TERRAIN_COLOR_HIGH
    else:
        color = TERRAIN_COLOR_MID

    color = hex_to_float(color)
    if (z < 0):
        minium_intensity = MIN_HEIGHT / (MIN_HEIGHT *
                                         DRAW_COLOR_INTENSITY_WEIGHT)
        intensity = (z / (MIN_HEIGHT * DRAW_COLOR_INTENSITY_WEIGHT))
        # intensity = 1 - (z / (MIN_HEIGHT * DRAW_COLOR_INTENSITY_WEIGHT))
    else:
        minium_intensity = MAX_HEIGHT / (MAX_HEIGHT *
                                         DRAW_COLOR_INTENSITY_WEIGHT)
        intensity = (z / (MAX_HEIGHT * DRAW_COLOR_INTENSITY_WEIGHT))
        # intensity = 1 - (z / (MAX_HEIGHT * DRAW_COLOR_INTENSITY_WEIGHT))
    intensity += minium_intensity
    color[0] = color[0] * intensity
    color[1] = color[1] * intensity
    color[2] = color[2] * intensity

    glColor3fv(color)
    glVertex3f(vertex[0], vertex[1], z * DRAW_HEIGHT_WEIGHT)
Пример #8
0
    def draw_sorted(sorted_by_color):   #russ 080320: factored out of finish().
        """
        Traverse color-sorted lists, invoking worker procedures.
        """
        objects_drawn = 0               # Keep track and return.
        glEnable(GL_LIGHTING)

        for color, funcs in sorted_by_color.iteritems():

            opacity = color[3]
            if opacity == -1:
                #piotr 080429: Opacity == -1 signals the "unshaded color".
                # Also, see my comment in "schedule".
                glDisable(GL_LIGHTING) # Don't forget to re-enable it!
                glColor3fv(color[:3])
            else:
                apply_material(color)
                pass

            for func, params, name in funcs:
                objects_drawn += 1
                if name != 0:
                    glPushName(name)
                func(params)
                if name != 0:
                    glPopName()
                    pass
                continue

            if opacity == -1:
                glEnable(GL_LIGHTING)

            continue
        return objects_drawn
Пример #9
0
def drawRotateSign(color, pos1, pos2, radius, rotation=0.0):
    """Rotate sign on top of the caps of the cylinder """
    glPushMatrix()
    glColor3fv(color)
    vec = pos2 - pos1
    axis = norm(vec)
    glTranslatef(pos1[0], pos1[1], pos1[2])

    ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes
    ## display problem on some platforms
    angle = -acos(axis[2]) * 180.0 / pi
    if (axis[2] * axis[2] >= 1.0):
        glRotate(angle, 0.0, 1.0, 0.0)
    else:
        glRotate(angle, axis[1], -axis[0], 0.0)
    glRotate(rotation, 0.0, 0.0, 1.0)  #bruce 050518
    glScale(radius, radius, Numeric.dot(vec, vec)**.5)

    glLineWidth(2.0)
    glDisable(GL_LIGHTING)
    glCallList(drawing_globals.rotSignList)
    glEnable(GL_LIGHTING)
    glLineWidth(1.0)

    glPopMatrix()
    return
Пример #10
0
def drawwiresphere_worker(params):
    """
    Draw a wireframe sphere.  Receive parameters through a sequence so that this
    function and its parameters can be passed to another function for
    deferment.  Right now this is only ColorSorter.schedule (see below)
    """

    (color, pos, radius, detailLevel) = params
    ## assert detailLevel == 1 # true, but leave out for speed
    from utilities.debug_prefs import debug_pref, Choice_boolean_True
    #bruce 060415 experiment, re iMac G4 wiresphere bug; fixes it!
    newway = debug_pref("new wirespheres?", Choice_boolean_True)
    oldway = not newway
    # These objects want a constant line color even if they are selected or
    # highlighted.
    glColor3fv(color)
    glDisable(GL_LIGHTING)
    if oldway:
        glPolygonMode(GL_FRONT, GL_LINE)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], pos[2])
    glScale(radius, radius, radius)
    if oldway:
        glCallList(drawing_globals.sphereList[detailLevel])
    else:
        glCallList(drawing_globals.wiresphere1list)
    glEnable(GL_LIGHTING)
    glPopMatrix()
    if oldway:
        glPolygonMode(GL_FRONT, GL_FILL)
    return
Пример #11
0
def drawFilledCircle(color, center, radius, normal):
    """
    Scale, rotate/translate the unit circle properly.
    Added a filled circle variant, piotr 080405
    """
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix() 
    glColor3fv(color)
    glDisable(GL_LIGHTING)

    glTranslatef(center[0], center[1], center[2])
    rQ = Q(V(0, 0, 1), normal)
    rotAngle = rQ.angle*180.0/pi

    #This may cause problems as proved before in Linear motor display.
    #rotation around (0, 0, 0)
    #if vlen(V(rQ.x, rQ.y, rQ.z)) < 0.00005:
    #      rQ.x = 1.0

    glRotatef(rotAngle, rQ.x, rQ.y, rQ.z)
    glScalef(radius, radius, 1.0)
    glCallList(drawing_globals.filledCircleList)
    glEnable(GL_LIGHTING)
    glPopMatrix()
    return
Пример #12
0
def drawCubeCell(color):
    sp0 = drawing_globals.sp0
    sp4 = drawing_globals.sp4
    vs = [[sp0, sp0, sp0], [sp4, sp0, sp0], [sp4, sp4, sp0], [sp0, sp4, sp0],
          [sp0, sp0, sp4], [sp4, sp0, sp4], [sp4, sp4, sp4], [sp0, sp4, sp4]]

    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glBegin(GL_LINE_LOOP)
    for ii in range(4):
        glVertex3fv(vs[ii])
    glEnd()

    glBegin(GL_LINE_LOOP)
    for ii in range(4, 8):
        glVertex3fv(vs[ii])
    glEnd()

    glBegin(GL_LINES)
    for ii in range(4):
        glVertex3fv(vs[ii])
        glVertex3fv(vs[ii+4])
    glEnd()

    glEnable(GL_LIGHTING) 
    return
Пример #13
0
    def paintGL(self):
        glLoadIdentity()
        gluPerspective(45, self.width / self.height, 0.1,
                       110.0)  #set perspective?
        glTranslatef(
            0, 0,
            self.zoomLevel)  #I used -10 instead of -2 in the PyGame version.
        glRotatef(self.rotateDegreeV, 1, 0,
                  0)  #I used 2 instead of 1 in the PyGame version.
        glRotatef(self.rotateDegreeH, 0, 0, 1)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        if len(self.shapes) != 0:
            glBegin(GL_LINES)
            for s in self.shapes:
                glColor3fv(s.color)
                if s.render and s.drawWires:
                    for e in s.edges:
                        for v in e:
                            glVertex3fv(s.vertices[v])
            glEnd()

            glBegin(GL_QUADS)
            for s in self.shapes:
                glColor3fv(s.color)
                if s.render and s.drawFaces:
                    for f in s.facets:
                        for v in f:
                            glVertex3fv(s.vertices[v])
            glEnd()
Пример #14
0
  def desenhar(self):

    glPushMatrix()
    glLoadIdentity()
    glTranslatef(*self.posicao)


    glColor3fv(self.cor)
    
    glBegin(GL_LINES)

    #desenha moldura

    glVertex3fv((0, 0, 0))
    glVertex3fv((self.largura, 0, 0))

    glVertex3fv((self.largura, 0, 0))
    glVertex3fv((self.largura, self.altura, 0))

    glVertex3fv((self.largura, self.altura, 0))
    glVertex3fv((0, self.altura, 0))

    glVertex3fv((0, self.altura, 0))
    glVertex3fv((0, 0, 0))

    i = 0
  

    while (i < len(self.pontos) - 1):
      glVertex3fv((self.pontos[i][0]*self.escala_x, self.pontos[i][1]*self.escala_y, 0))
      glVertex3fv((self.pontos[i + 1][0]*self.escala_x, self.pontos[i + 1][1]*self.escala_y, 0))
      i += 1
    glEnd()

    glPopMatrix()
Пример #15
0
def drawFilledCircle(color, center, radius, normal):
    """
    Scale, rotate/translate the unit circle properly.
    Added a filled circle variant, piotr 080405
    """
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glColor3fv(color)
    glDisable(GL_LIGHTING)

    glTranslatef(center[0], center[1], center[2])
    rQ = Q(V(0, 0, 1), normal)
    rotAngle = rQ.angle * 180.0 / pi

    #This may cause problems as proved before in Linear motor display.
    #rotation around (0, 0, 0)
    #if vlen(V(rQ.x, rQ.y, rQ.z)) < 0.00005:
    #      rQ.x = 1.0

    glRotatef(rotAngle, rQ.x, rQ.y, rQ.z)
    glScalef(radius, radius, 1.0)
    glCallList(drawing_globals.filledCircleList)
    glEnable(GL_LIGHTING)
    glPopMatrix()
    return
Пример #16
0
def drawPoint(color, 
              point, 
              pointSize = 3.0,
              isRound = True):
    """
    Draw a point using GL_POINTS. 
    @param point: The x,y,z coordinate array/ vector of the point 
    @type point: A or V
    @param pointSize: The point size to be used by glPointSize
    @type pointSize: float
    @param isRound: If True, the point will be drawn round otherwise square
    @type isRound: boolean
    """
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glPointSize(float(pointSize))
    if isRound:
        glEnable(GL_POINT_SMOOTH)
    glBegin(GL_POINTS)
    glVertex3fv(point)       
    glEnd()
    if isRound:
        glDisable(GL_POINT_SMOOTH)

    glEnable(GL_LIGHTING)
    if pointSize != 1.0:
        glPointSize(1.0)
    return
Пример #17
0
def draw_filled_rect(origin, dx, dy, color):
##    print 'draw_filled_rect',(origin, dx, dy, color) #####@@@@@
    glDisable(GL_LIGHTING) # this allows the specified color to work. Otherwise it doesn't work (I always get dark blue). Why???
     # guess: if i want lighting, i have to specify a materialcolor, not just a regular color. (and vertex normals)
    try:
        len(color)
    except:
        print "following exception in len(color) for color = %r" % (color,) # 061212 -- why didn't caller's fix_color catch it? ##k
        raise
    if len(color) == 4:
        glColor4fv(color)
        if 0 and color[3] != 1.0:
            print "color has alpha",color ####@@@@
    else:
        glColor3fv(color)
##    glRectfv(origin, origin + dx + dy) # won't work for most coords! also, ignores Z. color still not working.
    glBegin(GL_QUADS)
    glVertex3fv(origin)
    #glColor3fv(white)#
    glVertex3fv(origin + dx)
    # glColor3fv(white) # hack, see if works - yes!
    #glColor3fv(color)#
    glVertex3fv(origin + dx + dy)
    #glColor3fv(white)#
    glVertex3fv(origin + dy)
    glEnd()
    glEnable(GL_LIGHTING) # should be outside of glEnd! when inside, i got infloop! (not sure that was why; quit/reran after that)
Пример #18
0
def drawwiresphere_worker(params):
    """
    Draw a wireframe sphere.  Receive parameters through a sequence so that this
    function and its parameters can be passed to another function for
    deferment.  Right now this is only ColorSorter.schedule (see below)
    """

    (color, pos, radius, detailLevel) = params
    ## assert detailLevel == 1 # true, but leave out for speed
    from utilities.debug_prefs import debug_pref, Choice_boolean_True
    #bruce 060415 experiment, re iMac G4 wiresphere bug; fixes it!
    newway = debug_pref("new wirespheres?", Choice_boolean_True)
    oldway = not newway
    # These objects want a constant line color even if they are selected or
    # highlighted.
    glColor3fv(color)
    glDisable(GL_LIGHTING)
    if oldway:
        glPolygonMode(GL_FRONT, GL_LINE)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], pos[2])
    glScale(radius,radius,radius)
    if oldway:
        glCallList(drawing_globals.sphereList[detailLevel])
    else:
        glCallList(drawing_globals.wiresphere1list)
    glEnable(GL_LIGHTING)
    glPopMatrix()
    if oldway:
        glPolygonMode(GL_FRONT, GL_FILL)
    return
Пример #19
0
def drawCubeCell(color):
    sp0 = drawing_globals.sp0
    sp4 = drawing_globals.sp4
    vs = [[sp0, sp0, sp0], [sp4, sp0, sp0], [sp4, sp4, sp0], [sp0, sp4, sp0],
          [sp0, sp0, sp4], [sp4, sp0, sp4], [sp4, sp4, sp4], [sp0, sp4, sp4]]

    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glBegin(GL_LINE_LOOP)
    for ii in range(4):
        glVertex3fv(vs[ii])
    glEnd()

    glBegin(GL_LINE_LOOP)
    for ii in range(4, 8):
        glVertex3fv(vs[ii])
    glEnd()

    glBegin(GL_LINES)
    for ii in range(4):
        glVertex3fv(vs[ii])
        glVertex3fv(vs[ii + 4])
    glEnd()

    glEnable(GL_LIGHTING)
    return
Пример #20
0
 def draw_bottom_circle(self):
     glBegin(GL_TRIANGLE_FAN)
     glVertex3fv(self.bottom_point)
     for vertex in self.surfaces[1]:
         glVertex3fv(self.vertices[vertex])
     glColor3fv(self.color)
     glEnd()
Пример #21
0
def drawPoint(color, point, pointSize=3.0, isRound=True):
    """
    Draw a point using GL_POINTS.
    @param point: The x,y,z coordinate array/ vector of the point
    @type point: A or V
    @param pointSize: The point size to be used by glPointSize
    @type pointSize: float
    @param isRound: If True, the point will be drawn round otherwise square
    @type isRound: boolean
    """
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glPointSize(float(pointSize))
    if isRound:
        glEnable(GL_POINT_SMOOTH)
    glBegin(GL_POINTS)
    glVertex3fv(point)
    glEnd()
    if isRound:
        glDisable(GL_POINT_SMOOTH)

    glEnable(GL_LIGHTING)
    if pointSize != 1.0:
        glPointSize(1.0)
    return
Пример #22
0
def draw_filled_rect(origin, dx, dy, color):
    ##    print 'draw_filled_rect',(origin, dx, dy, color) #####@@@@@
    glDisable(
        GL_LIGHTING
    )  # this allows the specified color to work. Otherwise it doesn't work (I always get dark blue). Why???
    # guess: if i want lighting, i have to specify a materialcolor, not just a regular color. (and vertex normals)
    try:
        len(color)
    except:
        print "following exception in len(color) for color = %r" % (
            color,
        )  # 061212 -- why didn't caller's fix_color catch it? ##k
        raise
    if len(color) == 4:
        glColor4fv(color)
        if 0 and color[3] != 1.0:
            print "color has alpha", color  ####@@@@
    else:
        glColor3fv(color)
    ##    glRectfv(origin, origin + dx + dy) # won't work for most coords! also, ignores Z. color still not working.
    glBegin(GL_QUADS)
    glVertex3fv(origin)
    # glColor3fv(white)#
    glVertex3fv(origin + dx)
    # glColor3fv(white) # hack, see if works - yes!
    # glColor3fv(color)#
    glVertex3fv(origin + dx + dy)
    # glColor3fv(white)#
    glVertex3fv(origin + dy)
    glEnd()
    glEnable(
        GL_LIGHTING
    )  # should be outside of glEnd! when inside, i got infloop! (not sure that was why; quit/reran after that)
Пример #23
0
def drawRotateSign(color, pos1, pos2, radius, rotation = 0.0):
    """Rotate sign on top of the caps of the cylinder """
    glPushMatrix()
    glColor3fv(color)
    vec = pos2-pos1
    axis = norm(vec)
    glTranslatef(pos1[0], pos1[1], pos1[2])

    ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes 
    ## display problem on some platforms
    angle = -acos(axis[2])*180.0/pi
    if (axis[2]*axis[2] >= 1.0):
        glRotate(angle, 0.0, 1.0, 0.0)
    else:
        glRotate(angle, axis[1], -axis[0], 0.0)
    glRotate(rotation, 0.0, 0.0, 1.0) #bruce 050518
    glScale(radius,radius,Numeric.dot(vec,vec)**.5)

    glLineWidth(2.0)
    glDisable(GL_LIGHTING)
    glCallList(drawing_globals.rotSignList)
    glEnable(GL_LIGHTING)
    glLineWidth(1.0)

    glPopMatrix()
    return
Пример #24
0
def drawArrowHead(color, 
                  basePoint, 
                  drawingScale, 
                  unitBaseVector, 
                  unitHeightVector):



    arrowBase = drawingScale * 0.08
    arrowHeight = drawingScale * 0.12
    glDisable(GL_LIGHTING)
    glPushMatrix()
    glTranslatef(basePoint[0],basePoint[1],basePoint[2])
    point1 = V(0, 0, 0)
    point1 = point1 + unitHeightVector * arrowHeight    
    point2 = unitBaseVector * arrowBase    
    point3 = - unitBaseVector * arrowBase
    #Draw the arrowheads as filled triangles
    glColor3fv(color)
    glBegin(GL_POLYGON)
    glVertex3fv(point1)
    glVertex3fv(point2)
    glVertex3fv(point3)
    glEnd()    
    glPopMatrix()
    glEnable(GL_LIGHTING)
Пример #25
0
def draw_filled_triangle(origin, dx, dy, color):
    glColor3fv(color)
    glDisable(GL_LIGHTING)
    glBegin(GL_TRIANGLES)
    glVertex3fv(origin)
    glVertex3fv(origin + dx)
    glVertex3fv(origin + dy)
    glEnd()
    glEnable(GL_LIGHTING)
Пример #26
0
 def construct_cube(self):
     glBegin(GL_QUADS)
     for cubie in self.cubies:
         vertices = cubie.vertices
         for surface, color in cubie.surfaces:
             glColor3fv(color)
             for vertex in surface:
                 glVertex3fv(vertices[vertex])
     glEnd()
Пример #27
0
def drawlinelist(color,lines):
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glBegin(GL_LINES)
    for v in lines:
        glVertex3fv(v)
    glEnd()
    glEnable(GL_LIGHTING)
    return
Пример #28
0
def draw_filled_triangle(origin, dx, dy, color):
    glColor3fv(color)
    glDisable(GL_LIGHTING)
    glBegin(GL_TRIANGLES)
    glVertex3fv(origin)
    glVertex3fv(origin + dx)
    glVertex3fv(origin + dy)
    glEnd()
    glEnable(GL_LIGHTING)
Пример #29
0
 def draw_surfaces(self):
     if self.color is not None:
         glBegin(GL_TRIANGLE_FAN)
         glVertex3fv(self.center)
         for surface in self.surfaces:
             for vertex in surface:
                 glVertex3fv(self.vertices[vertex])
         glColor3fv(self.color)
         glEnd()
Пример #30
0
def drawlinelist(color, lines):
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glBegin(GL_LINES)
    for v in lines:
        glVertex3fv(v)
    glEnd()
    glEnable(GL_LIGHTING)
    return
Пример #31
0
def create_obb_gl_list(obb):
    from OpenGL.GL import glGenLists, glNewList, glFrontFace, glBegin, glEnd, glEndList, glColor3fv, glVertex3fv, \
        GL_CCW, GL_COMPILE, GL_LINES
    gl_list = glGenLists(1)
    glNewList(gl_list, GL_COMPILE)
    glFrontFace(GL_CCW)
    glBegin(GL_LINES)
    glColor3fv((1, 0, 0))

    def input_vertex(x, y, z):
        glVertex3fv((obb.rotation[0][0] * x + obb.rotation[0][1] * y +
                     obb.rotation[0][2] * z, obb.rotation[1][0] * x +
                     obb.rotation[1][1] * y + obb.rotation[1][2] * z,
                     obb.rotation[2][0] * x + obb.rotation[2][1] * y +
                     obb.rotation[2][2] * z))

    input_vertex(*obb.max)
    input_vertex(obb.max[0], obb.min[1], obb.max[2])

    input_vertex(obb.max[0], obb.min[1], obb.max[2])
    input_vertex(obb.min[0], obb.min[1], obb.max[2])

    input_vertex(obb.min[0], obb.min[1], obb.max[2])
    input_vertex(obb.min[0], obb.max[1], obb.max[2])

    input_vertex(obb.min[0], obb.max[1], obb.max[2])
    input_vertex(*obb.max)

    input_vertex(obb.max[0], obb.max[1], obb.max[2])
    input_vertex(obb.max[0], obb.max[1], obb.min[2])

    input_vertex(obb.max[0], obb.min[1], obb.max[2])
    input_vertex(obb.max[0], obb.min[1], obb.min[2])

    input_vertex(obb.min[0], obb.max[1], obb.max[2])
    input_vertex(obb.min[0], obb.max[1], obb.min[2])

    input_vertex(obb.min[0], obb.min[1], obb.max[2])
    input_vertex(obb.min[0], obb.min[1], obb.min[2])

    input_vertex(obb.max[0], obb.max[1], obb.min[2])
    input_vertex(obb.max[0], obb.min[1], obb.min[2])

    input_vertex(obb.max[0], obb.min[1], obb.min[2])
    input_vertex(*obb.min)

    input_vertex(*obb.min)
    input_vertex(obb.min[0], obb.max[1], obb.min[2])

    input_vertex(obb.min[0], obb.max[1], obb.min[2])
    input_vertex(obb.max[0], obb.max[1], obb.min[2])

    glEnd()
    glEndList()

    return gl_list
Пример #32
0
 def use_color(color):
     if use_apply_material:
         # This makes the colors visible even when lighting is enabled.
         apply_material(color)
     else:
         # Old code did this. These colors are only visible when lighting is
         # not enabled.
         glColor3fv(color)
         pass
     return
Пример #33
0
 def paintCells(self):
     size = 0.0855 * self.cl / 3.
     for i, p in enumerate(self.positions):
         color = (1., 0., 0.) if i == self.activeCell else (0., 0., 1.)
         glColor3fv(color)
         glPushMatrix()
         offs = np.array([p[0], p[2], p[1]]) / 35. + self.offsets
         glTranslatef(*offs.tolist())
         glutSolidCube(size)
         glPopMatrix()
Пример #34
0
 def use_color(color):
     if use_apply_material:
         # This makes the colors visible even when lighting is enabled.
         apply_material(color)
     else:
         # Old code did this. These colors are only visible when lighting is
         # not enabled.
         glColor3fv(color)
         pass
     return
Пример #35
0
 def __call__(self):
     """Display figure on screen."""
     glBegin(self.mode)
     for element in self.operation():
         for vertex in element:
             color = choice(self.color) if all(
                 [isinstance(x, tuple) for x in self.color]
             ) else self.color
             glColor3fv(color)
             glVertex3fv(self.vertices[vertex])
     glEnd()
Пример #36
0
def drawtriangle_strip_worker(params):
    """
    Draw a triangle strip using a list of triangle vertices
    and (optional) normals.
    """
    # Note: See the code in class ColorSorter for GL_COLOR_MATERIAL objects.

    # piotr 080904 - This method could be optimized by using vertex
    # arrays or VBOs.

    (triangles, normals, colors) = params

    # It needs to support two-sided triangles, therefore we disable
    # culling and enable two-sided lighting. These settings have to be
    # turned back to default setting.

    glDisable(GL_CULL_FACE)
    glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE)

    # Use color material mode if colors are present.

    if colors:
        glEnable(GL_COLOR_MATERIAL)

    glBegin(GL_TRIANGLE_STRIP)
    if normals:
        if colors:
            for p in range(len(triangles)):
                n = normals[p]
                v = triangles[p]
                c = colors[p]
                glNormal3fv(n)
                glColor3fv(c[:3])
                glVertex3fv(v)
        else:
            for p in range(len(triangles)):
                n = normals[p]
                v = triangles[p]
                glNormal3fv(n)
                glVertex3fv(v)
    else:
        for v in triangles:
            glVertex3fv(v)
    glEnd()

    if colors:
        glDisable(GL_COLOR_MATERIAL)

    # piotr 080904 - are these settings really default?

    glEnable(GL_CULL_FACE)
    glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE)

    return
Пример #37
0
def drawtriangle_strip_worker(params):
    """ 
    Draw a triangle strip using a list of triangle vertices
    and (optional) normals.
    """
    # Note: See the code in class ColorSorter for GL_COLOR_MATERIAL objects.
    
    # piotr 080904 - This method could be optimized by using vertex
    # arrays or VBOs.
    
    (triangles, normals, colors) = params

    # It needs to support two-sided triangles, therefore we disable
    # culling and enable two-sided lighting. These settings have to be 
    # turned back to default setting.
    
    glDisable(GL_CULL_FACE)
    glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE)

    # Use color material mode if colors are present.
    
    if colors:
        glEnable(GL_COLOR_MATERIAL)

    glBegin(GL_TRIANGLE_STRIP)
    if normals:
        if colors:
            for p in range(len(triangles)):
                n = normals[p]
                v = triangles[p]
                c = colors[p]
                glNormal3fv(n)
                glColor3fv(c[:3])
                glVertex3fv(v)
        else:
            for p in range(len(triangles)):
                n = normals[p]
                v = triangles[p]
                glNormal3fv(n)
                glVertex3fv(v)
    else:
        for v in triangles:
            glVertex3fv(v)
    glEnd()

    if colors:
        glDisable(GL_COLOR_MATERIAL)

    # piotr 080904 - are these settings really default?

    glEnable(GL_CULL_FACE)
    glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE)

    return
Пример #38
0
 def draw(self):
     glDisable(GL_LIGHTING) # note: the colors here don't work without this
     glBegin(GL_QUADS)
     for face in faces:
         face_normal = facenormal(face)
         for vert in faceverts(face):
             color = (fix(vert[0]), fix(vert[1]), fix(vert[2]))
             glColor3fv(color)
             glNormal3fv(face_normal)
             glVertex3fv(vert)
     glEnd()
     glEnable(GL_LIGHTING)
Пример #39
0
 def draw(self):
     glDisable(GL_LIGHTING)  # note: the colors here don't work without this
     glBegin(GL_QUADS)
     for face in faces:
         face_normal = facenormal(face)
         for vert in faceverts(face):
             color = (fix(vert[0]), fix(vert[1]), fix(vert[2]))
             glColor3fv(color)
             glNormal3fv(face_normal)
             glVertex3fv(vert)
     glEnd()
     glEnable(GL_LIGHTING)
Пример #40
0
    def schedule(color, func, params): # staticmethod
        if ColorSorter.sorting:

            ColorSorter._add_to_sorter(color, func, params)

        else:

            ColorSorter._immediate += 1 # for benchmark/debug stats, mostly

            # 20060216 We know we can do this here because the stack is
            # only ever one element deep
            name = ColorSorter._gl_name_stack[-1]
            if name:
                glPushName(name)
            ## Don't check in immediate drawing, e.g. preDraw_glselect_dict.
            ## else:
            ##   print "bug_1: attempt to push non-glname", name

            #Apply appropriate opacity for the object if it is specified
            #in the 'color' param. (Also do necessary things such as
            #call glBlendFunc it. -- Ninad 20071009

            if len(color) == 4:
                opacity = color[3]
            else:
                opacity = 1.0

            if opacity >= 0.0 and opacity != 1.0:
                glDepthMask(GL_FALSE)
                glEnable(GL_BLEND)
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            elif opacity == -1:
                # piotr 080429: I replaced the " < 0" condition with " == -1"
                # The opacity flag is now used to signal either "unshaded
                # colors" (opacity == -1) or "multicolor object" (opacity == -2)
                glDisable(GL_LIGHTING)          # Don't forget to re-enable it!
                glColor3fv(color[:3])
                pass

            apply_material(color)
            func(params)                # Call the draw worker function.

            if opacity > 0.0 and opacity != 1.0:
                glDisable(GL_BLEND)
                glDepthMask(GL_TRUE)
            elif opacity == -1:
                # piotr 080429: See my comment above.
                glEnable(GL_LIGHTING)

            if name:
                glPopName()
        return
Пример #41
0
    def schedule(color, func, params):  # staticmethod
        if ColorSorter.sorting:

            ColorSorter._add_to_sorter(color, func, params)

        else:

            ColorSorter._immediate += 1  # for benchmark/debug stats, mostly

            # 20060216 We know we can do this here because the stack is
            # only ever one element deep
            name = ColorSorter._gl_name_stack[-1]
            if name:
                glPushName(name)
            ## Don't check in immediate drawing, e.g. preDraw_glselect_dict.
            ## else:
            ##   print "bug_1: attempt to push non-glname", name

            #Apply appropriate opacity for the object if it is specified
            #in the 'color' param. (Also do necessary things such as
            #call glBlendFunc it. -- Ninad 20071009

            if len(color) == 4:
                opacity = color[3]
            else:
                opacity = 1.0

            if opacity >= 0.0 and opacity != 1.0:
                glDepthMask(GL_FALSE)
                glEnable(GL_BLEND)
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            elif opacity == -1:
                # piotr 080429: I replaced the " < 0" condition with " == -1"
                # The opacity flag is now used to signal either "unshaded
                # colors" (opacity == -1) or "multicolor object" (opacity == -2)
                glDisable(GL_LIGHTING)  # Don't forget to re-enable it!
                glColor3fv(color[:3])
                pass

            apply_material(color)
            func(params)  # Call the draw worker function.

            if opacity > 0.0 and opacity != 1.0:
                glDisable(GL_BLEND)
                glDepthMask(GL_TRUE)
            elif opacity == -1:
                # piotr 080429: See my comment above.
                glEnable(GL_LIGHTING)

            if name:
                glPopName()
        return
Пример #42
0
def drawPolyLine(color, points):
    """
    Draws a poly line passing through the given list of points
    """
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glBegin(GL_LINE_STRIP)
    for v in points:
        glVertex3fv(v)
    glEnd()

    glEnable(GL_LIGHTING)
    return
Пример #43
0
def drawLineLoop(color, lines, width=1):
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glLineWidth(width)
    glBegin(GL_LINE_LOOP)
    for v in lines:
        glVertex3fv(v)
    glEnd()
    glEnable(GL_LIGHTING)
    #reset the glLineWidth to 1
    if width != 1:
        glLineWidth(1)
    return
Пример #44
0
def drawLineLoop(color,lines, width = 1):
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glLineWidth(width)
    glBegin(GL_LINE_LOOP)
    for v in lines:
        glVertex3fv(v)
    glEnd()
    glEnable(GL_LIGHTING)  
    #reset the glLineWidth to 1
    if width!=1:
        glLineWidth(1)
    return
Пример #45
0
    def gl_draw(self):
        glEnable(GL_DEPTH_TEST)
        glTranslatef(0, 0, -10)
        glRotatef(self.arot[0], 1, 0, 0)
        glRotatef(self.arot[1], 0, 1, 0)
        glRotatef(self.arot[2], 0, 0, 1)
        glBegin(GL_QUADS)

        for aColor, face in zip(cube_colors, cube_faces):
            glColor3fv(aColor)
            for i in face:
                glVertex3fv(cube_pts[i])
        glEnd()
Пример #46
0
def drawPolyLine(color, points):
    """
    Draws a poly line passing through the given list of points
    """
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glBegin(GL_LINE_STRIP)
    for v in points:
        glVertex3fv(v)
    glEnd()

    glEnable(GL_LIGHTING)
    return
Пример #47
0
def drawFullWindow(vtColors):
    """
    Draw gradient background color.

    <vtColors> is a 4 element list specifying colors for the
       left-down, right-down, right-up, left-up window corners.

    To draw the full window, the modelview and projection should be set in
    identity.
    """
    from utilities.constants import GL_FAR_Z
    glDisable(GL_LIGHTING)

    glBegin(GL_QUADS)
    glColor3fv(vtColors[0])
    glVertex3f(-1, -1, GL_FAR_Z)
    glColor3fv(vtColors[1])
    glVertex3f(1, -1, GL_FAR_Z)
    glColor3fv(vtColors[2])
    glVertex3f(1, 1, GL_FAR_Z)
    glColor3fv(vtColors[3])
    glVertex3f(-1, 1, GL_FAR_Z)
    glEnd()

    glEnable(GL_LIGHTING)
    return
Пример #48
0
def drawFullWindow(vtColors):
    """
    Draw gradient background color.

    <vtColors> is a 4 element list specifying colors for the  
       left-down, right-down, right-up, left-up window corners.

    To draw the full window, the modelview and projection should be set in
    identity.
    """
    from utilities.constants import GL_FAR_Z
    glDisable(GL_LIGHTING)

    glBegin(GL_QUADS)
    glColor3fv(vtColors[0])
    glVertex3f(-1, -1, GL_FAR_Z)
    glColor3fv(vtColors[1])            
    glVertex3f(1, -1, GL_FAR_Z)
    glColor3fv(vtColors[2])
    glVertex3f(1, 1, GL_FAR_Z)
    glColor3fv(vtColors[3])
    glVertex3f(-1, 1, GL_FAR_Z)
    glEnd()

    glEnable(GL_LIGHTING)
    return
Пример #49
0
def drawtriangle_strip_worker(params):
    """ 
    Draw a triangle strip using a list of triangle vertices
    and (optional) normals.
    """
    (triangles, normals, colors) = params

    #glEnable(GL_LIGHTING)

    glDisable(GL_CULL_FACE)
    glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE)

    if colors:
        glEnable(GL_COLOR_MATERIAL)

    #glPolygonMode(GL_FRONT, GL_FILL)
    #glPolygonMode(GL_BACK, GL_FILL)
    # glPolygonOffset(0.0, 10.0)    

    glBegin(GL_TRIANGLE_STRIP)
    if normals:
        if colors:
            for p in range(len(triangles)):
                n = normals[p]
                v = triangles[p]
                c = colors[p]
                glNormal3fv(n)
                glColor3fv(c[:3])
                glVertex3fv(v)
        else:
            for p in range(len(triangles)):
                n = normals[p]
                v = triangles[p]
                glNormal3fv(n)
                glVertex3fv(v)
    else:
        for v in triangles:
            glVertex3fv(v)
    glEnd()

    if colors:
        glDisable(GL_COLOR_MATERIAL)

    glEnable(GL_CULL_FACE)
    glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE)

    return
Пример #50
0
def drawwirebox(color, pos, len):
    glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_BACK, GL_LINE)
    glDisable(GL_LIGHTING)
    glDisable(GL_CULL_FACE)
    glColor3fv(color)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], pos[2])
    glScale(len[0], len[1], len[2])
    glCallList(drawing_globals.CubeList)
    glPopMatrix()
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPolygonMode(GL_FRONT, GL_FILL)
    #bruce 050729 to help fix bug 835 or related bugs
    glPolygonMode(GL_BACK, GL_FILL)
    return
Пример #51
0
def drawaxes(scale, point, color = black, coloraxes = False, dashEnabled = False):
    """
    Draw axes.

    @note: used for both origin axes and point of view axes.

    @see: drawOriginAsSmallAxis (related code)
    """
    n = scale
    glPushMatrix()
    glTranslate(point[0], point[1], point[2])
    glDisable(GL_LIGHTING)
    
    if dashEnabled:
        #ninad060921 Note that we will only support dotted origin axis 
        #(hidden lines) but not POV axis. (as it could be annoying)
        glLineStipple(5, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)
        glDisable(GL_DEPTH_TEST)
    
    glColor3fv(color)
    
    if coloraxes: 
        glColor3fv(red)
        
    glBegin(GL_LINES)
    glVertex( n, 0, 0)
    glVertex(-n, 0, 0)
    
    if coloraxes: 
        glColor3fv(darkgreen)
        
    glVertex(0,  n, 0)
    glVertex(0, -n, 0)
    
    if coloraxes: 
        glColor3fv(blue)
        
    glVertex(0, 0,  n)
    glVertex(0, 0, -n)
    
    glEnd()

    if dashEnabled:
        glDisable(GL_LINE_STIPPLE)
        glEnable(GL_DEPTH_TEST)

    glEnable(GL_LIGHTING)
    glPopMatrix()
    return
Пример #52
0
def drawwirecube(color, pos, radius, lineWidth=3.0):
    glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_BACK, GL_LINE)
    glDisable(GL_LIGHTING)
    glDisable(GL_CULL_FACE)
    glColor3fv(color)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], pos[2])
    if type(radius) == type(1.0):
        glScale(radius,radius,radius)
    else: 
        glScale(radius[0], radius[1], radius[2])
    glLineWidth(lineWidth)
    glCallList(drawing_globals.lineCubeList)
    glLineWidth(1.0) ## restore its state
    glPopMatrix()
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPolygonMode(GL_FRONT, GL_FILL)
    #bruce 050729 to help fix bug 835 or related bugs
    glPolygonMode(GL_BACK, GL_FILL)
    return
Пример #53
0
def drawAxis(color, pos1, pos2, width = 2): #Ninad 060907
    """
    Draw chunk or jig axis
    """
    #ninad060907 Note that this is different than draw 
    # I may need this function to draw axis line. see its current implementation
    # in branch "ninad_060908_drawAxis_notAsAPropOfObject"
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glLineStipple(3, 0x1C47) # dash-dot-dash line
    glEnable(GL_LINE_STIPPLE)
    if width != 1:
        glLineWidth(width)
    glBegin(GL_LINES)
    glVertex(pos1[0], pos1[1], pos1[2])
    glVertex(pos2[0], pos2[1], pos2[2])
    glEnd()
    if width != 1:
        glLineWidth(1.0) # restore default state
    glDisable(GL_LINE_STIPPLE)
    glEnable(GL_LIGHTING)
    return
Пример #54
0
    def _draw_sorted(sorted_by_color):   #russ 080320: factored out of finish().
        """
        Traverse color-sorted lists, invoking worker procedures.
        """
        ### REVIEW: still needed? does this have some duplicated code with
        # parent_csdl.finish? If so, has this been maintained as that's been
        # modified? [bruce 090224 questions]

        glEnable(GL_LIGHTING)

        for color, funcs in sorted_by_color.iteritems():

            opacity = color[3]
            if opacity == -1:
                #piotr 080429: Opacity == -1 signals the "unshaded color".
                # Also, see my comment in "schedule".
                glDisable(GL_LIGHTING) # reenabled below
                glColor3fv(color[:3])
            else:
                apply_material(color)
                pass

            for func, params, name in funcs:
                if name:
                    glPushName(name)
                else:
                    pass ## print "bug_4: attempt to push non-glname", name
                func(params)            # Call the draw worker function.
                if name:
                    glPopName()
                    pass
                continue

            if opacity == -1:
                glEnable(GL_LIGHTING)

            continue
        return
Пример #55
0
def draw_filled_rect_frame(origin, dx, dy, thickness, color):
    """
    draw something that looks like a picture frame of a single filled color.
    """
    tx = thickness * norm(dx)
    ty = thickness * norm(dy)
    ## glColor3fv(color) ### this has an exception (wants 3 elts, gets 4) in Mac A9.1-rc1
    # (i.e. in the Mac "Gold" PyOpenGL for A9.1), so instead, do the following: [bruce 070703]
    glColor3fv(color[:3])
    glDisable(GL_LIGHTING)
    glBegin(GL_QUAD_STRIP)
    glVertex3fv(origin)
    glVertex3fv(origin + tx + ty)
    glVertex3fv(origin + dx)
    glVertex3fv(origin + dx - tx + ty)
    glVertex3fv(origin + dx + dy)
    glVertex3fv(origin + dx + dy - tx - ty)
    glVertex3fv(origin + dy)
    glVertex3fv(origin + dy + tx - ty)
    glVertex3fv(origin)
    glVertex3fv(origin + tx + ty)
    glEnd()
    glEnable(GL_LIGHTING)
Пример #56
0
def drawLineCube(color, pos, radius):
    vtIndices = [0,1,2,3, 0,4,5,1, 5,4,7,6, 6,7,3,2]
    glEnableClientState(GL_VERTEX_ARRAY)
    #bruce 051117 revised this
    glVertexPointer(3, GL_FLOAT, 0, drawing_globals.flatCubeVertices)
        #grantham 20051213 observations, reported/paraphrased by bruce 051215:
        # - should verify PyOpenGL turns Python float (i.e. C double) into C
        #     float for OpenGL's GL_FLOAT array element type.
        # - note that GPUs are optimized for DrawElements types GL_UNSIGNED_INT
        #     and GL_UNSIGNED_SHORT.
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], pos[2])
    glScale(radius,radius,radius)
    glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_BYTE, vtIndices)
    #glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_BYTE, vtIndices[4])
    #glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_BYTE, vtIndices[8])
    #glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_BYTE, vtIndices[12])
    glPopMatrix()
    glEnable(GL_LIGHTING)
    glDisableClientState(GL_VERTEX_ARRAY)
    return    
Пример #57
0
def drawSiCGrid(color, line_type, w, h, up, right):
    """
    Draw SiC grid.
    """
    
    if line_type == NO_LINE:
        return
    
    XLen = sic_uLen * 3.0
    YLen = sic_yU * 2.0
    hw = w/2.0; hh = h/2.0
    i1 = int(floor(-hw/XLen))
    i2 = int(ceil(hw/XLen))
    j1 = int(floor(-hh/YLen))
    j2 = int(ceil(hh/YLen))
    
    glDisable(GL_LIGHTING)
    glColor3fv(color)

    if line_type > 1:
        glEnable(GL_LINE_STIPPLE)
        if line_type == DASHED_LINE:
            glLineStipple (1, 0x00FF)  #  dashed
        elif line_type == DOTTED_LINE:
            glLineStipple (1, 0x0101)  #  dotted
        else:
            print "drawer.drawSiCGrid(): line_type '", line_type, \
                  "' is not valid.  Drawing dashed grid line."
            glLineStipple (1, 0x00FF)  #  dashed
    
    glClipPlane(GL_CLIP_PLANE0, (1.0, 0.0, 0.0, hw))
    glClipPlane(GL_CLIP_PLANE1, (-1.0, 0.0, 0.0, hw))
    glClipPlane(GL_CLIP_PLANE2, (0.0, 1.0, 0.0, hh))
    glClipPlane(GL_CLIP_PLANE3, (0.0, -1.0, 0.0, hh))
    glEnable(GL_CLIP_PLANE0)
    glEnable(GL_CLIP_PLANE1)
    glEnable(GL_CLIP_PLANE2)
    glEnable(GL_CLIP_PLANE3)
     
    glPushMatrix()
    glTranslate(i1*XLen,  j1*YLen, 0.0)
    for i in range(i1, i2):
        glPushMatrix()
        for j in range(j1, j2):
            glCallList(SiCGridList)
            glTranslate(0.0, YLen, 0.0)
        glPopMatrix()
        glTranslate(XLen, 0.0, 0.0)
    glPopMatrix()
    
    glDisable(GL_CLIP_PLANE0)
    glDisable(GL_CLIP_PLANE1)
    glDisable(GL_CLIP_PLANE2)
    glDisable(GL_CLIP_PLANE3)
        
    if line_type > 1:
        glDisable (GL_LINE_STIPPLE)

    xpos, ypos = hw, 0.0
    f3d = Font3D(xpos=xpos, ypos=ypos, right=right, up=up,
                 rot90=False, glBegin=False)
    for j in range(j1, j2):
        yoff = j * YLen
        if -hh < yoff + ypos < hh:
            f3d.drawString("%-.4g" % yoff, color=color, yoff=yoff)

    xpos, ypos = 0.0, hh
    f3d = Font3D(xpos=xpos, ypos=ypos, right=right, up=up,
                 rot90=True, glBegin=False)
    for i in range(2*i1, 2*i2):
        yoff = i * (XLen/2)
        if -hw < yoff + xpos < hw:
            f3d.drawString("%-.4g" % yoff, color=color, yoff=yoff)
    
    glEnable(GL_LIGHTING)
    return
Пример #58
0
def drawGPGridForPlane(glpane, color, line_type, w, h, uw, uh, up, right, 
                       displayLabels, originLocation, labelsDisplayStyle):
    """
    Draw grid lines for a Grid from Plane PM.
    
    glpane = the glpane
    color = grid line and unit text color
    line_type is: 0=None, 1=Solid, 2=Dashed, or 3=Dotted
    w = width
    h = height
    uw = width spacing between grid lines
    uh = height spacing between grid lines
    """
    
    if line_type == NO_LINE:
        return

    if uw > w: uw = w
    if uh > h: uh = h

    Z_OFF = 0.0 #0.001
    
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    
    hw = w/2.0; hh = h/2.0

    if line_type > 1:
        glEnable(GL_LINE_STIPPLE)
        if line_type == DASHED_LINE:
            glLineStipple (1, 0x00FF)  #  dashed
        elif line_type == DOTTED_LINE:
            glLineStipple (1, 0x0101)  #  dotted
        else:
            print "drawGPGrid(): line_type '", line_type,"' is not valid. ", \
                  "Drawing dashed grid line."
            glLineStipple (1, 0x00FF)  #  dashed
    
    glBegin(GL_LINES)

    #Draw horizontal lines
    y1 = 0
    while y1 > -hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 -= uh

    y1 = 0
    while y1 < hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 += uh

    #Draw vertical lines
    x1 = 0
    while x1 < hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 += uw

    x1 = 0
    while x1 > -hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 -= uw

    glEnd()

    if line_type > 1:
        glDisable (GL_LINE_STIPPLE)
    
    # Draw unit labels for gridlines (in nm).
    text_color = color
    
    import sys
    if sys.platform == "darwin":
        # WARNING: Anything smaller than 9 pt on Mac OS X results in 
        # un-rendered text. Not sure why. -- piotr 080616
        font_size = 9
    else:
        font_size = 8
        
    text_offset = 0.3 # Offset from edge of border, in Angstroms.
    
    if displayLabels == True:
        if (originLocation == PLANE_ORIGIN_LOWER_LEFT and
            labelsDisplayStyle == LABELS_ALONG_ORIGIN):
            displayLabelsAlongOriginLowerLeft(h, w, hh, hw, uh, uw,
                text_offset, text_color, font_size, glpane)
        elif (originLocation == PLANE_ORIGIN_UPPER_LEFT and
              labelsDisplayStyle == LABELS_ALONG_ORIGIN):
            displayLabelsAlongOriginUpperLeft(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)
        elif (originLocation == PLANE_ORIGIN_UPPER_RIGHT and
              labelsDisplayStyle == LABELS_ALONG_ORIGIN):
            displayLabelsAlongOriginUpperRight(h, w, hh, hw, uh, uw, 
                text_offset, text_color,font_size, glpane)  
        elif (originLocation == PLANE_ORIGIN_LOWER_RIGHT and
              labelsDisplayStyle == LABELS_ALONG_ORIGIN):
            displayLabelsAlongOriginLowerRight(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)  
        elif (originLocation == PLANE_ORIGIN_LOWER_LEFT and
              labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES):
            displayLabelsAlongPlaneEdgesLowerLeft(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)
        elif (originLocation == PLANE_ORIGIN_UPPER_LEFT and
              labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES):
            displayLabelsAlongPlaneEdgesUpperLeft(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)  
        elif (originLocation == PLANE_ORIGIN_UPPER_RIGHT and
              labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES):
            displayLabelsAlongPlaneEdgesUpperRight(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)  
        elif (originLocation == PLANE_ORIGIN_LOWER_RIGHT and
              labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES):
            displayLabelsAlongPlaneEdgesLowerRight(h, w, hh, hw, uh, uw, 
                text_offset, text_color, font_size, glpane)  
        
    glEnable(GL_LIGHTING)
    return
Пример #59
0
def drawGPGrid(glpane, color, line_type, w, h, uw, uh, up, right):
    """
    Draw grid lines for a Grid Plane.
    
    glpane = the glpane
    color = grid line and unit text color
    line_type is: 0=None, 1=Solid, 2=Dashed or 3=Dotted
    w = width
    h = height
    uw = width spacing between grid lines
    uh = height spacing between grid lines
    """
    
    if line_type == NO_LINE:
        return

    if uw > w: uw = w
    if uh > h: uh = h

    Z_OFF = 0.0 #0.001
    
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    
    hw = w/2.0; hh = h/2.0

    #glEnable(GL_LINE_SMOOTH)
    #glEnable(GL_BLEND)
    #glBlendFunc(GL_SRC_ALPHA, GL_ONE)#_MINUS_SRC_ALPHA)
    
    if line_type > 1:
        glEnable(GL_LINE_STIPPLE)
        if line_type == DASHED_LINE:
            glLineStipple (1, 0x00FF)  #  dashed
        elif line_type == DOTTED_LINE:
            glLineStipple (1, 0x0101)  #  dotted
        else:
            print "drawGPGrid(): line_type '", line_type, \
                  "' is not valid.  Drawing dashed grid line."
            glLineStipple (1, 0x00FF)  #  dashed
    
    glBegin(GL_LINES)

    #Draw horizontal lines
    y1 = 0
    while y1 > -hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 -= uh

    y1 = 0
    while y1 < hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 += uh

    #Draw vertical lines
    x1 = 0
    while x1 < hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 += uw

    x1 = 0
    while x1 > -hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 -= uw

    glEnd()

    if line_type > 1:
        glDisable (GL_LINE_STIPPLE)
    
    # Draw unit labels for gridlines (in nm).
    text_color = color
    
    import sys
    if sys.platform == "darwin":
        # WARNING: Anything smaller than 9 pt on Mac OS X results in 
        # un-rendered text. Not sure why. -- piotr 080616
        font_size = 9
    else:
        font_size = 8
        
    text_offset = 0.5 # Offset from edge of border, in Angstroms.
    
    
    # Draw unit text labels for horizontal lines (nm)
    y1 = 0
    while y1 > -hh:
        y1 -= uh
        drawtext("%g" % (-y1 / 10.0), text_color,
                 V(hw + text_offset, y1, 0.0), font_size, glpane)
    drawtext("%g" % (-y1 / 10.0), text_color,
             V(hw + text_offset, y1, 0.0), font_size, glpane)

    y1 = 0
    while y1 < hh:
        drawtext("%g" % (-y1 / 10.0), text_color,
                 V(hw + text_offset, y1, 0.0), font_size, glpane)
        y1 += uh
    drawtext("%g" % (-y1 / 10.0), text_color,
             V(hw + text_offset, y1, 0.0), font_size, glpane)

    # Draw unit text labels for vertical lines (nm).
    x1 = 0
    while x1 < hw:
        drawtext("%g" % (x1 / 10.0), text_color,
                 V(x1, hh + text_offset, 0.0), font_size, glpane)
        x1 += uw
    drawtext("%g" % (x1 / 10.0), text_color,
             V(x1, hh + text_offset, 0.0), font_size, glpane)

    x1 = 0
    while x1 > -hw:
        drawtext("%g" % (x1 / 10.0), text_color,
                 V(x1, hh + text_offset, 0.0), font_size, glpane)
        x1 -= uw
    drawtext("%g" % (x1 / 10.0), text_color,
             V(x1, hh + text_offset, 0.0), font_size, glpane)
    
    glEnable(GL_LIGHTING)
    return
Пример #60
0
    def draw(self):
        """
        Draws the rulers.
        """

        width = self.glpane.width
        height = self.glpane.height

        # These 3 attrs (scale, aspect, and ruler_position) are checked to
        # determine if they've changed. If any of them have,
        # getRulerDrawingParameters() must be called to get new drawing parms.
        if (
            (self.scale != self.glpane.scale)
            or (self.zoomFactor != self.glpane.zoomFactor)
            or (self.aspect != self.glpane.aspect)
            or (self.ruler_position != env.prefs[rulerPosition_prefs_key])
        ):

            self.scale = self.glpane.scale
            self.zoomFactor = self.glpane.zoomFactor
            self.aspect = self.glpane.aspect
            self.ruler_position = env.prefs[rulerPosition_prefs_key]

            self.ruler_drawing_params = getRulerDrawingParameters(
                width, height, self.aspect, self.scale, self.zoomFactor, self.ruler_position
            )

        (
            draw_ticks_and_text,
            units_text,
            units_format,
            units_scale,
            unit_label_inc,
            long_tickmark_inc,
            medium_tickmark_inc,
            num_vert_ticks,
            num_horz_ticks,
            tickmark_spacing_multiplier,
            ruler_origin,
            ruler_start_pt,
            units_text_origin,
            origin_square_pt1,
            origin_square_pt2,
            vr_thickness,
            vr_tickmark_spacing,
            vr_long_tick_len,
            vr_medium_tick_len,
            vr_short_tick_len,
            vr_rect_pt1,
            vr_rect_pt2,
            vr_line_pt1,
            vr_line_pt2,
            vr_units_x_offset,
            vr_units_y_offset,
            hr_thickness,
            hr_tickmark_spacing,
            hr_long_tick_len,
            hr_medium_tick_len,
            hr_short_tick_len,
            hr_rect_pt1,
            hr_rect_pt2,
            hr_line_pt1,
            hr_line_pt2,
            hr_units_x_offset,
            hr_units_y_offset,
        ) = self.ruler_drawing_params

        ruler_color = env.prefs[rulerColor_prefs_key]
        ruler_opacity = env.prefs[rulerOpacity_prefs_key]

        # These may become user preferences in the future.
        tickmark_color = darkgray
        text_color = black

        # Set up 2D (window) coordinate system.
        # Bruce - please review this section.
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()  # needed!
        gluOrtho2D(0.0, float(width), 0.0, float(height))
        glMatrixMode(GL_MODELVIEW)
        # About this glMatrixMode(GL_MODELVIEW) call, Bruce wrote in a review:
        # The only reason this is desirable (it's not really needed) is if,
        # when someone is editing the large body of drawing code after this,
        # they inadvertently do something which is only correct if the matrix
        # mode is GL_MODELVIEW (e.g. if they use glTranslate to shift a ruler
        # or tickmark position). Most of our drawing code assumes it can do
        # this, so a typical NE1 OpenGL programmer may naturally assume this,
        # which is why it's good to leave the matrix mode as GL_MODELVIEW when
        # entering into a large hunk of ordinary drawing code (especially if
        # it might call other drawing functions, now or in the future).
        # Mark 2008-03-03

        glDisable(GL_LIGHTING)
        glDisable(GL_DEPTH_TEST)
        # Note: disabling GL_DEPTH_TEST is not honored by the 3d version of
        # glpane.renderText -- ruler text can still be obscured by
        # previously drawn less-deep model objects.
        # But the 2d call of renderText in part.py does honor this.
        # The Qt doc says why, if I guess how to interpret it:
        #   http://doc.trolltech.com/4.3/qglwidget.html#renderText
        # says, for the 3d version of renderText only (passing three model
        # coords as opposed to two window coords):
        #   Note that this function only works properly if GL_DEPTH_TEST
        #   is enabled, and you have a properly initialized depth buffer.
        # Possible fixes:
        # - revise ruler_origin to be very close to the screen,
        #   and hope that this disable is merely ignored, not a messup;
        # - or, use the 2d version of the function.
        # I did the latter fix (2d renderText, below) and it seems to work.
        # [bruce 081204 comment]

        # Suppress writing into the depth buffer so anything behind the ruler
        # can still be highlighted/selected.
        glDepthMask(GL_FALSE)

        # == Draw v/h ruler rectangles in the user defined color and opacity.

        glColor4fv(list(ruler_color) + [ruler_opacity])
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glRectf(origin_square_pt1[0], origin_square_pt1[1], origin_square_pt2[0], origin_square_pt2[1])  # Origin square
        if env.prefs[displayVertRuler_prefs_key]:
            glRectf(vr_rect_pt1[0], vr_rect_pt1[1], vr_rect_pt2[0], vr_rect_pt2[1])  # Vertical ruler
        if env.prefs[displayHorzRuler_prefs_key]:
            glRectf(hr_rect_pt1[0], hr_rect_pt1[1], hr_rect_pt2[0], hr_rect_pt2[1])  # Horizontal ruler

        glDisable(GL_BLEND)

        # Set color of ruler lines, tick marks and text.
        glColor3fv(tickmark_color)
        self.glpane.qglColor(RGBf_to_QColor(text_color))

        # Draw unit of measurement in corner (A or nm).
        # piotr 080326: replaced drawText with drawCenteredText
        self.drawCenteredText(units_text, units_text_origin)

        # Kludge alert. Finish drawing ruler edge(s) if we will not be
        # drawing the ruler tick marks and text (only happens when the user
        # is zoomed out to an "absurd scale factor").
        if not draw_ticks_and_text:
            if env.prefs[displayVertRuler_prefs_key]:
                self.drawLine(vr_line_pt1, vr_line_pt2)
            if env.prefs[displayHorzRuler_prefs_key]:
                self.drawLine(hr_line_pt1, hr_line_pt2)

        # == Draw vertical ruler line(s) and tick marks

        if env.prefs[displayVertRuler_prefs_key] and draw_ticks_and_text:

            # Draw vertical line along right/left edge of ruler.
            self.drawLine(vr_line_pt1, vr_line_pt2)

            # Initialize pt1 and pt2, the tick mark endpoints. The first tick
            # mark will span the entire width of the ruler,  which serves as a
            # divider b/w the unit of measure text (i.e. A or nm) and the rest
            # of the ruler.
            pt1 = ruler_start_pt
            pt2 = ruler_start_pt + V(-vr_thickness, 0.0, 0.0)

            # Draw vertical ruler tickmarks, including numeric unit labels
            for tick_num in range(num_horz_ticks + 1):

                # pt1 and pt2 are modified by each iteration of the loop.
                self.drawLine(pt1, pt2)

                # Draw units number beside long tickmarks.
                if not tick_num % unit_label_inc:
                    units_num_origin = pt1 + V(vr_units_x_offset, vr_units_y_offset, 0.0)
                    units_num = units_format % (tick_num * units_scale)
                    self.drawText(units_num, units_num_origin)

                # Update tickmark endpoints for next tickmark.
                pt1 = ruler_start_pt + V(0.0, vr_tickmark_spacing * tickmark_spacing_multiplier * (tick_num + 1), 0.0)

                if not (tick_num + 1) % long_tickmark_inc:
                    pt2 = pt1 + V(vr_long_tick_len, 0.0, 0.0)
                elif not (tick_num + 1) % medium_tickmark_inc:
                    pt2 = pt1 + V(vr_medium_tick_len, 0.0, 0.0)
                else:
                    pt2 = pt1 + V(vr_short_tick_len, 0.0, 0.0)

            # End vertical ruler

        # == Draw horizontal ruler line(s) and tick marks

        if env.prefs[displayHorzRuler_prefs_key] and draw_ticks_and_text:
            # Draw horizontal line along top/bottom edge of ruler.
            self.drawLine(hr_line_pt1, hr_line_pt2)

            # Initialize pt1 and pt2, the tick mark endpoints. The first tick
            # mark will span the entire width of the ruler,  which serves as a
            # divider b/w the unit of measure text (i.e. A or nm) and the rest
            # of the ruler.
            pt1 = ruler_start_pt
            pt2 = ruler_start_pt + V(0.0, -hr_thickness, 0.0)

            # Draw horizontal ruler (with vertical) tickmarks, including its
            # numeric unit labels
            for tick_num in range(num_vert_ticks + 1):

                # pt1 and pt2 are modified by each iteration of the loop.
                self.drawLine(pt1, pt2)

                # Draw units number beside long tickmarks.
                if not tick_num % unit_label_inc:
                    units_num_origin = pt1 + V(hr_units_x_offset, hr_units_y_offset, 0.0)
                    units_num = units_format % (tick_num * units_scale)
                    self.drawText(units_num, units_num_origin)

                # Update tickmark endpoints for next tickmark.
                pt1 = ruler_start_pt + V(hr_tickmark_spacing * tickmark_spacing_multiplier * (tick_num + 1), 0.0, 0.0)

                if not (tick_num + 1) % long_tickmark_inc:
                    pt2 = pt1 + V(0.0, hr_long_tick_len, 0.0)
                elif not (tick_num + 1) % medium_tickmark_inc:
                    pt2 = pt1 + V(0.0, hr_medium_tick_len, 0.0)
                else:
                    pt2 = pt1 + V(0.0, hr_short_tick_len, 0.0)

            # End horizontal ruler

        # Restore OpenGL state.
        glDepthMask(GL_TRUE)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_LIGHTING)
        glDepthMask(GL_TRUE)
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        return  # from drawRulers