00001 #include <iostream>
00002 #include <fstream>
00003 #include <unistd.h>
00004 #include <errno.h>
00005 #include <stdlib.h>
00006 #include "vuFileHelper.h"
00007 #include "Volume/Regular/Unimodal/3d/1B/1B.h"
00008
00009 #include "vuHistogram.h"
00010
00011 using namespace std;
00012
00013 void usage(const char* exe);
00014 bool readnumber(const char* str, int& number);
00015
00016 int main(int argc, char ** argv)
00017 {
00018 if(argc != 9) {
00019 usage(argv[0]);
00020 return -1;
00021 }
00022
00023 vuString fileName = argv[1];
00024 vuString fileType = vuFileHelper::getFileType(fileName);
00025 if (fileType.isEmpty()) {
00026 cout << "Error: Wrong filetype." << endl;
00027 return -1;
00028 }
00029
00030 vuString outfileName = argv[2];
00031
00032 word cube[6];
00033 int i;
00034 for(i=0; i<6; i++)
00035 {
00036 int number;
00037 if(!readnumber(argv[i+3], number)) {
00038 usage(argv[0]);
00039 return false;
00040 }
00041 cube[i] = (word)number;
00042 }
00043 cout << "loading" << endl;
00044 vu11121 volume;
00045 volume.setFileName(fileName);
00046 if(!volume.read()) {
00047 cout << "Error: Could not load file " << fileName << "." << endl;
00048 return -1;
00049 }
00050 vu11121 cropvol;
00051 cropvol.cropFrom(volume, cube);
00052 cropvol.setFileName(outfileName);
00053 cout << "writing file " << cropvol.getFileName() << endl;
00054 cropvol.write();
00055
00056 cout << "done." << endl;
00057 return 0;
00058 }
00059
00060 void usage(const char* exe)
00061 {
00062 const char *file = strrchr(exe,'/');
00063 if(!file)
00064 {
00065 file = strrchr(exe,'\\');
00066 if(file) file++;
00067 else file = exe;
00068 } else file++;
00069
00070 cout << "usage: " << file << " inputfile outputfile x0 x1 y0 y1 z0 z1"
00071 << endl << endl;
00072 cout << "inputfile name of vud file including extension"<<endl;
00073 cout << "outputfile name of histogram file to ouput"<<endl;
00074 cout << "six numbers start and end for each dimension" << endl;
00075 }
00076
00077 bool readnumber(const char* str, int& number)
00078 {
00079 char *endp;
00080 errno = 0;
00081 number = strtol(str,&endp,10);
00082 if(errno ||
00083 endp != str+strlen(str)) return false;
00084 return true;
00085 }
00086