예제 #1
0
    def present(self):
        """Present updated buffers to screen."""

        def sort_key(op):
            return (op.key, op.shader.prog)

        polygon_mode = PolygonMode.fill

        current_shader = None
        for op in sorted(self.render_queue, key=sort_key, reverse=True):
            # perform actual rendering
            with ExitStack() as stack:
                for tex_unit, tex in enumerate(op.textures):
                    stack.enter_context(tex.use(tex_unit))

                if op.shader.prog != current_shader:
                    op.shader.use()
                    current_shader = op.shader.prog

                for k, v in op.shader_params.items():
                    # FIXME: rework this
                    if isinstance(v, Texture):
                        v = v.tex_unit
                    op.shader[k] = v

                # change the polygon mode, if requested by render op
                if polygon_mode != op.polygon_mode:
                    glPolygonMode(GL_FRONT_AND_BACK, op.polygon_mode)
                    polygon_mode = op.polygon_mode

                op.mesh.render()

        self.render_queue.clear()

        surrender.render()
예제 #2
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
예제 #3
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
예제 #4
0
    def draw_vertices(self):
        # Draw all the vbo defined in set_atoms
        if self.transparent:
            glEnable(GL_BLEND)
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            glDepthMask(GL_FALSE)
        if self.wireframe:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        glEnableClientState(GL_VERTEX_ARRAY)
        self._vbo_v.bind_vertexes(3, GL_FLOAT)

        glEnableClientState(GL_NORMAL_ARRAY)
        self._vbo_n.bind_normals(GL_FLOAT)

        glEnableClientState(GL_COLOR_ARRAY)
        self._vbo_c.bind_colors(4, GL_UNSIGNED_BYTE)

        glDrawArrays(GL_TRIANGLES, 0, self._n_triangles)

        self._vbo_v.unbind()
        self._vbo_n.unbind()
        self._vbo_c.unbind()

        if self.transparent:
            glDisable(GL_BLEND)
            #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            glDepthMask(GL_TRUE)
        if self.wireframe:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
예제 #5
0
    def draw_vertices(self):
        # Draw all the vbo defined in set_atoms
        if self.transparent:
            glEnable(GL_BLEND)
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            glDepthMask(GL_FALSE)
        if self.wireframe:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        glEnableClientState(GL_VERTEX_ARRAY)
        self._vbo_v.bind_vertexes(3, GL_FLOAT)
        
        glEnableClientState(GL_NORMAL_ARRAY)
        self._vbo_n.bind_normals(GL_FLOAT)
        
        glEnableClientState(GL_COLOR_ARRAY)
        self._vbo_c.bind_colors(4, GL_UNSIGNED_BYTE)
        
        glDrawArrays(GL_TRIANGLES, 0, self._n_triangles)
        
        self._vbo_v.unbind()
        self._vbo_n.unbind()
        self._vbo_c.unbind()

        if self.transparent:
            glDisable(GL_BLEND)
            #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            glDepthMask(GL_TRUE)
        if self.wireframe:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
예제 #6
0
    def display(self, color: List[float], draw_solid: bool):
        """Displays the cube with a specific color.

        :param color: Color to display the cube.
        :param draw_solid: Whether to draw solid polygons (False to draw wireframe).
        """
        glColor(color)

        if draw_solid:
            ambient_color = [
                color[0] * 0.1, color[1] * 0.1, color[2] * 0.1, 1.0
            ]
        else:
            ambient_color = color
        glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_color)
        glMaterialfv(GL_FRONT, GL_DIFFUSE, color)
        glMaterialfv(GL_FRONT, GL_SPECULAR, color)

        glMaterialfv(GL_FRONT, GL_SHININESS, 10.0)

        if draw_solid:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        self.display_by_key(self._display_list_name)
예제 #7
0
파일: grid.py 프로젝트: magandrez/payton
    def render(self, proj: np.ndarray, view: np.ndarray,
               _lights: List[Light]) -> bool:
        """
        Virtual function for rendering the object.

        Args:
          proj: Camera projection matrix.
          view: Camera location/view matrix.
        """

        if not self.visible:
            return True

        if self._vao == -1:
            self.build()

        self._model_matrix = np.array(self.matrix, dtype=np.float32)
        self._material.render(proj, view, self._model_matrix, [])

        if glIsVertexArray(self._vao):
            glBindVertexArray(self._vao)
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
            glDrawElements(
                GL_LINES,
                self._vertex_count,
                GL_UNSIGNED_INT,
                ctypes.c_void_p(0),
            )
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
            glBindVertexArray(0)
        self._material.end()
        return True
예제 #8
0
 def render(self):
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
     glMatrixMode(GL_MODELVIEW)
     glPushMatrix()
     glTranslated(self.center[0], self.center[1], self.center[2])
     glCallList(G_OBJ_CUBE)
     glPopMatrix()
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
예제 #9
0
 def render(self):
     """ render the AABB. This can be useful for debugging purposes """
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
     glMatrixMode(GL_MODELVIEW)
     glPushMatrix()
     glTranslated(self.center[0], self.center[1], self.center[2])
     glCallList(G_OBJ_CUBE)
     glPopMatrix()
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
예제 #10
0
 def render(self):
     """ 渲染显示包围盒,可在调试的时候使用 """
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
     glMatrixMode(GL_MODELVIEW)
     glPushMatrix()
     glTranslated(self.center[0], self.center[1], self.center[2])
     glCallList(G_OBJ_CUBE)
     glPopMatrix()
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    def render(self, user_data_queue: mp.Queue = None):
        """Low level OpenGL calls to render the current state in an opengl_viewer. This
        code will be executed inside the viewer's process.

        Can be added to a viewer with the following code, telling the viewer to call this
        whenever it redraws its geometry.

        .. code-block:: python

            robot.viewer_3d.add_render_call(my_map_state.render)

        :param user_data_queue: The queue to read MapState messages from the main process.
        :type user_data_queue: mulitprocessing.Queue
        """
        try:
            latest: MapState = user_data_queue.get(False)

            self._open_nodes = latest._open_nodes  # pylint: disable=protected-access
            self._contact_nodes = latest._contact_nodes  # pylint: disable=protected-access
            self._walls = latest._walls  # pylint: disable=protected-access
            self._cleared_territories = latest._cleared_territories  # pylint: disable=protected-access
            self._collection_active = latest._collection_active  # pylint: disable=protected-access
        except mp.queues.Empty:
            pass
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND)

        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        glDisable(GL_LIGHTING)

        if RENDER_METADATA_OBJECTS:
            self._render_points(self._contact_nodes, NODE_CONTACT_RENDER_SIZE,
                                NODE_CONTACT_RENDER_COLOR)
            self._render_points(self._open_nodes, NODE_OPEN_RENDER_SIZE,
                                NODE_OPEN_RENDER_COLOR)

            # render the nav point open sample
            if self._cleared_territories and self._open_nodes:
                self._render_circle(self._open_nodes[0], NAV_POINT_RENDER_SIZE,
                                    NAV_POINT_RENDER_SECTIONS,
                                    NAV_POINT_RENDER_COLOR)

            for cleared_territory in self._cleared_territories:
                self._render_circle(cleared_territory.center,
                                    cleared_territory.radius,
                                    TERRITORY_RENDER_SECTIONS,
                                    TERRITORY_RENDER_COLOR)

        glEnable(GL_LIGHTING)
        for wall in self._walls:
            self._render_wall(wall, WALL_RENDER_HEIGHT_MM, WALL_RENDER_COLOR)
예제 #12
0
def drawcylinder_wireframe(color, end1, end2, radius): #bruce 060608
    """
    Draw a wireframe cylinder (not too pretty, definitely could look nicer, but
    it works.)
    """
    # display polys as their edges (see drawer.py's drawwirecube or Jig.draw for
    # related code) (probably we should instead create a suitable lines display
    # list, or even use a wire-frame-like texture so various lengths work well)
    glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_BACK, GL_LINE)
    glDisable(GL_LIGHTING)
    # This makes motors look too busy, but without it, they look too weird
    # (which seems worse.)
    glDisable(GL_CULL_FACE)
    try:
        ##k Not sure if this color will end up controlling the edge color; we
        ## hope it will.
        drawcylinder(color, end1, end2, radius)
    except:
        debug.print_compact_traceback("bug, ignored: ")
    # The following assumes that we are never called as part of a jig's drawing
    # method, or it will mess up drawing of the rest of the jig if it's
    # disabled.
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPolygonMode(GL_FRONT, GL_FILL)
    glPolygonMode(GL_BACK, GL_FILL) # could probably use GL_FRONT_AND_BACK
    return
