00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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/subdivide_lines.c,v 1.10 2000/02/06 15:30:18 stever Exp $";
00020
#endif
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 private void subdivide_line(
00041
lines_struct *lines,
00042
int l,
00043
int *new_n_points,
00044 Point *new_points[],
00045
int *new_n_lines,
00046
int *new_end_indices[],
00047
int *new_n_indices,
00048
int *new_indices[] )
00049 {
00050
int edge, size, p1, p2, midpoint_index;
00051 Point midpoint;
00052
00053 size =
GET_OBJECT_SIZE( *lines, l );
00054
00055 for_less( edge, 0, size-1 )
00056 {
00057 p1 = lines->
indices[
POINT_INDEX(lines->
end_indices,l,edge)];
00058 p2 = lines->
indices[
POINT_INDEX(lines->
end_indices,l,edge+1)];
00059 midpoint_index = *new_n_points;
00060 INTERPOLATE_POINTS( midpoint, lines->
points[p1],
00061 lines->
points[p2], 0.5 );
00062 ADD_ELEMENT_TO_ARRAY( *new_points, *new_n_points,
00063 midpoint, DEFAULT_CHUNK_SIZE );
00064
00065
if( edge == 0 )
00066 {
00067 ADD_ELEMENT_TO_ARRAY( *new_indices, *new_n_indices,
00068 p1, DEFAULT_CHUNK_SIZE );
00069 }
00070
00071 ADD_ELEMENT_TO_ARRAY( *new_indices, *new_n_indices,
00072 midpoint_index, DEFAULT_CHUNK_SIZE );
00073 ADD_ELEMENT_TO_ARRAY( *new_indices, *new_n_indices,
00074 p2, DEFAULT_CHUNK_SIZE );
00075 }
00076
00077 ADD_ELEMENT_TO_ARRAY( *new_end_indices, *new_n_lines,
00078 *new_n_indices, DEFAULT_CHUNK_SIZE );
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 private void general_subdivide_lines(
00095
lines_struct *lines )
00096 {
00097
int size, i, new_n_points, new_n_indices, new_n_lines;
00098
int *new_indices, *new_end_indices;
00099 Point *new_points;
00100
00101 new_n_points = lines->
n_points;
00102 new_n_lines = 0;
00103 new_n_indices = 0;
00104 new_points = NULL;
00105
00106 size = 0;
00107 SET_ARRAY_SIZE( new_points, size, new_n_points, DEFAULT_CHUNK_SIZE );
00108
00109 for_less( i, 0, new_n_points )
00110 new_points[i] = lines->
points[i];
00111
00112 for_less( i, 0, lines->
n_items )
00113 {
00114
subdivide_line( lines, i, &new_n_points, &new_points,
00115 &new_n_lines, &new_end_indices,
00116 &new_n_indices, &new_indices );
00117 }
00118
00119
delete_lines( lines );
00120
00121 ALLOC( lines->
colours, 1);
00122 lines->
colours[0] =
WHITE;
00123 lines->
colour_flag =
ONE_COLOUR;
00124 lines->
n_points = new_n_points;
00125 lines->
points = new_points;
00126 lines->
n_items = new_n_lines;
00127 lines->
end_indices = new_end_indices;
00128 lines->
indices = new_indices;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 private void subdivide_closed_curve(
00146
lines_struct *lines )
00147 {
00148
int i;
00149 Point p1, p2, midpoint;
00150
00151 REALLOC( lines->
points, 2 * lines->
n_points );
00152
00153
for( i = lines->
n_points-1; i >= 0; --i )
00154 lines->
points[2*i] = lines->
points[i];
00155
00156 for_less( i, 0, lines->
n_points )
00157 {
00158 p1 = lines->
points[2* i];
00159 p2 = lines->
points[2* ((i+1)%lines->
n_points)];
00160 INTERPOLATE_POINTS( midpoint, p1, p2, 0.5 );
00161
00162 lines->
points[2*i+1] = midpoint;
00163 }
00164
00165 lines->
n_points = 2 * lines->
n_points;
00166 lines->
end_indices[0] = lines->
n_points + 1;
00167
00168 REALLOC( lines->
indices, lines->
n_points + 1 );
00169
00170 for_less( i, 0, lines->
n_points + 1 )
00171 lines->
indices[i] = i % lines->
n_points;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 public BOOLEAN
is_single_closed_curve(
00189
lines_struct *lines )
00190 {
00191
int i;
00192 BOOLEAN single_closed_curve;
00193
00194 single_closed_curve =
FALSE;
00195
00196
if( lines->
n_items == 1 &&
00197 lines->
n_points+1 == lines->
end_indices[0] )
00198 {
00199 single_closed_curve =
TRUE;
00200 for_less( i, 0, lines->
n_points + 1 )
00201 {
00202
if( lines->
indices[i] != (i % lines->
n_points) )
00203 {
00204 single_closed_curve =
FALSE;
00205
break;
00206 }
00207 }
00208 }
00209
00210
return( single_closed_curve );
00211 }
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 public void subdivide_lines(
00227
lines_struct *lines )
00228 {
00229
if(
is_single_closed_curve( lines ) )
00230
subdivide_closed_curve( lines );
00231
else
00232
general_subdivide_lines( lines );
00233 }