예제 #1
0
 def drawGL(self,mode,color=None):
     GL.glColor3fv(self.color)
     nurb = GLU.gluNewNurbsRenderer()
     GLU.gluNurbsProperty(nurb,GLU.GLU_SAMPLING_TOLERANCE,self.samplingTolerance)
     GLU.gluBeginCurve(nurb)
     GLU.gluNurbsCurve(nurb,self.knots,self.control,GL.GL_MAP1_VERTEX_3)
     GLU.gluEndCurve(nurb)
예제 #2
0
 def test_gluNurbsCurve(self):
     """Test that gluNurbsCurve raises error on invalid arguments"""
     nurb = GLU.gluNewNurbsRenderer()
     GLU.gluBeginCurve(nurb)
     if OpenGL.ERROR_CHECKING:
         self.assertRaises(
             error.GLUerror,
             GLU.gluNurbsCurve,
             nurb,
             [0, 1.0],
             [[0, 0, 0], [1, 0, 0], [1, 1, 0]],
             GL_MAP1_VERTEX_3,
         )
         self.assertRaises(
             error.GLUerror,
             GLU.gluNurbsCurve,
             nurb,
             [],
             [[0, 0, 0], [1, 0, 0], [1, 1, 0]],
             GL_MAP1_VERTEX_3,
         )
         self.assertRaises(
             error.GLUerror,
             GLU.gluNurbsCurve,
             nurb,
             [],
             [],
             GL_MAP1_VERTEX_3,
         )
예제 #3
0
    def drawGL(self, **kargs):
        if self.color is not None:
            GL.glColor3fv(self.color)

        nurb = GLU.gluNewNurbsRenderer()
        GLU.gluNurbsProperty(nurb, GLU.GLU_SAMPLING_TOLERANCE, self.samplingTolerance)
        GLU.gluBeginCurve(nurb)
        mode = GL.GL_MAP1_VERTEX_4
        # print "DRAW CONTROL",self.object.control
        GLU.gluNurbsCurve(nurb, self.object.knots, self.object.control, mode)
        GLU.gluEndCurve(nurb)
예제 #4
0
def drawNurbsCurves(x, knots, color=None, samplingTolerance=5.0):
    """Draw a collection of Nurbs curves.

    x: (nctrl,ndim) or (ncurve,nctrl,ndim) float array: control points,
       specifying either a single curve or ncurve curves defined by the
       same number of control points. ndim can be 3 or 4. If 4, the 4-th
       coordinate is interpreted as a weight for that point.
    knots: (nknots) or (ncurve,nknots) float array: knot vector, containing the
       parameter values to be used in the nurbs definition. Remark that
       nknots must be larger than nctrl. The order of the curve is
       nknots-nctrl and the degree of the curve is order-1.
       If a single knot vector is given, the same is used for all curves.
       Otherwise, the number of knot vectors must match the number of nurbs
       curves.

    If color is given it is an (ncurves,3) array of RGB values.
    """
    nurb = GLU.gluNewNurbsRenderer()
    if not nurb:
        raise RuntimeError, "Could not create a new NURBS renderer"
    nctrl, ndim = x.shape[-2:]
    nknots = asarray(knots).shape[-1]
    order = nknots - nctrl
    if order > 8:
        import warnings

        warnings.warn(
            "Nurbs curves of degree > 7 can currently not be drawn! You can create some approximation by evaluating the curve at some points."
        )
        return
    mode = {3: GL.GL_MAP1_VERTEX_3, 4: GL.GL_MAP1_VERTEX_4}[ndim]
    x = x.reshape(-1, nctrl, ndim)
    if color is not None:
        color = color.reshape(-1, 3)
        if color.shape[0] == 1:
            # Handle single color
            GL.glColor3fv(color[0])
            color = None
        elif color.shape[0] != x.shape[0]:
            raise ValueError, "Number of colors (%s) should equal 1 or the number of faces(%s)" % (
                color.shape[0],
                x.shape[0],
            )
    ki = knots
    GLU.gluNurbsProperty(nurb, GLU.GLU_SAMPLING_TOLERANCE, samplingTolerance)
    for i, xi in enumerate(x):
        if color is not None:
            GL.glColor3fv(color[i])
        if knots.ndim > 1:
            ki = knots[i]
        GLU.gluBeginCurve(nurb)
        # print ki,xi
        GLU.gluNurbsCurve(nurb, ki, xi, mode)
        GLU.gluEndCurve(nurb)
