31 #include <boost/algorithm/string/predicate.hpp>
33 #include <QListWidget>
35 #include <qnamespace.h>
93 simulator_ = getProxy<SimulatorInterfacePrx>(simulatorProxyName_);
100 std::map<std::string, simulation::scene_generation::ObjectSet>
101 ClutteredSceneGeneratorWidgetController::getObjectSets(
const armarx::PackagePath& packagePath)
103 const auto& directoryPackagePath = packagePath.
serialize();
104 std::map<std::string, simulation::scene_generation::ObjectSet> sets;
109 for (
const auto & setEntry : std::filesystem::directory_iterator(packagePath.
toSystemPath()))
111 if (!setEntry.is_directory())
115 const std::string
setName = setEntry.path().filename();
117 std::vector<simulation::scene_generation::ObjectSource> objectSources;
118 for (
const auto & objectEntry : std::filesystem::directory_iterator(setEntry.path()))
120 if (objectEntry.path().extension().string() ==
".xml")
122 std::filesystem::path newPath(directoryPackagePath.path);
123 newPath /=
setName / objectEntry.path().filename();
124 PackagePath objectPackagePath(directoryPackagePath.package, newPath);
126 simulation::scene_generation::ObjectSource objectSource = {
127 .path = objectPackagePath,
129 .objectID = std::nullopt
131 objectSources.push_back(objectSource);
134 simulation::scene_generation::ObjectSet currentObjectSet {.objects = objectSources};
136 sets[
setName] = currentObjectSet;
145 PackagePath path(
"ArmarXSimulation",
"random_objects");
146 objectSets_ = getObjectSets(path);
149 widget_.listWidgetObjectSets->clear();
150 objectSetListItems_.clear();
151 for (
auto& item : objectSetListItems_)
157 for (
const auto& [
setName, _] : objectSets_)
159 auto* item =
new QListWidgetItem;
160 objectSetListItems_.push_back(item);
163 std::string basename =
setName.substr(
setName.find_last_of(
'/') + 1);
164 item->setText(QString::fromStdString(basename));
165 item->setData(1, QString::fromStdString(
setName));
166 item->setFlags((item->flags() | Qt::ItemIsUserCheckable) & ~Qt::ItemIsSelectable);
167 item->setCheckState(Qt::Checked);
168 widget_.listWidgetObjectSets->addItem(item);
173 if (widget_.checkBoxAutoPoseConstraints->isChecked()) {
174 const double tableX = widget_.spinBoxTableX->value();
175 const double tableY = widget_.spinBoxTableY->value();
176 const double tableZ = widget_.spinBoxTableZ->value();
177 const double tableW = widget_.spinBoxTableW->value();
178 const double tableH = widget_.spinBoxTableH->value();
179 const double tableD = widget_.spinBoxTableD->value();
180 const double margin = widget_.spinBoxMarginBoxWalls->value();
182 const double minX = tableX - tableW / 2 + margin;
183 const double minY = tableY - tableH / 2 + margin;
184 const double maxX = tableX + tableW / 2 - margin;
185 const double maxY = tableY + tableH / 2 - margin;
186 const double minZ = tableZ + tableD + 150;
188 widget_.spinBoxObjectMinX->setValue(minX);
189 widget_.spinBoxObjectMinY->setValue(minY);
190 widget_.spinBoxObjectMaxX->setValue(maxX);
191 widget_.spinBoxObjectMaxY->setValue(maxY);
192 widget_.spinBoxObjectMinZ->setValue(minZ);
198 simulation::scene_generation::ClutteredSceneGenerator generator(simulator_, getGenConfig());
199 int seed = widget_.spinBoxSceneSeed->value();
200 generator.generateScene(seed);
205 simulation::scene_generation::ClutteredSceneGenerator::Config ClutteredSceneGeneratorWidgetController::getGenConfig() {
206 simulation::scene_generation::ClutteredSceneGenerator::Config genConfig;
209 std::vector<simulation::scene_generation::ObjectSet> selectedSets;
211 for (
int i = 0; i < widget_.listWidgetObjectSets->count(); ++i)
213 auto* item = widget_.listWidgetObjectSets->item(i);
214 if (item->checkState() == Qt::CheckState::Checked)
216 std::string setPath = item->data(1).toString().toStdString();
217 selectedSets.push_back(objectSets_[setPath]);
220 genConfig.objectSets = selectedSets;
222 genConfig.amountObjects = widget_.spinBoxSceneObjectAmount->value();
224 genConfig.fallingSteps = widget_.spinBoxObjectFallingSteps->value();
225 genConfig.autoResetInvalidObjects = widget_.checkBoxResetInvalidObjects->isChecked();
226 genConfig.maxResetTries = widget_.spinBoxMaxResetAttempts->value();
228 genConfig.boxX =
static_cast<float>(widget_.spinBoxTableX->value());
229 genConfig.boxY =
static_cast<float>(widget_.spinBoxTableY->value());
230 genConfig.boxZ =
static_cast<float>(widget_.spinBoxTableZ->value());
231 genConfig.boxW =
static_cast<float>(widget_.spinBoxTableW->value());
232 genConfig.boxH =
static_cast<float>(widget_.spinBoxTableH->value());
233 genConfig.boxD =
static_cast<float>(widget_.spinBoxTableD->value());
235 genConfig.objectMarginSide =
static_cast<float>(widget_.spinBoxMarginBoxWalls->value());
236 genConfig.objectSpacingZ =
static_cast<float>(widget_.spinBoxObjectSpacingZ->value());
238 genConfig.minObjectX =
static_cast<float>(widget_.spinBoxObjectMinX->value());
239 genConfig.minObjectY =
static_cast<float>(widget_.spinBoxObjectMinY->value());
240 genConfig.minObjectZ =
static_cast<float>(widget_.spinBoxObjectMinZ->value());
241 genConfig.maxObjectX =
static_cast<float>(widget_.spinBoxObjectMaxX->value());
242 genConfig.maxObjectY =
static_cast<float>(widget_.spinBoxObjectMaxY->value());
244 genConfig.minObjectZOtherwiseReset =
static_cast<float>(widget_.spinBoxZPosResetting->value());