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
|
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <map>
#include <rumba/arghandler.h>
#include <rumba/exception.h>
#include <rumba/parse.h>
#include <rumba/loadVols.h>
#include <rumba/manifoldmatrix.h>
#include <rumba/matrixio.h>
#include <rumba/matrix.hpp>
#include <rumba/util.hpp>
//template class std::map<std::string, RUMBA::Factory*>;
//RUMBA::Manifold<double> permute_fill(const std::vector<double> &, bool transpose = false);
using namespace RUMBA;
using RUMBA::Splodge;
using RUMBA::ManifoldFile;
using RUMBA::Argument;
using std::cerr;
using std::endl;
void usage()
{
std::cerr << "Usage: subsample -i infile -o outfile --dimensions x y z t\n";
}
RUMBA::intPoint chk_list(const std::vector<Splodge>& v)
{
RUMBA::intPoint p;
if (v.size() != 4)
throw RUMBA::Exception("Dimensions must be in form x y z t");
for ( std::vector<Splodge>::size_type i = 0; i < 4; ++i )
p[i]=v[i].asInt();
return p;
}
Argument myArgs [] = {
Argument("dimensions", RUMBA::NUMERIC, 'd', -1, true, true),
Argument()
};
int main(int argc,char** argv)
{
std::string infile , outfile;
RUMBA::intPoint dims;
RUMBA::ManifoldFile *fin, *fout;
RUMBA::intPoint ext;
try {
ArgHandler argh ( argc , argv, myArgs );
if ( argh.arg("help") )
{
usage();
exit(0);
}
argh.arg ( "infile" , infile );
argh.arg ( "outfile" , outfile );
dims = chk_list(argh.multiarg ("dimensions"));
fin = RUMBA::ManifoldFile::construct(infile.c_str());
if (!fin)
{
throw RUMBA::Exception(std::string("Couldn't open file ")+infile);
}
for ( int i = 0; i < 4; ++i )
{
ext[i] = fin->extent()[i] / dims[i];
if ( ext[i] <= 0 )
throw RUMBA::Exception("Dimensions ill-formed");
}
fout = RUMBA::ManifoldFile::construct(
outfile.c_str(),
fin->headerData()["normalized_datatype"].asString(), ext
);
if (!fout)
{
throw RUMBA::Exception(std::string("Couldn't open file ")+outfile);
}
RUMBA::downsample(dims,fin,fout);
delete fin;
delete fout;
}
catch ( RUMBA::InvalidArgumentException& s)
{
std::cerr << "Invalid argument: " << s.error() << std::endl;
}
catch (RUMBA::DuplicateArgumentException& s)
{
std::cerr << "Duplicate argument: " << s.error() << std::endl;
}
catch (RUMBA::ArgHandlerException& s)
{
std::cerr << "Error: " << s.error() << std::endl;
}
catch (RUMBA::Exception& s)
{
std::cerr << "Exception:" << s.error() << std::endl;
}
}
|