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

objects.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/objects.h> 00017 #include <bicpl/geom.h> 00018 00019 #ifndef lint 00020 static char rcsid[] = "$Header: /software/source//libraries/bicpl/Objects/objects.c,v 1.23 2000/02/06 15:30:44 stever Exp $"; 00021 #endif 00022 00023 private void advance_object_traverse( 00024 object_traverse_struct *object_traverse ); 00025 00026 /* ----------------------------- MNI Header ----------------------------------- 00027 @NAME : create_object 00028 @INPUT : object_type 00029 @OUTPUT : 00030 @RETURNS : an object 00031 @DESCRIPTION: Creates an object. 00032 @METHOD : 00033 @GLOBALS : 00034 @CALLS : 00035 @CREATED : 1993 David MacDonald 00036 @MODIFIED : 00037 ---------------------------------------------------------------------------- */ 00038 00039 public object_struct *create_object( 00040 Object_types object_type ) 00041 { 00042 object_struct *object; 00043 00044 ALLOC( object, 1 ); 00045 00046 object->object_type = object_type; 00047 object->visibility = TRUE; 00048 00049 return( object ); 00050 } 00051 00052 /* ----------------------------- MNI Header ----------------------------------- 00053 @NAME : get_object_type 00054 @INPUT : object 00055 @OUTPUT : 00056 @RETURNS : type 00057 @DESCRIPTION: Returns the type of the object. 00058 @METHOD : 00059 @GLOBALS : 00060 @CALLS : 00061 @CREATED : 1993 David MacDonald 00062 @MODIFIED : 00063 ---------------------------------------------------------------------------- */ 00064 00065 public Object_types get_object_type( 00066 object_struct *object ) 00067 { 00068 return( object->object_type ); 00069 } 00070 00071 /* ----------------------------- MNI Header ----------------------------------- 00072 @NAME : get_object_visibility 00073 @INPUT : object 00074 @OUTPUT : 00075 @RETURNS : visibility 00076 @DESCRIPTION: Returns the visibility of the object. 00077 @METHOD : 00078 @GLOBALS : 00079 @CALLS : 00080 @CREATED : 1993 David MacDonald 00081 @MODIFIED : 00082 ---------------------------------------------------------------------------- */ 00083 00084 public BOOLEAN get_object_visibility( 00085 object_struct *object ) 00086 { 00087 return( object->visibility ); 00088 } 00089 00090 /* ----------------------------- MNI Header ----------------------------------- 00091 @NAME : set_object_visibility 00092 @INPUT : object 00093 visibility 00094 @OUTPUT : 00095 @RETURNS : 00096 @DESCRIPTION: Sets the visibility of the object. 00097 @METHOD : 00098 @GLOBALS : 00099 @CALLS : 00100 @CREATED : 1993 David MacDonald 00101 @MODIFIED : 00102 ---------------------------------------------------------------------------- */ 00103 00104 public void set_object_visibility( 00105 object_struct *object, 00106 BOOLEAN visibility ) 00107 { 00108 object->visibility = visibility; 00109 } 00110 00111 /* ----------------------------- MNI Header ----------------------------------- 00112 @NAME : get_lines_ptr 00113 @INPUT : object 00114 @OUTPUT : 00115 @RETURNS : lines 00116 @DESCRIPTION: Returns a pointer to the lines of the object. 00117 @METHOD : 00118 @GLOBALS : 00119 @CALLS : 00120 @CREATED : 1993 David MacDonald 00121 @MODIFIED : 00122 ---------------------------------------------------------------------------- */ 00123 00124 public lines_struct *get_lines_ptr( 00125 object_struct *object ) 00126 { 00127 if( object->object_type != LINES ) 00128 { 00129 handle_internal_error( "get_lines_ptr" ); 00130 return( (lines_struct *) NULL ); 00131 } 00132 else 00133 return( &object->specific.lines ); 00134 } 00135 00136 /* ----------------------------- MNI Header ----------------------------------- 00137 @NAME : get_marker_ptr 00138 @INPUT : object 00139 @OUTPUT : 00140 @RETURNS : marker 00141 @DESCRIPTION: Returns a pointer to the marker of the object. 00142 @METHOD : 00143 @GLOBALS : 00144 @CALLS : 00145 @CREATED : 1993 David MacDonald 00146 @MODIFIED : 00147 ---------------------------------------------------------------------------- */ 00148 00149 public marker_struct *get_marker_ptr( 00150 object_struct *object ) 00151 { 00152 if( object->object_type != MARKER ) 00153 { 00154 handle_internal_error( "get_marker_ptr" ); 00155 return( (marker_struct *) NULL ); 00156 } 00157 else 00158 return( &object->specific.marker ); 00159 } 00160 00161 /* ----------------------------- MNI Header ----------------------------------- 00162 @NAME : get_model_ptr 00163 @INPUT : object 00164 @OUTPUT : 00165 @RETURNS : model 00166 @DESCRIPTION: Returns a pointer to the model of the object. 00167 @METHOD : 00168 @GLOBALS : 00169 @CALLS : 00170 @CREATED : 1993 David MacDonald 00171 @MODIFIED : 00172 ---------------------------------------------------------------------------- */ 00173 00174 public model_struct *get_model_ptr( 00175 object_struct *object ) 00176 { 00177 if( object->object_type != MODEL ) 00178 { 00179 handle_internal_error( "get_model_ptr" ); 00180 return( (model_struct *) NULL ); 00181 } 00182 else 00183 return( &object->specific.model ); 00184 } 00185 00186 /* ----------------------------- MNI Header ----------------------------------- 00187 @NAME : get_pixels_ptr 00188 @INPUT : object 00189 @OUTPUT : 00190 @RETURNS : pixels 00191 @DESCRIPTION: Returns a pointer to the pixels of the object. 00192 @METHOD : 00193 @GLOBALS : 00194 @CALLS : 00195 @CREATED : 1993 David MacDonald 00196 @MODIFIED : 00197 ---------------------------------------------------------------------------- */ 00198 00199 public pixels_struct *get_pixels_ptr( 00200 object_struct *object ) 00201 { 00202 if( object->object_type != PIXELS ) 00203 { 00204 handle_internal_error( "get_pixels_ptr" ); 00205 return( (pixels_struct *) NULL ); 00206 } 00207 else 00208 return( &object->specific.pixels ); 00209 } 00210 00211 /* ----------------------------- MNI Header ----------------------------------- 00212 @NAME : get_polygons_ptr 00213 @INPUT : object 00214 @OUTPUT : 00215 @RETURNS : polygons 00216 @DESCRIPTION: Returns a pointer to the polygons of the object. 00217 @METHOD : 00218 @GLOBALS : 00219 @CALLS : 00220 @CREATED : 1993 David MacDonald 00221 @MODIFIED : 00222 ---------------------------------------------------------------------------- */ 00223 00224 public polygons_struct *get_polygons_ptr( 00225 object_struct *object ) 00226 { 00227 if( object->object_type != POLYGONS ) 00228 { 00229 handle_internal_error( "get_polygons_ptr" ); 00230 return( (polygons_struct *) NULL ); 00231 } 00232 else 00233 return( &object->specific.polygons ); 00234 } 00235 00236 /* ----------------------------- MNI Header ----------------------------------- 00237 @NAME : get_quadmesh_ptr 00238 @INPUT : object 00239 @OUTPUT : 00240 @RETURNS : quadmesh 00241 @DESCRIPTION: Returns a pointer to the quadmesh of the object. 00242 @METHOD : 00243 @GLOBALS : 00244 @CALLS : 00245 @CREATED : 1993 David MacDonald 00246 @MODIFIED : 00247 ---------------------------------------------------------------------------- */ 00248 00249 public quadmesh_struct *get_quadmesh_ptr( 00250 object_struct *object ) 00251 { 00252 if( object->object_type != QUADMESH ) 00253 { 00254 handle_internal_error( "get_quadmesh_ptr" ); 00255 return( (quadmesh_struct *) NULL ); 00256 } 00257 else 00258 return( &object->specific.quadmesh ); 00259 } 00260 00261 /* ----------------------------- MNI Header ----------------------------------- 00262 @NAME : get_text_ptr 00263 @INPUT : object 00264 @OUTPUT : 00265 @RETURNS : text 00266 @DESCRIPTION: Returns a pointer to the text of the object. 00267 @METHOD : 00268 @GLOBALS : 00269 @CALLS : 00270 @CREATED : 1993 David MacDonald 00271 @MODIFIED : 00272 ---------------------------------------------------------------------------- */ 00273 00274 public text_struct *get_text_ptr( 00275 object_struct *object ) 00276 { 00277 if( object->object_type != TEXT ) 00278 { 00279 handle_internal_error( "get_text_ptr" ); 00280 return( (text_struct *) NULL ); 00281 } 00282 else 00283 return( &object->specific.text ); 00284 } 00285 00286 /* ----------------------------- MNI Header ----------------------------------- 00287 @NAME : get_lines_points 00288 @INPUT : object 00289 @OUTPUT : points 00290 @RETURNS : number of points 00291 @DESCRIPTION: Passes back the points of the object and returns the number 00292 of points. 00293 @METHOD : 00294 @GLOBALS : 00295 @CALLS : 00296 @CREATED : 1993 David MacDonald 00297 @MODIFIED : 00298 ---------------------------------------------------------------------------- */ 00299 00300 private int get_lines_points( 00301 object_struct *object, 00302 Point *points[] ) 00303 { 00304 *points = get_lines_ptr(object)->points; 00305 00306 return( get_lines_ptr(object)->n_points ); 00307 } 00308 00309 /* ----------------------------- MNI Header ----------------------------------- 00310 @NAME : get_marker_points 00311 @INPUT : object 00312 @OUTPUT : points 00313 @RETURNS : number of points 00314 @DESCRIPTION: Passes back the points of the object and returns the number 00315 of points. 00316 @METHOD : 00317 @GLOBALS : 00318 @CALLS : 00319 @CREATED : 1993 David MacDonald 00320 @MODIFIED : 00321 ---------------------------------------------------------------------------- */ 00322 00323 private int get_marker_points( 00324 object_struct *object, 00325 Point *points[] ) 00326 { 00327 *points = &get_marker_ptr(object)->position; 00328 00329 return( 1 ); 00330 } 00331 00332 /* ----------------------------- MNI Header ----------------------------------- 00333 @NAME : get_object_zero_points 00334 @INPUT : object 00335 @OUTPUT : points 00336 @RETURNS : number of points 00337 @DESCRIPTION: Passes back the points of objects with no points and returns 00338 the number of points (0). 00339 @METHOD : 00340 @GLOBALS : 00341 @CALLS : 00342 @CREATED : 1993 David MacDonald 00343 @MODIFIED : 00344 ---------------------------------------------------------------------------- */ 00345 00346 /* ARGSUSED */ 00347 00348 private int get_object_zero_points( 00349 object_struct *object, 00350 Point *points[] ) 00351 { 00352 return( 0 ); 00353 } 00354 00355 /* ----------------------------- MNI Header ----------------------------------- 00356 @NAME : get_polygons_points 00357 @INPUT : object 00358 @OUTPUT : points 00359 @RETURNS : number of points 00360 @DESCRIPTION: Passes back the points of the object and returns the number 00361 of points. 00362 @METHOD : 00363 @GLOBALS : 00364 @CALLS : 00365 @CREATED : 1993 David MacDonald 00366 @MODIFIED : 00367 ---------------------------------------------------------------------------- */ 00368 00369 private int get_polygons_points( 00370 object_struct *object, 00371 Point *points[] ) 00372 { 00373 *points = get_polygons_ptr(object)->points; 00374 00375 return( get_polygons_ptr(object)->n_points ); 00376 } 00377 00378 /* ----------------------------- MNI Header ----------------------------------- 00379 @NAME : get_quadmesh_points 00380 @INPUT : object 00381 @OUTPUT : points 00382 @RETURNS : number of points 00383 @DESCRIPTION: Passes back the points of the object and returns the number 00384 of points. 00385 @METHOD : 00386 @GLOBALS : 00387 @CALLS : 00388 @CREATED : 1993 David MacDonald 00389 @MODIFIED : 00390 ---------------------------------------------------------------------------- */ 00391 00392 private int get_quadmesh_points( 00393 object_struct *object, 00394 Point *points[] ) 00395 { 00396 *points = get_quadmesh_ptr(object)->points; 00397 00398 return( get_quadmesh_ptr(object)->m * get_quadmesh_ptr(object)->n ); 00399 } 00400 00401 /* ----------------------------- MNI Header ----------------------------------- 00402 @NAME : get_text_points 00403 @INPUT : object 00404 @OUTPUT : points 00405 @RETURNS : number of points 00406 @DESCRIPTION: Passes back the points of the object and returns the number 00407 of points. 00408 @METHOD : 00409 @GLOBALS : 00410 @CALLS : 00411 @CREATED : 1993 David MacDonald 00412 @MODIFIED : 00413 ---------------------------------------------------------------------------- */ 00414 00415 private int get_text_points( 00416 object_struct *object, 00417 Point *points[] ) 00418 { 00419 *points = &get_text_ptr(object)->origin; 00420 00421 return( 1 ); 00422 } 00423 00424 /* ----------------------------- MNI Header ----------------------------------- 00425 @NAME : get_object_zero_normals 00426 @INPUT : object 00427 @OUTPUT : normals 00428 @RETURNS : number of normals 00429 @DESCRIPTION: Passes back the normals of the object and returns the number 00430 of normals. 00431 @METHOD : 00432 @GLOBALS : 00433 @CALLS : 00434 @CREATED : 1993 David MacDonald 00435 @MODIFIED : 00436 ---------------------------------------------------------------------------- */ 00437 00438 /* ARGSUSED */ 00439 00440 private int get_object_zero_normals( 00441 object_struct *object, 00442 Vector *normals[] ) 00443 { 00444 *normals = NULL; 00445 return( 0 ); 00446 } 00447 00448 /* ----------------------------- MNI Header ----------------------------------- 00449 @NAME : get_polygons_normals 00450 @INPUT : object 00451 @OUTPUT : normals 00452 @RETURNS : number of normals 00453 @DESCRIPTION: Passes back the normals of the object and returns the number 00454 of normals. 00455 @METHOD : 00456 @GLOBALS : 00457 @CALLS : 00458 @CREATED : 1993 David MacDonald 00459 @MODIFIED : 00460 ---------------------------------------------------------------------------- */ 00461 00462 private int get_polygons_normals( 00463 object_struct *object, 00464 Vector *normals[] ) 00465 { 00466 *normals = get_polygons_ptr(object)->normals; 00467 00468 return( get_polygons_ptr(object)->n_points ); 00469 } 00470 00471 /* ----------------------------- MNI Header ----------------------------------- 00472 @NAME : get_quadmesh_normals 00473 @INPUT : object 00474 @OUTPUT : normals 00475 @RETURNS : number of normals 00476 @DESCRIPTION: Passes back the normals of the object and returns the number 00477 of normals. 00478 @METHOD : 00479 @GLOBALS : 00480 @CALLS : 00481 @CREATED : 1993 David MacDonald 00482 @MODIFIED : 00483 ---------------------------------------------------------------------------- */ 00484 00485 private int get_quadmesh_normals( 00486 object_struct *object, 00487 Vector *normals[] ) 00488 { 00489 *normals = get_quadmesh_ptr(object)->normals; 00490 00491 return( get_quadmesh_ptr(object)->m * get_quadmesh_ptr(object)->n ); 00492 } 00493 00494 /* ----------------------------- MNI Header ----------------------------------- 00495 @NAME : get_lines_colours 00496 @INPUT : object 00497 @OUTPUT : colours 00498 @RETURNS : colour flag 00499 @DESCRIPTION: Passes back the colours of the object and returns the colour 00500 flag. 00501 @METHOD : 00502 @GLOBALS : 00503 @CALLS : 00504 @CREATED : 1993 David MacDonald 00505 @MODIFIED : 00506 ---------------------------------------------------------------------------- */ 00507 00508 private Colour_flags *get_lines_colours( 00509 object_struct *object, 00510 Colour *colours[] ) 00511 { 00512 *colours = get_lines_ptr(object)->colours; 00513 00514 return( &get_lines_ptr(object)->colour_flag ); 00515 } 00516 00517 /* ----------------------------- MNI Header ----------------------------------- 00518 @NAME : get_marker_colours 00519 @INPUT : object 00520 @OUTPUT : colours 00521 @RETURNS : colour flag 00522 @DESCRIPTION: Passes back the colours of the object and returns the colour 00523 flag. 00524 @METHOD : 00525 @GLOBALS : 00526 @CALLS : 00527 @CREATED : 1993 David MacDonald 00528 @MODIFIED : 00529 ---------------------------------------------------------------------------- */ 00530 00531 private Colour_flags *get_marker_colours( 00532 object_struct *object, 00533 Colour *colours[] ) 00534 { 00535 *colours = &get_marker_ptr(object)->colour; 00536 00537 return( (Colour_flags *) 0 ); 00538 } 00539 00540 /* ----------------------------- MNI Header ----------------------------------- 00541 @NAME : get_object_zero_colours 00542 @INPUT : object 00543 @OUTPUT : colours 00544 @RETURNS : colour flag 00545 @DESCRIPTION: Passes back the colours of the object and returns the colour 00546 flag. 00547 @METHOD : 00548 @GLOBALS : 00549 @CALLS : 00550 @CREATED : 1993 David MacDonald 00551 @MODIFIED : 00552 ---------------------------------------------------------------------------- */ 00553 00554 /* ARGSUSED */ 00555 00556 private Colour_flags *get_object_zero_colours( 00557 object_struct *object, 00558 Colour *colours[] ) 00559 { 00560 *colours = (Colour *) NULL; 00561 00562 return( (Colour_flags *) 0 ); 00563 } 00564 00565 /* ----------------------------- MNI Header ----------------------------------- 00566 @NAME : get_polygons_colours 00567 @INPUT : object 00568 @OUTPUT : colours 00569 @RETURNS : colour flag 00570 @DESCRIPTION: Passes back the colours of the object and returns the colour 00571 flag. 00572 @METHOD : 00573 @GLOBALS : 00574 @CALLS : 00575 @CREATED : 1993 David MacDonald 00576 @MODIFIED : 00577 ---------------------------------------------------------------------------- */ 00578 00579 private Colour_flags *get_polygons_colours( 00580 object_struct *object, 00581 Colour *colours[] ) 00582 { 00583 *colours = get_polygons_ptr(object)->colours; 00584 00585 return( &get_polygons_ptr(object)->colour_flag ); 00586 } 00587 00588 /* ----------------------------- MNI Header ----------------------------------- 00589 @NAME : get_quadmesh_colours 00590 @INPUT : object 00591 @OUTPUT : colours 00592 @RETURNS : colour flag 00593 @DESCRIPTION: Passes back the colours of the object and returns the colour 00594 flag. 00595 @METHOD : 00596 @GLOBALS : 00597 @CALLS : 00598 @CREATED : 1993 David MacDonald 00599 @MODIFIED : 00600 ---------------------------------------------------------------------------- */ 00601 00602 private Colour_flags *get_quadmesh_colours( 00603 object_struct *object, 00604 Colour *colours[] ) 00605 { 00606 *colours = get_quadmesh_ptr(object)->colours; 00607 00608 return( &get_quadmesh_ptr(object)->colour_flag ); 00609 } 00610 00611 /* ----------------------------- MNI Header ----------------------------------- 00612 @NAME : get_text_colours 00613 @INPUT : object 00614 @OUTPUT : colours 00615 @RETURNS : colour flag 00616 @DESCRIPTION: Passes back the colours of the object and returns the colour 00617 flag. 00618 @METHOD : 00619 @GLOBALS : 00620 @CALLS : 00621 @CREATED : 1993 David MacDonald 00622 @MODIFIED : 00623 ---------------------------------------------------------------------------- */ 00624 00625 private Colour_flags *get_text_colours( 00626 object_struct *object, 00627 Colour *colours[] ) 00628 { 00629 *colours = &get_text_ptr(object)->colour; 00630 00631 return( (Colour_flags *) 0 ); 00632 } 00633 00634 /* ----------------------------- MNI Header ----------------------------------- 00635 @NAME : set_lines_colours 00636 @INPUT : object 00637 colours 00638 @OUTPUT : 00639 @RETURNS : 00640 @DESCRIPTION: Assigns the colours array of the object. 00641 @METHOD : 00642 @GLOBALS : 00643 @CALLS : 00644 @CREATED : 1993 David MacDonald 00645 @MODIFIED : 00646 ---------------------------------------------------------------------------- */ 00647 00648 private void set_lines_colours( 00649 object_struct *object, 00650 Colour colours[] ) 00651 { 00652 get_lines_ptr(object)->colours = colours; 00653 } 00654 00655 /* ----------------------------- MNI Header ----------------------------------- 00656 @NAME : set_object_no_colours 00657 @INPUT : object 00658 colours 00659 @OUTPUT : 00660 @RETURNS : 00661 @DESCRIPTION: Assigns the colours array of the object, for objects which 00662 have no colours. 00663 @METHOD : 00664 @GLOBALS : 00665 @CALLS : 00666 @CREATED : 1993 David MacDonald 00667 @MODIFIED : 00668 ---------------------------------------------------------------------------- */ 00669 00670 /* ARGSUSED */ 00671 00672 private void set_object_no_colours( 00673 object_struct *object, 00674 Colour colours[] ) 00675 { 00676 } 00677 00678 /* ----------------------------- MNI Header ----------------------------------- 00679 @NAME : set_polygons_colours 00680 @INPUT : object 00681 colours 00682 @OUTPUT : 00683 @RETURNS : 00684 @DESCRIPTION: Assigns the colours array of the object. 00685 @METHOD : 00686 @GLOBALS : 00687 @CALLS : 00688 @CREATED : 1993 David MacDonald 00689 @MODIFIED : 00690 ---------------------------------------------------------------------------- */ 00691 00692 private void set_polygons_colours( 00693 object_struct *object, 00694 Colour colours[] ) 00695 { 00696 get_polygons_ptr(object)->colours = colours; 00697 } 00698 00699 /* ----------------------------- MNI Header ----------------------------------- 00700 @NAME : set_quadmesh_colours 00701 @INPUT : object 00702 colours 00703 @OUTPUT : 00704 @RETURNS : 00705 @DESCRIPTION: Assigns the colours array of the object. 00706 @METHOD : 00707 @GLOBALS : 00708 @CALLS : 00709 @CREATED : 1993 David MacDonald 00710 @MODIFIED : 00711 ---------------------------------------------------------------------------- */ 00712 00713 private void set_quadmesh_colours( 00714 object_struct *object, 00715 Colour colours[] ) 00716 { 00717 get_quadmesh_ptr(object)->colours = colours; 00718 } 00719 00720 /* ----------------------------- MNI Header ----------------------------------- 00721 @NAME : get_object_no_surfprop 00722 @INPUT : object 00723 @OUTPUT : 00724 @RETURNS : pointer to surfprop 00725 @DESCRIPTION: Returns a null pointer for objects that do not have surfprops. 00726 @METHOD : 00727 @GLOBALS : 00728 @CALLS : 00729 @CREATED : 1993 David MacDonald 00730 @MODIFIED : 00731 ---------------------------------------------------------------------------- */ 00732 00733 /* ARGSUSED */ 00734 00735 private Surfprop *get_object_no_surfprop( 00736 object_struct *object ) 00737 { 00738 return( (Surfprop *) NULL ); 00739 } 00740 00741 /* ----------------------------- MNI Header ----------------------------------- 00742 @NAME : get_polygons_surfprop 00743 @INPUT : object 00744 @OUTPUT : 00745 @RETURNS : surfprop 00746 @DESCRIPTION: Returns a pointer to the object's surfprop. 00747 @METHOD : 00748 @GLOBALS : 00749 @CALLS : 00750 @CREATED : 1993 David MacDonald 00751 @MODIFIED : 00752 ---------------------------------------------------------------------------- */ 00753 00754 private Surfprop *get_polygons_surfprop( 00755 object_struct *object ) 00756 { 00757 return( &get_polygons_ptr(object)->surfprop ); 00758 } 00759 00760 /* ----------------------------- MNI Header ----------------------------------- 00761 @NAME : get_polygons_surfprop 00762 @INPUT : object 00763 @OUTPUT : 00764 @RETURNS : surfprop 00765 @DESCRIPTION: Returns a pointer to the object's surfprop. 00766 @METHOD : 00767 @GLOBALS : 00768 @CALLS : 00769 @CREATED : 1993 David MacDonald 00770 @MODIFIED : 00771 ---------------------------------------------------------------------------- */ 00772 00773 private Surfprop *get_quadmesh_surfprop( 00774 object_struct *object ) 00775 { 00776 return( &get_quadmesh_ptr(object)->surfprop ); 00777 } 00778 00779 /* ----------------------------- MNI Header ----------------------------------- 00780 @NAME : get_lines_name 00781 @INPUT : object 00782 @OUTPUT : name 00783 @RETURNS : 00784 @DESCRIPTION: Gets a name description for the object. 00785 @METHOD : 00786 @GLOBALS : 00787 @CALLS : 00788 @CREATED : 1993 David MacDonald 00789 @MODIFIED : 00790 ---------------------------------------------------------------------------- */ 00791 00792 private STRING get_lines_name( 00793 object_struct *object ) 00794 { 00795 char buffer[EXTREMELY_LARGE_STRING_SIZE]; 00796 00797 (void) sprintf( buffer, "Lines (%d:%d)", 00798 get_lines_ptr(object)->n_items, 00799 get_lines_ptr(object)->n_points ); 00800 00801 return( create_string( buffer ) ); 00802 } 00803 00804 /* ----------------------------- MNI Header ----------------------------------- 00805 @NAME : get_marker_name 00806 @INPUT : object 00807 @OUTPUT : name 00808 @RETURNS : 00809 @DESCRIPTION: Gets a name description for the object. 00810 @METHOD : 00811 @GLOBALS : 00812 @CALLS : 00813 @CREATED : 1993 David MacDonald 00814 @MODIFIED : 00815 ---------------------------------------------------------------------------- */ 00816 00817 private STRING get_marker_name( 00818 object_struct *object ) 00819 { 00820 STRING label; 00821 char buffer[EXTREMELY_LARGE_STRING_SIZE]; 00822 00823 if( string_length(get_marker_ptr(object)->label) == 0 ) 00824 label = "Marker"; 00825 else 00826 label = get_marker_ptr(object)->label; 00827 00828 (void) sprintf( buffer, "%s:%d:%d: (%g %g %g)", 00829 label, 00830 get_marker_ptr(object)->patient_id, 00831 get_marker_ptr(object)->structure_id, 00832 Point_x(get_marker_ptr(object)->position), 00833 Point_y(get_marker_ptr(object)->position), 00834 Point_z(get_marker_ptr(object)->position) ); 00835 00836 return( create_string( buffer ) ); 00837 } 00838 00839 /* ----------------------------- MNI Header ----------------------------------- 00840 @NAME : get_model_name 00841 @INPUT : object 00842 @OUTPUT : name 00843 @RETURNS : 00844 @DESCRIPTION: Gets a name description for the object. 00845 @METHOD : 00846 @GLOBALS : 00847 @CALLS : 00848 @CREATED : 1993 David MacDonald 00849 @MODIFIED : 00850 ---------------------------------------------------------------------------- */ 00851 00852 private STRING get_model_name( 00853 object_struct *object ) 00854 { 00855 char buffer[EXTREMELY_LARGE_STRING_SIZE]; 00856 00857 (void) sprintf( buffer, "Model (%s) ->", get_model_ptr(object)->filename ); 00858 00859 return( create_string( buffer ) ); 00860 } 00861 00862 /* ----------------------------- MNI Header ----------------------------------- 00863 @NAME : get_pixels_name 00864 @INPUT : object 00865 @OUTPUT : name 00866 @RETURNS : 00867 @DESCRIPTION: Gets a name description for the object. 00868 @METHOD : 00869 @GLOBALS : 00870 @CALLS : 00871 @CREATED : 1993 David MacDonald 00872 @MODIFIED : 00873 ---------------------------------------------------------------------------- */ 00874 00875 private STRING get_pixels_name( 00876 object_struct *object ) 00877 { 00878 char buffer[EXTREMELY_LARGE_STRING_SIZE]; 00879 00880 (void) sprintf( buffer, "Pixels (%d by %d)", 00881 get_pixels_ptr(object)->x_size, 00882 get_pixels_ptr(object)->y_size ); 00883 00884 return( create_string( buffer ) ); 00885 } 00886 00887 /* ----------------------------- MNI Header ----------------------------------- 00888 @NAME : get_polygons_name 00889 @INPUT : object 00890 @OUTPUT : name 00891 @RETURNS : 00892 @DESCRIPTION: Gets a name description for the object. 00893 @METHOD : 00894 @GLOBALS : 00895 @CALLS : 00896 @CREATED : 1993 David MacDonald 00897 @MODIFIED : 00898 ---------------------------------------------------------------------------- */ 00899 00900 private STRING get_polygons_name( 00901 object_struct *object ) 00902 { 00903 char buffer[EXTREMELY_LARGE_STRING_SIZE]; 00904 00905 (void) sprintf( buffer, "Polygons (%d:%d)", 00906 get_polygons_ptr(object)->n_items, 00907 get_polygons_ptr(object)->n_points ); 00908 00909 return( create_string( buffer ) ); 00910 } 00911 00912 /* ----------------------------- MNI Header ----------------------------------- 00913 @NAME : get_quadmesh_name 00914 @INPUT : object 00915 @OUTPUT : name 00916 @RETURNS : 00917 @DESCRIPTION: Gets a name description for the object. 00918 @METHOD : 00919 @GLOBALS : 00920 @CALLS : 00921 @CREATED : 1993 David MacDonald 00922 @MODIFIED : 00923 ---------------------------------------------------------------------------- */ 00924 00925 private STRING get_quadmesh_name( 00926 object_struct *object ) 00927 { 00928 char buffer[EXTREMELY_LARGE_STRING_SIZE]; 00929 00930 (void) sprintf( buffer, "Quadmesh [%d][%d]", 00931 get_quadmesh_ptr(object)->m, get_quadmesh_ptr(object)->n ); 00932 00933 return( create_string( buffer ) ); 00934 } 00935 00936 /* ----------------------------- MNI Header ----------------------------------- 00937 @NAME : get_text_name 00938 @INPUT : object 00939 @OUTPUT : name 00940 @RETURNS : 00941 @DESCRIPTION: Gets a name description for the object. 00942 @METHOD : 00943 @GLOBALS : 00944 @CALLS : 00945 @CREATED : 1993 David MacDonald 00946 @MODIFIED : 00947 ---------------------------------------------------------------------------- */ 00948 00949 private STRING get_text_name( 00950 object_struct *object ) 00951 { 00952 char buffer[EXTREMELY_LARGE_STRING_SIZE]; 00953 00954 (void) sprintf( buffer, "Text (%s)", get_text_ptr(object)->string ); 00955 00956 return( create_string( buffer ) ); 00957 } 00958 00959 /* ----------------------------- MNI Header ----------------------------------- 00960 @NAME : delete_lines_object 00961 @INPUT : object 00962 @OUTPUT : 00963 @RETURNS : 00964 @DESCRIPTION: Deletes the object. 00965 @METHOD : 00966 @GLOBALS : 00967 @CALLS : 00968 @CREATED : 1993 David MacDonald 00969 @MODIFIED : 00970 ---------------------------------------------------------------------------- */ 00971 00972 private void delete_lines_object( 00973 object_struct *object ) 00974 { 00975 delete_lines( get_lines_ptr(object) ); 00976 } 00977 00978 /* ----------------------------- MNI Header ----------------------------------- 00979 @NAME : delete_marker_object 00980 @INPUT : object 00981 @OUTPUT : 00982 @RETURNS : 00983 @DESCRIPTION: Deletes the object. 00984 @METHOD : 00985 @GLOBALS : 00986 @CALLS : 00987 @CREATED : 1993 David MacDonald 00988 @MODIFIED : 00989 ---------------------------------------------------------------------------- */ 00990 00991 /* ARGSUSED */ 00992 00993 private void delete_marker_object( 00994 object_struct *object ) 00995 { 00996 delete_marker( get_marker_ptr(object) ); 00997 } 00998 00999 /* ----------------------------- MNI Header ----------------------------------- 01000 @NAME : delete_model_object 01001 @INPUT : object 01002 @OUTPUT : 01003 @RETURNS : 01004 @DESCRIPTION: Deletes the object. 01005 @METHOD : 01006 @GLOBALS : 01007 @CALLS : 01008 @CREATED : 1993 David MacDonald 01009 @MODIFIED : 01010 ---------------------------------------------------------------------------- */ 01011 01012 private void delete_model_object( 01013 object_struct *object ) 01014 { 01015 delete_model( get_model_ptr(object) ); 01016 } 01017 01018 /* ----------------------------- MNI Header ----------------------------------- 01019 @NAME : delete_pixels_object 01020 @INPUT : object 01021 @OUTPUT : 01022 @RETURNS : 01023 @DESCRIPTION: Deletes the object. 01024 @METHOD : 01025 @GLOBALS : 01026 @CALLS : 01027 @CREATED : 1993 David MacDonald 01028 @MODIFIED : 01029 ---------------------------------------------------------------------------- */ 01030 01031 private void delete_pixels_object( 01032 object_struct *object ) 01033 { 01034 delete_pixels( get_pixels_ptr(object) ); 01035 } 01036 01037 /* ----------------------------- MNI Header ----------------------------------- 01038 @NAME : delete_polygons_object 01039 @INPUT : object 01040 @OUTPUT : 01041 @RETURNS : 01042 @DESCRIPTION: Deletes the object. 01043 @METHOD : 01044 @GLOBALS : 01045 @CALLS : 01046 @CREATED : 1993 David MacDonald 01047 @MODIFIED : 01048 ---------------------------------------------------------------------------- */ 01049 01050 private void delete_polygons_object( 01051 object_struct *object ) 01052 { 01053 delete_polygons( get_polygons_ptr(object) ); 01054 } 01055 01056 /* ----------------------------- MNI Header ----------------------------------- 01057 @NAME : delete_quadmesh_object 01058 @INPUT : object 01059 @OUTPUT : 01060 @RETURNS : 01061 @DESCRIPTION: Deletes the object. 01062 @METHOD : 01063 @GLOBALS : 01064 @CALLS : 01065 @CREATED : 1993 David MacDonald 01066 @MODIFIED : 01067 ---------------------------------------------------------------------------- */ 01068 01069 /* ARGSUSED */ 01070 01071 private void delete_quadmesh_object( 01072 object_struct *object ) 01073 { 01074 delete_quadmesh( get_quadmesh_ptr(object) ); 01075 } 01076 01077 /* ----------------------------- MNI Header ----------------------------------- 01078 @NAME : delete_text_object 01079 @INPUT : object 01080 @OUTPUT : 01081 @RETURNS : 01082 @DESCRIPTION: Deletes the object. 01083 @METHOD : 01084 @GLOBALS : 01085 @CALLS : 01086 @CREATED : 1993 David MacDonald 01087 @MODIFIED : 01088 ---------------------------------------------------------------------------- */ 01089 01090 /* ARGSUSED */ 01091 01092 private void delete_text_object( 01093 object_struct *object ) 01094 { 01095 delete_text( get_text_ptr(object) ); 01096 } 01097 01098 /* -------------------- function lookup table ------------------- */ 01099 01100 typedef struct 01101 { 01102 int (*get_points_function)( object_struct *, Point *[] ); 01103 int (*get_normals_function)( object_struct *, Vector *[] ); 01104 Colour_flags *(*get_colours_function)( object_struct *, Colour *[] ); 01105 void (*set_colours_function)( object_struct *, Colour [] ); 01106 Surfprop *(*get_surfprop_function)( object_struct * ); 01107 STRING (*get_name_function)( object_struct * ); 01108 void (*delete_function)( object_struct * ); 01109 } 01110 object_functions_list; 01111 01112 static object_functions_list object_functions[N_OBJECT_TYPES] = 01113 { 01114 { 01115 get_lines_points, 01116 get_object_zero_normals, 01117 get_lines_colours, 01118 set_lines_colours, 01119 get_object_no_surfprop, 01120 get_lines_name, 01121 delete_lines_object 01122 }, /* LINES */ 01123 { 01124 get_marker_points, 01125 get_object_zero_normals, 01126 get_marker_colours, 01127 set_object_no_colours, 01128 get_object_no_surfprop, 01129 get_marker_name, 01130 delete_marker_object 01131 }, /* MARKER */ 01132 { 01133 get_object_zero_points, 01134 get_object_zero_normals, 01135 get_object_zero_colours, 01136 set_object_no_colours, 01137 get_object_no_surfprop, 01138 get_model_name, 01139 delete_model_object 01140 }, /* MODEL */ 01141 { 01142 get_object_zero_points, 01143 get_object_zero_normals, 01144 get_object_zero_colours, 01145 set_object_no_colours, 01146 get_object_no_surfprop, 01147 get_pixels_name, 01148 delete_pixels_object 01149 }, /* PIXELS */ 01150 { 01151 get_polygons_points, 01152 get_polygons_normals, 01153 get_polygons_colours, 01154 set_polygons_colours, 01155 get_polygons_surfprop, 01156 get_polygons_name, 01157 delete_polygons_object 01158 }, /* POLYGONS */ 01159 { 01160 get_quadmesh_points, 01161 get_quadmesh_normals, 01162 get_quadmesh_colours, 01163 set_quadmesh_colours, 01164 get_quadmesh_surfprop, 01165 get_quadmesh_name, 01166 delete_quadmesh_object 01167 }, /* QUADMESH */ 01168 { 01169 get_text_points, 01170 get_object_zero_normals, 01171 get_text_colours, 01172 set_object_no_colours, 01173 get_object_no_surfprop, 01174 get_text_name, 01175 delete_text_object 01176 } /* TEXT */ 01177 }; 01178 01179 /* ----------------------------- MNI Header ----------------------------------- 01180 @NAME : delete_object 01181 @INPUT : object 01182 @OUTPUT : 01183 @RETURNS : 01184 @DESCRIPTION: Deletes the object. 01185 @METHOD : 01186 @GLOBALS : 01187 @CALLS : 01188 @CREATED : 1993 David MacDonald 01189 @MODIFIED : 01190 ---------------------------------------------------------------------------- */ 01191 01192 public void delete_object( 01193 object_struct *object ) 01194 { 01195 object_functions[object->object_type].delete_function( object ); 01196 FREE( object ); 01197 } 01198 01199 /* ----------------------------- MNI Header ----------------------------------- 01200 @NAME : get_object_points 01201 @INPUT : object 01202 @OUTPUT : points 01203 @RETURNS : n_points 01204 @DESCRIPTION: Passes back a pointer to the points of the object. 01205 @METHOD : 01206 @GLOBALS : 01207 @CALLS : 01208 @CREATED : 1993 David MacDonald 01209 @MODIFIED : 01210 ---------------------------------------------------------------------------- */ 01211 01212 public int get_object_points( 01213 object_struct *object, 01214 Point *points[] ) 01215 { 01216 return( object_functions[object->object_type].get_points_function 01217 ( object, points ) ); 01218 } 01219 01220 /* ----------------------------- MNI Header ----------------------------------- 01221 @NAME : get_object_normals 01222 @INPUT : object 01223 @OUTPUT : normals 01224 @RETURNS : n_normals 01225 @DESCRIPTION: Passes back a pointer to the normals of the object. 01226 @METHOD : 01227 @GLOBALS : 01228 @CALLS : 01229 @CREATED : 1993 David MacDonald 01230 @MODIFIED : 01231 ---------------------------------------------------------------------------- */ 01232 01233 public int get_object_normals( 01234 object_struct *object, 01235 Vector *normals[] ) 01236 { 01237 return( object_functions[object->object_type].get_normals_function 01238 ( object, normals ) ); 01239 } 01240 01241 /* ----------------------------- MNI Header ----------------------------------- 01242 @NAME : get_object_colours 01243 @INPUT : object 01244 @OUTPUT : colours 01245 @RETURNS : colour_flag 01246 @DESCRIPTION: Passes back a pointer to the colours array. 01247 @METHOD : 01248 @GLOBALS : 01249 @CALLS : 01250 @CREATED : 1993 David MacDonald 01251 @MODIFIED : 01252 ---------------------------------------------------------------------------- */ 01253 01254 public Colour_flags *get_object_colours( 01255 object_struct *object, 01256 Colour *colours[] ) 01257 { 01258 return( object_functions[object->object_type].get_colours_function 01259 ( object, colours ) ); 01260 } 01261 01262 /* ----------------------------- MNI Header ----------------------------------- 01263 @NAME : set_object_colours 01264 @INPUT : object 01265 colours 01266 @OUTPUT : 01267 @RETURNS : 01268 @DESCRIPTION: Sets the colours array of the object. 01269 @METHOD : 01270 @GLOBALS : 01271 @CALLS : 01272 @CREATED : 1993 David MacDonald 01273 @MODIFIED : 01274 ---------------------------------------------------------------------------- */ 01275 01276 public void set_object_colours( 01277 object_struct *object, 01278 Colour colours[] ) 01279 { 01280 object_functions[object->object_type].set_colours_function(object,colours); 01281 } 01282 01283 /* ----------------------------- MNI Header ----------------------------------- 01284 @NAME : get_object_surfprop 01285 @INPUT : object 01286 @OUTPUT : 01287 @RETURNS : surfprop 01288 @DESCRIPTION: Returns a pointer to the surfprop of the object. 01289 @METHOD : 01290 @GLOBALS : 01291 @CALLS : 01292 @CREATED : 1993 David MacDonald 01293 @MODIFIED : 01294 ---------------------------------------------------------------------------- */ 01295 01296 public Surfprop *get_object_surfprop( 01297 object_struct *object ) 01298 { 01299 return( object_functions[object->object_type].get_surfprop_function 01300 ( object ) ); 01301 } 01302 01303 /* ----------------------------- MNI Header ----------------------------------- 01304 @NAME : get_object_name 01305 @INPUT : object 01306 @OUTPUT : name 01307 @RETURNS : 01308 @DESCRIPTION: Gets the name description of the object. 01309 @METHOD : 01310 @GLOBALS : 01311 @CALLS : 01312 @CREATED : 1993 David MacDonald 01313 @MODIFIED : 01314 ---------------------------------------------------------------------------- */ 01315 01316 public STRING get_object_name( 01317 object_struct *object ) 01318 { 01319 return( object_functions[object->object_type].get_name_function( object ) ); 01320 } 01321 01322 private void pop_object_stack( 01323 object_traverse_struct *object_traverse ) 01324 { 01325 if( object_traverse->top_of_stack > 0 ) 01326 --object_traverse->top_of_stack; 01327 else 01328 handle_internal_error( "pop_object_stack" ); 01329 } 01330 01331 private void push_object_stack( 01332 object_traverse_struct *object_traverse, 01333 object_stack_struct *entry ) 01334 { 01335 if( object_traverse->top_of_stack+1 >= object_traverse->n_stack_alloced ) 01336 { 01337 SET_ARRAY_SIZE( object_traverse->alloced_stack, 01338 object_traverse->top_of_stack, 01339 object_traverse->top_of_stack+1, 01340 DEFAULT_CHUNK_SIZE ); 01341 01342 object_traverse->stack = object_traverse->alloced_stack; 01343 } 01344 01345 object_traverse->stack[object_traverse->top_of_stack] = *entry; 01346 ++object_traverse->top_of_stack; 01347 } 01348 01349 /* ----------------------------- MNI Header ----------------------------------- 01350 @NAME : initialize_object_traverse 01351 @INPUT : object_traverse 01352 n_objects 01353 object_list 01354 @OUTPUT : 01355 @RETURNS : 01356 @DESCRIPTION: Initializes a structure for traversing an object, which could 01357 potentially have a hierarchy, if models are present. 01358 @METHOD : 01359 @GLOBALS : 01360 @CALLS : 01361 @CREATED : 1993 David MacDonald 01362 @MODIFIED : 01363 ---------------------------------------------------------------------------- */ 01364 01365 public void initialize_object_traverse( 01366 object_traverse_struct *object_traverse, 01367 BOOLEAN visible_ones_only, 01368 int n_objects, 01369 object_struct *object_list[] ) 01370 { 01371 object_stack_struct push_entry; 01372 01373 object_traverse->visible_ones_only = visible_ones_only; 01374 object_traverse->n_stack_alloced = MAX_OBJECT_TRAVERSE; 01375 object_traverse->top_of_stack = 0; 01376 object_traverse->stack = object_traverse->static_stack; 01377 01378 if( n_objects > 0 ) 01379 { 01380 push_entry.index = 0; 01381 push_entry.n_objects = n_objects; 01382 push_entry.object_list = object_list; 01383 01384 while( push_entry.index < n_objects && 01385 visible_ones_only && 01386 !get_object_visibility( object_list[push_entry.index] ) ) 01387 ++push_entry.index; 01388 01389 if( push_entry.index < n_objects ) 01390 push_object_stack( object_traverse, &push_entry ); 01391 } 01392 } 01393 01394 /* ----------------------------- MNI Header ----------------------------------- 01395 @NAME : get_next_object_traverse 01396 @INPUT : object_traverse 01397 @OUTPUT : object 01398 @RETURNS : TRUE if object found 01399 @DESCRIPTION: Gets the next object from the traversal. 01400 @METHOD : 01401 @GLOBALS : 01402 @CALLS : 01403 @CREATED : 1993 David MacDonald 01404 @MODIFIED : 01405 ---------------------------------------------------------------------------- */ 01406 01407 public BOOLEAN get_next_object_traverse( 01408 object_traverse_struct *object_traverse, 01409 object_struct **object ) 01410 { 01411 BOOLEAN object_found; 01412 object_stack_struct *top_entry; 01413 01414 if( object_traverse->top_of_stack > 0 ) 01415 { 01416 top_entry = &object_traverse->stack[object_traverse->top_of_stack-1]; 01417 *object = top_entry->object_list[top_entry->index]; 01418 01419 advance_object_traverse( object_traverse ); 01420 object_found = TRUE; 01421 } 01422 else 01423 { 01424 terminate_object_traverse( object_traverse ); 01425 object_found = FALSE; 01426 } 01427 01428 return( object_found ); 01429 } 01430 01431 /* ----------------------------- MNI Header ----------------------------------- 01432 @NAME : advance_object_traverse 01433 @INPUT : object_traverse 01434 @OUTPUT : 01435 @RETURNS : 01436 @DESCRIPTION: Advances the object_traverse struct to point to the next object. 01437 @METHOD : 01438 @GLOBALS : 01439 @CALLS : 01440 @CREATED : 1993 David MacDonald 01441 @MODIFIED : 01442 ---------------------------------------------------------------------------- */ 01443 01444 private void advance_object_traverse( 01445 object_traverse_struct *object_traverse ) 01446 { 01447 object_stack_struct *top_entry, push_entry; 01448 object_struct *object; 01449 model_struct *model; 01450 01451 top_entry = &object_traverse->stack[object_traverse->top_of_stack-1]; 01452 object = top_entry->object_list[top_entry->index]; 01453 ++top_entry->index; 01454 01455 while( top_entry->index < top_entry->n_objects && 01456 object_traverse->visible_ones_only && 01457 !get_object_visibility( top_entry->object_list[top_entry->index]) ) 01458 { 01459 ++top_entry->index; 01460 } 01461 01462 if( object->object_type == MODEL ) 01463 { 01464 model = get_model_ptr( object ); 01465 push_entry.index = 0; 01466 push_entry.n_objects = model->n_objects; 01467 push_entry.object_list = model->objects; 01468 01469 while( push_entry.index < push_entry.n_objects && 01470 object_traverse->visible_ones_only && 01471 !get_object_visibility(push_entry.object_list[push_entry.index])) 01472 ++push_entry.index; 01473 01474 if( push_entry.index < push_entry.n_objects ) 01475 push_object_stack( object_traverse, &push_entry ); 01476 } 01477 01478 while( object_traverse->top_of_stack > 0 && 01479 object_traverse->stack[object_traverse->top_of_stack-1].index >= 01480 object_traverse->stack[object_traverse->top_of_stack-1].n_objects ) 01481 { 01482 pop_object_stack( object_traverse ); 01483 } 01484 } 01485 01486 /* ----------------------------- MNI Header ----------------------------------- 01487 @NAME : terminate_object_traverse 01488 @INPUT : object_traverse 01489 @OUTPUT : 01490 @RETURNS : 01491 @DESCRIPTION: Deletes the object traversal structure. 01492 @METHOD : 01493 @GLOBALS : 01494 @CALLS : 01495 @CREATED : 1993 David MacDonald 01496 @MODIFIED : 01497 ---------------------------------------------------------------------------- */ 01498 01499 public void terminate_object_traverse( 01500 object_traverse_struct *object_traverse ) 01501 { 01502 if( object_traverse->n_stack_alloced > MAX_OBJECT_TRAVERSE ) 01503 FREE( object_traverse->alloced_stack ); 01504 } 01505 01506 /* ----------------------------- MNI Header ----------------------------------- 01507 @NAME : get_range_of_object 01508 @INPUT : object 01509 visible_ones_only 01510 @OUTPUT : min_corner 01511 max_corner 01512 @RETURNS : TRUE if range found. 01513 @DESCRIPTION: Returns the range of the object. 01514 @METHOD : 01515 @GLOBALS : 01516 @CALLS : 01517 @CREATED : 1993 David MacDonald 01518 @MODIFIED : 01519 ---------------------------------------------------------------------------- */ 01520 01521 public BOOLEAN get_range_of_object( 01522 object_struct *object, 01523 BOOLEAN visible_ones_only, 01524 Point *min_corner, 01525 Point *max_corner ) 01526 { 01527 BOOLEAN found_flag; 01528 Point min_obj, max_obj, *points; 01529 int n_points; 01530 object_struct *current_object; 01531 object_traverse_struct object_traverse; 01532 01533 found_flag = FALSE; 01534 01535 initialize_object_traverse( &object_traverse, visible_ones_only, 1,&object); 01536 01537 while( get_next_object_traverse( &object_traverse, &current_object ) ) 01538 { 01539 n_points = get_object_points( current_object, &points ); 01540 01541 if( n_points > 0 ) 01542 { 01543 get_range_points( n_points, points, &min_obj, &max_obj ); 01544 01545 if( !found_flag ) 01546 { 01547 found_flag = TRUE; 01548 *min_corner = min_obj; 01549 *max_corner = max_obj; 01550 } 01551 else 01552 { 01553 expand_min_and_max_points( min_corner, max_corner, 01554 &min_obj, &max_obj ); 01555 } 01556 } 01557 } 01558 01559 return( found_flag ); 01560 } 01561 01562 /* ----------------------------- MNI Header ----------------------------------- 01563 @NAME : reverse_object_normals 01564 @INPUT : object 01565 @OUTPUT : 01566 @RETURNS : 01567 @DESCRIPTION: Reverses the normals of the object. 01568 @METHOD : 01569 @GLOBALS : 01570 @CALLS : 01571 @CREATED : 1993 David MacDonald 01572 @MODIFIED : 01573 ---------------------------------------------------------------------------- */ 01574 01575 public void reverse_object_normals( 01576 object_struct *object ) 01577 { 01578 int n_normals; 01579 Vector *normals; 01580 object_struct *current_object; 01581 object_traverse_struct object_traverse; 01582 01583 initialize_object_traverse( &object_traverse, FALSE, 1, &object ); 01584 01585 while( get_next_object_traverse( &object_traverse, &current_object ) ) 01586 { 01587 n_normals = get_object_normals( current_object, &normals ); 01588 reverse_vectors( n_normals, normals ); 01589 } 01590 } 01591 01592 /* ----------------------------- MNI Header ----------------------------------- 01593 @NAME : get_object_colour 01594 @INPUT : object 01595 @OUTPUT : colour 01596 @RETURNS : TRUE if object has single colour 01597 @DESCRIPTION: Returns the global colour of the object, if any. 01598 @METHOD : 01599 @GLOBALS : 01600 @CALLS : 01601 @CREATED : 1993 David MacDonald 01602 @MODIFIED : 01603 ---------------------------------------------------------------------------- */ 01604 01605 public BOOLEAN get_object_colour( 01606 object_struct *object, 01607 Colour *colour ) 01608 { 01609 BOOLEAN has_single_colour; 01610 Colour_flags *colour_flag; 01611 Colour *colours; 01612 01613 colour_flag = get_object_colours( object, &colours ); 01614 01615 if( (colour_flag == (Colour_flags *) NULL || 01616 *colour_flag == ONE_COLOUR) && colours != (Colour *) NULL ) 01617 { 01618 has_single_colour = TRUE; 01619 *colour = colours[0]; 01620 } 01621 else 01622 { 01623 has_single_colour = FALSE; 01624 } 01625 01626 return( has_single_colour ); 01627 } 01628 01629 /* ----------------------------- MNI Header ----------------------------------- 01630 @NAME : set_object_colour 01631 @INPUT : object 01632 col 01633 @OUTPUT : 01634 @RETURNS : 01635 @DESCRIPTION: Sets the colour of the object. 01636 @METHOD : 01637 @GLOBALS : 01638 @CALLS : 01639 @CREATED : 1993 David MacDonald 01640 @MODIFIED : 01641 ---------------------------------------------------------------------------- */ 01642 01643 public void set_object_colour( 01644 object_struct *object, 01645 Colour col ) 01646 { 01647 Colour_flags *colour_flag; 01648 Colour *colours; 01649 01650 colour_flag = get_object_colours( object, &colours ); 01651 01652 if( colour_flag != (Colour_flags *) NULL && *colour_flag != ONE_COLOUR ) 01653 { 01654 *colour_flag = ONE_COLOUR; 01655 01656 if( colours != (Colour *) NULL ) 01657 FREE( colours ); 01658 01659 ALLOC( colours, 1 ); 01660 set_object_colours( object, colours ); 01661 } 01662 01663 if( colours != (Colour *) NULL ) 01664 colours[0] = col; 01665 } 01666 01667 /* ----------------------------- MNI Header ----------------------------------- 01668 @NAME : set_object_surfprop 01669 @INPUT : object 01670 spr 01671 @OUTPUT : 01672 @RETURNS : 01673 @DESCRIPTION: Sets the surfprop of the object. 01674 @METHOD : 01675 @GLOBALS : 01676 @CALLS : 01677 @CREATED : 1993 David MacDonald 01678 @MODIFIED : 01679 ---------------------------------------------------------------------------- */ 01680 01681 public void set_object_surfprop( 01682 object_struct *object, 01683 Surfprop *spr ) 01684 { 01685 Surfprop *object_spr; 01686 01687 object_spr = get_object_surfprop( object ); 01688 01689 if( object_spr != (Surfprop *) NULL ) 01690 *object_spr = *spr; 01691 } 01692 01693 /* ----------------------------- MNI Header ----------------------------------- 01694 @NAME : free_colours 01695 @INPUT : colour_flag 01696 colours 01697 n_points 01698 n_items 01699 @OUTPUT : 01700 @RETURNS : 01701 @DESCRIPTION: Frees the colours. 01702 @METHOD : 01703 @GLOBALS : 01704 @CALLS : 01705 @CREATED : 1993 David MacDonald 01706 @MODIFIED : 01707 ---------------------------------------------------------------------------- */ 01708 01709 public void free_colours( 01710 Colour_flags colour_flag, 01711 Colour colours[], 01712 int n_points, 01713 int n_items ) 01714 { 01715 BOOLEAN should_free; 01716 01717 should_free = FALSE; 01718 01719 switch( colour_flag ) 01720 { 01721 case ONE_COLOUR: 01722 should_free = TRUE; 01723 break; 01724 01725 case PER_ITEM_COLOURS: 01726 should_free = (n_items > 0); 01727 break; 01728 01729 case PER_VERTEX_COLOURS: 01730 should_free = (n_points > 0); 01731 break; 01732 } 01733 01734 if( should_free ) 01735 FREE( colours ); 01736 } 01737 01738 /* ----------------------------- MNI Header ----------------------------------- 01739 @NAME : objects_are_same_topology 01740 @INPUT : n_points1 01741 n_items1 01742 end_indices1 01743 indices1 01744 n_points2 01745 n_items2 01746 end_indices2 01747 indices2 01748 @OUTPUT : 01749 @RETURNS : TRUE if same topology 01750 @DESCRIPTION: Tests if two objects are the same topology. 01751 @METHOD : 01752 @GLOBALS : 01753 @CALLS : 01754 @CREATED : 1993 David MacDonald 01755 @MODIFIED : 01756 ---------------------------------------------------------------------------- */ 01757 01758 public BOOLEAN objects_are_same_topology( 01759 int n_points1, 01760 int n_items1, 01761 int *end_indices1, 01762 int *indices1, 01763 int n_points2, 01764 int n_items2, 01765 int *end_indices2, 01766 int *indices2 ) 01767 { 01768 int p; 01769 01770 if( n_points1 != n_points2 || n_items1 != n_items2 ) 01771 return( FALSE ); 01772 01773 for_less( p, 0, n_items1 ) 01774 if( end_indices1[p] != end_indices2[p] ) 01775 return( FALSE ); 01776 01777 for_less( p, 0, end_indices1[n_items1-1] ) 01778 if( indices1[p] != indices2[p] ) 01779 return( FALSE ); 01780 01781 return( TRUE ); 01782 } 01783 01784 /* ----------------------------- MNI Header ----------------------------------- 01785 @NAME : get_n_colours 01786 @INPUT : colour_flag 01787 n_points 01788 n_items 01789 @OUTPUT : 01790 @RETURNS : number of colours 01791 @DESCRIPTION: Returns the number of colours corresponding to the colour_flag. 01792 @METHOD : 01793 @GLOBALS : 01794 @CALLS : 01795 @CREATED : 1993 David MacDonald 01796 @MODIFIED : 01797 ---------------------------------------------------------------------------- */ 01798 01799 public int get_n_colours( 01800 Colour_flags colour_flag, 01801 int n_points, 01802 int n_items ) 01803 { 01804 int n_colours; 01805 01806 switch( colour_flag ) 01807 { 01808 case ONE_COLOUR: 01809 n_colours = 1; 01810 break; 01811 01812 case PER_ITEM_COLOURS: 01813 n_colours = n_items; 01814 break; 01815 01816 case PER_VERTEX_COLOURS: 01817 n_colours = n_points; 01818 break; 01819 01820 default: 01821 print_error( "invalid colour flag\n" ); 01822 n_colours = 0; 01823 break; 01824 } 01825 01826 return( n_colours ); 01827 }

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