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

subdivide_lines.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/subdivide_lines.c,v 1.10 2000/02/06 15:30:18 stever Exp $"; 00020 #endif 00021 00022 /* ----------------------------- MNI Header ----------------------------------- 00023 @NAME : subdivide_line 00024 @INPUT : l 00025 @OUTPUT : new_n_points 00026 new_points 00027 new_n_lines 00028 new_end_indices 00029 new_n_indices 00030 new_indices 00031 @RETURNS : 00032 @DESCRIPTION: Subdivides the l'th line segment, adding to the new line. 00033 @METHOD : 00034 @GLOBALS : 00035 @CALLS : 00036 @CREATED : 1993 David MacDonald 00037 @MODIFIED : 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 /* ----------------------------- MNI Header ----------------------------------- 00082 @NAME : general_subdivide_lines 00083 @INPUT : lines 00084 @OUTPUT : 00085 @RETURNS : 00086 @DESCRIPTION: Subdivides a line structure of any topology. 00087 @METHOD : 00088 @GLOBALS : 00089 @CALLS : 00090 @CREATED : 1993 David MacDonald 00091 @MODIFIED : 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 /* ----------------------------- MNI Header ----------------------------------- 00132 @NAME : subdivide_closed_curve 00133 @INPUT : lines 00134 @OUTPUT : 00135 @RETURNS : 00136 @DESCRIPTION: Subdivides a lines structure of a single loop topology, into 00137 similar topology. 00138 @METHOD : 00139 @GLOBALS : 00140 @CALLS : 00141 @CREATED : 1993 David MacDonald 00142 @MODIFIED : 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 /* ----------------------------- MNI Header ----------------------------------- 00175 @NAME : is_single_closed_curve 00176 @INPUT : 00177 @OUTPUT : 00178 @RETURNS : TRUE if single loop 00179 @DESCRIPTION: Checks if lines is a single closed loop, with indices 00180 0, 1, 2, lines->n_points-1, 0. 00181 @METHOD : 00182 @GLOBALS : 00183 @CALLS : 00184 @CREATED : 1993 David MacDonald 00185 @MODIFIED : 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 /* ----------------------------- MNI Header ----------------------------------- 00214 @NAME : subdivide_lines 00215 @INPUT : lines 00216 @OUTPUT : 00217 @RETURNS : 00218 @DESCRIPTION: Subdivides the lines, splitting each segment in half. 00219 @METHOD : 00220 @GLOBALS : 00221 @CALLS : 00222 @CREATED : 1993 David MacDonald 00223 @MODIFIED : 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 }

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