forked from freesurfer/freesurfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmri_copy_values.cpp
114 lines (96 loc) · 2.8 KB
/
mri_copy_values.cpp
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
/*
*
* Copyright © 2021 The General Hospital Corporation (Boston, MA) "MGH"
*
* Terms and conditions for use, reproduction, distribution and contribution
* are found in the 'FreeSurfer Software License Agreement' contained
* in the file 'LICENSE' found in the FreeSurfer distribution, and here:
*
* https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense
*
* Reporting: freesurfer@nmr.mgh.harvard.edu
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include "mri.h"
#include "macros.h"
#include "error.h"
#include "diag.h"
#include "proto.h"
#include "version.h"
int main(int argc, char *argv[]) ;
static int get_option(int argc, char *argv[]) ;
const char *Progname ;
int
main(int argc, char *argv[]) {
char **av ;
int ac, nargs ;
MRI *mri_src, *mri_dst ;
char *in_fname, *out_fname ;
int label, nvox ;
nargs = handleVersionOption(argc, argv, "mri_copy_values");
if (nargs && argc - nargs == 1)
exit (0);
argc -= nargs;
Progname = argv[0] ;
ErrorInit(NULL, NULL, NULL) ;
DiagInit(NULL, NULL, NULL) ;
ac = argc ;
av = argv ;
for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) {
nargs = get_option(argc, argv) ;
argc -= nargs ;
argv += nargs ;
}
if (argc < 2)
ErrorExit(ERROR_BADPARM, "%s: no input name specified", Progname) ;
in_fname = argv[1] ;
if (argc < 3)
ErrorExit(ERROR_BADPARM, "%s: no value specified", Progname) ;
label = atoi(argv[2]) ;
if (argc < 4)
ErrorExit(ERROR_BADPARM, "%s: no output name specified", Progname) ;
out_fname = argv[3] ;
fprintf(stderr, "reading from %s...\n", in_fname) ;
mri_src = MRIread(in_fname) ;
if (!mri_src)
ErrorExit(ERROR_NOFILE, "%s: could not read input volume %s",
Progname, in_fname) ;
mri_dst = MRIread(out_fname) ;
if (!mri_dst)
ErrorExit(ERROR_NOFILE, "%s: could not read destination volume %s",
Progname, out_fname) ;
nvox = MRIcopyLabel(mri_src, mri_dst, label) ;
fprintf(stderr, "%d voxels copied from input to output volume...\n", nvox);
fprintf(stderr, "writing to %s...\n", out_fname) ;
MRIwrite(mri_dst, out_fname) ;
MRIfree(&mri_dst) ;
MRIfree(&mri_src) ;
exit(0) ;
return(0) ;
}
/*----------------------------------------------------------------------
Parameters:
Description:
----------------------------------------------------------------------*/
static int
get_option(int argc, char *argv[]) {
int nargs = 0 ;
char *option ;
option = argv[1] + 1 ; /* past '-' */
switch (toupper(*option)) {
case '?':
case 'U':
printf("usage: %s <input volume> <label> <output volume>\n", argv[0]) ;
exit(1) ;
break ;
default:
fprintf(stderr, "unknown option %s\n", argv[1]) ;
exit(1) ;
break ;
}
return(nargs) ;
}