KSquare Utilities
FactoryFVProducer.h
Go to the documentation of this file.
1 #if !defined(_FACTORYFVPRODUCER_)
2 #define _FACTORYFVPRODUCER_
3 
4 
5 #include "RunLog.h"
6 
7 
8 namespace KKMLL
9 {
10 
11 #if !defined(_FeatureVector_Defined_)
12  class FeatureVector;
14 #endif
15 
16 
17 #if !defined(_FeatureVectorList_Defined_)
18  class FeatureVectorList;
20 #endif
21 
22 
23 #if !defined(_FeatureVectorProducer_Defined_)
26 #endif
27 
28 
29 #if !defined(_FeatureFileIO_Defined_)
30  class FeatureFileIO;
32 #endif
33 
34 
35 #if !defined(_FileDesc_Defined_)
36  class FileDesc;
37  typedef FileDesc* FileDescPtr;
38 #endif
39 
40 
41 #if !defined(_TrainingConfiguration2_Defined_)
44 #endif
45 
46 
47  /**
48  *@class FactoryFVProducer
49  *@brief Responsible for creating a FeatureFectorProducer instance.
50  *@details
51  * To make the 'KKMLL' library independent of the actual details of the FeatureVetir computations and
52  * their underlying source data a Factory - Producer strategy was implemented. For every FeatureVector derived class
53  * there will be at least one 'FeatureVectorProducer' derived class and one 'FactoryFVProducer' derived class.
54  *
55  * -FeatureVectorProducer Responsible for computing instances of 'FeatureVector' derived classes from source data
56  * such as a "Raster" instance.
57  * -FactoryFVProducer Responsible for creating new instances of the 'FeatureVectorProducer' derived classes. Will
58  * also provide the appropriate 'FileDesc' instance that describes the features computed and Instantiate new
59  * "FeatureVectorList" derived instances for containing the produced FeatureFevtor derived instances.
60  *
61  * New FeatureVector instances will be computed by a instance of the 'FeatureVectorProducer' class. The
62  * appropriate 'FeatureVectorProducer' derived class will be manufactured by a corresponding 'FactoryFVProducer' class.
63  * This class(FactoryFVProducer) will maintain a list of all 'FactoryFVProducer' derived classes created in the
64  * 'factories' static data member.
65  *
66  * The idea is for each class derived from FeatureVector there will be a corresponding 'FeatureVectorProducer'
67  * and 'FactoryFVProducer'. The 'FeatureVectorProducer' will be responsible for generating 'FeatureVector' instances
68  * from source data(Images) and the 'FactoryFVProducer' class will generate the correct 'FactoryFVProducer' to do
69  * these computations. Other functions of this class are to return the corresponding "FileDesc" instance, that describes
70  * the features that are going to be computed, and the appropriate 'FeatureFectorList' derived container.
71  */
73  {
74  public:
76 
77  FactoryFVProducer (const KKStr& _name,
78  const KKStr& _fvClassName,
79  const KKStr& _description
80  );
81 
82  protected:
83  /**
84  *@brief A Factory can near be deleted until the application terminates; the atexit method will perform the deletes.
85  */
86  virtual ~FactoryFVProducer ();
87 
88  public:
89  const KKStr& Description () const {return description;}
90  const KKStr& FvClassName () const {return fvClassName;}
91  const KKStr& Name () const {return name;}
92 
93 
94  virtual FeatureFileIOPtr DefaultFeatureFileIO () const = 0;
95 
96  /** @brief Returns the 'type_info' of the FeatureVector that this instance of 'FactoryFVProducer' works with. */
97  virtual const type_info* FeatureVectorTypeId () const = 0;
98 
99  /** @brief Returns the 'type_info' of the FeatureVectorList that this instance of 'FactoryFVProducer' will create. */
100  virtual const type_info* FeatureVectorListTypeId () const = 0;
101 
102  virtual FileDescPtr FileDesc () const = 0;
103 
104  /**
105  *@brief Derived classes will instantiate appropriate instances of 'FeatureVectorProducer'.
106  */
108 
109 
110  /**
111  *@brief Manufactures a instance of a derived 'FeatureVector' class that is appropriate for containing instances
112  *of FeatureVectors produced by the associated FeatureVectorProducer.
113  */
114  virtual FeatureVectorPtr ManufacturFeatureVector (kkint32 numOfFeatires,
115  RunLog& runLog
116  );
117 
118  /**
119  *@brief Manufactures a instance of a derived 'FeatureVectorList' class that is appropriate for containing instances
120  *of FeatureVectors produced by the associated FeatureVectorProducer.
121  */
123  RunLog& runLog
124  )
125  const;
126 
127 
128  /**
129  *@brief Returns a 'TrainingConfiguration2' derived instance.
130  */
132 
133 
134  /**
135  *@brief Will instantiate a new instance of the appropriate 'FeatureVectorProducer' class given the supplied name.
136  *@param[in] name The name given the 'FactoryFVProducer' instance when originally instantiated; this will
137  * typically be the name of the 'FeatureVector' derived Class.
138  *@param[in] runLog reference to the logger where messages will be written to.
139  *@returns returns a new instance of 'FeatureVectorProducer' that will be generated by registered 'FactoryFVProducer'; If
140  * 'name' is not found will return NULL.
141  */
143  RunLog& runLog
144  );
145 
146 
147  /**
148  *@brief Returns pointer to existing instance of 'FactoryFVProducer' that was previously registered with 'name'.
149  *@param[in] name The name of the 'FactoryFVProducer' that you are locking for; this is the same name as would
150  * have been passed to the constructor.
151  *@returns The existing 'FactoryFVProducer' instance of found otherwise NULL.
152  */
153  static FactoryFVProducerPtr LookUpFactory (const KKStr& name);
154 
155 
156 
157  /**
158  *@brief This is where you register newly instantiated instances of 'FactoryFVProducer' derived classes.
159  *@details The instance will be added to a list of existing factories "FactoryFVProducer::factories".
160  *This list is a map structure indexed by "FactoryFVProducer::Name()". If an instance with the same
161  *name already exists a appropriate error message will be written to the "runLog" and will not be added
162  * to "FactoryFVProducer::factories".
163  *@param[in] factory The newly created instance of a "FactoryFVProducer" derived class that you want to register.
164  *@param[in] runLog Pointer to logger; if equal NULL will write messages to temp created instance.
165  */
166  static void RegisterFactory (FactoryFVProducerPtr factory,
167  RunLog* runLog
168  );
169 
170 
171  private:
172  KKStr description; /**< Description of FeatuireVectorProducer. */
173  KKStr fvClassName; /**< The name of the 'FeatureVector' derived class that we are going to generate. */
174  KKStr name; /**< Name of FeatuireVectorProducer will create. */
175 
176  static void FinaleCleanUp ();
177 
178  static bool atExitDefined;
179 
180  typedef std::map<KKStr,FactoryFVProducerPtr> FactoryMap;
181  static FactoryMap* factories;
182  }; /* FactoryFVProducer */
183 
185 
186 #define _FactoryFVProducer_Defined_
187 
188 
189 } /* KKMLL */
190 
191 
192 
193 #endif
const KKStr & Description() const
__int32 kkint32
Definition: KKBaseTypes.h:88
FeatureVector * FeatureVectorPtr
Definition: Model.h:44
const KKStr & FvClassName() const
#define _FeatureVector_Defined_
FactoryFVProducer(const KKStr &_name, const KKStr &_fvClassName, const KKStr &_description)
static FactoryFVProducerPtr LookUpFactory(const KKStr &name)
Returns pointer to existing instance of &#39;FactoryFVProducer&#39; that was previously registered with &#39;name...
static void RegisterFactory(FactoryFVProducerPtr factory, RunLog *runLog)
This is where you register newly instantiated instances of &#39;FactoryFVProducer&#39; derived classes...
#define _FileDesc_Defined_
Definition: FileDesc.h:309
#define _FeatureFileIO_Defined_
virtual const type_info * FeatureVectorTypeId() const =0
Returns the &#39;type_info&#39; of the FeatureVector that this instance of &#39;FactoryFVProducer&#39; works with...
virtual const type_info * FeatureVectorListTypeId() const =0
Returns the &#39;type_info&#39; of the FeatureVectorList that this instance of &#39;FactoryFVProducer&#39; will creat...
FeatureFileIO * FeatureFileIOPtr
Definition: FileDesc.h:45
virtual FeatureVectorListPtr ManufacturFeatureVectorList(bool owner, RunLog &runLog) const
Manufactures a instance of a derived &#39;FeatureVectorList&#39; class that is appropriate for containing ins...
virtual FeatureVectorProducerPtr ManufactureInstance(RunLog &runLog)=0
Derived classes will instantiate appropriate instances of &#39;FeatureVectorProducer&#39;.
#define _FeatureVectorList_Defined_
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
FileDesc * FileDescPtr
FactoryFVProducer * FactoryFVProducerPtr
const KKStr & Name() const
static FeatureVectorProducerPtr ManufactureInstance(const KKStr &name, RunLog &runLog)
Will instantiate a new instance of the appropriate &#39;FeatureVectorProducer&#39; class given the supplied n...
virtual TrainingConfiguration2Ptr ManufacturTrainingConfiguration() const
Returns a &#39;TrainingConfiguration2&#39; derived instance.
Used for logging messages.
Definition: RunLog.h:49
void EncodeProblem(const struct svm_paramater &param, struct svm_problem &prob_in, struct svm_problem &prob_out)
Responsible for creating a FeatureFectorProducer instance.
FeatureVectorProducer * FeatureVectorProducerPtr
virtual FeatureVectorPtr ManufacturFeatureVector(kkint32 numOfFeatires, RunLog &runLog)
Manufactures a instance of a derived &#39;FeatureVector&#39; class that is appropriate for containing instanc...
TrainingConfiguration2 * TrainingConfiguration2Ptr
Definition: Classifier2.h:56
FeatureVectorList * FeatureVectorListPtr
Definition: Model.h:46
virtual FileDescPtr FileDesc() const =0
A abstract class that is meant to compute a FeatureVector from a source image.
FactoryFVProducer * FactoryFVProducerPtr
Definition: Model.h:75
virtual ~FactoryFVProducer()
A Factory can near be deleted until the application terminates; the atexit method will perform the de...
virtual FeatureFileIOPtr DefaultFeatureFileIO() const =0