3
// simulate scores from a mask
4
// Copyright (c) 2010 by The VoxBo Development Team
6
// VoxBo is free software: you can redistribute it and/or modify it
7
// under the terms of the GNU General Public License as published by
8
// the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
11
// VoxBo is distributed in the hope that it will be useful, but
12
// WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with VoxBo. If not, see <http://www.gnu.org/licenses/>.
19
// For general information on VoxBo, including the latest complete
20
// source code and binary distributions, manual, and associated files,
21
// see the VoxBo home page at: http://www.voxbo.org/
23
// original version written by Dan Kimberg
30
#include "vbscoregen.hlp.h"
32
void vbscoregen_help();
33
void vbscoregen_version();
37
double gaussian_random(double sigma);
41
VBscoregen(string cfg) {parseconfig(cfg);}
44
map<string,VBRegion> maskmap;
45
map<string,VBVoxel> voxelmap;
46
double mean1,sd1,mean2,sd2;
48
void parseconfig(string configfile);
49
double genscore(double pct);
50
void do_ifvoxel(string v1);
51
void do_ifvoxelor(string v1,string v2);
52
void do_ifvoxeland(string v1,string v2);
53
void do_region(string r1);
54
void do_regionor(string r1,string r2);
55
void do_regionand(string r1,string r2);
56
void do_regionpct(string r1);
57
void do_regionpctor(string r1,string r2);
58
void do_regionpctand(string r1,string r2);
62
main(int argc,char **argv)
79
VBscoregen::genscore(double pct)
81
double mean=mean1+(pct*(mean2-mean1));
82
double sd=sd1+(pct*(sd2-sd1));
83
return mean+gaussian_random(sd);
87
VBscoregen::parseconfig(string configfile)
90
infile.open(configfile.c_str());
95
chdir(xdirname(configfile).c_str());
99
while (infile.getline(buf,STRINGLEN,'\n')) {
101
if (args.size()==0) continue;
102
if (args[0][0]=='#' || args[0][0] == ';')
104
if (args[0]=="intact" && args.size()==3) {
105
mean1=strtod(args[1]);
108
else if (args[0]=="damaged" && args.size()==3) {
109
mean2=strtod(args[1]);
112
else if (args[0]=="mask" && args.size()==3) {
114
if (m.ReadFile(args[2])) {
118
VBRegion rr=findregion_mask(m,vb_agt,0.0);
120
// cout loaded mask xxxx stats
122
else if (args[0]=="voxel" && args.size()==5) {
123
VBVoxel vv(strtol(args[2]),strtol(args[3]),strtol(args[4]));
124
voxelmap[args[1]]=vv;
125
// cout loaded voxel xxxx location
127
else if (args[0]=="lesions" && args.size()==2) {
128
if (lesions.ReadFile(args[1])) {
132
scores.resize(lesions.dimt);
134
else if (args[0]=="ifvoxel" && args.size()==2) {
137
else if (args[0]=="ifvoxelor" && args.size()==3) {
138
do_ifvoxelor(args[1],args[2]);
140
else if (args[0]=="ifvoxeland" && args.size()==3) {
141
do_ifvoxeland(args[1],args[2]);
143
else if (args[0]=="region" && args.size()==2) {
146
else if (args[0]=="regionor" && args.size()==3) {
147
do_regionor(args[1],args[2]);
149
else if (args[0]=="regionand" && args.size()==3) {
150
do_regionand(args[1],args[2]);
152
else if (args[0]=="regionpct" && args.size()==2) {
153
do_regionpct(args[1]);
155
else if (args[0]=="regionpctor" && args.size()==3) {
156
do_regionpctor(args[1],args[2]);
158
else if (args[0]=="regionpctand" && args.size()==3) {
159
do_regionpctand(args[1],args[2]);
161
else if (args[0]=="generate" && args.size()==2) {
162
scores.WriteFile(args[1]);
176
VBscoregen::do_ifvoxel(string v1)
178
if (!voxelmap.count(v1))
180
for (int i=0; i<lesions.dimt; i++) {
181
if (abs(lesions.GetValue(voxelmap[v1],i))>DBL_MIN)
182
scores[i]=genscore(1.0);
184
scores[i]=genscore(0.0);
189
VBscoregen::do_ifvoxelor(string v1,string v2)
191
if (!voxelmap.count(v1) || !voxelmap.count(v2))
193
for (int i=0; i<lesions.dimt; i++) {
194
if (abs(lesions.GetValue(voxelmap[v1],i))>DBL_MIN
195
||abs(lesions.GetValue(voxelmap[v2],i))>DBL_MIN)
196
scores[i]=genscore(1.0);
198
scores[i]=genscore(0.0);
203
VBscoregen::do_ifvoxeland(string v1,string v2)
205
if (!voxelmap.count(v1) || !voxelmap.count(v2))
207
for (int i=0; i<lesions.dimt; i++) {
208
if (abs(lesions.GetValue(voxelmap[v1],i))>DBL_MIN
209
&&abs(lesions.GetValue(voxelmap[v2],i))>DBL_MIN)
210
scores[i]=genscore(1.0);
212
scores[i]=genscore(0.0);
217
VBscoregen::do_region(string r1)
219
if (!maskmap.count(r1))
221
VBRegion reg=maskmap[r1];
222
for (int i=0; i<lesions.dimt; i++) {
224
for (VI v=reg.begin(); v!=reg.end(); v++) {
225
if (abs(lesions.GetValue(v->second,i))>DBL_MIN) {
231
scores[i]=genscore(1.0);
233
scores[i]=genscore(0.0);
238
VBscoregen::do_regionor(string r1,string r2)
240
if (!maskmap.count(r1) || !maskmap.count(r2))
242
VBRegion reg1=maskmap[r1];
243
VBRegion reg2=maskmap[r2];
244
for (int i=0; i<lesions.dimt; i++) {
245
bool dflg1=0,dflg2=0;
246
for (VI v=reg1.begin(); v!=reg1.end(); v++) {
247
if (abs(lesions.GetValue(v->second,i))>DBL_MIN) {
253
for (VI v=reg2.begin(); v!=reg2.end(); v++) {
254
if (abs(lesions.GetValue(v->second,i))>DBL_MIN) {
260
scores[i]=genscore(1.0);
262
scores[i]=genscore(0.0);
267
VBscoregen::do_regionand(string r1,string r2)
269
if (!maskmap.count(r1) || !maskmap.count(r2))
271
VBRegion reg1=maskmap[r1];
272
VBRegion reg2=maskmap[r2];
273
for (int i=0; i<lesions.dimt; i++) {
274
bool dflg1=0,dflg2=0;
275
for (VI v=reg1.begin(); v!=reg1.end(); v++) {
276
if (abs(lesions.GetValue(v->second,i))>DBL_MIN) {
282
for (VI v=reg2.begin(); v!=reg2.end(); v++) {
283
if (abs(lesions.GetValue(v->second,i))>DBL_MIN) {
289
scores[i]=genscore(1.0);
291
scores[i]=genscore(0.0);
296
VBscoregen::do_regionpct(string r1)
298
if (!maskmap.count(r1))
300
VBRegion reg1=maskmap[r1];
301
for (int i=0; i<lesions.dimt; i++) {
303
for (VI v=reg1.begin(); v!=reg1.end(); v++) {
304
if (abs(lesions.GetValue(v->second,i))>DBL_MIN)
307
scores[i]=genscore((double)cnt/(double)reg1.size());
312
VBscoregen::do_regionpctor(string r1,string r2)
314
if (!maskmap.count(r1) || !maskmap.count(r2))
316
VBRegion reg1=maskmap[r1];
317
VBRegion reg2=maskmap[r2];
318
for (int i=0; i<lesions.dimt; i++) {
321
for (VI v=reg1.begin(); v!=reg1.end(); v++) {
322
if (abs(lesions.GetValue(v->second,i))>DBL_MIN)
325
pct1=(double)cnt/(double)reg1.size();
326
for (VI v=reg2.begin(); v!=reg2.end(); v++) {
327
if (abs(lesions.GetValue(v->second,i))>DBL_MIN)
330
pct2=(double)cnt/(double)reg2.size();
331
scores[i]=genscore((pct2>pct1 ? pct2 : pct1));
336
VBscoregen::do_regionpctand(string r1,string r2)
338
if (!maskmap.count(r1) || !maskmap.count(r2))
340
VBRegion reg1=maskmap[r1];
341
VBRegion reg2=maskmap[r2];
342
for (int i=0; i<lesions.dimt; i++) {
345
for (VI v=reg1.begin(); v!=reg1.end(); v++) {
346
if (abs(lesions.GetValue(v->second,i))>DBL_MIN)
349
pct1=(double)cnt/(double)r1.size();
350
for (VI v=reg2.begin(); v!=reg2.end(); v++) {
351
if (abs(lesions.GetValue(v->second,i))>DBL_MIN)
354
pct2=(double)cnt/(double)reg2.size();
355
scores[i]=genscore((pct2>pct1 ? pct1 : pct2));
362
gaussian_random(double sigma)
365
rng=gsl_rng_alloc(gsl_rng_mt19937);
367
gsl_rng_set(rng,VBRandom());
369
return gsl_ran_gaussian(rng,sigma);
378
cout << boost::format(myhelp) % vbversion;
384
printf("VoxBo vbscoregen (v%s)\n",vbversion.c_str());