OGS
Vtu2GridDialog Class Reference

Detailed Description

Definition at line 29 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 34 of file Vtu2GridDialog.cpp.

35 : QDialog(parent), _mesh_model(mesh_model)
36{
37 setupUi(this);
38 QStringList MeshList;
39
40 for (int model_index = 0; model_index < mesh_model.rowCount();
41 ++model_index)
42 {
43 auto const* mesh = mesh_model.getMesh(mesh_model.index(model_index, 0));
44 MeshList.append(QString::fromStdString(mesh->getName()));
45 }
46
47 if (MeshList.empty())
48 {
49 MeshList.append("[No Mesh available.]");
50 this->expectedVoxelLabel->setText(
51 "Expected number of voxels: undefined");
52 }
53
54 _allMeshes.setStringList(MeshList);
55 this->meshListBox->addItems(_allMeshes.stringList());
56 this->xlineEdit->setFocus();
57}
const MeshLib::Mesh * getMesh(const QModelIndex &idx) const
Returns the mesh with the given index.
Definition MeshModel.cpp:96
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.cpp:50
MeshModel & _mesh_model
QStringListModel _allMeshes

References _allMeshes, 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 133 of file Vtu2GridDialog.cpp.

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

◆ on_xlineEdit_textChanged()

void Vtu2GridDialog::on_xlineEdit_textChanged ( )
private

Definition at line 118 of file Vtu2GridDialog.cpp.

119{
121}
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 123 of file Vtu2GridDialog.cpp.

124{
126}

References updateExpectedVoxel().

◆ on_zlineEdit_textChanged()

void Vtu2GridDialog::on_zlineEdit_textChanged ( )
private

Definition at line 128 of file Vtu2GridDialog.cpp.

129{
131}

References updateExpectedVoxel().

◆ reject

void Vtu2GridDialog::reject ( )
inlineoverrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 44 of file Vtu2GridDialog.h.

44{ 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 88 of file Vtu2GridDialog.cpp.

89{
90 if (_allMeshes.stringList()[0] == "[No Mesh available.]")
91 {
92 this->expectedVoxelLabel->setText("approximated Voxel: undefined");
93 return;
94 }
95
96 auto const opt_xyz =
97 fillXYZ(this->xlineEdit->text(), this->ylineEdit->text(),
98 this->zlineEdit->text());
99
100 if (!opt_xyz)
101 {
102 this->expectedVoxelLabel->setText("approximated Voxel: undefined");
103 return;
104 }
105
106 auto const delta = getMeshExtent(
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];
110
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));
116}
Eigen::Vector3d getMeshExtent(MeshLib::Mesh const *_mesh)

References _allMeshes, _mesh_model, fillXYZ(), MeshModel::getMesh(), 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 38 of file Vtu2GridDialog.h.

Referenced by Vtu2GridDialog(), and updateExpectedVoxel().

◆ _mesh_model

MeshModel& Vtu2GridDialog::_mesh_model
private

Definition at line 37 of file Vtu2GridDialog.h.

Referenced by accept(), and updateExpectedVoxel().


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