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

« back to all changes in this revision

Viewing changes to munge/tes2cub.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
// tes2cub.cpp
 
3
// extract a single 3D image from a TES1 file
 
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 <sstream>
 
30
#include "vbutil.h"
 
31
#include "vbio.h"
 
32
#include "tes2cub.hlp.h"
 
33
 
 
34
void tes2cub_help();
 
35
 
 
36
int
 
37
main(int argc,char *argv[])
 
38
{
 
39
  tokenlist args;
 
40
  Tes *tes;
 
41
  Cube *cub;
 
42
  int ind=0;
 
43
  stringstream tmps;
 
44
 
 
45
  args.Transfer(argc-1,argv+1);
 
46
 
 
47
  if (args.size() == 0) {
 
48
    tes2cub_help();
 
49
    exit(0);
 
50
  }
 
51
 
 
52
  if (args.size() != 2 && args.size() != 3) {
 
53
    tes2cub_help();
 
54
    exit(5);
 
55
  }
 
56
 
 
57
  if (args.size() == 3)
 
58
    ind = strtol(args[2]);
 
59
  tes = new Tes();
 
60
  if (tes->ReadFile(args[0])) {
 
61
    tmps.str("");
 
62
    tmps << "tes2cub: couldn't read tes file " << args[0];
 
63
    printErrorMsg(VB_ERROR,tmps.str());
 
64
    exit(5);
 
65
  }
 
66
  if (!tes->data_valid) {
 
67
    tmps.str("");
 
68
    tmps << "tes2cub: tes file " << args[0] << "isn't valid.";
 
69
    printErrorMsg(VB_ERROR,tmps.str());
 
70
    exit(5);
 
71
  }
 
72
  if (ind > tes->dimt) {
 
73
    tmps.str("");
 
74
    tmps << "tes2cub: index (" << ind << ") is beyond the last image (" << tes->dimt << ").";
 
75
    printErrorMsg(VB_ERROR,tmps.str());
 
76
    exit(5);
 
77
  } 
 
78
  cub = new Cube((*tes)[ind]);
 
79
  if (!cub->data_valid) {
 
80
    tmps.str("");
 
81
    tmps << "tes2cub: error extracting the cube from the 4D file (shouldn't happen!).";
 
82
    printErrorMsg(VB_ERROR,tmps.str());
 
83
    exit(5);
 
84
  } 
 
85
  if (!cub->WriteFile(args[1])) {
 
86
    tmps.str("");
 
87
    tmps << "tes2cub: wrote cube " << ind << " to file " << args[1] << ".";
 
88
    printErrorMsg(VB_INFO,tmps.str());
 
89
    exit(0);
 
90
  }
 
91
  else {
 
92
    tmps.str("");
 
93
    tmps << "tes2cub: failed to write extracted cube to file " << args[1] << ".";
 
94
    printErrorMsg(VB_INFO,tmps.str());
 
95
    exit(5);
 
96
  }
 
97
  exit(0);
 
98
}
 
99
 
 
100
void
 
101
tes2cub_help()
 
102
{
 
103
  cout << boost::format(myhelp) % vbversion;
 
104
}