예제 #13
0
def drawcylinder_wireframe(color, end1, end2, radius): #bruce 060608
    """
    Draw a wireframe cylinder (not too pretty, definitely could look nicer, but
    it works.)
    """
    # display polys as their edges (see drawer.py's drawwirecube or Jig.draw for
    # related code) (probably we should instead create a suitable lines display
    # list, or even use a wire-frame-like texture so various lengths work well)
    glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_BACK, GL_LINE)
    glDisable(GL_LIGHTING)
    # This makes motors look too busy, but without it, they look too weird
    # (which seems worse.)
    glDisable(GL_CULL_FACE)
    try:
        ##k Not sure if this color will end up controlling the edge color; we
        ## hope it will.
        drawcylinder(color, end1, end2, radius)
    except:
        debug.print_compact_traceback("bug, ignored: ")
    # The following assumes that we are never called as part of a jig's drawing
    # method, or it will mess up drawing of the rest of the jig if it's
    # disabled.
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPolygonMode(GL_FRONT, GL_FILL)
    glPolygonMode(GL_BACK, GL_FILL) # could probably use GL_FRONT_AND_BACK
    return
예제 #14
0
    def _render_highlighted(self) -> None:
        """Render cube outline on face that is hovered."""
        if not self._hovered:
            return

        glDisable(GL_DEPTH_TEST)
        glLineWidth(2.0)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        glBindVertexArray(self._vao_outline)
        glDrawArrays(GL_QUADS, self._hover_id * 4, 4)

        glEnable(GL_DEPTH_TEST)
        glLineWidth(1.0)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
예제 #15
0
    def init_opengl(self) -> bool:
        """Initialize and set OpenGL capabilities.

        Returns:
            True if initialized without error, False otherwise.
        """
        if self._gl_initialized:
            return True

        if self._context is None:
            return False

        glClearColor(*self.background_color)
        glClearDepth(1.0)

        glDepthFunc(GL_LESS)

        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        # set antialiasing
        glEnable(GL_LINE_SMOOTH)

        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
        glEnable(GL_COLOR_MATERIAL)
        glEnable(GL_MULTISAMPLE)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

        self.create_vaos()

        # compile shader programs
        self._shaders['default'] = shaderlib.compile_shader(*shaderlib.default)
        self._shaders['single_color'] = shaderlib.compile_shader(
            *shaderlib.single_color)
        self._shaders['instanced_model_color'] = shaderlib.compile_shader(
            *shaderlib.instanced_model_color)
        self._shaders['instanced_picking'] = shaderlib.compile_shader(
            *shaderlib.instanced_picking)
        self._shaders['diffuse'] = shaderlib.compile_shader(*shaderlib.diffuse)
        self._shaders['solid'] = shaderlib.compile_shader(*shaderlib.solid)

        self._gl_initialized = True
        return True
예제 #16
0
def render_to_png(filename,
                  callback,
                  obb,
                  model_matrix=(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
                                1)):
    from pygame import init, display, quit
    from pygame.constants import OPENGL, DOUBLEBUF
    from OpenGL.GL import glLightfv, glCullFace, glEnable, glShadeModel, glMatrixMode, glLoadIdentity, glClear, \
        glLoadMatrixf, glPolygonMode, glCallList, glReadPixels, GL_LIGHT0, GL_POSITION, GL_AMBIENT, GL_DIFFUSE, \
        GL_BACK, GL_LIGHTING, GL_COLOR_MATERIAL, GL_DEPTH_TEST, GL_SMOOTH, GL_PROJECTION, GL_MODELVIEW, \
        GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_FRONT_AND_BACK, GL_FILL, GL_LINE, GL_BGR, GL_UNSIGNED_BYTE
    from OpenGL.GLU import gluPerspective
    from cv2 import imwrite
    from numpy import frombuffer, uint8
    init()
    viewport = (800, 600)
    display.set_mode(viewport, OPENGL | DOUBLEBUF)
    glLightfv(GL_LIGHT0, GL_POSITION, (0, -1, 0, 0))
    glLightfv(GL_LIGHT0, GL_AMBIENT, (0.2, 0.2, 0.2, 1))
    glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.5, 0.5, 0.5, 1))
    glCullFace(GL_BACK)
    glEnable(GL_LIGHT0)
    glEnable(GL_LIGHTING)
    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_DEPTH_TEST)
    glShadeModel(GL_SMOOTH)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    width, height = viewport
    gluPerspective(90.0, width / float(height), 0.1, 100.0)
    glEnable(GL_DEPTH_TEST)
    glMatrixMode(GL_MODELVIEW)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    glLoadMatrixf(model_matrix)
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    glCallList(callback())
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    glCallList(create_obb_gl_list(obb))
    img_data = glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE)
    img = frombuffer(img_data, dtype=uint8)
    img = img.reshape((height, width, 3))
    imwrite(filename, img)
    quit()
예제 #17
0
def key_callback(window, key, scancode, action, mods):
    global keys
    global filling

    if key == glfw.KEY_ESCAPE and action == glfw.PRESS:
        glfw.set_window_should_close(window, 1)
    if key == glfw.KEY_SPACE and action == glfw.PRESS:

        if (filling):
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
            filling = False
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
            filling = True
    else:
        if action == glfw.PRESS:
            keys[key] = 1
        elif action == glfw.RELEASE:
            keys[key] = 0
예제 #18
0
def _draw_compass_geometry():
    """
    Do GL state changes and draw constant geometry for compass.
    Doesn't depend on any outside state, so can be compiled
    into an unchanging display list. 
    """
    glEnable(GL_COLOR_MATERIAL)
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    glDisable(GL_CULL_FACE)
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)

    #ninad 070122 - parametrized the compass drawing. (also added some doc). 
    #Also reduced the overall size of the compass. 

    p1 = -1 # ? start point of arrow cyl? 
    p2 = 3.25 #end point of the arrow cylindrical portion
    p3 = 2.5 #arrow head start point
    p5 = 4.5 # cone tip

    r1 = 0.2 #cylinder radius 
    r2 =0.2
    r3 = 0.2
    r4 = 0.60 #cone base radius

    glePolyCone([[p1,0,0], [0,0,0], [p2,0,0], [p3,0,0], [_P4,0,0], [p5,0,0]],
                [[0,0,0], [1,0,0], [1,0,0], [.5,0,0], [.5,0,0], [0,0,0]],
                [r1,r2,r3,r4,0,0])

    glePolyCone([[0,p1,0], [0,0,0], [0,p2,0], [0,p3,0], [0,_P4,0], [0,p5,0]],
                [[0,0,0], [0,.9,0], [0,.9,0], [0,.4,0], [0,.4,0], [0,0,0]],
                [r1,r2,r3,r4,0,0])

    glePolyCone([[0,0,p1], [0,0,0], [0,0,p2], [0,0,p3], [0,0,_P4], [0,0,p5]],
                [[0,0,0], [0,0,1], [0,0,1], [0,0,.4], [0,0,.4], [0,0,0]],
                [r1,r2,r3,r4,0,0])

    glEnable(GL_CULL_FACE)
    glDisable(GL_COLOR_MATERIAL)

    return
예제 #19
0
def _draw_compass_geometry():
    """
    Do GL state changes and draw constant geometry for compass.
    Doesn't depend on any outside state, so can be compiled
    into an unchanging display list. 
    """
    glEnable(GL_COLOR_MATERIAL)
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    glDisable(GL_CULL_FACE)
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)

    #ninad 070122 - parametrized the compass drawing. (also added some doc).
    #Also reduced the overall size of the compass.

    p1 = -1  # ? start point of arrow cyl?
    p2 = 3.25  #end point of the arrow cylindrical portion
    p3 = 2.5  #arrow head start point
    p5 = 4.5  # cone tip

    r1 = 0.2  #cylinder radius
    r2 = 0.2
    r3 = 0.2
    r4 = 0.60  #cone base radius

    glePolyCone([[p1, 0, 0], [0, 0, 0], [p2, 0, 0], [p3, 0, 0], [_P4, 0, 0],
                 [p5, 0, 0]], [[0, 0, 0], [1, 0, 0], [1, 0, 0], [.5, 0, 0],
                               [.5, 0, 0], [0, 0, 0]], [r1, r2, r3, r4, 0, 0])

    glePolyCone([[0, p1, 0], [0, 0, 0], [0, p2, 0], [0, p3, 0], [0, _P4, 0],
                 [0, p5, 0]], [[0, 0, 0], [0, .9, 0], [0, .9, 0], [0, .4, 0],
                               [0, .4, 0], [0, 0, 0]], [r1, r2, r3, r4, 0, 0])

    glePolyCone([[0, 0, p1], [0, 0, 0], [0, 0, p2], [0, 0, p3], [0, 0, _P4],
                 [0, 0, p5]], [[0, 0, 0], [0, 0, 1], [0, 0, 1], [0, 0, .4],
                               [0, 0, .4], [0, 0, 0]], [r1, r2, r3, r4, 0, 0])

    glEnable(GL_CULL_FACE)
    glDisable(GL_COLOR_MATERIAL)

    return
예제 #20
0
def drawsurface_wireframe(color, pos, radius, tm, nm): 
    glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_BACK, GL_LINE)
    glDisable(GL_LIGHTING)
    glDisable(GL_CULL_FACE) 
    try:
        drawsurface(color, pos, radius, tm, nm) 
    except:
        debug.print_compact_traceback("bug, ignored: ")
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPolygonMode(GL_FRONT, GL_FILL)
    glPolygonMode(GL_BACK, GL_FILL) 
    return
