diff --git a/stim/envi/bil.h b/stim/envi/bil.h index 791af15..de68ac4 100644 --- a/stim/envi/bil.h +++ b/stim/envi/bil.h @@ -1005,7 +1005,12 @@ public: /// @param y0 is the lower-left y pixel coordinate to be included in the cropped image /// @param x1 is the upper-right x pixel coordinate to be included in the cropped image /// @param y1 is the upper-right y pixel coordinate to be included in the cropped image - bool crop(std::string outfile, unsigned x0, unsigned y0, unsigned x1, unsigned y1){ + bool crop(std::string outfile, unsigned long long x0, + unsigned long long y0, + unsigned long long x1, + unsigned long long y1, + unsigned long long b0, + unsigned long long b1){ //calculate the new number of samples and lines unsigned long long sam = x1 - x0; //samples diff --git a/stim/envi/bip.h b/stim/envi/bip.h index 88055fe..897fbe0 100644 --- a/stim/envi/bip.h +++ b/stim/envi/bip.h @@ -1061,7 +1061,12 @@ public: /// @param y0 is the lower-left y pixel coordinate to be included in the cropped image /// @param x1 is the upper-right x pixel coordinate to be included in the cropped image /// @param y1 is the upper-right y pixel coordinate to be included in the cropped image - bool crop(std::string outfile, unsigned x0, unsigned y0, unsigned x1, unsigned y1){ + bool crop(std::string outfile, unsigned long long x0, + unsigned long long y0, + unsigned long long x1, + unsigned long long y1, + unsigned long long b0, + unsigned long long b1){ //calculate the new number of samples and lines unsigned long long sam = x1 - x0; //samples diff --git a/stim/envi/bsq.h b/stim/envi/bsq.h index 299cdfd..6c2b240 100644 --- a/stim/envi/bsq.h +++ b/stim/envi/bsq.h @@ -968,27 +968,45 @@ public: /// @param y0 is the lower-left y pixel coordinate to be included in the cropped image /// @param x1 is the upper-right x pixel coordinate to be included in the cropped image /// @param y1 is the upper-right y pixel coordinate to be included in the cropped image - bool crop(std::string outfile, unsigned x0, unsigned y0, unsigned x1, unsigned y1){ - - //calculate the new number of samples and lines - unsigned long long sam = x1 - x0; //samples - unsigned long long lin = y1 - y0; //lines - unsigned long long L = sam * lin * sizeof(T); - //get specified band and save + bool crop(std::string outfile, unsigned long long x0, + unsigned long long y0, + unsigned long long x1, + unsigned long long y1, + unsigned long long b0, + unsigned long long b1){ + + //calculate the new number of samples, lines, and bands + unsigned long long samples = x1 - x0; + unsigned long long lines = y1 - y0; + unsigned long long bands = b1 - b0; + + //calculate the size of a single band + unsigned long long L = samples * lines * sizeof(T); + + //allocate space for a single band T* temp = (T*)malloc(L); + + //create an output stream to store the output file std::ofstream out(outfile.c_str(), std::ios::binary); - unsigned long long jumpb = X() * (Y() - lin) * sizeof(T); //jump pointer to the next band - unsigned long long jumpl = (X() - sam) * sizeof(T); //jump pointer to the next line - //get start - file.seekg((y0 * X() + x0) * sizeof(T), std::ios::beg); - for (unsigned z = 0; z < Z(); z++) + + //calculate the distance required to jump from the end of one band to the beginning of another + unsigned long long jumpb = X() * (Y() - lines) * sizeof(T); + + //calculate the distance required to jump from the end of one line to the beginning of another + unsigned long long jumpl = (X() - samples) * sizeof(T); + + //seek to the start of the cropped region in the input file + file.seekg( (b0 * X() * Y() + y0 * X() + x0) * sizeof(T), std::ios::beg); + + //for each band + for (unsigned long long z = b0; z < b1; z++) { - for (unsigned j = 0; j < lin; j++) + for (unsigned y = 0; y < lines; y++) { - file.read((char *)(temp + j * sam), sizeof(T) * sam); + file.read((char *)(temp + y * samples), sizeof(T) * samples); file.seekg(jumpl, std::ios::cur); //go to the next band - thread_data = (double)(z * lin + j) / (Z() * lin) * 100; + thread_data = (double)(z * lines + y) / (Z() * lines) * 100; } out.write(reinterpret_cast(temp), L); //write slice data into target file file.seekg(jumpb, std::ios::cur); diff --git a/stim/envi/envi.h b/stim/envi/envi.h index 1c27f04..e104f31 100644 --- a/stim/envi/envi.h +++ b/stim/envi/envi.h @@ -1022,13 +1022,13 @@ public: /// @param y0 is the lower-left y pixel coordinate to be included in the cropped image /// @param x1 is the upper-right x pixel coordinate to be included in the cropped image /// @param y1 is the upper-right y pixel coordinate to be included in the cropped image - bool crop(std::string outfile,unsigned x0, unsigned y0, unsigned x1, unsigned y1){ + bool crop(std::string outfile,unsigned x0, unsigned y0, unsigned x1, unsigned y1, unsigned b0, unsigned b1){ if (header.interleave == envi_header::BSQ){ if (header.data_type == envi_header::float32) - return ((bsq*)file)->crop(outfile, x0, y0, x1, y1); + return ((bsq*)file)->crop(outfile, x0, y0, x1, y1, b0, b1); else if (header.data_type == envi_header::float64) - return ((bsq*)file)->crop(outfile, x0, y0, x1, y1); + return ((bsq*)file)->crop(outfile, x0, y0, x1, y1, b0, b1); else{ std::cout << "ERROR: unidentified data type" << std::endl; exit(1); @@ -1036,9 +1036,9 @@ public: } else if (header.interleave == envi_header::BIL){ if (header.data_type == envi_header::float32) - return ((bil*)file)->crop(outfile, x0, y0, x1, y1); + return ((bil*)file)->crop(outfile, x0, y0, x1, y1, b0, b1); else if (header.data_type == envi_header::float64) - return ((bil*)file)->crop(outfile, x0, y0, x1, y1); + return ((bil*)file)->crop(outfile, x0, y0, x1, y1, b0, b1); else{ std::cout << "ERROR: unidentified data type" << std::endl; exit(1); @@ -1046,9 +1046,9 @@ public: } else if (header.interleave == envi_header::BIP){ if (header.data_type == envi_header::float32) - return ((bip*)file)->crop(outfile, x0, y0, x1, y1); + return ((bip*)file)->crop(outfile, x0, y0, x1, y1, b0, b1); else if (header.data_type == envi_header::float64) - return ((bip*)file)->crop(outfile, x0, y0, x1, y1); + return ((bip*)file)->crop(outfile, x0, y0, x1, y1, b0, b1); else{ std::cout << "ERROR: unidentified data type" << std::endl; exit(1); diff --git a/stim/parser/arguments.h b/stim/parser/arguments.h index be5ff0a..5a758f8 100644 --- a/stim/parser/arguments.h +++ b/stim/parser/arguments.h @@ -479,6 +479,14 @@ namespace stim{ return args.size(); } + /// Returns the number of options that are set + unsigned int nopts(){ + unsigned int n = 0; //initialize the counter for the number of options + for(unsigned int i = 0; i < opts.size(); i++) //go through each option + if(opts[i].is_set()) n++; //if a value is specified, increment the counter + return n; + } + ///Returns the name of an argument, given its index /// @param a is the index of the requested argument -- libgit2 0.21.4