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: sh1851.c,v 1.2 2001-03-19 15:59:06 afr Exp $
45 *
46 */
47
48
49 #define SH1851
50
51 #include "sislP.h"
52
53 #if defined(SISLNEEDPROTOTYPES)
sh1851(SISLSurf * ps1,double epoint[],double enorm[],int idim,double aepsco,double aepsge,int trackflag,int * jtrack,SISLTrack *** wtrack,int * jpt,double ** gpar,int ** pretop,int * jcrv,SISLIntcurve *** wcurve,int * jsurf,SISLIntsurf *** wsurf,int * jstat)54 void sh1851(SISLSurf * ps1, double epoint[], double enorm[], int idim,
55 double aepsco, double aepsge,int trackflag, int *jtrack,
56 SISLTrack *** wtrack,int *jpt, double **gpar, int **pretop,
57 int *jcrv, SISLIntcurve *** wcurve, int *jsurf,
58 SISLIntsurf ***wsurf, int *jstat)
59 #else
60 void sh1851(ps1, epoint, enorm, idim, aepsco, aepsge,trackflag, jtrack,
61 wtrack, jpt, gpar, pretop, jcrv, wcurve,jsurf,wsurf, jstat)
62 SISLSurf *ps1;
63 double epoint[];
64 double enorm[];
65 int idim;
66 double aepsco;
67 double aepsge;
68 int trackflag;
69 int *jtrack;
70 SISLTrack ***wtrack;
71 int *jpt;
72 double **gpar;
73 int **pretop;
74 int *jcrv;
75 SISLIntcurve ***wcurve;
76 int *jsurf;
77 SISLIntsurf ***wsurf;
78 int *jstat;
79 #endif
80 /*
81 *********************************************************************
82 *
83 *********************************************************************
84 *
85 * PURPOSE : Find all intersections between a tensor-product surface
86 * and a plane.
87 *
88 *
89 *
90 * INPUT : ps1 - Pointer to surface.
91 * epoint - SISLPoint in the plane.
92 * enorm - Normal to the plane.
93 * idim - Dimension of the space in which the plane lies.
94 * aepsco - Computational resolution.
95 * aepsge - Geometry resolution.
96 * trackflag - If true, create tracks.
97 *
98 *
99 *
100 * OUTPUT : jtrack - Number of tracks created
101 * wtrack - Array of pointers to tracks
102 * jpt - Number of single intersection points.
103 * gpar - Array containing the parameter values of the
104 * single intersection points in the parameter
105 * plane of the surface. The points lie continuous.
106 * Intersection curves are stored in wcurve.
107 * pretop - Topology info. for single intersection points.
108 * *jcrv - Number of intersection curves.
109 * wcurve - Array containing descriptions of the intersection
110 * curves. The curves are only described by points
111 * in the parameter plane. The curve-pointers points
112 * to nothing. (See description of Intcurve
113 * in intcurve.dcl).
114 * jstat - status messages
115 * > 0 : warning
116 * = 0 : ok
117 * < 0 : error
118 *
119 *
120 * METHOD : The vertices of the surface are put into the equation of the
121 * plane achieving a surface in the one-dimentional space.
122 * Then the zeroes of this surface is found.
123 *
124 *
125 * REFERENCES :
126 *
127 *-
128 * CALLS : sh1761 - Perform point object-intersection.
129 * s1329 - Equation of surface into equation of plane.
130 * hp_s1880 - Put intersections on output format.
131 * make_sf_kreg - Ensure k-regularity of surface.
132 * newObject - Create new object.
133 * newPoint - Create new point.
134 * freeObject - Free space occupied by an object.
135 * freeIntdat - Free space occupied by an intersection data.
136 *
137 * WRITTEN BY : Vibeke Skytt, SI, 88-06.
138 * REWRITTEN BY : Bjoern Olav Hoset, SI, 89-06.
139 * UJK, SI, 91-07
140 *********************************************************************
141 */
142 {
143 int kstat = 0; /* Local status varible. */
144 int kpos = 0; /* Position of error. */
145 int kdim = 1; /* Dimension of space in which the point in the
146 intersect point and surface problem lies. */
147 double *spar = SISL_NULL; /* Dummy array containing parameter values of
148 second object of single intersection points.*/
149 double spoint[1]; /* SISLPoint to intersect with object. */
150 SISLSurf *qs = SISL_NULL; /* Pointer to surface in
151 surface/point intersection.*/
152 SISLPoint *qp = SISL_NULL; /* Pointer to point in
153 surface/point intersection. */
154 SISLObject *qo1 = SISL_NULL; /* Pointer to surface in
155 object/point intersection. */
156 SISLObject *qo2 = SISL_NULL; /* Pointer to point in
157 object/point intersection */
158 SISLIntdat *qintdat = SISL_NULL; /* Intersection result */
159 int kdeg = 1; /* Implisit descr. to track */
160 double simpli[16];
161 double snorm[3];
162 SISLObject *track_obj=SISL_NULL;
163 SISLSurf *qkreg=SISL_NULL; /* Input surface ensured k-regularity. */
164
165 /* -------------------------------------------------------- */
166
167 if (ps1->cuopen_1 == SISL_SURF_PERIODIC ||
168 ps1->cuopen_2 == SISL_SURF_PERIODIC)
169 {
170 /* Cyclic surface. */
171
172 make_sf_kreg(ps1,&qkreg,&kstat);
173 if (kstat < 0) goto error;
174 }
175 else
176 qkreg = ps1;
177
178 /*
179 * Create new object and connect surface to object.
180 * ------------------------------------------------
181 */
182
183 if (!(track_obj = newObject (SISLSURFACE)))
184 goto err101;
185 track_obj->s1 = ps1;
186
187 /*
188 * Check dimension.
189 * ----------------
190 */
191
192 *jpt = 0;
193 *jcrv = 0;
194 *jtrack = 0;
195
196 if (idim != qkreg->idim)
197 goto err106;
198
199 /*
200 * Put surface into plane-equation.
201 * --------------------------------
202 */
203
204 s1329 (qkreg, epoint, enorm, idim, &qs, &kstat);
205 if (kstat < 0)
206 goto error;
207
208 /*
209 * Create new object and connect surface to object.
210 * ------------------------------------------------
211 */
212
213 if (!(qo1 = newObject (SISLSURFACE)))
214 goto err101;
215 qo1->s1 = qs;
216 qo1->o1 = qo1;
217
218 /*
219 * Create new object and connect point to object.
220 * ----------------------------------------------
221 */
222
223 if (!(qo2 = newObject (SISLPOINT)))
224 goto err101;
225 spoint[0] = DZERO;
226 if (!(qp = newPoint (spoint, kdim, 1)))
227 goto err101;
228 qo2->p1 = qp;
229
230 /*
231 * Find intersections.
232 * -------------------
233 */
234
235 sh1761 (qo1, qo2, aepsge, &qintdat, &kstat);
236 if (kstat < 0)
237 goto error;
238
239 /* Represent degenerated intersection curves as one point. */
240
241 sh6degen(track_obj,track_obj,&qintdat,aepsge,&kstat);
242 if (kstat < 0) goto error;
243
244 /* BUG BEOrd13026, simpli is now always in use, UJK */
245 /* Normalize plane normal */
246
247 (void) s6norm (enorm, 3, snorm, &kstat);
248
249 simpli[0] = snorm[0];
250 simpli[1] = snorm[1];
251 simpli[2] = snorm[2];
252 simpli[3] = -s6scpr (epoint, snorm, 3);
253
254
255 /* Create tracks */
256 if (trackflag && qintdat)
257 {
258 refine_all (&qintdat, track_obj, track_obj, simpli, kdeg, aepsge, &kstat);
259 if (kstat < 0)
260 goto error;
261 }
262
263 /* Join periodic curves */
264 int_join_per( &qintdat,track_obj, track_obj, simpli, kdeg,aepsge,&kstat);
265 if (kstat < 0)
266 goto error;
267
268 if (trackflag && qintdat)
269 {
270 make_tracks (track_obj, track_obj, kdeg, simpli,
271 qintdat->ilist, qintdat->vlist,
272 jtrack, wtrack, aepsge, &kstat);
273 if (kstat < 0)
274 goto error;
275 }
276
277 /*
278 * Express intersections on output format.
279 * ---------------------------------------
280 */
281
282 if (qintdat) /* Only if there were intersections found */
283 {
284 hp_s1880 (track_obj, track_obj, kdeg,
285 2, 0, qintdat, jpt, gpar, &spar, pretop, jcrv, wcurve, jsurf,wsurf,&kstat);
286 if (kstat < 0)
287 goto error;
288 }
289
290 /*
291 * Intersections found.
292 * --------------------
293 */
294
295 *jstat = 0;
296 goto out;
297
298 /* Error in space allocation. */
299
300 err101:*jstat = -101;
301 s6err ("sh1851", *jstat, kpos);
302 goto out;
303
304 /* Dimensions conflicting. */
305
306 err106:*jstat = -106;
307 s6err ("sh1851", *jstat, kpos);
308 goto out;
309
310 /* Error in lower level routine. */
311
312 error:*jstat = kstat;
313 s6err ("sh1851", *jstat, kpos);
314 goto out;
315
316 out:
317
318 /* Free allocated space. */
319
320 if (spar)
321 freearray (spar);
322 if (qo1)
323 freeObject (qo1);
324 if (qo2)
325 freeObject (qo2);
326 if (qintdat)
327 freeIntdat (qintdat);
328 if (track_obj)
329 {
330 track_obj->s1 = SISL_NULL;
331 freeObject(track_obj);
332 }
333
334 /* Free local surface. */
335 if (qkreg != SISL_NULL && qkreg != ps1) freeSurf(qkreg);
336
337 return;
338 }
339
340
341