예제 #21
0
def drawsurface_wireframe(color, pos, radius, tm, nm): 
    glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_BACK, GL_LINE)
    glDisable(GL_LIGHTING)
    glDisable(GL_CULL_FACE) 
    try:
        drawsurface(color, pos, radius, tm, nm) 
    except:
        debug.print_compact_traceback("bug, ignored: ")
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPolygonMode(GL_FRONT, GL_FILL)
    glPolygonMode(GL_BACK, GL_FILL) 
    return
예제 #22
0
def startPatternedDrawing(highlight=False, select=False):
    """
    Start drawing with a patterned style, if either highlight or select is
    passed as True, and the corresponding preference is set to select a
    patterned drawing style.

    This is common code for two different prefs keys, each of which has its own
    set of settings constants...

    Return value is True if one of the patterned styles is selected.
    """
    (key, style, solid, pattern, edges, halos) = \
          _decodePatternPrefs(highlight, select)

    if solid:
        # Nothing to do here for solid colors.
        return False

    # Set up stipple-patterned drawing styles.
    if pattern is not None:
        glEnable(GL_POLYGON_STIPPLE)
        glPolygonStipple(pattern)
        return True

    # Both polygon edges and halos are drawn in line-mode.
    if edges or halos:
        glPolygonMode(GL_FRONT, GL_LINE)
        glPolygonMode(GL_BACK, GL_LINE)

        if halos:
            # Draw wide, unshaded lines, offset a little bit away from the
            # viewer so that only the silhouette edges are visible.
            glDisable(GL_LIGHTING)
            glLineWidth(env.prefs[haloWidth_prefs_key])
            glEnable(GL_POLYGON_OFFSET_LINE)
            glPolygonOffset(0.0, 5.e4)  # Constant offset.
            pass

        pass
    return True
예제 #23
0
def startPatternedDrawing(highlight = False, select = False):
    """
    Start drawing with a patterned style, if either highlight or select is
    passed as True, and the corresponding preference is set to select a
    patterned drawing style.

    This is common code for two different prefs keys, each of which has its own
    set of settings constants...

    Return value is True if one of the patterned styles is selected.
    """
    (key, style, solid, pattern, edges, halos) = \
          _decodePatternPrefs(highlight, select)

    if solid:
        # Nothing to do here for solid colors.
        return False

    # Set up stipple-patterned drawing styles.
    if pattern is not None:
        glEnable(GL_POLYGON_STIPPLE)
        glPolygonStipple(pattern)
        return True

    # Both polygon edges and halos are drawn in line-mode.
    if edges or halos:
        glPolygonMode(GL_FRONT, GL_LINE)
        glPolygonMode(GL_BACK, GL_LINE)

        if halos:
            # Draw wide, unshaded lines, offset a little bit away from the
            # viewer so that only the silhouette edges are visible.
            glDisable(GL_LIGHTING)
            glLineWidth(env.prefs[haloWidth_prefs_key])
            glEnable(GL_POLYGON_OFFSET_LINE)
            glPolygonOffset(0.0, 5.e4) # Constant offset.
            pass

        pass
    return True
예제 #24
0
    def display(self, pose: util.Pose, head_angle: util.Angle,
                lift_position: util.Distance):
        """Displays the precomputed view at a specific pose in 3d space.

        :param pose: Where to display the robot.
        """
        if not self._display_lists:
            return

        robot_matrix = pose.to_matrix()
        head_angle_degrees = head_angle.degrees

        # Get the angle of Vector's lift for rendering - we subtract the angle
        # of the lift in the default pose in the object, and apply the inverse
        # rotation
        sin_angle = (lift_position.distance_mm -
                     LIFT_PIVOT_HEIGHT_MM) / LIFT_ARM_LENGTH_MM
        angle_radians = math.asin(sin_angle)

        lift_angle = -(angle_radians - LIFT_ANGLE_IN_DEFAULT_POSE)
        lift_angle_degrees = math.degrees(lift_angle)

        glPushMatrix()
        glEnable(GL_LIGHTING)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND)

        glMultMatrixf(robot_matrix.in_row_order)

        robot_scale_amt = 10.0  # cm to mm
        glScalef(robot_scale_amt, robot_scale_amt, robot_scale_amt)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

        self._display_vector_body()
        self._display_vector_lift(lift_angle_degrees)
        self._display_vector_head(head_angle_degrees)

        glDisable(GL_LIGHTING)
        glPopMatrix()
예제 #25
0
def endPatternedDrawing(highlight = False, select = False):
    """
    End drawing with a patterned style, if either highlight or select is
    passed as True, and the corresponding preference is set to select a
    patterned drawing style.

    This is common code for two different prefs keys, each of which has its own
    set of settings constants...

    Return value is True if one of the patterned styles is selected.
    """
    (key, style, solid, pattern, edges, halos) = \
          _decodePatternPrefs(highlight, select)

    if solid:
        # Nothing to do here for solid colors.
        return False

    # End stipple-patterned drawing styles.
    if pattern is not None:
        glDisable(GL_POLYGON_STIPPLE)
        return True

    # End line-mode for polygon-edges or halos styles.
    if edges or halos:
        glPolygonMode(GL_FRONT, GL_FILL)
        glPolygonMode(GL_BACK, GL_FILL)

        if halos:
            # Back to normal lighting and treatment of lines and polygons.
            glEnable(GL_LIGHTING)
            glLineWidth(1.0)
            glDisable(GL_POLYGON_OFFSET_LINE)
            glPolygonOffset(0.0, 0.0)
            pass

        pass
    return True
예제 #26
0
def endPatternedDrawing(highlight=False, select=False):
    """
    End drawing with a patterned style, if either highlight or select is
    passed as True, and the corresponding preference is set to select a
    patterned drawing style.

    This is common code for two different prefs keys, each of which has its own
    set of settings constants...

    Return value is True if one of the patterned styles is selected.
    """
    (key, style, solid, pattern, edges, halos) = \
          _decodePatternPrefs(highlight, select)

    if solid:
        # Nothing to do here for solid colors.
        return False

    # End stipple-patterned drawing styles.
    if pattern is not None:
        glDisable(GL_POLYGON_STIPPLE)
        return True

    # End line-mode for polygon-edges or halos styles.
    if edges or halos:
        glPolygonMode(GL_FRONT, GL_FILL)
        glPolygonMode(GL_BACK, GL_FILL)

        if halos:
            # Back to normal lighting and treatment of lines and polygons.
            glEnable(GL_LIGHTING)
            glLineWidth(1.0)
            glDisable(GL_POLYGON_OFFSET_LINE)
            glPolygonOffset(0.0, 0.0)
            pass

        pass
    return True
예제 #27
0
 def __draw_cube(self, size = None):
     size = 1 if size == None else size
     glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
     glBegin(GL_QUADS)
     #==========================
     glVertex3f(size,size,size)
     glVertex3f(-size,size,size)
     glVertex3f(-size,-size,size)
     glVertex3f(size,-size,size)
     #==========================
     glVertex3f(size,size,-size)
     glVertex3f(-size,size,-size)
     glVertex3f(-size,-size,-size)
     glVertex3f(size,-size,-size)
     #==========================
     glVertex3f(size,size,size)
     glVertex3f(size,-size,size)
     glVertex3f(size,-size,-size)
     glVertex3f(size,size,-size)
     #==========================
     glVertex3f(-size,size,size)
     glVertex3f(-size,-size,size)
     glVertex3f(-size,-size,-size)
     glVertex3f(-size,size,-size)
     #==========================
     glVertex3f(size,size,size)
     glVertex3f(-size,size,size)
     glVertex3f(-size,size,-size)
     glVertex3f(size,size,-size)
     #==========================
     glVertex3f(size,-size,size)
     glVertex3f(-size,-size,size)
     glVertex3f(-size,-size,-size)
     glVertex3f(size,-size,-size)
     #==========================
     glEnd()
     return
예제 #28
0
    def render(self):
        """Low level OpenGL calls to render the current state in an opengl_viewer.

        Can be added to a viewer with the following code, telling the viewer to call this
        whenever it redraws its geometry.
        .. code-block:: python

            my_opengl_viewer.add_render_call(my_map_state.render)
        """
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND)

        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        glDisable(GL_LIGHTING)

        if RENDER_METADATA_OBJECTS:
            self._render_points(self._contact_nodes, NODE_CONTACT_RENDER_SIZE,
                                NODE_CONTACT_RENDER_COLOR)
            self._render_points(self._open_nodes, NODE_OPEN_RENDER_SIZE,
                                NODE_OPEN_RENDER_COLOR)

            # render the nav point open sample
            if self._cleared_territories and self._open_nodes:
                self._render_circle(self._open_nodes[0], NAV_POINT_RENDER_SIZE,
                                    NAV_POINT_RENDER_SECTIONS,
                                    NAV_POINT_RENDER_COLOR)

            for cleared_territory in self._cleared_territories:
                self._render_circle(cleared_territory.center,
                                    cleared_territory.radius,
                                    TERRITORY_RENDER_SECTIONS,
                                    TERRITORY_RENDER_COLOR)

        glEnable(GL_LIGHTING)
        for wall in self._walls:
            self._render_wall(wall, WALL_RENDER_HEIGHT_MM, WALL_RENDER_COLOR)
