1 /*
2  * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
3  * Applied Mathematics, Norway.
4  *
5  * Contact information: E-mail: tor.dokken@sintef.no
6  * SINTEF ICT, Department of Applied Mathematics,
7  * P.O. Box 124 Blindern,
8  * 0314 Oslo, Norway.
9  *
10  * This file is part of SISL.
11  *
12  * SISL is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * SISL is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public
23  * License along with SISL. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  * In accordance with Section 7(b) of the GNU Affero General Public
27  * License, a covered work must retain the producer line in every data
28  * file that is created or manipulated using SISL.
29  *
30  * Other Usage
31  * You can be released from the requirements of the license by purchasing
32  * a commercial license. Buying such a license is mandatory as soon as you
33  * develop commercial activities involving the SISL library without
34  * disclosing the source code of your own applications.
35  *
36  * This file may be used in accordance with the terms contained in a
37  * written agreement between you and SINTEF ICT.
38  */
39 
40 #include "sisl-copyright.h"
41 
42 /*
43  *
44  * $Id: s1931unit.c,v 1.2 2001-03-19 15:58:56 afr Exp $
45  *
46  */
47 
48 
49 #define S1931UNIT
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s1931unit(int inbcrv,SISLCurve ** vpcrv,double ** gknot2,double ** gcoef2,int * jn2,int * jord2,int * jstat)55    s1931unit (int inbcrv, SISLCurve ** vpcrv, double **gknot2,
56        double **gcoef2, int *jn2, int *jord2, int *jstat)
57 #else
58 void
59    s1931unit (inbcrv, vpcrv, gknot2, gcoef2, jn2, jord2, jstat)
60      int inbcrv;
61      SISLCurve **vpcrv;
62      double **gknot2;
63      double **gcoef2;
64      int *jn2;
65      int *jord2;
66      int *jstat;
67 #endif
68 /*
69 *********************************************************************
70 *
71 * PURPOSE    : Given a set of curve, put these on a common basis
72 *              using a unit knot vector.
73 *              (Common knot-vector of length (jn2+jord2).
74 *              The vertices are recomputed according to this new basis.
75 *
76 * INPUT      : inbcrv - Number of curves in the curve-set.
77 *              vpcrv  - Array (length inbcrv) of pointers to the
78 *                       curves in the curve-set.
79 *
80 * OUTPUT     : gknot2 - Common knot-vector (new basis) for the curves.
81 *                       (jn2+jord2).
82 *              gcoef2 - The vertices of the inbcrv curves
83 *                       expressed in the new basis. Stored in sequence
84 *                       first curve, second curve,...
85 *              jn2    - The no. of vertices in each of the inbcrv curves.
86 *              jord2  - The order of the new representation of the curves.
87 *              jstat  - Output status:
88 *                        < 0: Error.
89 *                        = 0: Ok.
90 *                        > 0: Warning.
91 *
92 * NOTE	     : The maximal order of the B-spline basis in the lofting
93 *	       direction is no longer used. In earlier version (s1337)
94 *	       the maximal order iord1 was not found, nor calculated.
95 *
96 * CALLS      : s1349,s1933,s1932,s6err.
97 *
98 * WRITTEN BY : Christophe R. Birkeland, SI, 1991-07
99 *
100 *********************************************************************
101 */
102 {
103    int ki;                      /* Counter.                               */
104   double tstart = 0;           	/* Start parameter-value of B-spline basis
105 			         * to be made 			 	  */
106   double tstop = 1;          	/* Stop parameter-value of B-spline basis
107 			         * to be made			  	  */
108   int kstat = 0;		/* Status variable.                         */
109   int kpos = 0;			/* Position of error.                       */
110 
111   SISLCurve **tmp_vpcrv = SISL_NULL;  /* Temporary array for curve pointers   */
112   SISLCurve *pcrv=SISL_NULL;
113 
114   *jstat = 0;
115 
116   /* s1349 make all the curves k-regular, copy curves not to destroy cyclic bases */
117 
118   tmp_vpcrv = new0array(inbcrv, SISLCurve*);
119   if (tmp_vpcrv == SISL_NULL) goto err101;
120 
121   /* Copy all curves */
122   for (ki=0 ; ki<inbcrv ; ki++)
123     {
124        pcrv = SISL_NULL;
125        pcrv = newCurve(vpcrv[ki]->in,vpcrv[ki]->ik,vpcrv[ki]->et,vpcrv[ki]->ecoef,
126 		       vpcrv[ki]->ikind,vpcrv[ki]->idim,1);
127        if (pcrv==SISL_NULL) goto err101;
128        tmp_vpcrv[ki] = pcrv;
129     }
130 
131   /* Be sure that all curves have got an open description. */
132 
133   s1349 (inbcrv, tmp_vpcrv, &kstat);
134   if (kstat < 0) goto error;
135 
136   /* Find common basis for all B-spline curves. */
137 
138   s1933 (inbcrv, tmp_vpcrv, tstart, tstop, gknot2, jn2, jord2, &kstat);
139   if (kstat < 0) goto error;
140 
141   /* Express the curves in the already found basis. */
142 
143   s1932 (inbcrv, tmp_vpcrv, tstart, tstop, *gknot2, *jn2, *jord2, gcoef2, &kstat);
144   if (kstat < 0) goto error;
145 
146   goto out;
147 
148   err101:
149     *jstat = -101;
150     s6err("s1931unit",*jstat,kpos);
151     goto out;
152 
153   /* Error in lower level routine.  */
154 
155   error:
156     *jstat = kstat;
157     s6err ("s1931unit", *jstat, kpos);
158     goto out;
159 
160   out:
161     /* Release allocated curve pointer array and curves */
162 
163     if (tmp_vpcrv != SISL_NULL)
164     {
165 
166       for (ki=0 ; ki<inbcrv ; ki++)
167 	{
168 	  if (tmp_vpcrv[ki] != SISL_NULL) freeCurve(tmp_vpcrv[ki]);
169 	}
170       if (tmp_vpcrv != SISL_NULL) freearray(tmp_vpcrv);
171     }
172 
173     return;
174 }
175