~ubuntu-branches/ubuntu/raring/voxbo/raring

« back to all changes in this revision

Viewing changes to munge/vbregion.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2010-06-06 11:33:11 UTC
  • Revision ID: james.westby@ubuntu.com-20100606113311-v3c13imdkkd5n7ae
Tags: upstream-1.8.5~svn1172
ImportĀ upstreamĀ versionĀ 1.8.5~svn1172

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// vbregion.cpp
 
3
// region of interest info for voxbo stat cubes
 
4
// Copyright (c) 2003-2008 by The VoxBo Development Team
 
5
 
 
6
// This file is part of VoxBo
 
7
// 
 
8
// VoxBo is free software: you can redistribute it and/or modify it
 
9
// under the terms of the GNU General Public License as published by
 
10
// the Free Software Foundation, either version 3 of the License, or
 
11
// (at your option) any later version.
 
12
// 
 
13
// VoxBo is distributed in the hope that it will be useful, but
 
14
// WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
// General Public License for more details.
 
17
// 
 
18
// You should have received a copy of the GNU General Public License
 
19
// along with VoxBo.  If not, see <http://www.gnu.org/licenses/>.
 
20
// 
 
21
// For general information on VoxBo, including the latest complete
 
22
// source code and binary distributions, manual, and associated files,
 
23
// see the VoxBo home page at: http://www.voxbo.org/
 
24
//
 
25
// original version written by Dan Kimberg
 
26
 
 
27
using namespace std;
 
28
 
 
29
#include <stdio.h>
 
30
#include <string.h>
 
31
#include <algorithm>
 
32
#include "vbutil.h"
 
33
#include "vbio.h"
 
34
#include "vbregion.hlp.h"
 
35
 
 
36
void vbregion_help();
 
37
 
 
38
int
 
39
main(int argc,char *argv[])
 
