3 using namespace yarp::math;
9 skinPartBase::skinPartBase() : name(
"unknown_skin_part"), size(0), version(
"unknown_version") {}
63 yDebug(
"**********\n");
64 yDebug(
"name: %s\t",
name.c_str());
65 yDebug(
"total number of taxels: %i\n",
size);
66 yDebug(
"version: %s\n",
version.c_str());
71 std::stringstream res;
72 res <<
"**********\n" <<
"Name: " <<
name <<
"\tSize: "<<
size <<
"\tVersion: "<<
version << std::endl;
109 for (std::vector<Taxel*>::const_iterator it = _sp.
taxels.begin();
110 it != _sp.
taxels.end(); ++it)
123 filename = strrchr(_filePath.c_str(),
'/');
124 filename = filename.c_str() ? filename.c_str() + 1 : _filePath.c_str();
126 yarp::os::ResourceFinder rf;
127 rf.setDefaultContext(
"skinGui");
128 rf.setDefaultConfigFile(_filePath.c_str());
129 rf.configure(0,NULL);
131 if (rf.check(
"name"))
133 setName(rf.find(
"name").asString());
137 yWarning(
"[skinPart::setTaxelPosesFromFile] no name field found. Using filename.");
152 yError(
"[skinPart::setTaxelPosesFromFile] Unexpected skin part file name: %s.\n",filename.c_str());
156 yTrace(
"[skinPart] name set to %s",
name.c_str());
158 if (rf.check(
"spatial_sampling"))
160 std::string _ss=rf.find(
"spatial_sampling").asString();
163 if (_spatial_sampling==
"default" && (_ss==
"taxel" || _ss==
"triangle"))
167 else if (_spatial_sampling==
"taxel" || _spatial_sampling==
"triangle")
171 else if ((_spatial_sampling!=
"default" && _spatial_sampling!=
"taxel" &&
172 _spatial_sampling!=
"triangle") && (_ss==
"taxel" || _ss==
"triangle"))
179 yWarning(
"[skinPart::setTaxelPosesFromFile] no spatial_sampling field found.");
183 yarp::os::Bottle &calibration = rf.findGroup(
"calibration");
184 if (calibration.isNull())
186 yWarning(
"[skinPart::setTaxelPosesFromFile] No calibration group found!");
187 yWarning(
"[skinPart::setTaxelPosesFromFile] Using old convention");
194 yarp::sig::Vector taxelPos(3,0.0);
195 yarp::sig::Vector taxelNrm(3,0.0);
196 yarp::sig::Vector taxelPosNrm(6,0.0);
198 for (
int i = 1; i <
getSize(); i++)
201 taxelPos = taxelPosNrm.subVector(0,2);
202 taxelNrm = taxelPosNrm.subVector(3,5);
204 if (
norm(taxelNrm) != 0 ||
norm(taxelPos) != 0)
206 taxels.push_back(
new Taxel(taxelPos,taxelNrm,i-1));
213 if (rf.check(
"taxel2Repr"))
215 yarp::os::Bottle b = *(rf.find(
"taxel2Repr").asList());
217 for (
int i = 0; i <
getSize(); i++)
225 yError(
"[skinPart::setTaxelPosesFromFile] No 'taxel2Repr' field found");
238 std::ifstream posFile;
239 yarp::sig::Vector taxelPos(3,0.0);
240 yarp::sig::Vector taxelNrm(3,0.0);
242 std::string filename = strrchr(_filePath.c_str(),
'/');
243 filename = filename.c_str() ? filename.c_str() + 1 : _filePath.c_str();
246 posFile.open(_filePath.c_str());
247 if (!posFile.is_open())
249 yError(
"[skinPart::setTaxelPosesFromFileOld] File %s has not been opened!",
256 posFile.seekg(0, std::ios::beg);
257 for(
unsigned int i= 0; getline(posFile,line); i++)
259 line.erase(line.find_last_not_of(
" \n\r\t")+1);
263 std::istringstream iss(line, std::istringstream::in);
264 for(
unsigned int j = 0; iss >> number; j++ )
267 taxelPos[j] = strtod(number.c_str(),NULL);
269 taxelNrm[j-3] = strtod(number.c_str(),NULL);
273 if (
norm(taxelNrm) != 0 ||
norm(taxelPos) != 0)
288 for (
int i = 0; i <
getSize(); ++i)
290 bool isIvalidID=
false;
293 if (
taxels[j]->getID()==i)
320 size_t mappsize = mapp.size();
321 for (
size_t i = 0; i < mappsize; i++)
357 yDebug(
"Taxel ID -> Representative ID:");
359 for (
int i=0; i<
size; i++)
365 yDebug(
"Representative ID -> Taxel IDs:\n");
368 std::list<unsigned int> l = iter_map->second;
369 printf(
"\t%d -> {",iter_map->first);
370 for(std::list<unsigned int>::const_iterator iter_list = l.begin(); iter_list != l.end(); iter_list++)
372 printf(
"%u, ",*iter_list);
380 for (
size_t i = 0; i <
taxels.size(); i++)
383 yDebug(
"**********\n");
389 for (
size_t i = 0; i <
taxels.size(); i++)
391 res <<
"**********\n";