OGS
Vtu2GridDialog Class Reference

Detailed Description

Definition at line 19 of file Vtu2GridDialog.h.

#include <Vtu2GridDialog.h>

Inheritance diagram for Vtu2GridDialog:
[legend]
Collaboration diagram for Vtu2GridDialog:
[legend]

Public Member Functions

 Vtu2GridDialog (MeshModel &mesh_model, QDialog *parent=nullptr)

Private Slots

void accept () override
 Instructions if the OK-Button has been pressed.
void reject () override
 Instructions if the Cancel-Button has been pressed.

Private Member Functions

void updateExpectedVoxel ()
 As the x/y/z input changes an estimation of the expected Voxel is given.
void on_xlineEdit_textChanged ()
void on_ylineEdit_textChanged ()
void on_zlineEdit_textChanged ()

Private Attributes

MeshModel_mesh_model
QStringListModel _allMeshes

Constructor & Destructor Documentation

◆ Vtu2GridDialog()

Vtu2GridDialog::Vtu2GridDialog ( MeshModel & mesh_model,
QDialog * parent = nullptr )
explicit

Definition at line 24 of file Vtu2GridDialog.cpp.

25 : QDialog(parent), _mesh_model(mesh_model)
26{
27 setupUi(this);
28 QStringList MeshList;
29
30 for (int model_index = 0; model_index < mesh_model.rowCount();
31 ++model_index)
32 {
33 auto const* mesh = mesh_model.getMesh(mesh_model.index(model_index, 0));
34 MeshList.append(QString::fromStdString(mesh->getName()));
35 }
36
37 if (MeshList.empty())
38 {
39 MeshList.append("[No Mesh available.]");
40 this->expectedVoxelLabel->setText(
41 "Expected number of voxels: undefined");
42 }
43
44 _allMeshes.setStringList(MeshList);
45 this->meshListBox->addItems(_allMeshes.stringList());
46 this->xlineEdit->setFocus();
47}
const MeshLib::Mesh * getMesh(const QModelIndex &idx) const
Returns the mesh with the given index.
Definition MeshModel.cpp:85
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.cpp:93
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.cpp:39
MeshModel & _mesh_model
QStringListModel _allMeshes

References _allMeshes, _mesh_model, MeshModel::getMesh(), TreeModel::index(), and TreeModel::rowCount().

Member Function Documentation

◆ accept

void Vtu2GridDialog::accept ( )
overrideprivateslot

Instructions if the OK-Button has been pressed.

Definition at line 123 of file Vtu2GridDialog.cpp.

124{
125 using namespace MeshToolsLib::MeshGenerator;
126 if (this->meshListBox->currentText().toStdString() ==
127 "[No Mesh available.]")
128 {
130 "Please specify the input meshes. It has to be a 3D mesh.");
131 return;
132 }
133
134 auto cellsize = fillXYZ(this->xlineEdit->text(), this->ylineEdit->text(),
135 this->zlineEdit->text());
136
137 if (!cellsize)
138 {
140 "At least the x-length of a voxel must be specified and > 0.\n If "
141 "y-/z-input "
142 "are not specified, equal to 0, or not a real number, they are "
143 "treated as "
144 "the x-input.");
145 }
146 auto _mesh(
147 _mesh_model.getMesh(this->meshListBox->currentText().toStdString()));
148
149 if (_mesh->MeshLib::Mesh::getDimension() < 3)
150 {
151 OGSError::box("The dimension of the mesh has to be 3.");
152 return;
153 }
154
155 vtkNew<MeshLib::VtkMappedMeshSource> vtkSource;
156 vtkSource->SetMesh(_mesh);
157 vtkSource->Update();
158 vtkSmartPointer<vtkUnstructuredGrid> mesh = vtkSource->GetOutput();
159
160 double* const bounds = mesh->GetBounds();
161 MathLib::Point3d const min(
162 std::array<double, 3>{bounds[0], bounds[2], bounds[4]});
163 MathLib::Point3d const max(
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],
166 max[2] - min[2]};
167 if (ranges[0] < 0 || ranges[1] < 0 || ranges[2] < 0)
168 {
170 "The range (max-min of the bounding box) is not allowed to be < 0");
171 }
172 std::array<std::size_t, 3> const dims =
173 VoxelGridFromMesh::getNumberOfVoxelPerDimension(ranges, *cellsize);
174 std::unique_ptr<MeshLib::Mesh> grid(
175 generateRegularHexMesh(dims[0], dims[1], dims[2], (*cellsize)[0],
176 (*cellsize)[1], (*cellsize)[2], min, "grid"));
177 if (grid == nullptr)
178 {
179 OGSError::box(QString::fromStdString(
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])));
184 }
185
186 MeshLib::PropertyVector<int>* cell_ids =
187 grid->getProperties().createNewPropertyVector<int>(
188 VoxelGridFromMesh::cell_id_name, MeshLib::MeshItemType::Cell, 1);
189 if (cell_ids == nullptr)
190 {
191 OGSError::box("Could not create cell ids.");
192 }
193 cell_ids->assign(
194 VoxelGridFromMesh::assignCellIds(mesh, min, dims, *cellsize));
195 if (!VoxelGridFromMesh::removeUnusedGridCells(mesh, grid))
196 {
197 return;
198 }
199
200 VoxelGridFromMesh::mapMeshArraysOntoGrid(mesh, grid);
201
202 if (grid == nullptr)
203 {
204 OGSError::box("No voxelgrid could be created from the mesh.");
205 return;
206 }
207
208 _mesh_model.addMesh(grid.release());
209 this->done(QDialog::Accepted);
210}
std::optional< std::array< double, 3 > > fillXYZ(QString xin, QString yin, QString zin)
constexpr void assign(R &&r)
static void box(const QString &e)
Definition OGSError.cpp:13
MeshLib::Mesh * generateRegularHexMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, const BaseLib::ISubdivision &div_z, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")

