iCub-main
iCubSkin.cpp
Go to the documentation of this file.
2 
3 using namespace iCub::skinDynLib;
4 
5 /****************************************************************/
6 /* ICUBSKIN WRAPPER
7 *****************************************************************/
9  {
11  }
12 
13  iCubSkin::iCubSkin(const std::string &_from)
14  {
15  configureSkinFromFile(_from);
16  }
17 
18  iCubSkin::iCubSkin(const std::string &_from, const std::string &_context)
19  {
20  configureSkinFromFile(_from,_context);
21  }
22 
23  bool iCubSkin::configureSkinFromFile(const std::string &_from,
24  const std::string &_context)
25  {
26  skin.clear();
27 
28  yarp::os::ResourceFinder skinRF;
29  skinRF.setDefaultContext(_context.c_str()); //overridden by --context parameter
30  skinRF.setDefaultConfigFile(_from.c_str()); //overridden by --from parameter
31  skinRF.configure(0,NULL);
32 
33  yarp::os::Bottle &skinConf = skinRF.findGroup("SKIN_EVENTS");
34 
35  if(!skinConf.isNull())
36  {
37  yInfo("[iCubSkin] SKIN_EVENTS section found");
38 
39  yarp::os::Bottle* skinPartList;
40  if(skinConf.check("skinParts"))
41  {
42  skinPartList = skinConf.find("skinParts").asList();
43  }
44  else
45  {
46  yError("[iCubSkin] No skinParts field found!");
47  return false;
48  }
49 
50  yarp::os::Bottle *taxelPosFiles;
51  if(skinConf.check("taxelPositionFiles"))
52  {
53  taxelPosFiles = skinConf.find("taxelPositionFiles").asList();
54  }
55  else
56  {
57  yError("[iCubSkin] No taxelPositionFiles field found!");
58  return false;
59  }
60 
61  for (int i = 0; i < skinPartList->size(); ++i)
62  {
63  std::string taxelPosFile = taxelPosFiles->get(i).asString().c_str();
64  std::string filePath = skinRF.findFile(taxelPosFile.c_str());
65  if (filePath!="")
66  {
67  yInfo("[iCubSkin] filePath [%i] %s\n",i,filePath.c_str());
68  skinPart p;
69  if (p.setTaxelPosesFromFile(filePath))
70  {
71  skin.push_back(p);
72  }
73  }
74  }
75  }
76  else
77  {
78  yError("[iCubSkin] No skin configuration files found.");
79  return false;
80  }
81 
82  if (skin.size()==0)
83  {
84  yError("[iCubSkin] No valid ini file found. Skin is empty!");
85  return false;
86  }
87 
88  return true;
89  }
90 
92 {
93  yDebug("********************\n");
94  yDebug("iCubSkin size %zi",skin.size());
95  for (size_t i = 0; i < skin.size(); ++i)
96  {
97  skin[i].print(verbosity);
98  }
99  yDebug("********************\n");
100 }
101 
102 // empty line to make gcc happy
bool configureSkinFromFile(const std::string &_from="skinManAll.ini", const std::string &_context="skinGui")
Configures the class with an .ini file.
Definition: iCubSkin.cpp:23
void print(int verbosity=0)
Print Method.
Definition: iCubSkin.cpp:91
iCubSkin()
Default constructor.
Definition: iCubSkin.cpp:8
std::vector< skinPart > skin
Definition: iCubSkin.h:53
Class that encloses everything relate to a skinPart.
Definition: skinPart.h:146
int verbosity
Definition: main.cpp:17