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

« back to all changes in this revision

Viewing changes to munge/vb2cub.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
// vb2cub.cpp
 
3
// convert arbitrary 3D data to VoxBo CUB1
 
4
// Copyright (c) 1998-2004 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 <sstream>
 
30
#include "vbutil.h"
 
31
#include "vbio.h"
 
32
#include "vb2cub.hlp.h"
 
33
 
 
34
void vb2cub_help();
 
35
void vb2cub_version();
 
36
 
 
37
int
 
38
main(int argc,char *argv[])
 
39
{
 
40
  if (argc==1) {
 
41
    vb2cub_help();
 
42
    exit(0);
 
43
  }
 
44
  tokenlist args;
 
45
  string infile,outfile;
 
46
  int floatflag=0,nanflag=1;
 
47
 
 
48
  arghandler ah;
 
49
  string errstr;
 
50
  ah.setArgs("-f","--nofloat",0);
 
51
  ah.setArgs("-n","--nonan",0);
 
52
  ah.setArgs("-h","--help",0);
 
53
  ah.setArgs("-v","--version",0);
 
54
  ah.parseArgs(argc,argv);
 
55
 
 
56
  if ((errstr=ah.badArg()).size()) {
 
57
    printf("[E] vb2cub: %s\n",errstr.c_str());
 
58
    exit(10);
 
59
  }
 
60
  if (ah.flagPresent("-h")) {
 
61
    vb2cub_help();
 
62
    exit(0);
 
63
  }
 
64
  if (ah.flagPresent("-v")) {
 
65
    vb2cub_version();
 
66
    exit(0);
 
67
  }
 
68
  tokenlist filelist=ah.getUnflaggedArgs();
 
69
  if (filelist.size()!=2) {
 
70
    printf("[E] vb2cub: requires an input and an output file\n");
 
71
    exit(10);
 
72
  }
 
73
  if (ah.flagPresent("-f"))
 
74
    floatflag=1;
 
75
  if (ah.flagPresent("-n"))
 
76
    nanflag=1;
 
77
 
 
78
  infile = filelist[0];
 
79
  outfile = filelist[1];
 
80
  printf("[I] vb2cub: converting %s to %s\n",infile.c_str(),outfile.c_str());
 
81
 
 
82
  Cube mycube;
 
83
  mycube.ReadFile(infile);
 
84
  if (!(mycube.data_valid)) {
 
85
    printf("[E] vb2cub: couldn't make a valid cube out of %s\n",infile.c_str());
 
86
    exit(5);
 
87
  }
 
88
 
 
89
  // remove NaNs if requested
 
90
  if (nanflag)
 
91
    mycube.removenans();
 
92
  // convert to float if requested
 
93
  if (floatflag && mycube.datatype != vb_float)
 
94
    mycube.convert_type(vb_float,VBSETALT|VBNOSCALE);
 
95
 
 
96
  if (mycube.SetFileFormat("cub1")) {
 
97
    printf("[E] vb2cub: file format cub1 not available\n");
 
98
    exit (106);
 
99
  }
 
100
  mycube.SetFileName(outfile);
 
101
  if (mycube.WriteFile()) {
 
102
    printf("[E] vb2cub: error writing file %s\n",outfile.c_str());
 
103
    exit(110);
 
104
  }
 
105
  else
 
106
    printf("[I] vb2cub: done.\n");
 
107
  exit(0);
 
108
}
 
109
 
 
110
void
 
111
vb2cub_help()
 
112
{
 
113
  cout << boost::format(myhelp) % vbversion;
 
114
}
 
115
 
 
116
void
 
117
vb2cub_version()
 
118
{
 
119
  printf("VoxBo vb2cub (v%s)\n",vbversion.c_str());
 
120
}