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

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

~ [ 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.