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/data_structures.h>
00017
#include <bicpl/geom.h>
00018
#include <bicpl/objects.h>
00019
00020
#ifndef lint
00021
static char rcsid[] =
"$Header: /software/source//libraries/bicpl/Data_structures/object_bintrees.c,v 1.11 2000/02/06 15:30:11 stever Exp $";
00022
#endif
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 public void delete_the_bintree(
00038
bintree_struct_ptr *bintree )
00039 {
00040
if( *bintree != (
bintree_struct_ptr) NULL )
00041 {
00042
delete_bintree( *bintree );
00043
00044 FREE( *bintree );
00045 *bintree = (
bintree_struct_ptr) NULL;
00046 }
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 private void check_install_bintree_delete_function(
void )
00066 {
00067
static BOOLEAN first =
TRUE;
00068
00069
if( first )
00070 {
00071 first =
FALSE;
00072
set_bintree_delete_function(
delete_the_bintree );
00073 }
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 public void *
allocate_bintree(
void )
00090 {
00091
bintree_struct_ptr bintree;
00092
00093 ALLOC( bintree, 1 );
00094
00095
return( (
void *) bintree );
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 public void create_lines_bintree(
00113
lines_struct *lines,
00114
int max_nodes )
00115 {
00116 Real radius;
00117
int line, size, n_segments, seg, object_id;
00118
range_struct *bound_vols;
00119 Point min_range, max_range;
00120 Point points[2];
00121
00122
check_install_bintree_delete_function();
00123
00124 lines->
bintree =
allocate_bintree();
00125
00126 n_segments = 0;
00127 for_less( line, 0, lines->
n_items )
00128 n_segments +=
GET_OBJECT_SIZE( *lines, line ) - 1;
00129
00130 ALLOC( bound_vols, n_segments );
00131
00132 radius = (Real) lines->
line_thickness;
00133
00134 object_id = 0;
00135 for_less( line, 0, lines->
n_items )
00136 {
00137 size =
GET_OBJECT_SIZE( *lines, line );
00138
00139 for_less( seg, 0, size - 1 )
00140 {
00141 points[0] = lines->
points[lines->
indices[
00142
POINT_INDEX(lines->
end_indices,line,seg)]];
00143 points[1] = lines->
points[lines->
indices[
00144
POINT_INDEX(lines->
end_indices,line,seg+1)]];
00145
00146
get_range_points( 2, points, &min_range, &max_range );
00147 bound_vols[object_id].
limits[X][0] =
00148 (
float) ((Real) Point_x(min_range) - radius);
00149 bound_vols[object_id].
limits[Y][0] =
00150 (
float) ((Real) Point_y(min_range) - radius);
00151 bound_vols[object_id].
limits[Z][0] =
00152 (
float) ((Real) Point_z(min_range) - radius);
00153 bound_vols[object_id].
limits[X][1] =
00154 (
float) ((Real) Point_x(max_range) + radius);
00155 bound_vols[object_id].
limits[Y][1] =
00156 (
float) ((Real) Point_y(max_range) + radius);
00157 bound_vols[object_id].
limits[Z][1] =
00158 (
float) ((Real) Point_z(max_range) + radius);
00159 ++object_id;
00160 }
00161 }
00162
00163
create_object_bintree( n_segments, bound_vols,
00164 lines->
bintree, max_nodes );
00165
00166 FREE( bound_vols );
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 public void create_polygons_bintree(
00185
polygons_struct *polygons,
00186
int max_nodes )
00187 {
00188
int poly, size;
00189
range_struct *bound_vols;
00190 Point min_range, max_range;
00191 Point points[
MAX_POINTS_PER_POLYGON];
00192
00193
check_install_bintree_delete_function();
00194
00195 polygons->
bintree =
allocate_bintree();
00196
00197 ALLOC( bound_vols, polygons->
n_items );
00198
00199 for_less( poly, 0, polygons->
n_items )
00200 {
00201 size =
get_polygon_points( polygons, poly, points );
00202
00203
get_range_points( size, points, &min_range, &max_range );
00204 bound_vols[poly].
limits[X][0] = Point_x(min_range);
00205 bound_vols[poly].
limits[Y][0] = Point_y(min_range);
00206 bound_vols[poly].
limits[Z][0] = Point_z(min_range);
00207 bound_vols[poly].
limits[X][1] = Point_x(max_range);
00208 bound_vols[poly].
limits[Y][1] = Point_y(max_range);
00209 bound_vols[poly].
limits[Z][1] = Point_z(max_range);
00210 }
00211
00212
create_object_bintree( polygons->
n_items, bound_vols,
00213 polygons->
bintree, max_nodes );
00214
00215 FREE( bound_vols );
00216 }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 public void create_quadmesh_bintree(
00234
quadmesh_struct *quadmesh,
00235
int max_nodes )
00236 {
00237
int i, j, m, n, obj_index;
00238
range_struct *bound_vols;
00239 Point min_range, max_range;
00240 Point points[4];
00241
00242
check_install_bintree_delete_function();
00243
00244 quadmesh->
bintree =
allocate_bintree();
00245
00246
get_quadmesh_n_objects( quadmesh, &m, &n );
00247
00248 ALLOC( bound_vols, m * n );
00249
00250 for_less( i, 0, m )
00251 {
00252 for_less( j, 0, n )
00253 {
00254 obj_index = IJ( i, j, n );
00255
get_quadmesh_patch( quadmesh, i, j, points );
00256
00257
get_range_points( 4, points, &min_range, &max_range );
00258
00259 bound_vols[obj_index].
limits[X][0] = Point_x(min_range);
00260 bound_vols[obj_index].
limits[Y][0] = Point_y(min_range);
00261 bound_vols[obj_index].
limits[Z][0] = Point_z(min_range);
00262 bound_vols[obj_index].
limits[X][1] = Point_x(max_range);
00263 bound_vols[obj_index].
limits[Y][1] = Point_y(max_range);
00264 bound_vols[obj_index].
limits[Z][1] = Point_z(max_range);
00265 }
00266 }
00267
00268
create_object_bintree( m * n, bound_vols,
00269 quadmesh->
bintree, max_nodes );
00270
00271 FREE( bound_vols );
00272 }