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: sh6idput.c,v 1.2 2001-03-19 16:06:03 afr Exp $
45 *
46 */
47
48
49 #define SH6IDPUT
50
51 #include "sislP.h"
52
53
54 #if defined(SISLNEEDPROTOTYPES)
55 void
sh6idput(SISLObject * po1,SISLObject * po2,SISLIntdat ** rintdat,SISLIntdat * pintdat,int inr,double apar,SISLIntpt *** outintpt,int * npoint,int * jstat)56 sh6idput (SISLObject * po1, SISLObject * po2,
57 SISLIntdat ** rintdat, SISLIntdat * pintdat,
58 int inr, double apar, SISLIntpt *** outintpt, int *npoint, int *jstat)
59 #else
60 void
61 sh6idput (po1, po2, rintdat, pintdat, inr, apar, outintpt, npoint, jstat)
62 SISLObject *po1;
63 SISLObject *po2;
64 SISLIntdat **rintdat;
65 SISLIntdat *pintdat;
66 int inr;
67 double apar;
68 SISLIntpt ***outintpt;
69 int *npoint;
70 int *jstat;
71 #endif
72 /*
73 *********************************************************************
74 *
75 *********************************************************************
76 *
77 * PURPOSE : To insert all points in one intdat with one less number
78 * of parameters into rintdat. New copies is made with
79 * the missing parameter. Connections are kept.
80 * The geometry data of the object not enhanced, is kept.
81 *
82 *
83 *
84 * INPUT : po1 - First object in the intersection.
85 * po2 - Second object in the intersection.
86 * pintdat - Pointer to intersection data with one less
87 * parameter than rintdat.
88 * inr - Number of the parameter that is missing in pintdat.
89 * apar - Parameter value of the missing parameter.
90 *
91 *
92 * OUTPUT : rintdat - Pointer to a pointer to intersection data.
93 * outintpt - Help array containing pointers to the enhanced
94 * points in rintdat.
95 * npoints - Size of outinpt.
96 * jstat - status messages
97 * = 0 : Inserting done.
98 * < 0 : error
99 *
100 *
101 * METHOD :
102 *
103 *
104 * REFERENCES :
105 *
106 *-
107 * CALLS : s6err - Gives error message.
108 * sh6idnpt - Insert a new intpt structure.
109 * sh6idfcross - Fetch cross intersections.
110 * sh6idrmcross - Remove cross intersections.
111 *
112 * WRITTEN BY : Ulf J. Krystad, SI, 06.91.
113 * CHANGED BY : Vibeke Skytt, SI, 12.92. Remove cross intersections in
114 * closed and degenerate coincidence.
115 *********************************************************************
116 */
117 {
118 int kstat; /* Local status variable. */
119 int kpos = 0; /* Position of error. */
120 int ki, kj; /* Counters */
121 int keep_first; /* Flag, which object is not enhanced */
122 int kant; /* Number of parameters in new points. */
123 int ind1, ind2; /* Indexes (not used) */
124 int no; /* No. of doubles to copy into geo_aux */
125 double *scoef = SISL_NULL; /* Pointer to array copying into geo_aux*/
126 double *spar = SISL_NULL; /* Storing uppdated parametervalues. */
127 SISLIntpt **uintpt = SISL_NULL; /* Help array while getting connections */
128 int iinter;
129 double *nullp = SISL_NULL;
130 /* VSK. Remove cross intersections. ---------------------------- */
131 int kcross = 1; /* Indicates existence of cross intersections. */
132 int kncross = 0; /* Number of cross intersections. */
133 int kpt; /* Index in uintpt. */
134 SISLIntpt *ucross[4]; /* Cross intersections. */
135
136 *npoint = 0;
137
138 /* Find out which object the parameter belongs to */
139 if (inr < po1->iobj)
140 keep_first = 0;
141 else
142 keep_first = 1;
143
144 /* Do we have an intdat structure? */
145 if (pintdat == SISL_NULL)
146 {
147 *jstat = 0;
148 goto out;
149 }
150
151 /* Computing number of new parameter direction. */
152 kant = pintdat->vpoint[0]->ipar + 1;
153
154
155 if (inr < 0 || inr >= kant)
156 goto err191;
157
158 *npoint = pintdat->ipoint;
159
160 /* Allocate an array for intersection points. */
161 if ((uintpt = newarray (pintdat->ipoint, SISLIntpt *)) == SISL_NULL)
162 goto err101;
163
164 /* Allocate an array for parametervalues. */
165 if ((spar = newarray (kant, double)) == SISL_NULL)
166 goto err101;
167
168
169 /* Enhance all intersection points. */
170 for (ki = 0; ki < pintdat->ipoint; ki++)
171 {
172 /* Insert the missing parameter value. */
173
174 for (kj = 0; kj < inr; kj++)
175 spar[kj] = pintdat->vpoint[ki]->epar[kj];
176 spar[kj] = apar;
177 for (kj++; kj < kant; kj++)
178 spar[kj] = pintdat->vpoint[ki]->epar[kj - 1];
179
180 iinter = pintdat->vpoint[ki]->iinter;
181
182 uintpt[ki] = hp_newIntpt (kant, spar, pintdat->vpoint[ki]->adist,
183 iinter,
184 pintdat->vpoint[ki]->left_obj_1[0],
185 pintdat->vpoint[ki]->right_obj_1[0],
186 pintdat->vpoint[ki]->left_obj_2[0],
187 pintdat->vpoint[ki]->right_obj_2[0],
188 (keep_first ? pintdat->vpoint[ki]->size_1 : 0),
189 (keep_first ? 0 : pintdat->vpoint[ki]->size_2),
190 (keep_first ? pintdat->vpoint[ki]->geo_data_1 : nullp),
191 (keep_first ? nullp : pintdat->vpoint[ki]->geo_data_2));
192
193 if (uintpt[ki] == SISL_NULL)
194 goto err101;
195
196 /* Store info from lower level object */
197 if (keep_first)
198 {
199 /* Store second object geometry in geo_aux */
200 no = pintdat->vpoint[ki]->size_2;
201 scoef = pintdat->vpoint[ki]->geo_data_2;
202 }
203 else
204 {
205 /* Store first object geometry in geo_aux */
206 no = pintdat->vpoint[ki]->size_1;
207 scoef = pintdat->vpoint[ki]->geo_data_1;
208 }
209 /* if (no > 0)
210 memcopy (uintpt[ki]->geo_aux, scoef, (no < 6) ? no : 6, DOUBLE); */
211
212
213
214 }
215
216
217
218 /* Insert all new intersection points in rintdat. */
219 for (ki = 0; ki < pintdat->ipoint; ki++)
220 {
221 sh6idnpt (rintdat, &uintpt[ki], 1, &kstat);
222 if (kstat < 0)
223 goto error;
224 }
225
226 /* Transform the connections. */
227 for (ki = 0; ki < pintdat->ipoint; ki++)
228 {
229 for (kj = ki + 1; kj < pintdat->ipoint; kj++)
230 {
231 sh6getlist (pintdat->vpoint[ki], pintdat->vpoint[kj],
232 &ind1, &ind2, &kstat);
233 if (kstat < 0)
234 goto error;
235 if (kstat == 0)
236 {
237 sh6idcon (rintdat, &uintpt[ki], &uintpt[kj], &kstat);
238 if (kstat < 0)
239 goto error;
240 }
241 }
242
243 if (sh6ismain (pintdat->vpoint[ki]) &&
244 sh6nmbmain (pintdat->vpoint[ki], &kstat))
245 {
246 sh6tomain (uintpt[ki], &kstat);
247 if (kstat < 0)
248 goto error;
249 }
250 }
251
252 if (po1->iobj > SISLPOINT && po2->iobj > SISLPOINT)
253 {
254 /* There is a possibility for cross intersections. Check the
255 intersection data. */
256
257 kpt = 0;
258 while (kpt < (*npoint))
259 {
260 kncross = 0;
261 ucross[kncross] = uintpt[kpt];
262 kncross = 1;
263
264 /* Fetch cross intersections. */
265
266 sh6idfcross(*rintdat,ucross,&kncross,po1->iobj,po2->iobj,&kstat);
267 kcross = kstat;
268
269 if (kcross)
270 {
271 /* Remove cross intersections. */
272
273 sh6idrmcross(po1, po2, rintdat, ucross, kncross, uintpt,
274 *npoint, &kstat);
275 if (kstat < 0) goto error;
276
277 if (kstat)
278 {
279 /* Points have been removed. Update uintpt. */
280
281 for (kj=0; kj<*npoint; kj++)
282 if (uintpt[kj] == SISL_NULL)
283 {
284 uintpt[kj] = uintpt[(*npoint)-1];
285 kj--;
286 (*npoint)--;
287 }
288 }
289 else kpt++;
290 }
291 else kpt++;
292 }
293 }
294
295 *jstat = 0;
296 goto out;
297
298
299 /* Error in inserted parameter number. */
300
301 err191:*jstat = -191;
302 s6err ("sh6idput", *jstat, kpos);
303 goto out;
304
305
306 /* Error in space allocation. */
307
308 err101:*jstat = -101;
309 s6err ("sh6idput", *jstat, kpos);
310 goto out;
311
312 /* Error in sub function. */
313
314 error:*jstat = kstat;
315 s6err ("sh6idput", *jstat, kpos);
316 goto out;
317
318 out:*outintpt = uintpt;
319 if (spar != SISL_NULL)
320 freearray (spar);
321 }
322