00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
#ifndef lint
00017
static char rcsid[] =
"$Header: /software/source//libraries/bicpl/Geometry/flatten.c,v 1.5 2000/02/06 15:30:13 stever Exp $";
00018
#endif
00019
00020
#include <bicpl/geom.h>
00021
#include <bicpl/trans.h>
00022
#include <volume_io/internal_volume_io.h>
00023
00024 public void flatten_around_vertex(
00025 Point *vertex,
00026
int n_neighbours,
00027 Point neighbours[],
00028 BOOLEAN closed_flag,
00029 Real x_flat[],
00030 Real y_flat[] )
00031 {
00032 Real sum_angles, factor, angle, dist;
00033
int i;
00034
00035 sum_angles = 0.0;
00036
00037 for_less( i, 0, n_neighbours )
00038 {
00039
if( closed_flag || i < n_neighbours-1 )
00040 {
00041 angle =
get_angle_between_points( &neighbours[i], vertex,
00042 &neighbours[(i+1)%n_neighbours] );
00043 sum_angles += angle;
00044 }
00045 }
00046
00047
if( sum_angles == 0.0 )
00048 {
00049 print_error(
"flatten_around_vertex: sum of angles is 0.\n" );
00050
return;
00051 }
00052
00053
if( !closed_flag && sum_angles < 2.0 * PI )
00054 factor = 1.0;
00055
else
00056 factor = 2.0 * PI / sum_angles;
00057
00058 sum_angles = 0.0;
00059 for_less( i, 0, n_neighbours )
00060 {
00061 angle = sum_angles * factor;
00062
00063 dist =
distance_between_points( vertex, &neighbours[i] );
00064
00065 x_flat[i] = dist * cos( angle );
00066 y_flat[i] = dist * sin( angle );
00067
00068 angle =
get_angle_between_points( &neighbours[i], vertex,
00069 &neighbours[(i+1)%n_neighbours] );
00070 sum_angles += angle;
00071 }
00072 }
00073
00074 public void flatten_around_vertex_to_sphere(
00075 Real radius,
00076 Point *vertex,
00077
int n_neighbours,
00078 Point neighbours[],
00079 Real x_sphere[],
00080 Real y_sphere[],
00081 Real z_sphere[] )
00082 {
00083
int n;
00084 Real *x_flat, *y_flat, angle, x,
y, z, dist;
00085 Vector axis;
00086 Transform transform;
00087
00088 ALLOC( x_flat, n_neighbours );
00089 ALLOC( y_flat, n_neighbours );
00090
00091
flatten_around_vertex( vertex, n_neighbours, neighbours,
TRUE,
00092 x_flat, y_flat );
00093
00094 for_less( n, 0, n_neighbours )
00095 {
00096 dist = sqrt( x_flat[n] * x_flat[n] + y_flat[n] * y_flat[n] );
00097
if( dist / 2.0 > radius )
00098 dist = 2.0 * radius;
00099 angle = -2.0 * asin( dist / 2.0 / radius );
00100 fill_Vector( axis, y_flat[n], -x_flat[n], 0.0 );
00101 NORMALIZE_VECTOR( axis, axis );
00102
if(
null_Vector( &axis ) )
00103 {
00104 x_sphere[n] = 0.0;
00105 y_sphere[n] = 0.0;
00106 z_sphere[n] = 0.0;
00107 }
00108
else
00109 {
00110
make_rotation_about_axis( &axis, angle, &transform );
00111 transform_point( &transform, 0.0, 0.0, radius, &x, &
y, &z );
00112 z -= radius;
00113 x_sphere[n] = x;
00114 y_sphere[n] =
y;
00115 z_sphere[n] = z;
00116 }
00117 }
00118
00119 FREE( x_flat );
00120 FREE( y_flat );
00121 }