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: s1705.c,v 1.2 2005-02-28 09:04:48 afr Exp $
45  *
46  */
47 
48 
49 #define S1705
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s1705(SISLCurve * pc,int * jstat)55 s1705(SISLCurve *pc,int *jstat)
56 #else
57 void s1705(pc,jstat)
58      SISLCurve *pc;
59      int   *jstat;
60 #endif
61 /*
62 *********************************************************************
63 *
64 *********************************************************************
65 *
66 * PURPOSE    : Remove unnessesary knots and vertices of a B-spline curve.
67 *
68 *
69 *
70 * INPUT      : pc     - SISLCurve to treat.
71 *
72 *
73 *
74 * OUTPUT     : jstat     - status messages
75 *                                         > 0      : warning
76 *                                         = 0      : ok
77 *                                         < 0      : error
78 *
79 *
80 * METHOD     : Traverse the knot vector and remove multiplisety higher than
81 *              the order of the curve, which give zero basis.
82 *
83 *
84 * REFERENCES :
85 *
86 *-
87 * CALLS      :
88 *
89 * WRITTEN BY : Arne Laksaa, SI, 88-06.
90 * REVISED BY : Johannes Kaasa, SI, 92-04 (Introduced NURBS).
91 * REVISED BY : Christophe Birkeland, SINTEF, 93-05 (*jstat = 0 in start).
92 *
93 **********************************************************************/
94 {
95   int kk=pc->ik;           /* Order of the input curve.                  */
96   int kn=pc->in;           /* Number of the vertices in input curves.    */
97   int kdim=pc->idim;       /* Dimensjon of the space in whice curve lies.*/
98   int rdim = kdim + 1;     /* Rational dimension.                        */
99   int knnew=0;             /* Number of vertices in the new curves.      */
100   register int ki;                  /* Control variable in loop.         */
101   register double *s1,*s2,*s3,*s4;  /* Pointers used in loop.            */
102   register double *st=pc->et;       /* The first new knot-vector.        */
103   register double *scoef=pc->ecoef; /* The first new vertice.            */
104   double *rcoef = pc->rcoef; /* The rational vertices.                    */
105   int kind = pc->ikind;    /* The type of curve, 2 and 4 are rational.   */
106 
107   *jstat = 0;
108 
109   /* s1 is used to traverse scoef, s2 is used to traverse st.
110      We just remove unnecesary knots by kompressing the arraies. */
111 
112   s4 = rcoef;
113   for (s1=scoef,s2=st,s3=s2+kn; s2<s3; s1+=kdim,s4+=rdim,s2++)
114     if (s2[kk] > *s2)
115       {
116 	/* Here we copies nessecary vertices to compress the vector. */
117 
118 	for (ki=0; ki<kdim; ki++)
119 	  scoef[knnew*kdim+ki] = s1[ki];
120 
121         /* Here we copy rational vertices. */
122 
123 	if (kind == 2 || kind == 4)
124 	  {
125             for (ki=0; ki<rdim; ki++)
126 	      rcoef[knnew*rdim+ki] = s4[ki];
127 	  }
128 
129 	/* Here we copies nessecary knots to compress the vector. */
130 
131 	st[knnew] = *s2;
132 
133 	/* Updating number of copied knots. */
134 
135 	knnew++;
136       }
137 
138   /* At last we have to copy the last kk knots. */
139 
140   for (ki=0; ki<kk; ki++)
141     st[knnew+ki] = s3[ki];
142 
143   /* If some knots are removed we have to update the size of the vectors.*/
144 
145   if (knnew == 0)
146     goto err111;
147   else
148     if (knnew < kn)
149       {
150 	pc->in = knnew;
151       }
152   goto out;
153 
154   err111:
155     *jstat = -111;
156 
157   out:
158     return;
159 }
160