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

Linux Cross Reference
Tina4/src/vision/geom/geom_hull.c

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

  1 /**@(#)
  2 **/
  3 #include <stdio.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 #include <tina/vision.h>
  9 #include <tina/visionfuncs.h>
 10 
 11 /* crude use static variables in reclist_list_apply */
 12 static Vec3 vmin = {Vec3_id};
 13 static Vec3 vmax = {Vec3_id};
 14 
 15 /* add a single 3D geometrical primitive to the current hull bounds */
 16 static void geom_add_to_hull(void *geom, int type)
 17 {
 18     switch (type)
 19     {
 20         case POINT3:
 21         vec3_extend_hull(&vmin, &vmax, ((Point3 *) geom)->p);
 22         break;
 23     case LINE3:
 24         vec3_extend_hull(&vmin, &vmax, ((Line3 *) geom)->p1);
 25         vec3_extend_hull(&vmin, &vmax, ((Line3 *) geom)->p2);
 26         break;
 27     case CONIC3:
 28         {
 29             Conic3 *c3 = (Conic3 *) geom;
 30             double  t;
 31 
 32             vec3_extend_hull(&vmin, &vmax, conic3_point(c3, c3->conic->t1));
 33             vec3_extend_hull(&vmin, &vmax, conic3_point(c3, c3->conic->t2));
 34             t = (c3->conic->t1 + c3->conic->t2) * 0.5;
 35             vec3_extend_hull(&vmin, &vmax, conic3_point(c3, t));
 36             break;
 37         }
 38     case PLANE:
 39         vec3_extend_hull(&vmin, &vmax, ((Plane *) geom)->p);
 40         break;
 41     }
 42 }
 43 
 44 /* takes a list (might be recursive) of geometrical primitives and
 45  * computes an approximate bounding hull, represented as a centre and
 46  * radius
 47  * 
 48  * does not protect against a list with no 3D geometry in it */
 49 
 50 void    geom_hull_get(List * geom, Vec3 * centre, double *radius)
 51 {
 52     /* initialise hull bounds */
 53     vmin = vec3(1e10, 1e10, 1e10);
 54     vmax = vec3(-1e10, -1e10, -1e10);
 55 
 56     reclist_list_apply(geom, geom_add_to_hull, (int) NULL, NULL);
 57 
 58     *centre = vec3_times(0.5, vec3_sum(vmin, vmax));
 59     *radius = 0.45 * vec3_dist(vmin, vmax);
 60 }
 61 

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