Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

genhist.cpp

Go to the documentation of this file.
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/2B/2B.h"
00008 #include "Volume/Regular/Unimodal/3d/1B/1B.h"
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 != 3) {
00019         usage(argv[0]);
00020         return -1;
00021     }
00022 
00023     vuString outfileName = argv[2];
00024     vuString fileName = argv[1];
00025     vuString fileType = vuFileHelper::getFileType(fileName);
00026     vu1112 *volume = NULL;
00027     if (fileType.isEmpty()) {
00028         cout << "Error: Wrong filetype." << endl;
00029         return -1;
00030     } else if(fileType == "11121") volume = new vu11121;
00031     else if(fileType == "11122") volume = new vu11122;
00032     else {
00033         cout << "Error: Unsupported volume type " << fileType << endl;
00034         return -1;
00035     }
00036     
00037 
00038     cout << "loading" << endl;
00039     volume->setFileName(fileName);
00040     if(!((vu1*)volume)->read()) {
00041         cout << "Error: Could not load file " << fileName << "." << endl;
00042         return -1;
00043     }
00044     cout << "calculating histogram" << endl;
00045     vuHistogram hist(vuHistogram::TYPE_INTENSITY);
00046     volume->createHistogram(hist);
00047     ofstream hf(outfileName);
00048     hf << hist;
00049     hf.close();
00050     cout << "done." << endl;
00051     return 0;
00052 }
00053 
00054 void usage(const char* exe)
00055 {
00056     const char *file = strrchr(exe,'/');
00057     if(!file) 
00058     {
00059         file = strrchr(exe,'\\');
00060         if(file) file++;
00061         else file = exe;
00062     } else file++;
00063 
00064     cout << "usage:  " << file << " inputfile outputfile " 
00065          << endl << endl;
00066     cout << "inputfile      name of vud file including extension"<<endl;
00067     cout << "outputfile     name of histogram file to ouput"<<endl;
00068 }
00069 
00070 bool readnumber(const char* str, int& number)
00071 {
00072     char *endp;
00073     errno = 0;
00074     number = strtol(str,&endp,10);
00075     if(errno || 
00076        endp != str+strlen(str)) return false;
00077     return true;
00078 }
00079 

Generated on Wed Dec 15 21:20:28 2004 for vuVolume by  doxygen 1.3.9.1