예제 #29
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
예제 #30
0
파일: renderer.py 프로젝트: jfozard/pyvol
    def _render_solid_obj(self, solid_object, width, height, VMatrix, PMatrix):

        glEnable(GL_DEPTH_TEST)

        glUseProgram(self.shader.program)
        glBindVertexArray(solid_object.vao)

        solid_object.elVBO.bind()

        mv_matrix = np.dot(VMatrix, solid_object.transform)
        glUniformMatrix4fv(self.shader.get_uniform("mv_matrix"),
                           1, True, mv_matrix.astype('float32'))
        glUniformMatrix4fv(self.shader.get_uniform("p_matrix"),
                           1, True, PMatrix.astype('float32'))

        glDisable(GL_CULL_FACE)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
#       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        glDrawElements(GL_TRIANGLES, solid_object.elCount,
                       GL_UNSIGNED_INT, solid_object.elVBO)

        solid_object.elVBO.unbind()
        glBindVertexArray(0)
        glUseProgram(0)
예제 #31
0
def drawwirebox(color, pos, length):
    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(length[0], length[1], length[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
예제 #32
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
예제 #33
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
예제 #34
0
  def display(self) :
    if self.display_mode == "lined" :
      
      if self.lines_color :	
        # Lines color configuration. 
        glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)    # Setting the line width given as argument.
     
      i=-1
      boolean=False

      while i < len(self.trigons)-1 :
	# Loop to display the triangles from our sphere.
	# Throught iterating over the polygons on the XZ surface.
	ii=-1
	while ii < len(self.trigons[i])-1 :
          glBegin(GL_LINE_LOOP)
	  if boolean :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii].get_vertex())
	  else :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii+1].get_vertex())
          glEnd()
	  ii += 1

	if boolean :
	  boolean=False
	else :
	  boolean=True

	i += 1
	  
    elif self.display_mode == "faced" :
      
      if self.faces_color :	
        # Faces color configuration. 
        glColor4ubv(self.faces_color.get_ubyte_v())
      
      i=-1
      boolean=False

      while i < len(self.trigons)-1 :
	# Loop to display the triangles from our sphere.
	# Throught iterating over the polygons on the XZ surface.
	ii=-1
	while ii < len(self.trigons[i])-1 :
          glBegin(GL_TRIANGLES)
	  if boolean :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii].get_vertex())
	  else :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii+1].get_vertex())
          glEnd()
	  ii += 1

	if boolean :
	  boolean=False
	else :
	  boolean=True

	i += 1
		  
      
    if self.display_mode == "twice" :  
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL) 
      
      if self.faces_color :
         # Faces color configuration. 	
        glColor4ubv(self.faces_color.get_ubyte_v())
      
      
      i=-1
      boolean=False

      while i < len(self.trigons)-1 :
	# Loop to display the triangles from our sphere.
	# Throught iterating over the polygons on the XZ surface.
	ii=-1
	while ii < len(self.trigons[i])-1 :
          glBegin(GL_TRIANGLES)
	  if boolean :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii].get_vertex())
	  else :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii+1].get_vertex())
          glEnd()
	  ii += 1

	if boolean :
	  boolean=False
	else :
	  boolean=True

	i += 1
	
      if self.lines_color :
         # Lines color configuration. 	
        glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)    # Setting the line width given as argument.
     
      i=-1
      boolean=False

      while i < len(self.trigons)-1 :
	# Loop to display the triangles from our sphere.
	# Throught iterating over the polygons on the XZ surface.
	ii=-1
	while ii < len(self.trigons[i])-1 :
          glBegin(GL_LINE_LOOP)
	  if boolean :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii].get_vertex())
	  else :
	    glVertex3fv(self.trigons[i][ii].get_vertex())
	    glVertex3fv(self.trigons[i][ii+1].get_vertex())
	    glVertex3fv(self.trigons[i+1][ii+1].get_vertex())
          glEnd()
	  ii += 1

	if boolean :
	  boolean=False
	else :
	  boolean=True

	i += 1

    if self.display_ls :
      # Displaying the Localview.
      self.ls.display(self.radius*2.0/10.0)
예제 #35
0
def drawOriginAsSmallAxis(scale, origin, dashEnabled = False):
    """
    Draws a small wireframe version of the origin. It is rendered as a 
    3D point at (0, 0, 0) with 3 small axes extending from it in the positive
    X, Y, Z directions.

    @see: drawaxes (related code)
    """
    #Perhaps we should split this method into smaller methods? ninad060920
    #Notes:
    #1. drawing arrowheads implemented on 060918
    #2. ninad060921 Show the origin axes as dotted if behind the mode. 
    #3. ninad060922 The arrow heads are drawn as wireframe cones if behind the
    #   object the arrowhead size is slightly smaller (otherwise some portion of
    #   the the wireframe arrow shows up!
    #4 .Making origin non-zoomable is acheived by replacing hardcoded 'n' with
    #   glpane's scale - ninad060922

    #ninad060922 in future , the following could be user preferences. 
    if (dashEnabled):
        dashShrinkage = 0.9
    else:
        dashShrinkage=1
    x1, y1, z1 = scale * 0.01, scale * 0.01, scale * 0.01
    xEnd, yEnd, zEnd = scale * 0.04, scale * 0.09, scale * 0.025
    arrowBase = scale * 0.0075 * dashShrinkage
    arrowHeight = scale * 0.035 * dashShrinkage
    lineWidth = 1.0

    glPushMatrix()

    glTranslate(origin[0], origin[1], origin[2])
    glDisable(GL_LIGHTING)
    glLineWidth(lineWidth)

    gleNumSides = gleGetNumSides()
    #Code to show hidden lines of the origin if some model obscures it
    #  ninad060921
    if dashEnabled:
        glLineStipple(2, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)
        glDisable(GL_DEPTH_TEST)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        gleSetNumSides(5)   
    else:   
        gleSetNumSides(10)

    glBegin(GL_LINES)

    color = env.prefs[originAxisColor_prefs_key]
    
    glColor3fv(color)

    #start draw a point at origin . 
    #ninad060922 is thinking about using GL_POINTS here

    glVertex(-x1, 0.0, 0.0)
    glVertex( x1, 0.0, 0.0)
    glVertex(0.0, -y1, 0.0)
    glVertex(0.0,  y1, 0.0)
    glVertex(-x1,  y1,  z1)
    glVertex( x1, -y1, -z1)    
    glVertex(x1,   y1,  z1)
    glVertex(-x1, -y1, -z1)    
    glVertex(x1,   y1, -z1)
    glVertex(-x1, -y1,  z1)    
    glVertex(-x1,  y1, -z1)
    glVertex(x1,  -y1,  z1)   
    #end draw a point at origin 

    #start draw small origin axes

    glColor3fv(color)
    glVertex(xEnd, 0.0, 0.0)
    glVertex( 0.0, 0.0, 0.0)

    glColor3fv(color)
    glVertex(0.0, yEnd, 0.0)
    glVertex(0.0,  0.0, 0.0)

    glColor3fv(color)
    glVertex(0.0, 0.0, zEnd)
    glVertex(0.0, 0.0,  0.0)
    glEnd() #end draw lines
    glLineWidth(1.0)

    # End push matrix for drawing various lines in the origin and axes.
    glPopMatrix()
    
    #start draw solid arrow heads  for  X , Y and Z axes
    glPushMatrix() 
    glDisable(GL_CULL_FACE)
    glColor3fv(color)
    glTranslatef(xEnd, 0.0, 0.0)
    glRotatef(90, 0.0, 1.0, 0.0)

    glePolyCone([[0, 0, -1],
                 [0, 0, 0],
                 [0, 0, arrowHeight],
                 [0, 0, arrowHeight+1]],
                None,
                [arrowBase, arrowBase, 0, 0])

    glPopMatrix()

    glPushMatrix()
    glColor3fv(color)
    glTranslatef(0.0, yEnd, 0.0)
    glRotatef(-90, 1.0, 0.0, 0.0)

    glePolyCone([[0, 0, -1],
                 [0, 0, 0],
                 [0, 0, arrowHeight],
                 [0, 0, arrowHeight+1]],
                None,
                [arrowBase, arrowBase, 0, 0])

    glPopMatrix()

    glPushMatrix()
    glColor3fv(color)
    glTranslatef(0.0,0.0,zEnd)

    glePolyCone([[0, 0, -1],
                 [0, 0, 0],
                 [0, 0, arrowHeight],
                 [0, 0, arrowHeight+1]],
                None,
                [arrowBase, arrowBase, 0, 0])

    #Disable line stipple and Enable Depth test
    if dashEnabled:
        glLineStipple(1, 0xAAAA)
        glDisable(GL_LINE_STIPPLE)
        glEnable(GL_DEPTH_TEST)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    gleSetNumSides(gleNumSides)
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPopMatrix() 
    #end draw solid arrow heads  for  X , Y and Z axes
    return
