32#include <boost/algorithm/string/predicate.hpp>
36#include <qnamespace.h>
86 connect(widget_.pushButtonRefreshObjectSets,
87 &QPushButton::clicked,
90 connect(widget_.pushButtonGenerateNewScene,
91 &QPushButton::clicked,
95 connect(widget_.checkBoxAutoPoseConstraints,
96 &QCheckBox::stateChanged,
99 connect(widget_.spinBoxTableX,
100 QOverload<double>::of(&QDoubleSpinBox::valueChanged),
103 connect(widget_.spinBoxTableY,
104 QOverload<double>::of(&QDoubleSpinBox::valueChanged),
107 connect(widget_.spinBoxTableZ,
108 QOverload<double>::of(&QDoubleSpinBox::valueChanged),
111 connect(widget_.spinBoxTableW,
112 QOverload<double>::of(&QDoubleSpinBox::valueChanged),
115 connect(widget_.spinBoxTableH,
116 QOverload<double>::of(&QDoubleSpinBox::valueChanged),
119 connect(widget_.spinBoxTableD,
120 QOverload<double>::of(&QDoubleSpinBox::valueChanged),
132 std::map<std::string, simulation::scene_generation::ObjectSet>
133 ClutteredSceneGeneratorWidgetController::getObjectSets(
const armarx::PackagePath& packagePath)
135 const auto& directoryPackagePath = packagePath.
serialize();
136 std::map<std::string, simulation::scene_generation::ObjectSet> sets;
141 for (
const auto& setEntry : std::filesystem::directory_iterator(packagePath.
toSystemPath()))
143 if (!setEntry.is_directory())
147 const std::string
setName = setEntry.path().filename();
149 std::vector<simulation::scene_generation::ObjectSource> objectSources;
150 for (
const auto& objectEntry : std::filesystem::directory_iterator(setEntry.path()))
152 if (objectEntry.path().extension().string() ==
".xml")
154 std::filesystem::path newPath(directoryPackagePath.path);
155 newPath /=
setName / objectEntry.path().filename();
156 PackagePath objectPackagePath(directoryPackagePath.package, newPath);
158 simulation::scene_generation::ObjectSource objectSource = {
159 .path = objectPackagePath,
161 .objectID = std::nullopt};
162 objectSources.push_back(objectSource);
165 simulation::scene_generation::ObjectSet currentObjectSet{.objects = objectSources};
167 sets[
setName] = currentObjectSet;
178 PackagePath path(
"ArmarXSimulation",
"random_objects");
179 objectSets_ = getObjectSets(path);
182 widget_.listWidgetObjectSets->clear();
183 objectSetListItems_.clear();
184 for (
auto& item : objectSetListItems_)
190 for (
const auto& [
setName, _] : objectSets_)
192 auto* item =
new QListWidgetItem;
193 objectSetListItems_.push_back(item);
196 std::string basename =
setName.substr(
setName.find_last_of(
'/') + 1);
197 item->setText(QString::fromStdString(basename));
198 item->setData(1, QString::fromStdString(
setName));
199 item->setFlags((item->flags() | Qt::ItemIsUserCheckable) & ~Qt::ItemIsSelectable);
200 item->setCheckState(Qt::Checked);
201 widget_.listWidgetObjectSets->addItem(item);
208 if (widget_.checkBoxAutoPoseConstraints->isChecked())
210 const double tableX = widget_.spinBoxTableX->value();
211 const double tableY = widget_.spinBoxTableY->value();
212 const double tableZ = widget_.spinBoxTableZ->value();
213 const double tableW = widget_.spinBoxTableW->value();
214 const double tableH = widget_.spinBoxTableH->value();
215 const double tableD = widget_.spinBoxTableD->value();
216 const double margin = widget_.spinBoxMarginBoxWalls->value();
218 const double minX = tableX - tableW / 2 + margin;
219 const double minY = tableY - tableH / 2 + margin;
220 const double maxX = tableX + tableW / 2 - margin;
221 const double maxY = tableY + tableH / 2 - margin;
222 const double minZ = tableZ + tableD + 150;
224 widget_.spinBoxObjectMinX->setValue(minX);
225 widget_.spinBoxObjectMinY->setValue(minY);
226 widget_.spinBoxObjectMaxX->setValue(maxX);
227 widget_.spinBoxObjectMaxY->setValue(maxY);
228 widget_.spinBoxObjectMinZ->setValue(minZ);
236 int seed = widget_.spinBoxSceneSeed->value();
241 ClutteredSceneGeneratorWidgetController::getGenConfig()
246 std::vector<simulation::scene_generation::ObjectSet> selectedSets;
248 for (
int i = 0; i < widget_.listWidgetObjectSets->count(); ++i)
250 auto* item = widget_.listWidgetObjectSets->item(i);
251 if (item->checkState() == Qt::CheckState::Checked)
253 std::string setPath = item->data(1).toString().toStdString();
254 selectedSets.push_back(objectSets_[setPath]);
259 genConfig.
amountObjects = widget_.spinBoxSceneObjectAmount->value();
261 genConfig.
fallingSteps = widget_.spinBoxObjectFallingSteps->value();
263 genConfig.
maxResetTries = widget_.spinBoxMaxResetAttempts->value();
265 genConfig.
boxX =
static_cast<float>(widget_.spinBoxTableX->value());
266 genConfig.
boxY =
static_cast<float>(widget_.spinBoxTableY->value());
267 genConfig.
boxZ =
static_cast<float>(widget_.spinBoxTableZ->value());
268 genConfig.
boxW =
static_cast<float>(widget_.spinBoxTableW->value());
269 genConfig.
boxH =
static_cast<float>(widget_.spinBoxTableH->value());
270 genConfig.
boxD =
static_cast<float>(widget_.spinBoxTableD->value());
272 genConfig.
objectMarginSide =
static_cast<float>(widget_.spinBoxMarginBoxWalls->value());
273 genConfig.
objectSpacingZ =
static_cast<float>(widget_.spinBoxObjectSpacingZ->value());
275 genConfig.
minObjectX =
static_cast<float>(widget_.spinBoxObjectMinX->value());
276 genConfig.
minObjectY =
static_cast<float>(widget_.spinBoxObjectMinY->value());
277 genConfig.
minObjectZ =
static_cast<float>(widget_.spinBoxObjectMinZ->value());
278 genConfig.
maxObjectX =
static_cast<float>(widget_.spinBoxObjectMaxX->value());
279 genConfig.
maxObjectY =
static_cast<float>(widget_.spinBoxObjectMaxY->value());
282 static_cast<float>(widget_.spinBoxZPosResetting->value());
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
void setName(std::string name)
Override name of well-known object.
data::PackagePath serialize() const
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
Brief description of class ClutteredSceneGenerator.
void generateScene(int seed)
#define ARMARX_INFO
The normal logging level.
This file offers overloads of toIce() and fromIce() functions for STL container types.
uint fallingSteps
Number of simulation steps executed for letting objects fall onto the table.
float minObjectZOtherwiseReset
uint amountObjects
Number of objects to generate in a scene.
uint maxResetTries
Maximum number of retries when resetting objects.
std::vector< ObjectSet > objectSets
bool autoResetInvalidObjects
Whether to automatically reset invalid objects after scene generation.