-
Notifications
You must be signed in to change notification settings - Fork 0
/
tgastack2xrw.c
140 lines (125 loc) · 3.86 KB
/
tgastack2xrw.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
/* tgastack2xrw.c
*
* Copyright 2012 David G. Barnes
*
* This file is part of S2VOLSURF.
*
* S2VOLSURF is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* S2VOLSURF is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with S2VOLSURF. If not, see <http://www.gnu.org/licenses/>.
*
* We would appreciate it if research outcomes using S2VOLSURF would
* provide the following acknowledgement:
*
* "Three-dimensional visualisation was conducted with the S2PLOT
* progamming library"
*
* and a reference to
*
* D.G.Barnes, C.J.Fluke, P.D.Bourke & O.T.Parry, 2006, Publications
* of the Astronomical Society of Australia, 23(2), 82-93.
*
* $Id: tgastack2xrw.c 70 2012-11-22 23:00:34Z barnesd $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include "libxrw.c"
void usage(char *exename) {
fprintf(stderr, "usage: %s [options] -f infileformat.tga -o xrwfilename\n", exename);
fprintf(stderr, " * * * (infileformat should include integer specifier e.g. %%04d)\n");
fprintf(stderr, " -s s1 s2 s3\t\t set data averaging along each axis (1 1 1)\n");
fprintf(stderr, " -w wx wy wz\t\t set world size of pixels (1.0 1.0 1.0)\n");
}
#define FNAMELEN 400
int main(int argc, char *argv[]) {
char ifname[FNAMELEN+1];
int haveifname = 0;
char ofname[FNAMELEN+1];
int haveofname = 0;
float wdelta[] = {1.,1.,1.};
int stride[] = {1,1,1};
if (argc < 5) {
usage(argv[0]);
return -1;
}
int ic = 1;
while (ic < argc) {
if (!strcmp(argv[ic], "-f")) {
strncpy(ifname, argv[++ic], FNAMELEN);
haveifname = 1;
} else if (!strcmp(argv[ic], "-o")) {
strncpy(ofname, argv[++ic], FNAMELEN);
haveofname = 1;
} else if (!strcmp(argv[ic], "-s")) {
stride[0] = atoi(argv[++ic]);
stride[1] = atoi(argv[++ic]);
stride[2] = atoi(argv[++ic]);
if (stride[0] < 1 || stride[1] < 1 || stride[2] < 1) {
fprintf(stderr, "stride must be at least 1 in each direction!\n");
exit(-1);
}
} else if (!strcmp(argv[ic], "-w")) {
wdelta[0] = atof(argv[++ic]);
wdelta[1] = atof(argv[++ic]);
wdelta[2] = atof(argv[++ic]);
}
ic++;
}
if (!haveifname || !haveofname) {
usage(argv[0]);
}
// find start/end of filename indices
fprintf(stderr, "Finding start/end indices for stack: check inputs if this hangs!\n");
int istart=0, iend;
char tfname[FNAMELEN+1];
sprintf(tfname, ifname, istart);
FILE *tf = fopen(tfname, "r");
while (!tf) {
//fclose(tf);
istart++;
sprintf(tfname, ifname, istart);
//fprintf(stderr, "istart = %d\n", istart);
//fprintf(stderr, "tfname = %s\n", tfname);
tf = fopen(tfname, "r");
}
fclose(tf);
iend = istart + 1;
sprintf(tfname, ifname, iend);
tf = fopen(tfname, "r");
while (tf) {
fclose(tf);
iend++;
sprintf(tfname, ifname, iend);
//fprintf(stderr, "iend = %d\n", iend);
//fprintf(stderr, "tfname = %s\n", tfname);
tf = fopen(tfname, "r");
}
iend--;
fprintf(stderr, "File index appears to go from %d to %d\n", istart, iend);
VOL_STRUCT *tgavol = loadTGAstack(ifname, istart, iend, 1);
tgavol->wdx = wdelta[0];
tgavol->wdy = wdelta[1];
tgavol->wdz = wdelta[2];
showXvol(tgavol);
VOL_STRUCT *tgavol_sm = rebinXvol(tgavol, stride);
normaliseXvol(tgavol_sm);
showXvol(tgavol_sm);
XRAW_STRUCT *xraw = Xvol2Xraw(tgavol_sm);
sprintf(xraw->filename, ofname);
showXraw(xraw);
saveXraw(xraw);
return 0;
}