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

object_bintrees.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/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 /* ----------------------------- MNI Header ----------------------------------- 00025 @NAME : delete_the_bintree 00026 @INPUT : bintree 00027 @OUTPUT : 00028 @RETURNS : 00029 @DESCRIPTION: Deletes the bintree. 00030 @METHOD : 00031 @GLOBALS : 00032 @CALLS : 00033 @CREATED : 1993 David MacDonald 00034 @MODIFIED : 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 /* ----------------------------- MNI Header ----------------------------------- 00050 @NAME : check_install_bintree_delete_function 00051 @INPUT : 00052 @OUTPUT : 00053 @RETURNS : 00054 @DESCRIPTION: Checks whether the bintree delete function has been installed. 00055 In order to avoid linking in all the bintree stuff whenever 00056 object_struct's are used, the delete function is called as 00057 a pointer. 00058 @METHOD : 00059 @GLOBALS : 00060 @CALLS : 00061 @CREATED : 1993 David MacDonald 00062 @MODIFIED : 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 /* ----------------------------- MNI Header ----------------------------------- 00077 @NAME : allocate_bintree 00078 @INPUT : 00079 @OUTPUT : 00080 @RETURNS : 00081 @DESCRIPTION: Allocates a bintree structure. 00082 @METHOD : 00083 @GLOBALS : 00084 @CALLS : 00085 @CREATED : 1993 David MacDonald 00086 @MODIFIED : 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 /* ----------------------------- MNI Header ----------------------------------- 00099 @NAME : create_lines_bintree 00100 @INPUT : lines 00101 max_nodes 00102 @OUTPUT : 00103 @RETURNS : 00104 @DESCRIPTION: Creates a bintree for the lines, storing it in lines->bintree. 00105 @METHOD : 00106 @GLOBALS : 00107 @CALLS : 00108 @CREATED : 1993 David MacDonald 00109 @MODIFIED : 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 /* ----------------------------- MNI Header ----------------------------------- 00170 @NAME : create_polygons_bintree 00171 @INPUT : polygons 00172 max_nodes 00173 @OUTPUT : 00174 @RETURNS : 00175 @DESCRIPTION: Creates a bintree for the polygons, storing it in 00176 polygons->bintree. 00177 @METHOD : 00178 @GLOBALS : 00179 @CALLS : 00180 @CREATED : 1993 David MacDonald 00181 @MODIFIED : 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 /* ----------------------------- MNI Header ----------------------------------- 00219 @NAME : create_quadmesh_bintree 00220 @INPUT : quadmesh 00221 max_nodes 00222 @OUTPUT : 00223 @RETURNS : 00224 @DESCRIPTION: Creates a bintree for the quadmesh, storing it in 00225 quadmesh->bintree. 00226 @METHOD : 00227 @GLOBALS : 00228 @CALLS : 00229 @CREATED : 1993 David MacDonald 00230 @MODIFIED : 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 }

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