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: shmkhlppts.c,v 1.4 2001-03-19 16:06:04 afr Exp $
45 *
46 */
47
48
49 #define SHMKHLPPTS
50
51 #include "sislP.h"
52 #if defined(SISLNEEDPROTOTYPES)
53 void
shmkhlppts(SISLObject * po1,SISLObject * po2,double aepsge,SISLIntdat ** rintdat,SISLEdge * vedge[],int * jnewpt,int * jstat)54 shmkhlppts (SISLObject * po1, SISLObject * po2, double aepsge,
55 SISLIntdat ** rintdat, SISLEdge * vedge[], int *jnewpt, int *jstat)
56 #else
57 void
58 shmkhlppts (po1, po2, aepsge, rintdat, vedge, jnewpt, jstat)
59 SISLObject *po1;
60 SISLObject *po2;
61 double aepsge;
62 SISLIntdat **rintdat;
63 SISLEdge *vedge[];
64 int *jnewpt;
65 int *jstat;
66 #endif
67 /*
68 *********************************************************************
69 *
70 *********************************************************************
71 *
72 * PURPOSE : Make help points (and pretopology) for main points.
73 *
74 *
75 * INPUT : po1 - Pointer to the first object in the intersection.
76 * po2 - Pointer to the second object in the intersection.
77 * aepsge - Geometry resolution.
78 * vedge - SISLEdge intersection objects to the two
79 * objects in intersection problem.
80 *
81 *
82 * INPUT/OUTPUT : rintdat - Intersection data of object-object intersection.
83 *
84 * OUTPUT : jnewpt - Number of new intersection points.
85 * jstat - status messages
86 * > 0 : Warning.
87 * = 0 : Ok.
88 * < 0 : Error.
89 *
90 *
91 * METHOD :
92 *
93 * CALLS : sh1781 - Find pre-topology of 1D curve-point.
94 * sh1780 - Find pre-topology of curve-curve.
95 * sh1779 - Find pre-topology of 3D curve-surface.
96 * sh1786 - Find pre-topology of 2D point-curve.
97 * sh1787 - Find pre-topology of 2D point-surface.
98 *
99 * REFERENCES :
100 *
101 * WRITTEN BY : Ulf J. Krystad, SI, 09.91
102 * Revised by : Paal Fugelli, SINTEF, Oslo, Norway, 09-94. Fixed over-running
103 * of 'up' array.
104 *********************************************************************
105 */
106 {
107 int kstat = 0; /* Status variable. */
108 int knum = 0; /* Number of intpt on edges. */
109 int ki; /* Counter. */
110 int kdim; /* Dimension of geometry space. */
111 int knewpt = 0; /* Number of new intersection points. */
112 int kobj; /* Number of obj, used in s6idint */
113 int index1, index2; /* Dummy in this context */
114 SISLIntpt **up = SISL_NULL; /* Array of poiners to intersection point. */
115 /* SISLIntpt *lup[3];*/ /* Array of poiners to intersection point. */
116 SISLIntpt *qptint = SISL_NULL; /* Pointer to internal intersection point. */
117 SISLIntpt *qpt = SISL_NULL; /* Pointer to intersection point. */
118 /* --------------------------------------------------------------------- */
119
120 /* Init */
121 *jstat = 0;
122 *jnewpt = 0;
123
124 /* Test if an intersection data structure exist. */
125 if (*rintdat == SISL_NULL)
126 goto out;
127
128
129 /* Fetch dimension of geometry space. */
130 if (po1->iobj == SISLPOINT)
131
132 kdim = po1->p1->idim;
133 else if (po1->iobj == SISLCURVE)
134 kdim = po1->c1->idim;
135 else
136 kdim = po1->s1->idim;
137
138 /* Treat only cases:
139 crv vs pt 1D
140 crv vs crv
141 crv vs sf
142 crv vs pt 2D
143 sf vs pt 2D
144 */
145
146 if (!(((po1->iobj == SISLCURVE && po2->iobj >= SISLCURVE) ||
147 (po2->iobj == SISLCURVE && po1->iobj >= SISLCURVE)) ||
148 (kdim == 1 && (po1->iobj + po2->iobj) == (SISLPOINT + SISLCURVE)) ||
149 (kdim == 2 && (po1->iobj + po2->iobj) >= (SISLPOINT + SISLCURVE))))
150 goto out;
151
152 /* Compute number of intersection points on edges, 0 1 or 2. */
153 if (vedge[0] == SISL_NULL)
154 knum = 0;
155 else
156 knum = vedge[0]->ipoint;
157
158 if (vedge[1] != SISL_NULL)
159 knum += vedge[1]->ipoint;
160
161
162 if (knum > 0)
163 {
164 sh6edgpoint (vedge, &up, &knum, &kstat);
165 if (kstat < 0)
166 goto error;
167 }
168
169 if (knum == 2)
170 {
171 /* when two edge points, check if they are connected */
172 sh6getlist (up[0], up[1], &index1, &index2, &kstat);
173 if (kstat == 0)
174 knum = 0;
175 }
176
177 if (knum == 0) /* BOH & ALA Added: 200993 */
178 {
179 /* Task performed. */
180
181 *jstat = 0;
182 goto out;
183 }
184
185 /* Copy pointer of edge points into local pointer array */
186 /*for (ki = 0; ki < knum; ki++)
187
188 lup[ki] = up[ki]; */
189
190 /* Get the internal point if any */
191 if (po1->iobj == SISLPOINT)
192 kobj = 2;
193 else
194 kobj = 1;
195
196 s6idint (po1, po2, *rintdat, &qptint, kobj);
197 if (qptint)
198 {
199 qpt = qptint;
200 ki=-1;
201 }
202 else
203 {
204 ki = 0;
205 qpt = up[0];
206 }
207
208 for (; ki < knum; ki++ )
209 {
210
211 if (ki >= 0) qpt = up[ki];
212
213 /* Browse on the dimension of geometry space and the type of
214 the input objects. */
215
216 if (kdim == 1 && ((po1->iobj == SISLCURVE && po2->iobj == SISLPOINT)
217 || (po2->iobj == SISLCURVE && po1->iobj == SISLPOINT)))
218 {
219 /* Compute pre-topology in one-dimensional curve-level value
220 intersection. */
221
222 sh1781 (po1, po2, aepsge, rintdat, qpt, &knewpt, &kstat);
223 if (kstat < 0)
224 goto error;
225 *jnewpt += knewpt;
226 }
227 else if (po1->iobj == SISLCURVE && po2->iobj == SISLCURVE)
228 {
229 /* curve-curve intersection. */
230 sh1780 (po1, po2, aepsge, rintdat, qpt, &knewpt, &kstat);
231 if (kstat < 0)
232 goto error;
233 *jnewpt += knewpt;
234 }
235 else if (kdim == 2 &&
236 ((po1->iobj == SISLCURVE && po2->iobj == SISLPOINT)
237 || (po2->iobj == SISLCURVE && po1->iobj == SISLPOINT)))
238 {
239 /* 2 dimensional point-curve intersection. */
240
241 sh1786 (po1, po2, aepsge, rintdat, qpt, &knewpt, &kstat);
242 if (kstat < 0)
243 goto error;
244 *jnewpt += knewpt;
245 }
246 else if (kdim == 2 &&
247 ((po1->iobj == SISLSURFACE && po2->iobj == SISLPOINT)
248 || (po2->iobj == SISLSURFACE && po1->iobj == SISLPOINT)))
249 {
250 /* 2 dimensional point-surface intersection. */
251
252 sh1787 (po1, po2, aepsge, rintdat, qpt, &knewpt, &kstat);
253 if (kstat < 0)
254 goto error;
255 *jnewpt += knewpt;
256 }
257 else if (kdim == 3 &&
258 ((po1->iobj == SISLCURVE && po2->iobj == SISLSURFACE) ||
259 (po1->iobj == SISLSURFACE && po2->iobj == SISLCURVE)))
260 {
261 /* Surface-curve intersection in 3-dimensional geometry space. */
262
263 sh1779 (po1, po2, aepsge, rintdat, qpt, &knewpt, &kstat);
264 if (kstat < 0)
265 goto error;
266 *jnewpt += knewpt;
267
268 }
269 }
270
271 /* Task performed. */
272
273 *jstat = 0;
274 goto out;
275
276 /* Error in lower level routine. */
277
278 error:*jstat = kstat;
279 goto out;
280
281 out:
282 if (up != SISL_NULL)
283 freearray (up);
284
285 return;
286 }
287