ClutteredSceneGenerator.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXSimulation::ArmarXObjects::ClutteredSceneGenerator
17 * @author Patrick Hegemann ( patrick dot hegemann at kit dot edu )
18 * @date 2021
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <memory>
26
27#include <boost/random/mersenne_twister.hpp>
28
29#include <VirtualRobot/VirtualRobot.h>
30
32
33#include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
35
37{
38 /**
39 * @defgroup Library-ClutteredSceneGenerator ClutteredSceneGenerator
40 * @ingroup ArmarXSimulation
41 * A description of the library ClutteredSceneGenerator.
42 *
43 * @class ClutteredSceneGenerator
44 * @ingroup Library-ClutteredSceneGenerator
45 * @brief Brief description of class ClutteredSceneGenerator.
46 *
47 * Detailed description of class ClutteredSceneGenerator.
48 */
50 {
51 public:
52 struct Config
53 {
54 // Object sets
55 std::vector<ObjectSet> objectSets;
56
57 /** Number of objects to generate in a scene */
58 uint amountObjects = 6;
59
60 /** Number of simulation steps executed for letting objects fall onto the table */
61 uint fallingSteps = 100;
62
63 /** Whether to automatically reset invalid objects after scene generation */
65 /** Maximum number of retries when resetting objects */
66 uint maxResetTries = 1;
67
68 // Table position and dimensions
69 float boxX = 0;
70 float boxY = 0;
71 float boxZ = 0;
72 float boxW = 1500;
73 float boxH = 750;
74 float boxD = 1000; // approximately
75
76 // Minimum distance between object pivot and table edge
77 float objectMarginSide = 200;
78 // Initial vertical distance between objects
79 float objectSpacingZ = 100;
80
81 // Bounding box for creating objects
82 float minObjectX = -550; // BOX_X - BOX_W / 2 + MARGIN
83 float minObjectY = -175; // BOX_Y - BOX_H / 2 + MARGIN
84 float maxObjectX = 550; // BOX_X + BOX_W / 2 - MARGIN
85 float maxObjectY = 175; // BOX_Y + BOX_H / 2 - MARGIN
86 float minObjectZ = 150;
87
88 // If an object has a Z position less than this it will be reset
90 };
91
92 ClutteredSceneGenerator(const armarx::SimulatorInterfacePrx& simulator,
93 const Config& config);
94
95 void generateScene(int seed);
96
97 [[nodiscard]] const Config& getConfig() const;
98 void setConfig(const Config& conf);
99
100 [[nodiscard]] const SimulatorInterfacePrx& getSimulator() const;
101 void setSimulator(const SimulatorInterfacePrx& simulator);
102
103 private:
104 void createCollisionWalls();
105
106 /**
107 * @brief randomObjectPose
108 * Generates a random pose for an object.
109 * @param heightIndex
110 * How far above the box the pose should be (z = MIN_OBJECT_Z + heightIndex * OBJECT_SPACING_Z)
111 * @return
112 * a random pose.
113 */
114 armarx::PosePtr randomObjectPose(uint heightIndex);
115
116 /**
117 * @brief deleteLocalObjectCopies
118 * Deletes all local copies of the objects in the scene
119 */
120 void deleteLocalObjectCopies();
121
122 static std::unique_ptr<SimulatedObject> makeObject(const std::string& name,
123 const ObjectSource& objectSource);
124
125 /**
126 * @brief updateLocalObjectCopies
127 * Updates local copies of objects by retrieving their poses from the simulator.
128 */
129 void updateLocalObjectCopies();
130
131 void dropObjects();
132 void resetInvalidObjects();
133
134 Config config_;
135 armarx::SimulatorInterfacePrx simulator_;
136
137 boost::mt19937 rnd_;
138
139 std::vector<std::unique_ptr<SimulatedObject>> localObjectCopies_;
140
141 // Walls for collision detection to ensure objects are inside the box
142 VirtualRobot::SceneObjectPtr frontWall_;
143 VirtualRobot::SceneObjectPtr backWall_;
144 VirtualRobot::SceneObjectPtr leftWall_;
145 VirtualRobot::SceneObjectPtr rightWall_;
146 VirtualRobot::SceneObjectSetPtr walls_;
147 };
148} // namespace armarx::simulation::scene_generation
ClutteredSceneGenerator(const armarx::SimulatorInterfacePrx &simulator, const Config &config)
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
uint fallingSteps
Number of simulation steps executed for letting objects fall onto the table.
uint maxResetTries
Maximum number of retries when resetting objects.
bool autoResetInvalidObjects
Whether to automatically reset invalid objects after scene generation.