3using namespace yarp::math;
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)
122 std::string filename =
"";
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");
366 for(std::map<
int, std::list<unsigned int> >::const_iterator iter_map =
repr2TaxelList.begin(); iter_map !=
repr2TaxelList.end(); ++iter_map)
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";
Class that encloses everything relate to a Taxel, i.e.
virtual void print(int verbosity=0)
Print Method.
std::string getName()
Gets the name of the class.
int getSize()
Gets the size of the class.
void setSize(int _size)
Sets the size of the class.
skinPartBase()
Constructor.
virtual std::string toString(int precision=0)
toString Method
std::recursive_mutex recursive_mtx
std::string getVersion()
Gets the version.
void setName(const std::string &_name)
Sets the name of the class.
virtual skinPartBase & operator=(const skinPartBase &_sp)
Copy Operator.
void setVersion(const std::string &_version)
Sets the version ("V1" / "V2" / "V2.1")
Class that encloses everything relate to a skinPart.
std::vector< int > taxel2Repr
Indexing variable used in the case of reducing the resolution - e.g.
bool mapTaxelsOntoThemselves()
Maps the taxels onto themselves, performing a 1:1 mapping.
std::map< int, std::list< unsigned int > > repr2TaxelList
Mapping in the opposite direction Indexed by representative taxel IDs, it stores lists of the taxels ...
std::vector< Taxel * > taxels
List of taxels that belong to the skinPart.
skinPart & operator=(const skinPart &_sp)
Copy Operator.
std::string spatial_sampling
Spatial_sampling used in building up the skinPart class.
bool setTaxelPosesFromFileOld(const std::string &_filePath)
Populates the skinPart by reading from a file - old convention.
int getTaxelsSize()
gets the size of the taxel vector (it differs from skinPartBase::getSize())
void clearTaxels()
Clears the vector of taxels properly and gracefully.
std::string toString(int precision=0)
toString Method
bool initRepresentativeTaxels()
Initializes the mapping between the taxels and their representatives (i.e.
bool setTaxelPosesFromFile(const std::string &_filePath, const std::string &_spatial_sampling="default")
Populates the skinPart by reading from a file.
void print(int verbosity=0)
Print Method.
std::list< unsigned int > vectorofIntEqualto(const std::vector< int > vec, const int val)
Returns a list of indexes corresponding to the values of vec that are equal to val.
yarp::sig::Vector vectorFromBottle(const yarp::os::Bottle b, int in, const int size)
Retrieves a vector from a bottle.
const std::string SkinPart_s[]