This is an automated email from the git hooks/post-receive script. sebastic-guest pushed a commit to branch upstream-master in repository pktools.
commit f66b880de108bcd29dcee51bcbdeef1b7aab2aa2 Author: Pieter Kempeneers <kempe...@gmail.com> Date: Sat Dec 7 12:24:03 2013 +0100 replaced empty string with empty vector in options --- src/algorithms/ConfusionMatrix.cc | 19 +++++++++++++------ src/algorithms/ConfusionMatrix.h | 20 ++++++++++++++------ src/apps/pkclassify_svm.cc | 4 ++-- src/apps/pkcreatect.cc | 28 ++++++++++++++-------------- src/apps/pkcrop.cc | 12 ++++++------ src/apps/pkmosaic.cc | 4 ++-- src/apps/pkndvi.cc | 15 +++++++++------ 7 files changed, 60 insertions(+), 42 deletions(-) diff --git a/src/algorithms/ConfusionMatrix.cc b/src/algorithms/ConfusionMatrix.cc index 64b2945..f7ef7a3 100644 --- a/src/algorithms/ConfusionMatrix.cc +++ b/src/algorithms/ConfusionMatrix.cc @@ -153,8 +153,10 @@ void ConfusionMatrix::setResult(const std::string& theRef, const std::string& th } void ConfusionMatrix::incrementResult(const std::string& theRef, const std::string& theClass, double theIncrement){ - int ir=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theRef)); - int ic=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass)); + // int ir=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theRef)); + // int ic=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass)); + int ir=getClassIndex(theRef); + int ic=getClassIndex(theClass); assert(ir>=0); if(ir>=m_results.size()) std::cerr << "Error: " << theRef << " not found in class ConfusionMatrix when incrementing for class " << theClass << std::endl; @@ -165,7 +167,8 @@ void ConfusionMatrix::incrementResult(const std::string& theRef, const std::stri } double ConfusionMatrix::nReference(const std::string& theRef) const{ - int ir=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theRef)); + // int ir=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theRef)); + int ir=getClassIndex(theRef); return accumulate(m_results[ir].begin(),m_results[ir].end(),0); } @@ -177,7 +180,8 @@ double ConfusionMatrix::nReference() const{ } double ConfusionMatrix::nClassified(const std::string& theClass) const{ - int ic=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass)); + // int ic=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass)); + int ic=getClassIndex(theClass); double nclassified=0; for(int iref=0;iref<m_results.size();++iref){ assert(ic<m_results[iref].size()); @@ -190,7 +194,8 @@ double ConfusionMatrix::pa(const std::string& theClass, double* se95) const{ assert(m_results.size()); assert(m_results.size()==m_classes.size()); double producer=0; - int ir=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass)); + // int ir=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass)); + int ir=getClassIndex(theClass); assert(ir>=0); assert(ir<m_results.size()); assert(!theClass.compare(m_classes[ir])); @@ -217,8 +222,10 @@ double ConfusionMatrix::ua(const std::string& theClass, double* se95) const{ assert(m_results.size()); assert(m_results.size()==m_classes.size()); double user=0; - int ic=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass)); + // int ic=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),theClass)); + int ic=getClassIndex(theClass); assert(ic>=0); + assert(ic<m_results.size()); assert(!theClass.compare(m_classes[ic])); for(int iref=0;iref<m_results.size();++iref){ assert(ic<m_results[iref].size()); diff --git a/src/algorithms/ConfusionMatrix.h b/src/algorithms/ConfusionMatrix.h index a6ae270..4a2b22d 100644 --- a/src/algorithms/ConfusionMatrix.h +++ b/src/algorithms/ConfusionMatrix.h @@ -46,12 +46,20 @@ public: int nClasses() const {return m_classes.size();}; std::string getClass(int iclass) const {assert(iclass>=0);assert(iclass<m_classes.size());return m_classes[iclass];}; int getClassIndex(std::string className) const { - int index=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),className)); - assert(index>=0); - if(index<m_results.size()) - return(index); - else - return(-1); + int index=0; + for(index=0;index<m_classes.size();++index){ + if(m_classes[index].find(className)!=std::string::npos) + break; + } + if(index>=m_classes.size()) + index=-1; + return index; + // int index=distance(m_classes.begin(),find(m_classes.begin(),m_classes.end(),className)); + // assert(index>=0); + // if(index<m_results.size()) + // return(index); + // else + // return(-1); } std::vector<std::string> getClassNames() const {return m_classes;}; ~ConfusionMatrix(); diff --git a/src/apps/pkclassify_svm.cc b/src/apps/pkclassify_svm.cc index 2205a2b..0b62975 100644 --- a/src/apps/pkclassify_svm.cc +++ b/src/apps/pkclassify_svm.cc @@ -536,8 +536,8 @@ int main(int argc, char *argv[]) double dpa=0; double doa=0; for(short iclass=0;iclass<cm.nClasses();++iclass){ - dua=cm.ua_pct(cm.getClass(iclass),&se95_ua); - dpa=cm.pa_pct(cm.getClass(iclass),&se95_pa); + dua=cm.ua(cm.getClass(iclass),&se95_ua); + dpa=cm.pa(cm.getClass(iclass),&se95_pa); cout << cm.getClass(iclass) << " " << cm.nReference(cm.getClass(iclass)) << " " << dua << " (" << se95_ua << ")" << " " << dpa << " (" << se95_pa << ")" << endl; } std::cout << "Kappa: " << cm.kappa() << std::endl; diff --git a/src/apps/pkcreatect.cc b/src/apps/pkcreatect.cc index c880cce..19ba4d0 100644 --- a/src/apps/pkcreatect.cc +++ b/src/apps/pkcreatect.cc @@ -30,17 +30,17 @@ int main(int argc,char **argv) { short green=-1; short blue=-1; - Optionpk<string> input_opt("i", "input", "Input image file", ""); - Optionpk<string> output_opt("o", "output", "Output image file", ""); - Optionpk<string> legend_opt("l", "legend", "Create legend as png file", ""); + Optionpk<string> input_opt("i", "input", "Input image file"); + Optionpk<string> output_opt("o", "output", "Output image file"); + Optionpk<string> legend_opt("l", "legend", "Create legend as png file"); Optionpk<short> dim_opt("dim", "dim", "number of columns and rows in legend.", 100); Optionpk<double> min_opt("min", "min", "minimum value", 0); Optionpk<double> max_opt("max", "max", "maximum value", 100); Optionpk<bool> grey_opt("g", "grey", "grey scale", false); - Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", ""); + Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)"); Optionpk<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "GTiff"); Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND"); - Optionpk<string> description_opt("d", "description", "Set image description", ""); + Optionpk<string> description_opt("d", "description", "Set image description"); Optionpk<bool> verbose_opt("v", "verbose", "verbose", false); bool doProcess;//stop process when program was invoked with help option (-h --help) @@ -69,7 +69,7 @@ int main(int argc,char **argv) { GDALColorTable colorTable; GDALColorEntry sEntry; - if(colorTable_opt[0]==""){ + if(colorTable_opt.empty()){ sEntry.c4=255; for(int i=min_opt[0];i<=max_opt[0];++i){ if(grey_opt[0]){ @@ -100,14 +100,14 @@ int main(int argc,char **argv) { } } colorTable.SetColorEntry(i,&sEntry); - if(output_opt[0]=="") + if(output_opt.empty()) cout << i << " " << sEntry.c1 << " " << sEntry.c2 << " " << sEntry.c3 << " " << sEntry.c4 << endl; } } ImgWriterGdal legendWriter; short ncol=dim_opt[0]; short nrow; - if(legend_opt[0]!=""){ + if(legend_opt.size()){ if(dim_opt.size()>1) nrow=dim_opt[1]; else{ @@ -118,13 +118,13 @@ int main(int argc,char **argv) { // pngOption.push_back("-co worldfile=no"); pngOption.push_back(""); legendWriter.open(legend_opt[0],ncol,nrow,1,GDT_Byte,oformat_opt[0],option_opt); - if(colorTable_opt[0]!=""){ + if(colorTable_opt.size()){ if(colorTable_opt[0]!="none") legendWriter.setColorTable(colorTable_opt[0]); } else legendWriter.setColorTable(&colorTable); - if(legend_opt[0]!=""){ + if(legend_opt.size()){ for(int irow=0;irow<legendWriter.nrOfRow();++irow){ vector<char> buffer(legendWriter.nrOfCol()); for(int icol=0;icol<legendWriter.nrOfCol();++icol) @@ -139,7 +139,7 @@ int main(int argc,char **argv) { // GDALProgressFunc pfnProgress=GDALTermProgress; // double progress=0; // pfnProgress(progress,pszMessage,pProgressArg); - if(input_opt[0]!=""&&output_opt[0]!=""){ + if(input_opt.size()&&output_opt.size()){ ImgReaderGdal imgReader(input_opt[0]); ImgWriterGdal imgWriter; if(option_opt.findSubstring("INTERLEAVE=")==option_opt.end()){ @@ -151,13 +151,13 @@ int main(int argc,char **argv) { imgWriter.open(output_opt[0],imgReader.nrOfCol(),imgReader.nrOfRow(),1,GDT_Byte,oformat_opt[0],option_opt); imgWriter.copyGeoTransform(imgReader); - if(colorTable_opt[0]!=""){ + if(colorTable_opt.size()){ if(colorTable_opt[0]!="none") imgWriter.setColorTable(colorTable_opt[0]); } else imgWriter.setColorTable(&colorTable); - if(description_opt[0]!="") + if(description_opt.size()) imgWriter.setImageDescription(description_opt[0]); switch(imgReader.getDataType()){ case(GDT_Byte):{ @@ -192,7 +192,7 @@ int main(int argc,char **argv) { imgReader.close(); imgWriter.close(); } - if(legend_opt[0]!="") + if(legend_opt.size()) legendWriter.close(); } diff --git a/src/apps/pkcrop.cc b/src/apps/pkcrop.cc index ea95ff3..8d4ff0f 100644 --- a/src/apps/pkcrop.cc +++ b/src/apps/pkcrop.cc @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) Optionpk<string> input_opt("i", "input", "Input image file(s). If input contains multiple images, a multi-band output is created"); Optionpk<string> output_opt("o", "output", "Output image file"); Optionpk<string> projection_opt("a_srs", "a_srs", "Override the projection for the output file (leave blank to copy from input file, use epsg:3035 to use European projection and force to European grid", ""); - Optionpk<string> extent_opt("e", "extent", "get boundary from extent from polygons in vector file", ""); + Optionpk<string> extent_opt("e", "extent", "get boundary from extent from polygons in vector file"); Optionpk<bool> mask_opt("m","mask","mask values out of polygon in extent file to flag option (tip: for better performance, use gdal_rasterize -i -burn 0 -l extent extent.shp output (with output the result of pkcrop)",false); Optionpk<double> ulx_opt("ulx", "ulx", "Upper left x value bounding box (in geocoordinates if georef is true)", 0.0); Optionpk<double> uly_opt("uly", "uly", "Upper left y value bounding box (in geocoordinates if georef is true)", 0.0); @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)"); Optionpk<short> flag_opt("f", "flag", "Flag value to put in image if out of bounds.", 0); Optionpk<string> resample_opt("r", "resampling-method", "Resampling method (near: nearest neighbour, bilinear: bi-linear interpolation).", "near"); - Optionpk<string> description_opt("d", "description", "Set image description", ""); + Optionpk<string> description_opt("d", "description", "Set image description"); Optionpk<bool> verbose_opt("v", "verbose", "verbose", false); bool doProcess;//stop process when program was invoked with help option (-h --help) @@ -178,7 +178,7 @@ int main(int argc, char *argv[]) double croplry=lry_opt[0]; //get bounding box from extentReader if defined ImgReaderOgr extentReader; - if(extent_opt[0]!=""){ + if(extent_opt.size()){ for(int iextent=0;iextent<extent_opt.size();++iextent){ extentReader.open(extent_opt[iextent]); if(!(extentReader.getExtent(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))){ @@ -346,7 +346,7 @@ int main(int argc, char *argv[]) cout << errorstring << endl; exit(4); } - if(description_opt[0]!="") + if(description_opt.size()) imgWriter.setImageDescription(description_opt[0]); imgWriter.setGeoTransform(cropulx,cropuly,dx,dy,0,0); if(projection_opt[0]!=""){ @@ -439,7 +439,7 @@ int main(int argc, char *argv[]) } else{ bool valid=true; - if(mask_opt[0]&&extent_opt[0]!=""){ + if(mask_opt[0]&&extent_opt.size()){ valid=false; OGRPoint thePoint; thePoint.setX(x); @@ -532,7 +532,7 @@ int main(int argc, char *argv[]) } imgReader.close(); } - if(extent_opt[0]!=""&&mask_opt[0]){ + if(extent_opt.size()&&mask_opt[0]){ extentReader.close(); } imgWriter.close(); diff --git a/src/apps/pkmosaic.cc b/src/apps/pkmosaic.cc index 9fd8a68..0c9d3d7 100644 --- a/src/apps/pkmosaic.cc +++ b/src/apps/pkmosaic.cc @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND"); Optionpk<short> flag_opt("f", "flag", "Flag value to put in image if out of bounds.", 0); Optionpk<unsigned short> resample_opt("r", "resample", "Resampling method (0: nearest neighbour, 1: bi-linear interpolation).", 0); - Optionpk<string> description_opt("\0", "description", "Set image description", ""); + Optionpk<string> description_opt("\0", "description", "Set image description"); Optionpk<string> mrule_opt("m", "mrule", "Mosaic rule for mosaic (overwrite, maxndvi, maxband, minband, validband, mean, maxvote (only for byte images), median, sum", "overwrite"); Optionpk<int> ruleBand_opt("rb", "rband", "band index used for the rule (for ndvi, use --ruleBand=redBand --ruleBand=nirBand", 0); Optionpk<int> validBand_opt("vb", "validBand", "valid band index(es)", 0); @@ -377,7 +377,7 @@ int main(int argc, char *argv[]) catch(string error){ cout << error << endl; } - if(description_opt[0]!="") + if(description_opt.size()) imgWriter.setImageDescription(description_opt[0]); imgWriter.setGeoTransform(minULX,maxULY,dx,dy,0,0); if(projection_opt[0]!=""){ diff --git a/src/apps/pkndvi.cc b/src/apps/pkndvi.cc index 4aab3fb..6bb3250 100644 --- a/src/apps/pkndvi.cc +++ b/src/apps/pkndvi.cc @@ -28,14 +28,14 @@ using namespace std; int main(int argc, char *argv[]) { //command line options - Optionpk<string> input_opt("i","input","input image file",""); - Optionpk<string> output_opt("o","output","output image file containing ndvi",""); + Optionpk<string> input_opt("i","input","input image file"); + Optionpk<string> output_opt("o","output","output image file containing ndvi"); Optionpk<short> band_opt("b", "band", "Bands to be used for vegetation index (see rule option)", 0); Optionpk<string> rule_opt("r", "rule", "Rule for index. ndvi (b1-b0)/(b1+b0), ndvi2 (b1-b0)/(b2+b3), gvmi (b0+0.1)-(b1+0.02))/((b0+0.1)+(b1+0.02))), vari (b1-b2)/(b1+b2-b0), osavi, mcari, tcari, diff (b1-b0), scale, ratio.", "ndvi"); Optionpk<double> invalid_opt("t", "invalid", "Mask value where image is invalid.", 0); Optionpk<int> flag_opt("f", "flag", "Flag value to put in image if not valid (0)", 0); - Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", ""); - Optionpk<string> description_opt("d", "description", "Set image description", ""); + Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)"); + Optionpk<string> description_opt("d", "description", "Set image description"); Optionpk<double> minmax_opt("m", "minmax", "minimum and maximum values for ndvi (limit all values smaller/larger to min/max", 0); Optionpk<double> eps_opt("e", "eps", "epsilon, contraint division by zero", 0); Optionpk<double> scale_opt("s", "scale", "scale[0] is used for input, scale[1] is used for output: DN=scale[1]*ndvi+offset[1]", 1); @@ -73,6 +73,9 @@ int main(int argc, char *argv[]) exit(0);//help was invoked, stop processing } + assert(input_opt.size()); + assert(output_opt.size()); + if(scale_opt.size()<2){ if(input_opt.size()<2) scale_opt.push_back(1); @@ -148,7 +151,7 @@ int main(int argc, char *argv[]) } outputWriter.open(output_opt[0],inputReader[0].nrOfCol(),inputReader[0].nrOfRow(),1,theType,oformat_opt[0],option_opt); - if(description_opt[0]!="") + if(description_opt.size()) outputWriter.setImageDescription(description_opt[0]); //if input image is georeferenced, copy projection info to output image if(inputReader[0].isGeoRef()){ @@ -157,7 +160,7 @@ int main(int argc, char *argv[]) inputReader[0].getBoundingBox(ulx,uly,lrx,lry); outputWriter.copyGeoTransform(inputReader[0]); } - if(colorTable_opt[0]!=""){ + if(colorTable_opt.size()){ if(colorTable_opt[0]!="none") outputWriter.setColorTable(colorTable_opt[0]); } -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pktools.git _______________________________________________ Pkg-grass-devel mailing list Pkg-grass-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel