From 70407ea9143be076b3c5e3b24305c87de98c6256 Mon Sep 17 00:00:00 2001 From: heziqi Date: Wed, 15 Oct 2014 09:25:18 +0800 Subject: [PATCH] Ziqi completed height2heigth area2height area2area ratio --- envi/bil.h | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- envi/bip.h | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- envi/bsq.h | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- envi/envi.h | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 311 insertions(+), 91 deletions(-) diff --git a/envi/bil.h b/envi/bil.h index 88fd3d5..733c7f5 100644 --- a/envi/bil.h +++ b/envi/bil.h @@ -403,17 +403,16 @@ public: } //untested //providing the left and the right bound wavelength, return baseline-corrected band height - bool height(double lb, double rb, double bandwavelength){ + bool height(double lb, double rb, double bandwavelength, T* result){ T* lp; T* rp; - T* result; - - lp = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); //memory allocation - rp = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); - result = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); + unsigned XY = R[0] * R[1]; + unsigned S = XY * sizeof(T); + lp = (T*) malloc(S); //memory allocation + rp = (T*) malloc(S); - band(lp, lb); //get the data of the left bounbd and the right bound + band(lp, lb); band(rp, rb); baseline_band(lb, rb, lp, rp, bandwavelength, result); @@ -421,14 +420,14 @@ public: return true; } + //calculate the area between two bound point(including baseline correction) - bool area(double lb, double rb){ + bool area(double lb, double rb, double lab, double rab, T* result){ T* lp; //left band pointer T* rp; //right band pointer T* cur; //current band 1 T* cur2; //current band 2 - T* result; //area result unsigned XY = R[0] * R[1]; unsigned S = XY * sizeof(T); @@ -437,7 +436,6 @@ public: rp = (T*) malloc(S); cur = (T*) malloc(S); cur2 = (T*) malloc(S); - result = (T*) malloc(S); memset(result, (char)0, S); @@ -460,10 +458,10 @@ public: } //get the position of lb and rb - while (lb >= w[ai]){ + while (lab >= w[ai]){ ai++; } - while (rb <= w[bi]){ + while (rab <= w[bi]){ bi--; } @@ -471,13 +469,15 @@ public: band(rp, rb); //calculate the beginning and the ending part - baseline_band(lb, rb, lp, rp, w[bi], cur); //ending part + baseline_band(lb, rb, lp, rp, rab, cur2); //ending part + baseline_band(lb, rb, lp, rp, w[bi], cur); for(unsigned j = 0; j < XY; j++){ - result[j] += (rb - w[bi]) * cur[j] / 2.0; + result[j] += (rab - w[bi]) * (cur[j] + cur2[j]) / 2.0; } - baseline_band(lb, rb, lp, rp, w[ai], cur); //beginnning part + baseline_band(lb, rb, lp, rp, lab, cur2); //beginnning part + baseline_band(lb, rb, lp, rp, w[ai], cur); for(unsigned j = 0; j < XY; j++){ - result[j] += (w[ai] - lb) * cur[j] / 2.0; + result[j] += (w[ai] - lab) * (cur[j] + cur2[j]) / 2.0; } //calculate the area ai++; @@ -490,20 +490,69 @@ public: } std::swap(cur,cur2); //swap the band pointers } - ///////////////for testing use - std::ofstream text("area_result.txt",std::ios::out); - for (unsigned i = 0; i < 640; i++) - { - for (unsigned j = 0; j < 384; j++) - { - text<= w[ai]){ + while (lab >= w[ai]){ ai++; } - while (rb <= w[bi]){ + while (rab <= w[bi]){ bi--; } @@ -559,13 +556,15 @@ public: band(rp, rb); //calculate the beginning and the ending part - baseline_band(lb, rb, lp, rp, w[bi], cur); //ending part + baseline_band(lb, rb, lp, rp, rab, cur2); //ending part + baseline_band(lb, rb, lp, rp, w[bi], cur); for(unsigned j = 0; j < XY; j++){ - result[j] += (rb - w[bi]) * cur[j] / 2.0; + result[j] += (rab - w[bi]) * (cur[j] + cur2[j]) / 2.0; } - baseline_band(lb, rb, lp, rp, w[ai], cur); //beginnning part + baseline_band(lb, rb, lp, rp, lab, cur2); //beginnning part + baseline_band(lb, rb, lp, rp, w[ai], cur); for(unsigned j = 0; j < XY; j++){ - result[j] += (w[ai] - lb) * cur[j] / 2.0; + result[j] += (w[ai] - lab) * (cur[j] + cur2[j]) / 2.0; } //calculate the area ai++; @@ -578,20 +577,68 @@ public: } std::swap(cur,cur2); //swap the band pointers } - ///////////////for testing use - std::ofstream text("area_result.txt",std::ios::out); - for (unsigned i = 0; i < 640; i++) - { - for (unsigned j = 0; j < 384; j++) - { - text<= w[ai]){ + while (lab >= w[ai]){ ai++; } - while (rb <= w[bi]){ + while (rab <= w[bi]){ bi--; } @@ -394,14 +395,17 @@ public: band(rp, rb); //calculate the beginning and the ending part - baseline_band(lb, rb, lp, rp, w[bi], cur); //ending part + baseline_band(lb, rb, lp, rp, rab, cur2); //ending part + baseline_band(lb, rb, lp, rp, w[bi], cur); for(unsigned j = 0; j < XY; j++){ - result[j] += (rb - w[bi]) * cur[j] / 2.0; + result[j] += (rab - w[bi]) * (cur[j] + cur2[j]) / 2.0; } - baseline_band(lb, rb, lp, rp, w[ai], cur); //beginnning part + baseline_band(lb, rb, lp, rp, lab, cur2); //beginnning part + baseline_band(lb, rb, lp, rp, w[ai], cur); for(unsigned j = 0; j < XY; j++){ - result[j] += (w[ai] - lb) * cur[j] / 2.0; + result[j] += (w[ai] - lab) * (cur[j] + cur2[j]) / 2.0; } + //calculate the area ai++; for(unsigned i = ai; i <= bi ;i++) @@ -413,21 +417,68 @@ public: } std::swap(cur,cur2); //swap the band pointers } - ///////////////for testing use - std::ofstream text("area_result.txt",std::ios::out); - for (unsigned i = 0; i < 640; i++) - { - for (unsigned j = 0; j < 384; j++) - { - text<*)file)->area(lb, rb); + return ((bsq*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (float*)result); else if(header.data_type == envi_header::float64) - return ((bsq*)file)->area(lb, rb); + return ((bsq*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (double*)result); else std::cout<<"ERROR: unidentified data type"<*)file)->area(lb, rb); + return ((bil*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (float*)result); else if(header.data_type == envi_header::float64) - return ((bil*)file)->area(lb, rb); + return ((bil*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (double*)result); else std::cout<<"ERROR: unidentified data type"<*)file)->area(lb, rb); + return ((bip*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (float*)result); else if(header.data_type == envi_header::float64) - return ((bip*)file)->area(lb, rb); + return ((bip*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (double*)result); + else + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (float*)result); + else if(header.data_type == envi_header::float64) + return ((bsq*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (double*)result); + else + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (float*)result); + else if(header.data_type == envi_header::float64) + return ((bil*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (double*)result); + else + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (float*)result); + else if(header.data_type == envi_header::float64) + return ((bip*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (double*)result); + else + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (float*)result); + else if(header.data_type == envi_header::float64) + return ((bsq*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (double*)result); + else + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (float*)result); + else if(header.data_type == envi_header::float64) + return ((bil*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (double*)result); + else + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (float*)result); + else if(header.data_type == envi_header::float64) + return ((bip*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (double*)result); else std::cout<<"ERROR: unidentified data type"<