예제 #36
0
    def render(
        self,
        proj: np.ndarray,
        view: np.ndarray,
        lights: List[Light],
        parent_matrix: Optional[np.ndarray] = None,
    ) -> None:
        """
        Virtual function for rendering the object. Some objects can overwrite
        this function.

        Args:
          proj: Camera projection matrix.
          view: Camera location/view matrix.
          lights: Light objects in the scene
          parent_matrix: Parent matrix is the matrix of the parent. Parent can
                         be the scene itself or another object. In case of
                         another object, object will position itself relative
                         to its parent object.
        """
        if not self._visible:
            return

        if not self.has_vao or self._needs_update:
            self.build()

        if self._vertex_count == 0:
            return

        self.update_matrix(parent_matrix=parent_matrix)
        self.track()

        # Material shading mode.
        mode = None
        if self._has_vertex_colors:
            mode = Shader.PER_VERTEX_COLOR

        self.material.render(proj, view, self._model_matrix, lights, mode)

        # Actual rendering
        if glIsVertexArray(self._vao):
            glBindVertexArray(self._vao)
            pmode = GL_LINE
            primitive = GL_LINE_STRIP
            if self.material.display == SOLID:
                pmode = GL_FILL
                primitive = GL_TRIANGLES
            if self.material.display == POINTS:
                pmode = GL_POINT
                primitive = GL_POINTS
            glPolygonMode(GL_FRONT_AND_BACK, pmode)

            glDrawElements(
                primitive,
                self._vertex_count,
                GL_UNSIGNED_INT,
                ctypes.c_void_p(0),
            )
            if pmode != GL_FILL:
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
            glBindVertexArray(0)

        # End using the shader program.
        self.material.end()

        # Render motion path
        if self.track_motion:
            self._motion_path_line.render(proj, view, lights, parent_matrix)

        # render children
        for child in self.children:
            self.children[child].render(proj, view, lights, self._model_matrix)
예제 #37
0
def drawPlane(color, w, h, textureReady, opacity,
              SOLID=False, pickCheckOnly=False, tex_coords=None):
    """
    Draw polygon with size of <w>*<h> and with color <color>. Optionally, it
    could be texuture mapped, translucent.

    @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick
      selection purpose.
    """
    vs = [[-0.5, 0.5, 0.0], [-0.5, -0.5, 0.0],
          [0.5, -0.5, 0.0], [0.5, 0.5, 0.0]]
    
    # piotr 080529: use external texture coordinates if provided
    if tex_coords is None:
        vt = [[0.0, 1.0], [0.0, 0.0], [1.0, 0.0], [1.0, 1.0]]    
    else:
        vt = tex_coords
    
    if textureReady:
        opacity = 1.0
            
    glDisable(GL_LIGHTING)
    glColor4fv(list(color) + [opacity])

    glPushMatrix()
    glScalef(w, h, 1.0)

    if SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    else:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    glDisable(GL_CULL_FACE) 
    
    if not pickCheckOnly:
        # This makes sure a translucent object will not occlude another
        # translucent object.
        glDepthMask(GL_FALSE)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if textureReady:
            glEnable(GL_TEXTURE_2D)  

    glBegin(GL_QUADS)
    for ii in range(len(vs)):
        t = vt[ii]; v = vs[ii]
        if textureReady:
            glTexCoord2fv(t)
        glVertex3fv(v)
    glEnd()

    if not pickCheckOnly:
        if textureReady:
            glDisable(GL_TEXTURE_2D)

        glDisable(GL_BLEND)
        glDepthMask(GL_TRUE) 

    glEnable(GL_CULL_FACE)
    if not SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPopMatrix()
    glEnable(GL_LIGHTING)
    return
예제 #38
0
def drawHeightfield(color, w, h, textureReady, opacity,
                    SOLID=False, pickCheckOnly=False, hf=None):
    """
    Draw a heighfield using vertex and normal arrays. Optionally, it could be
    texuture mapped.

    @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick
      selection purpose.
    """        

    from OpenGL.GL import glTexEnvf
    from OpenGL.GL import GL_TEXTURE_ENV
    from OpenGL.GL import GL_TEXTURE_ENV_MODE
    from OpenGL.GL import GL_MODULATE
    from OpenGL.GL import glVertexPointer
    from OpenGL.GL import glNormalPointer
    from OpenGL.GL import glTexCoordPointer
    from OpenGL.GL import glDrawArrays
    from OpenGL.GL import glEnableClientState
    from OpenGL.GL import GL_VERTEX_ARRAY
    from OpenGL.GL import GL_NORMAL_ARRAY
    from OpenGL.GL import GL_TEXTURE_COORD_ARRAY
        
    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_LIGHTING)

    ### glColor4fv(list(color) + [opacity])
    ### glColor3fv(list(color))
    glColor3f(1.0, 1.0, 1.0)
    
    glPushMatrix()
    glScalef(w, h, 1.0)

    if SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    else:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    
    glDisable(GL_CULL_FACE) 
    
    if not pickCheckOnly:
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if textureReady:
            glEnable(GL_TEXTURE_2D)  
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_NORMAL_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)

    for tstrip_vert, tstrip_norm, tstrip_tex in hf:
        glVertexPointer(3, GL_FLOAT, 0, tstrip_vert)
        glNormalPointer(GL_FLOAT, 0, tstrip_norm)
        glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex)
        glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert))
        
    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_NORMAL_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)

    glDisable(GL_COLOR_MATERIAL)
    
    if not pickCheckOnly:
        if textureReady:
            glDisable(GL_TEXTURE_2D)

        glDepthMask(GL_TRUE) 

    glEnable(GL_CULL_FACE)
    if not SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPopMatrix()
    glEnable(GL_LIGHTING)
    
    return
예제 #39
0
    def set_fill():
        """Set OpenGL fill rendering."""

        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        glEnable(GL_CULL_FACE)
예제 #40
0
    def set_lines():
        """Set OpenGL lines rendering."""

        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        glDisable(GL_CULL_FACE)
예제 #41
0
def drawHeightfield(color, w, h, textureReady, opacity,
                    SOLID = False, pickCheckOnly = False, hf = None):
    """
    Draw a heighfield using vertex and normal arrays. Optionally, it could be
    texture mapped.

    @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick
      selection purpose.
    """        

    if not hf:
        # Return if heightfield is not provided
        return
    
    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_LIGHTING)

    # Don't use opacity, otherwise the heighfield polygons should be sorted
    # - something to implement later...
    ## glColor3v(list(color))
    
    if textureReady:
        # For texturing, use white color (to be modulated by the texture)
        glColor3f(1,1,1)
    else:
        glColor3fv(list(color))
        
    glPushMatrix()
    glScalef(w, h, 1.0)

    if SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    else:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    
    glDisable(GL_CULL_FACE) 
    
    if not pickCheckOnly:
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if textureReady:
            glEnable(GL_TEXTURE_2D)  
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_NORMAL_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)

    for tstrip_vert, tstrip_norm, tstrip_tex in hf:
        glVertexPointer(3, GL_FLOAT, 0, tstrip_vert)
        glNormalPointer(GL_FLOAT, 0, tstrip_norm)
        glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex)
        glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert))
        
    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_NORMAL_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)

    glDisable(GL_COLOR_MATERIAL)
    
    if not pickCheckOnly:
        if textureReady:
            glDisable(GL_TEXTURE_2D)

        glDepthMask(GL_TRUE) 

    glEnable(GL_CULL_FACE)
    if not SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPopMatrix()
    glEnable(GL_LIGHTING)
    
    return
예제 #42
0
    def _render_world_frame(self, world_frame: opengl_vector.WorldRenderFrame):
        """Render the world to the current OpenGL context

        :param world_frame: frame to render
        """
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        glEnable(GL_NORMALIZE)  # to re-scale scaled normals

        light_cube_view = self._vector_view_manifest.light_cube_view
        unit_cube_view = self._vector_view_manifest.unit_cube_view
        robot_view = self._vector_view_manifest.robot_view
        nav_map_view = self._vector_view_manifest.nav_map_view

        robot_frame = world_frame.robot_frame
        robot_pose = robot_frame.pose

        try:
            glDisable(GL_LIGHTING)
            nav_map_view.display()

            glEnable(GL_LIGHTING)
            # Render the cube
            for obj in world_frame.cube_frames:
                cube_pose = obj.pose
                if cube_pose is not None and cube_pose.is_comparable(
                        robot_pose):
                    light_cube_view.display(cube_pose)

            # Render the custom objects
            for obj in world_frame.custom_object_frames:
                obj_pose = obj.pose
                if obj_pose is not None and obj_pose.is_comparable(robot_pose):
                    glPushMatrix()
                    obj_matrix = obj_pose.to_matrix()
                    glMultMatrixf(obj_matrix.in_row_order)

                    glScalef(obj.x_size_mm * 0.5, obj.y_size_mm * 0.5,
                             obj.z_size_mm * 0.5)

                    # Only draw solid object for observable custom objects

                    if obj.is_fixed:
                        # fixed objects are drawn as transparent outlined boxes to make
                        # it clearer that they have no effect on vision.
                        FIXED_OBJECT_COLOR = [1.0, 0.7, 0.0, 1.0]
                        unit_cube_view.display(FIXED_OBJECT_COLOR, False)
                    else:
                        CUSTOM_OBJECT_COLOR = [1.0, 0.3, 0.3, 1.0]
                        unit_cube_view.display(CUSTOM_OBJECT_COLOR, True)

                    glPopMatrix()

            glBindTexture(GL_TEXTURE_2D, 0)

            for face in world_frame.face_frames:
                face_pose = face.pose
                if face_pose is not None and face_pose.is_comparable(
                        robot_pose):
                    glPushMatrix()
                    face_matrix = face_pose.to_matrix()
                    glMultMatrixf(face_matrix.in_row_order)

                    # Approximate size of a head
                    glScalef(100, 25, 100)

                    FACE_OBJECT_COLOR = [0.5, 0.5, 0.5, 1.0]
                    draw_solid = face.time_since_last_seen < 30
                    unit_cube_view.display(FACE_OBJECT_COLOR, draw_solid)

                    glPopMatrix()
        except BaseException as e:
            self._logger.error('rendering error: {0}'.format(e))

        glDisable(GL_LIGHTING)

        # Draw the Vector robot to the screen
        robot_view.display(robot_frame.pose, robot_frame.head_angle,
                           robot_frame.lift_position)

        if self.show_controls:
            self._draw_controls(world_frame.cube_connected(),
                                world_frame.cube_connecting())
