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: sh1870.c,v 1.4 2002-05-07 11:46:54 jbt Exp $
45  *
46  */
47 
48 
49 #define SH1870
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
sh1870(SISLSurf * ps1,double * pt1,int idim,double aepsco,double aepsge,int trackflag,int * jtrack,SISLTrack *** wtrack,int * jpt,double ** gpar1,int ** pretop,int * jcrv,SISLIntcurve *** wcurve,int * jstat)55 sh1870(SISLSurf *ps1, double *pt1, int idim, double aepsco, double aepsge,
56 	int trackflag, int *jtrack, SISLTrack *** wtrack,
57 	   int *jpt,double **gpar1,int **pretop,int *jcrv,SISLIntcurve ***wcurve,int *jstat)
58 #else
59 void sh1870(ps1,pt1,idim,aepsco,aepsge,
60 	trackflag,jtrack,wtrack,jpt,gpar1,pretop,jcrv,wcurve,jstat)
61      SISLSurf     *ps1;
62      double    *pt1;
63      int	idim;
64      double   aepsco;
65      double   aepsge;
66      int       trackflag;
67      int       *jtrack;
68      SISLTrack ***wtrack;
69      int      *jpt;
70      double   **gpar1;
71      int      **pretop;
72      int      *jcrv;
73      SISLIntcurve ***wcurve;
74      int      *jstat;
75 #endif
76 /*
77 *********************************************************************
78 *
79 *********************************************************************
80 *
81 * PURPOSE    : Find all intersections between a B-spline surface
82 *              and a point.
83 *
84 *
85 *
86 * INPUT      : ps1    - Pointer to the surface.
87 *              pt1    - coordinates of the point.
88 *	       idim   - number of coordinates in pt1.
89 *              aepsco - Computational resolution.
90 *              aepsge - Geometry resolution.
91 *              trackflag - For future use. Should now be 0.
92 *              *jstat    - Flag
93 *                          = 202 : Complicated point-surface intersection
94 *                                  in 3D. Perform extra interception test.
95 *
96 *
97 *
98 * OUTPUT     : jtrack - Number of tracks created
99 *              wtrack - Array of pointers to tracks
100 *              jpt    - Number of single intersection points.
101 *              gpar1  - Array containing the parameter values of the
102 *                       single intersection points in the parameter
103 *                       interval of the surface. The points lie
104 *                       continuous. Intersection curves are stored in wcurve.
105 *              pretop - Topology info. for single intersection points.
106 *              jcrv   - Number of intersection curves.
107 *              wcurve - Array containing descriptions of the intersection
108 *                       curves. The curves are only described by points
109 *                       in the parameter plane. The curve-pointers points
110 *                       to nothing. (See description of Intcurve
111 *                       in intcurve.dcl).
112 *                       If the curves given as input are degnenerate an
113 *                       intersection point can be returned as an intersection
114 *                       curve. Use s1327 to decide if an intersection curve
115 *                       is a point on one of the curves.
116 *              jstat  - status messages
117 *                                         > 0      : warning
118 *                                         = 0      : ok
119 *                                         < 0      : error
120 *
121 *
122 * REFERENCES :
123 *
124 *-
125 * CALLS      : sh1761      - Perform object/object-intersection.
126 *              hp_s1880      - Put intersections on output format.
127 *              newObject  - Create new object.
128 	       newPoint   - Create new SISLPoint.
129 *              freeObject - Free space occupied by an object.
130 *              freeIntdat - Free space occupied by the intdat structure.
131 *
132 * WRITTEN BY : K. Stroem, SI, 92-10.
133 *
134 *********************************************************************
135 */
136 {
137   double *nullp = SISL_NULL;
138   int kstat = 0;                 /* Local status variable.                   */
139   int kpos = 0;                  /* Position of error.                       */
140   SISLObject *qo1 = SISL_NULL;            /* Object containing first curve in
141 				    the intersection.                        */
142   SISLObject *qo2 = SISL_NULL;            /* Object containing second curve in
143 				    the intersection.*/
144   SISLPoint  *pp1 = SISL_NULL;	   /* Point object containing the point */
145   SISLIntdat *qintdat = SISL_NULL;        /* Structure holding the intersection data. */
146   int      ksurf=0;         /* Dummy number of Intsurfs. */
147   SISLIntsurf **wsurf=SISL_NULL;    /* Dummy array of Intsurfs. */
148   int kdeg=0;
149 
150   /*
151    * Check dimensions.
152    * -----------------
153    */
154 
155   *jpt  = 0;
156   *jcrv = 0;
157   *jtrack = 0;
158 
159   if (ps1 -> idim != idim) goto err106;
160 
161   /*
162    * Create objects and connect surface/point to the objects.
163    * --------------------------------------------------------
164    */
165 
166   if ((qo1 = newObject(SISLSURFACE)) == SISL_NULL) goto err101;
167   qo1 -> s1 = ps1;
168   qo1 -> o1 = qo1;
169 
170   if ((pp1 = newPoint(pt1,idim, 0)) == SISL_NULL) goto err101;
171 
172   if ((qo2 = newObject(SISLPOINT)) == SISL_NULL) goto err101;
173   qo2 -> p1 = pp1;
174   qo2 -> o1 = qo2;
175 
176   /*
177    * Find intersections.
178    * -------------------
179    */
180 
181   kstat = *jstat;
182   sh1761(qo1,qo2,aepsge,&qintdat,&kstat);
183   if (kstat < 0) goto error;
184 
185   /* Represent degenerated intersection curves as one point.  */
186 
187   sh6degen(qo1,qo2,&qintdat,aepsge,&kstat);
188   if (kstat < 0) goto error;
189 
190   /* Join periodic curves */
191 /*    int_join_per( &qintdat,qo1,qo2,nullp,kdeg=0,aepsge,&kstat); */
192 /*    if (kstat < 0) */
193 /*      goto error; */
194 
195   /* Create tracks */
196   if (trackflag && qintdat)
197     {
198       make_tracks (qo1, qo2, kdeg=0, nullp,
199 		   qintdat->ilist, qintdat->vlist,
200 		   jtrack, wtrack, aepsge, &kstat);
201       if (kstat < 0)
202 	goto error;
203 
204     }
205 
206   /*
207    * Express intersections on output format.
208    * ---------------------------------------
209    */
210 
211   if (qintdat)/* Only if there were intersections found */
212     {
213       hp_s1880(qo1, qo2, 0,
214 	       2,0,qintdat,jpt,gpar1,&nullp,pretop,jcrv,wcurve,&ksurf,&wsurf,&kstat);
215       if (kstat < 0) goto error;
216     }
217 
218   /*
219    * Intersections found.
220    * --------------------
221    */
222 
223   *jstat = 0;
224   goto out;
225 
226   /*
227    * Error in space allocation.
228    * --------------------------
229    */
230 
231  err101: *jstat = -101;
232         s6err("sh1870",*jstat,kpos);
233         goto out;
234 
235   /* Dimensions conflicting.  */
236 
237  err106: *jstat = -106;
238   s6err("sh1870",*jstat,kpos);
239         goto out;
240 
241   /* Error in lower level routine.  */
242 
243   error : *jstat = kstat;
244         s6err("sh1870",*jstat,kpos);
245         goto out;
246 
247  out:
248 
249   /*
250    * Free allocated space.
251    * ---------------------
252    */
253 
254   if (qo1)
255     {
256       qo1 -> s1 = SISL_NULL;  freeObject(qo1);
257     }
258   if (qo2)
259     {
260       freeObject(qo2);
261     }
262   if (qintdat) freeIntdat(qintdat);
263 
264   /*
265    * Exit sh1870.
266    * -----------
267    */
268 
269   return;
270 }
271 
272