def plotfunc3d2poly(minx, maxx, miny, maxy, n, m): first = 1 x = minx while (x <= maxx): lst = irit.nil() y = miny while (y <= maxy): irit.snoc(irit.vector(x, y, plotfn3d(x, y)), lst) y = y + (maxy - miny) / float(n - 1) if (first == 1): retval = irit.poly(lst, irit.TRUE) first = 0 else: retval = retval + irit.poly(lst, irit.TRUE) x = x + (maxx - minx) / float(m - 1) y = miny while (y <= maxy): lst = irit.nil() x = minx while (x <= maxx): irit.snoc(irit.vector(x, y, plotfn3d(x, y)), lst) x = x + (maxx - minx) / float(n - 1) retval = retval + irit.poly(lst, irit.TRUE) y = y + (maxy - miny) / float(m - 1) return retval
def evaltv(tv, ulen, vlen, wlen): retval = irit.nil() dom = irit.pdomain(tv) i = 0 while (i <= ulen - 1): u = irit.FetchRealObject(irit.nth(dom, 1)) + i * irit.FetchRealObject( irit.nth(dom, 2) - irit.nth(dom, 1)) / float(ulen - 1) lst2 = irit.nil() j = 0 while (j <= vlen - 1): v = irit.FetchRealObject(irit.nth( dom, 3)) + j * irit.FetchRealObject( irit.nth(dom, 4) - irit.nth(dom, 3)) / float(vlen - 1) lst3 = irit.nil() k = 0 while (k <= wlen - 1): w = irit.FetchRealObject(irit.nth( dom, 5)) + k * irit.FetchRealObject( irit.nth(dom, 6) - irit.nth(dom, 5)) / float(wlen - 1) irit.snoc(irit.teval(tv, u, v, w), lst3) k = k + 1 irit.snoc(lst3 * irit.tx(0), lst2) j = j + 1 irit.snoc(lst2 * irit.tx(0), retval) i = i + 1 retval = irit.tbezier(retval) return retval
def evalonebitangency(srfs, pts): ruling = irit.nil() tmp1pts = irit.nil() tmp2pts = irit.nil() if (irit.ThisObject(srfs) == irit.SURFACE_TYPE): srf1 = srfs srf2 = srfs else: srf1 = irit.nth(srfs, 1) srf2 = irit.nth(srfs, 2) i = 1 while (i <= irit.SizeOf(pts)): pt = irit.nth(pts, i) pt1 = irit.seval(srf1, irit.FetchRealObject(irit.coord(pt, 1)), irit.FetchRealObject(irit.coord(pt, 2))) pt2 = irit.seval(srf2, irit.FetchRealObject(irit.coord(pt, 3)), irit.FetchRealObject(irit.coord(pt, 4))) irit.snoc(pt1 + pt2, ruling) irit.snoc(pt1 * irit.tx(0), tmp1pts) irit.snoc(pt2 * irit.tx(0), tmp2pts) i = i + 1 irit.attrib(ruling, "rgb", irit.GenStrObject("255, 128, 128")) if (irit.SizeOf(tmp1pts) > 1 and irit.SizeOf(tmp2pts) > 1): tmp1pts = irit.poly(tmp1pts, irit.TRUE) tmp2pts = irit.poly(tmp2pts, irit.TRUE) irit.attrib(tmp1pts, "rgb", irit.GenStrObject("128, 255, 128")) irit.attrib(tmp2pts, "rgb", irit.GenStrObject("128, 255, 128")) retval = irit.list(ruling, tmp1pts, tmp2pts) else: retval = irit.nil() return retval
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 printctlpoint( cpt ): s = irit.SizeOf( cpt ) if ( s < 0 ): irit.printf( "\t[w=%-9.6lg ", irit.list( irit.coord( cpt, 0 ) ) ) s = (-s ) else: irit.printf( "\t[", irit.nil( ) ) i = 1 while ( i <= s ): irit.printf( "%9.6lg ", irit.list( irit.coord( cpt, i ) ) ) i = i + 1 irit.printf( "]\n", irit.nil( ) )
def crveqlparamsegmarkers(c): crvswsegs = irit.nil() crvsbsegs = irit.nil() numsegs = 10 i = 1 while (i <= numsegs): irit.snoc(irit.cregion(c, (i - 1) / numsegs, (i - 0.5) / numsegs), crvswsegs) irit.snoc(irit.cregion(c, (i - 0.5) / numsegs, (i - 0) / numsegs), crvsbsegs) i = i + 1 irit.color(crvswsegs, irit.RED) irit.color(crvsbsegs, irit.YELLOW) retval = irit.list(crvswsegs, crvsbsegs) return retval
def getlistwithoutlast( lst ): retval = irit.nil( ) i = 1 while ( i <= irit.SizeOf( lst ) - 1 ): irit.snoc( irit.nth( lst, i ), retval ) i = i + 1 return retval
def evalantipodalptsonsrf( srf ): aps = irit.antipodal( srf, 0.001, (-1e-012 ) ) irit.printf( "%d antipodal points detected\n", irit.list( irit.SizeOf( aps ) ) ) retval = irit.nil( ) diam = 0 i = 1 while ( i <= irit.SizeOf( aps ) ): ap = irit.nth( aps, i ) u1 = irit.coord( ap, 1 ) v1 = irit.coord( ap, 2 ) u2 = irit.coord( ap, 3 ) v2 = irit.coord( ap, 4 ) pt1 = irit.seval( srf, irit.FetchRealObject(u1), irit.FetchRealObject(v1) ) pt2 = irit.seval( srf, irit.FetchRealObject(u2), irit.FetchRealObject(v2) ) if ( irit.dstptpt( irit.coerce( pt1, irit.POINT_TYPE ), irit.coerce( pt2, irit.POINT_TYPE ) ) > diam ): diam = irit.dstptpt( irit.coerce( pt1, irit.POINT_TYPE ), irit.coerce( pt2, irit.POINT_TYPE ) ) diamline = pt1 + pt2 irit.snoc( irit.list( pt1 + pt2, pt1 * irit.tx( 0 ), pt2 * irit.tx( 0 ) ), retval ) i = i + 1 irit.color( retval, irit.YELLOW ) irit.color( diamline, irit.CYAN ) irit.adwidth( diamline, 3 ) irit.snoc( irit.list( diamline ), retval ) 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 printknotvector( str, kv ): irit.printf( " [%sknotvector:", irit.list( str ) ) i = 1 while ( i <= irit.SizeOf( kv ) ): irit.printf( " %-.6lg", irit.list( irit.nth( kv, i ) ) ) i = i + 1 irit.printf( "]\n", irit.nil( ) )
def buildvisibilitymap( c, step, highlightangle ): retval = irit.nil( ) i = 0 while ( i <= 360 ): dir = irit.point( math.cos( i * math.pi/180 ), math.sin( i * 3.14159/180 ), 0 ) crvs = irit.cvisible( c, irit.Fetch3TupleObject(dir), 1e-005 ) crvdmn = cnvrtcrvs2domains( crvs, i ) if ( highlightangle == i ): irit.attrib( crvdmn, "width", irit.GenRealObject(0.01 )) irit.attrib( crvdmn, "gray", irit.GenRealObject(0 )) irit.attrib( crvdmn, "rgb", irit.GenStrObject("255, 255, 128" )) irit.adwidth( crvdmn, 3 ) highcrvdmn = crvdmn * irit.sx( 1/360.0 ) irit.attrib( crvs, "width", irit.GenRealObject(0.03 )) irit.adwidth( crvs, 3 ) irit.attrib( crvs, "rgb", irit.GenStrObject("255, 255, 128" )) irit.snoc( crvs, retval ) else: irit.attrib( crvdmn, "width", 0.01 ) irit.attrib( crvdmn, "gray", 0.5 ) irit.attrib( crvdmn, "rgb", "128, 128, 255" ) irit.snoc( crvdmn * irit.sx( 1/360 ), retval ) i = i + step retval = ( retval + irit.list( highcrvdmn ) ) return retval
def evaltritangency(srfs, pts): retval = irit.nil() if (irit.ThisObject(srfs) == irit.SURFACE_TYPE): srf1 = srfs srf2 = srfs srf3 = srfs else: srf1 = irit.nth(srfs, 1) srf2 = irit.nth(srfs, 2) srf3 = irit.nth(srfs, 3) i = 1 while (i <= irit.SizeOf(pts)): pt = irit.nth(pts, i) irit.snoc( irit.seval(srf1, irit.FetchRealObject(irit.coord(pt, 1)), irit.FetchRealObject(irit.coord(pt, 2))) + irit.seval(srf2, irit.FetchRealObject(irit.coord(pt, 3)), irit.FetchRealObject(irit.coord(pt, 4))), retval) irit.snoc( irit.seval(srf1, irit.FetchRealObject(irit.coord(pt, 1)), irit.FetchRealObject(irit.coord(pt, 2))) + irit.seval(srf3, irit.FetchRealObject(irit.coord(pt, 5)), irit.FetchRealObject(irit.coord(pt, 6))), retval) irit.snoc( irit.seval(srf2, irit.FetchRealObject(irit.coord(pt, 3)), irit.FetchRealObject(irit.coord(pt, 4))) + irit.seval(srf3, irit.FetchRealObject(irit.coord(pt, 5)), irit.FetchRealObject(irit.coord(pt, 6))), retval) i = i + 1 return retval
def srflistframecrvs(srflist, width): retval = irit.nil() i = 1 while (i <= irit.SizeOf(srflist)): retval = retval + srfframecrvs(irit.nth(srflist, i), width) i = i + 1 return retval
def srflineinter( srf, pt1, pt2, dir, param, numsegs,\ tol ): pta = irit.srinter(srf, irit.Fetch3TupleObject(pt1), dir, tol) ptb = irit.srinter( srf, irit.Fetch3TupleObject( ppblend(irit.Fetch3TupleObject(pt1), irit.Fetch3TupleObject(pt2), 2 / 3.0)), dir, tol) ptc = irit.srinter( srf, irit.Fetch3TupleObject( ppblend(irit.Fetch3TupleObject(pt1), irit.Fetch3TupleObject(pt2), 1 / 3.0)), dir, tol) ptd = irit.srinter(srf, irit.Fetch3TupleObject(pt2), dir, tol) crv = irit.bsp2bzr( irit.cinterp(irit.list(pta, ptb, ptc, ptd), 4, 4, irit.GenRealObject(param), 0)) crvs = irit.nil() i = 1 while (i <= numsegs): c = irit.cregion(crv, (i - 1) / float(numsegs), i / float(numsegs)) irit.color(c, i) irit.snoc(c, crvs) i = i + 1 retval = crvs return retval
def virttree3(pos, dir, size, blevel, level): retval = irit.nil() newpos = (pos + dir) if (level > 0): tr = treebranch(pos, newpos, size) if (level >= blevel): irit.color(tr, bcolor) irit.attrib(tr, "ptexture", irit.GenStrObject("trunk.rle")) irit.attrib(tr, "rgb", irit.GenStrObject(brgb)) else: irit.color(tr, lcolor) irit.attrib(tr, "rgb", irit.GenStrObject(lrgb)) irit.attrib(tr, "ptexture", irit.GenStrObject("leaves.rle")) irit.snoc(tr, retval) if (level > 1): tr1 = virttree3(newpos, rotatevector2(dir, rfactor) * lfactor, size * wfactor, blevel, level - 1) tr2 = virttree3( newpos, rotatevector2(dir, rfactor * irit.random((-1), 1)) * lfactor, size * wfactor, blevel, level - 1) tr3 = virttree3(newpos, rotatevector2(dir, (-rfactor)) * lfactor, size * wfactor, blevel, level - 1) retval = retval + tr1 + tr2 + tr3 return retval
def offsetcrvlist( clst, ofst ): retval = irit.nil( ) i = 1 while ( i <= irit.SizeOf( clst ) ): irit.snoc( irit.offset( irit.nth( clst, i ), irit.GenRealObject(ofst), 1e-006, 1 ), retval ) i = i + 1 return retval
def plotfunc2d2poly(min, max, n): lst = irit.nil() t = min while (t <= max): irit.snoc(irit.vector(t, plotfn2d(t), 0), lst) t = t + (max - min) / float(n - 1) retval = irit.poly(lst, irit.TRUE) return retval
def layouthandletrimmedsrfs(tsrfs, highlighttrim): retval = irit.nil() i = 1 while (i <= irit.SizeOf(tsrfs)): irit.snoc(layouthandleonetrimmed(irit.nth(tsrfs, i), highlighttrim), retval) i = i + 1 return retval
def printcurve( crv ): orders = irit.fforder( crv ) msize = irit.ffmsize( crv ) irit.printf( "curve of order %d, poly size %d and point type %s\n", orders + msize + irit.list( getpointtype( irit.coord( crv, 0 ) ) ) ) irit.printf( "control polygon:\n", irit.nil( ) ) printctlmesh( crv ) if ( 1 ): kvs = irit.ffkntvec( crv ) printknotvector( "u ", irit.nth( kvs, 1 ) )
def cnvrtcrvs2domains( crvs, theta ): retval = irit.nil( ) i = 1 while ( i <= irit.SizeOf( crvs ) ): dm = irit.pdomain( irit.nth( crvs, i ) ) irit.snoc( irit.ctlpt( irit.E2, theta, irit.nth( dm, 1 ) ) + \ irit.ctlpt( irit.E2, theta, irit.nth( dm, 2 ) ), retval ) i = i + 1 return retval
def intercrvspaint(crvs): retval = irit.nil() i = 1 while (i <= irit.SizeOf(crvs)): crv = irit.nth(crvs, i) irit.attrib(crv, "rgb", irit.GenStrObject(getrandrgb())) irit.snoc(crv * irit.sc(1), retval) i = i + 1 return retval
def buildvisibilitymap( c, step ): retval = irit.nil( ) i = 0 while ( i <= 360 ): dir = irit.point( math.cos( i * math.pi/180 ), math.sin( i * math.pi/180 ), 0 ) crvs = irit.cvisible( c, dir, 1e-005 ) irit.snoc( cnvrtcrvs2domains( crvs, i ) * irit.sx( 1/360.0 ), retval ) i = i + step return retval
def shelfunit( w, dw, h, dh, n ): retval = irit.nil( ) i = 1 while ( i <= n ): irit.snoc( marbleshelfunit( w, h ), retval ) w = w - dw h = h + dh i = i + 1 return retval
def computeviews( c, dms, fname ): ranges = irit.nil( ) i = 1 while ( i <= irit.SizeOf( dms ) ): irit.snoc( cnvrtcrvs2ranges( irit.nth( dms, i ), i, 1 ), ranges ) i = i + 1 irit.printf( "%d views are considered\n", irit.list( irit.SizeOf( dms ) ) ) retval = irit.setcover( ranges, 0.001 ) return retval
def plgntoplln( pl ): retval = irit.nil( ) j = 0 while ( j <= irit.SizeOf( pl ) - 1 ): irit.snoc( irit.coord( pl, j ), retval ) j = j + 1 irit.snoc( irit.coord( pl, 0 ), retval ) retval = irit.poly( retval, irit.TRUE ) irit.attrib( retval, "dwidth", irit.GenIntObject(3 )) return retval
def gammakernelpolysrfs( pl, maxgamma, extent ): retval = irit.nil( ) i = 1 while ( i <= irit.SizeOf( pl ) ): c = irit.coerce( irit.coord( pl, i - 1 ), irit.E2 ) + irit.coerce( irit.coord( pl, i ), irit.E2 ) k1 = irit.crvkernel( c, maxgamma, 0, irit.GenRealObject(extent), 2 ) k2 = irit.crvkernel( c, (-maxgamma ), 0, irit.GenRealObject(extent), 2 ) irit.snoc( irit.list( setrandomcolor( k1 ), setrandomcolor( k2 ) ), retval ) i = i + 1 return retval
def printsurface( srf ): orders = irit.fforder( srf ) msize = irit.ffmsize( srf ) irit.printf( "surface of orders %d x %d, mesh size %d x %d and point type %s\n", orders + msize + irit.list( getpointtype( irit.coord( srf, 0 ) ) ) ) irit.printf( "control mesh:\n", irit.nil( ) ) printctlmesh( srf ) if ( 1 ): kvs = irit.ffkntvec( srf ) printknotvector( "u ", irit.nth( kvs, 1 ) ) printknotvector( "v ", irit.nth( kvs, 2 ) )
def makepolylines(listofctlpts): retval = irit.nil() i = 1 while (i <= irit.SizeOf(listofctlpts)): pl = irit.nth(listofctlpts, i) if (irit.SizeOf(pl) > 1): irit.snoc(irit.poly(irit.nth(listofctlpts, i), 1), retval) i = i + 1 return retval
def textgeom3d(txt, wdth, dpth): if (irit.ThisObject(txt) == irit.LIST_TYPE): retval = irit.nil() i = 1 while (i <= irit.SizeOf(txt)): irit.snoc(textgeom3d(irit.nth(txt, i), wdth, dpth), retval) i = i + 1 else: retval = textgeom3daux(txt, wdth, dpth) return retval
def randomcrvs(numcrvs, crvdeg, crvlen, size): l = irit.nil() i = 1 while (i <= numcrvs): irit.snoc(genrandomcrv(crvdeg, crvlen, size), l) i = i + 1 retval = l irit.color(retval, irit.RED) irit.adwidth(retval, 3) return retval