[pktools] 193/375: porting to windows via Visual Studio 2010 Express using git for windows

Bas Couwenberg sebastic at xs4all.nl
Wed Dec 3 21:54:13 UTC 2014


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 701e2c702d90cf0780b3614bfc37d9f108ee938f
Author: Pieter Kempeneers <pieter.kempeneers at vito.be>
Date:   Mon Mar 10 17:14:47 2014 +0100

    porting to windows via Visual Studio 2010 Express using git for windows
---
 src/algorithms/Egcs.cc           |   6 +-
 src/algorithms/Egcs.h            |   4 +-
 src/algorithms/FeatureSelector.h |   4 +-
 src/algorithms/Filter.h          |  12 +-
 src/algorithms/Filter2d.cc       |  20 ++--
 src/algorithms/Filter2d.h        |  28 ++---
 src/algorithms/StatFactory.h     |  73 ++++++------
 src/algorithms/myfann_cpp.h      |   2 +-
 src/apps/pkascii2img.cc          |   2 +-
 src/apps/pkclassify_nn.cc        |  15 ++-
 src/apps/pkclassify_svm.cc       |   5 +
 src/apps/pkcrop.cc               |   2 +-
 src/apps/pkdiff.cc               |   2 +-
 src/apps/pkdumpimg.cc            |   2 +-
 src/apps/pkextract.cc            | 232 +++++++++++----------------------------
 src/apps/pkfilterascii.cc        |  32 +++---
 src/apps/pkfs_nn.cc              |  21 ++--
 src/apps/pkfs_svm.cc             |  10 +-
 src/apps/pkinfo.cc               |   4 +-
 src/apps/pkmosaic.cc             |   2 +-
 src/apps/pkopt_svm.cc            |  10 +-
 src/apps/pkregression_nn.cc      |   3 +-
 src/apps/pksieve.cc              |  21 ++--
 src/apps/pkstatascii.cc          |  70 ++++++++++--
 src/base/Makefile.am             |   2 +-
 src/base/Optionpk.h              | 107 ++----------------
 src/base/Vector2d.h              |   4 +-
 27 files changed, 280 insertions(+), 415 deletions(-)