예제 #43
0
def drawHeightfield(color,
                    w,
                    h,
                    textureReady,
                    opacity,
                    SOLID=False,
                    pickCheckOnly=False,
                    hf=None):
    """
    Draw a heighfield using vertex and normal arrays. Optionally, it could be
    texture mapped.

    @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick
      selection purpose.
    """

    if not hf:
        # Return if heightfield is not provided
        return

    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_LIGHTING)

    # Don't use opacity, otherwise the heighfield polygons should be sorted
    # - something to implement later...
    ## glColor3v(list(color))

    if textureReady:
        # For texturing, use white color (to be modulated by the texture)
        glColor3f(1, 1, 1)
    else:
        glColor3fv(list(color))

    glPushMatrix()
    glScalef(w, h, 1.0)

    if SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    else:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

    glDisable(GL_CULL_FACE)

    if not pickCheckOnly:
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if textureReady:
            glEnable(GL_TEXTURE_2D)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_NORMAL_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)

    for tstrip_vert, tstrip_norm, tstrip_tex in hf:
        glVertexPointer(3, GL_FLOAT, 0, tstrip_vert)
        glNormalPointer(GL_FLOAT, 0, tstrip_norm)
        glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex)
        glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert))

    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_NORMAL_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)

    glDisable(GL_COLOR_MATERIAL)

    if not pickCheckOnly:
        if textureReady:
            glDisable(GL_TEXTURE_2D)

        glDepthMask(GL_TRUE)

    glEnable(GL_CULL_FACE)
    if not SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPopMatrix()
    glEnable(GL_LIGHTING)

    return
예제 #44
0
    def display(self):
        ''' Icosahedron displaying method towards the settings. '''

        faces_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

        if self.display_mode == "lined" or self.display_mode == "faced":

            if self.display_mode == "lined" and self.lines_color:
                # Configuration of polygons lines displaying.
                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

                if self.lines_color:
                    # Lines color configuration.
                    glColor4ubv(self.lines_color.get_ubyte_v())

                glLineWidth(self.lines_width)

            elif self.display_mode == "faced":
                # Configuration of polygons faces displaying.
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

                if self.faces_color and isinstance(self.faces_color, Color):
                    # Faces colorizing configuration.
                    glColor4ubv(self.faces_color.get_ubyte_v())

            for polygon in self.polyhedron:
                # We loop over the polyhedron polygons container.

                if self.faces_color and isinstance(
                        self.faces_color,
                        list) and self.display_mode == "faced":
                    # Faces multi-colorizing configuration.
                    glColor4ubv(
                        self.faces_color[faces_color_index].get_ubyte_v())

                # Displaying one polygon:
                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()

                faces_color_index += 1

        elif self.display_mode == "twice":

            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

            if self.faces_color and isinstance(self.faces_color, Color):
                glColor4ubv(self.faces_color.get_ubyte_v())

            for faces in self.polyhedron:
                # We loop over the polyhedron polygons container.

                if self.faces_color and isinstance(self.faces_color, list):
                    # Faces multi-colorizing configuration.
                    glColor4ubv(
                        self.faces_color[faces_color_index].get_ubyte_v())

                # Displaying one polygon face:
                glBegin(GL_POLYGON)
                for v in faces:
                    # We loop over the every vertice from the face.
                    glVertex3fv(v.get_vertex())
                glEnd()

                faces_color_index += 1

            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

            if self.lines_color:
                # Lines color configuration.
                glColor4ubv(self.lines_color.get_ubyte_v())

            glLineWidth(self.lines_width)

            # Displaying one polygon face edges:
            for faces in self.polyhedron:

                glBegin(GL_POLYGON)
                for v in faces:
                    # We loop over the every vertice from the face.
                    glVertex3fv(v.get_vertex())
                glEnd()

        if self.display_ls:
            # Displaying the Localview.
            self.ls.display(self.side_length * 2.0 / 10.0)
예제 #45
0
    def display(self):

        if self.display_mode == "lined":
            # Configuration of polygons lines displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

            if self.lines_color:
                # Lines color configuration.
                glColor4ubv(self.lines_color.get_ubyte_v())

            glLineWidth(self.lines_width)

            for polygon in self.quads:
                # Loop over every quad from the polyhedron.
                # For only lines displaying.
                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()

        elif self.display_mode == "faced":
            # Configuration of polygons faces displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

            if self.quads_color and isinstance(self.quads_color, Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.quads_color.get_ubyte_v())

            quads_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            if self.quads_color and isinstance(self.quads_color, Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.quads_color.get_ubyte_v())

            for polygon in self.quads:
                # Loop over every quad from the polyhedron.
                if self.quads_color and isinstance(self.quads_color, list):
                    # Case there are more than one color for the faces displaying.
                    glColor4ubv(
                        self.quads_color[quads_color_index].get_ubyte_v())

                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()

                quads_color_index += 1

            if self.triangles_color and isinstance(self.triangles_color,
                                                   Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.triangles_color.get_ubyte_v())

            triangles_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            for polygon in self.triangles:
                # Loop over every triangle from the polyhedron.
                if self.triangles_color and isinstance(self.triangles_color,
                                                       list):
                    # Case there are more than one color for the faces displaying.
                    glColor4ubv(self.triangles_color[triangles_color_index].
                                get_ubyte_v())

                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()
                triangles_color_index += 1

        elif self.display_mode == "twice":
            # Configuration of polygons faces displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

            if self.quads_color and isinstance(self.quads_color, Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.quads_color.get_ubyte_v())

            quads_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            if self.quads_color and isinstance(self.quads_color, Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.quads_color.get_ubyte_v())

            for polygon in self.quads:
                # Loop over every quad from the polyhedron.
                if self.quads_color and isinstance(self.quads_color, list):
                    glColor4ubv(
                        self.quads_color[quads_color_index].get_ubyte_v())

                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()

                quads_color_index += 1

            if self.triangles_color and isinstance(self.triangles_color,
                                                   Color):
                # Case one same color for the faces displaying.
                glColor4ubv(self.triangles_color.get_ubyte_v())

            triangles_color_index = 0  # Iterator, case there are more than one color for the faces displaying.

            for polygon in self.triangles:
                # Loop over every triangle from the polyhedron.
                if self.triangles_color and isinstance(self.triangles_color,
                                                       list):
                    # Case there are more than one color for the faces displaying.
                    glColor4ubv(self.triangles_color[triangles_color_index].
                                get_ubyte_v())

                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()
                triangles_color_index += 1

            # Configuration of polygons lines displaying.
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

            if self.lines_color:
                # Lines color configuration.
                glColor4ubv(self.lines_color.get_ubyte_v())

            glLineWidth(self.lines_width)

            for polygon in self.quads:
                # Loop over every quad from the polyhedron.
                # For only lines displaying.
                glBegin(GL_POLYGON)
                for v in polygon:
                    # We loop over the every vertice from the polygon.
                    glVertex3fv(v.get_vertex())
                glEnd()

        if self.display_ls:
            # Displaying the Localview.
            self.ls.display(self.side_length * 2.0 / 10.0)
예제 #46
0
    def set_points():
        """Set OpenGL points rendering."""

        glPolygonMode(GL_FRONT_AND_BACK, GL_POINTS)
