Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

surface_area.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- 00002 @COPYRIGHT : 00003 Copyright 1993,1994,1995 David MacDonald, 00004 McConnell Brain Imaging Centre, 00005 Montreal Neurological Institute, McGill University. 00006 Permission to use, copy, modify, and distribute this 00007 software and its documentation for any purpose and without 00008 fee is hereby granted, provided that the above copyright 00009 notice appear in all copies. The author and McGill University 00010 make no representations about the suitability of this 00011 software for any purpose. It is provided "as is" without 00012 express or implied warranty. 00013 ---------------------------------------------------------------------------- */ 00014 00015 #include <volume_io/internal_volume_io.h> 00016 #include <bicpl/geom.h> 00017 00018 #ifndef lint 00019 static char rcsid[] = "$Header: /software/source//libraries/bicpl/Geometry/surface_area.c,v 1.7 2000/02/06 15:30:19 stever Exp $"; 00020 #endif 00021 00022 /* ----------------------------- MNI Header ----------------------------------- 00023 @NAME : get_polygon_2d_area 00024 @INPUT : n_points 00025 points 00026 @OUTPUT : 00027 @RETURNS : area 00028 @DESCRIPTION: Computes the area of a 2D polygon (convex or not). 00029 @METHOD : 00030 @GLOBALS : 00031 @CALLS : 00032 @CREATED : 1993 David MacDonald 00033 @MODIFIED : 00034 ---------------------------------------------------------------------------- */ 00035 00036 public Real get_polygon_2d_area( 00037 int n_points, 00038 Point points[] ) 00039 { 00040 int i, next_i; 00041 Real area; 00042 00043 area = 0.0; 00044 00045 for_less( i, 0, n_points ) 00046 { 00047 next_i = (i + 1) % n_points; 00048 area += (Real) Point_x(points[i]) * (Real) Point_y(points[next_i])- 00049 (Real) Point_x(points[next_i]) * (Real) Point_y(points[i]); 00050 } 00051 00052 return( FABS( area / 2.0 ) ); 00053 } 00054 00055 /* ----------------------------- MNI Header ----------------------------------- 00056 @NAME : get_polygon_surface_area 00057 @INPUT : n_points 00058 points 00059 @OUTPUT : 00060 @RETURNS : surface area 00061 @DESCRIPTION: Returns the surface area of the 3D polygon (convex or not). 00062 If it is not planar, then the surface area is just an 00063 approximation. 00064 @METHOD : 00065 @GLOBALS : 00066 @CALLS : 00067 @CREATED : 1993 David MacDonald 00068 @MODIFIED : 00069 ---------------------------------------------------------------------------- */ 00070 00071 public Real get_polygon_surface_area( 00072 int n_points, 00073 Point points[] ) 00074 { 00075 int i; 00076 Vector prev, this, cross_prod, sum; 00077 Real surface_area; 00078 00079 fill_Vector( sum, 0.0, 0.0, 0.0 ); 00080 SUB_VECTORS( this, points[1], points[0] ); 00081 00082 for_less( i, 2, n_points ) 00083 { 00084 prev = this; 00085 SUB_VECTORS( this, points[i], points[0] ); 00086 CROSS_VECTORS( cross_prod, prev, this ); 00087 ADD_VECTORS( sum, sum, cross_prod ); 00088 } 00089 00090 surface_area = MAGNITUDE( sum ) / 2.0; 00091 00092 return( surface_area ); 00093 } 00094 00095 /* ----------------------------- MNI Header ----------------------------------- 00096 @NAME : get_polygons_surface_area 00097 @INPUT : polygons 00098 @OUTPUT : 00099 @RETURNS : surface area 00100 @DESCRIPTION: Computes the sum of the surface areas of all the polygons. 00101 @METHOD : 00102 @GLOBALS : 00103 @CALLS : 00104 @CREATED : 1993 David MacDonald 00105 @MODIFIED : 00106 ---------------------------------------------------------------------------- */ 00107 00108 public Real get_polygons_surface_area( 00109 polygons_struct *polygons ) 00110 { 00111 int poly, size; 00112 Point points[MAX_POINTS_PER_POLYGON]; 00113 Real surface_area; 00114 00115 surface_area = 0.0; 00116 00117 for_less( poly, 0, polygons->n_items ) 00118 { 00119 size = get_polygon_points( polygons, poly, points ); 00120 surface_area += get_polygon_surface_area( size, points ); 00121 } 00122 00123 return( surface_area ); 00124 }

Generated on Wed Jul 28 09:10:58 2004 for BICPL by doxygen 1.3.7