~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina5/tina-libs/tina/vision/visModel_pwrte.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  *
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc.,
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  **********
 20  *
 21  * Program :    TINA
 22  * File    :  $Source: /home/tina/cvs/tina-libs/tina/vision/visModel_pwrte.c,v $
 23  * Date    :  $Date: 2003/10/06 12:29:48 $
 24  * Version :  $Revision: 1.4 $
 25  * CVS Id  :  $Id: visModel_pwrte.c,v 1.4 2003/10/06 12:29:48 neil Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes :
 30  * 
 31  * code to build and manipulate pair wise relation tables for representing
 32  * object constraints in matching
 33  *
 34  *********
 35 */
 36 
 37 #include "visModel_pwrte.h"
 38 
 39 #if HAVE_CONFIG_H
 40   #include <config.h>
 41 #endif
 42 
 43 #include <math.h>
 44 #include <tina/sys/sysDef.h>
 45 #include <tina/sys/sysPro.h>
 46 #include <tina/math/mathDef.h>
 47 #include <tina/math/mathPro.h>
 48 #include <tina/geometry/geomDef.h>
 49 #include <tina/geometry/geomPro.h>
 50 #include <tina/vision/vis_ModelDef.h>
 51 #include <tina/vision/vis_ModelPro.h>
 52 
 53 static double sep_error_ratio = 0.05;   /* 5% of separation */
 54 
 55 Pwrte  *pwrte_alloc(Ts_id ts_id)
 56 {
 57     Pwrte  *p = ralloc(sizeof(Pwrte));
 58 
 59     *(Ts_id *) p = ts_id;
 60 
 61     return (p);
 62 }
 63 
 64 void    pwrte_free(Pwrte * p)
 65 {
 66     rfree((void *) p);
 67 }
 68 
 69 void    pwtre_table_free(Matrix * tbl)
 70 {
 71     int     i, j;
 72     int     m, n;
 73 
 74     if (tbl == NULL)
 75         return;
 76 
 77     m = tbl->m;
 78     n = tbl->n;
 79     for (i = 0; i < m; ++i)
 80         for (j = 0; j < n; ++j)
 81             pwrte_free((Pwrte *) tbl->el.ptr_v[i][j]);
 82     matrix_free(tbl);
 83 }
 84 
 85 Pwrte  *pwrte_point_to_point_make(Point3 * p1, Point3 * p2)
 86 {
 87     Pwrte  *pwrte;
 88     Pwrte_point_to_point *p;
 89     Iso_error *iso1;
 90     Iso_error *iso2;
 91     double  seperror, poserror, dist;
 92 
 93     if (p1 == NULL || p2 == NULL)
 94         return (NULL);
 95 
 96     pwrte = pwrte_alloc(Pwrte_point_to_point_id);
 97     p = &(pwrte->p_to_p);
 98     p->type1 = POINT3;
 99     p->type2 = POINT3;
100     p->p1 = (void *) p1;
101     p->p2 = (void *) p2;
102 
103     dist = vec3_mod(vec3_diff(p2->p, p1->p));
104 
105     iso1 = (Iso_error *) prop_get(p1->props, ISO_ERROR);
106     iso2 = (Iso_error *) prop_get(p2->props, ISO_ERROR);
107     poserror = iso1->pos + iso2->pos;
108     seperror = sep_error_ratio * dist;
109 
110     if (seperror > poserror)
111         poserror = seperror;
112 
113     p->lowdist = (float)((dist < poserror) ? 0 : dist - poserror);
114     p->hidist = (float)(dist + poserror);
115     return (pwrte);
116 }
117 
118 Pwrte  *pwrte_point_to_line_make(void *p1, int type1, void *p2, int type2)
119 {
120     Pwrte  *pwrte;
121     Pwrte_point_to_vec *p;
122     Point3 *point;
123     Line3  *line;
124     Iso_error *iso1;
125     Iso_error *iso2;
126     double  poserror, rot_lever, mind, d1, d2;
127     Vec3    closest = {Vec3_id};
128 
129     if (p1 == NULL || p2 == NULL)
130         return (NULL);
131 
132     pwrte = pwrte_alloc(Pwrte_point_to_vec_id);
133     p = &(pwrte->p_to_v);
134     p->type1 = type1;
135     p->type2 = type2;
136     p->p1 = p1;
137     p->p2 = p2;
138 
139     line = (type1 == LINE3) ? (Line3 *) p1 : (Line3 *) p2;
140     point = (type1 == POINT3) ? (Point3 *) p1 : (Point3 *) p2;
141 
142     iso1 = (Iso_error *) prop_get(point->props, ISO_ERROR);
143     iso2 = (Iso_error *) prop_get(line->props, ISO_ERROR);
144 
145     poserror = iso1->pos + iso2->pos;
146 
147     closest = vec3_proj_on_line(point->p, line->p, line->v);
148 
149     mind = vec3_mod(vec3_diff(point->p, closest));
150     d1 = vec3_dot(line->v, vec3_diff(closest, line->p1));/* signed value */
151     d2 = vec3_dot(line->v, vec3_diff(closest, line->p2));
152 
153     ORDER(double, d1, d2);
154     p->lowvecd = (float)(d1 - poserror - mind * iso2->rot);/* small angle sine
155                                                             * assump */
156     p->hivecd = (float)(d2 + poserror + mind * iso2->rot);
157 
158     rot_lever = (BETWEEN(0, d1, d2)) ? 0 : tina_fmin(fabs(d1), fabs(d2));
159     poserror += atan(iso2->rot) * rot_lever;
160 
161     p->lowmind = (float)((mind < poserror) ? 0.0 : mind - poserror);
162     p->himind = (float)(mind + poserror);
163     return (pwrte);
164 }
165 
166 Pwrte  *pwrte_point_to_conic_make(void *p1, int type1, void *p2, int type2)
167 {
168     Pwrte  *pwrte;
169     Pwrte_point_to_vec *p;
170     Point3 *point;
171     Conic3 *conic;
172     Iso_error *iso1;
173     Iso_error *iso2;
174     double  poserror, seperror, dist;
175     Vec3    closest = {Vec3_id};
176 
177     if (p1 == NULL || p2 == NULL)
178         return (NULL);
179 
180     pwrte = pwrte_alloc(Pwrte_point_to_vec_id);
181     p = &(pwrte->p_to_v);
182     p->type1 = type1;
183     p->type2 = type2;
184     p->p1 = p1;
185     p->p2 = p2;
186 
187     conic = (type1 == CONIC3) ? (Conic3 *) p1 : (Conic3 *) p2;
188     point = (type1 == POINT3) ? (Point3 *) p1 : (Point3 *) p2;
189 
190     dist = vec3_mod(vec3_diff(conic->origin, point->p));
191 
192     iso1 = (Iso_error *) prop_get(conic->conic->props, ISO_ERROR);
193     iso2 = (Iso_error *) prop_get(point->props, ISO_ERROR);
194     poserror = iso1->pos + iso2->pos;
195     seperror = sep_error_ratio * dist;
196 
197     if (seperror > poserror)
198         poserror = seperror;
199 
200     p->lowmind = (float)((dist < poserror) ? 0 : dist - poserror);
201     p->himind = (float)(dist + poserror);
202 
203     closest = vec3_proj_on_line(point->p, conic->origin, conic->ez);
204     dist = vec3_mod(vec3_diff(point->p, closest));
205     poserror += dist * iso1->rot;       /* small angle sine assumption */
206     dist = vec3_dot(conic->ez, vec3_diff(closest, conic->origin));
207     p->lowvecd = (float)(dist - poserror);
208     p->hivecd = (float)(dist + poserror);
209 
210     return (pwrte);
211 }
212 
213 Pwrte  *pwrte_line_to_line_make(Line3 * l1, Line3 * l2)
214 {
215     Pwrte  *pwrte;
216     Pwrte_vec_to_vec *p;
217     Iso_error *iso1;
218     Iso_error *iso2;
219     double  roterror, poserror;
220     double  dp, angle;
221 
222     if (l1 == NULL || l2 == NULL)
223         return (NULL);
224 
225     pwrte = pwrte_alloc(Pwrte_vec_to_vec_id);
226     p = &(pwrte->v_to_v);
227     p->type1 = LINE3;
228     p->type2 = LINE3;
229     p->p1 = (void *) l1;
230     p->p2 = (void *) l2;
231 
232     iso1 = (Iso_error *) prop_get(l1->props, ISO_ERROR);
233     iso2 = (Iso_error *) prop_get(l2->props, ISO_ERROR);
234 
235     roterror = iso1->rot + iso2->rot;
236     poserror = iso1->pos + iso2->pos;
237 
238     p->parallel = smm_geom_parallel((void *) l1, LINE3, (void *) l2, LINE3);
239 
240     dp = vec3_dot(l1->v, l2->v);
241     angle = tina_acos(dp);
242 
243     p->lowang = (float)((angle < roterror) ? 0.0 : angle - roterror);
244     p->hiang = (float)((angle + roterror > PI) ? PI : angle + roterror);
245 
246     if (p->parallel == false)
247     {
248         Vec3    c1 = {Vec3_id};
249         Vec3    c2 = {Vec3_id};
250         double  a1, b1, a2, b2, m1, m2;
251         double  tanrot, angscale;
252         double  mind, minderror;
253 
254         tanrot = atan(roterror);
255         angscale = tanrot / sin(fabs(angle));
256 
257         mind = vec3_closest_app(l1->p1, l1->v, l2->p1, l2->v, &c1, &c2);
258         a1 = vec3_dot(l1->v, vec3_diff(c1, l1->p1));    /* directed */
259         b1 = vec3_dot(l1->v, vec3_diff(c1, l1->p2));
260         a2 = vec3_dot(l2->v, vec3_diff(c2, l2->p1));
261         b2 = vec3_dot(l2->v, vec3_diff(c2, l2->p2));
262         m1 = (BETWEEN(0, a1, b1)) ? 0 : tina_fmin(fabs(a1), fabs(b1));
263         m2 = (BETWEEN(0, a2, b2)) ? 0 : tina_fmin(fabs(a2), fabs(b2));
264         ORDER(double, a1, b1);
265         ORDER(double, a2, b2);
266 
267         p->lowvec1 = (float)(a1 - poserror - m2 * angscale);
268         p->hivec1 = (float)(b1 + poserror + m2 * angscale);
269         p->lowvec2 = (float)(a2 - poserror - m1 * angscale);
270         p->hivec2 = (float)(b2 + poserror + m1 * angscale);
271 
272         minderror = (m1 + m2) * tanrot + poserror;
273 
274         p->lowmind = (float)(mind - minderror);
275         p->himind = (float)(mind + minderror);
276     } else
277     {
278         /* towards parallel */
279         double  d1, d2;
280 
281         if (l1->length > l2->length)
282         {
283             d1 = vec3_dist_point_line(l1->p1, l2->p1, l2->v);
284             d2 = vec3_dist_point_line(l1->p2, l2->p1, l2->v);
285         } else
286         {
287             d1 = vec3_dist_point_line(l2->p1, l1->p1, l1->v);
288             d2 = vec3_dist_point_line(l2->p2, l1->p1, l1->v);
289         }
290         ORDER(double, d1, d2);
291         p->lowmind = (float)((d1 < poserror) ? 0.0 : d1 - poserror);
292         p->himind = (float)(d2 + poserror);
293     }
294     return (pwrte);
295 }
296 
297 Pwrte  *pwrte_conic_to_line_make(Conic3 * conic, Line3 * line)
298 {
299     Pwrte  *pwrte;
300     Pwrte_vec_to_vec *p;
301     Iso_error *iso1;
302     Iso_error *iso2;
303     double  roterror, poserror;
304     double  dp, angle, dist, d1, d2, minderror, rot_lever;
305     Vec3    closest = {Vec3_id};
306 
307     if (conic == NULL || line == NULL)
308         return (NULL);
309 
310     pwrte = pwrte_alloc(Pwrte_vec_to_vec_id);
311     p = &(pwrte->v_to_v);
312     p->type1 = CONIC3;
313     p->type2 = LINE3;
314     p->p1 = (void *) conic;
315     p->p2 = (void *) line;
316 
317     iso1 = (Iso_error *) prop_get(conic->conic->props, ISO_ERROR);
318     iso2 = (Iso_error *) prop_get(line->props, ISO_ERROR);
319 
320     roterror = iso1->rot + iso2->rot;
321     poserror = iso1->pos + iso2->pos;
322 
323     p->parallel = smm_geom_parallel((void *) conic, CONIC3, (void *) line, LINE3);
324 
325     dp = vec3_dot(conic->ez, line->v);
326     angle = tina_acos(dp);
327 
328     p->lowang = (float)((angle < roterror) ? 0.0 : angle - roterror);
329     p->hiang = (float)((angle + roterror > PI) ? PI : angle + roterror);
330 
331     closest = vec3_proj_on_line(conic->origin, line->p, line->v);
332 
333     dist = vec3_mod(vec3_diff(conic->origin, closest));
334     d1 = vec3_dot(line->v, vec3_diff(closest, line->p1));       /* signed value */
335     d2 = vec3_dot(line->v, vec3_diff(closest, line->p2));
336 
337     ORDER(double, d1, d2);
338     p->lowvec2 = (float)(d1 - poserror - dist * iso2->rot);
339     p->hivec2 = (float)(d2 + poserror + dist * iso2->rot);
340 
341     rot_lever = (BETWEEN(0, d1, d2)) ? 0 : tina_fmin(fabs(d1), fabs(d2));
342     minderror = poserror + atan(iso2->rot) * rot_lever;
343 
344     p->lowmind = (float)((dist < minderror) ? 0.0 : dist - minderror);
345     p->himind = (float)(dist + minderror);
346 
347     if (p->parallel == false)
348     {
349         Vec3    c1 = {Vec3_id};
350         Vec3    c2 = {Vec3_id};
351         double  tanrot, angscale;
352 
353         tanrot = atan(roterror);
354         angscale = tanrot / sin(fabs(angle));
355 
356         (void) vec3_closest_app(conic->origin, conic->ez, line->p1, line->v, &c1, &c2);
357         dist = vec3_dot(conic->ez, vec3_diff(c1, conic->origin));
358         d1 = vec3_dot(line->v, vec3_diff(c1, line->p1));
359         d2 = vec3_dot(line->v, vec3_diff(c1, line->p2));
360         angscale *= (BETWEEN(0, d1, d2)) ? 0 : tina_fmin(fabs(d1), fabs(d2));
361 
362         p->lowvec1 = (float)(dist - poserror - angscale);
363         p->hivec1 = (float)(dist + poserror + angscale);
364     }
365     return (pwrte);
366 }
367 
368 Pwrte  *pwrte_line_to_conic_make(Line3 * line, Conic3 * conic)
369 {
370     Pwrte  *pwrte;
371     Pwrte_vec_to_vec *p;
372     Iso_error *iso1;
373     Iso_error *iso2;
374     double  roterror, poserror;
375     double  dp, angle, dist, d1, d2, minderror, rot_lever;
376     Vec3    closest = {Vec3_id};
377 
378     if (conic == NULL || line == NULL)
379         return (NULL);
380 
381     pwrte = pwrte_alloc(Pwrte_vec_to_vec_id);
382     p = &(pwrte->v_to_v);
383     p->type1 = LINE3;
384     p->type2 = CONIC3;
385     p->p1 = (void *) line;
386     p->p2 = (void *) conic;
387 
388     iso1 = (Iso_error *) prop_get(line->props, ISO_ERROR);
389     iso2 = (Iso_error *) prop_get(conic->conic->props, ISO_ERROR);
390 
391     roterror = iso1->rot + iso2->rot;
392     poserror = iso1->pos + iso2->pos;
393 
394     p->parallel = smm_geom_parallel((void *) conic, CONIC3, (void *) line, LINE3);
395 
396     dp = vec3_dot(conic->ez, line->v);
397     angle = tina_acos(dp);
398 
399     p->lowang = (float)((angle < roterror) ? 0.0 : angle - roterror);
400     p->hiang = (float)((angle + roterror > PI) ? PI : angle + roterror);
401 
402     closest = vec3_proj_on_line(conic->origin, line->p, line->v);
403 
404     dist = vec3_mod(vec3_diff(conic->origin, closest));
405     d1 = vec3_dot(line->v, vec3_diff(closest, line->p1));       /* signed value */
406     d2 = vec3_dot(line->v, vec3_diff(closest, line->p2));
407 
408     ORDER(double, d1, d2);
409     p->lowvec1 = (float)(d1 - poserror - dist * iso2->rot);
410     p->hivec1 = (float)(d2 + poserror + dist * iso2->rot);
411 
412     rot_lever = (BETWEEN(0, d1, d2)) ? 0 : tina_fmin(fabs(d1), fabs(d2));
413     minderror = poserror + atan(iso2->rot) * rot_lever;
414 
415     p->lowmind = (float)((dist < minderror) ? 0.0 : dist - minderror);
416     p->himind = (float)(dist + minderror);
417 
418     if (p->parallel == false)
419     {
420         Vec3    c1 = {Vec3_id};
421         Vec3    c2 = {Vec3_id};
422         double  tanrot, angscale;
423 
424         tanrot = atan(roterror);
425         angscale = tanrot / sin(fabs(angle));
426 
427         (void) vec3_closest_app(conic->origin, conic->ez, line->p1, line->v, &c1, &c2);
428         dist = vec3_dot(conic->ez, vec3_diff(c1, conic->origin));
429         d1 = vec3_dot(line->v, vec3_diff(c1, line->p1));
430         d2 = vec3_dot(line->v, vec3_diff(c1, line->p2));
431         angscale *= (BETWEEN(0, d1, d2)) ? 0 : tina_fmin(fabs(d1), fabs(d2));
432 
433         p->lowvec2 = (float)(dist - poserror - angscale);
434         p->hivec2 = (float)(dist + poserror + angscale);
435     }
436     return (pwrte);
437 }
438 
439 Pwrte  *pwrte_conic_to_conic_make(Conic3 * c1, Conic3 * c2)
440 {
441     Pwrte  *pwrte;
442     Pwrte_vec_to_vec *p;
443     Iso_error *iso1;
444     Iso_error *iso2;
445     double  roterror, poserror, seperror;
446     double  dp, angle, dist;
447     Vec3    closest = {Vec3_id};
448 
449     if (c1 == NULL || c2 == NULL)
450         return (NULL);
451 
452     pwrte = pwrte_alloc(Pwrte_vec_to_vec_id);
453     p = &(pwrte->v_to_v);
454     p->type1 = CONIC3;
455     p->type2 = CONIC3;
456     p->p1 = (void *) c1;
457     p->p2 = (void *) c2;
458 
459     dist = vec3_mod(vec3_diff(c1->origin, c2->origin));
460 
461     iso1 = (Iso_error *) prop_get(c1->conic->props, ISO_ERROR);
462     iso2 = (Iso_error *) prop_get(c2->conic->props, ISO_ERROR);
463 
464     roterror = iso1->rot + iso2->rot;
465     poserror = iso1->pos + iso2->pos;
466     seperror = sep_error_ratio * dist;
467 
468     if (seperror > poserror)
469         poserror = seperror;
470 
471     p->parallel = false;
472 
473     dp = vec3_dot(c1->ez, c2->ez);
474     angle = tina_acos(dp);
475 
476     p->lowang = (float)((angle < roterror) ? 0.0 : angle - roterror);
477     p->hiang = (float)((angle + roterror > PI) ? PI : angle + roterror);
478 
479     p->lowmind = (float)((dist < poserror) ? 0 : dist - poserror);
480     p->himind = (float)(dist + poserror);
481 
482     closest = vec3_proj_on_line(c2->origin, c1->origin, c1->ez);
483     roterror = vec3_mod(vec3_diff(closest, c2->origin)) * iso1->rot;
484     dist = vec3_dot(c1->ez, vec3_diff(closest, c1->origin));
485     p->lowvec1 = (float)(dist - poserror - roterror);
486     p->hivec1 = (float)(dist + poserror + roterror);
487 
488     closest = vec3_proj_on_line(c1->origin, c2->origin, c2->ez);
489     roterror = vec3_mod(vec3_diff(closest, c1->origin)) * iso2->rot;
490     dist = vec3_dot(c2->ez, vec3_diff(closest, c2->origin));
491     p->lowvec2 = (float)(dist - poserror - roterror);
492     p->hivec2 = (float)(dist + poserror + roterror);
493 
494     return (pwrte);
495 }
496 
497 Pwrte  *pwrte_make(void *p1, int type1, void *p2, int type2)
498 {
499     switch (PAIR(type1, type2))
500     {
501         case PAIR(POINT3, POINT3):
502         return (pwrte_point_to_point_make((Point3 *) p1, (Point3 *) p2));
503     case PAIR(POINT3, LINE3):
504         return (pwrte_point_to_line_make(p1, type1, p2, type2));
505     case PAIR(POINT3, CONIC3):
506         return (pwrte_point_to_conic_make(p1, type1, p2, type2));
507     case PAIR(LINE3, LINE3):
508         return (pwrte_line_to_line_make((Line3 *) p1, (Line3 *) p2));
509     case PAIR(LINE3, CONIC3):
510         switch (OPAIR(type1, type2))
511         {
512         case OPAIR(LINE3, CONIC3):
513             return (pwrte_line_to_conic_make((Line3 *) p1, (Conic3 *) p2));
514         case OPAIR(CONIC3, LINE3):
515             return (pwrte_conic_to_line_make((Conic3 *) p1, (Line3 *) p2));
516         }
517     case PAIR(CONIC3, CONIC3):
518         return (pwrte_conic_to_conic_make((Conic3 *) p1, (Conic3 *) p2));
519     default:
520         return (NULL);
521     }
522 }
523 
524 Bool    point_to_point_pwrte_compatible(Pwrte_point_to_point * p1, Pwrte_point_to_point * p2)
525 {
526     if (p1 == NULL || p2 == NULL)
527         return (false);
528 
529     if (!OVERLAPPED(p1->lowdist, p1->hidist, p2->lowdist, p2->hidist))
530         return (false);
531     return (true);
532 }
533 
534 Bool    point_to_vec_pwrte_compatible(Pwrte_point_to_vec * p1, Pwrte_point_to_vec * p2)
535 {
536     if (p1 == NULL || p2 == NULL)
537         return (false);
538 
539     if (!OVERLAPPED(p1->lowmind, p1->himind, p2->lowmind, p2->himind))
540         return (false);
541 
542     if (!OVERLAPPED(p1->lowvecd, p1->hivecd, p2->lowvecd, p2->hivecd))
543         return (false);
544 
545     return (true);
546 }
547 
548 Bool    line_to_line_pwrte_compatible(Pwrte_vec_to_vec * p1, Pwrte_vec_to_vec * p2)
549 {
550     if (p1 == NULL || p2 == NULL)
551         return (false);
552 
553     if (!OVERLAPPED(p1->lowang, p1->hiang, p2->lowang, p2->hiang))
554         return (false);
555 
556     if (p1->parallel == false && p2->parallel == false)
557     {
558         if (!OVERLAPPED(p1->lowmind, p1->himind, p2->lowmind, p2->himind))
559             return (false);
560 
561         if (!OVERLAPPED(p1->lowvec1, p1->hivec1, p2->lowvec1, p2->hivec1))
562             return (false);
563 
564         if (!OVERLAPPED(p1->lowvec2, p1->hivec2, p2->lowvec2, p2->hivec2))
565             return (false);
566 
567         return (true);
568     }
569     if (p1->parallel == p2->parallel)   /* both parallel */
570     {
571         if (OVERLAPPED(p1->lowmind, p1->himind, p2->lowmind, p2->himind))
572             return (true);
573         else
574             return (false);
575     }
576     if (p1->parallel == true)
577     {
578         double  d1, d2;
579         Line3  *l1 = (Line3 *) p2->p1;
580         Line3  *l2 = (Line3 *) p2->p2;
581 
582         if (l1->length > l2->length)
583         {
584             d1 = vec3_dist_point_line(l1->p1, l2->p1, l2->v);
585             d2 = vec3_dist_point_line(l1->p2, l2->p1, l2->v);
586         } else
587         {
588             d1 = vec3_dist_point_line(l2->p1, l1->p1, l1->v);
589             d2 = vec3_dist_point_line(l2->p2, l1->p1, l1->v);
590         }
591         ORDER(double, d1, d2);
592         return (OVERLAPPED(p1->lowmind, p1->himind, d1, d2) ? true : false);
593     } else
594     {
595         /* p2 parallel */
596         double  d1, d2;
597         Line3  *l1 = (Line3 *) p1->p1;
598         Line3  *l2 = (Line3 *) p1->p2;
599 
600         if (l1->length > l2->length)
601         {
602             d1 = vec3_dist_point_line(l1->p1, l2->p1, l2->v);
603             d2 = vec3_dist_point_line(l1->p2, l2->p1, l2->v);
604         } else
605         {
606             d1 = vec3_dist_point_line(l2->p1, l1->p1, l1->v);
607             d2 = vec3_dist_point_line(l2->p2, l1->p1, l1->v);
608         }
609         ORDER(double, d1, d2);
610         return (OVERLAPPED(p2->lowmind, p2->himind, d1, d2) ? true : false);
611     }
612 }
613 
614 Bool    line_to_conic_pwrte_compatible(Pwrte_vec_to_vec * p1, Pwrte_vec_to_vec * p2)
615 {
616     Bool    parallel;
617 
618     if (p1 == NULL || p2 == NULL)
619         return (false);
620 
621     if (!OVERLAPPED(p1->lowang, p1->hiang, p2->lowang, p2->hiang))
622         return (false);
623 
624     if (!OVERLAPPED(p1->lowmind, p1->himind, p2->lowmind, p2->himind))
625         return (false);
626 
627     parallel = (Bool) (p1->parallel == true || p2->parallel == true);
628 
629     if ((parallel == false || p1->type1 == LINE3) &&    /* if // only test line */
630         !OVERLAPPED(p1->lowvec1, p1->hivec1, p2->lowvec1, p2->hivec1))
631         return (false);
632 
633     if ((parallel == false || p1->type2 == LINE3) &&    /* if // only test line */
634         !OVERLAPPED(p1->lowvec2, p1->hivec2, p2->lowvec2, p2->hivec2))
635         return (false);
636 
637     return (true);
638 }
639 
640 Bool    conic_to_conic_pwrte_compatible(Pwrte_vec_to_vec * p1, Pwrte_vec_to_vec * p2)
641 {
642     if (p1 == NULL || p2 == NULL)
643         return (false);
644 
645     if (!OVERLAPPED(p1->lowang, p1->hiang, p2->lowang, p2->hiang))
646         return (false);
647 
648     if (!OVERLAPPED(p1->lowmind, p1->himind, p2->lowmind, p2->himind))
649         return (false);
650 
651     if (!OVERLAPPED(p1->lowvec1, p1->hivec1, p2->lowvec1, p2->hivec1))
652         return (false);
653 
654     if (!OVERLAPPED(p1->lowvec2, p1->hivec2, p2->lowvec2, p2->hivec2))
655         return (false);
656 
657     return (true);
658 }
659 
660 Bool    pwrte_compatible(Pwrte * p1, Pwrte * p2)
661 {
662     if (p1 == NULL || p2 == NULL)
663         return (false);
664 
665     if (OPAIR(p1->gen.type1, p1->gen.type2) != OPAIR(p2->gen.type1, p2->gen.type2))
666         return (false);
667 
668     switch (PAIR(p1->gen.type1, p1->gen.type2))
669     {
670     case PAIR(POINT3, POINT3):
671         return (point_to_point_pwrte_compatible(&(p1->p_to_p), &(p2->p_to_p)));
672     case PAIR(POINT3, LINE3):
673     case PAIR(POINT3, CONIC3):
674         return (point_to_vec_pwrte_compatible(&(p1->p_to_v), &(p2->p_to_v)));
675     case PAIR(LINE3, LINE3):
676         return (line_to_line_pwrte_compatible(&(p1->v_to_v), &(p2->v_to_v)));
677     case PAIR(LINE3, CONIC3):
678         return (line_to_conic_pwrte_compatible(&(p1->v_to_v), &(p2->v_to_v)));
679     case PAIR(CONIC3, CONIC3):
680         return (conic_to_conic_pwrte_compatible(&(p1->v_to_v), &(p2->v_to_v)));
681     }
682     return (false);
683 }
684 
685 void    pwrte_set_entry(Matrix * table, void *p1, int type1, void *p2, int type2)
686 /* of shape full; type ptr_v */
687 
688 
689 {
690     int     i, j;
691 
692     i = (int) geom_prop_get(p1, type1, PWR);
693     j = (int) geom_prop_get(p2, type2, PWR);
694 
695     if (table->el.ptr_v[i][j] == NULL)
696         table->el.ptr_v[i][j] = (void *) pwrte_make(p1, type1, p2, type2);
697     if (i != j && table->el.ptr_v[j][i] == NULL)
698         table->el.ptr_v[j][i] = (void *) pwrte_make(p2, type2, p1, type1);
699 }
700 
701 Matrix *pwrte_build_full_table(List * list)
702 /* list of geom primitives */
703 {
704     List   *l1;
705     List   *l2;
706     Matrix *table;
707     int     n;
708 
709     if (list == NULL)
710         return (NULL);
711 
712     for (n = 0, l1 = list; l1 != NULL; l1 = l1->next, n++)
713         geom_prop_addifnp(l1->to, l1->type, (void *) n, PWR, (void (*) ()) NULL, false);
714 
715     table = matrix_alloc(n, n, matrix_full, ptr_v);
716 
717     if (list->next == NULL)
718         return (table);
719 
720     for (l1 = list; l1->next != NULL; l1 = l1->next)
721         for (l2 = l1->next; l2 != NULL; l2 = l2->next)
722             pwrte_set_entry(table, l1->to, l1->type, l2->to, l2->type);
723 
724     return (table);
725 }
726 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.