30 for (
int model_index = 0; model_index < mesh_model.
rowCount();
33 auto const* mesh = mesh_model.
getMesh(mesh_model.
index(model_index, 0));
34 MeshList.append(QString::fromStdString(mesh->getName()));
39 MeshList.append(
"[No Mesh available.]");
40 this->expectedVoxelLabel->setText(
41 "Expected number of voxels: undefined");
45 this->meshListBox->addItems(
_allMeshes.stringList());
46 this->xlineEdit->setFocus();
49std::optional<std::array<double, 3>>
fillXYZ(QString xin, QString yin,
53 if (!xin.toDouble(&ok))
57 double const xinput = xin.toDouble();
58 double const yinput = (yin.toDouble(&ok)) ? yin.toDouble() : xinput;
59 double const zinput = (zin.toDouble(&ok)) ? zin.toDouble() : xinput;
61 if (xinput <= 0 || yinput <= 0 || zinput <= 0)
66 return std::optional<std::array<double, 3>>{{xinput, yinput, zinput}};
80 if (
_allMeshes.stringList()[0] ==
"[No Mesh available.]")
82 this->expectedVoxelLabel->setText(
"approximated Voxel: undefined");
87 fillXYZ(this->xlineEdit->text(), this->ylineEdit->text(),
88 this->zlineEdit->text());
92 this->expectedVoxelLabel->setText(
"approximated Voxel: undefined");
97 _mesh_model.getMesh(this->meshListBox->currentText().toStdString()));
98 double const expected_voxel = (delta[0]) * (delta[1]) * (delta[2]) /
99 (*opt_xyz)[0] / (*opt_xyz)[1] / (*opt_xyz)[2];
101 int const exponent = std::floor(std::log10(std::abs(expected_voxel)));
102 this->expectedVoxelLabel->setText(
103 "approximated Voxel = " +
104 QString::number(std::round(expected_voxel / std::pow(10, exponent))) +
105 " x 10^" + QString::number(exponent));
126 if (this->meshListBox->currentText().toStdString() ==
127 "[No Mesh available.]")
130 "Please specify the input meshes. It has to be a 3D mesh.");
134 auto cellsize =
fillXYZ(this->xlineEdit->text(), this->ylineEdit->text(),
135 this->zlineEdit->text());
140 "At least the x-length of a voxel must be specified and > 0.\n If "
142 "are not specified, equal to 0, or not a real number, they are "
147 _mesh_model.getMesh(this->meshListBox->currentText().toStdString()));
149 if (_mesh->MeshLib::Mesh::getDimension() < 3)
155 vtkNew<MeshLib::VtkMappedMeshSource> vtkSource;
156 vtkSource->SetMesh(_mesh);
158 vtkSmartPointer<vtkUnstructuredGrid> mesh = vtkSource->GetOutput();
160 double*
const bounds = mesh->GetBounds();
162 std::array<double, 3>{bounds[0], bounds[2], bounds[4]});
164 std::array<double, 3>{bounds[1], bounds[3], bounds[5]});
165 std::array<double, 3> ranges = {max[0] - min[0], max[1] - min[1],
167 if (ranges[0] < 0 || ranges[1] < 0 || ranges[2] < 0)
170 "The range (max-min of the bounding box) is not allowed to be < 0");
172 std::array<std::size_t, 3>
const dims =
174 std::unique_ptr<MeshLib::Mesh> grid(
176 (*cellsize)[1], (*cellsize)[2], min,
"grid"));
180 fmt::format(
"Could not generate regular hex mesh. With "
181 "parameters dims={} {} {}, cellsize={} {} {}",
182 dims[0], dims[1], dims[2], (*cellsize)[0],
183 (*cellsize)[1], (*cellsize)[2])));
187 grid->getProperties().createNewPropertyVector<
int>(
189 if (cell_ids ==
nullptr)
204 OGSError::box(
"No voxelgrid could be created from the mesh.");
209 this->done(QDialog::Accepted);