예제 #5
0
def drawNurbsCurves(x,color=None):
    """Draw a collection of curves.

    x is a (nlines,3,3) shaped array of coordinates.

    If color is given it is an (nlines,3) array of RGB values.
    """
    nurb = GLU.gluNewNurbsRenderer()
    if x.shape[1] == 4:
        knots = array([0.,0.,0.,0.,1.0,1.0,1.0,1.0])
    if x.shape[1] == 3:
        knots = array([0.,0.,0.,1.0,1.0,1.0])
    if not nurb:
        return
    for i,xi in enumerate(x):
        if color is not None:
            GL.glColor3fv(color[i])
        GLU.gluBeginCurve(nurb)
        GLU.gluNurbsCurve(nurb,knots,xi,GL.GL_MAP1_VERTEX_3)
        GLU.gluEndCurve(nurb)
예제 #6
0
def drawCurves(x,color=None):
    """Draw a collection of curves.

    x is a (nlines,3,3) shaped array of coordinates.

    If color is given it is an (nlines,3) array of RGB values.
    """
    nurb = GLU.gluNewNurbsRenderer()
    nkots = 7
    knots = arange(nkots+1) / float(nkots)
    knots = array([0.,0.,0.,0.,1.,1.,1.,1.])
    
    if not nurb:
        return
    for i,xi in enumerate(x):
        if color is not None:
            GL.glColor3fv(color[i])
        print knots
        print xi
        GLU.gluBeginCurve(nurb)
        GLU.gluNurbsCurve(nurb,knots,xi,GL.GL_MAP1_VERTEX_3)
        GLU.gluEndCurve(nurb)
예제 #7
0
파일: canvas.py 프로젝트: alien9/dedada
    def paintGL(self):
        glClear(GL_COLOR_BUFFER_BIT)

        # draw FBO layers from the bottom up
        for layer in reversed(self.layers):
            self.drawTexture(QPointF(0,0), layer.texture(), GL_TEXTURE_RECTANGLE_ARB)

        # if stroke, draw to the stroke layer, draw stroke layer
        self.program.bind()
        glBegin(GL_LINE_STRIP)
        g=gluNewNurbsRenderer()
        x1 = y1 = 25
        x2 = y2 = 450
        scale = abs(x2-x1)/3.0
        midx, midy = (abs(x2+x1)/2.0), abs(y2+y1)/2.0   
        degree = 3

            
        ctrlpoints=[[x1, y1, 0],
            [x1+scale, y1, 0],
            [midx, midy, 0],
            [x2-scale, y2, 0],
            [x2, y2, 0]]   
        
        glu.gluBeginCurve(g)
        glu.gluNurbsCurve(g,
                          [[10,10,0],[50,30,0],[100,100,0],[110,220,0],[400,280,0]],
                          [[0,0,0.1,0.1],[0,0,0.1,0.1],[0,0,0.1,0.1],[0,0,0.1,0.1],[0,0,0.1,0.1],[0,0,0.1,0.1],[0,0,0.1,0.1],[0,0,0.1,0.1],],
                          GL_MAP1_VERTEX_3)
        glu.gluEndCurve(g)
        
        glVertex2f(10,10)
        glVertex2f(20,10)
        glVertex2f(10,200)
        glVertex2f(100,200)
        
        glEnd()
        self.program.release()