40
{
 
41
  tokenlist args;
 
42
  args.Transfer(argc-1,argv+1);
 
43
  if (args.size() < 1) {
 
44
    vbregion_help();
 
45
    exit(100);
 
46
  }
 
47
 
 
48
  string maskfile="";
 
49
  double threshold=0.0;
 
50
  list<string>cubelist;
 
51
  int i,f_thresh=0,f_absthresh=0,f_mask=0;
 
52
  stringstream tmps;
 
53
  
 
54
  for (i=0; i<args.size(); i++) {
 
55
    if (args[i]=="-m" && i<args.size()-1) {
 
56
      maskfile=args[i+1];
 
57
      i++;
 
58
    }
 
59
    else if (args[i]=="-t" && i<args.size()-1) {
 
60
      threshold=strtod(args[i+1]);
 
61
      f_thresh=1;
 
62
      i++;
 
63
    }
 
64
    else if (args[i]=="-a" && i<args.size()-1) {
 
65
      threshold=strtod(args[i+1]);
 
66
      f_absthresh=1;
 
67
      i++;
 
68
    }
 
69
    else {
 
70
      cubelist.push_back(args[i]);
 
71
    }
 
72
  }
 
73
 
 
74
  Cube mycub,mask;
 
75
 
 
76
  if (maskfile.size()) {
 
77
    if (mask.ReadFile(maskfile)) {
 
78
      printf("[E] vbregion: invalid mask volume %s\n",maskfile.c_str());
 
79
      exit(170);
 
80
    }
 
81
    f_mask=1;
 
82
  }
 
83
  for (list<string>::iterator mm=cubelist.begin(); mm!=cubelist.end(); mm++) {
 
84
    if (mycub.ReadFile(*mm)) {
 
85
      printf("[E] vbregion: couldn't read cube %s\n",mm->c_str());
 
86
      continue;
 
87
    }
 
88
    if (f_mask)
 
89
      mycub.intersect(mask);
 
90
    vector<VBRegion> rlist;
 
91
    if (f_thresh)
 
92
      rlist=findregions(mycub,vb_gt,threshold);
 
93
    else if (f_absthresh)
 
94
      rlist=findregions(mycub,vb_agt,threshold);
 
95
    else
 
96
      rlist=findregions(mycub,vb_gt,0.0);
 
97
    uint64 xx,yy,zz;
 
98
    double xxx,yyy,zzz,val;
 
99
    int index=1;
 
100
    // make sure origin is sane for origin-corrected coordinates
 
101
    if (mycub.origin[0]==0 && mycub.origin[1]==0 && mycub.origin[2]==0) {
 
102
      mycub.guessorigin();
 
103
      if (mycub.origin[0] || mycub.origin[1] || mycub.origin[2])
 
104
        printf("[I] vbregion: guessing origin %d,%d,%d based on image dimensions\n",
 
105
               mycub.origin[0],mycub.origin[1],mycub.origin[2]);
 
106
    }
 
107
    printf("[I] vbregion: cube %s has %d regions\n",mm->c_str(),(int)(rlist.size()));
 
108
    if (!(mycub.voxsize[0]>0.0 && mycub.voxsize[1]>0.0 && mycub.voxsize[2]>0.0)) {
 
109
      printf("[W] vbregion: no voxel sizes found, all origin-relative coordinates\n");
 
110
      printf("[W] vbregion: are in voxels, not mm.\n");
 
111
    }
 
112
    for (vector<VBRegion>::iterator rr=rlist.begin(); rr!=rlist.end(); rr++) {
 
113
      printf("region %d info:\n",index++);
 
114
      printf("  %d voxels\n",rr->size());
 
115
      rr->max(xx,yy,zz,val);
 
116
 
 
117
      printf("  max voxel at %d,%d,%d ",(int)xx,(int)yy,(int)zz);
 
118
      if (mycub.voxsize[0]>0.0 && mycub.voxsize[1]>0.0 && mycub.voxsize[2]>0.0)
 
119
        printf("(%.2f,%.2f,%.2f mm relative to origin), ",
 
120
               mycub.voxsize[0]*(xx-mycub.origin[0]),
 
121
               mycub.voxsize[1]*(yy-mycub.origin[1]),
 
122
               mycub.voxsize[2]*(zz-mycub.origin[2]));
 
123
      else
 
124
        printf("(%d,%d,%d voxels relative to origin), ",
 
125
               (int)(xx-mycub.origin[0]),
 
126
               (int)(yy-mycub.origin[1]),
 
127
               (int)(zz-mycub.origin[2]));
 
128
      printf("value is %g\n",val);
 
129
 
 
130
      rr->min(xx,yy,zz,val);
 
131
      printf("  min voxel at %d,%d,%d ",(int)xx,(int)yy,(int)zz);
 
132
      if (mycub.voxsize[0]>0.0 && mycub.voxsize[1]>0.0 && mycub.voxsize[2]>0.0)
 
133
        printf("(%.2f,%.2f,%.2f mm relative to origin), ",
 
134
               mycub.voxsize[0]*(xx-mycub.origin[0]),
 
135
               mycub.voxsize[1]*(yy-mycub.origin[1]),
 
136
               mycub.voxsize[2]*(zz-mycub.origin[2]));
 
137
      else
 
138
        printf("(%d,%d,%d voxels relative to origin), ",
 
139
               (int)(xx-mycub.origin[0]),
 
140
               (int)(yy-mycub.origin[1]),
 
141
               (int)(zz-mycub.origin[2]));
 
142
      printf("value is %g\n",val);
 
143
 
 
144
      rr->GeometricCenter(xxx,yyy,zzz);
 
145
      printf("  geometric center is at %.2f,%.2f,%.2f ",xxx,yyy,zzz);
 
146
      if (mycub.voxsize[0]>0.0 && mycub.voxsize[1]>0.0 && mycub.voxsize[2]>0.0)
 
147
        printf("(%.2f,%.2f,%.2f mm relative to origin), ",
 
148
               mycub.voxsize[0]*(xxx-mycub.origin[0]),
 
149
               mycub.voxsize[1]*(yyy-mycub.origin[1]),
 
150
               mycub.voxsize[2]*(zzz-mycub.origin[2]));
 
151
      else
 
152
        printf("(%.2f,%.2f,%.2f voxels relative to origin), ",
 
153
               (xxx-mycub.origin[0]),
 
154
               (yyy-mycub.origin[1]),
 
155
               (zzz-mycub.origin[2]));
 
156
      printf("value is %g\n",val);
 
157
    }
 
158
  }
 
159
  exit(0);
 
160
}
 
161
 
 
162
void
 
163
vbregion_help()
 
164
{
 
165
  cout << boost::format(myhelp) % vbversion;
 
166
}