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: s1440.c,v 1.3 2001-03-19 15:58:49 afr Exp $
45  *
46  */
47 
48 
49 #define S1440
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s1440(SISLSurf * ps1,SISLSurf ** rs2,int * jstat)55 s1440(SISLSurf *ps1,SISLSurf **rs2,int *jstat)
56 #else
57 void s1440(ps1,rs2,jstat)
58      SISLSurf *ps1;
59      SISLSurf **rs2;
60      int  *jstat;
61 #endif
62 /*
63 *********************************************************************
64 *
65 *********************************************************************
66 *
67 * PURPOSE    : Interchange the two parameter directions used in the
68 *              mathematical description of a surface and thereby
69 *              change the direction of the normal vector of the surface.
70 *
71 *
72 *
73 * INPUT      : ps1    - Pointer to the original surface.
74 *
75 *
76 *
77 * OUTPUT     : rs2    - Pointer to the surface with interchanged
78 *                       parameter directions.
79 *              jstat  - status messages
80 *                                         > 0      : warning
81 *                                         = 0      : ok
82 *                                         < 0      : error
83 *
84 *
85 * METHOD     :
86 *
87 *
88 * REFERENCES :
89 *
90 *-
91 * CALLS      : s6chpar  - Change parameter directions of the vertices
92 *                         of the surface.
93 *              newSurf  - Create new surface.
94 *
95 * WRITTEN BY : Vibeke Skytt, SI, 88-11.
96 * REVISED BY : Johannes Kaasa, SI, 91-09 (Introduced NURBS).
97 * Revised by : Paal Fugelli, SINTEF, Oslo, Norway, Nov. 1994.  Added
98 *              handling of 'cuopen' flags.
99 *
100 *********************************************************************
101 */
102 {
103   int kpos = 0;          /* Position of error.                  */
104   double *ssurf = SISL_NULL;  /* Pointer to vertices of new surface. */
105   int kdim;              /* Local (rational) dimension.         */
106   double *vert;          /* Pointer to vertices.                */
107 
108   /* Check for rational surface. */
109 
110   if (ps1->ikind == 2 || ps1->ikind == 4)
111     {
112       kdim = ps1->idim + 1;
113       vert = ps1->rcoef;
114     }
115   else
116     {
117       kdim = ps1->idim;
118       vert = ps1->ecoef;
119     }
120 
121   /* Allocate scratch for vertices of new surface.  */
122 
123   ssurf = newarray(ps1->in1*ps1->in2*kdim,double);
124   if (ssurf == SISL_NULL) goto err101;
125 
126   /* Change parameter directions of vertices.  */
127 
128   s6chpar(vert,ps1->in1,ps1->in2,kdim,ssurf);
129 
130   /* Create output surface.  */
131 
132   *rs2 = SISL_NULL;
133   if ((*rs2 = newSurf(ps1->in2,ps1->in1,ps1->ik2,ps1->ik1,ps1->et2,
134 		      ps1->et1,ssurf,ps1->ikind,ps1->idim,1)) == SISL_NULL) goto err101;
135 
136   /* Set periodicity flag */
137 
138   (*rs2)->cuopen_1 = ps1->cuopen_2;
139   (*rs2)->cuopen_2 = ps1->cuopen_1;
140 
141   /* Parameter directions changed.  */
142 
143   *jstat = 0;
144   goto out;
145 
146   /* Error in space allocation.  */
147 
148  err101: *jstat = -101;
149   s6err("s1440",*jstat,kpos);
150   goto out;
151 
152  out:
153 
154   /* Free space occupied by local array.  */
155 
156   if (ssurf != SISL_NULL) freearray(ssurf);
157 
158   return;
159 }
160