예제 #47
0
def drawPlane(color,
              w,
              h,
              textureReady,
              opacity,
              SOLID=False,
              pickCheckOnly=False,
              tex_coords=None):
    """
    Draw polygon with size of <w>*<h> and with color <color>. Optionally, it
    could be texuture mapped, translucent.

    @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick
      selection purpose.

    @param tex_coords: texture coordinates to be explicitly provided (for
    simple image transformation purposes)
    """
    vs = [[-0.5, 0.5, 0.0], [-0.5, -0.5, 0.0], [0.5, -0.5, 0.0],
          [0.5, 0.5, 0.0]]

    # piotr 080529: use external texture coordinates if provided
    if tex_coords is None:
        vt = [[0.0, 1.0], [0.0, 0.0], [1.0, 0.0], [1.0, 1.0]]
    else:
        vt = tex_coords

    if textureReady:
        opacity = 1.0

    glDisable(GL_LIGHTING)
    glColor4fv(list(color) + [opacity])

    glPushMatrix()
    glScalef(w, h, 1.0)

    if SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    else:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    glDisable(GL_CULL_FACE)

    if not pickCheckOnly:
        # This makes sure a translucent object will not occlude another
        # translucent object.
        glDepthMask(GL_FALSE)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if textureReady:
            glEnable(GL_TEXTURE_2D)

    glBegin(GL_QUADS)
    for ii in range(len(vs)):
        t = vt[ii]
        v = vs[ii]
        if textureReady:
            glTexCoord2fv(t)
        glVertex3fv(v)
    glEnd()

    if not pickCheckOnly:
        if textureReady:
            glDisable(GL_TEXTURE_2D)

        glDisable(GL_BLEND)
        glDepthMask(GL_TRUE)

    glEnable(GL_CULL_FACE)
    if not SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPopMatrix()
    glEnable(GL_LIGHTING)
    return
예제 #48
0
  def display(self) :
    
    if self.display_mode == "lined" :
      # Configuration of polygons lines displaying.
      glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
      
      if self.lines_color :
	# Lines color configuration. 
	glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)
    
    
      for polygon in self.hexagons :
	# Loop over every hexagon from the polyhedron. 
	# For only lines displaying.
        glBegin(GL_POLYGON)
        for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
        glEnd()	
      
    
    elif self.display_mode == "faced" :
      # Configuration of polygons faces displaying.
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
      if self.pentagons_color and isinstance(self.pentagons_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.pentagons_color.get_ubyte_v())
      
      
	
      pentagons_color_index=0  # Iterator, case there are more than one color for the faces displaying.	
	
      if self.pentagons_color and isinstance(self.pentagons_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.pentagons_color.get_ubyte_v())
      
      for polygon in self.pentagons :
	# Loop over every pentagon from the polyhedron. 
	if self.pentagons_color and isinstance(self.pentagons_color,list) : 
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.pentagons_color[pentagons_color_index].get_ubyte_v())
	  
	glBegin(GL_POLYGON)
	for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
	glEnd()	
    
	pentagons_color_index += 1
      
      if self.hexagons_color and isinstance(self.hexagons_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.hexagons_color.get_ubyte_v())
	
      hexagons_color_index=0  # Iterator, case there are more than one color for the faces displaying. 	
	
      for polygon in self.hexagons :
	# Loop over every hexagon from the polyhedron. 
	if self.hexagons_color and isinstance(self.hexagons_color,list) : 
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.hexagons_color[hexagons_color_index].get_ubyte_v())
	  
	glBegin(GL_POLYGON)
	for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
	glEnd()
	hexagons_color_index += 1
      
    elif self.display_mode == "twice" :
      # Configuration of polygons faces displaying.
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
      if self.pentagons_color and isinstance(self.pentagons_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.pentagons_color.get_ubyte_v())
      
      
	
      pentagons_color_index=0	
      for polygon in self.pentagons :
	# Loop over every pentagon from the polyhedron. 
	if self.pentagons_color and isinstance(self.pentagons_color,list) : 
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.pentagons_color[pentagons_color_index].get_ubyte_v())
	  
	glBegin(GL_POLYGON)
	for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
	glEnd()	
    
	pentagons_color_index += 1
      
      if self.hexagons_color and isinstance(self.hexagons_color,Color) :
	# Case one same color for the faces displaying.
	glColor4ubv(self.hexagons_color.get_ubyte_v())
	
      hexagons_color_index=0  # Iterator, case there are more than one color for the faces displaying.	
	
      for polygon in self.hexagons :
	# Loop over every hexagon from the polyhedron. 
	if self.hexagons_color and isinstance(self.hexagons_color,list) :
	  # Case there are more than one color for the faces displaying.
	  glColor4ubv(self.hexagons_color[hexagons_color_index].get_ubyte_v())
	  
	glBegin(GL_POLYGON)
	for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
	glEnd()
	
	hexagons_color_index += 1
      
      # Configuration of polygons lines displaying.
      glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
      
      if self.lines_color :
	# Lines color configuration. 
	glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)
    
    
      for polygon in self.hexagons :
	# Loop over every hexagon from the polyhedron.
	# For only lines displaying.
        glBegin(GL_POLYGON)
        for lines in polygon :
	  for v in lines :
	    # We loop over the every vertice from the polygon.
	    glVertex3fv(v.get_vertex())
        glEnd()	
      
    if self.display_ls :
      # Displaying the Localview.
      self.ls.display(self.side_length*4.0/10.0)
예제 #49
0
  def display(self) :
    if self.display_mode == "lined" :
      if self.lines_color :
        # Lines color configuration. 	
        glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)    # Setting the line width given as argument.
      
      i=0
      while i < len(self.polygons) :
	# Loop displaying the lines of the polygons on an surface of the sphere.
	# We process by crossing the line displaying.
	ii=0
	glBegin(GL_LINE_LOOP)
	while ii < len(self.polygons[i]) :
	  glVertex3fv(self.polygons[i][ii].get_vertex())
	  ii += 1 
	glEnd()
	i += 1    
      
      
      i=0
      while i < len(self.polygons) :
	# Loop displaying the lines of the polygons on an surface of the sphere.
	# We process by crossing the line displaying.
	ii=0
	glBegin(GL_LINE_LOOP)
	while ii < len(self.polygons[i]) : 
	  glVertex3fv(self.polygons[ii][i].get_vertex())
	  ii += 1  
	glEnd()
	i += 1
	
    elif self.display_mode == "faced" :
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL) 
      
      if self.faces_color :
	# Faces color configuration. 
        glColor4ubv(self.faces_color.get_ubyte_v())
	
      i=0	
      while i < len(self.polygons) :
	# Iteration over the polygon container variable to compute the quads.
	ii=0
	while ii < self.basis-1 :
	  # We compute the quads: for spheres quads displaying.
	  glBegin(GL_QUADS)
	  if not i == self.basis-1 :
	    glVertex3fv(self.polygons[i][ii].get_vertex())
	    glVertex3fv(self.polygons[i+1][ii].get_vertex())
	    glVertex3fv(self.polygons[i+1][ii+1].get_vertex())
	    glVertex3fv(self.polygons[i][ii+1].get_vertex())
	  else :
	    glVertex3fv(self.polygons[i][ii].get_vertex())
	    glVertex3fv(self.polygons[0][ii].get_vertex())
	    glVertex3fv(self.polygons[0][ii+1].get_vertex())
	    glVertex3fv(self.polygons[i][ii+1].get_vertex())
          
          glEnd()
          
	  ii += 1
	i += 1
		  
      
    elif self.display_mode == "twice" :  
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL) 
      
      if self.faces_color :
        glColor4ubv(self.faces_color.get_ubyte_v())
	
      i=0	
      while i < len(self.polygons) :
	# Iteration over the polygon container variable to compute the quads.
	ii=0
	while ii < self.basis-1 :
	  # We compute the quads: for spheres quads displaying.
	  glBegin(GL_QUADS)
	  if not i == self.basis-1 :
	    glVertex3fv(self.polygons[i][ii].get_vertex())
	    glVertex3fv(self.polygons[i+1][ii].get_vertex())
	    glVertex3fv(self.polygons[i+1][ii+1].get_vertex())
	    glVertex3fv(self.polygons[i][ii+1].get_vertex())
	  else :
	    glVertex3fv(self.polygons[i][ii].get_vertex())
	    glVertex3fv(self.polygons[0][ii].get_vertex())
	    glVertex3fv(self.polygons[0][ii+1].get_vertex())
	    glVertex3fv(self.polygons[i][ii+1].get_vertex())
          
          glEnd()
          
	  ii += 1
	i += 1
	
      if self.lines_color :
        # Lines color configuration. 	
        glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)    # Setting the line width given as argument.
      
      i=0
      while i < len(self.polygons) :
	# Loop displaying the lines of the polygons on an surface of the sphere.
	# We process by crossing the line displaying.
	ii=0
	glBegin(GL_LINE_LOOP)
	while ii < len(self.polygons[i]) :
	  glVertex3fv(self.polygons[i][ii].get_vertex())
	  ii += 1 
	glEnd()
	i += 1    
      
      
      i=0
      while i < len(self.polygons) :
	# Loop displaying the lines of the polygons on an surface of the sphere.
	# We process by crossing the line displaying.
	ii=0
	glBegin(GL_LINE_LOOP)
	while ii < len(self.polygons[i]) : 
	  glVertex3fv(self.polygons[ii][i].get_vertex())
	  ii += 1  
	glEnd()
	i += 1	
	
    if self.display_ls :
      # Displaying the Localview.
      self.ls.display(self.radius*2.0/10.0)	
