def raytraptris3d(srfs, subeps, numeps): pts = irit.raytraps(srfs, 1, subeps, numeps, 1) retval = irit.nil() if (irit.SizeOf(pts) > 1): irit.printf("%d solution(s) found\n", irit.list(irit.SizeOf(pts))) i = 1 while (i <= irit.SizeOf(pts)): pt = irit.coord(pts, i) err = irit.getattr(pt, "rngerror") if (irit.ThisObject(err) == irit.NUMERIC_TYPE): irit.printf("error = %16.14f\n", irit.list(err)) else: irit.printf("error is not provided\n", irit.nil()) points = irit.nil() j = 1 while (j <= irit.SizeOf(srfs)): irit.snoc( irit.seval( irit.nth(srfs, j), irit.FetchRealObject(irit.coord(pt, 1 + (j - 1) * 2)), irit.FetchRealObject(irit.coord(pt, 2 + (j - 1) * 2))), points) j = j + 1 irit.snoc(irit.poly(points, 0), retval) i = i + 1 return retval
def dominos(path, scl, piecetimestep): retval = irit.nil() animtime = 0 dominopiece = irit.box( (-0.01, -0.006, 0), 0.02, 0.006, 0.05) * irit.sc(scl) rot_x = irit.cbezier( irit.list( irit.ctlpt( irit.E1, 0 ), \ irit.ctlpt( irit.E1, 80 ) ) ) crvdomain = irit.pdomain(path) t = irit.FetchRealObject(irit.nth(crvdomain, 1)) dpath = irit.cderive(path) while (t < irit.FetchRealObject(irit.nth(crvdomain, 2))): d = irit.Fetch3TupleObject( irit.coerce(irit.ceval(dpath, t), irit.POINT_TYPE)) dlen = math.sqrt(DotProd(d, d)) rot_x = irit.creparam(rot_x, animtime, animtime + piecetimestep) irit.attrib(dominopiece, "animation", irit.list(rot_x)) irit.setname(irit.getattr(dominopiece, "animation"), 0, "rot_x") dp = dominopiece * irit.rz( -math.atan2(d[0], d[1]) * 180 / math.pi) * irit.trans( irit.Fetch3TupleObject( irit.coerce(irit.ceval(path, t), irit.VECTOR_TYPE))) irit.snoc(dp, retval) t = t + 0.04 * scl / dlen animtime = animtime + piecetimestep * 0.6 return retval
def extractidparts(obj, id, rgb): retval = irit.nil() i = 0 while (i <= irit.SizeOf(obj) - 1): p = irit.coord(obj, i) if (irit.getattr(p, "id") == irit.GenRealObject(id)): irit.snoc(p, retval) i = i + 1 retval = irit.mergepoly(retval) irit.attrib(retval, "rgb", irit.GenStrObject(rgb)) return retval
def mergeverticalbndrycrvs( crvs ): crvs = crvs * irit.tx( 0 ) retval = irit.nil( ) i = 1 while ( i <= irit.SizeOf( crvs ) ): c1 = irit.nth( crvs, i ) used = irit.getattr( c1, "used" ) if ( irit.ThisObject( used ) != irit.NUMERIC_TYPE ): j = i + 1 while ( j <= irit.SizeOf( crvs ) ): c2 = irit.nth( crvs, j ) used = irit.getattr( c2, "used" ) if ( irit.ThisObject( used ) != irit.NUMERIC_TYPE ): c1a = mergeverticaltwocrvs( c1, c2 ) if ( c1a != c1 ): irit.attrib( irit.nref( crvs, j ), "used", irit.GenIntObject(1 )) c1 = c1a j = j + 1 irit.snoc( c1 * irit.tx( 0 ), retval ) i = i + 1 return retval
def displayptscrctan2crvs(pts, r, c1, c2): retval = irit.nil() circ = irit.circle((0, 0, 0), r) i = 1 while (i <= irit.SizeOf(pts)): pt = irit.coord(pts, i) prms = irit.getattr(pt, "params") ptc1 = irit.ceval(c1, irit.FetchRealObject(irit.coord(prms, 0))) ptc2 = irit.ceval(c2, irit.FetchRealObject(irit.coord(prms, 1))) irit.snoc( irit.list( irit.coerce( pt, irit.E2 ) + ptc1, \ irit.coerce( pt, irit.E2 ) + ptc2, \ circ * irit.trans( irit.Fetch3TupleObject(irit.coerce( pt, irit.VECTOR_TYPE )) ) ), retval ) i = i + 1 return retval
def interptseval(crvs): retval = irit.nil() i = 1 while (i <= irit.SizeOf(crvs)): crv = irit.nth(crvs, i) interpts = irit.getattr(crv, "interpts") j = 1 while (j <= irit.SizeOf(interpts)): irit.snoc( irit.ceval(crv, irit.FetchRealObject(irit.nth(interpts, j))), retval) j = j + 1 i = i + 1 irit.printf("numer of intersections detected = %d\n", irit.list(irit.SizeOf(retval))) return retval
def warpsurface( srf, tv ): usize = irit.FetchRealObject(irit.nth( irit.ffmsize( srf ), 1 )) vsize = irit.FetchRealObject(irit.nth( irit.ffmsize( srf ), 2 )) clr = irit.getattr( srf, "color" ) i = 0 while ( i <= usize * vsize - 1 ): pt = irit.coord( srf, i ) x = irit.FetchRealObject(irit.coord( pt, 1 )) y = irit.FetchRealObject(irit.coord( pt, 2 )) z = irit.FetchRealObject(irit.coord( pt, 3 )) pt = irit.teval( tv, x, y, z ) v = math.floor( i/float(usize) ) u = i - v * usize srf = irit.seditpt( srf, pt, u, v ) i = i + 1 irit.attrib( srf, "color", clr ) retval = srf return retval
def computeviews( c, step, fname ): dms = buildvisibilitymap( c, step ) ranges = irit.nil( ) i = 1 while ( i <= irit.SizeOf( dms ) ): ranges = cnvrtcrvs2ranges( irit.nth( dms, i ), i, 1 ) + ranges i = i + 1 irit.printf( "%d views are considered\n", irit.list( irit.SizeOf( dms ) ) ) cvrs = irit.setcover( ranges, 0.001 ) cvrcrvs = irit.nil( ) i = 1 while ( i <= irit.SizeOf( cvrs ) ): cvr = irit.nth( ranges, irit.FetchRealObject(irit.nth( cvrs, i )) + 1 ) irit.printf( "curve %d [idx = %d] covers from t = %f to t = %f\n", irit.list( i, irit.getattr( cvr, "index" ), irit.nth( cvr, 1 ), irit.nth( cvr, 2 ) ) ) irit.snoc( extractcrvregion( c, irit.nth( cvr, 1 ), irit.nth( cvr, 2 ), (irit.getattr( cvr, "index" )/irit.SizeOf( dms ) ) * 360 ), cvrcrvs ) i = i + 1 irit.attrib( c, "width", irit.GenRealObject(0.005 )) irit.attrib( c, "rgb", irit.GenStrObject("255, 255, 255" )) retval = irit.list( c, cvrcrvs ) if ( irit.SizeOf( irit.GenStrObject( fname ) ) > 0 ): irit.save( fname, retval ) return retval
def skel2dcolor( prim1, prim2, prim3, eps, mzerotols, drawall, fname ): equapt = irit.skel2dint( prim1, prim2, prim3, 100, eps, 300, mzerotols ) if ( irit.SizeOf( equapt ) > 1 ): irit.printf( "%d solutions detected\n", irit.list( irit.SizeOf( equapt ) ) ) irit.color( equapt, irit.WHITE ) irit.adwidth( prim1, 2 ) irit.adwidth( prim2, 2 ) irit.adwidth( prim3, 2 ) tans = irit.nil( ) edges = irit.nil( ) circs = irit.nil( ) i = 1 while ( i <= irit.SizeOf( equapt ) ): e = irit.nth( equapt, i ) clrs = getrandomcolors( ) clr = irit.nth( clrs, 1 ) dclr = irit.nth( clrs, 2 ) d = irit.getattr( e, "prim1pos" ) irit.snoc( d, tans ) irit.snoc( setcolor( irit.coerce( irit.getattr( e, "prim1pos" ), irit.E2 ) + irit.coerce( e, irit.E2 ), dclr ), edges ) irit.snoc( irit.getattr( e, "prim2pos" ), tans ) irit.snoc( setcolor( irit.coerce( irit.getattr( e, "prim2pos" ), irit.E2 ) + irit.coerce( e, irit.E2 ), dclr ), edges ) irit.snoc( irit.getattr( e, "prim3pos" ), tans ) irit.snoc( setcolor( irit.coerce( irit.getattr( e, "prim3pos" ), irit.E2 ) + irit.coerce( e, irit.E2 ), dclr ), edges ) irit.snoc( setcolor( irit.pcircle( irit.Fetch3TupleObject(irit.coerce( e, irit.VECTOR_TYPE )), irit.dstptpt( d, e ) ), clr ), circs ) i = i + 1 irit.color( edges, irit.MAGENTA ) irit.color( tans, irit.GREEN ) if ( drawall ): all = irit.list( prim1, prim2, prim3, edges, tans, circs,\ equapt ) else: all = irit.list( prim1, prim2, prim3, circs ) if ( irit.SizeOf( irit.GenStrObject(fname) ) > 0 ): irit.save( fname, all ) irit.view( all, irit.ON )
teapot = teapotorig * irit.sc( 0.13 ) * irit.rz( 90 ) * irit.rx( 90 ) * irit.sx( (-1 ) ) * irit.trans( ( 0, 0.5, 0.5 ) ) all = irit.list( prmdomain, teapot ) * irit.rz( 90 ) * irit.ry( 40 ) * irit.rx( 40 ) interact( irit.list( all, irit.GetViewMatrix() ) ) irit.save( "warp1trv", all ) # # Warp the teapot, one surface at a time, after some surface refinement. # warpedteapot = irit.nil( ) i = 1 while ( i <= irit.SizeOf( teapot ) ): srf = irit.nth( teapot, i ) clr = irit.getattr( srf, "color" ) srf = irit.sreparam( irit.sreparam( srf, irit.COL, 0, 1 ), irit.ROW, 0,\ 1 ) srf = irit.srefine( irit.srefine( srf, irit.COL, 0, irit.list( 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,\ 0.7, 0.8, 0.9 ) ), irit.ROW, 0, irit.list( 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,\ 0.7, 0.8, 0.9 ) ) irit.attrib( srf, "color", clr ) irit.snoc( warpsurface( srf, tv ), warpedteapot ) i = i + 1 prmdomain = irit.list( irit.strivar( tv, irit.COL, 0 ), irit.strivar( tv, irit.COL, 0.5 ), irit.strivar( tv, irit.ROW, 0.2 ), irit.strivar( tv, irit.ROW, 0.8 ), irit.strivar( tv, irit.DEPTH, 0 ), irit.strivar( tv, irit.DEPTH, 1 ) ) irit.attrib( prmdomain, "transp", irit.GenRealObject(0.8 )) all = irit.list( warpedteapot, prmdomain ) * irit.rx( 90 ) * irit.ry( 20 ) * irit.rx( 10 ) * irit.sc( 0.5 ) interact( irit.list( all, irit.GetViewMatrix() ) )
pln = irit.ruledsrf( irit.ctlpt( irit.E3, (-1 ), (-1 ), 0 ) + \ irit.ctlpt( irit.E3, (-1 ), 1, 0 ), \ irit.ctlpt( irit.E3, 1, (-1 ), 0 ) + \ irit.ctlpt( irit.E3, 1, 1, 0 ) ) irit.color(pln, irit.RED) pts = irit.saccess(pln, irit.GenRealObject(0), psphere, irit.GenRealObject(0), 0.1, 1e-005) spts = irit.nil() sptserr = irit.nil() i = 1 while (i <= irit.SizeOf(pts)): pt = irit.nth(pts, i) err = irit.FetchRealObject(irit.getattr(pt, "rngerror")) if (err > 1e-005): irit.snoc(irit.seval(pln, irit.coord(pt, 1), irit.coord(pt, 2)), sptserr) else: irit.snoc( irit.seval(pln, irit.FetchRealObject(irit.coord(pt, 1)), irit.FetchRealObject(irit.coord(pt, 2))), spts) i = i + 1 irit.color(spts, irit.GREEN) irit.color(sptserr, irit.RED) all = irit.list(psphere, pln, spts, sptserr) irit.save("saccess1", all) irit.interact(all)
# ############################################################################ # # Points # # MSC and CH of points in the plane. # pause(): n = 4 while (n <= 1024): irit.printf("processing %4d 2d pts...", irit.list(n)) p = randompts(n) ch = irit.cnvxhull(p, 0) irit.color(ch, irit.GREEN) irit.adwidth(ch, 2) msc = irit.mscirc(p, irit.GenIntObject(0)) cntr = irit.getattr(msc, "center") rad = irit.getattr(msc, "radius") irit.color(msc, irit.YELLOW) irit.adwidth(msc, 2) irit.view(irit.list(p, msc, ch), irit.ON) irit.printf("done (center = %.5lg %.5lg, radius = %.5lg).\n", irit.list(irit.coord(cntr, 0), irit.coord(cntr, 1), rad)) irit.milisleep(1000) n = n * 2 irit.save("msc_ch1", irit.list(ch, msc, p)) irit.pause() # MSS of points in 3-space. # pause():
irit.ctlpt( irit.E2, 2, 0 ) ), \ irit.list( irit.KV_OPEN ) ) c2 = irit.cbspline( 2, irit.list( irit.ctlpt( irit.E3, 2, (-2 ), 0 ), \ irit.ctlpt( irit.E2, 0, 0 ), \ irit.ctlpt( irit.E2, (-2 ), (-2 ) ) ), \ irit.list( irit.KV_OPEN ) ) ip = irit.ccintrprop(c1, c2, 1e-008) irit.printf("number of intersection loops = %d\n", irit.list(irit.SizeOf(ip) - 1)) inter = irit.nth(ip, 2) irit.color(inter, 4) irit.adwidth(inter, 3) irit.printf("area = %f\n", irit.list(irit.getattr(inter, "area"))) irit.interact(irit.list(c1, c2, inter)) # ################################ view_mat2 = irit.sc(0.5) irit.viewobj(view_mat2) c1 = irit.cbspline( 4, irit.list( irit.ctlpt( irit.E3, 1, 0, 0 ), \ irit.ctlpt( irit.E2, 1, 0.5523 ), \ irit.ctlpt( irit.E2, 0.5523, 1 ), \ irit.ctlpt( irit.E2, (-0.5523 ), 1 ), \ irit.ctlpt( irit.E2, (-1 ), 0.5523 ), \ irit.ctlpt( irit.E2, (-1 ), (-0.5523 ) ), \ irit.ctlpt( irit.E2, (-0.5523 ), (-1 ) ), \
irit.color(crv, irit.RED) srf = irit.swpcircsrf(irit.circle((0, 0, 0), 0.7), 0.2, 0) irit.color(srf, irit.GREEN) menu = menugengeometry( irit.list( "quit", "draw crv", "draw srf", "draw all", "ctl mesh" ), 0.7,\ 0.5, 0.5, 0.95, 0.95 ) irit.color(menu, irit.WHITE) irit.view(irit.list(menu, crv, srf), irit.ON) # Handle only button 1 down events: while (quit == 0): c = irit.clntcrsr(60000) if (irit.SizeOf(c) == 0): irit.printf("time out in input (one minute wait)\n", irit.nil()) quit = 1 else: xypos = irit.ptlnpln(irit.nth(c, 1), irit.nth(c, 2), xyplane) if (irit.getattr(irit.nth(c, 1), "eventtype") == 2): menuindex = irit.menugetselection(irit.coord(xypos, 0), irit.coord(xypos, 1), irit.SizeOf(menu), 0.5, 0.5, 0.95, 0.95) irit.printf( "menu (%f %f) %f\n", irit.list(irit.coord(xypos, 0), irit.coord(xypos, 1), menuindex)) if (menuindex == 1): quit = 1 if (menuindex == 2): irit.view(irit.list(menu, crv), irit.ON) if (menuindex == 3): irit.view(irit.list(menu, srf), irit.ON) if (menuindex == 4):