diff --git a/src/algorithms/Egcs.cc b/src/algorithms/Egcs.cc
index ddbf20b..9810875 100644
--- a/src/algorithms/Egcs.cc
+++ b/src/algorithms/Egcs.cc
@@ -57,14 +57,14 @@ Egcs::~Egcs(){
 }
 
 unsigned short Egcs::res2level(double resolution) const{
-  double base=pow(10,log(resolution*4)/log(10));
+  double base=pow(10,log(resolution*4.0)/log(10.0));
   double diff=base/(2*resolution);
-  return 0.5+(log(base)/log(10)*3+1-diff);
+  return 0.5+(log(base)/log(10.0)*3+1-diff);
 }
 
 double Egcs::getResolution() const{
   unsigned short exponent=(m_level+1)/3;
-  double base=pow(10,exponent);
+  double base=pow(10.0,exponent);
   if((m_level)%3==2)
     return(base/4);
   else if((m_level)%3==0)
diff --git a/src/algorithms/Egcs.h b/src/algorithms/Egcs.h
index d1fdafd..8bf5e2b 100644
--- a/src/algorithms/Egcs.h
+++ b/src/algorithms/Egcs.h
@@ -32,7 +32,7 @@ public:
   ~Egcs();
   unsigned short cell2level(const std::string& cellCode) const;
   std::string geo2cell(double x, double y) const;
-  double getSize() const {return getBaseSize()*pow(2,(m_level-19)%3);};
+  double getSize() const {return getBaseSize()*pow(2.0,(m_level-19)%3);};
   void setLevel(unsigned short level){m_level=level;};
   unsigned short getLevel() const{return m_level;};
   unsigned short res2level(double resolution) const;
@@ -41,7 +41,7 @@ public:
   void cell2bb(const std::string& cellCode, int &ulx, int &uly, int &lrx, int &lry) const;
   void cell2mid(const std::string& cellCode, double& midX, double& midY) const;
 private:
-  int getBaseSize() const {return pow(10,(m_level+1)/3);};
+  int getBaseSize() const {return pow(10.0,(m_level+1)/3);};
   unsigned short m_level;
 // level square scheme         example
 // 19    1000km xy             32
diff --git a/src/algorithms/FeatureSelector.h b/src/algorithms/FeatureSelector.h
index fafd98a..b57771e 100644
--- a/src/algorithms/FeatureSelector.h
+++ b/src/algorithms/FeatureSelector.h
@@ -26,8 +26,8 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include <algorithm>
 #include <iostream>
 #include <iomanip>
-#include "IndexValue.h"
-#include "Vector2d.h"
+#include "base/IndexValue.h"
+#include "base/Vector2d.h"
 #include "gsl/gsl_combination.h"
 
 class FeatureSelector
diff --git a/src/algorithms/Filter.h b/src/algorithms/Filter.h
index d843ded..3cdab8e 100644
--- a/src/algorithms/Filter.h
+++ b/src/algorithms/Filter.h
@@ -486,10 +486,10 @@ template<class T> void Filter::morphology(const std::vector<T>& input, std::vect
     }
     switch(getFilterType(method)){
     case(filter::dilate):
-      output[(i-offset+down-1)/down]=stat.max(statBuffer);
+      output[(i-offset+down-1)/down]=stat.mymax(statBuffer);
       break;
     case(filter::erode):
-      output[(i-offset+down-1)/down]=stat.min(statBuffer);
+      output[(i-offset+down-1)/down]=stat.mymin(statBuffer);
       break;
     default:
       std::string errorString="method not supported";
@@ -526,10 +526,10 @@ template<class T> void Filter::morphology(const std::vector<T>& input, std::vect
     }
     switch(getFilterType(method)){
     case(filter::dilate):
-      output[(i-offset+down-1)/down]=stat.max(statBuffer);
+      output[(i-offset+down-1)/down]=stat.mymax(statBuffer);
       break;
     case(filter::erode):
-      output[(i-offset+down-1)/down]=stat.min(statBuffer);
+      output[(i-offset+down-1)/down]=stat.mymin(statBuffer);
       break;
     default:
       std::string errorString="method not supported";
@@ -580,10 +580,10 @@ template<class T> void Filter::morphology(const std::vector<T>& input, std::vect
     }
     switch(getFilterType(method)){
     case(filter::dilate):
-      output[(i-offset+down-1)/down]=stat.max(statBuffer);
+      output[(i-offset+down-1)/down]=stat.mymax(statBuffer);
       break;
     case(filter::erode):
-      output[(i-offset+down-1)/down]=stat.min(statBuffer);
+      output[(i-offset+down-1)/down]=stat.mymin(statBuffer);
       break;
     default:
       std::string errorString="method not supported";
diff --git a/src/algorithms/Filter2d.cc b/src/algorithms/Filter2d.cc
index 5fc341e..8cf0db0 100644
--- a/src/algorithms/Filter2d.cc
+++ b/src/algorithms/Filter2d.cc
@@ -378,7 +378,6 @@ void filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output,
       ++indexJ;
     }
     for(int y=0;y<input.nrOfRow();++y){
-    // for(int y=0;y<input.nrOfRow()+down;++y){
       if(y){//inBuffer already initialized for y=0
 	//erase first line from inBuffer
 	inBuffer.erase(inBuffer.begin());
@@ -404,7 +403,6 @@ void filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output,
       if((y+1+down/2)%down)
         continue;
       for(int x=0;x<input.nrOfCol();++x){
-      // for(int x=0;x<input.nrOfCol()+down;++x){
         if((x+1+down/2)%down)
           continue;
 	outBuffer[x/down]=0;
@@ -481,14 +479,14 @@ void filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output,
           if(windowBuffer.empty())
             outBuffer[x/down]=(m_noDataValues.size())? m_noDataValues[0] : 0;
           else
-           outBuffer[x/down]=stat.min(windowBuffer);
+           outBuffer[x/down]=stat.mymin(windowBuffer);
           break;
         }
         case(filter2d::ismin):{
            if(windowBuffer.empty())
             outBuffer[x/down]=(m_noDataValues.size())? m_noDataValues[0] : 0;
           else
-            outBuffer[x/down]=(stat.min(windowBuffer)==windowBuffer[centre])? 1:0;
+            outBuffer[x/down]=(stat.mymin(windowBuffer)==windowBuffer[centre])? 1:0;
           break;
         }
         case(filter2d::minmax):{//is the same as homog?
@@ -509,14 +507,14 @@ void filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output,
           if(windowBuffer.empty())
             outBuffer[x/down]=(m_noDataValues.size())? m_noDataValues[0] : 0;
           else
-            outBuffer[x/down]=stat.max(windowBuffer);
+            outBuffer[x/down]=stat.mymax(windowBuffer);
           break;
         }
         case(filter2d::ismax):{
           if(windowBuffer.empty())
             outBuffer[x/down]=(m_noDataValues.size())? m_noDataValues[0] : 0;
           else
-            outBuffer[x/down]=(stat.max(windowBuffer)==windowBuffer[centre])? 1:0;
+            outBuffer[x/down]=(stat.mymax(windowBuffer)==windowBuffer[centre])? 1:0;
           break;
         }
         case(filter2d::order):{
@@ -525,8 +523,8 @@ void filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output,
           else{
             double lbound=0;
             double ubound=dimX*dimY;
-            double theMin=stat.min(windowBuffer);
-            double theMax=stat.max(windowBuffer);
+            double theMin=stat.mymin(windowBuffer);
+            double theMax=stat.mymax(windowBuffer);
             double scale=(ubound-lbound)/(theMax-theMin);
             outBuffer[x/down]=static_cast<short>(scale*(windowBuffer[centre]-theMin)+lbound);
           }
@@ -1074,10 +1072,10 @@ void filter2d::Filter2d::morphology(const ImgReaderGdal& input, ImgWriterGdal& o
 	  if(statBuffer.size()){
             switch(getFilterType(method)){
             case(filter2d::dilate):
-              outBuffer[x]=stat.max(statBuffer);
+              outBuffer[x]=stat.mymax(statBuffer);
               break;
             case(filter2d::erode):
-              outBuffer[x]=stat.min(statBuffer);
+              outBuffer[x]=stat.mymin(statBuffer);
               break;
             default:
               std::ostringstream ess;
@@ -1170,7 +1168,7 @@ void filter2d::Filter2d::linearFeature(const Vector2d<float>& input, std::vector
   for(int iband=0;iband<output.size();++iband)
     output[iband].resize(input.nRows(),input.nCols());
   if(maxDistance<=0)
-    maxDistance=sqrt(input.nRows()*input.nCols());
+    maxDistance=sqrt(static_cast<float>(input.nRows()*input.nCols()));
   int indexI=0;
   int indexJ=0;
   const char* pszMessage;
diff --git a/src/algorithms/Filter2d.h b/src/algorithms/Filter2d.h
index bbb2af5..8d3717c 100644
--- a/src/algorithms/Filter2d.h
+++ b/src/algorithms/Filter2d.h
@@ -33,6 +33,7 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #endif
 
 #ifdef WIN32
+#include <process.h>
 #define getpid _getpid
 #endif
 
@@ -119,7 +120,7 @@ public:
   void shadowDsm(const ImgReaderGdal& input, ImgWriterGdal& output, double sza, double saa, double pixelSize, short shadowFlag=1);
   void dwt_texture(const std::string& inputFilename, const std::string& outputFilename,int dim, int scale, int down=1, int iband=0, bool verbose=false);
   void shift(const ImgReaderGdal& input, ImgWriterGdal& output, double offsetX=0, double offsetY=0, double randomSigma=0, RESAMPLE resample=BILINEAR, bool verbose=false);
-  template<class T> void shift(const Vector2d<T>& input, Vector2d<T>& output, double offsetX=0, double offsetY=0, double randomSigma=0, RESAMPLE resample=0, bool verbose=false);
+  template<class T> void shift(const Vector2d<T>& input, Vector2d<T>& output, double offsetX=0, double offsetY=0, double randomSigma=0, RESAMPLE resample=NEAR, bool verbose=false);
   void linearFeature(const Vector2d<float>& input, std::vector< Vector2d<float> >& output, float angle=361, float angleStep=1, float maxDistance=0, float eps=0, bool l1=true, bool a1=true, bool l2=true, bool a2=true, bool verbose=false);
   void linearFeature(const ImgReaderGdal& input, ImgWriterGdal& output, float angle=361, float angleStep=1, float maxDistance=0, float eps=0, bool l1=true, bool a1=true, bool l2=true, bool a2=true, int band=0, bool verbose=false);
   
@@ -362,14 +363,14 @@ template<class T1, class T2> void Filter2d::doit(const Vector2d<T1>& inputVector
         if(windowBuffer.empty())
           outBuffer[x/down]=noDataValue;
         else
-          outBuffer[x/down]=stat.min(windowBuffer);
+          outBuffer[x/down]=stat.mymin(windowBuffer);
         break;
       }
       case(filter2d::ismin):{
         if(windowBuffer.empty())
           outBuffer[x/down]=noDataValue;
         else
-          outBuffer[x/down]=(stat.min(windowBuffer)==windowBuffer[centre])? 1:0;
+          outBuffer[x/down]=(stat.mymin(windowBuffer)==windowBuffer[centre])? 1:0;
         break;
       }
       case(filter2d::minmax):{
@@ -390,14 +391,14 @@ template<class T1, class T2> void Filter2d::doit(const Vector2d<T1>& inputVector
         if(windowBuffer.empty())
           outBuffer[x/down]=noDataValue;
         else
-          outBuffer[x/down]=stat.max(windowBuffer);
+          outBuffer[x/down]=stat.mymax(windowBuffer);
         break;
       }
       case(filter2d::ismax):{
         if(windowBuffer.empty())
           outBuffer[x/down]=noDataValue;
         else
-          outBuffer[x/down]=(stat.max(windowBuffer)==windowBuffer[centre])? 1:0;
+          outBuffer[x/down]=(stat.mymax(windowBuffer)==windowBuffer[centre])? 1:0;
         break;
       }
       case(filter2d::order):{
@@ -406,8 +407,8 @@ template<class T1, class T2> void Filter2d::doit(const Vector2d<T1>& inputVector
         else{
           double lbound=0;
           double ubound=dimX*dimY;
-          double theMin=stat.min(windowBuffer);
-          double theMax=stat.max(windowBuffer);
+          double theMin=stat.mymin(windowBuffer);
+          double theMax=stat.mymax(windowBuffer);
           double scale=(ubound-lbound)/(theMax-theMin);
           outBuffer[x/down]=static_cast<short>(scale*(windowBuffer[centre]-theMin)+lbound);
         }
@@ -711,14 +712,14 @@ template<class T> unsigned long int Filter2d::morphology(const Vector2d<T>& inpu
         if(statBuffer.size()){
           switch(getFilterType(method)){
           case(filter2d::dilate):
-            if(output[y][x]<stat.max(statBuffer)-hThreshold){
-              output[y][x]=stat.max(statBuffer);
+            if(output[y][x]<stat.mymax(statBuffer)-hThreshold){
+              output[y][x]=stat.mymax(statBuffer);
               ++nchange;
             }
             break;
           case(filter2d::erode):
-            if(output[y][x]>stat.min(statBuffer)+hThreshold){
-              output[y][x]=stat.min(statBuffer);
+            if(output[y][x]>stat.mymin(statBuffer)+hThreshold){
+              output[y][x]=stat.mymin(statBuffer);
               ++nchange;
             }
             break;
@@ -805,8 +806,7 @@ template<class T> void Filter2d::dwtForward(Vector2d<T>& theBuffer, const std::s
     while(theBuffer[irow].size()&(theBuffer[irow].size()-1))
       theBuffer[irow].push_back(theBuffer[irow].back());
   std::vector<double> vdata(theBuffer.size()*theBuffer[0].size());
-  double *data=&(vdata[0]);
-  //double data[theBuffer.size()*theBuffer[0].size()];
+  double* data=&(vdata[0]);
   for(int irow=0;irow<theBuffer.size();++irow){
     for(int icol=0;icol<theBuffer[0].size();++icol){
       int index=irow*theBuffer[0].size()+icol;
@@ -853,7 +853,7 @@ template<class T> void Filter2d::dwtInverse(Vector2d<T>& theBuffer, const std::s
     while(theBuffer[irow].size()&(theBuffer[irow].size()-1))
       theBuffer[irow].push_back(theBuffer[irow].back());
   std::vector<double> vdata(theBuffer.size()*theBuffer[0].size());
-  double *data=&(vdata[0]);
+  double* data=&(vdata[0]);
   //double data[theBuffer.size()*theBuffer[0].size()];
   for(int irow=0;irow<theBuffer.size();++irow){
     for(int icol=0;icol<theBuffer[0].size();++icol){
diff --git a/src/algorithms/StatFactory.h b/src/algorithms/StatFactory.h
index d4b972c..bf2e602 100644
--- a/src/algorithms/StatFactory.h
+++ b/src/algorithms/StatFactory.h
@@ -135,21 +135,24 @@ public:
     }
     return randValue;
   };
-  template<class T> T min(const std::vector<T>& v) const;
-  template<class T> T max(const std::vector<T>& v) const;
-  template<class T> T min(const std::vector<T>& v, T minConstraint) const;
-  template<class T> T max(const std::vector<T>& v, T maxConstraint) const;
-//   template<class T> typename std::vector<T>::const_iterator max(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const;
-  template<class T> typename std::vector<T>::const_iterator min(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const;
-  template<class T> typename std::vector<T>::iterator min(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end) const;
-  template<class T> typename std::vector<T>::const_iterator min(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end, T minConstraint) const;
-  template<class T> typename std::vector<T>::iterator min(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end, T minConstraint) const;
-  template<class T> typename std::vector<T>::const_iterator max(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const;
-  template<class T> typename std::vector<T>::iterator max(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end) const;
-  template<class T> typename std::vector<T>::const_iterator max(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end, T maxConstraint) const;
-  template<class T> typename std::vector<T>::iterator max(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end, T maxConstraint) const;
+  
+
+  template<class T> T mymin(const typename std::vector<T>& v) const;
+  template<class T> T mymax(const typename std::vector<T>& v) const;
+  template<class T> T mymin(const typename std::vector<T>& v, typename T minConstraint) const;
+  template<class T> T mymax(const typename std::vector<T>& v, typename T maxConstraint) const;
+//   template<class T> typename std::vector<T>::const_iterator mymax(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const;
+  template<class T> typename std::vector<T>::const_iterator mymin(const typename std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const;
+  template<class T> typename std::vector<T>::iterator mymin(const typename std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end) const;
+  template<class T> typename std::vector<T>::const_iterator mymin(const typename std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end, typename T minConstraint) const;
+  template<class T> typename std::vector<T>::iterator mymin(const typename std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end, typename T minConstraint) const;
+  template<class T> typename std::vector<T>::const_iterator mymax(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const;
+  template<class T> typename std::vector<T>::iterator mymax(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end) const;
+  template<class T> typename std::vector<T>::const_iterator mymax(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end, T maxConstraint) const;
+  template<class T> typename std::vector<T>::iterator mymax(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end, T maxConstraint) const;
   template<class T> typename std::vector<T>::const_iterator absmin(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const;
   template<class T> typename std::vector<T>::const_iterator absmax(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const;
+  
   template<class T> void minmax(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end, T& theMin, T& theMax) const;  
   template<class T> T sum(const std::vector<T>& v) const;
   template<class T> double mean(const std::vector<T>& v) const;
@@ -172,7 +175,6 @@ public:
   template<class T> void normalize(const std::vector<T>& input, std::vector<double>& output) const;
   template<class T> void normalize_pct(std::vector<T>& input) const;
   template<class T> double rmse(const std::vector<T>& x, const std::vector<T>& y) const;
-  template<class T> double rrmse(const std::vector<T>& x, const std::vector<T>& y) const;
   template<class T> double correlation(const std::vector<T>& x, const std::vector<T>& y, int delay=0) const;
   template<class T> double cross_correlation(const std::vector<T>& x, const std::vector<T>& y, int maxdelay, std::vector<T>& z) const;
   template<class T> double linear_regression(const std::vector<T>& x, const std::vector<T>& y, double &c0, double &c1) const;
@@ -204,7 +206,7 @@ private:
 };
 
 
-template<class T> inline typename std::vector<T>::const_iterator StatFactory::min(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const
+template<class T> inline typename std::vector<T>::const_iterator StatFactory::mymin(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const
 {
   typename std::vector<T>::const_iterator tmpIt=begin;
   for (typename std::vector<T>::const_iterator it = begin; it!=end; ++it){
@@ -215,7 +217,7 @@ template<class T> inline typename std::vector<T>::const_iterator StatFactory::mi
   return tmpIt;
 }
 
-template<class T> inline typename std::vector<T>::iterator StatFactory::min(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end) const
+template<class T> inline typename std::vector<T>::iterator StatFactory::mymin(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end) const
 {
   typename std::vector<T>::iterator tmpIt=begin;
   for (typename std::vector<T>::const_iterator it = begin; it!=end; ++it){
@@ -226,7 +228,7 @@ template<class T> inline typename std::vector<T>::iterator StatFactory::min(cons
   return tmpIt;
 }
 
-template<class T> inline  typename std::vector<T>::const_iterator StatFactory::min(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end, T minConstraint) const
+template<class T> inline  typename std::vector<T>::const_iterator StatFactory::mymin(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end, T minConstraint) const
 {
   typename std::vector<T>::const_iterator tmpIt=v.end();
   T minValue=minConstraint;
@@ -241,7 +243,7 @@ template<class T> inline  typename std::vector<T>::const_iterator StatFactory::m
   return tmpIt;
 }
 
-template<class T> inline typename std::vector<T>::iterator StatFactory::min(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end, T minConstraint) const
+template<class T> inline typename std::vector<T>::iterator StatFactory::mymin(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end, T minConstraint) const
 {
   typename std::vector<T>::iterator tmpIt=v.end();
   T minValue=minConstraint;
@@ -256,7 +258,7 @@ template<class T> inline typename std::vector<T>::iterator StatFactory::min(cons
   return tmpIt;
 }
 
-template<class T> inline typename std::vector<T>::const_iterator StatFactory::max(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const
+template<class T> inline typename std::vector<T>::const_iterator StatFactory::mymax(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end) const
 {
   typename std::vector<T>::const_iterator tmpIt=begin;
   for (typename std::vector<T>::iterator it = begin; it!=end; ++it){
@@ -268,7 +270,7 @@ template<class T> inline typename std::vector<T>::const_iterator StatFactory::ma
   return tmpIt;
 }
 
-template<class T> inline typename std::vector<T>::iterator StatFactory::max(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end) const
+template<class T> inline typename std::vector<T>::iterator StatFactory::mymax(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end) const
 {
   typename std::vector<T>::iterator tmpIt=begin;
   for (typename std::vector<T>::iterator it = begin; it!=end; ++it){
@@ -280,7 +282,7 @@ template<class T> inline typename std::vector<T>::iterator StatFactory::max(cons
   return tmpIt;
 }
 
-template<class T> inline typename std::vector<T>::const_iterator StatFactory::max(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end, T maxConstraint) const
+template<class T> inline typename std::vector<T>::const_iterator StatFactory::mymax(const std::vector<T>& v, typename std::vector<T>::const_iterator begin, typename std::vector<T>::const_iterator end, T maxConstraint) const
 {
   typename std::vector<T>::const_iterator tmpIt=v.end();
   T maxValue=maxConstraint;
@@ -295,7 +297,7 @@ template<class T> inline typename std::vector<T>::const_iterator StatFactory::ma
   return tmpIt;
 }
 
-template<class T> inline typename std::vector<T>::iterator StatFactory::max(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end, T maxConstraint) const
+template<class T> inline typename std::vector<T>::iterator StatFactory::mymax(const std::vector<T>& v, typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end, T maxConstraint) const
 {
   typename std::vector<T>::iterator tmpIt=v.end();
   T maxValue=maxConstraint;
@@ -313,7 +315,7 @@ template<class T> inline typename std::vector<T>::iterator StatFactory::max(cons
 
 
 
-template<class T> inline T StatFactory::min(const std::vector<T>& v) const
+template<class T> inline typename T StatFactory::mymin(const std::vector<T>& v) const
 {
   T minValue=*(v.begin());
   for (typename std::vector<T>::const_iterator it = v.begin(); it!=v.end(); ++it){
@@ -325,7 +327,7 @@ template<class T> inline T StatFactory::min(const std::vector<T>& v) const
   return minValue;
 }
 
- template<class T> inline T StatFactory::min(const std::vector<T>& v, T minConstraint) const
+ template<class T> inline typename T StatFactory::mymin(const std::vector<T>& v, T minConstraint) const
 {
   T minValue=minConstraint;
   for (typename std::vector<T>::const_iterator it = v.begin(); it!=v.end(); ++it){
@@ -335,7 +337,7 @@ template<class T> inline T StatFactory::min(const std::vector<T>& v) const
   return minValue;
 }
 
-template<class T> inline T StatFactory::max(const std::vector<T>& v) const
+template<class T> inline T StatFactory::mymax(const std::vector<T>& v) const
 {
   T maxValue=*(v.begin());
   for (typename std::vector<T>::const_iterator it = v.begin(); it!=v.end(); ++it){
@@ -347,7 +349,7 @@ template<class T> inline T StatFactory::max(const std::vector<T>& v) const
   return maxValue;
 }
 
-template<class T> inline T StatFactory::max(const std::vector<T>& v, T maxConstraint) const
+template<class T> inline T StatFactory::mymax(const std::vector<T>& v, T maxConstraint) const
 {
   T maxValue=maxConstraint;
   for (typename std::vector<T>::const_iterator it = v.begin(); it!=v.end(); ++it){
@@ -562,8 +564,8 @@ template<class T> void StatFactory::meanVar(const std::vector<T>& v, double& m1,
 template<class T1, class T2> void StatFactory::scale2byte(const std::vector<T1>& input, std::vector<T2>& output, unsigned char lbound,  unsigned char ubound) const
 {
   output.resize(input.size());
-  T1 minimum=min(input);
-  T1 maximum=max(input);
+  T1 minimum=mymin(input);
+  T1 maximum=mymax(input);
   assert(maximum>minimum);
   double scale=(ubound-lbound)/(maximum-minimum);
   for (int i=0;i<input.size();++i)
@@ -620,7 +622,7 @@ template<class T> void  StatFactory::distribution(const std::vector<T>& input, t
       if(*it==maximum)
         theBin=nbin-1;
       else if(*it>minimum && *it<maximum)
-        theBin=static_cast<int>(static_cast<double>((nbin-1)*(*it-minimum)/(maximum-minimum)));
+        theBin=static_cast<int>(static_cast<double>((nbin-1)*(*it)-minimum)/(maximum-minimum));
       ++output[theBin];
       // if(*it==maximum)
       //   ++output[nbin-1];
@@ -828,19 +830,6 @@ template<class T> double StatFactory::rmse(const std::vector<T>& x, const std::v
   return sqrt(mse);
 }
 
-template<class T> double StatFactory::rrmse(const std::vector<T>& x, const std::vector<T>& y) const{
-  assert(x.size()==y.size());
-  assert(x.size());
-  double mse=0;
-  for(int isample=0;isample<x.size();++isample){
-    if(x[isample]==0)
-      continue;
-    double e=(x[isample]-y[isample])/x[isample];
-    mse+=e*e/x.size();
-  }
-  return sqrt(mse);
-}
-
 template<class T> double StatFactory::correlation(const std::vector<T>& x, const std::vector<T>& y, int delay) const{
   double meanX=0;
   double meanY=0;
diff --git a/src/algorithms/myfann_cpp.h b/src/algorithms/myfann_cpp.h
index e3d4005..7938379 100644
--- a/src/algorithms/myfann_cpp.h
+++ b/src/algorithms/myfann_cpp.h
@@ -89,7 +89,7 @@
 #include <string>
 #include <vector>
 #include <cassert>
-#include "Vector2d.h"
+#include "base/Vector2d.h"
 
 /* Namespace: FANN
     The FANN namespace groups the C++ wrapper definitions */
diff --git a/src/apps/pkascii2img.cc b/src/apps/pkascii2img.cc
index 82a10bb..57bf31c 100644
--- a/src/apps/pkascii2img.cc
+++ b/src/apps/pkascii2img.cc
@@ -19,7 +19,7 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************/
 #include <string>
 #include <fstream>
-#include "Optionpk.h"
+#include "base/Optionpk.h"
 #include <assert.h>
 #include "imageclasses/ImgWriterGdal.h"
 
diff --git a/src/apps/pkclassify_nn.cc b/src/apps/pkclassify_nn.cc
index 3fadf15..01337ad 100644
--- a/src/apps/pkclassify_nn.cc
+++ b/src/apps/pkclassify_nn.cc
@@ -17,6 +17,11 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************/
+#include <stdlib.h>
+#ifdef WIN32
+#define random rand
+#define srandom srand
+#endif
 #include <vector>
 #include <map>
 #include <algorithm>
@@ -28,7 +33,7 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include "base/PosValue.h"
 #include "algorithms/ConfusionMatrix.h"
 #include "floatfann.h"
-#include "myfann_cpp.h"
+#include "algorithms/myfann_cpp.h"
 
 using namespace std;
 
@@ -850,7 +855,7 @@ int main(int argc, char *argv[])
               probOut[iclass][icol]+=result[iclass]*priors[iclass];//add probabilities for each bag
               break;
             case(1)://product rule
-              probOut[iclass][icol]*=pow(priors[iclass],static_cast<float>(1.0-nbag)/nbag)*result[iclass];//multiply probabilities for each bag
+              probOut[iclass][icol]*=pow(static_cast<float>(priors[iclass]),static_cast<float>(1.0-nbag)/nbag)*result[iclass];//multiply probabilities for each bag
               break;
             case(2)://max rule
               if(priors[iclass]*result[iclass]>probOut[iclass][icol])
@@ -889,7 +894,7 @@ int main(int argc, char *argv[])
         for(short iclass=0;iclass<nclass;++iclass){
           float prv=probOut[iclass][icol];
           prv/=normBag;
-          entropy[icol]-=prv*log(prv)/log(2);
+          entropy[icol]-=prv*log(prv)/log(2.0);
           prv*=100.0;
             
           probOut[iclass][icol]=static_cast<short>(prv+0.5);
@@ -897,7 +902,7 @@ int main(int argc, char *argv[])
           // assert(classValueMap[nameVector[iclass]]>=0);
           // probOut[classValueMap[nameVector[iclass]]][icol]=static_cast<short>(prv+0.5);
         }
-        entropy[icol]/=log(nclass)/log(2);
+        entropy[icol]/=log(static_cast<double>(nclass))/log(2.0);
         entropy[icol]=static_cast<short>(100*entropy[icol]+0.5);
 	if(active_opt.size()){
 	  if(entropy[icol]>activePoints.back().value){
@@ -1042,7 +1047,7 @@ int main(int argc, char *argv[])
 		probOut[iclass]+=result[iclass]*priors[iclass];//add probabilities for each bag
               break;
 	      case(1)://product rule
-		probOut[iclass]*=pow(priors[iclass],static_cast<float>(1.0-nbag)/nbag)*result[iclass];//multiply probabilities for each bag
+		probOut[iclass]*=pow(static_cast<float>(priors[iclass]),static_cast<float>(1.0-nbag)/nbag)*result[iclass];//multiply probabilities for each bag
 		break;
 	      case(2)://max rule
 		if(priors[iclass]*result[iclass]>probOut[iclass])
diff --git a/src/apps/pkclassify_svm.cc b/src/apps/pkclassify_svm.cc
index b7d24c2..e5d7896 100644
--- a/src/apps/pkclassify_svm.cc
+++ b/src/apps/pkclassify_svm.cc
@@ -17,6 +17,11 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************/
+#include <stdlib.h>
+#ifdef WIN32
+#define random rand
+#define srandom srand
+#endif
 #include <vector>
 #include <map>
 #include <algorithm>
diff --git a/src/apps/pkcrop.cc b/src/apps/pkcrop.cc
index 4248e61..d27483b 100644
--- a/src/apps/pkcrop.cc
+++ b/src/apps/pkcrop.cc
@@ -271,7 +271,7 @@ int main(int argc, char *argv[])
     double uli,ulj,lri,lrj;//image coordinates
     bool forceEUgrid=false;
     if(projection_opt.size())
-      forceEUgrid=(!(projection_opt[0].compare("EPSG:3035"))||!(projection_opt[0].compare("epsg:3035"))||projection_opt[0].find("ETRS-LAEA")!=string::npos);
+      forceEUgrid=(!(projection_opt[0].compare("EPSG:3035"))||!(projection_opt[0].compare("EPSG:3035"))||projection_opt[0].find("ETRS-LAEA")!=string::npos);
     if(ulx_opt[0]>=lrx_opt[0]){//default bounding box: no cropping
       uli=0;
       lri=imgReader.nrOfCol()-1;
diff --git a/src/apps/pkdiff.cc b/src/apps/pkdiff.cc
index d299fe5..ae744a2 100644
--- a/src/apps/pkdiff.cc
+++ b/src/apps/pkdiff.cc
@@ -22,7 +22,7 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include "imageclasses/ImgWriterGdal.h"
 #include "imageclasses/ImgReaderOgr.h"
 #include "imageclasses/ImgWriterOgr.h"
-#include "Optionpk.h"
+#include "base/Optionpk.h"
 #include "algorithms/ConfusionMatrix.h"
 
 using namespace std;
diff --git a/src/apps/pkdumpimg.cc b/src/apps/pkdumpimg.cc
index 671d4e2..0e40462 100644
--- a/src/apps/pkdumpimg.cc
+++ b/src/apps/pkdumpimg.cc
@@ -22,7 +22,7 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include <vector>
 #include <iostream>
 #include <assert.h>
-#include "Optionpk.h"
+#include "base/Optionpk.h"
 #include "imageclasses/ImgReaderOgr.h"
 #include "imageclasses/ImgWriterGdal.h"
 // #include "imageclasses/ImgWriterOgr.h"
diff --git a/src/apps/pkextract.cc b/src/apps/pkextract.cc
index 101f103..d893ee2 100644
--- a/src/apps/pkextract.cc
+++ b/src/apps/pkextract.cc
@@ -19,6 +19,11 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************/
 #include <assert.h>
 #include <math.h>
+#include <stdlib.h>
+#ifdef WIN32
+#define random rand
+#define srandom srand
+#endif
 #include <sstream>
 #include <string>
 #include <algorithm>
@@ -34,7 +39,7 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #endif
 
 namespace rule{
-  enum RULE_TYPE {point=0, mean=1, proportion=2, custom=3, minimum=4, maximum=5, maxvote=6, centroid=7, sum=8, median=9};
+  enum RULE_TYPE {point=0, mean=1, proportion=2, custom=3, minimum=4, maximum=5, maxvote=6, centroid=7, sum=8};
 }
 
 using namespace std;
@@ -64,7 +69,7 @@ int main(int argc, char *argv[])
   Optionpk<string> label_opt("cn", "cname", "name of the class label in the output vector file", "label");
   Optionpk<bool> polygon_opt("polygon", "polygon", "create OGRPolygon as geometry instead of OGRPoint. Only if sample option is also of polygon type.", false);
   Optionpk<int> band_opt("b", "band", "band index to crop. Use -1 to use all bands)", -1);
-  Optionpk<string> rule_opt("r", "rule", "rule how to report image information per feature. point (value at each point or at centroid if polygon), centroid, mean (of polygon), median (of polygon), proportion, minimum (of polygon), maximum (of polygon), maxvote, sum.", "point");
+  Optionpk<string> rule_opt("r", "rule", "rule how to report image information per feature. point (value at each point or at centroid if polygon), centroid, mean (of polygon), proportion, minimum (of polygon), maximum (of polygon), maxvote, sum.", "point");
   Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
 
   bool doProcess;//stop process when program was invoked with help option (-h --help)
@@ -109,7 +114,6 @@ int main(int argc, char *argv[])
   ruleMap["point"]=rule::point;
   ruleMap["centroid"]=rule::centroid;
   ruleMap["mean"]=rule::mean;
-  ruleMap["median"]=rule::median;
   ruleMap["proportion"]=rule::proportion;
   ruleMap["minimum"]=rule::minimum;
   ruleMap["maximum"]=rule::maximum;
@@ -242,7 +246,7 @@ int main(int argc, char *argv[])
   void* pProgressArg=NULL;
   GDALProgressFunc pfnProgress=GDALTermProgress;
   double progress=0;
-  srand(time(NULL));
+  srandom(time(NULL));
 
   bool sampleIsRaster=false;
   ImgReaderOgr sampleReaderOgr;
@@ -423,7 +427,7 @@ int main(int argc, char *argv[])
               }
               float theThreshold=(threshold_opt.size()>1)?threshold_opt[processClass]:threshold_opt[0];
               if(theThreshold>0){//percentual value
-                double p=static_cast<double>(rand())/(RAND_MAX);
+                double p=static_cast<double>(random())/(RAND_MAX);
                 p*=100.0;
                 if(p>theThreshold)
 		  continue;//do not select for now, go to next column
@@ -667,7 +671,7 @@ int main(int argc, char *argv[])
               }
               float theThreshold=(threshold_opt.size()>1)?threshold_opt[processClass]:threshold_opt[0];
               if(theThreshold>0){//percentual value
-                double p=static_cast<double>(rand())/(RAND_MAX);
+                double p=static_cast<double>(random())/(RAND_MAX);
                 p*=100.0;
                 if(p>theThreshold)
                   continue;//do not select for now, go to next column
@@ -835,7 +839,6 @@ int main(int argc, char *argv[])
       break;
       case(rule::point):
       case(rule::mean):
-      case(rule::median):
       case(rule::sum):
       case(rule::centroid):
       default:{
@@ -887,6 +890,24 @@ int main(int argc, char *argv[])
 	bool writeTest=false;//write this feature to test_opt[0] instead of output_opt
 	if(verbose_opt[0]>0)
 	  std::cout << "reading feature " << readFeature->GetFID() << std::endl;
+	if(threshold_opt[0]>0){//percentual value
+	  double p=static_cast<double>(random())/(RAND_MAX);
+	  p*=100.0;
+	  if(p>threshold_opt[0]){
+	    if(test_opt.size())
+	      writeTest=true;
+	    else
+	      continue;//do not select for now, go to next feature
+	  }
+	}
+	else{//absolute value
+	  if(ntotalvalid>-threshold_opt[0]){
+	    if(test_opt.size())
+	      writeTest=true;
+	    else
+	      continue;//do not select any more pixels, go to next column feature
+	  }
+	}
 	if(verbose_opt[0]>0)
 	  std::cout << "processing feature " << readFeature->GetFID() << std::endl;
 	//get x and y from readFeature
@@ -896,25 +917,6 @@ int main(int argc, char *argv[])
 	assert(poGeometry!=NULL);
 	try{
 	  if(wkbFlatten(poGeometry->getGeometryType()) == wkbPoint ){
-	    if(threshold_opt[0]>0){//percentual value
-	      double p=static_cast<double>(rand())/(RAND_MAX);
-	      p*=100.0;
-	      if(p>threshold_opt[0]){
-		if(test_opt.size())
-		  writeTest=true;
-		else
-		  continue;//do not select for now, go to next feature
-	      }
-	    }
-	    else{//absolute value
-	      if(ntotalvalid>-threshold_opt[0]){
-		if(test_opt.size())
-		  writeTest=true;
-		else
-		  continue;//do not select any more pixels, go to next column feature
-	      }
-	    }
-
 	    assert(class_opt.size()<=1);//class_opt not implemented for point yet
 	    OGRPoint *poPoint = (OGRPoint *) poGeometry;
 	    x=poPoint->getX();
@@ -1162,27 +1164,7 @@ int main(int argc, char *argv[])
 	      std::cout << "ntotalvalid: " << ntotalvalid << std::endl;
 	  }//if wkbPoint
 	  else if(wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon){
-	    //select percentage of polygons (if point, select percentage of points within polygons)
-	    if(ruleMap[rule_opt[0]]!=rule::point){
-	      if(threshold_opt[0]>0){//percentual value
-		double p=static_cast<double>(rand())/(RAND_MAX);
-		p*=100.0;
-		if(p>threshold_opt[0]){
-		  if(test_opt.size())
-		    writeTest=true;
-		  else
-		    continue;//do not select for now, go to next feature
-		}
-	      }
-	      else{//absolute value
-		if(ntotalvalid>-threshold_opt[0]){
-		  if(test_opt.size())
-		    writeTest=true;
-		  else
-		    continue;//do not select any more pixels, go to next column feature
-		}
-	      }
-	    }
+            
 	    OGRPolygon readPolygon = *((OGRPolygon *) poGeometry);
 	    OGRPolygon writePolygon;
 	    OGRLinearRing writeRing;
@@ -1245,7 +1227,7 @@ int main(int argc, char *argv[])
 	      else
 		writePolygonFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
 	    }
-	    else if(ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::median||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
+	    else if(ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
 	      if(writeTest)
 		writeCentroidFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
 	      else
@@ -1253,10 +1235,7 @@ int main(int argc, char *argv[])
 	    }
 	    //previously here
 	    vector<double> polyValues;
-	    vector< vector<double> > polyValuesVector;
 	    switch(ruleMap[rule_opt[0]]){
-	    case(rule::median):
-	      polyValuesVector.resize(nband);
 	    case(rule::point):
 	    case(rule::mean):
 	    case(rule::sum):
@@ -1369,29 +1348,6 @@ int main(int argc, char *argv[])
 		    continue;
 		  if(j<0||j>=imgReader.nrOfRow())
 		    continue;
-
-		  //select percentage of points within polygon
-		  if(ruleMap[rule_opt[0]]==rule::point){
-		    if(threshold_opt[0]>0){//percentual value
-		      double p=static_cast<double>(rand())/(RAND_MAX);
-		      p*=100.0;
-		      if(p>threshold_opt[0]){
-			if(test_opt.size())
-			  writeTest=true;
-			else
-			  continue;//do not select for now, go to next feature
-		      }
-		    }
-		    else{//absolute value
-		      if(ntotalvalid>-threshold_opt[0]){
-			if(test_opt.size())
-			  writeTest=true;
-			else
-			  continue;//do not select any more pixels, go to next column feature
-		      }
-		    }
-		  }
-
 		  writeRing.addPoint(&thePoint);
 		  if(verbose_opt[0]>1)
 		    std::cout << "point is on surface:" << thePoint.getX() << "," << thePoint.getY() << std::endl;
@@ -1399,7 +1355,7 @@ int main(int argc, char *argv[])
 		  OGRFeature *writePointFeature;
 		  if(!polygon_opt[0]){
 		    //create feature
-		    if(ruleMap[rule_opt[0]]!=rule::mean&&ruleMap[rule_opt[0]]!=rule::median&&ruleMap[rule_opt[0]]!=rule::centroid&&ruleMap[rule_opt[0]]!=rule::sum){//do not create in case of mean, median, sum or centroid (only create point at centroid)
+		    if(ruleMap[rule_opt[0]]!=rule::mean&&ruleMap[rule_opt[0]]!=rule::centroid&&ruleMap[rule_opt[0]]!=rule::sum){//do not create in case of mean, sum or centroid (only create point at centroid)
 		      if(writeTest)
 			writePointFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
 		      else
@@ -1424,9 +1380,18 @@ int main(int argc, char *argv[])
 		    imgReader.readData(value,GDT_Float64,i,j,theBand);
 		    if(verbose_opt[0]>1)
 		      std::cout << ": " << value << std::endl;
-		    if(polygon_opt[0]||ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::median||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
+		    if(polygon_opt[0]||ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
 		      int iclass=0;
 		      switch(ruleMap[rule_opt[0]]){
+		      case(rule::point)://in centroid if polygon_opt==true or all values as points if polygon_opt!=true
+		      case(rule::centroid):
+		      default:
+			polyValues[iband]=value;
+		      break;
+		      case(rule::sum):
+		      case(rule::mean)://mean as polygon if polygon_opt==true or as point in centroid if polygon_opt!=true
+			polyValues[iband]+=value;
+			break;
 		      case(rule::proportion):
 		      case(rule::custom):
 		      case(rule::minimum):
@@ -1440,26 +1405,14 @@ int main(int argc, char *argv[])
 			  }
 			}
 		      break;
-		      case(rule::sum):
-		      case(rule::mean)://mean as polygon if polygon_opt==true or as point in centroid if polygon_opt!=true
-			polyValues[iband]+=value;
-		      break;
-		      case(rule::median):
-			polyValuesVector[iband].push_back(value);
-		      break;
-		      case(rule::point)://in centroid if polygon_opt==true or all values as points if polygon_opt!=true
-		      case(rule::centroid):
-		      default:
-			polyValues[iband]=value;
-		      break;
 		      }
 		    }
 		    else{
-		    // ostringstream fs;
-		    // if(imgReader.nrOfBand()==1)
-		    //   fs << fieldname_opt[0];
-		    // else
-		    //   fs << fieldname_opt[0] << theBand;
+		      // ostringstream fs;
+		      // if(imgReader.nrOfBand()==1)
+		      //   fs << fieldname_opt[0];
+		      // else
+		      //   fs << fieldname_opt[0] << theBand;
 		      if(verbose_opt[0]>1)
 			std::cout << "set field " << fieldname_opt[iband] << " to " << value << std::endl;
 		      switch( fieldType ){
@@ -1494,7 +1447,7 @@ int main(int argc, char *argv[])
 		    }
 		  }
 		  if(!polygon_opt[0]){
-		    if(ruleMap[rule_opt[0]]!=rule::mean&&ruleMap[rule_opt[0]]!=rule::median&&ruleMap[rule_opt[0]]!=rule::centroid&&ruleMap[rule_opt[0]]!=rule::sum){//do not create in case of mean value (only at centroid)
+		    if(ruleMap[rule_opt[0]]!=rule::mean&&ruleMap[rule_opt[0]]!=rule::centroid&&ruleMap[rule_opt[0]]!=rule::sum){//do not create in case of mean value (only at centroid)
 		      //write feature
 		      if(verbose_opt[0]>1)
 			std::cout << "creating point feature" << std::endl;
@@ -1521,7 +1474,7 @@ int main(int argc, char *argv[])
 		}
 	      }
 	    }
-	    if(polygon_opt[0]||ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::median||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
+	    if(polygon_opt[0]||ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
 	      //do not create if no points found within polygon
 	      if(!nPointPolygon)
 		continue;
@@ -1539,7 +1492,7 @@ int main(int argc, char *argv[])
 		  std::cout << "write feature has " << writePolygonFeature->GetFieldCount() << " fields" << std::endl;
 		//write polygon feature
 	      }
-	      else{//write mean value of polygon to centroid point (ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::median)
+	      else{//write mean value of polygon to centroid point (ruleMap[rule_opt[0]]==rule::mean)
 		//create feature
 		if(verbose_opt[0]>1)
 		  std::cout << "copying fields from polygons " << sample_opt[0] << std::endl;
@@ -1626,7 +1579,6 @@ int main(int argc, char *argv[])
 		break;
 	      }
 	      case(rule::mean):
-	      case(rule::median):
 	      case(rule::sum):
 	      case(rule::centroid):{//mean value (written to centroid of polygon if line is not set)
 		if(verbose_opt[0])
@@ -1639,8 +1591,6 @@ int main(int argc, char *argv[])
 		  // ostringstream fs;
 		  if(ruleMap[rule_opt[0]]==rule::mean)
 		    theValue/=nPointPolygon;
-		  else if(ruleMap[rule_opt[0]]==rule::median)
-		    theValue=stat.median(polyValuesVector[index]);
 		  int theBand=(band_opt[0]<0)?index:band_opt[index];
 		  // if(nband==1)
 		  //   fs << fieldname_opt[0];
@@ -1750,7 +1700,7 @@ int main(int argc, char *argv[])
 		if(verbose_opt[0])
 		  std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
 		//search for min class
-		int minClass=stat.max(class_opt);
+		int minClass=stat.mymax(class_opt);
 		for(int iclass=0;iclass<class_opt.size();++iclass){
 		  if(polyValues[iclass]>0){
 		    if(verbose_opt[0]>1)
@@ -1770,7 +1720,7 @@ int main(int argc, char *argv[])
 		if(verbose_opt[0])
 		  std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
 		//search for max class
-		int maxClass=stat.min(class_opt);
+		int maxClass=stat.mymin(class_opt);
 		for(int iclass=0;iclass<class_opt.size();++iclass){
 		  if(polyValues[iclass]>0){
 		    if(verbose_opt[0]>1)
@@ -1790,9 +1740,9 @@ int main(int argc, char *argv[])
 		if(verbose_opt[0])
 		  std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
 		//search for class with maximum votes
-		int maxClass=stat.min(class_opt);
+		int maxClass=stat.mymin(class_opt);
 		vector<double>::iterator maxit;
-		maxit=stat.max(polyValues,polyValues.begin(),polyValues.end());
+		maxit=stat.mymax(polyValues,polyValues.begin(),polyValues.end());
 		int maxIndex=distance(polyValues.begin(),maxit);
 		maxClass=class_opt[maxIndex];
 		if(verbose_opt[0]>0)
@@ -1828,27 +1778,6 @@ int main(int argc, char *argv[])
 	    }
 	  }
 	  else if(wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon){//todo: try to use virtual OGRGeometry instead of OGRMultiPolygon and OGRPolygon
-	    //select percentage of polygons (if point, select percentage of points within polygons)
-	    if(ruleMap[rule_opt[0]]!=rule::point){
-	      if(threshold_opt[0]>0){//percentual value
-		double p=static_cast<double>(rand())/(RAND_MAX);
-		p*=100.0;
-		if(p>threshold_opt[0]){
-		  if(test_opt.size())
-		    writeTest=true;
-		  else
-		    continue;//do not select for now, go to next feature
-		}
-	      }
-	      else{//absolute value
-		if(ntotalvalid>-threshold_opt[0]){
-		  if(test_opt.size())
-		    writeTest=true;
-		  else
-		    continue;//do not select any more pixels, go to next column feature
-		}
-	      }
-	    }
 	    OGRMultiPolygon readPolygon = *((OGRMultiPolygon *) poGeometry);
 	    OGRPolygon writePolygon;
 	    OGRLinearRing writeRing;
@@ -1911,17 +1840,15 @@ int main(int argc, char *argv[])
 	      else
 		writePolygonFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
 	    }
-	    else if(ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::median||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
+	    else if(ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
 	      if(writeTest)
 		writeCentroidFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
 	      else
 		writeCentroidFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
 	    }
+	    //previously here
 	    vector<double> polyValues;
-	    vector< vector<double> > polyValuesVector;
 	    switch(ruleMap[rule_opt[0]]){
-	    case(rule::median):
-	      polyValuesVector.resize(nband);
 	    case(rule::point):
 	    case(rule::mean):
 	    case(rule::sum):
@@ -2034,29 +1961,6 @@ int main(int argc, char *argv[])
 		    continue;
 		  if(j<0||j>=imgReader.nrOfRow())
 		    continue;
-
-		  //select percentage of points within polygon
-		  if(ruleMap[rule_opt[0]]==rule::point){
-		    if(threshold_opt[0]>0){//percentual value
-		      double p=static_cast<double>(rand())/(RAND_MAX);
-		      p*=100.0;
-		      if(p>threshold_opt[0]){
-			if(test_opt.size())
-			  writeTest=true;
-			else
-			  continue;//do not select for now, go to next feature
-		      }
-		    }
-		    else{//absolute value
-		      if(ntotalvalid>-threshold_opt[0]){
-			if(test_opt.size())
-			  writeTest=true;
-			else
-			  continue;//do not select any more pixels, go to next column feature
-		      }
-		    }
-		  }
-
 		  writeRing.addPoint(&thePoint);
 		  if(verbose_opt[0]>1)
 		    std::cout << "point is on surface:" << thePoint.getX() << "," << thePoint.getY() << std::endl;
@@ -2064,7 +1968,7 @@ int main(int argc, char *argv[])
 		  OGRFeature *writePointFeature;
 		  if(!polygon_opt[0]){
 		    //create feature
-		    if(ruleMap[rule_opt[0]]!=rule::mean&&ruleMap[rule_opt[0]]!=rule::median&&ruleMap[rule_opt[0]]!=rule::centroid&&ruleMap[rule_opt[0]]!=rule::sum){//do not create in case of mean or sum (only create point at centroid)
+		    if(ruleMap[rule_opt[0]]!=rule::mean&&ruleMap[rule_opt[0]]!=rule::centroid&&ruleMap[rule_opt[0]]!=rule::sum){//do not create in case of mean or sum (only create point at centroid)
 		      if(writeTest)
 			writePointFeature = OGRFeature::CreateFeature(writeTestLayer->GetLayerDefn());
 		      else
@@ -2089,7 +1993,7 @@ int main(int argc, char *argv[])
 		    imgReader.readData(value,GDT_Float64,i,j,theBand);
 		    if(verbose_opt[0]>1)
 		      std::cout << ": " << value << std::endl;
-		    if(polygon_opt[0]||ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::median||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
+		    if(polygon_opt[0]||ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
 		      int iclass=0;
 		      switch(ruleMap[rule_opt[0]]){
 		      case(rule::point)://in centroid if polygon_opt==true or all values as points if polygon_opt!=true
@@ -2098,12 +2002,9 @@ int main(int argc, char *argv[])
 			polyValues[iband]=value;
 		      break;
 		      case(rule::sum):
-		      case(rule::mean)://mean sum polygon if polygon_opt==true or as point in centroid if polygon_opt!=true
+		      case(rule::mean)://mean or sum polygon if polygon_opt==true or as point in centroid if polygon_opt!=true
 			polyValues[iband]+=value;
 			break;
-		      case(rule::median):
-			polyValuesVector[iband].push_back(value);
-			break;
 		      case(rule::proportion):
 		      case(rule::custom):
 		      case(rule::minimum):
@@ -2159,7 +2060,7 @@ int main(int argc, char *argv[])
 		    }
 		  }
 		  if(!polygon_opt[0]){
-		    if(ruleMap[rule_opt[0]]!=rule::mean&&ruleMap[rule_opt[0]]!=rule::median&&ruleMap[rule_opt[0]]!=rule::centroid&&ruleMap[rule_opt[0]]!=rule::sum){//do not create in case of mean or median value (only at centroid)
+		    if(ruleMap[rule_opt[0]]!=rule::mean&&ruleMap[rule_opt[0]]!=rule::centroid&&ruleMap[rule_opt[0]]!=rule::sum){//do not create in case of mean value (only at centroid)
 		      //write feature
 		      if(verbose_opt[0]>1)
 			std::cout << "creating point feature" << std::endl;
@@ -2189,7 +2090,7 @@ int main(int argc, char *argv[])
 	    //test
 	    if(!validFeature)
 	      continue;
-	    if(polygon_opt[0]||ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::median||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
+	    if(polygon_opt[0]||ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::centroid||ruleMap[rule_opt[0]]==rule::sum){
 	      //add ring to polygon
 	      if(polygon_opt[0]){
 		writePolygon.addRing(&writeRing);
@@ -2204,7 +2105,7 @@ int main(int argc, char *argv[])
 		  std::cout << "write feature has " << writePolygonFeature->GetFieldCount() << " fields" << std::endl;
 		//write polygon feature
 	      }
-	      else{//write mean value of polygon to centroid point (ruleMap[rule_opt[0]]==rule::mean||ruleMap[rule_opt[0]]==rule::median)
+	      else{//write mean value of polygon to centroid point (ruleMap[rule_opt[0]]==rule::mean)
 		//create feature
 		if(verbose_opt[0]>1)
 		  std::cout << "copying fields from polygons " << sample_opt[0] << std::endl;
@@ -2287,7 +2188,6 @@ int main(int argc, char *argv[])
 		break;
 	      }//case 0 and default
 	      case(rule::mean):
-	      case(rule::median):
 	      case(rule::sum):
 	      case(rule::centroid):{//mean value (written to centroid of polygon if line is not set)
 		if(verbose_opt[0])
@@ -2300,8 +2200,6 @@ int main(int argc, char *argv[])
 		  // ostringstream fs;
 		  if(ruleMap[rule_opt[0]]==rule::mean)
 		    theValue/=nPointPolygon;
-		  else if(ruleMap[rule_opt[0]]==rule::median)
-		    theValue=stat.median(polyValuesVector[index]);
 		  int theBand=(band_opt[0]<0)?index:band_opt[index];
 		  // if(nband==1)
 		  //   fs << fieldname_opt[0];
@@ -2407,7 +2305,7 @@ int main(int argc, char *argv[])
 		if(verbose_opt[0])
 		  std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
 		//search for min class
-		int minClass=stat.max(class_opt);
+		int minClass=stat.mymax(class_opt);
 		for(int iclass=0;iclass<class_opt.size();++iclass){
 		  if(polyValues[iclass]>0){
 		    if(verbose_opt[0]>1)
@@ -2426,7 +2324,7 @@ int main(int argc, char *argv[])
 		if(verbose_opt[0])
 		  std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
 		//search for max class
-		int maxClass=stat.min(class_opt);
+		int maxClass=stat.mymin(class_opt);
 		for(int iclass=0;iclass<class_opt.size();++iclass){
 		  if(polyValues[iclass]>0){
 		    if(verbose_opt[0]>1)
@@ -2445,9 +2343,9 @@ int main(int argc, char *argv[])
 		if(verbose_opt[0])
 		  std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
 		//search for max votes
-		int maxClass=stat.min(class_opt);
+		int maxClass=stat.mymin(class_opt);
 		vector<double>::iterator maxit;
-		maxit=stat.max(polyValues,polyValues.begin(),polyValues.end());
+		maxit=stat.mymax(polyValues,polyValues.begin(),polyValues.end());
 		int maxIndex=distance(polyValues.begin(),maxit);
 		maxClass=class_opt[maxIndex];
 	      }
diff --git a/src/apps/pkfilterascii.cc b/src/apps/pkfilterascii.cc
index 75afc5e..d560e4b 100644
--- a/src/apps/pkfilterascii.cc
+++ b/src/apps/pkfilterascii.cc
@@ -42,7 +42,7 @@ int main(int argc,char **argv) {
   Optionpk<std::string> input_opt("i","input","input ASCII file");
   Optionpk<std::string> output_opt("o", "output", "Output ASCII file");
   Optionpk<int> inputCols_opt("ic", "inputCols", "input columns (e.g., for three dimensional input data in first three columns use: -ic 0 -ic 1 -ic 2"); 
-  Optionpk<std::string> method_opt("f", "filter", "filter function");
+  Optionpk<std::string> method_opt("f", "filter", "filter function (to be implemented: dwt, dwti,dwt_cut)");
   Optionpk<std::string> wavelet_type_opt("wt", "wavelet", "wavelet type: daubechies,daubechies_centered, haar, haar_centered, bspline, bspline_centered", "daubechies");
   Optionpk<int> family_opt("wf", "family", "wavelet family (vanishing moment, see also http://www.gnu.org/software/gsl/manual/html_node/DWT-Initialization.html)", 4);
   Optionpk<double> threshold_opt("cut", "cut", "threshold to cut dwt coefficients. Use 0 to keep all.", 0);
@@ -107,9 +107,7 @@ int main(int argc,char **argv) {
     assert(wavelengthIn_opt.size());
     if(verbose_opt[0])
       std::cout << "spectral filtering to " << fwhm_opt.size() << " bands with provided fwhm " << std::endl;
-    while(fwhm_opt.size()<wavelengthOut_opt.size())//extend fwhm to all
-      fwhm_opt.push_back(fwhm_opt[0]);
-    // assert(wavelengthOut_opt.size()==fwhm_opt.size());
+    assert(wavelengthOut_opt.size()==fwhm_opt.size());
     std::vector<double> fwhmData(wavelengthOut_opt.size());
     for(int icol=0;icol<inputCols_opt.size();++icol)
       filter1d.applyFwhm<double>(wavelengthIn,inputData[icol], wavelengthOut_opt,fwhm_opt, interpolationType_opt[0], filteredData[icol],verbose_opt[0]);
@@ -171,12 +169,8 @@ int main(int argc,char **argv) {
   else{//no filtering
     if(verbose_opt[0])
       std::cout << "no filtering selected" << std::endl;
-    wavelengthOut=wavelengthIn;
-    for(int icol=0;icol<inputCols_opt.size();++icol){
+    for(int icol=0;icol<inputCols_opt.size();++icol)
       filteredData[icol]=inputData[icol];
-      if(verbose_opt[0])
-	std::cout << "size filtered data for col " << icol << ": " << filteredData[icol].size() << std::endl;
-    }
   }
   
   if(method_opt.size()){
@@ -240,13 +234,25 @@ int main(int argc,char **argv) {
   }
   else{
     // int nband=wavelengthOut.size()? wavelengthOut.size() : filteredData[0].size();
-    int nband=wavelengthOut.size();
+    int nband=0;
     if(method_opt.size()){
-      if(filter::Filter::getFilterType(method_opt[0])==filter::dwt_cut)
+      switch(filter::Filter::getFilterType(method_opt[0])){
+      case(filter::dwt):
+        nband=filteredData[0].size();
+        break;
+      case(filter::dwti):
+        nband=filteredData[0].size();
+        break;
+      case(filter::dwt_cut):
+        nband=filteredData[0].size();
+        break;
+      default:
         nband=wavelengthOut.size();
-      else
-	nband=filteredData[0].size();
+        break;
+      }
     }
+    else
+      nband=wavelengthOut.size();
     if(verbose_opt[0]){
       std::cout << "number of bands: " << nband << std::endl;
       std::cout << "wavelengthOut.size(): " << wavelengthOut.size() << std::endl;
diff --git a/src/apps/pkfs_nn.cc b/src/apps/pkfs_nn.cc
index 99bbb48..6ac56b2 100644
--- a/src/apps/pkfs_nn.cc
+++ b/src/apps/pkfs_nn.cc
@@ -17,29 +17,32 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************/
+#include <stdlib.h>
+#ifdef WIN32
+#define random rand
+#define srandom srand
+#endif
 #include <vector>
 #include <string>
 #include <map>
 #include <algorithm>
-#include "floatfann.h"
-#include "imageclasses/ImgReaderOgr.h"
-// #include "imageclasses/ImgReaderGdal.h"
-// #include "imageclasses/ImgWriterGdal.h"
-// #include "imageclasses/ImgWriterOgr.h"
 #include "base/Optionpk.h"
-#include "algorithms/myfann_cpp.h"
+#include "imageclasses/ImgReaderOgr.h"
 #include "algorithms/ConfusionMatrix.h"
 #include "algorithms/FeatureSelector.h"
+#include "floatfann.h"
+#include "algorithms/myfann_cpp.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
+enum SelectorValue  { NA=0, SFFS=1, SFS=2, SBS=3, BFS=4 };
+
 using namespace std;
 
 #define Malloc(type,n) (type *)malloc((n)*sizeof(type))
 
-enum SelectorValue  { NA=0, SFFS=1, SFS=2, SBS=3, BFS=4 };
 
 //global parameters used in cost function getCost
 map<string,short> classValueMap;
@@ -215,6 +218,7 @@ int main(int argc, char *argv[])
   Optionpk<string> label_opt("\0", "label", "identifier for class label in training shape file.","label"); 
   Optionpk<unsigned short> maxFeatures_opt("n", "nf", "number of features to select (0 to select optimal number, see also ecost option)", 0);
   Optionpk<unsigned int> balance_opt("\0", "balance", "balance the input data to this number of samples for each class", 0);
+  Optionpk<bool> random_opt("random","random", "in case of balance, randomize input data", true);
   Optionpk<int> minSize_opt("m", "min", "if number of training pixels is less then min, do not take this class into account", 0);
   Optionpk<double> start_opt("s", "start", "start band sequence number (set to 0)",0); 
   Optionpk<double> end_opt("e", "end", "end band sequence number (set to 0 for all bands)", 0); 
@@ -233,6 +237,7 @@ int main(int argc, char *argv[])
     maxFeatures_opt.retrieveOption(argc,argv);
     label_opt.retrieveOption(argc,argv);
     balance_opt.retrieveOption(argc,argv);
+	random_opt.retrieveOption(argc,argv);
     minSize_opt.retrieveOption(argc,argv);
     start_opt.retrieveOption(argc,argv);
     end_opt.retrieveOption(argc,argv);
@@ -418,7 +423,7 @@ int main(int argc, char *argv[])
   //do not remove outliers here: could easily be obtained through ogr2ogr -where 'B2<110' output.shp input.shp
   //balance training data
   if(balance_opt[0]>0){
-    if(random)
+    if(random_opt[0])
       srand(time(NULL));
     totalSamples=0;
     for(int iclass=0;iclass<nclass;++iclass){
diff --git a/src/apps/pkfs_svm.cc b/src/apps/pkfs_svm.cc
index bc839cf..45f8996 100644
--- a/src/apps/pkfs_svm.cc
+++ b/src/apps/pkfs_svm.cc
@@ -17,6 +17,11 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************/
+#include <stdlib.h>
+#ifdef WIN32
+#define random rand
+#define srandom srand
+#endif
 #include <vector>
 #include <string>
 #include <map>
@@ -224,6 +229,7 @@ int main(int argc, char *argv[])
   Optionpk<string> label_opt("\0", "label", "identifier for class label in training shape file.","label"); 
   Optionpk<unsigned short> maxFeatures_opt("n", "nf", "number of features to select (0 to select optimal number, see also ecost option)", 0);
   Optionpk<unsigned int> balance_opt("\0", "balance", "balance the input data to this number of samples for each class", 0);
+  Optionpk<bool> random_opt("random","random", "in case of balance, randomize input data", true);
   Optionpk<int> minSize_opt("m", "min", "if number of training pixels is less then min, do not take this class into account", 0);
   Optionpk<double> start_opt("s", "start", "start band sequence number (set to 0)",0); 
   Optionpk<double> end_opt("e", "end", "end band sequence number (set to 0 for all bands)", 0); 
@@ -240,6 +246,7 @@ int main(int argc, char *argv[])
     maxFeatures_opt.retrieveOption(argc,argv);
     label_opt.retrieveOption(argc,argv);
     balance_opt.retrieveOption(argc,argv);
+	random_opt.retrieveOption(argc,argv);
     minSize_opt.retrieveOption(argc,argv);
     start_opt.retrieveOption(argc,argv);
     end_opt.retrieveOption(argc,argv);
@@ -439,8 +446,9 @@ int main(int argc, char *argv[])
 
   //do not remove outliers here: could easily be obtained through ogr2ogr -where 'B2<110' output.shp input.shp
   //balance training data
+  //todo: do I mean to use random_opt?
   if(balance_opt[0]>0){
-    if(random)
+    if(random_opt[0])
       srand(time(NULL));
     totalSamples=0;
     for(int iclass=0;iclass<nclass;++iclass){
diff --git a/src/apps/pkinfo.cc b/src/apps/pkinfo.cc
index f7a72ba..6469263 100644
--- a/src/apps/pkinfo.cc
+++ b/src/apps/pkinfo.cc
@@ -43,8 +43,8 @@ int main(int argc, char *argv[])
   Optionpk<bool>  min_opt("min", "min", "Shows min value of the image ", false,0);
   Optionpk<bool>  max_opt("max", "max", "Shows max value of the image ", false,0);
   Optionpk<bool>  stat_opt("stats", "stats", "Shows statistics (min,max, mean and stdDev of the image)", false,0);
-  Optionpk<double>  src_min_opt("src_min", "src_min", "Sets minimum for histogram (does not calculate min value: use -min or -mm instead)");
-  Optionpk<double>  src_max_opt("src_max", "src_max", "Sets maximum for histogram (does not calculate min value: use -max or -mm instead)");
+  Optionpk<double>  src_min_opt("src_min", "src_min", "Sets minimum for histogram (does not calculate min value: use -mm instead)");
+  Optionpk<double>  src_max_opt("src_max", "src_max", "Sets maximum for histogram (does not calculate min value: use -mm instead)");
   Optionpk<bool>  relative_opt("rel", "rel", "Calculates relative histogram in percentage", false,0);
   Optionpk<bool>  projection_opt("a_srs", "a_srs", "Shows projection of the image ", false,0);
   Optionpk<bool>  geo_opt("geo", "geo", "Gets geotransform  ", false,0);
diff --git a/src/apps/pkmosaic.cc b/src/apps/pkmosaic.cc
index 4e3e4aa..a88a430 100644
--- a/src/apps/pkmosaic.cc
+++ b/src/apps/pkmosaic.cc
@@ -894,7 +894,7 @@ int main(int argc, char *argv[])
       else{
         for(int icol=0;icol<imgWriter.nrOfCol();++icol){
           vector<short>::iterator maxit=maxBuffer[icol].begin();
-          maxit=stat.max(maxBuffer[icol],maxBuffer[icol].begin(),maxBuffer[icol].end());
+          maxit=stat.mymax(maxBuffer[icol],maxBuffer[icol].begin(),maxBuffer[icol].end());
           writeBuffer[0][icol]=distance(maxBuffer[icol].begin(),maxit);
           fileBuffer[icol]=*(maxit);
         }
diff --git a/src/apps/pkopt_svm.cc b/src/apps/pkopt_svm.cc
index 6e48923..b1422bc 100644
--- a/src/apps/pkopt_svm.cc
+++ b/src/apps/pkopt_svm.cc
@@ -235,6 +235,7 @@ int main(int argc, char *argv[])
   Optionpk<string> label_opt("\0", "label", "identifier for class label in training shape file.","label"); 
   // Optionpk<unsigned short> reclass_opt("\0", "rc", "reclass code (e.g. --rc=12 --rc=23 to reclass first two classes to 12 and 23 resp.).", 0);
   Optionpk<unsigned int> balance_opt("\0", "balance", "balance the input data to this number of samples for each class", 0);
+  Optionpk<bool> random_opt("random","random", "in case of balance, randomize input data", true);
   Optionpk<int> minSize_opt("m", "min", "if number of training pixels is less then min, do not take this class into account", 0);
   Optionpk<double> start_opt("s", "start", "start band sequence number (set to 0)",0); 
   Optionpk<double> end_opt("e", "end", "end band sequence number (set to 0 for all bands)", 0); 
@@ -255,6 +256,7 @@ int main(int argc, char *argv[])
     label_opt.retrieveOption(argc,argv);
     // reclass_opt.retrieveOption(argc,argv);
     balance_opt.retrieveOption(argc,argv);
+	random_opt.retrieveOption(argc,argv);
     minSize_opt.retrieveOption(argc,argv);
     start_opt.retrieveOption(argc,argv);
     end_opt.retrieveOption(argc,argv);
@@ -453,7 +455,7 @@ int main(int argc, char *argv[])
   //do not remove outliers here: could easily be obtained through ogr2ogr -where 'B2<110' output.shp input.shp
   //balance training data
   if(balance_opt[0]>0){
-    if(random)
+    if(random_opt[0])
       srand(time(NULL));
     totalSamples=0;
     for(int iclass=0;iclass<nclass;++iclass){
@@ -601,10 +603,8 @@ int main(int argc, char *argv[])
     double progress=0;
     if(!verbose_opt[0])
       pfnProgress(progress,pszMessage,pProgressArg);
-    // double ncost=log(ccost_opt[1])/log(step_opt[0])-log(ccost_opt[0])/log(step_opt[0]);
-    double ncost=log(ccost_opt[1]/ccost_opt[0])/log(step_opt[0]);
-    // double ngamma=log(gamma_opt[1])/log(step_opt[1])-log(gamma_opt[0])/log(step_opt[1]);
-    double ngamma=log(gamma_opt[1]/gamma_opt[0])/log(step_opt[1]);
+    double ncost=log(ccost_opt[1])/log(10.0)-log(ccost_opt[0])/log(10.0);
+    double ngamma=log(gamma_opt[1])/log(10.0)-log(gamma_opt[0])/log(10.0);
     for(double ccost=ccost_opt[0];ccost<=ccost_opt[1];ccost*=step_opt[0]){
       for(double gamma=gamma_opt[0];gamma<=gamma_opt[1];gamma*=step_opt[1]){
 	x[0]=ccost;
diff --git a/src/apps/pkregression_nn.cc b/src/apps/pkregression_nn.cc
index 88155e0..1e052a1 100644
--- a/src/apps/pkregression_nn.cc
+++ b/src/apps/pkregression_nn.cc
@@ -22,8 +22,7 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include "base/Optionpk.h"
 #include "fileclasses/FileReaderAscii.h"
 #include "floatfann.h"
-#include "myfann_cpp.h"
-
+#include "algorithms/myfann_cpp.h"
 using namespace std;
 
 int main(int argc, char *argv[])
diff --git a/src/apps/pksieve.cc b/src/apps/pksieve.cc
index 39b01ca..7d373a5 100644
--- a/src/apps/pksieve.cc
+++ b/src/apps/pksieve.cc
@@ -74,6 +74,15 @@ int main(int argc,char **argv) {
   GDALProgressFunc pfnProgress=GDALTermProgress;
   pfnProgress(dfComplete,pszMessage,pProgressArg);
   
+  ImgReaderGdal maskReader;
+  GDALRasterBand *maskBand=NULL;
+  if(mask_opt.size()){
+    if(verbose_opt[0])
+      cout << "opening mask file " << mask_opt[0] << endl;
+    maskReader.open(mask_opt[0]);
+    maskBand = maskReader.getRasterBand(0);
+  }
+
   assert(input_opt.size());
   assert(output_opt.size());
   ImgReaderGdal inputReader(input_opt[0]);
@@ -85,17 +94,6 @@ int main(int argc,char **argv) {
   if(verbose_opt[0])
     cout << "opening output file " << output_opt[0] << endl;
   outputWriter.open(output_opt[0],inputReader);
-
-  ImgReaderGdal maskReader;
-  GDALRasterBand *maskBand=NULL;
-  if(mask_opt.size()){
-    if(verbose_opt[0])
-      cout << "opening mask file " << mask_opt[0] << endl;
-    maskReader.open(mask_opt[0]);
-    maskBand = maskReader.getRasterBand(0);
-    outputWriter.GDALSetNoDataValue(0);
-  }
-
   if(colorTable_opt.size()){
     if(colorTable_opt[0]!="none")
       outputWriter.setColorTable(colorTable_opt[0]);
@@ -103,7 +101,6 @@ int main(int argc,char **argv) {
   else if (inputReader.getColorTable()!=NULL)//copy colorTable from input image
     outputWriter.setColorTable(inputReader.getColorTable());
   outputBand = outputWriter.getRasterBand(0);
-
   //sieve filter to remove small raster elements (overwrite input band)
   if(size_opt[0]){
     if(GDALSieveFilter((GDALRasterBandH)inputBand, (GDALRasterBandH)maskBand, (GDALRasterBandH)outputBand, size_opt[0], connect_opt[0],NULL,pfnProgress,pProgressArg)!=CE_None)
diff --git a/src/apps/pkstatascii.cc b/src/apps/pkstatascii.cc
index a228158..6dbb3f1 100644
--- a/src/apps/pkstatascii.cc
+++ b/src/apps/pkstatascii.cc
@@ -59,7 +59,6 @@ int main(int argc, char *argv[])
   Optionpk<double> kde_opt("kde","kde","bandwith of kernel density when producing histogram, use 0 for practical estimation based on Silverman's rule of thumb. Leave empty if no kernel density is required");
   Optionpk<bool> correlation_opt("cor","correlation","calculate Pearson produc-moment correlation coefficient between two columns (defined by -c <col1> -c <col2>",false);
   Optionpk<bool> rmse_opt("rmse","rmse","calculate root mean square error between two columns (defined by -c <col1> -c <col2>",false);
-  Optionpk<bool> rrmse_opt("rrmse","rrmse","calculate relative root mean square error between two columns (defined by -c <col1> -c <col2>",false);
   Optionpk<bool> reg_opt("reg","regression","calculate linear regression error between two columns (defined by -c <col1> -c <col2>",false);
   Optionpk<short> verbose_opt("v", "verbose", "verbose mode when > 0", 0);
 
@@ -96,7 +95,6 @@ int main(int argc, char *argv[])
     kde_opt.retrieveOption(argc,argv);
     correlation_opt.retrieveOption(argc,argv);
     rmse_opt.retrieveOption(argc,argv);
-    rrmse_opt.retrieveOption(argc,argv);
     reg_opt.retrieveOption(argc,argv);
     verbose_opt.retrieveOption(argc,argv);
   }
@@ -196,14 +194,13 @@ int main(int argc, char *argv[])
     if(median_opt[0])
       cout << "median value column " << col_opt[icol] << ": " << stat.median(dataVector[icol]) << endl;
     if(minmax_opt[0]){
-      cout << "min value column " << col_opt[icol] << ": " << stat.min(dataVector[icol]) << endl;
-      cout << "max value column " << col_opt[icol] << ": " << stat.max(dataVector[icol]) << endl;
+      cout << "min value column " << col_opt[icol] << ": " << stat.mymin(dataVector[icol]) << endl;
+      cout << "max value column " << col_opt[icol] << ": " << stat.mymax(dataVector[icol]) << endl;
     }
     if(min_opt[0])
-      cout << "min value column " << col_opt[icol] << ": " << stat.min(dataVector[icol]) << endl;
+      cout << "min value column " << col_opt[icol] << ": " << stat.mymin(dataVector[icol]) << endl;
     if(max_opt[0])
-      cout << "max value column " << col_opt[icol] << ": " << stat.max(dataVector[icol]) << endl;
-
+      cout << "max value column " << col_opt[icol] << ": " << stat.mymax(dataVector[icol]) << endl;
     if(histogram_opt[0]){
       //todo: support kernel density function and estimate sigma as in practical estimate of the bandwith in http://en.wikipedia.org/wiki/Kernel_density_estimation
       double sigma=0;
@@ -220,8 +217,62 @@ int main(int argc, char *argv[])
         else
           std::cout << "calculating histogram for col " << icol << std::endl;
       }
+      //test
+      // cout << "debug0" << endl;
+      // cout << "dataVector.size(): " << dataVector.size() << endl;
+      // cout << "statVector.size(): " << statVector.size() << endl;
+
+      // double theMinValue=0;
+      // double theMaxValue=0;
+      
+      // stat.minmax(dataVector[icol],dataVector[icol].begin(),dataVector[icol].end(),theMinValue,theMaxValue);
+      // if(minValue<maxValue&&minValue>theMinValue)
+      // 	theMinValue=minValue;
+      // if(minValue<maxValue&&maxValue<theMaxValue)
+      // 	theMaxValue=maxValue;
+
+      // //todo: check...
+      // minValue=theMinValue;
+      // maxValue=theMaxValue;
 
+      // if(maxValue<=minValue){
+      // 	std::ostringstream s;
+      // 	s<<"Error: could not calculate distribution (min>=max)";
+      // 	throw(s.str());
+      // }
+      // assert(nbin);
+      // assert(dataVector[icol].size());
+      // if(statVector[icol].size()!=nbin){
+      // 	statVector[icol].resize(nbin);
+      // 	for(int i=0;i<nbin;statVector[icol][i++]=0);
+      // }
+      // typename std::vector<double>::const_iterator it;
+      // for(it=dataVector[icol].begin();it!=dataVector[icol].end();++it){
+      // 	if(*it<minValue)
+      // 	  continue;
+      // 	if(*it>maxValue)
+      // 	  continue;
+      // 	if(stat.isNoData(*it))
+      // 	  continue;
+      // 	int theBin=0;
+      // 	if(*it==maxValue)
+      // 	  theBin=nbin-1;
+      // 	else if(*it>minValue && *it<maxValue)
+      // 	  theBin=static_cast<int>(static_cast<double>((nbin-1)*(*it)-minValue)/(maxValue-minValue));
+      // 	assert(theBin<statVector[icol].size());
+      // 	++statVector[icol][theBin];
+      // 	// if(*it==maxValue)
+      // 	//   ++statVector[icol][nbin-1];
+      // 	// else if(*it>=minValue && *it<maxValue)
+      // 	//   ++statVector[icol][static_cast<int>(static_cast<double>((*it)-minValue)/(maxValue-minValue)*nbin)];
+      // }
+
+      // exit(0);
+      //end test
+      
       stat.distribution(dataVector[icol],dataVector[icol].begin(),dataVector[icol].end(),statVector[icol],nbin,minValue,maxValue,sigma);
+      //test
+      cout << "debug1" << endl;
       if(verbose_opt[0])
         std::cout << "min and max values: " << minValue << ", " << maxValue << std::endl;
     }
@@ -234,10 +285,6 @@ int main(int argc, char *argv[])
     assert(dataVector.size()==2);
     cout << "root mean square error between columns " << col_opt[0] << " and " << col_opt[1] << ": " << stat.rmse(dataVector[0],dataVector[1]) << endl;
   }
-  if(rrmse_opt[0]){
-    assert(dataVector.size()==2);
-    cout << "relative root mean square error between columns " << col_opt[0] << " and " << col_opt[1] << ": " << stat.rrmse(dataVector[0],dataVector[1]) << endl;
-  }
   if(reg_opt[0]){
     assert(dataVector.size()==2);
     double c0=0;
@@ -253,6 +300,7 @@ int main(int argc, char *argv[])
       else
 	binValue=minValue+static_cast<double>(maxValue-minValue)*(irow+0.5)/nbin;
       std::cout << binValue << " ";
+      // std::cout << minValue+static_cast<double>(maxValue-minValue)*(irow+0.5)/nbin << " ";
       for(int icol=0;icol<col_opt.size();++icol){
         if(relative_opt[0])
           std::cout << 100.0*static_cast<double>(statVector[icol][irow])/static_cast<double>(dataVector[icol].size());
diff --git a/src/base/Makefile.am b/src/base/Makefile.am
index 23345e2..efde6a4 100644
--- a/src/base/Makefile.am
+++ b/src/base/Makefile.am
@@ -26,7 +26,7 @@ libbase_la_HEADERS = $(top_srcdir)/config.h Vector2d.h IndexValue.h Optionpk.h P
 
 # the sources to add to the library and to add to the source distribution
 ###############################################################################
-libbase_la_SOURCES = Optionpk.cc $(libbase_la_HEADERS)
+libbase_la_SOURCES = $(libbase_la_HEADERS)
 
 # list of sources for the binaries
 pktestOption_SOURCES = pktestOption.cc
diff --git a/src/base/Optionpk.h b/src/base/Optionpk.h
index f790804..9c07f43 100644
--- a/src/base/Optionpk.h
+++ b/src/base/Optionpk.h
@@ -29,7 +29,9 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include <iomanip>
 #include <sstream>
 #include <typeinfo>
+#ifndef WIN32
 #include <cxxabi.h>
+#endif
 #include "ogr_feature.h"
 
 #ifdef HAVE_CONFIG_H
@@ -112,6 +114,7 @@ public:
   void setHelp(const std::string& helpInfo){m_help=helpInfo;};
   bool retrieveOption(int argc, char ** argv);
   template<class T1> friend std::ostream& operator<<(std::ostream & os, const Optionpk<T1>& theOption);
+
   void setAll(const std::string& shortName, const std::string& longName, const std::string& helpInfo);
   void setAll(const std::string& shortName, const std::string& longName, const std::string& helpInfo,const T& defaultValue, short hide);
   void setDefault(const T& defaultValue);
@@ -233,7 +236,8 @@ template<class T> inline std::string Optionpk<T>::usageDoxygen() const
   else
     helpss << std::setiosflags(std::ios::left) << "                     | ";
   int status;
-  helpss << std::setiosflags(std::ios::left) << std::setw(4) << abi::__cxa_demangle(typeid(T).name(),0,0,&status) << " | ";
+  helpss << std::setiosflags(std::ios::left) << std::setw(4) << typeid(T).name() << " | ";
+  //helpss << std::setiosflags(std::ios::left) << std::setw(4) << abi::__cxa_demangle(typeid(T).name(),0,0,&status) << " | ";
   if(m_hasDefault)
     helpss <<std::setiosflags(std::ios::left) << std::setw(5) << type2string<T>(m_defaultValue) << " |";
   else
@@ -263,6 +267,7 @@ template<class T> inline void Optionpk<T>::setAll(const std::string& shortName,
   m_hide=hide;
 }
 
+
 template<class T> inline Optionpk<T>::~Optionpk() 
 {
 }
@@ -338,104 +343,6 @@ template<class T> inline bool Optionpk<T>::retrieveOption(int argc, char **argv)
   return(noHelp);
 }
 
-//todo: to be put in .cc file
-/////////////////// Specializations /////////////////
-
-///specialization for string
-template<> inline std::string string2type(std::string const& s){
-  return s;
-}
-
-///specialization for OGRFieldType
-template<> inline OGRFieldType string2type(std::string const& s){
-  OGRFieldType ftype;
-  int ogr_typecount=11;//hard coded for now!
-  for(int iType = 0; iType < ogr_typecount; ++iType){
-    if( OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType) != NULL
-        && EQUAL(OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType),s.c_str()))
-      ftype=(OGRFieldType) iType;
-  }
-  return ftype;
-}
-
-///specialization for bool
-template<> inline std::string type2string(bool const& value){
-  if(value)
-    return("true");
-  else
-    return("false");
-}
-
-///specialization for string
-template<> inline std::string type2string(std::string const& value){
-  // if(value.empty())
-  //   return("<empty string>");
-  // else
-    return(value);
-}
-
-///specialization for float
-template<> inline std::string type2string(float const& value){
-  std::ostringstream oss;
-  // oss.precision(1);
-  // oss.setf(ios::fixed);
-  oss << value;
-  return oss.str();
-}
-
-///specialization for double
-template<> inline std::string type2string(double const& value){
-  std::ostringstream oss;
-  // oss.precision(1);
-  //  oss.setf(ios::fixed);
-  oss << value;
-  return oss.str();
-}
-
-///specialization for bool
-template<> inline void Optionpk<bool>::setAll(const std::string& shortName, const std::string& longName, const std::string& helpInfo)
-{
-  m_shortName=shortName;
-  m_longName=longName;
-  m_hasArgument=false;
-  m_help=helpInfo;
-  m_hide=0;
-}
-
-///specialization for bool
-template<> inline void Optionpk<bool>::setAll(const std::string& shortName, const std::string& longName, const std::string& helpInfo,const bool& defaultValue, short hide)
-{
-  m_shortName=shortName;
-  m_longName=longName;
-  m_hasArgument=false;
-  m_help=helpInfo;
-  m_defaultValue=defaultValue;
-  m_hasDefault=true;
-  m_hide=hide;
-}
-
-///specialization for bool
-template<> inline Optionpk<bool>::Optionpk(const std::string& shortName, const std::string& longName, const std::string& helpInfo)
-{
-  setAll(shortName,longName,helpInfo);
-}
-
-///specialization for bool
-template<> inline Optionpk<bool>::Optionpk(const std::string& shortName, const std::string& longName, const std::string& helpInfo,const bool& defaultValue, short hide)
-{
-  setAll(shortName,longName,helpInfo,defaultValue, hide);
-}
-
-//specialization (only makes sense for T=std::string), generic function throws exception
-//find a substring in string option (e.g., option is of type -co INTERLEAVE=BAND)
-template<> inline std::vector<std::string>::const_iterator Optionpk<std::string>::findSubstring(const std::string& argument) const{
-  std::vector<std::string>::const_iterator opit=this->begin();
-  while(opit!=this->end()){
-    if(opit->find(argument)!=std::string::npos)
-      break;
-    ++opit;
-  }
-  return opit;
-}
+//template<class T> typename std::vector<T>::const_iterator Optionpk<T>::findSubstring(const T& argument) const {std::string errorString="Error: findSubstring only defined for options of type std::string"; throw(errorString);}
 
 #endif
diff --git a/src/base/Vector2d.h b/src/base/Vector2d.h
index a10c192..12ac813 100644
--- a/src/base/Vector2d.h
+++ b/src/base/Vector2d.h
@@ -66,7 +66,7 @@ public:
 //   template<class T> std::ostream& operator<<(std::ostream& os, const Vector2d<T>& v);
   template<class T1> friend std::ostream& operator<<(std::ostream & os, const Vector2d<T1>& v);
   Vector2d<T> sum(const Vector2d<T>& v1, const Vector2d<T>& v2) const;
-  T max(int& x, int& y, double maxValue) const;
+  T mymax(int& x, int& y, double maxValue) const;
 
   T sum() const;
 };
@@ -285,7 +285,7 @@ template<class T> T Vector2d<T>::sum() const{
   return theSum;
 }
 
-template<class T> T Vector2d<T>::max(int& x, int& y, double maxValue) const{
+template<class T> T Vector2d<T>::mymax(int& x, int& y, double maxValue) const{
   //todo: what if this->operator[](0)[0] >=maxValue?
   // double theMax=(this->operator[](0))[0];
   double theMax=0;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pktools.git



More information about the Pkg-grass-devel mailing list