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: s1602.c,v 1.3 2005-02-28 09:04:48 afr Exp $
45  *
46  */
47 
48 
49 #define S1602
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s1602(double estapt[],double endpt[],int ik,int idim,double astpar,double * cendpar,SISLCurve ** rc,int * jstat)55 s1602(double estapt[],double endpt[],int ik,int idim,double astpar,
56 	   double *cendpar,SISLCurve **rc,int *jstat)
57 #else
58 void s1602(estapt,endpt,ik,idim,astpar,cendpar,rc,jstat)
59      double estapt[];
60      double endpt[];
61      int    ik;
62      int    idim;
63      double astpar;
64      double *cendpar;
65      SISLCurve  **rc;
66      int    *jstat;
67 #endif
68 /*
69 *********************************************************************
70 *
71 * PURPOSE    : Convert a straight line to a B-spline described curve.
72 *
73 *
74 * INPUT      : estapt - start point of the straight line
75 *              endpt  - end point of the straight line
76 *              ik     - the order of the B-spline curve to be found
77 *              idim   - The dimension of the space
78 *              astpar - start value of parameterization of the curve
79 *
80 * OUTPUT
81 *            : cendpar - parameter used at the end of the curve
82 *              rc      - Pointer to the found curve
83 *              jstat  - status messages
84 
85 *                                         > 0      : warning
86 *                                         = 0      : ok
87 *                                         < 0      : error
88 *
89 * METHOD     : First the knots are found with ik knots in the start
90 *              and ik knots in the end of the curve. Then a modified
91 *              Marsdens identity is used to find ik vertices equally
92 *              spaced on the straight line.
93 *
94 * EXAMPLE OF USE:
95 *
96 * REFERENCES :
97 *
98 *-
99 * CALLS      : s6dist,newCurve,s6err
100 *
101 *
102 * WRITTEN BY : Qyvind Hjelle, SI, Oslo, Norway. 10. Nov 1988
103 *
104 *********************************************************************
105 */
106 {
107   int kit;            /* Loop control                                    */
108   int kit2;           /* Loop contero                                    */
109   int kvert;          /* Counter for position in vertex array            */
110   int kpos=0;         /* Position of error                               */
111 
112   double *st=SISL_NULL;    /* Pointer to the first element of the knot vector
113 			 of the curve.                                   */
114   double *scoef=SISL_NULL; /* Pointer to the first element of the curve's
115 			 B-spline coefficients.                          */
116   double tdist;       /* Distance                                        */
117   double tdel;        /* Delta x, y , ....                               */
118 
119   /* Check input */
120 
121   if (idim <  1) goto err102;
122   if (ik   <  2) goto err109;
123 
124   /* Find distance between start nd end point */
125   tdist = s6dist(estapt,endpt,idim);
126 
127 
128   /* Make knots. First allocate space */
129 
130   st = newarray(ik*2,DOUBLE);
131   if (st == SISL_NULL) goto err101;
132 
133   for (kit=0; kit<ik; kit++)
134     {
135       st[kit]    = astpar;
136       st[kit+ik] = astpar + tdist;
137     }
138 
139   /* calculate the vertices. First allocate space */
140 
141   /* First allocate space for vertices */
142 
143   scoef = newarray(ik*idim,DOUBLE);
144   if (scoef == SISL_NULL) goto err101;
145 
146   /* Find first and last vertex. */
147 
148   kvert = (ik-1) * idim;
149   for (kit=0; kit<idim; kit++,kvert++)
150     {
151       scoef[kit]   = estapt[kit];
152       scoef[kvert] = endpt[kit];
153     }
154 
155   /* Find other vertices */
156 
157   for (kit=0; kit<idim; kit++)
158     {
159       tdel = (endpt[kit] - estapt[kit])/(ik - 1);
160       for (kit2=2; kit2<ik; kit2++)
161 	scoef[(kit2-1)*idim + kit] = scoef[(kit2-2)*idim + kit] + tdel;
162     }
163 
164   /* Make the curve */
165 
166   *rc = SISL_NULL;
167   *rc = newCurve(ik,ik,st,scoef,1,idim,1);
168   if (*rc == SISL_NULL) goto err101;
169 
170   *cendpar = st[ik];
171   *jstat = 0;
172   goto out;
173 
174   /* Error in memory allocation */
175 
176  err101:
177   *jstat = -101;
178   s6err("s1602",*jstat,kpos);
179   goto out;
180 
181   /* Error in input. Dimension less than 1 */
182 
183  err102:
184   *jstat = -102;
185   s6err("s1602",*jstat,kpos);
186   goto out;
187   /* Error in input. Order less than 2 */
188 
189  err109:
190   *jstat = -109;
191   s6err("s1602",*jstat,kpos);
192   goto out;
193 
194  out:
195   if (st     != SISL_NULL) freearray(st);
196   if (scoef  != SISL_NULL) freearray(scoef);
197   return;
198 }
199 
200