예제 #8
0
def drawNurbsCurves(x,knots,color=None,alpha=1.0,samplingTolerance=5.0):
    """Draw a collection of Nurbs curves.

    x: (nctrl,ndim) or (ncurve,nctrl,ndim) float array: control points,
       specifying either a single curve or ncurve curves defined by the
       same number of control points. ndim can be 3 or 4. If 4, the 4-th
       coordinate is interpreted as a weight for that point.
    knots: (nknots) or (ncurve,nknots) float array: knot vector, containing the
       parameter values to be used in the nurbs definition. Remark that
       nknots must be larger than nctrl. The order of the curve is
       nknots-nctrl and the degree of the curve is order-1.
       If a single knot vector is given, the same is used for all curves.
       Otherwise, the number of knot vectors must match the number of nurbs
       curves.

    If color is given it is an (ncurves,3) array of RGB values.
    """
    nctrl,ndim = x.shape[-2:]
    nknots = asarray(knots).shape[-1]
    order = nknots-nctrl
    if  order > 8:
        utils.warn('Nurbs curves of degree > 7 can currently not be drawn! You can create some approximation by evaluating the curve at some points.')
        return

    if x.ndim == 2:
        x = x.reshape(-1,nctrl,ndim)
        if color is not None and color.ndim == 2:
            color = color.reshape(-1,nctrl,color.shape[-1])

    if color is not None:
        pf.debug('Coords shape: %s' % str(x.shape),pf.DEBUG.DRAW)
        pf.debug('Color shape: %s' % str(color.shape),pf.DEBUG.DRAW)
        if color.ndim == 1:
            pf.debug('Single color',pf.DEBUG.DRAW)
        elif color.ndim == 2 and color.shape[0] == x.shape[0]:
            pf.debug('Element color: %s colors' % color.shape[0],pf.DEBUG.DRAW)
        elif color.shape == x.shape[:-1] + (3,):
            pf.debug('Vertex color: %s colors' % str(color.shape[:-1]),pf.DEBUG.DRAW)
        else:
            raise ValueError,"Number of colors (%s) should equal 1 or the number of curves(%s) or the number of curves * number of vertices" % (color.shape[0],x.shape[0])

        pf.debug("Color shape = %s" % str(color.shape),pf.DEBUG.DRAW)
        if color.shape[-1] not in (3,4):
            raise ValueError,"Expected 3 or 4 color components"

    if color is not None:
        pf.debug("Final Color shape = %s" % str(color.shape),pf.DEBUG.DRAW)

    nurb = GLU.gluNewNurbsRenderer()
    if not nurb:
        raise RuntimeError,"Could not create a new NURBS renderer"

    GLU.gluNurbsProperty(nurb,GLU.GLU_SAMPLING_TOLERANCE,samplingTolerance)

    mode = {3:GL.GL_MAP1_VERTEX_3, 4:GL.GL_MAP1_VERTEX_4}[ndim]

    if color is not None and color.ndim == 1:
        # Handle single color
        pf.debug('Set single color: OK',pf.DEBUG.DRAW)
        glColor(color)
        color = None

    ki = knots
    for i,xi in enumerate(x):
        if color is not None and color.ndim == 2:
            # Handle element color
            glColor(color[i])
        if knots.ndim > 1:
            ki = knots[i]
        GLU.gluBeginCurve(nurb)
        if color is not None and color.ndim == 3:
            # Handle vertex color
            ci = color[i]
            if ci.shape[-1] == 3:
                # gluNurbs always wants 4 colors
                ci = growAxis(ci,1,axis=-1,fill=alpha)
            GLU.gluNurbsCurve(nurb,ki,ci,GL.GL_MAP1_COLOR_4)
        GLU.gluNurbsCurve(nurb,ki,xi,mode)
        GLU.gluEndCurve(nurb)

    GLU.gluDeleteNurbsRenderer(nurb)
예제 #9
0
 def draw(self):
     glu.gluBeginCurve(self.glID)
     glu.gluNurbsCurve(self.glID, self.uKnot, self.controlPoints, self.target)
     glu.gluEndCurve(self.glID)