46 std::vector < ROSEE::ActionPinchLoose::StateWithDistance > retVect;
47 retVect.reserve ( actionStates.size() );
49 for (
auto it : actionStates ) {
50 retVect.push_back(it);
57 return (actionStates.begin()->first);
61 auto it = actionStates.begin();
72 std::vector < JointPos > retVect;
73 retVect.reserve(actionStates.size());
75 for (
auto it : actionStates ) {
76 retVect.push_back(it.first);
84 auto pairRet = actionStates.insert ( std::make_pair (jp, dist) ) ;
86 if (actionStates.size() > maxStoredActionStates) {
88 auto it = pairRet.first;
90 if (++(it) == actionStates.end() ){
92 actionStates.erase(pairRet.first);
97 auto lastElem = actionStates.end();
99 actionStates.erase(lastElem);
108 std::stringstream output;
110 output <<
"ActionName: " <<
name << std::endl;
112 output <<
"FingersInvolved: [";
113 for (
auto fingName : fingersInvolved){
114 output << fingName <<
", " ;
116 output.seekp (-2, output.cur);
117 output <<
"]" << std::endl;
119 output <<
"JointsInvolvedCount: " << std::endl;;
120 output << jointsInvolvedCount << std::endl;
122 unsigned int nActState = 1;
123 for (
auto itemSet : actionStates) {
124 output <<
"Action_State_" << nActState <<
" :" << std::endl;
126 output <<
"\t" <<
"JointStates:" << std::endl;
127 output << itemSet.first;
128 output <<
"\t" <<
"Distance:" << std::endl;
129 output <<
"\t\tdistance " << itemSet.second << std::endl;
135 std::cout << output.str();
142 out << YAML::Key << YAML::Flow << fingersInvolved;
144 unsigned int nCont = 1;
145 out << YAML::Value << YAML::BeginMap;
146 out << YAML::Key <<
"PrimitiveType" << YAML::Value << primitiveType;
147 out << YAML::Key <<
"ActionName" << YAML::Value <<
name;
148 out << YAML::Key <<
"JointsInvolvedCount" << YAML::Value << YAML::BeginMap;
149 for (
const auto &jointCount : jointsInvolvedCount ) {
150 out << YAML::Key << jointCount.first;
151 out << YAML::Value << jointCount.second;
155 for (
const auto & actionState : actionStates) {
157 std::string contSeq =
"ActionState_" + std::to_string(nCont);
158 out << YAML::Key << contSeq;
160 out << YAML::Value << YAML::BeginMap;
162 out << YAML::Key <<
"JointStates" << YAML::Value << YAML::BeginMap;
163 for (
const auto &joint : actionState.first) {
164 out << YAML::Key << joint.first;
165 out << YAML::Value << YAML::Flow << joint.second;
170 out << YAML::Key <<
"Optional" << YAML::Value << YAML::BeginMap;
171 out << YAML::Key <<
"distance" << YAML::Value << actionState.second;
184 std::vector <std::string> fingInvolvedVect = yamlIt->first.as <std::vector < std::string >> ();
185 for (
const auto &it : fingInvolvedVect) {
186 fingersInvolved.insert(it);
189 for ( YAML::const_iterator keyValue = yamlIt->second.begin(); keyValue != yamlIt->second.end(); ++keyValue) {
191 std::string key = keyValue->first.as<std::string>();
192 if ( key.compare(
"JointsInvolvedCount") == 0 ) {
195 }
else if (key.compare (
"ActionName") == 0 ) {
196 name = keyValue->second.as <std::string> ();
198 }
else if (key.compare (
"PrimitiveType") == 0) {
200 keyValue->second.as <
unsigned int>() );
201 if (parsedType != primitiveType ) {
202 std::cerr <<
"[ERROR ActionPinchLoose::" << __func__ <<
" parsed a type " << parsedType <<
203 " but this object has primitive type " << primitiveType << std::endl;
207 }
else if (key.compare(0, 12,
"ActionState_") == 0) {
211 for(YAML::const_iterator asEl = keyValue->second.begin(); asEl != keyValue->second.end(); ++asEl) {
214 if (asEl->first.as<std::string>().compare (
"JointStates") == 0 ) {
215 jointPos = asEl->second.as <
JointPos >();
217 }
else if (asEl->first.as<std::string>().compare (
"Optional") == 0 ) {
218 distance = asEl->second[
"distance"].as <
double >();
222 std::cerr <<
"[ERROR ActionPinchLoose::" << __func__ <<
"not know key "
223 << asEl->first.as<std::string>() <<
224 " found in the yaml file at this level" << std::endl;
228 actionStates.insert ( std::make_pair (jointPos,
distance));
231 std::cerr <<
"[ERROR ActionPinchLoose::" << __func__ <<
"not know key " << key <<
232 " found in the yaml file" << std::endl;