
/* $XConsortium: nurbss1.pi,v 5.2 94/04/17 20:48:55 rws Exp $ */

/*****************************************************************

Copyright (c) 1989, 1990, 1991,1990  X Consortium

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.

Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its 
documentation for any purpose and without fee is hereby granted, 
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in 
supporting documentation, and that the names of Sun Microsystems,
and the X Consortium, not be used in advertising or publicity 
pertaining to distribution of the software without specific, written 
prior permission.  

SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/

## nurbss1.pi
## test nurbs surface geometry with trimming curves
## 	. 1 trim curve consisting of 1 curve
## 	. 1 trim curve consisting of 2 curves
## 	. 2 trim curves each consisting of 1 curve

source macro.pi

tbegintest("nurbss1","nurbs surface geometry with trimming curves");

# initialize: nurbs surface data structures 

# nurbs surfaces of order u=3,v=4

fa1 = IA_Pfloat(6, 0.0,0.0,0.0,1.0,1.0,1.0);
fa2 = IA_Pfloat(8, 0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0);
knots1 = I_Pfloat_list(6,fa1);
knots2 = I_Pfloat_list(8,fa2);
spts1 = IA_Ppoint3(12, 0.3,0.2,0.0, 0.4,0.25,0.1, 0.5,0.2,0.0,
                     0.2,0.3,0.1, 0.3,0.35,0.3, 0.4,0.3,0.2,
                     0.3,0.4,0.0, 0.4,0.45,0.2, 0.5,0.4,0.0,
                     0.2,0.5,0.2, 0.3,0.55,0.0, 0.4,0.5,0.2);
spts2 = IA_Ppoint3(12, 0.7,0.2,0.0, 0.8,0.25,0.1, 0.9,0.2,0.0,
                     0.6,0.3,0.1, 0.7,0.35,0.3, 0.8,0.3,0.2,
                     0.7,0.4,0.0, 0.8,0.45,0.2, 0.9,0.4,0.0,
                     0.6,0.5,0.2, 0.7,0.55,0.0, 0.8,0.5,0.2);
spts3 = IA_Ppoint3(12, 0.7,0.6,0.0, 0.8,0.65,0.1, 0.9,0.6,0.0,
                     0.6,0.7,0.1, 0.7,0.75,0.3, 0.8,0.7,0.2,
                     0.7,0.8,0.0, 0.8,0.85,0.2, 0.9,0.8,0.0,
                     0.6,0.9,0.2, 0.7,0.95,0.0, 0.8,0.9,0.2);
spts4 = IA_Ppoint3(12, 0.3,0.6,0.0, 0.4,0.65,0.1, 0.5,0.6,0.0,
                     0.2,0.7,0.1, 0.3,0.75,0.3, 0.4,0.7,0.2,
                     0.3,0.8,0.0, 0.4,0.85,0.2, 0.5,0.8,0.0,
                     0.2,0.9,0.2, 0.3,0.95,0.0, 0.4,0.9,0.2);

grid1 = I_Ppoint_grid34(3,4,"3D",spts1);
grid2 = I_Ppoint_grid34(3,4,"3D",spts2);
grid3 = I_Ppoint_grid34(3,4,"3D",spts3);
grid4 = I_Ppoint_grid34(3,4,"3D",spts4);
characs1 = I_Ppara_surf_characs(3,PCP_UNIFORM,6,9);

#. 1 trim curve consisting of 1 curve
pts1 = IA_Ppoint(4, 0.35,0.05, 0.95,0.95, 0.25,0.95, 0.35,0.05);
tcfa1 = IA_Pfloat(8, 0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0);
tcknots1 = I_Pfloat_list(8,tcfa1);
cpts1 = I_Ppoint_list23(4,"2D",pts1);
tc1 = I_Ptrimcurve(PEDGE_ON,PNON_RATIONAL,4,
	PCURV_CONSTANT_PARAMETRIC_BETWEEN_KNOTS,10.0,tcknots1,0.0,1.0,cpts1);
tcl1 = I_Ptrimcurve_list(1, &tc1);
tclist1 = IA_Ptrimcurve_list(1, tcl1);


#. 2 trim curves each consisting of 1 curve
pts21 = IA_Ppoint(5, 0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0, 0.0,0.0);
pts22 = IA_Ppoint(4, 0.35,0.05, 0.25,0.95, 0.95,0.95, 0.35,0.05);
tcfa21 = IA_Pfloat(7, 0.0,1.0,2.0,3.0,4.0,5.0,6.0);
tcfa22 = IA_Pfloat(8, 0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0);
tcknots21 = I_Pfloat_list(8,tcfa21);
tcknots22 = I_Pfloat_list(7,tcfa22);
cpts21 = I_Ppoint_list23(5,"2D",pts21);
cpts22 = I_Ppoint_list23(4,"2D",pts22);
tc21 = I_Ptrimcurve(PEDGE_ON,PNON_RATIONAL,2,
	PCURV_CONSTANT_PARAMETRIC_BETWEEN_KNOTS,10.0,tcknots21,0.0,6.0,cpts21);
tc22 = I_Ptrimcurve(PEDGE_ON,PNON_RATIONAL,4,
	PCURV_CONSTANT_PARAMETRIC_BETWEEN_KNOTS,10.0,tcknots22,0.0,1.0,cpts22);
tcl21 = I_Ptrimcurve_list(1, &tc21);
tcl22 = I_Ptrimcurve_list(1, &tc22);
tclist2 = IA_Ptrimcurve_list(2, tcl21,tcl22);

#. 1 trim curve consisting of 2 curves
pts31 = IA_Ppoint(3, 0.25,0.25, 0.75,0.25, 0.75,0.75);
tcfa31 = IA_Pfloat(6, 0.0,0.0,0.0,1.0,1.0,1.0);
tcknots31 = I_Pfloat_list(6,tcfa31);
cpts31 = I_Ppoint_list23(3,"2D",pts31);
tc31 = I_Ptrimcurve(PEDGE_ON,PNON_RATIONAL,3,
	PCURV_CONSTANT_PARAMETRIC_BETWEEN_KNOTS,10.0,tcknots31,0.0,1.0,cpts31);
pts32 = IA_Ppoint(2, 0.5,0.75, 0.25,0.75, 0.25,0.25);
tcfa32 = IA_Pfloat(6, 0.0,0.0,0.0,1.0,1.0,1.0);
tcknots32 = I_Pfloat_list(6,tcfa32);
cpts32 = I_Ppoint_list23(3,"2D",pts32);
tc32 = I_Ptrimcurve(PEDGE_ON,PNON_RATIONAL,3,
	PCURV_CONSTANT_PARAMETRIC_BETWEEN_KNOTS,10.0,tcknots32,0.0,1.0,cpts32);
tc3132 = IA_Ptrimcurve(2,tc31,tc32);

tcl3 = I_Ptrimcurve_list(1, tc3132);
tclist3 = IA_Ptrimcurve_list(1, tcl3);

# setup: open phigs, workstation, open and post a structure
i_open_phigs(NULL,0);
i_open_x_ws(1,&xdisplay,&xwindow,0,0,200,200);
popen_struct(1);

pset_int_colr_ind(2);
pset_surf_approx(PSURF_CONSTANT_PARAMETRIC_BETWEEN_KNOTS,10.0,10.0);

#non-rational
pset_para_surf_characs(PSC_ISOPARAMETRIC_CURVES,&characs1);
pnuni_bsp_surf(3,4,&knots1,&knots2,PNON_RATIONAL,&grid1,1,tclist1);
pnuni_bsp_surf(3,4,&knots1,&knots2,PNON_RATIONAL,&grid2,2,tclist2);
pnuni_bsp_surf(3,4,&knots1,&knots2,PNON_RATIONAL,&grid3,1,tclist3);
pnuni_bsp_surf(3,4,&knots1,&knots2,PNON_RATIONAL,&grid4,0,NULL);

ppost_struct(1,1,1.0);

# verify image
i_check_image("nurbss1",xdisplay,xwindow,0,0,199,199,
	"nurbs surface geometry with trimming curves");

i_pause();

tendtest();
