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

« back to all changes in this revision

Viewing changes to munge/fillmask.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
// fillmask.cpp
 
3
// fill in missing slices in a mask (e.g., lesion)
 
4
// Copyright (c) 1998-2002 by The VoxBo Development Team
 
5
 
 
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.
 
10
// 
 
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.
 
15
// 
 
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/>.
 
18
// 
 
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/
 
22
//
 
23
// original version written by Dan Kimberg
 
24
 
 
25
using namespace std;
 
26
 
 
27
#include <stdio.h>
 
28
#include <string.h>
 
29
#include "vbutil.h"
 
30
#include "vbio.h"
 
31
#include "fillmask.hlp.h"
 
32
 
 
33
void fillmask_help();
 
34
int getsampleslice(int start,int interval,int slice,int dimz);
 
35
 
 
36
int
 
37
main(int argc,char *argv[])
 
38
{
 
39
  tokenlist args;
 
40
  string infile,outfile;
 
41
  int start,interval,sampleslice;
 
42
  double val;
 
43
 
 
44
  args.Transfer(argc-1,argv+1);
 
45
 
 
46
  if (args.size() == 0) {
 
47
    fillmask_help();
 
48
    exit(0);
 
49
  }
 
50
 
 
51
  if (args.size() != 4) {
 
52
    fillmask_help();
 
53
    exit(5);
 
54
  }
 
55
 
 
56
  start=strtol(args[2]);
 
57
  interval=strtol(args[3]);
 
58
  printf("fillmasking %s to %s beginning slice %d and every %d...\n",args(0),args(1),start,interval);
 
59
  infile = args[0];
 
60
  outfile = args[1];
 
61
 
 
62
  Cube mycube,newcube;
 
63
  mycube.ReadFile(infile);
 
64
  if (!mycube.data_valid) {
 
65
    printf("\nCouldn't make a valid cube out of %s.\n",infile.c_str());
 
66
    exit(5);
 
67
  }
 
68
  // cout << mycube.GetFileType() << " " << t_img3d << endl;
 
69
  newcube=mycube;
 
70
  for (int k=0; k<mycube.dimz; k++) {
 
71
    sampleslice=getsampleslice(start,interval,k,mycube.dimz);
 
72
    for (int i=0; i<mycube.dimx; i++) {
 
73
      for (int j=0; j<mycube.dimy; j++) {
 
74
        val=mycube.GetValue(i,j,sampleslice);
 
75
        newcube.SetValue(i,j,k,val);
 
76
      }
 
77
    }
 
78
  }
 
79
  newcube.SetFileName(outfile);
 
80
  newcube.SetFileFormat("img3d");
 
81
  if (newcube.WriteFile())
 
82
    printf("Error writing file %s.\n",outfile.c_str());
 
83
  else
 
84
    printf("Done.\n");
 
85
  exit(0);
 
86
}
 
87
 
 
88
int
 
89
getsampleslice(int start,int interval,int slice,int dimz)
 
90
{
 
91
  for (int i=0; i<dimz; i++) {
 
92
    if (slice-i>=0 && slice-i <dimz)
 
93
      if ((((slice-i)-start)%interval)==0)
 
94
        return (slice-i);
 
95
    if (slice+i>=0 && slice+i <dimz)
 
96
      if ((((slice+i)-start)%interval)==0)
 
97
        return (slice+i);
 
98
  }
 
99
  return slice;
 
100
}
 
101
 
 
102
void
 
103
fillmask_help()
 
104
{
 
105
  cout << boost::format(myhelp) % vbversion;
 
106
}