References _mesh_model, MeshLib::PropertyVector< PROP_VAL_TYPE >::assign(), MeshToolsLib::MeshGenerator::VoxelGridFromMesh::assignCellIds(), OGSError::box(), MeshLib::Cell, MeshToolsLib::MeshGenerator::VoxelGridFromMesh::cell_id_name, fillXYZ(), MeshToolsLib::MeshGenerator::generateRegularHexMesh(), MeshToolsLib::MeshGenerator::VoxelGridFromMesh::getNumberOfVoxelPerDimension(), MeshToolsLib::MeshGenerator::VoxelGridFromMesh::mapMeshArraysOntoGrid(), and MeshToolsLib::MeshGenerator::VoxelGridFromMesh::removeUnusedGridCells().

◆ on_xlineEdit_textChanged()

void Vtu2GridDialog::on_xlineEdit_textChanged ( )
private

Definition at line 108 of file Vtu2GridDialog.cpp.

109{
111}
void updateExpectedVoxel()
As the x/y/z input changes an estimation of the expected Voxel is given.

References updateExpectedVoxel().

◆ on_ylineEdit_textChanged()

void Vtu2GridDialog::on_ylineEdit_textChanged ( )
private

Definition at line 113 of file Vtu2GridDialog.cpp.

114{
116}

References updateExpectedVoxel().

◆ on_zlineEdit_textChanged()

void Vtu2GridDialog::on_zlineEdit_textChanged ( )
private

Definition at line 118 of file Vtu2GridDialog.cpp.

119{
121}

References updateExpectedVoxel().

◆ reject

void Vtu2GridDialog::reject ( )
inlineoverrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 34 of file Vtu2GridDialog.h.

34{ this->done(QDialog::Rejected); };

◆ updateExpectedVoxel()

void Vtu2GridDialog::updateExpectedVoxel ( )
private

As the x/y/z input changes an estimation of the expected Voxel is given.

Definition at line 78 of file Vtu2GridDialog.cpp.

79{
80 if (_allMeshes.stringList()[0] == "[No Mesh available.]")
81 {
82 this->expectedVoxelLabel->setText("approximated Voxel: undefined");
83 return;
84 }
85
86 auto const opt_xyz =
87 fillXYZ(this->xlineEdit->text(), this->ylineEdit->text(),
88 this->zlineEdit->text());
89
90 if (!opt_xyz)
91 {
92 this->expectedVoxelLabel->setText("approximated Voxel: undefined");
93 return;
94 }
95
96 auto const delta = getMeshExtent(
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];
100
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));
106}
Eigen::Vector3d getMeshExtent(MeshLib::Mesh const *_mesh)

References _allMeshes, _mesh_model, fillXYZ(), and getMeshExtent().

Referenced by on_xlineEdit_textChanged(), on_ylineEdit_textChanged(), and on_zlineEdit_textChanged().

Member Data Documentation

◆ _allMeshes

QStringListModel Vtu2GridDialog::_allMeshes
private

Definition at line 28 of file Vtu2GridDialog.h.

Referenced by Vtu2GridDialog(), and updateExpectedVoxel().

◆ _mesh_model

MeshModel& Vtu2GridDialog::_mesh_model
private

Definition at line 27 of file Vtu2GridDialog.h.

Referenced by Vtu2GridDialog(), accept(), and updateExpectedVoxel().


The documentation for this class was generated from the following files: