27 #include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
40 #include <SimoxUtility/json/io.h>
41 #include <SimoxUtility/math/pose/pose.h>
43 #include <Eigen/src/Core/Matrix.h>
44 #include <Eigen/src/Geometry/Quaternion.h>
52 Component::defaultName =
"ClutteredSceneGenerator";
60 def->component(simulator_);
61 def->component(objectMemoryToSimulation_);
66 def->optional(properties_.out.packageName,
"p.out.packageName");
67 def->optional(properties_.out.packagePath,
"p.out.packagePath");
69 def->optional(properties_.gen.initialSeed,
"p.initialSeed",
"Initial random seed for scene generation");
71 def->optional(properties_.gen.nScenes,
"p.gen.nScenes",
"Number of scenes to generate");
72 def->optional(properties_.gen.nObjects,
"p.gen.nObjects",
"Number of objects to generate");
73 def->optional(properties_.gen.verticalSpacing,
"p.gen.verticalSpacing",
"Vertical spacing between objects as they are generated");
111 .amountObjects = properties_.gen.nObjects,
112 .objectSpacingZ = properties_.gen.verticalSpacing,
120 for (uint i = 0; i < properties_.gen.nScenes; ++i)
122 simulator_->reInitialize();
123 objectMemoryToSimulation_->synchronizeSimulator();
125 int seed = properties_.gen.initialSeed +
static_cast<int>(i);
126 generateScene(config, seed);
130 if (!properties_.out.packageName.empty() && !properties_.out.packagePath.empty())
134 storeScene(scene, sceneFileName);
152 return Component::defaultName;
158 return Component::defaultName;
174 auto makeObjectSource = [&](
const ObjectInfo& info) {
178 .objectID = info.id()
183 std::back_inserter(objectSet.
objects),
189 void Component::generateScene(
const scene_generation::ClutteredSceneGenerator::Config& config,
const int seed)
192 scene_generation::ClutteredSceneGenerator gen(simulator_, config);
193 gen.generateScene(seed);
196 objects::Scene Component::getScene()
200 objects::Scene scene;
201 armarx::SceneVisuData sceneData = simulator_->getScene();
203 auto makeSceneObject = [](
const armarx::ObjectVisuData& simObject) {
208 return objects::SceneObject {
209 .className = objectID.getClassID().str(),
210 .instanceName = objectID.instanceName(),
211 .collection = objectID.dataset(),
212 .position = simox::math::position(objectPose),
219 std::transform(sceneData.objects.begin(), sceneData.objects.end(),
220 std::back_inserter(scene.objects),
226 void Component::storeScene(
const objects::Scene& scene,
const std::filesystem::path& path)
230 ARMARX_INFO <<
"Storing scene snapshot at: \n\t" << path;
235 catch (
const simox::json::error::JsonError& e)
237 ARMARX_WARNING <<
"Storing scene snapshot failed: \n" << e.what();