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

safe_compute_xfm.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- 00002 @COPYRIGHT : 00003 Copyright 1993,1994,1995 David MacDonald, 00004 Peter Neelin, Louis Collins, 00005 McConnell Brain Imaging Centre, 00006 Montreal Neurological Institute, McGill University. 00007 Permission to use, copy, modify, and distribute this 00008 software and its documentation for any purpose and without 00009 fee is hereby granted, provided that the above copyright 00010 notice appear in all copies. The author and McGill University 00011 make no representations about the suitability of this 00012 software for any purpose. It is provided "as is" without 00013 express or implied warranty. 00014 ---------------------------------------------------------------------------- */ 00015 00016 /* ----------------------------- MNI Header ----------------------------------- 00017 @NAME : safe_compute_xfm.c 00018 @DESCRIPTION: Routine to calculate a General_transform from a pair of tag 00019 point lists. This routine is safe in that it returns 00020 an identity matrix if any error occurs. 00021 @METHOD : 00022 @GLOBALS : 00023 @CREATED : April 21, 1994 (Peter Neelin) 00024 @MODIFIED : $Log: safe_compute_xfm.c,v $ 00025 @MODIFIED : Revision 1.11 2000/02/06 15:30:51 stever 00026 @MODIFIED : rearranged header file structure; add gcc -Wall fixes 00027 @MODIFIED : 00028 @MODIFIED : Revision 1.10 2000/02/05 21:27:21 stever 00029 @MODIFIED : change include lines <foo.h> --> <bicpl/foo.h> 00030 @MODIFIED : 00031 @MODIFIED : Revision 1.9 1995/10/19 15:48:59 david 00032 @MODIFIED : check_in_all 00033 @MODIFIED : 00034 * Revision 1.8 1995/09/29 19:06:37 david 00035 * *** empty log message *** 00036 * 00037 * Revision 1.7 1995/07/31 13:46:03 david 00038 * check_in_all 00039 * 00040 * Revision 1.6 1995/07/10 18:02:53 david 00041 * check_in_all 00042 * 00043 * Revision 1.5 1995/07/10 14:36:11 david 00044 * check_in_all 00045 * 00046 * Revision 1.4 1995/04/28 18:30:19 david 00047 * check_in_all 00048 * 00049 * Revision 1.3 1995/03/07 18:54:51 david 00050 * check_in_all 00051 * 00052 * Revision 1.2 94/11/25 14:23:27 david 00053 * check_in_all 00054 * 00055 * Revision 1.1 94/11/04 14:45:55 david 00056 * Initial revision 00057 * 00058 * Revision 1.1 94/04/22 08:07:20 neelin 00059 * Initial revision 00060 * 00061 ---------------------------------------------------------------------------- */ 00062 00063 #include <stdlib.h> 00064 #include <string.h> 00065 #include <sys/types.h> 00066 #include <unistd.h> 00067 #include <sys/wait.h> 00068 #include <volume_io/internal_volume_io.h> 00069 #include <bicpl/trans.h> 00070 00071 #ifndef lint 00072 static char rcsid[] = "$Header: /software/source//libraries/bicpl/Transforms/safe_compute_xfm.c,v 1.11 2000/02/06 15:30:51 stever Exp $"; 00073 #endif 00074 00075 #define NO_FORK 00076 #undef NO_FORK 00077 00078 /* ----------------------------- MNI Header ----------------------------------- 00079 @NAME : safe_compute_transform_from_tags 00080 @INPUT : npoints - number of pairs of tag points 00081 tag_list1 - first list of tag points 00082 tag_list2 - second list of tag points 00083 trans_type - type of transformation to calculate 00084 @OUTPUT : transform - computed transform 00085 @RETURNS : (nothing) 00086 @DESCRIPTION: Routine to calculate a general transform from a pair of lists 00087 of tag points. The transform is from tag_list2 to tag_list1. 00088 This routine is safe in that it returns an identity matrix 00089 if any error occurs. 00090 @METHOD : 00091 @GLOBALS : 00092 @CALLS : 00093 @CREATED : April 21, 1994 (Peter Neelin) 00094 @MODIFIED : 00095 ---------------------------------------------------------------------------- */ 00096 00097 public void safe_compute_transform_from_tags( 00098 int npoints, 00099 Real **tag_list1, 00100 Real **tag_list2, 00101 Trans_type trans_type, 00102 General_transform *transform ) 00103 { 00104 #ifdef NO_FORK 00105 compute_transform_from_tags( npoints, tag_list1, tag_list2, trans_type, 00106 transform ); 00107 #else 00108 int fildes[2]; 00109 FILE *fpin, *fpout; 00110 Status status; 00111 int statptr; 00112 General_transform computed_transform; 00113 00114 /* Create a pipe */ 00115 00116 if (pipe(fildes)) { 00117 create_linear_transform(transform, NULL); 00118 return; 00119 } 00120 00121 /* Fork */ 00122 if (fork()) { /* Parent */ 00123 (void) close(fildes[1]); 00124 fpin = fdopen(fildes[0], "r"); 00125 status = input_transform(fpin, NULL, transform); 00126 (void) fclose(fpin); 00127 do { 00128 (void) wait(&statptr); 00129 } while (WIFSTOPPED(statptr)); 00130 if (WEXITSTATUS(statptr) || status != OK) { 00131 if( status == OK ) 00132 delete_general_transform( transform ); 00133 create_linear_transform(transform, NULL); 00134 return; 00135 } 00136 } 00137 00138 else { /* Child */ 00139 (void) close(fildes[0]); 00140 fpout = fdopen(fildes[1], "w"); 00141 compute_transform_from_tags(npoints, tag_list1, tag_list2, trans_type, 00142 &computed_transform); 00143 status = output_transform(fpout, NULL, NULL, NULL, &computed_transform); 00144 delete_general_transform( &computed_transform ); 00145 (void) fclose(fpout); 00146 if (status != OK) { 00147 exit(EXIT_FAILURE); 00148 } 00149 else { 00150 exit(EXIT_SUCCESS); 00151 } 00152 } 00153 00154 return; 00155 #endif 00156 }

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