SignatureDB.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                         SignatureDB.h - Copyright klank
00021 
00022 
00023 **************************************************************************/
00024 
00025 
00026 #ifndef SIGNATUREDB_H
00027 #define SIGNATUREDB_H
00028 
00029 #include <string>
00030 #include <vector>
00031 
00032 #include "XMLTag.h"
00033 #include "PerceptionPrimitive.h"
00034 #ifndef XML_NODE_SIGNATURE
00035 #define XML_NODE_SIGNATURE "Signature"
00036 #endif
00037 
00038 #define XML_NODE_SIGNATUREDB "SignatureDB"
00039 
00040 #define PROP_DECAY       0.01
00041 #define STARTING_WEIGHT  0.25
00042 
00043 namespace cop
00044 {
00045 
00046   typedef struct
00047   {
00048      RelPose* pose;
00049      double quality;
00050      Sensor* camera;
00051      Algorithm<std::vector<RelPose*> > * alg;
00052      Signature* signature;
00053   } Results_t;
00054 
00059   class SignatureDB
00060   {
00061   public:
00062 
00063     // Constructors/Destructors
00064     //
00065 
00066 
00071     SignatureDB ( XMLTag* config );
00072 
00076     virtual ~SignatureDB ( );
00077 
00078     // Methods
00079     //
00080     void UpdateNodes(Signature* sig, int index);
00084     int AddSignature(Signature* sig);
00085     void AddSignatures(std::vector<Results_t> matches);
00086   #ifdef BOOST_THREAD
00087     void AddAndShowSignatureAsync(Signature* sig, Sensor* sens);
00088     void AddAndShowSignaturesAsync(std::vector<Results_t> &all_matches, const int &num_results_accepted);
00089   #endif
00090 
00094     void FreeActiveSignature(Signature* sig);
00095       /***
00096       *   Adds a class to the database
00097       *  @returns an id if the string already exists
00098       */
00099     int AddClass(std::string stname, int id);
00103     Signature* GetSignatureByID(ObjectID_t ElemID);
00104 
00105     /*******************************************************************************
00106     *   GetClassByID                                                              */
00107     /*******************************************************************************
00108     *
00109     * @brief Direct Request for a class
00110     * @remarks throws on error a char* Exception
00111     *
00112     *******************************************************************************/
00113     Class* GetClassByID(ObjectID_t id);
00117     Signature* GetSignatureByClass(ObjectID_t ClassID, int index = 0);
00118     Signature* GetSignatureByClass(std::string className, int index = 0){return GetSignatureByClass(CheckClass(className), index);}
00119 
00120     /*******************************************************************************
00121     *   GetSignature                                                              */
00122     /*******************************************************************************
00123     *
00124     * @param class_ids  a list of ids that specify classes in the database
00125     *
00126     * @return           returns the Signature of a new instance of an object
00127     *                   having all class labels, returns NULL if the classes
00128     *                   do not exist and could not be derived
00129     * @throw char* on error
00130     *******************************************************************************/
00131     Signature* GetSignature(std::vector<ObjectID_t> class_ids);
00132 
00133     /*******************************************************************************
00134     *   CreateNewPerceptionPrimitive                                                              */
00135     /*******************************************************************************
00136     *
00137     * @param sig       a signature the will be changed by the signature
00138     *
00139     * @return           creates a new PerceptionPrimitive changinf the signature
00140     * @throw char* on error
00141     *******************************************************************************/
00142     PerceptionPrimitive& CreateNewPerceptionPrimitive(Signature* sig);
00143     /*******************************************************************************
00144     *   EvaluatePerceptionPrimitive                                                              */
00145     /*******************************************************************************
00146     *
00147     * @param id       a signature the will be changed by the signature
00148     * @param value    The value that should be back propagated
00149     * @throw char* on error
00150     *******************************************************************************/
00151     void EvaluatePerceptionPrimitive(PerceptionPrimitiveID_t id, double value, double weight, std::vector<ObjectID_t> blacklist);
00152     /*******************************************************************************
00153     *   GetCurrentRunState                                                              */
00154     /*******************************************************************************
00155     *
00156     * @brief retrieve current Run State of cop
00157     *******************************************************************************/
00158     std::vector<std::pair <PerceptionPrimitiveID_t, PerceptionPrimitiveState> > GetCurrentRunState();
00159 
00160     /*******************************************************************************
00161     *   CompleteSignature                                                              */
00162     /*******************************************************************************
00163     * @brief            Add all classes (if they are already existing
00164                         descriptors for those classes) to a signature
00165     * @param sig_max    the signature that receives all classes.
00166     * @param class_ids  a list of ids that specify classes in the database
00167     *
00168     * @throw char* on error
00169     *******************************************************************************/
00170     void CompleteSignature(Signature* sig_max, std::vector<ObjectID_t> class_ids);
00171     /*******************************************************************************
00172     *   FindCreateDescriptor                                                      */
00173     /*******************************************************************************
00174     *
00175     * @param class_id   an id that specify an class
00176     * @return           returns an Elem describing the
00177     *                   class class_id, returns NULL if the class
00178     *                   does not exist and could not be derived
00179     * @remarks throws char* on error
00180     *******************************************************************************/
00181     Elem* FindCreateDescriptor(ObjectID_t class_id);
00182 
00183      /*******************************************************************************
00184     *   SetNewObjectCallback                                                      */
00185     /*******************************************************************************
00186     *
00187     * @param comm       means to communicate every new added signature to a subscriber
00188     *
00189     *******************************************************************************/
00190     void SetNewObjectCallback(Comm* comm, bool wait_for_new = true);
00191     // Public attributes
00192     //
00193 
00194     std::string CheckClass(ObjectID_t id);
00195     ObjectID_t CheckClass(std::string name);
00196 
00197     // Public attribute accessor methods
00198     //
00202     XMLTag* Query(std::string stQueryString);
00203 
00207     bool Check(ObjectID_t sigID, int& error) const;
00208 
00209 
00210     XMLTag* Save();
00211   protected:
00212 
00213     // Static Protected attributes
00214     //
00215 
00216     // Protected attributes
00217     //
00218     void UpdateIDList();
00219 
00220     Signature* GetSignatureByIndex(unsigned int index);
00221 
00226     void CleanUpActiveSignatureList();
00231     void AddSignatureToActiveList(Signature* sig, int index);
00232   private:
00233     // XML data
00234     //
00235     XMLTag* m_dbStarter;
00236     XMLTag* m_index;
00237 
00238     std::vector<Comm*>   m_newObjectSubscriber;
00239 
00240     std::vector<ObjectID_t> m_ids;
00241     std::vector<std::pair<std::string, ObjectID_t> > m_classes;
00242 
00243     std::vector<std::pair<Signature*, int> > m_currentlyActiveSignatures;
00244     std::map<int, int> m_activeMap;
00245     std::map<ObjectID_t, std::vector<ObjectID_t> > m_classToSignature;
00246     std::map<PerceptionPrimitiveID_t, PerceptionPrimitive*> m_ppMap;
00250     int GetElemIdByClass(ObjectID_t ClassID, int index = 0);
00251     void SetClassSignature(ObjectID_t idClass, ObjectID_t idObject);
00252 
00253   };
00254 }
00255 #endif // SIGNATUREDB_H


cognitive_perception
Author(s): Ulrich F Klank
autogenerated on Mon Oct 6 2014 10:48:45