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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomGen_hull.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/geometry/geomGen_hull.c,v $
 27  * Date    :  $Date: 2008/12/07 04:33:58 $
 28  * Version :  $Revision: 1.3 $
 29  * CVS Id  :  $Id: geomGen_hull.c,v 1.3 2008/12/07 04:33:58 paul Exp $
 30  *
 31  * Notes :
 32  *
 33  *********
 34 */
 35 
 36 
 37 #include "geomGen_hull.h"
 38 
 39 #if HAVE_CONFIG_H
 40   #include <config.h>
 41 #endif
 42 
 43 #include <tina/sys/sysDef.h>
 44 #include <tina/sys/sysPro.h>
 45 #include <tina/math/mathDef.h>
 46 #include <tina/math/mathPro.h>
 47 #include <tina/geometry/geomDef.h>
 48 #include <tina/geometry/geom_PointDef.h>
 49 #include <tina/geometry/geom_LineDef.h>
 50 #include <tina/geometry/geom_CurveDef.h>
 51 #include <tina/geometry/geom_CurvePro.h>
 52 
 53 
 54 /* crude use static variables in reclist_list_apply */
 55 static Vec3 vmin = {Vec3_id};           /* static data! */
 56 static Vec3 vmax = {Vec3_id};           /* static data! */
 57 
 58 /* add a single 3D geometrical primitive to the current hull bounds */
 59 static void geom_add_to_hull(void *geom, int type)
 60 {
 61     switch (type)
 62     {
 63         case POINT3:
 64         vec3_extend_hull(&vmin, &vmax, ((Point3 *) geom)->p);
 65         break;
 66     case LINE3:
 67         vec3_extend_hull(&vmin, &vmax, ((Line3 *) geom)->p1);
 68         vec3_extend_hull(&vmin, &vmax, ((Line3 *) geom)->p2);
 69         break;
 70     case CONIC3:
 71         {
 72             Conic3 *c3 = (Conic3 *) geom;
 73             double  t;
 74 
 75             vec3_extend_hull(&vmin, &vmax, conic3_point(c3, c3->conic->t1));
 76             vec3_extend_hull(&vmin, &vmax, conic3_point(c3, c3->conic->t2));
 77             t = (c3->conic->t1 + c3->conic->t2) * 0.5;
 78             vec3_extend_hull(&vmin, &vmax, conic3_point(c3, t));
 79             break;
 80         }
 81     case PLANE:
 82         vec3_extend_hull(&vmin, &vmax, ((Plane *) geom)->p);
 83         break;
 84     }
 85 }
 86 
 87 /* takes a list (might be recursive) of geometrical primitives and
 88  * computes an approximate bounding hull, represented as a centre and
 89  * radius
 90  * 
 91  * does not protect against a list with no 3D geometry in it */
 92 
 93 void    geom_hull_get(List * geom, Vec3 * centre, double *radius)
 94 {
 95     /* initialise hull bounds */
 96     vmin = vec3(1e10, 1e10, 1e10);
 97     vmax = vec3(-1e10, -1e10, -1e10);
 98 
 99     reclist_list_apply(geom, geom_add_to_hull, 0, NULL);
100 
101     *centre = vec3_times(0.5, vec3_sum(vmin, vmax));
102     /*
103     *radius = 0.45 * vec3_dist(vmin, vmax);
104     */
105     *radius = 0.5 * sqrt((vmax.el[0]-vmin.el[0])*(vmax.el[0]-vmin.el[0])+
106                          (vmax.el[1]-vmin.el[1])*(vmax.el[1]-vmin.el[1]));
107 }
108 

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