1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
#
# copyright_notice
#
"""glu wrappers
"""
import numpy
from opengltk import util
from opengltk.extent import _gllib, _glulib
from opengltk.util import gltypmap, revtypmap ,\
GLdouble, GLfloat, GLint, readModProjView
from opengltk.ccallback import swigptrcallback
import gl_wrapper
def gluBuild1DMipMaps( target, component, format, data):
"""
target - GLenum
component - GLint
format - GLenum
data - numpy array
"""
_glulib.gluBuild1DMipMaps( target, component, len( data), format,
gltypmap[ data.dtype.char], data)
def gluBuild2DMipMaps( target, component, width, format, data):
"""
target - GLenum
component - GLint
width - GLsizei
format - GLenum
data - numpy array
"""
lendat = len( data)
if lendat % width:
raise TypeError( (width, len( data)),
'len( data) nota multiple of "width"')
_glulib.gluBuild2DMipMaps( target, component, width, lendat/width, format,
gltypmap[ data.dtype.char], data)
def gluGetNurbsProperty( nurb, property):
"""
nurb - GLUnurbs*
property - GLenum
return - GLfloat
"""
data = numpy.zeros( 1, 'f')
_glulib.gluGetNurbsProperty( nurb, property, data)
return data[ 0]
def gluGetTessProperty( tess, property):
"""
tess - GLUtesselator*
property - GLenum
return - GLdouble
"""
data = numpy.zeros( 1, 'd')
_glulib.gluGetTessProperty( nurb, property, data)
return data[ 0]
def gluLoadSamplingMatrices( nurb, model, perspective, view):
"""
nurb - GLUnurb
model - sequence of 16 floats
perspective - sequence of 16 floats
view - sequence of 4 floats
"""
model, perspective, view = readModProjView( model, perspective, view)
_glulib.gluLoadSamplingMatrices( nurb, model, perspective, view)
def gluNurbsCallback( element, which, callback):
return _glulib.gluNurbsCallback( element, which,
swigptrcallback( util,
('void', ['GLenum']),
callback))
def gluNurbsCurve( nurb, type, knots, order, control, stride):
"""
nurb - GLUnurbs
type - GLenum
knots - seq( GLfloat)
order - GLint
control - seq( GLfloat)
stride - GLint
"""
lknot = len( knots)
assert stride
if lknot % stride:
raise TypeError( (len( knots), stride),
"(len( knots), stride) not compatible")
nknot = lknot / stride
if len( control) != nknot - order:
raise TypeError( (len( knots), order, stride, len( control)),
'(len( knots), order, stride, len( control))'
' not compatible')
_glulib.gluNurbsCurve( nurb, nknot, knots, stride,
control, order, type)
def gluNurbsSurface( nurb, type, sKnots, tKnots, sOrder, tOrder, control,
sStride, tStride):
"""
nurb - GLUnurbs
type - GLenum
sKnots, tKnots - seq( GLfloat)
sOrder, tOrder - GLint
control - seq( GLfloat)
sStride, tStride - GLint
"""
assert sStride
assert tStride
lsknot = len( sKnots)
if lsknot % sStride:
raise TypeError( (len( sKnots), sStride),
"(len( sKnots), sStride) not compatible")
nsknot = lsknot / sStride
ltknot = len( tKnots)
if ltknot % sStride:
raise TypeError( (len( tKnots), sStride),
"(len( tKnots), sStride) not compatible")
ntknot = ltknot / sStride
if len( control) != (nsknot - sOrder)*(ntknot - tOrder):
raise TypeError( (len( control), (nsknot, sOrder), (ntknot, tOrder)),
'(len( control), (nsknot, sOrder), (ntknot, tOrder))'
' not compatible')
_glulib.gluNurbsSurface( nurb, nsknot, sKnots, ntknot, tKnots,
sStride, tStride, control, sOrder, tOrder, type)
def gluPickMatrix( x, y, delX, delY, view):
"""
x, y, delX, delY - GLdouble
"""
if len( view) != 4:
raise TypeError( view, len( view), '4 expected')
if not isinstance(view , numpy.ndarray):
view = numpy.array(view, GLint)
_glulib.gluPickMatrix( x, y, delX, delY, view)
def gluProject( obj, model, proj, view):
"""
obj - seq( 3, GLdouble)
model - seq( gl.MODELVIEW_MATRIX, GLfloat)
perspective - seq( gl.PROJECTION_MATRIX, GLfloat)
view - seq( gl.VIEWPORT, GLfloat)
return - numpy array (shape: (3,), type: GLdouble)
"""
win = numpy.zeros( 3, GLdouble)
gluProjectv( obj, model, proj, view, win[0:1], win[ 1:2], win[ 2:3])
return win
def gluProjectv( obj, model, proj, view, win):
"""
obj - seq( 3, GLdouble)
model - seq( gl.MODELVIEW_MATRIX, GLfloat)
perspective - seq( gl.PROJECTION_MATRIX, GLfloat)
view - seq( gl.VIEWPORT, GLfloat)
win - numpy array (shape: (3,), type: GLdouble): gets the new coordinates
"""
if 3 != len( obj):
raise TypeError( len( obj), "obj not 3-array")
model, proj, view = readModProjView( model, proj, view)
_glulib.gluProject( obj[ 0], obj[ 1], obj[ 2], model, proj, view,
win[0:1], win[ 1:2], win[ 2:3])
def gluPwlCurve( nurb, type, data, stride):
"""
nurb - GLUnurbs*
type - GLenum
data - seq( GLfloat)
stride - GLint
"""
assert stride
ldata = len( data)
if ldata % stride:
raise TypeError( (len( data), stride),
"len( data) not a multiple of stride")
_glulib.gluPwlCurve( nurb, len( data) / stride, data, stride, type)
def gluQuadricCallback( element, which, callback):
return _glulib.gluQuadricCallback( element, which,
swigptrcallback( util,
('void', ['GLenum']),
callback))
def gluScaleImage( format, wIn, dataIn, wOut, hOut, typeOut):
"""
format - GLenum
wIn - GLsizei
dataIn - numpy array / list
wOut, hOut - GLsizei
typeOut - GLenum
return - numpy array(shape: wOut*hOut, type; typeOut)
"""
lin = len( dataIn)
if lin % wIn:
raise TypeError( (len( dataIn), wIn),
"len( dataIn) not multiple of wIn")
gltout = typeOut
typeOut = revtypmap[ typeout]
result = numpy.zeros( wOut * hOut, typeOut)
_glulib.gluScaleImage( format,
wIn, lin / wIn, gltypmap[ dataIn.dtype.char], dataIn,
wOut, hOut, gltout, result)
return result
def gluTessCallback( element, which, callback):
return _glulib.gluTessCallback( element, which,
swigptrcallback( util,
('void', ['GLenum']),
callback))
def gluTessNormaldv( tess, normale):
"""
tess - GLUtesselator*
normale - seq( 3, GLdouble)
"""
_glulib.gluTessNormal( tess, normale[ 0], normale[ 1], normale[ 2])
def gluTessNormalfv( tess, normale):
"""
tess - GLUtesselator*
normale - seq( 3, GLfloat)
"""
_glulib.gluTessNormal( tess, normale[ 0], normale[ 1], normale[ 2])
def gluTessVertex( tess, location, data):
"""
tess - GLUtesselator*
location - seq( 3, GLdouble)
data - GLvoid*
"""
if 3 != len( location):
raise TypeError( len( location), "location not a 3-array")
_glulib.gluTessVertex( tess, location, data)
def gluUnProject( obj, model, proj, view):
"""
obj - seq( 3, GLdouble)
model - seq( gl.MODELVIEW_MATRIX, GLfloat)
perspective - seq( gl.PROJECTION_MATRIX, GLfloat)
view - seq( gl.VIEWPORT, GLfloat)
return - numpy.array ( 3, GLdouble)
"""
win = numpy.zeros( 3, GLdouble)
gluUnProjectv( obj, model, proj, view, win )
return win[:3]
def gluUnProjectv( obj, model, proj, view, win):
"""
obj - seq( 3, GLdouble)
model - seq( gl.MODELVIEW_MATRIX, GLfloat)
perspective - seq( gl.PROJECTION_MATRIX, GLfloat)
view - seq( gl.VIEWPORT, GLfloat)
win - numpy array( 3, GLdouble): gets the new coordinates
"""
if 3 != len( obj):
raise TypeError( len( obj), "obj not 3-array")
model, proj, view = readModProjView( model, proj, view)
_glulib.gluUnProject( obj[ 0], obj[ 1], obj[ 2], model, proj, view,
win[0:1], win[ 1:2], win[ 2:9])
__all__ = [
'gluBuild1DMipMaps',
'gluBuild2DMipMaps',
'gluGetNurbsProperty',
'gluGetTessProperty',
'gluLoadSamplingMatrices',
'gluNurbsCallback',
'gluNurbsCurve',
'gluNurbsSurface',
'gluPickMatrix',
'gluProject',
'gluProjectv',
'gluPwlCurve',
'gluQuadricCallback',
'gluScaleImage',
'gluTessCallback',
'gluTessNormaldv',
'gluTessNormalfv',
'gluTessVertex',
'gluUnProject',
'gluUnProjectv',
]
|