[pktools] 192/375: porting to windows from linux
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 6328ba7ae06ab2daec84be7ed8c8a0e55a6bb285
Author: Default Seadas User <seadas-user at localhost>
Date: Mon Mar 10 17:04:29 2014 +0100
porting to windows from linux
---
src/apps/pkclassify_svm.cc | 8 +--
src/apps/pkextract.cc | 134 +++++++++++++++++++++++++++++++++++++--------
src/base/Optionpk.cc | 95 --------------------------------
src/base/Optionpk.h | 102 +++++++++++++++++++++++++++++++++-
4 files changed, 215 insertions(+), 124 deletions(-)
diff --git a/src/apps/pkclassify_svm.cc b/src/apps/pkclassify_svm.cc
index 1ed2ffa..b7d24c2 100644
--- a/src/apps/pkclassify_svm.cc
+++ b/src/apps/pkclassify_svm.cc
@@ -847,7 +847,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])
@@ -887,7 +887,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);
@@ -895,7 +895,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){
@@ -1061,7 +1061,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/pkextract.cc b/src/apps/pkextract.cc
index eac8c8d..101f103 100644
--- a/src/apps/pkextract.cc
+++ b/src/apps/pkextract.cc
@@ -242,7 +242,7 @@ int main(int argc, char *argv[])
void* pProgressArg=NULL;
GDALProgressFunc pfnProgress=GDALTermProgress;
double progress=0;
- srandom(time(NULL));
+ srand(time(NULL));
bool sampleIsRaster=false;
ImgReaderOgr sampleReaderOgr;
@@ -423,7 +423,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>(random())/(RAND_MAX);
+ double p=static_cast<double>(rand())/(RAND_MAX);
p*=100.0;
if(p>theThreshold)
continue;//do not select for now, go to next column
@@ -667,7 +667,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>(random())/(RAND_MAX);
+ double p=static_cast<double>(rand())/(RAND_MAX);
p*=100.0;
if(p>theThreshold)
continue;//do not select for now, go to next column
@@ -887,24 +887,6 @@ 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
@@ -914,6 +896,25 @@ 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();
@@ -1161,7 +1162,27 @@ 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;
@@ -1348,6 +1369,29 @@ 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;
@@ -1448,7 +1492,7 @@ int main(int argc, char *argv[])
break;
}
}
- }
+ }
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)
//write feature
@@ -1784,6 +1828,27 @@ 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;
@@ -1969,6 +2034,29 @@ 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;
diff --git a/src/base/Optionpk.cc b/src/base/Optionpk.cc
index 07a326f..a89b2cf 100644
--- a/src/base/Optionpk.cc
+++ b/src/base/Optionpk.cc
@@ -21,98 +21,3 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "Optionpk.h"
-///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);
-
-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);
-
-///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,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;
-}
diff --git a/src/base/Optionpk.h b/src/base/Optionpk.h
index 38cda5f..f790804 100644
--- a/src/base/Optionpk.h
+++ b/src/base/Optionpk.h
@@ -112,7 +112,6 @@ 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);
@@ -264,7 +263,6 @@ template<class T> inline void Optionpk<T>::setAll(const std::string& shortName,
m_hide=hide;
}
-
template<class T> inline Optionpk<T>::~Optionpk()
{
}
@@ -340,4 +338,104 @@ 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;
+}
+
#endif
--
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