File: volume-normalize.cc

package info (click to toggle)
rumba-utils 1.0.1-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,764 kB
  • ctags: 414
  • sloc: sh: 7,541; cpp: 6,037; makefile: 1,127; xml: 605; perl: 70
file content (121 lines) | stat: -rw-r--r-- 2,473 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <rumba/baseManifold.h>
#include <rumba/manifoldFile.h>
#include <rumba/arghandler.h>
#include <rumba/util.hpp>
#include <rumba/parse.h>
#include <rumba/matrixio.h>
#include <iostream>
#include <cstdlib>
#include <algorithm>

using std::cout;
using std::endl;

using RUMBA::Argument;

Argument myArgs [] = {
	Argument ( "lower", RUMBA::NUMERIC, 'l', 0 ),
	Argument ("upper", RUMBA::NUMERIC, 'u', 0 ),
	Argument()
};

void help_message()
{	
	std::cerr << "Usage: volume-normalize\n"
	   	"[-i|--infile] infile [-o|--outfile] outfile\n"
		"[[--lower|-l] lower] (default: 0)\n"
		"[[--upper|-u] upper]  (default: 100)\n" << std::endl;
}



int main(int argc, char** argv)
{
	RUMBA::ArgHandler::setRequiredDefaultArg("infile");
	RUMBA::ArgHandler::setRequiredDefaultArg("outfile");
	bool help;
	double tmp1,tmp2;
	double lower = 0, upper = 100;
	try 
	{
		RUMBA::ArgHandler argh(argc,argv,myArgs);
		std::string infile, outfile;

		help = argh.arg ("help");

		if ( help )
		{
			help_message();
			exit(0);
		}

		argh.arg("infile", infile );
		argh.arg("outfile", outfile );
		argh.arg("lower",lower);
		argh.arg("upper",upper );
//		argh.arg("savestats",savestats);


	
		RUMBA::ManifoldFile* inManifold;
		RUMBA::BaseManifold* volume;
		RUMBA::ManifoldFile* outManifold;


		RUMBA::Manifold<double> stats;

		inManifold= RUMBA::ManifoldFile::construct(infile.c_str());
		if (!inManifold)
		{
			cout << "Fatal: can't identify file type" << endl;
			exit (1);
		}

		outManifold = RUMBA::ManifoldFile::construct ( outfile, std::ios::out, inManifold );

		for ( int i = 0; i < inManifold->timepoints(); ++i )
		{
			volume = inManifold->get 
				( 
					RUMBA::intPoint(0,0,0,i),
					RUMBA::intPoint(
						inManifold->width(),
						inManifold->height(),
						inManifold->depth(),
						1
					)
				);
			
			RUMBA::normalize ( lower, upper, volume );
			outManifold->put ( volume, RUMBA::intPoint(0,0,0,i));

			delete volume;
		}

		delete inManifold;
		delete outManifold;

	}

    catch (RUMBA::MissingArgumentException& s)
    {
		cout << "Error, missing required argument: " << s.error() << endl;
		help_message();
	}
    catch (RUMBA::DuplicateArgumentException& s)
    {
		cout << "Duplicate argument: " << s.error() << endl;
		help_message();
	}
	catch (RUMBA::ArgHandlerException& s)
	{
		cout << "Error: " << s.error() << endl;
		help_message();
	}
	catch ( RUMBA::Exception & e)
	{
		cout << "Fatal exception " << e.error() << endl;	
	}

	return 0;
}