PerceptionPrimitive.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 by Ulrich Friedrich Klank <klank@in.tum.de>
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 /************************************************************************
00020                         PerceptionPrimitive.h - Copyright klank
00021 
00022 
00023 **************************************************************************/
00024 
00025 #ifndef PERCEPTIONPRIMITIVE_H
00026 #define PERCEPTIONPRIMITIVE_H
00027 
00028 
00029 #include "Signature.h"
00030 #include "AlgorithmEval.h"
00031 #include "Sensor.h"
00032 
00033 namespace cop
00034 {
00035   enum PerceptionPrimitiveState
00036   {
00037     PP_STARTED,
00038     PP_TERMINATED,
00039     PP_EVALUATING,
00040     PP_EVALUATING_RUNNING,
00041     PP_EVALUATED,
00042     PP_DELETABLE
00043   };
00044 
00045   template< typename T>
00046   bool find_in_vec(std::vector<T> list, T id)
00047   {
00048     for(size_t i = 0; i < list.size(); i++)
00049     {
00050       if(list[i] == id)
00051         return true;
00052     }
00053     return false;
00054   }
00055 
00056 
00057   /************************************************************************
00058   *  class PerceptionPrimitive
00059   *  @brief Describes the entity created by each call of cop in order
00060   *         to answer a query and enable later evaluation (short name PP)
00061   **************************************************************************/
00062   class PerceptionPrimitive
00063   {
00064   public:
00070     PerceptionPrimitive(Signature* sig) :
00071       m_evaluation(0),
00072       m_timing(0),
00073       m_count(0),
00074       m_startTime(time(NULL)),
00075       m_uniqueID(m_lastID++),
00076       m_currState(PP_STARTED)
00077     {
00078       m_signatures.push_back(sig);
00079     }
00080 
00081     ~PerceptionPrimitive()
00082     {
00083       printf("Creating time: %ld\n", m_startTime);
00084     }
00089     Signature* GetSignature(size_t index = 0){return m_signatures[index];}
00090     PerceptionPrimitiveID_t GetID(){return m_uniqueID;}
00099     void AddResult(Evaluable* alg, Evaluator* eval, ObjectID_t id, double quality =  1.0, unsigned long calctime = 0)
00100     {
00101       m_results.push_back(id);
00102       bool found = false;
00103       for(size_t i = 0; i < m_AlgorithmIDs.size(); i++)
00104       {
00105         if(m_AlgorithmIDs[i].first == alg)
00106         {
00107           found = true;
00108         }
00109       }
00110       if(!found)
00111         m_AlgorithmIDs.push_back(std::pair<Evaluable*, Evaluator*>(alg, eval));
00112 
00113       m_evaluation += quality;
00114       m_timing += calctime;
00115       m_count++;
00116     }
00117 
00118     void SetTerminated()
00119     {
00120       if(m_currState == PP_EVALUATED)
00121         m_currState = PP_DELETABLE;
00122       else if (m_currState == PP_TERMINATED)
00123         printf("State transition from PP_TERMINATED to PP_TERMINATED\n");
00124       else if(m_currState == PP_EVALUATING_RUNNING)
00125         m_currState = PP_EVALUATING;
00126       else
00127         m_currState = PP_TERMINATED;
00128     }
00129 
00130     void SetEvaluated()
00131     {
00132        if(m_currState == PP_TERMINATED || m_currState == PP_EVALUATING)
00133         m_currState = PP_DELETABLE;
00134       else
00135         m_currState = PP_EVALUATED;
00136     }
00137     void SetEvaluating()
00138     {
00139       if(m_currState == PP_TERMINATED)
00140         m_currState = PP_EVALUATING;
00141       else
00142         m_currState = PP_EVALUATING_RUNNING;
00143     }
00144 
00145     PerceptionPrimitiveState GetCurrState(){return m_currState;}
00146     std::vector<Signature*> m_signatures;
00147     std::vector< std::pair<Evaluable*, Evaluator*> > m_AlgorithmIDs;
00148     std::vector<Sensor*> m_sensors;
00149 
00150     std::vector<ObjectID_t> m_results;
00151     double        m_evaluation;
00152     unsigned long m_timing;
00153     unsigned long m_count;
00154     time_t        m_startTime;
00155   private:
00156     PerceptionPrimitiveID_t m_uniqueID;
00157     static PerceptionPrimitiveID_t m_lastID;
00158     PerceptionPrimitiveState m_currState;
00159   };
00160 }
00161 #endif /* PERCEPTIONPRIMITIVE_H*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


cognitive_perception
Author(s): Ulrich F Klank
autogenerated on Thu May 23 2013 07:38:34