//Take in arguments from command line
int main(int argc,char* argv[]) {
    cout << "Volumetric Image Manipulation Tool - SCRSHA001" << endl;
    cout << "Available commands = -x -d -g " << endl;

    //Check if right amount of arguments
    if (argc >6 || argc < 4){
        cout << "Incorrect arguments passed (Not enough or too little found) " <<endl;
    }
    else { //right amount of arguments
        //Check if valid arguments
        if (string(argv[2]) == "-x" || string(argv[2]) == "-d" || string(argv[2]) == "-g"){
            cout <<"Arguments validated." <<endl;
            cout <<endl;
            //Done here as each command has the same start
            VolImage volImage = VolImage(); //Create VolImage object on stack so automatically deleted
            (volImage).readImages( string (argv[1])); //Read in all Images into vector inside VolImage
            cout << "Number of images: " << (volImage).numOfImages() <<endl;
            cout << "Number of bytes required: "<< (volImage).volImageSize() <<endl; //todo Find out how to get the number of bytes required
            cout <<endl;

            //If command is to extract
            if (string(argv[2]) == "-x"){
                cout<<"Extract option chosen"<<endl;
                //Get variables from the command line arguments
                int indexOfFile = getIntFromArgument(argv[3]);

                stringstream getOutputFileName(argv[4]);
                string outputName;
                getOutputFileName >> outputName;

                cout<< "Extracting slice "<< indexOfFile << " into file " << outputName << ".raw"<<endl;
                volImage.extract(indexOfFile,outputName);
            }
            else if (string(argv[2]) == "-d"){
Exemple #2
0
int main(int argc, char* argv[]){
    using namespace ptlmuh006;
    
    VolImage volimg;
    if(argc < 2){
        //Invalid usage
        handleInvalidArgs();
        
    }else if(argc == 2){
        //Just load data and exit        
        bool success = volimg.readImages(argv[1]);
        if(!success){
            std::cout << "Error reading in data." << std::endl;
            return 1;
        }
        
    }else{
        bool success = volimg.readImages(argv[1]);
        if(!success){
            std::cout << "Error reading in data." << std::endl;
            return 1;
        }
        
        //Handle flags        
        std::string flag = std::string(argv[2]);
        
        if(flag == "-d" && argc == 6){
            //Handle diffmap option
            
            int sliceI = std::stoi(argv[3]);
            int sliceJ = std::stoi(argv[4]);
            std::string output_prefix = argv[5];
            
            volimg.diffmap(sliceI, sliceJ, output_prefix);
            
            std::cout << "Difference-map between slice ";
            std::cout << sliceI << " and " << sliceJ;
            std::cout << " computed and written to ";
            std::cout << output_prefix << ".dat and ";
            std::cout << output_prefix << ".raw." << std::endl;
            
        }else if(flag == "-x" && argc == 5){
            //Handle extract option
        
            int slice = std::stoi(argv[3]);
            std::string output_prefix = argv[4];
            
            volimg.extract(slice, output_prefix);
            
            std::cout << "Extracted slice " << slice;
            std::cout << " and wrote it to ";
            std::cout << output_prefix << ".dat and ";
            std::cout << output_prefix << ".raw." << std::endl;
            
        }else if(flag == "-g" && argc == 5){
            //Handle row extract option
            
            int row = std::stoi(argv[3]);
            std::string output_prefix = argv[4];
            
            volimg.extractRow(row, output_prefix);
            
            std::cout << "Extracted row " << row;
            std::cout << " across all slices and wrote it to ";
            std::cout << output_prefix << ".dat and ";
            std::cout << output_prefix << ".raw." << std::endl;
            
        }else{
            //Invalid usage
            handleInvalidArgs();
        }
    }
    
    return 0;
}