iCub-main
ITransformer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2011 RobotCub Consortium, European Commission FP6 Project IST-004370
3  * author: Arjan Gijsberts
4  * email: arjan.gijsberts@iit.it
5  * website: www.robotcub.org
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * http://www.robotcub.org/icub/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
19 #ifndef LM_ITRANSFORMER__
20 #define LM_ITRANSFORMER__
21 
22 #include <sstream>
23 #include <string>
24 
25 #include <yarp/os/Portable.h>
26 #include <yarp/os/Bottle.h>
27 #include <yarp/sig/Vector.h>
28 
29 namespace iCub {
30 namespace learningmachine {
31 
57 class ITransformer : public yarp::os::Portable {
58 protected:
62  std::string name;
63 
68 
76  virtual void writeBottle(yarp::os::Bottle& bot) const = 0;
77 
85  virtual void readBottle(yarp::os::Bottle& bot) = 0;
86 
87 public:
91  ITransformer() : name(""), sampleCount(0) { }
92 
96  virtual ~ITransformer() { }
97 
104  virtual yarp::sig::Vector transform(const yarp::sig::Vector& input) {
105  this->sampleCount++;
106  return yarp::sig::Vector();
107  }
108 
115  virtual std::string getInfo() {
116  std::ostringstream buffer;
117  buffer << "Type: " << this->getName() << ", ";
118  buffer << "Sample Count: " << this->sampleCount << std::endl;
119  return buffer.str();
120  }
121 
125  virtual void reset() {
126  this->sampleCount = 0;
127  }
128 
134  std::string getName() const {
135  return this->name;
136  }
137 
143  void setName(std::string name) {
144  this->name = name;
145  }
146 
153  virtual std::string getConfigHelp() {
154  return std::string("Transformer configuration options for '") +
155  this->getName() + "'\n";
156  }
157 
163  virtual ITransformer* clone() = 0;
164 
165  /*
166  * Configure.
167  */
168  virtual bool configure(yarp::os::Searchable& config) { return true; }
169 
170  /*
171  * Inherited from Portable.
172  */
173  bool write(yarp::os::ConnectionWriter& connection) const {
174  yarp::os::Bottle model;
175  this->writeBottle(model);
176  return model.write(connection);
177  }
178 
179  /*
180  * Inherited from Portable.
181  */
182  bool read(yarp::os::ConnectionReader& connection) {
183  yarp::os::Bottle model;
184  model.read(connection);
185  this->readBottle(model);
186  return true;
187  }
188 
194  virtual std::string toString() {
195  yarp::os::Bottle model;
196  this->writeBottle(model);
197  return model.toString().c_str();
198  }
199 
205  virtual bool fromString(const std::string& str) {
206  yarp::os::Bottle model(str.c_str());
207  this->readBottle(model);
208  return true;
209  }
210 
211 };
212 
213 } // learningmachine
214 } // iCub
215 
216 #endif
A class that provides a preprocessing interface, which can be used to preprocess the data samples tha...
Definition: ITransformer.h:57
virtual ~ITransformer()
Destructor (empty).
Definition: ITransformer.h:96
bool write(yarp::os::ConnectionWriter &connection) const
Definition: ITransformer.h:173
virtual std::string getConfigHelp()
Asks the transformer to return a string containing the list of configuration options that it supports...
Definition: ITransformer.h:153
virtual bool configure(yarp::os::Searchable &config)
Definition: ITransformer.h:168
bool read(yarp::os::ConnectionReader &connection)
Definition: ITransformer.h:182
int sampleCount
Number of samples transformed since initialization.
Definition: ITransformer.h:67
virtual yarp::sig::Vector transform(const yarp::sig::Vector &input)
Transforms an input vector.
Definition: ITransformer.h:104
virtual void reset()
Forget everything and start over.
Definition: ITransformer.h:125
virtual ITransformer * clone()=0
Asks the transformer to return a new object of its type.
virtual std::string toString()
Asks the transformer to return a string serialization.
Definition: ITransformer.h:194
virtual void readBottle(yarp::os::Bottle &bot)=0
Unserializes a transformer from a bottle.
std::string name
The name of this type of transformer.
Definition: ITransformer.h:62
virtual bool fromString(const std::string &str)
Asks the transformer to initialize from a string serialization.
Definition: ITransformer.h:205
virtual std::string getInfo()
Asks the transformer to return a string containing statistics on its operation so far.
Definition: ITransformer.h:115
virtual void writeBottle(yarp::os::Bottle &bot) const =0
Writes a serialization of the transformer into a bottle.
std::string getName() const
Retrieve the name of this transformer.
Definition: ITransformer.h:134
void setName(std::string name)
Set the name of this transformer.
Definition: ITransformer.h:143
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.