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