예제 #50
0
def drawOriginAsSmallAxis(scale, origin, dashEnabled=False):
    """
    Draws a small wireframe version of the origin. It is rendered as a
    3D point at (0, 0, 0) with 3 small axes extending from it in the positive
    X, Y, Z directions.

    @see: drawaxes (related code)
    """
    #Perhaps we should split this method into smaller methods? ninad060920
    #Notes:
    #1. drawing arrowheads implemented on 060918
    #2. ninad060921 Show the origin axes as dotted if behind the mode.
    #3. ninad060922 The arrow heads are drawn as wireframe cones if behind the
    #   object the arrowhead size is slightly smaller (otherwise some portion of
    #   the the wireframe arrow shows up!
    #4 .Making origin non-zoomable is acheived by replacing hardcoded 'n' with
    #   glpane's scale - ninad060922

    #ninad060922 in future , the following could be user preferences.
    if (dashEnabled):
        dashShrinkage = 0.9
    else:
        dashShrinkage = 1
    x1, y1, z1 = scale * 0.01, scale * 0.01, scale * 0.01
    xEnd, yEnd, zEnd = scale * 0.04, scale * 0.09, scale * 0.025
    arrowBase = scale * 0.0075 * dashShrinkage
    arrowHeight = scale * 0.035 * dashShrinkage
    lineWidth = 1.0

    glPushMatrix()

    glTranslate(origin[0], origin[1], origin[2])
    glDisable(GL_LIGHTING)
    glLineWidth(lineWidth)

    gleNumSides = gleGetNumSides()
    #Code to show hidden lines of the origin if some model obscures it
    #  ninad060921
    if dashEnabled:
        glLineStipple(2, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)
        glDisable(GL_DEPTH_TEST)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        gleSetNumSides(5)
    else:
        gleSetNumSides(10)

    glBegin(GL_LINES)

    color = env.prefs[originAxisColor_prefs_key]

    glColor3fv(color)

    #start draw a point at origin .
    #ninad060922 is thinking about using GL_POINTS here

    glVertex(-x1, 0.0, 0.0)
    glVertex(x1, 0.0, 0.0)
    glVertex(0.0, -y1, 0.0)
    glVertex(0.0, y1, 0.0)
    glVertex(-x1, y1, z1)
    glVertex(x1, -y1, -z1)
    glVertex(x1, y1, z1)
    glVertex(-x1, -y1, -z1)
    glVertex(x1, y1, -z1)
    glVertex(-x1, -y1, z1)
    glVertex(-x1, y1, -z1)
    glVertex(x1, -y1, z1)
    #end draw a point at origin

    #start draw small origin axes

    glColor3fv(color)
    glVertex(xEnd, 0.0, 0.0)
    glVertex(0.0, 0.0, 0.0)

    glColor3fv(color)
    glVertex(0.0, yEnd, 0.0)
    glVertex(0.0, 0.0, 0.0)

    glColor3fv(color)
    glVertex(0.0, 0.0, zEnd)
    glVertex(0.0, 0.0, 0.0)
    glEnd()  #end draw lines
    glLineWidth(1.0)

    # End push matrix for drawing various lines in the origin and axes.
    glPopMatrix()

    #start draw solid arrow heads  for  X , Y and Z axes
    glPushMatrix()
    glDisable(GL_CULL_FACE)
    glColor3fv(color)
    glTranslatef(xEnd, 0.0, 0.0)
    glRotatef(90, 0.0, 1.0, 0.0)

    glePolyCone(
        [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]],
        None, [arrowBase, arrowBase, 0, 0])

    glPopMatrix()

    glPushMatrix()
    glColor3fv(color)
    glTranslatef(0.0, yEnd, 0.0)
    glRotatef(-90, 1.0, 0.0, 0.0)

    glePolyCone(
        [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]],
        None, [arrowBase, arrowBase, 0, 0])

    glPopMatrix()

    glPushMatrix()
    glColor3fv(color)
    glTranslatef(0.0, 0.0, zEnd)

    glePolyCone(
        [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]],
        None, [arrowBase, arrowBase, 0, 0])

    #Disable line stipple and Enable Depth test
    if dashEnabled:
        glLineStipple(1, 0xAAAA)
        glDisable(GL_LINE_STIPPLE)
        glEnable(GL_DEPTH_TEST)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    gleSetNumSides(gleNumSides)
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPopMatrix()
    #end draw solid arrow heads  for  X , Y and Z axes
    return
예제 #51
0
def drawHeightfield(color,
                    w,
                    h,
                    textureReady,
                    opacity,
                    SOLID=False,
                    pickCheckOnly=False,
                    hf=None):
    """
    Draw a heighfield using vertex and normal arrays. Optionally, it could be
    texuture mapped.

    @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick
      selection purpose.
    """

    from OpenGL.GL import glTexEnvf
    from OpenGL.GL import GL_TEXTURE_ENV
    from OpenGL.GL import GL_TEXTURE_ENV_MODE
    from OpenGL.GL import GL_MODULATE
    from OpenGL.GL import glVertexPointer
    from OpenGL.GL import glNormalPointer
    from OpenGL.GL import glTexCoordPointer
    from OpenGL.GL import glDrawArrays
    from OpenGL.GL import glEnableClientState
    from OpenGL.GL import GL_VERTEX_ARRAY
    from OpenGL.GL import GL_NORMAL_ARRAY
    from OpenGL.GL import GL_TEXTURE_COORD_ARRAY

    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_LIGHTING)

    ### glColor4fv(list(color) + [opacity])
    ### glColor3fv(list(color))
    glColor3f(1.0, 1.0, 1.0)

    glPushMatrix()
    glScalef(w, h, 1.0)

    if SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    else:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

    glDisable(GL_CULL_FACE)

    if not pickCheckOnly:
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if textureReady:
            glEnable(GL_TEXTURE_2D)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_NORMAL_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)

    for tstrip_vert, tstrip_norm, tstrip_tex in hf:
        glVertexPointer(3, GL_FLOAT, 0, tstrip_vert)
        glNormalPointer(GL_FLOAT, 0, tstrip_norm)
        glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex)
        glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert))

    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_NORMAL_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)

    glDisable(GL_COLOR_MATERIAL)

    if not pickCheckOnly:
        if textureReady:
            glDisable(GL_TEXTURE_2D)

        glDepthMask(GL_TRUE)

    glEnable(GL_CULL_FACE)
    if not SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPopMatrix()
    glEnable(GL_LIGHTING)

    return
예제 #52
0
  def display(self) :
    ''' Icosahedron displaying method towards the settings. '''
    
    
    faces_color_index=0  # Iterator, case there are more than one color for the faces displaying.
    
    if self.display_mode == "lined" or self.display_mode == "faced" :
      
      if self.display_mode == "lined" and self.lines_color :
	  # Configuration of polygons lines displaying.
	  glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
	  
	  if self.lines_color :
	    # Lines color configuration. 
	    glColor4ubv(self.lines_color.get_ubyte_v())

	  glLineWidth(self.lines_width)
	
      elif self.display_mode == "faced" :
	# Configuration of polygons faces displaying.
	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
	
	if self.faces_color and isinstance(self.faces_color,Color) :
	  # Faces colorizing configuration.
	  glColor4ubv(self.faces_color.get_ubyte_v())
      
      for polygon in self.polyhedron :
	# We loop over the polyhedron polygons container.
	
	if self.faces_color and isinstance(self.faces_color,list) and self.display_mode == "faced" : 
	  # Faces multi-colorizing configuration.
	  glColor4ubv(self.faces_color[faces_color_index].get_ubyte_v())
	
	# Displaying one polygon:
	glBegin(GL_POLYGON)
	for v in polygon :
	  # We loop over the every vertice from the polygon.
	  glVertex3fv(v.get_vertex())
	glEnd()	
	
	faces_color_index += 1 
      
    elif self.display_mode == "twice" :
      
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
      
      if self.faces_color and isinstance(self.faces_color,Color) :
	glColor4ubv(self.faces_color.get_ubyte_v())
	
      for faces in self.polyhedron :
	# We loop over the polyhedron polygons container.
	
	if self.faces_color and isinstance(self.faces_color,list) :
	  # Faces multi-colorizing configuration.
	  glColor4ubv(self.faces_color[faces_color_index].get_ubyte_v())
	  
	# Displaying one polygon face:  
	glBegin(GL_POLYGON)
        for v in faces :
	   # We loop over the every vertice from the face.
	  glVertex3fv(v.get_vertex())
        glEnd()
        
        faces_color_index += 1  
        
      glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
      
      if self.lines_color :
	# Lines color configuration. 
	glColor4ubv(self.lines_color.get_ubyte_v())
      
      glLineWidth(self.lines_width)
      
      # Displaying one polygon face edges: 
      for faces in self.polyhedron :
	
	glBegin(GL_POLYGON)
        for v in faces :
	  # We loop over the every vertice from the face.
	  glVertex3fv(v.get_vertex())
        glEnd() 
      
    if self.display_ls :
      # Displaying the Localview.
      self.ls.display(self.side_length*2.0/10.0)