iCub-main
merge.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2010 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 // e.g. ./merge --format "(/foo:o[3,1] /bar:o[2,3][1-4] (/baz:o))"
20 
51 #include <iostream>
52 #include <sstream>
53 #include <string>
54 #include <map>
55 #include <vector>
56 #include <stdexcept>
57 #include <cassert>
58 #include <list>
59 
60 #include <yarp/sig/Vector.h>
61 #include <yarp/os/Port.h>
62 #include <yarp/os/ResourceFinder.h>
63 #include <yarp/os/RFModule.h>
64 //#include <yarp/os/BufferedPort.h>
65 #include <yarp/os/Network.h>
66 #include <yarp/os/Time.h>
67 #include <yarp/os/Vocab.h>
68 
69 
70 using namespace yarp::os;
71 using namespace yarp::sig;
72 
73 namespace iCub {
74 namespace learningmachine {
75 namespace merge {
76 
81 class PortSource {
82 protected:
86  Bottle data;
87 
91  Port port;
92 
99  std::string getInputName(std::string prefix) {
100  std::ostringstream buffer;
101  int i = 1;
102  do {
103  // standard prefix + i
104  buffer.str(""); // clear buffer
105  buffer << prefix << i++ << ":i";
106  } while (Network::queryName(buffer.str().c_str()).isValid());
107  return buffer.str();
108  }
109 
113  PortSource(const PortSource& other);
114 
119 
120 public:
124  PortSource(std::string name, std::string pp) {
125  this->initPort(pp);
126  }
127 
132  this->interrupt();
133  this->close();
134  }
135 
140  virtual void initPort(std::string prefix) {
141  port.open(this->getInputName(prefix).c_str());
142  }
143 
148  virtual void connect(std::string dst) {
149  if (Network::queryName(dst.c_str()).isValid()) {
150  Network::connect(dst.c_str(), this->port.where().getName().c_str());
151  } else {
152  throw std::runtime_error("Cannot find requested port: " + dst);
153  }
154  }
155 
159  virtual void update() {
160  this->port.read(data);
161  }
162 
167  virtual Bottle& getData() {
168  return this->data;
169  }
170 
174  virtual void interrupt() {
175  this->port.interrupt();
176  }
177 
181  virtual void close() {
182  this->port.close();
183  }
184 };
185 
189 class SourceList {
190 protected:
191  typedef std::map<std::string, PortSource*> SourceMap;
192 
196  std::string portPrefix;
197 
203 
204 public:
208  SourceList(std::string pp = "/lm/merge/source") : portPrefix(pp) { }
209 
214  for (SourceMap::iterator it = this->sourceMap.begin(); it != this->sourceMap.end(); it++) {
215  delete it->second;
216  }
217  }
218 
222  SourceList(const SourceList& other);
223 
228 
232  virtual void update() {
233  // for each in portmap, port.read, store in datamap
234  SourceMap::iterator it;
235  for (it = this->sourceMap.begin(); it != this->sourceMap.end(); it++ ) {
236  it->second->update();
237  }
238  }
239 
243  virtual bool hasSource(std::string name) {
244  return (this->sourceMap.count(name) > 0);
245  }
246 
253  virtual void addSource(std::string name) {
254  if (!this->hasSource(name)) {
255  this->sourceMap[name] = new PortSource(name, this->portPrefix);
256  this->sourceMap[name]->connect(name);
257  }
258  }
259 
266  virtual PortSource& getSource(std::string name) {
267  if (!this->hasSource(name)) {
268  throw std::runtime_error("Attempt to retrieve inexistent source.");
269  }
270  return *(this->sourceMap[name]);
271  }
272 
276  virtual void interrupt() {
277  for (SourceMap::iterator it = this->sourceMap.begin(); it != this->sourceMap.end(); it++) {
278  it->second->interrupt();
279  }
280  }
281 
285  virtual void close() {
286  for (SourceMap::iterator it = this->sourceMap.begin(); it != this->sourceMap.end(); it++) {
287  it->second->close();
288  }
289  }
290 
295  virtual std::string getPortPrefix() {
296  return this->portPrefix;
297  }
298 
303  virtual void setPortPrefix(std::string pp) {
304  this->portPrefix = pp;
305  }
306 };
307 
308 
315 protected:
316 
317 public:
322  virtual std::string toString(int indent = 0) = 0;
323 
328  virtual void declareSources(SourceList& sl) = 0;
329 
335  virtual void select(Bottle& bot, SourceList& sl) = 0;
336 
337 };
338 
339 
346 class IndexSelector : public DataSelector {
347 protected:
351  std::string name;
352 
357  std::list<std::list<int> > indices;
358 
367  virtual void selectRecursive(Bottle& out, Bottle& in, std::list< std::list<int> >::iterator it) {
368  std::list<int>::iterator it2;
369  for (it2 = (*it).begin(); it2 != (*it).end(); ++it2) {
370  it++;
371  int idx = *it2 - 1;
372  if(it == this->indices.end()) {
373  if(in.get(idx).isList()) {
374  // add unwrapped bottle
375  this->addBottle(out, *(in.get(idx).asList()));
376  } else {
377  // add value directly
378  out.add(in.get(idx));
379  }
380  } else {
381  if(!in.get(idx).isList()) {
382  throw std::runtime_error("Cannot index non-list type");
383  }
384  this->selectRecursive(out, *(in.get(idx).asList()), it);
385  }
386  it--;
387 
388  }
389 
390  }
391 
398  virtual void addBottle(Bottle& out, const Bottle& in) {
399  for(int i = 0; i < in.size(); i++) {
400  out.add(in.get(i));
401  }
402  }
403 
404 public:
410  IndexSelector(std::string format) {
411  this->loadFormat(format);
412  }
413 
414  /*
415  * Inherited from DataSelector.
416  */
417  std::string toString(int indent = 0) {
418  std::ostringstream buffer;
419  buffer << std::string(indent, ' ') << this->name;
420  std::list< std::list<int> >::iterator it1;
421  for (it1 = this->indices.begin(); it1 != this->indices.end(); ++it1) {
422  buffer << "[";
423  std::list<int>::iterator it2;
424  for (it2 = (*it1).begin(); it2 != (*it1).end(); ++it2) {
425  if (it2 != (*it1).begin())
426  buffer << ",";
427  buffer << *it2;
428  }
429  buffer << "]";
430  }
431  buffer << std::endl;
432  return buffer.str();
433  }
434 
435  /*
436  * Inherited from DataSelector.
437  */
438  virtual void declareSources(SourceList& sl) {
439  sl.addSource(this->name);
440  }
441 
442  /*
443  * Inherited from DataSelector.
444  */
445  virtual void select(Bottle& bot, SourceList& sl) {
446  if(this->indices.size() == 0) {
447  // no indices, select all
448  this->addBottle(bot, sl.getSource(this->name).getData());
449  } else {
450  // select sub-bottles and items recursively
451  std::list< std::list<int> >::iterator it1;
452  it1 = this->indices.begin();
453  this->selectRecursive(bot, sl.getSource(this->name).getData(), it1);
454  }
455  }
456 
457 
464  virtual void loadFormat(std::string format) {
465  //std::cout << "Parsing format: " << format << std::endl;
466  // find indexing specifier
467  std::string::size_type idxStart = format.find("[");
468  this->name = format.substr(0, idxStart);
469 
470  std::string::size_type idxEnd;
471  while (idxStart != std::string::npos) {
472  idxEnd = format.find("]", idxStart);
473  if (idxEnd == std::string::npos) {
474  throw std::runtime_error("Missing closing bracket ']'");
475  }
476  this->loadIndices(format.substr(idxStart + 1, idxEnd - idxStart - 1));
477  idxStart = format.find("[", idxStart + 1);
478  if (idxStart != std::string::npos && (idxStart < idxEnd)) {
479  throw std::runtime_error("Unexpected opening bracket '['");
480  }
481  }
482  }
483 
490  virtual void loadIndices(std::string format) {
491  std::list<int> idxList;
492  std::vector<std::string> indexSplit = this->split(format, ",");
493  for (unsigned int i = 0; i < indexSplit.size(); i++) {
494  std::vector<std::string> rangeSplit = this->split(indexSplit[i], "-");
495 
496  if (rangeSplit.size() == 0) {
497  // should be impossible
498  throw std::runtime_error("Unexpected problem parsing: " + indexSplit[i]);
499 
500  } else if (rangeSplit.size() == 1) {
501  // single index specification
502  idxList.push_back(this->stringToInt(rangeSplit[0]));
503 
504  } else if (rangeSplit.size() == 2) {
505  // start-end index specification
506  int start = this->stringToInt(rangeSplit[0]);
507  int end = this->stringToInt(rangeSplit[1]);
508  if (start > end) {
509  throw std::runtime_error("End of range before start of range: " + indexSplit[i]);
510  }
511  for (int idx = start; idx <= end; idx++) {
512  idxList.push_back(idx);
513  }
514 
515  } else if (rangeSplit.size() > 2) {
516  // illegal
517  throw std::runtime_error("Illegal range specification: " + indexSplit[i]);
518  }
519  }
520  this->indices.push_back(idxList);
521  }
522 
530  static std::vector<std::string> split(std::string input, std::string delimiter) {
531  std::string::size_type start = 0;
532  std::string::size_type end = 0;
533  std::vector<std::string> output;
534  while (end != std::string::npos) {
535  end = input.find(delimiter, start);
536  output.push_back(input.substr(start, (end == std::string::npos) ? end : end - start));
537  start = end + 1;
538  }
539  return output;
540  }
541 
548  static int stringToInt(std::string str) {
549  std::istringstream buffer(str);
550  int ret;
551  if (buffer >> ret) {
552  return ret;
553  } else {
554  throw std::runtime_error("Could not read integer from '" + str + "'");
555  }
556  }
557 };
558 
559 
565 protected:
566  std::vector<DataSelector*> children;
567 public:
571  CompositeSelector(Bottle& format) {
572  this->loadFormat(format);
573  }
574 
579  // clear children vector
580  for (unsigned int i = 0; i < this->children.size(); i++) {
581  delete this->children[i];
582  }
583  this->children.clear();
584  this->children.resize(0);
585  }
586 
591 
596 
597  void addChild(DataSelector* ds) {
598  this->children.push_back(ds);
599  }
600 
607  void loadFormat(Bottle& format) {
608  int i = 0;
609  int len = format.size();
610  while (i < len) {
611  if (format.get(i).isString()) {
612  //std::cout << "Adding Index for " << format.get(i).asString().c_str() << std::endl;
613  this->addChild(new IndexSelector(format.get(i).asString().c_str()));
614  } else if (format.get(i).isList()) {
615  //std::cout << "Adding Composite for " << format.get(i).asList()->toString().c_str() << std::endl;
616  this->addChild(new CompositeSelector(*(format.get(i).asList())));
617  } else {
618  throw std::runtime_error(std::string("Unexpected token during parsing: ") +
619  format.get(i).asString().c_str());
620  }
621  i++;
622  }
623  }
624 
625  /*
626  * Inherited from DataSelector.
627  */
628  std::string toString(int indent = 0) {
629  std::ostringstream buffer;
630  buffer << std::string(indent, ' ') << "(" << std::endl;
631  for (unsigned int i = 0; i < this->children.size(); i++) {
632  buffer << this->children[i]->toString(indent + 2);
633  }
634  buffer << std::string(indent, ' ') << ")" << std::endl;
635  return buffer.str();
636  }
637 
638  /*
639  * Inherited from DataSelector.
640  */
641  virtual void declareSources(SourceList& sl) {
642  for (unsigned int i = 0; i < this->children.size(); i++) {
643  this->children[i]->declareSources(sl);
644  }
645  }
646 
647  /*
648  * Inherited from DataSelector.
649  */
650  virtual void select(Bottle& bot, SourceList& sl) {
651  Bottle& bot2 = bot.addList();
652  for (unsigned int i = 0; i < this->children.size(); i++) {
653  this->children[i]->select(bot2, sl);
654  }
655  }
656 };
657 
664 public:
668  RootSelector(Bottle& format) : CompositeSelector(format) { }
669 
670  /*
671  * Inherited from DataSelector.
672  */
673  virtual void select(Bottle& bot, SourceList& sl) {
674  for (unsigned int i = 0; i < this->children.size(); i++) {
675  this->children[i]->select(bot, sl);
676  }
677  }
678 };
679 
688 class MergeModule : public RFModule {
689 protected:
693  std::string portPrefix;
694 
699 
704 
709 
713  Port output;
714 
715  void printOptions(std::string error = "") {
716  if (error != "") {
717  std::cerr << "Error: " << error << std::endl;
718  }
719  std::cout << "Available options" << std::endl;
720  std::cout << "--format The format for the output (required)" << std::endl;
721  std::cout << "--frequency f Sampling frequency in Hz" << std::endl;
722  std::cout << "--port pfx Prefix for registering the ports" << std::endl;
723  }
724 
732  void registerPort(Contactable& port, std::string name) {
733  if (port.open(name.c_str()) != true) {
734  std::string msg("could not register port ");
735  msg+=name;
736  throw std::runtime_error(msg);
737  }
738  }
739 
744  this->registerPort(this->output, this->portPrefix + "/output:o");
745  }
746 
753  this->sourceList.close();
754  this->output.close();
755  }
756 
757 
758 public:
762  MergeModule(std::string pp = "/lm/merge")
763  : portPrefix(pp), desiredPeriod(0.1), dataSelector((DataSelector*) 0) { }
764 
769  delete this->dataSelector;
770  }
771 
772  /*
773  * Inherited from yarp::os::RFModule
774  */
775  virtual double getPeriod() {
776  return this->desiredPeriod;
777  }
778 
779  /*
780  * Inherited from yarp::os::RFModule
781  */
782  virtual bool interruptModule() {
783  this->sourceList.interrupt();
784  this->output.interrupt();
785  return true;
786  }
787 
788  /*
789  * Inherited from yarp::os::RFModule
790  */
791  virtual bool close() {
792  this->unregisterAllPorts();
793  return true;
794  }
795 
796  /*
797  * Inherited from yarp::os::RFModule
798  */
799  virtual bool configure(ResourceFinder& opt) {
800  // read for the general specifiers:
801  Value* val;
802  bool success = false;
803 
804  if (opt.check("help")) {
805  this->printOptions();
806  return false;
807  }
808 
809  // check for port specifier: portSuffix
810  if (opt.check("port", val)) {
811  this->portPrefix = val->asString().c_str();
812  }
813 
814  // set port prefix
815  this->sourceList.setPortPrefix(this->portPrefix + "/source");
816 
817  // read and parse format
818  if (opt.check("format", val)) {
819  if (val->isList()) {
820  this->dataSelector = new RootSelector(*(val->asList()));
821  this->dataSelector->declareSources(this->sourceList);
822  success = true;
823  } else {
824  throw std::runtime_error("The format must be a list!");
825  }
826  } else {
827  // error, no format!
828  this->printOptions("Please supply a format!");
829  return false;
830  }
831 
832 
833  if (opt.check("frequency", val)) {
834  if (val->isFloat64() || val->isInt32()) {
835  this->setFrequency(val->asFloat64());
836  }
837  }
838 
839  this->registerAllPorts();
840 
841  this->attachTerminal();
842 
843  return success;
844  }
845 
846 
847  /*
848  * Inherited from yarp::os::RFModule
849  */
850  virtual bool updateModule() {
851  assert(this->dataSelector != (DataSelector*) 0);
852  try {
853  this->sourceList.update();
854  Bottle out;
855  this->dataSelector->select(out, this->sourceList);
856  //std::cout << "Bottle: " << out.toString().c_str() << std::endl;
857  this->output.write(out);
858  //this->listeners.process(this->portSource);
859  } catch (const std::exception& e) {
860  std::cerr << "Error: " << e.what() << std::endl;
861  } catch (...) {
862  std::cerr << "Error... something bad happened, but I wouldn't know what!" << std::endl;
863  }
864  return true;
865  }
866 
867  /*
868  * Inherited from yarp::os::RFModule
869  */
870  bool respond(const Bottle& cmd, Bottle& reply) {
871  bool success = false;
872 
873  try {
874  switch (cmd.get(0).asVocab32()) {
875  case yarp::os::createVocab32('h','e','l','p'): // print help information
876  success = true;
877  reply.add(Value::makeVocab32("help"));
878 
879  reply.addString("Merge module configuration options");
880  reply.addString(" help Displays this message");
881  reply.addString(" info Prints information");
882  reply.addString(" freq f Sampling frequency in Hertz (0 for disabled)");
883  break;
884 
885  case yarp::os::createVocab32('i','n','f','o'): // print information
886  {
887  reply.add(Value::makeVocab32("help"));
888  success = true;
889  reply.addString(this->dataSelector->toString().c_str());
890  break;
891  }
892 
893  case yarp::os::createVocab32('f','r','e','q'): // set sampling frequency
894  {
895  if (cmd.size() > 1 && (cmd.get(1).isInt32() || cmd.get(1).isFloat64())) {
896  success = true;
897  this->setDesiredPeriod(1. / cmd.get(1).asFloat64());
898  //reply.addString((std::string("Current frequency: ") + cmd.get(1).toString().c_str()).c_str());
899  }
900  break;
901  }
902 
903  default:
904  break;
905  }
906  } catch (const std::exception& e) {
907  success = true; // to make sure YARP prints the error message
908  std::string msg = std::string("Error: ") + e.what();
909  reply.addString(msg.c_str());
910  this->close();
911  } catch (...) {
912  success = true; // to make sure YARP prints the error message
913  std::string msg = std::string("Error. (something bad happened, but I wouldn't know what!)");
914  reply.addString(msg.c_str());
915  this->close();
916  }
917 
918  return success;
919  }
920 
926  virtual void setDesiredPeriod(double p) {
927  this->desiredPeriod = p;
928  }
929 
935  virtual void setFrequency(double f) {
936  if (f <= 0) {
937  throw std::runtime_error("Frequency must be larger than 0");
938  }
939  this->setDesiredPeriod(1. / f);
940  }
941 
946  virtual double getDesiredPeriod() {
947  return this->desiredPeriod;
948  }
949 };
950 
951 } // merge
952 } // learningmachine
953 } // iCub
954 
955 using namespace iCub::learningmachine::merge;
956 
957 int main(int argc, char *argv[]) {
958  Network yarp;
959  int ret;
960 
961  ResourceFinder rf;
962  rf.setDefaultContext("learningMachine");
963  rf.configure(argc, argv);
964  MergeModule module;
965  try {
966  ret = module.runModule(rf);
967  } catch(const std::exception& e) {
968  std::cerr << "Error: " << e.what() << std::endl;
969  module.close();
970  return 1;
971  } catch(char* msg) {
972  std::cerr << "Error: " << msg << std::endl;
973  module.close();
974  return 1;
975  }
976  return ret;
977 }
978 
@ data
The composite selector groups other data selectors.
Definition: merge.cpp:564
CompositeSelector & operator=(const CompositeSelector &other)
Assignment operator.
std::vector< DataSelector * > children
Definition: merge.cpp:566
virtual void declareSources(SourceList &sl)
Declares the required sources for this data selector to the source list.
Definition: merge.cpp:641
void loadFormat(Bottle &format)
Loads the format of this composite selector from a Bottle.
Definition: merge.cpp:607
std::string toString(int indent=0)
Returns a string specification of the data selector.
Definition: merge.cpp:628
CompositeSelector(Bottle &format)
Default constructor.
Definition: merge.cpp:571
CompositeSelector(const CompositeSelector &other)
Copy constructor.
virtual void select(Bottle &bot, SourceList &sl)
Selectively adds data from the source list to an output bottle.
Definition: merge.cpp:650
The DataSelector is an interface for an object that selects data from one or more DataSources.
Definition: merge.cpp:314
virtual void declareSources(SourceList &sl)=0
Declares the required sources for this data selector to the source list.
virtual void select(Bottle &bot, SourceList &sl)=0
Selectively adds data from the source list to an output bottle.
virtual std::string toString(int indent=0)=0
Returns a string specification of the data selector.
The IndexSelector selects the components at specified indices from the source.
Definition: merge.cpp:346
virtual void selectRecursive(Bottle &out, Bottle &in, std::list< std::list< int > >::iterator it)
Select data from source recursively using the index specifiers.
Definition: merge.cpp:367
std::string toString(int indent=0)
Returns a string specification of the data selector.
Definition: merge.cpp:417
std::string name
The name of the source port.
Definition: merge.cpp:351
std::list< std::list< int > > indices
A list of a list of indices.
Definition: merge.cpp:357
IndexSelector(std::string format)
Default constructor.
Definition: merge.cpp:410
virtual void loadIndices(std::string format)
Loads index specifiers from a string format.
Definition: merge.cpp:490
virtual void loadFormat(std::string format)
Loads the format of the IndexSelector from a string.
Definition: merge.cpp:464
virtual void declareSources(SourceList &sl)
Declares the required sources for this data selector to the source list.
Definition: merge.cpp:438
static int stringToInt(std::string str)
Converts a string to an integer in a proper C++ way.
Definition: merge.cpp:548
virtual void addBottle(Bottle &out, const Bottle &in)
Adds all the elements in one bottle to an output bottle.
Definition: merge.cpp:398
static std::vector< std::string > split(std::string input, std::string delimiter)
Splits a string into parts at the given delimiter.
Definition: merge.cpp:530
virtual void select(Bottle &bot, SourceList &sl)
Selectively adds data from the source list to an output bottle.
Definition: merge.cpp:445
The MergeModule merges data from several input ports into a single output port.
Definition: merge.cpp:688
void registerAllPorts()
Register all ports for this module.
Definition: merge.cpp:743
void registerPort(Contactable &port, std::string name)
Register a port at a specified name.
Definition: merge.cpp:732
virtual bool configure(ResourceFinder &opt)
Definition: merge.cpp:799
void unregisterAllPorts()
Attempts to unregister all ports used by this module.
Definition: merge.cpp:752
MergeModule(std::string pp="/lm/merge")
Constructor.
Definition: merge.cpp:762
bool respond(const Bottle &cmd, Bottle &reply)
Definition: merge.cpp:870
void printOptions(std::string error="")
Definition: merge.cpp:715
double desiredPeriod
Desired period of the module updates.
Definition: merge.cpp:698
SourceList sourceList
The collecting resource for all data from all sources.
Definition: merge.cpp:703
std::string portPrefix
Prefix for the ports.
Definition: merge.cpp:693
DataSelector * dataSelector
A pointer to the root DataSelector.
Definition: merge.cpp:708
virtual double getDesiredPeriod()
Accessor for the desired period.
Definition: merge.cpp:946
virtual void setDesiredPeriod(double p)
Mutator for the desired period.
Definition: merge.cpp:926
virtual void setFrequency(double f)
Mutator for the desired period by means of setting the frequency.
Definition: merge.cpp:935
The PortSource collects data from a source port and caches the most recent Bottle of data.
Definition: merge.cpp:81
std::string getInputName(std::string prefix)
Returns the first free port given a prefix appended by an integer.
Definition: merge.cpp:99
virtual Bottle & getData()
Returns the locally cached data.
Definition: merge.cpp:167
~PortSource()
Default destructor.
Definition: merge.cpp:131
virtual void connect(std::string dst)
Connects the incoming port to the specified port.
Definition: merge.cpp:148
Port port
The port for incoming data.
Definition: merge.cpp:91
virtual void initPort(std::string prefix)
Opens the first free incoming port with the given prefix.
Definition: merge.cpp:140
virtual void update()
Reads new data from the port and caches it locally.
Definition: merge.cpp:159
virtual void interrupt()
Interrupts the port.
Definition: merge.cpp:174
PortSource(std::string name, std::string pp)
Default constructor.
Definition: merge.cpp:124
PortSource & operator=(const PortSource &other)
Assignment operator (private and unimplemented on purpose).
virtual void close()
Closes the port.
Definition: merge.cpp:181
PortSource(const PortSource &other)
Copy constructor (private and unimplemented on purpose).
The RootSelector is entry point for a format bottle.
Definition: merge.cpp:663
virtual void select(Bottle &bot, SourceList &sl)
Selectively adds data from the source list to an output bottle.
Definition: merge.cpp:673
RootSelector(Bottle &format)
Default constructor.
Definition: merge.cpp:668
The SourceList manages a map of PortSource objects.
Definition: merge.cpp:189
virtual void interrupt()
Recursively interrupt all sources.
Definition: merge.cpp:276
std::string portPrefix
Prefix for ports.
Definition: merge.cpp:196
virtual PortSource & getSource(std::string name)
Retrives the port source for a given name.
Definition: merge.cpp:266
virtual void addSource(std::string name)
Adds a source port for the given name.
Definition: merge.cpp:253
virtual void setPortPrefix(std::string pp)
Sets the prefix for the source ports.
Definition: merge.cpp:303
virtual void close()
Recursively interrupt all sources.
Definition: merge.cpp:285
virtual void update()
Updates each registered port with new data.
Definition: merge.cpp:232
std::map< std::string, PortSource * > SourceMap
Definition: merge.cpp:191
~SourceList()
Default destructor.
Definition: merge.cpp:213
SourceList & operator=(const SourceList &other)
Assignment operator.
SourceList(const SourceList &other)
Copy constructor.
virtual std::string getPortPrefix()
Returns the prefix for the source ports.
Definition: merge.cpp:295
SourceMap sourceMap
Map that links port names to the PortSource objects that are connected to them.
Definition: merge.cpp:202
SourceList(std::string pp="/lm/merge/source")
Default constructor.
Definition: merge.cpp:208
virtual bool hasSource(std::string name)
Returns true iff a PortSource has been registered for the given port name.
Definition: merge.cpp:243
cmd
Definition: dataTypes.h:30
static uint32_t idx[BOARD_NUM]
void merge(const ImageOf< PixelRgb > &imgR, const ImageOf< PixelRgb > &imgL, ImageOf< PixelRgb > &out, size_t start_lx, size_t start_ly, size_t start_rx, size_t start_ry, double alpha1, double alpha2)
Definition: main.cpp:17
int main(int argc, char *argv[])
Definition: merge.cpp:957
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
Copyright (C) 2008 RobotCub Consortium.
out
Definition: sine.m:8