-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck_tags.c
184 lines (161 loc) · 4.95 KB
/
check_tags.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <bicpl.h>
private int tags_exist(
int n_objects,
object_struct *object_list[],
int id1,
int id2 );
private BOOLEAN get_next_filename(
char *filename[] )
{
static FILE *file = 0;
static BOOLEAN in_list = FALSE;
static STRING filename_string;
char *argument;
BOOLEAN found;
found = FALSE;
do
{
if( in_list )
{
if( input_string( file, filename_string, MAX_STRING_LENGTH, ' ' )
== OK )
{
*filename = filename_string;
found = TRUE;
}
else
{
(void) close_file( file );
in_list = FALSE;
}
}
else if( get_string_argument( "", &argument ) )
{
if( filename_extension_matches( argument,
get_default_landmark_file_suffix() )||
filename_extension_matches( argument,
get_default_tag_file_suffix() ) ||
filename_extension_matches( argument, "obj" ) )
{
*filename = argument;
found = TRUE;
}
else
{
if( open_file( argument, READ_FILE, ASCII_FORMAT, &file ) != OK)
break;
in_list = TRUE;
}
}
else
break;
}
while( !found );
return( found );
}
int main(
int argc,
char *argv[] )
{
Status status;
char *landmark_filename, *error_filename;
BOOLEAN left;
char *format;
STRING *filenames;
Volume volume;
volume_input_struct volume_input;
int n_files, n_objects;
object_struct **object_list;
int p;
int n_left, n_right, n_12, n_22;
initialize_argument_processing( argc, argv );
n_files = 0;
volume = (Volume) NULL;
while( get_next_filename( &landmark_filename ) )
{
if( filename_extension_matches( landmark_filename, "mnc" ) ||
filename_extension_matches( landmark_filename, "mni" ) ||
filename_extension_matches( landmark_filename, "fre" ) )
{
if( volume != (Volume) NULL )
cancel_volume_input( volume, &volume_input );
status = start_volume_input(
landmark_filename, 3, XYZ_dimension_names,
NC_UNSPECIFIED, FALSE, 0.0, 0.0,
TRUE, &volume, (minc_input_options *) NULL,
&volume_input );
}
else
{
SET_ARRAY_SIZE( filenames, n_files, n_files + 1,
DEFAULT_CHUNK_SIZE );
(void) strcpy( filenames[n_files], landmark_filename );
++n_files;
}
}
n_12 = 0;
n_22 = 0;
n_left = 0;
n_right = 0;
for_less( p, 0, n_files )
{
status = input_objects_any_format( volume, filenames[p],
GREEN, 1.0, BOX_MARKER,
&n_objects, &object_list );
if( strstr( filenames[p], "cing_l" ) != (char *) NULL )
left = TRUE;
else if( strstr( filenames[p], "cing_r" ) != (char *) NULL )
left = FALSE;
else
{
print( "Filename %s does not match cing_l or cing_r\n",
filenames[p] );
break;
}
if( left )
{
if( tags_exist( n_objects, object_list, 12, 13 ) )
++n_12;
++n_left;
}
else
{
if( tags_exist( n_objects, object_list, 22, 23 ) )
++n_22;
++n_right;
}
delete_object_list( n_objects, object_list );
}
if( volume != (Volume) NULL )
cancel_volume_input( volume, &volume_input );
print( "Branch frequency left : %d out of %d files.\n", n_12, n_left );
print( "Branch frequency right: %d out of %d files.\n", n_22, n_right );
return( status != OK );
}
private int tags_exist(
int n_objects,
object_struct *object_list[],
int id1,
int id2 )
{
BOOLEAN id1_exists, id2_exists;
int i, id;
marker_struct *marker;
id1_exists = FALSE;
id2_exists = FALSE;
for_less( i, 0, n_objects )
{
if( object_list[i]->object_type == MARKER )
{
marker = get_marker_ptr( object_list[i] );
id = marker->structure_id;
if( id >= 1000 )
id -= 1000;
if( id == id1 )
id1_exists = TRUE;
if( id == id2 )
id2_exists = TRUE;
}
}
return( id1_exists && id2_exists );
}