16#include <vtkXMLUnstructuredGridWriter.h>
19#include <QStringListModel>
40 for (
int model_index = 0; model_index < mesh_model.
rowCount();
43 auto const* mesh = mesh_model.
getMesh(mesh_model.
index(model_index, 0));
44 MeshList.append(QString::fromStdString(mesh->getName()));
49 MeshList.append(
"[No Mesh available.]");
50 this->expectedVoxelLabel->setText(
51 "Expected number of voxels: undefined");
55 this->meshListBox->addItems(
_allMeshes.stringList());
56 this->xlineEdit->setFocus();
59std::optional<std::array<double, 3>>
fillXYZ(QString xin, QString yin,
63 if (!xin.toDouble(&ok))
67 double const xinput = xin.toDouble();
68 double const yinput = (yin.toDouble(&ok)) ? yin.toDouble() : xinput;
69 double const zinput = (zin.toDouble(&ok)) ? zin.toDouble() : xinput;
71 if (xinput <= 0 || yinput <= 0 || zinput <= 0)
76 return std::optional<std::array<double, 3>>{{xinput, yinput, zinput}};
81 auto const& nodes = _mesh->
getNodes();
90 if (
_allMeshes.stringList()[0] ==
"[No Mesh available.]")
92 this->expectedVoxelLabel->setText(
"approximated Voxel: undefined");
97 fillXYZ(this->xlineEdit->text(), this->ylineEdit->text(),
98 this->zlineEdit->text());
102 this->expectedVoxelLabel->setText(
"approximated Voxel: undefined");
107 _mesh_model.getMesh(this->meshListBox->currentText().toStdString()));
108 double const expected_voxel = (delta[0]) * (delta[1]) * (delta[2]) /
109 (*opt_xyz)[0] / (*opt_xyz)[1] / (*opt_xyz)[2];
111 int const exponent = std::floor(std::log10(std::abs(expected_voxel)));
112 this->expectedVoxelLabel->setText(
113 "approximated Voxel = " +
114 QString::number(std::round(expected_voxel / std::pow(10, exponent))) +
115 " x 10^" + QString::number(exponent));
136 if (this->meshListBox->currentText().toStdString() ==
137 "[No Mesh available.]")
140 "Please specify the input meshes. It has to be a 3D mesh.");
144 auto cellsize =
fillXYZ(this->xlineEdit->text(), this->ylineEdit->text(),
145 this->zlineEdit->text());
150 "At least the x-length of a voxel must be specified and > 0.\n If "
152 "are not specified, equal to 0, or not a real number, they are "
157 _mesh_model.getMesh(this->meshListBox->currentText().toStdString()));
159 if (_mesh->MeshLib::Mesh::getDimension() < 3)
165 vtkNew<MeshLib::VtkMappedMeshSource> vtkSource;
166 vtkSource->SetMesh(_mesh);
168 vtkSmartPointer<vtkUnstructuredGrid> mesh = vtkSource->GetOutput();
170 double*
const bounds = mesh->GetBounds();
172 std::array<double, 3>{bounds[0], bounds[2], bounds[4]});
174 std::array<double, 3>{bounds[1], bounds[3], bounds[5]});
175 std::array<double, 3> ranges = {max[0] - min[0], max[1] - min[1],
177 if (ranges[0] < 0 || ranges[1] < 0 || ranges[2] < 0)
180 "The range (max-min of the bounding box) is not allowed to be < 0");
182 std::array<std::size_t, 3>
const dims =
184 std::unique_ptr<MeshLib::Mesh> grid(
186 (*cellsize)[1], (*cellsize)[2], min,
"grid"));
190 fmt::format(
"Could not generate regular hex mesh. With "
191 "parameters dims={} {} {}, cellsize={} {} {}",
192 dims[0], dims[1], dims[2], (*cellsize)[0],
193 (*cellsize)[1], (*cellsize)[2])));
197 grid->getProperties().createNewPropertyVector<
int>(
199 if (cell_ids ==
nullptr)
214 OGSError::box(
"No voxelgrid could be created from the mesh.");
219 this->done(QDialog::Accepted);
Definition of the AABB class.
Definition of the MeshModel class.
Definition of the Mesh class.
Definition of the Node class.
Definition of the OGSError class.
Implementation of the StrictDoubleValidator class.
VtkMappedMeshSource is a source class to transform OGS meshes into complete vtkUnstructuredGrids....
std::optional< std::array< double, 3 > > fillXYZ(QString xin, QString yin, QString zin)
Eigen::Vector3d getMeshExtent(MeshLib::Mesh const *_mesh)
Definition of the Vtu2GridDialog class.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Eigen::Vector3d const & getMaxPoint() const
Eigen::Vector3d const & getMinPoint() const
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
constexpr void assign(R &&r)
const MeshLib::Mesh * getMesh(const QModelIndex &idx) const
Returns the mesh with the given index.
static void box(const QString &e)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
void on_xlineEdit_textChanged()
Vtu2GridDialog(MeshModel &mesh_model, QDialog *parent=nullptr)
void on_zlineEdit_textChanged()
void updateExpectedVoxel()
As the x/y/z input changes an estimation of the expected Voxel is given.
void on_ylineEdit_textChanged()
void accept() override
Instructions if the OK-Button has been pressed.
QStringListModel _allMeshes