33 #include <VirtualRobot/CollisionDetection/CollisionChecker.h>
34 #include <VirtualRobot/ManipulationObject.h>
35 #include <VirtualRobot/Obstacle.h>
36 #include <VirtualRobot/SceneObjectSet.h>
37 #include <VirtualRobot/XML/RobotIO.h>
38 #include <VirtualRobot/XML/ObjectIO.h>
40 #include <SimoxUtility/math/pose/pose.h>
42 #include <boost/random/uniform_int.hpp>
43 #include <boost/random/uniform_real.hpp>
55 createCollisionWalls();
60 deleteLocalObjectCopies();
71 const size_t objectSetIndex = i % config_.
objectSets.size();
76 const boost::uniform_int<uint> uniform(0, objectSet.
objects.size() - 1);
77 const size_t objectIndex = uniform(rnd_);
86 objectName = newID.
str();
88 std::unique_ptr<SimulatedObject>
object = makeObject(objectName, objectSource);
89 object->setLocalPose(randomObjectPose(i));
90 object->addToSimulator(simulator_);
91 object->updatePoseToSimulator(simulator_);
92 localObjectCopies_.push_back(std::move(
object));
101 resetInvalidObjects();
107 void ClutteredSceneGenerator::createCollisionWalls()
110 const float wallHeight = 1000;
111 frontWall_ = VirtualRobot::Obstacle::createBox(config_.
boxW, 1, wallHeight);
112 backWall_ = VirtualRobot::Obstacle::createBox(config_.
boxW, 1, wallHeight);
113 leftWall_ = VirtualRobot::Obstacle::createBox(1, config_.
boxH, wallHeight);
114 rightWall_ = VirtualRobot::Obstacle::createBox(1, config_.
boxH, wallHeight);
116 const float wallZ = config_.
boxZ + config_.
boxD + wallHeight / 2;
117 frontWall_->setGlobalPose(simox::math::pose(Eigen::Vector3f{config_.
boxX, config_.
boxY - config_.
boxH / 2.0f, wallZ}));
118 backWall_->setGlobalPose(simox::math::pose(Eigen::Vector3f{config_.
boxX, config_.
boxY + config_.
boxH / 2.0f, wallZ}));
119 leftWall_->setGlobalPose(simox::math::pose(Eigen::Vector3f{config_.
boxX - config_.
boxW / 2.0f, config_.
boxY, wallZ}));
120 rightWall_->setGlobalPose(simox::math::pose(Eigen::Vector3f{config_.
boxX + config_.
boxW / 2.0f, config_.
boxY, wallZ}));
122 walls_.reset(
new VirtualRobot::SceneObjectSet(
"walls"));
123 walls_->addSceneObject(frontWall_);
124 walls_->addSceneObject(backWall_);
125 walls_->addSceneObject(leftWall_);
126 walls_->addSceneObject(rightWall_);
129 armarx::PosePtr ClutteredSceneGenerator::randomObjectPose(uint heightIndex)
134 boost::uniform_real<float> objectAngleDist(0, 2 *
M_PI);
137 float x = objectPositionDistX(rnd_);
138 float y = objectPositionDistY(rnd_);
140 float angle = objectAngleDist(rnd_);
142 Eigen::AngleAxisf rotation(
angle, Eigen::Vector3f::UnitZ());
147 void ClutteredSceneGenerator::deleteLocalObjectCopies()
149 localObjectCopies_.clear();
152 std::unique_ptr<SimulatedObject>
153 ClutteredSceneGenerator::makeObject(
const std::string& name,
const ObjectSource& objectSource)
155 switch (objectSource.type) {
157 return std::make_unique<SimulatedObjectAsObject>(name, objectSource);
159 return std::make_unique<SimulatedObjectAsRobot>(name, objectSource);
162 ARMARX_INFO << __FUNCTION__ <<
" Unknown SimulationObjectType: TO DO: Implement";
165 ARMARX_ERROR << __FUNCTION__ <<
" - unknown object type for " << name;
170 void ClutteredSceneGenerator::updateLocalObjectCopies()
172 for (
const auto&
object : localObjectCopies_)
174 object->updatePoseFromSimulator(simulator_);
178 void ClutteredSceneGenerator::dropObjects()
188 void ClutteredSceneGenerator::resetInvalidObjects()
190 VirtualRobot::CollisionCheckerPtr col = VirtualRobot::CollisionChecker::getGlobalCollisionChecker();
191 bool anyRespawn =
false;
196 updateLocalObjectCopies();
204 for (
const auto&
object : localObjectCopies_)
207 bool collision =
object->checkCollision(col, walls_);
209 float z =
object->getLocalPose()->position->z;
213 if (collision || isObjectOutsideOfTable)
216 object->setLocalPose(randomObjectPose(heightIndex));
217 object->updatePoseToSimulator(simulator_);
238 ClutteredSceneGenerator::config_ = conf;
248 ClutteredSceneGenerator::simulator_ = sim;