pointFilter.h

Go to the documentation of this file.
00001 
00002 
00003 #include <stdint.h>
00004 #include <vector>
00005 #include <map>
00006 #include <iostream>
00007 #include <string>
00008 #include "assert.h"
00009 #include <boost/foreach.hpp>
00010 #include "random.h"
00011 #include <utility>
00012 #include <boost/spirit.hpp> 
00013 //#include <boost/spirit/home/classic/tree/common.hpp>
00014 //#include <boost/spirit/include/classic_parse_tree.hpp>
00015 //#include <boost/spirit/include/classic_parse_tree_utils.hpp>
00016 //#include <boost/spirit/include/classic.hpp>
00017 //#include <boost/spirit/include/classic_core.hpp>
00018 //#include <boost/spirit/home/classic/meta.hpp>
00019 //#include <boost/spirit/home/classic/core.hpp>
00020 //#include <boost/spirit/home/classic/core/non_terminal/grammar.hpp>
00021 
00022 //#include <boost/spirit/include/classic_primitives.hpp>
00023 //#include <boost/spirit/include/classic_grammar_def.hpp>
00024 
00025 
00026 using boost::spirit::rule;
00027 
00028 using boost::spirit::ch_p;
00029 using boost::spirit::str_p;
00030 using boost::spirit::int_p;
00031 using boost::spirit::assign_a;
00032 using boost::spirit::parse_info;
00033 
00034 
00035 //const rule<>  space_rule_g = ( (boost::spirit::space_p>> *( str_p("\t")) >> boost::spirit::space_p ) |boost::spirit:: eps_p );
00036 const rule<>  space_rule_g = ( (boost::spirit::space_p) | boost::spirit:: eps_p );
00037 //const rule<>  space_rule_g =  (boost::spirit::space_p);
00038 //const rule<>  space_rule_g = *(*( str_p("\t")|boost::spirit:: eps_p) >> *(boost::spirit::space_p|boost::spirit:: eps_p)  );
00039 const rule<>  spacy_colon_g = space_rule_g >> ch_p(',') >> space_rule_g;
00040 
00041 
00042 
00043 
00044 
00045 
00053 class PointFilterKey
00054 {
00057                 uint16_t        exactVanishedFocalValues_m;
00058                 uint16_t        jacobianRank_m;
00059                 bool    smooth_m;
00060                 uint16_t        quadricsRank_m;
00063 
00064 
00065         const rule<>* pointFilterKeyRule_m;
00066 
00067         static const bool trueValue_m;
00068         static const bool falseValue_m;
00069 
00070 
00071         
00077         const rule<> * initRule();
00078 
00079         public:
00080                 PointFilterKey();
00081 
00082                 PointFilterKey(std::string str);
00083         
00084                 PointFilterKey( uint16_t exactVanishedFocalValues,      
00085                                         uint16_t        jacobianRank,
00086                                         bool    smooth,
00087                                         uint16_t        quadricsRank
00088                                         );
00089         
00090                 
00091                 
00092                 // funktion kann selbst nicht konst sein, da das Parsen das Objekt beeinflussen w├╝rde.
00094                 const rule<> &  getConstRuleRef()               {       return *pointFilterKeyRule_m;           }
00095 
00096                 //const rule<> *        getRulePtr()            {       return pointFilterKeyRule_m;            }
00097 
00099                 bool operator<(const PointFilterKey& pfkey)     const;
00100 
00102                 void print(std::ostream &os)    const;
00103 };
00104 
00105 
00106 
00114 class PointFilterRule
00115 {
00118                 const rule<> * pointFilterRule_m;
00119 
00120 
00122                 PointFilterKey  key_m;
00123 
00124                 uint32_t        passFilterRate_m;
00125 
00126         
00127 
00128         public:
00129 
00130                 PointFilterRule();
00131         
00132 
00139                 PointFilterRule(std::string str) ;
00140 
00142                 PointFilterRule(        const PointFilterKey & key, 
00143                                         uint64_t        filterRate              ) ;
00144         
00147                 PointFilterRule(        uint16_t exactVanishedFocalValues,      
00148                                         uint16_t        jacobianRank,
00149                                         bool    smooth,
00150                                         uint16_t        quadricsRank,
00151                                         uint64_t        passFilterRate
00152                                         );
00153 
00154         
00155                 const rule<>* initRule();
00156         
00158                 const rule<> &          getRuleRef()                    {       return *pointFilterRule_m;      }
00159 
00160                 uint32_t                        getPassFilterRate()     const   {       return passFilterRate_m;                }
00161                 
00163                 const PointFilterKey&   getKeyConstRef()        const           {       return key_m;                   }
00164 
00166                 bool operator<(const PointFilterRule& rule)     const   {       return key_m<rule.key_m;        }
00167 
00169                 void    print(std::ostream & os);
00170 
00171 };
00172 
00173  
00185 class CFilterStrategy
00186 {
00187         public:
00188                 
00189                 //std::string name_m;
00190 
00191                 enum FilterStrategy
00192                 {
00193                         CF_FILTER_UNDEFINED,
00194                         CF_FILTER_RANDOM_START, // point counter is randomly initialized at the begin
00195                         CF_FILTER_RANDOM_SYNC,  // every time a random  number is generated 
00196                         CF_FILTER_SAVE_FIRST            // point counter is initialized in a such way that the first detected point is stored.
00197                 };
00198 
00199         protected:
00200 
00201                 FilterStrategy  strategy_m;
00202 
00203         public:
00204 
00205                 static const    CFilterStrategy FilterRandomStart_Strategy_s, 
00206                                                                 FilterRandomSync_Strategy_s, 
00207                                                                 FilterSaveFirst_Strategy_s;
00208 
00209                 static const    std::string     cfRandomStartStr_s, 
00210                                                                 cfRandomSyncStr_s, 
00211                                                                 cfSaveFirstStr_s;
00212                 
00213         
00214                 CFilterStrategy(std::string strFilterStrategy);
00215 
00216                 CFilterStrategy( CFilterStrategy::FilterStrategy strategy );
00217 
00219                 int                     integral()              const           {       return strategy_m;      }
00220 
00221                 std::string     getValueAsString();
00222 
00223                 void    printValue(std::ostream & os)                   {       os << getValueAsString();       }
00224 
00225 };
00226 
00227 
00228 
00229 class CFPointFilter;
00230 
00231 
00235 struct rule_term_scanned
00236 {
00237         
00238     rule_term_scanned(CFPointFilter& pfk)       : pfk_m(pfk) 
00239         {
00240         }
00241 
00242         void  operator()(char const* first, char const* last) const;
00243 
00244        CFPointFilter&    pfk_m;
00245 };
00246 
00247 
00248 
00249 
00252 
00255 class CFPointFilter
00256 {
00257 
00258         private:
00259 
00265                 struct FilterRateCounterPair
00266                 {
00267                 
00268                         uint32_t        passFilterRate_m;
00269                 
00270                         public:
00271                         
00272                                 mutable         uint32_t                counter_m;
00273                         
00274                                 FilterRateCounterPair() : passFilterRate_m(1),
00275                                                                                                 counter_m(0)
00276                                 {}
00277                 
00278                                 FilterRateCounterPair(  uint32_t        filterRate, 
00279                                                                 uint32_t        counter ) :  passFilterRate_m(filterRate),
00280                                                                                                         counter_m(counter)
00281                         {}
00282                         
00283                         uint32_t        getPassFilterRate()     const           {       return  passFilterRate_m;       }
00284                 };
00285 
00286 
00287                 long    randomSeed_m ;
00288         
00289                 long &  randomSeedRef_m ;
00290 
00291                 CFilterStrategy         strategy_m;
00292 
00294                 rule_term_scanned       *       singleRuleScannedTrigger_m;
00295 
00296                 std::string     name_m;
00297         
00298                 //typedef std::map<unsigned short, boost::any>  hierarchicalFilterRuleMap_Type;
00299                 typedef  std::map< const PointFilterKey, FilterRateCounterPair >  hierarchicalFilterRuleMap_Type;
00300         
00301                 mutable hierarchicalFilterRuleMap_Type  hierarchicalFilterRules_m;
00302 
00303 
00304 
00305 
00306 
00307 
00308         public:
00309 
00310                 static double seedFromTime()
00311                 {
00312                         time_t tt;
00313                         time(&tt);
00314                         return tt;
00315                 }
00316         
00317         
00318                 CFPointFilter( CFilterStrategy strategy, std::vector<PointFilterRule>   filterRules, 
00319                                         std::string name,       long & randomSeedRef);
00320         
00321                 CFPointFilter( CFilterStrategy strategy, std::vector<PointFilterRule>   filterRules ,
00322                                         std::string name );
00323 
00324                 CFPointFilter( CFilterStrategy strategy , std::string name );
00325 
00326                 
00327 
00335                 CFPointFilter( std::string str ,
00336                                   CFilterStrategy strategy,
00337                                   std::string name ) ;
00338 
00339                 
00340                 void onRuleScanned(std::string str);
00341 
00342         
00343                 void   addFilterRule    (       uint16_t        exactVanishedFocalValues,
00344                                                         uint16_t        jacobianRank,
00345                                                         bool    smooth,
00346                                                         uint16_t        quadricsRank,
00347                                                         uint32_t        filterRate )    ;
00348         
00349                 void    addFilterRule(const PointFilterRule & fr);
00350                 
00351                 bool   pointPassedFilter(       uint16_t        exactVanishedFocalValues,
00352                                                         uint16_t        jacobianRank,
00353                                                         bool    smooth,
00354                                                         uint16_t        quadricsRank)   const   ;
00355         
00356         
00357                 void print(std::ostream & os);
00358                 void printInMacaulayStyle(std::ostream & os);
00359 };
00360 
00361 
00362 
00363 
00364 void    rule_term_scanned::operator()(char const* first, char const* last) const
00365 {
00366                 std::string str(first, last);
00367                 
00368                 pfk_m.onRuleScanned(str);
00369 }
00370 
00371 
00372 #include "pointFilter.hpp"
Generated on Tue Nov 23 13:10:52 2010 for centerfocus by  doxygen 1.6.3