Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00059
00060
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