home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
graphic
/
irit
/
bspline.irt
< prev
next >
Wrap
Text File
|
1991-12-15
|
7KB
|
312 lines
#
# Some routines to test bspline curves/surfaces.
#
#
# Set display to on to view some results, off to view nothing.
#
display = on;
resolution = 10;
if ( machine, "=", msdos, (resolution = 5));
s45 = sin( pi / 4 );
cbsp = list( ctlpt( P2, 1.0, 1.0, 0.0 ),
ctlpt( P2, s45, s45, s45 ),
ctlpt( P2, 1.0, 0.0, 1.0 ) );
sbsp = list ( list( ctlpt( E3, 0.0, 0.0, 1.0 ),
ctlpt( E3, 0.0, 1.0, 0.0 ),
ctlpt( E3, 0.0, 2.0, 1.0 ) ),
list( ctlpt( E3, 1.0, 0.0, 0.0 ),
ctlpt( E3, 1.0, 1.0, 2.0 ),
ctlpt( E3, 1.0, 2.0, 0.0 ) ),
list( ctlpt( E3, 2.0, 0.0, 2.0 ),
ctlpt( E3, 2.0, 1.0, 0.0 ),
ctlpt( E3, 2.0, 2.0, 2.0 ) ),
list( ctlpt( E3, 3.0, 0.0, 0.0 ),
ctlpt( E3, 3.0, 1.0, 2.0 ),
ctlpt( E3, 3.0, 2.0, 0.0 ) ),
list( ctlpt( E3, 4.0, 0.0, 1.0 ),
ctlpt( E3, 4.0, 1.0, 0.0 ),
ctlpt( E3, 4.0, 2.0, 1.0 ) ) );
cb = cbspline( 3, cbsp, list( 0, 0, 0, 1, 1, 1 ) );
color( cb, red );
sb = sbspline( 3, 3, sbsp, list( list( 1, 1, 1, 2, 2, 2 ),
list( 3, 3, 3, 4, 5, 6, 6, 6 ) ) );
color( sb, red );
drawctlpt = 0;
if ( display, "=", on, interact( list( axes, cb, sb ), 0 ) );
drawctlpt = blue;
if ( display, "=", on, interact( list( axes, cb, sb ), 0 ) );
drawctlpt = 0;
#
# Curve refinement.
#
cb_ref = crefine( cb, false, list( 0.25, 0.5, 0.75 ) );
color( cb_ref, yellow );
if ( display, "=", on, interact( list( axes, cb, cb_ref ), 0 ) );
free( cb_ref );
#
# Knot substitution (One internal knot is moved from 0.1 to 0.9).
#
cb_ref = crefine( cb, false, list( 0.5 ) );
cb_all = list( axes );
cb1 = 0; # Define a dummy variable to use in loop.
for ( (t = 0.1), 0.1, 0.9,
(
(cb1 = crefine( cb_ref, true, list( 0, 0, 0, t, 1, 1, 1 ) ) ):
color( cb1, green ):
snoc( cb1, cb_all )
)
);
if ( display, "=", on, interact( cb_all, 0 ) );
free( cb_all );
#
# Curve subdivision.
#
cb_lst = cdivide( cb, 0.5 );
cb1 = nth( cb_lst, 1 );
color( cb1, green );
cb2 = nth( cb_lst, 2 );
color( cb2, yellow );
free( cb_lst );
if ( display, "=", on, interact( list( axes, cb, cb1, cb2 ), 0 ) );
free( cb1 );
free( cb2 );
#
# Region from curve.
#
cbr1 = cregion( cb, 0.3, 0.6 );
color( cbr1, yellow );
cbr2 = cregion( cb, 0.5, 1.0 );
color( cbr2, green );
cbr3 = cregion( cb, 0.3, 0.0 );
color( cbr3, blue );
interact( list( cb, cbr1, cbr2, cbr3 ), 0 );
free( cbr1 ); free( cbr2 ); free( cbr3 );
#
# Surface subdivision.
#
sb_lst = sdivide( sb, COL, 1.4 );
sb1 = nth( sb_lst, 1 );
color( sb1, green );
sb2 = nth( sb_lst, 2 );
color( sb2, yellow );
free( sb_lst );
if ( display, "=", on, interact( list( axes, sb, sb1, sb2 ), 0 ) );
free( sb1 );
free( sb2 );
sb_lst = sdivide( sb, ROW, 4.8 );
sb1 = nth( sb_lst, 1 );
color( sb1, green );
sb2 = nth( sb_lst, 2 );
color( sb2, yellow );
free( sb_lst );
if ( display, "=", on, interact( list( axes, sb, sb1, sb2 ), 0 ) );
free( sb1 ); free( sb2 );
#
# Region from surface.
#
sbr1 = sregion( sb, COL, 1.3, 1.6 );
color( sbr1, yellow );
sbr2 = sregion( sb, COL, 1.8, 2.0 );
color( sbr2, green );
sbr3 = sregion( sb, ROW, 4.0, 5.0 );
color( sbr3, blue );
interact( list( sb, sbr1, sbr2, sbr3 ), 0);
free( sbr1 ); free( sbr2 ); free( sbr3 );
#
# Iso curves extraction from surface.
#
cb_all = list( axes );
snoc( sb, cb_all );
cb1 = 0; # Define a dummy variable to use in loop.
for ( (t = 1.1), 0.1, 1.9,
(
( cb1 = csurface( sb, COL, t ) ):
color( cb1, green ):
snoc( cb1, cb_all )
)
);
for ( (t = 3.1), 0.2, 5.9,
(
( cb1 = csurface( sb, ROW, t ) ):
color( cb1, green ):
snoc( cb1, cb_all )
)
);
if ( display, "=", on, interact( cb_all, 0 ) );
free( cb_all );
#
# curves extraction from surface mesh. Note curves may be not on the surface.
#
cb_all = list( axes );
snoc( sb, cb_all );
cb1 = 0; # Define a dummy variable to use in loop.
for ( (t = 0), 1, 2,
(
( cb1 = cmesh( sb, COL, t ) ):
color( cb1, green ):
snoc( cb1, cb_all )
)
);
for ( (t = 0), 1, 4,
(
( cb1 = cmesh( sb, ROW, t ) ):
color( cb1, green ):
snoc( cb1, cb_all )
)
);
drawctlpt = blue;
if ( display, "=", on, interact( cb_all, 0 ) );
drawctlpt = 0;
free( cb_all );
#
# convert into polygons/polylines (using default resolution).
#
dumplvl = 1;
resolution;
p = gpolyline( list( sb, cb ) );
if ( display, "=", on, interact( list( p, axes ), 0 ) );
p = gpolygon( sb );
if ( display, "=", on, interact( list( p, axes ), 0 ) );
#
# reverse surface ( flip normals ).
#
q = gpolygon( -sb );
normal( on, 0.1, green );
if ( display, "=", on, interact( list( p, q, axes ), 0 ) );
normal( off, 0.1, green );
free(p);
free(q);
#
# Offset approximation by translation of srf/crv in normal direction.
#
cbo = offset(cb, 0.1);
if ( display, "=", on, interact( list( axes, cb, cbo ), 0 ) );
free(cbo);
sbo = offset(sb, 0.2);
if ( display, "=", on, interact( list( axes, sb, sbo ), 0 ) );
free(sbo);
#
# Surface and Curve evaluation.
#
v1 = ceval( cb, 0.0 );
v2 = ceval( cb, 0.1 );
v3 = ceval( cb, 0.3 );
v4 = ceval( cb, 0.5 );
v5 = ceval( cb, 0.9 );
v6 = ceval( cb, 1.0 );
v1;
v2;
v3;
v4;
v5;
v6;
v7 = ceval( cb, -0.3 );
pause(1);
w1 = seval( sb, 1.0, 3.0 );
w2 = seval( sb, 1.1, 3.0 );
w3 = seval( sb, 1.3, 3.0 );
w4 = seval( sb, 1.5, 3.5 );
w5 = seval( sb, 1.9, 3.1 );
w6 = seval( sb, 1.0, 4.0 );
w7 = seval( sb, 1.5, 4.0 );
w1;
w2;
w3;
w4;
w5;
w6;
w7;
w7 = seval( sb, 0.5, 4.0 );
pause(1);
#
#
# Surface and Curve tangents.
#
v1 = ctangent( cb, 0.0 );
v2 = ctangent( cb, 0.1 );
v3 = ctangent( cb, 0.3 );
v4 = ctangent( cb, 0.5 );
v5 = ctangent( cb, 0.9 );
v6 = ctangent( cb, 1.0 );
v1;
v2;
v3;
v4;
v5;
v6;
pause(1);
w1 = stangent( sb, 1, 1.0, 3.0 );
w2 = stangent( sb, 2, 1.1, 3.0 );
w3 = stangent( sb, 1, 1.3, 3.0 );
w4 = stangent( sb, 2, 1.5, 3.5 );
w5 = stangent( sb, 1, 1.9, 3.1 );
w6 = stangent( sb, 2, 1.0, 4.0 );
w7 = stangent( sb, 2, 1.5, 4.0 );
w1;
w2;
w3;
w4;
w5;
w6;
w7;
#
#
# Surface normals.
#
w1 = snormal( sb, 1.0, 3.0 );
w2 = snormal( sb, 1.1, 3.0 );
w3 = snormal( sb, 1.3, 3.0 );
w4 = snormal( sb, 1.5, 3.5 );
w5 = snormal( sb, 1.9, 3.1 );
w6 = snormal( sb, 1.0, 4.0 );
w7 = snormal( sb, 1.5, 4.0 );
w1;
w2;
w3;
w4;
w5;
w6;
w7;
pause(1);
#
# save("cb", cb);
# save("sb", sb);
#
# cb1 = load("cb.crv");
# sb1 = load("sb.srf");
#
# save("cb1", cb1);
# save("sb1", sb1);
#