27 #include <VirtualRobot/Robot.h>
37 : environment(environment)
52 designerTrajectories.insert(
73 int numberOfErasedElements = designerTrajectories.erase(rnsName);
75 if (numberOfErasedElements > 0)
94 return designerTrajectories.at(rnsName);
98 throw InvalidArgumentException(
"RNS name does not exist in map");
104 VirtualRobot::RobotNodeSetPtr tmpRns = designerTrajectory->getRns();
108 tmpDTM.get()->import(designerTrajectory);
114 designerTrajectories.insert(std::make_pair(tmpRns->getName(), tmpDTM));
120 designerTrajectories[tmpRns->getName()] = tmpDTM;
132 if (designerTrajectories.find(rnsName) != designerTrajectories.end())
148 std::vector<std::vector<std::string>> rnssNodeNames;
150 for (std::map<std::string, DesignerTrajectoryManagerPtr>::iterator it
151 = designerTrajectories.begin();
152 it != designerTrajectories.end();
155 VirtualRobot::RobotNodeSetPtr rnsptr = environment->getRobot()->getRobotNodeSet(it->first);
156 std::vector<std::string> tmpRnsNodesNames = rnsptr->getNodeNames();
157 rnssNodeNames.push_back(tmpRnsNodesNames);
162 std::vector<std::string> givenRnsNodeNames
163 = environment->getRobot()->getRobotNodeSet(rnsName)->getNodeNames();
166 for (std::vector<std::string> rnsNodeNames : rnssNodeNames)
170 sort(rnsNodeNames.begin(), rnsNodeNames.end());
171 sort(givenRnsNodeNames.begin(), givenRnsNodeNames.end());
173 std::set_intersection(rnsNodeNames.begin(), rnsNodeNames.end(),
174 givenRnsNodeNames.begin(), givenRnsNodeNames.end(),
187 std::vector<std::string> bodyColModelsNames,
196 VirtualRobot::CDManagerPtr cdm(
new VirtualRobot::CDManager());
199 if (cdRob->getRobotNodeSet(activeColModelName) ==
nullptr)
204 VirtualRobot::SceneObjectSetPtr sosActiveColModel(
new VirtualRobot::SceneObjectSet());
205 sosActiveColModel->addSceneObjects(
206 cdRob->getRobotNodeSet(activeColModelName));
209 cdm->addCollisionModel(sosActiveColModel);
212 for (std::string bodyColModelName : bodyColModelsNames)
215 if (cdRob->getRobotNodeSet(bodyColModelName) ==
nullptr)
220 VirtualRobot::SceneObjectSetPtr sosBodyColModel(
new VirtualRobot::SceneObjectSet());
221 sosBodyColModel->addSceneObjects(
222 cdRob->getRobotNodeSet(bodyColModelName));
225 cdm->addCollisionModel(sosBodyColModel);
232 double increment = 1.0 / fps;
235 while (t->dataExists(time))
239 std::vector<std::string> dimNames = t->getDimensionNames();
240 std::vector<double> jointValuesDouble = t->getStates(time, 0);
241 std::vector<float> jointValues(jointValuesDouble.begin(), jointValuesDouble.end());
243 VirtualRobot::RobotConfigPtr robConf(
new VirtualRobot::RobotConfig(
251 cdRob->setConfig(robConf);
255 if (cdm->isInCollision())
262 time = time + increment;
268 TrajectoryPtr DesignerTrajectoryHolder::mergeTrajectories(
unsigned int fps)
270 std::vector<TrajectoryPtr> trajectories;
271 std::vector<double> endTimes;
272 double maxEndTime = 0;
273 std::vector<double> timestamps;
276 for (std::map<std::string, DesignerTrajectoryManagerPtr>::iterator it
277 = designerTrajectories.begin();
278 it != designerTrajectories.end();
281 if (!it->second->getDesignerTrajectory())
285 TrajectoryPtr traj = it->second->getDesignerTrajectory()->getFinalTrajectory();
287 trajectories.push_back(traj);
288 double t = traj->getTimeLength();
293 endTimes.push_back(t);
296 double inc = 1.0 / fps;
297 for (
double d = 0.0; d < maxEndTime; d = d + inc)
299 timestamps.push_back(d);
302 timestamps.push_back(maxEndTime);
305 for (
unsigned int t = 0; t < trajectories.size(); t++)
307 for (
unsigned int dim = 0; dim < trajectories[t]->dim(); dim++)
309 std::vector<double> dimData;
310 for (
double time : timestamps)
312 if (time < endTimes[t])
314 dimData.push_back(trajectories[t]->getState(time, dim));
318 dimData.push_back(trajectories[t]->getState(endTimes[t], dim));
322 finalTrajectory->addDimension(dimData, timestamps, trajectories[t]->getDimensionName(dim));
325 return finalTrajectory;