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: s1909.c,v 1.2 2001-03-19 15:58:56 afr Exp $
45  *
46  */
47 
48 
49 #define S1909
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s1909(double econd[],int ntype[],int inpt,int idim,int iopen,double astpar,double * cendpar,double * epar1[],double * epar2[],int * jstat)55 s1909 (double econd[], int ntype[], int inpt, int idim, int iopen,
56        double astpar, double *cendpar, double *epar1[],
57        double *epar2[], int *jstat)
58 #else
59 void
60 s1909 (econd, ntype, inpt, idim, iopen, astpar, cendpar, epar1, epar2, jstat)
61      double econd[];
62      int ntype[];
63      int inpt;
64      int idim;
65      int iopen;
66      double astpar;
67      double *cendpar;
68      double *epar1[];
69      double *epar2[];
70      int *jstat;
71 #endif
72 /*
73 *********************************************************************
74 *
75 * PURPOSE    : Make cord length parametrization of interpolation
76 *              conditions. Derivative conditions are given the same value
77 *	       as the corresponding point condition.
78 *
79 * INPUT      : econd  - Array of interpolation conditions. The last
80 *                       condition must be a point. Dimension is inpt*idim.
81 *              ntype  - Array containing kind of condition. Dimension
82 *                       is inpt.
83 *                       =  0 : A point is given.
84 *                       =  d : The d'th derivatative condition to the
85 *                              previous point is given.
86 *                       = -d : The d'th derivatative condition to the
87 *                              next point is given.
88 *              inpt   - Number of interpolation conditions.
89 *              idim   - Dimension of geometry space.
90 *	       iopen  - Open/closed curve.
91 *              astpar - Start parameter of parametrization.
92 *
93 * OUTPUT     : cendpar - End parameter of parametrization.
94 *              epar1   - Parametrization array. Derivative conditions has
95 *                        got the same parameter value as the corresponding
96 *                        positional condition.
97 *              epar2   - Parametrization array to use when making a knot
98 *                        vector. All entries are different.
99 *              jstat  - status messages
100 *                                         > 0      : warning
101 *                                         = 0      : ok
102 *                                         < 0      : error
103 *
104 * METHOD     :
105 *
106 * REFERENCES :
107 *
108 * CALLS      : s6dist,s6err.
109 *
110 * WRITTEN BY : Trond Vidar Stensby, SI, 1991-07
111 *
112 *********************************************************************
113 */
114 {
115   int count1, count2, count3;	/* Loop control variables. */
116   int knpt;			/* Number of parameter values to
117 				   be produced. */
118 
119   double kpar, npar;		/* Used when calculating
120 				   the parameter values. */
121   int kpos = 0;
122 
123   *jstat = 0;
124 
125 
126   if (iopen != SISL_CRV_OPEN)
127     knpt = inpt + 1;
128   else
129     knpt = inpt;
130 
131 
132   /* Allocate arrays. */
133 
134   *epar1 = newarray (knpt, DOUBLE);
135   if (*epar1 == SISL_NULL)
136     goto err101;
137 
138   *epar2 = newarray (knpt, DOUBLE);
139   if (*epar2 == SISL_NULL)
140     goto err101;
141 
142   (*epar1)[0] = astpar;
143   kpar = astpar;
144 
145   for (count1 = 1, kpar = astpar; count1 < inpt; count1++)
146     {
147       if (ntype[count1] == 0)
148 	{
149 	  kpar += s6dist (&econd[(count1 - 1) * idim], &econd[count1 * idim], idim);
150 	  (*epar1)[count1] = kpar;
151 	}
152       else
153 	{
154 	  /* Find next value. */
155 
156 	  for (count2 = count1 + 1; ntype[count2] != 0 && count2 < inpt; count2++) ;
157 
158 	  if (count2 < inpt)
159 	    {
160 	      npar = kpar + s6dist (&econd[(count1 - 1) * idim],
161 				    &econd[count2 * idim], idim);
162 	      (*epar1)[count2] = npar;
163 	    }
164 
165 	  for (count3 = count1; count3 < count2; count3++)
166 	    {
167 	      if (ntype[count3] > 0)
168 		(*epar1)[count3] = kpar;
169 	      else
170 		(*epar1)[count3] = npar;
171 	    }
172 	  count1 = count2;
173 	  kpar = npar;
174 	}
175     }
176 
177   if (iopen != SISL_CRV_OPEN)
178     {
179       /* Calculate distance between first and last point. */
180 
181       for (count1 = 0; count1 < inpt && ntype[count1] != 0; count1++) ;
182 
183       for (count2 = inpt - 1; count2 >= 0 && ntype[count2] != 0; count2--) ;
184 
185       if (count1 >= inpt || count2 < 0)
186 	goto err164;
187 
188       (*epar1)[inpt] = kpar + s6dist (&econd[count1 * idim],
189 				      &econd[count2 * idim], idim);
190     }
191 
192   *cendpar = (*epar1)[knpt - 1];
193 
194   count2 = 1;
195   (*epar2)[0] = (*epar1)[0];
196 
197   for (count1 = 1; count1 < knpt; count1++)
198     {
199       if ((*epar1)[count1 - 1] < (*epar1)[count1])
200 	{
201 	  (*epar2)[count2] = (*epar1)[count1];
202 	  count2++;
203 	}
204     }
205 
206   *epar2 = increasearray (*epar2, count2, DOUBLE);
207   if (*epar2 == SISL_NULL)
208     goto err101;
209 
210 
211   /* Parametrization computed.  */
212 
213   goto out;
214 
215 
216   /* No point conditions given. */
217 
218 err164:
219   *jstat = -164;
220   s6err ("s1909", *jstat, kpos);
221   goto out;
222 
223   /* Error in scratch allocation. */
224 
225 err101:
226   *jstat = -101;
227   s6err ("s1909", *jstat, kpos);
228   goto out;
229 
230 out:
231 
232   return;
233 }
234