AutoParameterExplorer.h
Go to the documentation of this file.
00001 #ifndef FACE_CONTOUR_DETECTOR_AUTOPARAMETEREXPLORER_H_
00002 #define FACE_CONTOUR_DETECTOR_AUTOPARAMETEREXPLORER_H_
00003 
00004 #include <ros/ros.h>
00005 
00006 //std
00007 #include <vector>
00008 #include <utility>
00009 #include <string>
00010 #include <map>
00011 #include <functional>
00012 #include <algorithm>
00013 
00014 //boost
00015 #include <boost/function.hpp>
00016 
00017 //cassert
00018 #include <cassert>
00019 
00020 #include <face_contour_detector/LimitedPriorityQueueSet.h>
00021 
00022 namespace face_contour_detector {
00023 
00029         class AutoParameterExplorer {
00030         private:
00031                 class Vector;
00032                 class Area;
00033                 class ParameterPoint {
00034                 public:
00036                         ParameterPoint();
00039                         ParameterPoint(const ParameterPoint& other);
00040 
00043                         void AddParam(double value);
00046                         std::vector<double>& Params() { return m_params; }
00049                         const std::vector<double>& Params() const { return m_params; }
00050 
00054                         AutoParameterExplorer::ParameterPoint Midpoint(AutoParameterExplorer::ParameterPoint& other);
00055 
00059                         Vector VectorTo(const ParameterPoint& other);
00063                         ParameterPoint operator+ (const Vector& vector);
00064 
00067                         inline bool HasCosts() const { return m_costsSet; }
00071                         inline double Costs() const { assert(m_costsSet); return m_costs; }
00074                         inline void Costs(double costs) { m_costsSet = true; m_costs = costs;}
00075 
00077                         struct LessCosts {
00078                                 bool operator() (const ParameterPoint& x, const ParameterPoint& y) const {return x.Costs()<y.Costs();}
00079                         };
00080 
00081                 private:
00082                         std::vector<double> m_params;
00083                         bool m_costsSet;
00084                         double m_costs;
00085                 };
00086 
00087         public:
00091                 AutoParameterExplorer(boost::function<void (const std::vector<double>&, std::map<std::string, double>&)> paramsFunction, boost::function<double (const std::map<std::string, double>&, const std::map<std::string, double>&)> costFunction);
00093                 virtual ~AutoParameterExplorer();
00099                 void AddParameter(const std::string& name, double min, double max);
00106                 void FindBest(std::map<std::string, double> targetValue, int steps, int numResults, std::vector<std::map<std::string, double> >& results);
00107 
00108         private:
00109                 //Vars
00110                 std::vector<std::string> m_paramNames;
00111                 std::vector<std::pair<double,double> > m_startEnd;
00112                 boost::function<void (const std::vector<double>&, std::map<std::string, double>&)> m_paramsFunction;
00113                 boost::function<double (const std::map<std::string, double>&, const std::map<std::string, double>&)> m_costsFunction;
00114 
00115                 //methods
00116                 void M_GetCosts(std::map<std::string, double>& targetValue, ParameterPoint& paramPoint);
00117                 void M_GetCosts(std::map<std::string, double>& targetValue, Area& area);
00118                 bool M_IsTargetValueInside(std::map<std::string, double>& targetValue, Area& area);
00119                 void M_PushAllPoints(Area& area, std::map<std::string, double>& targetValues, face_contour_detector::LimitedPriorityQueueSet<ParameterPoint, ParameterPoint::LessCosts>& results);
00120 
00121                 //sub classes
00122 
00124                 class Vector {
00125                 public:
00127                         Vector();
00130                         Vector(const Vector& other);
00131 
00134                         void AddParam(double value);
00138                         Vector operator+(const Vector& other);
00142                         Vector operator*(double factor);
00143 
00145                         std::vector<double> values;
00146                 };
00147 
00148 
00149                 class Area {
00150                 public:
00151                         Area(const ParameterPoint& base);
00152                         void AddDimension(double value);
00153 
00154                         ParameterPoint Middle();
00155                         void SubAreas(std::vector<Area>& result);
00156                         void EdgePoints(std::vector<ParameterPoint>& result);
00157 
00158                         ParameterPoint base;
00159                         std::vector<double> dimensions;
00160 
00161                         bool HasCosts() const;
00162 
00163                         void Costs(double costs);
00164                         double Costs() const;
00165 
00166                         struct GreaterCosts {
00167                                 bool operator() (const Area& x, const Area& y) const;
00168                         };
00169 
00170                 private:
00171                         bool m_hasCosts;
00172                         double m_costs;
00173 
00174                         inline static unsigned int M_UIntPower2(unsigned int exponent) {
00175                                 return (unsigned int)1 << exponent;
00176                         }
00177                 };
00178         };
00179 
00180 } //namespace face_contour_detector
00181 
00182 template<class OStream>
00183 OStream& operator<< (OStream& os, const face_contour_detector::AutoParameterExplorer::ParameterPoint& obj) {
00184         os<<"Point(";
00185     std::vector<double>::const_iterator it;
00186     for (it = obj.Params().begin(); it != obj.Params().end(); it++) {
00187         os<<*it<<", ";
00188     }
00189     os<<")";
00190         return os;
00191 }
00192 
00193 template<class OStream>
00194 OStream& operator<< (OStream& os, const face_contour_detector::AutoParameterExplorer::Area& obj) {
00195         os<<"Area(base[";
00196     std::vector<double>::const_iterator it;
00197     for (it = obj.base.Params().begin(); it != obj.base.Params().end(); it++) {
00198         os<<*it<<", ";
00199     }
00200     os<<"], ";
00201     for (it = obj.dimensions.begin(); it != obj.dimensions.end(); it++) {
00202         os<<*it<<", ";
00203     }
00204     os<<"C=";
00205     if (obj.HasCosts()) {
00206         os<<obj.Costs();
00207     } else {
00208         os<<"none";
00209     }
00210     os<<")";
00211         return os;
00212 }
00213 
00214 #endif //FACE_CONTOUR_DETECTOR_AUTOPARAMETEREXPLORER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends


face_contour_detector
Author(s): Fabian Wenzelmann and Julian Schmid
autogenerated on Wed Dec 26 2012 16:18:17