예제 #1
0
def gluNurbsSurface(baseFunction, nurb, sKnots, tKnots, control, type):
    """Pythonic version of gluNurbsSurface

    Calculates knotCount, stride, and order automatically
    """
    sKnots = arrays.GLfloatArray.asArray(sKnots)
    sKnotCount = arrays.GLfloatArray.arraySize(sKnots)
    tKnots = arrays.GLfloatArray.asArray(tKnots)
    tKnotCount = arrays.GLfloatArray.arraySize(tKnots)
    control = arrays.GLfloatArray.asArray(control)

    try:
        length, width, step = arrays.GLfloatArray.dimensions(control)
    except ValueError as err:
        raise error.GLUError("""Need a 3-dimensional control array""")
    sOrder = sKnotCount - length
    tOrder = tKnotCount - width
    sStride = width * step
    tStride = step
    if _configflags.ERROR_CHECKING:
        checkOrder(sOrder, sKnotCount, "sOrder of NURBS surface")
        checkOrder(tOrder, tKnotCount, "tOrder of NURBS surface")
        checkKnots(sKnots, "sKnots of NURBS surface")
        checkKnots(tKnots, "tKnots of NURBS surface")
    if not (sKnotCount - sOrder) * (tKnotCount - tOrder) == length * width:
        raise error.GLUError("""Invalid NURB structure""", nurb, sKnotCount,
                             sKnots, tKnotCount, tKnots, sStride, tStride,
                             control, sOrder, tOrder, type)

    result = baseFunction(nurb, sKnotCount, sKnots, tKnotCount, tKnots,
                          sStride, tStride, control, sOrder, tOrder, type)
    return result
예제 #2
0
def checkOrder(order, knotCount, name):
    """Check that order is valid..."""
    if order < 1:
        raise error.GLUError("""%s should be 1 or more, is %s""" % (
            name,
            order,
        ))
    elif order > MAX_ORDER:
        raise error.GLUError("""%s should be %s or less, is %s""" %
                             (name, MAX_ORDER, order))
    elif knotCount < (2 * order):
        raise error.GLUError(
            """Knotcount must be at least 2x %s is %s should be at least %s"""
            % (name, knotCount, 2 * order))
예제 #3
0
def gluNurbsCurve(baseFunction, nurb, knots, control, type):
    """Pythonic version of gluNurbsCurve

    Calculates knotCount, stride, and order automatically
    """
    knots = arrays.GLfloatArray.asArray(knots)
    knotCount = arrays.GLfloatArray.arraySize(knots)
    control = arrays.GLfloatArray.asArray(control)
    try:
        length, step = arrays.GLfloatArray.dimensions(control)
    except ValueError as err:
        raise error.GLUError("""Need a 2-dimensional control array""")
    order = knotCount - length
    if _configflags.ERROR_CHECKING:
        checkOrder(order, knotCount, "order of NURBS curve")
        checkKnots(knots, "knots of NURBS curve")
    return baseFunction(
        nurb,
        knotCount,
        knots,
        step,
        control,
        order,
        type,
    )
예제 #4
0
def checkKnots(knots, name):
    """Check that knots are in ascending order"""
    if len(knots):
        knot = knots[0]
        for next in knots[1:]:
            if next < knot:
                raise error.GLUError("""%s has decreasing knot %s after %s""" %
                                     (name, next, knot))
예제 #5
0
def gluNurbsCurve( baseFunction, nurb, knots, control, type ):
    """Pythonic version of gluNurbsCurve
    
    Calculates knotCount, stride, and order automatically
    """
    knots = arrays.GLfloatArray.asArray( knots )
    knotCount = arrays.GLfloatArray.arraySize( knots )
    control = arrays.GLfloatArray.asArray( control )
    try:
        length,step = arrays.GLfloatArray.dimensions( control )
    except ValueError, err:
        raise error.GLUError( """Need a 2-dimensional control array""" )
예제 #6
0
    except ValueError, err:
        raise error.GLUError( """Need a 3-dimensional control array""" )
    sOrder = sKnotCount - length 
    tOrder = tKnotCount - width 
    sStride = width*step
    tStride = step
    if OpenGL.ERROR_CHECKING:
        checkOrder( sOrder, sKnotCount, 'sOrder of NURBS surface')
        checkOrder( tOrder, tKnotCount, 'tOrder of NURBS surface')
        checkKnots( sKnots, 'sKnots of NURBS surface')
        checkKnots( tKnots, 'tKnots of NURBS surface')
    if not (sKnotCount-sOrder)*(tKnotCount-tOrder) == length*width:
        raise error.GLUError(
            """Invalid NURB structure""",
            nurb, sKnotCount, sKnots, tKnotCount, tKnots,
            sStride, tStride, control,
            sOrder,tOrder,
            type
        )

    result = baseFunction(
        nurb, sKnotCount, sKnots, tKnotCount, tKnots,
        sStride, tStride, control,
        sOrder,tOrder,
        type
    )
    return result

@lazy( simple.gluPwlCurve )
def gluPwlCurve( baseFunction, nurb, data, type ):
    """gluPwlCurve -- piece-wise linear curve within GLU context