OGS
Layers2GridDialog Class Reference

Detailed Description

Definition at line 20 of file Layers2GridDialog.h.

#include <Layers2GridDialog.h>

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

Public Member Functions

 Layers2GridDialog (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 on_deleteMeshButton_pressed ()
 Instructions if the ">>" button has been pressed.
void on_upOrderButton_pressed ()
 Instructions if the "↑"-button has been pressed.
void on_downOrderButton_pressed ()
 Instructions if the "↓"-button has been pressed.
void on_orderButton_pressed ()
 Instructions if the "order mesh"-button has been pressed.
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 _layeredMeshes
QStringListModel _neglectedMeshes

Constructor & Destructor Documentation

◆ Layers2GridDialog()

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

Definition at line 19 of file Layers2GridDialog.cpp.

20 : QDialog(parent), _mesh_model(mesh_model)
21{
22 setupUi(this);
23 QStringList MeshList;
24
25 for (int model_index = 0; model_index < mesh_model.rowCount();
26 ++model_index)
27 {
28 auto const* mesh = mesh_model.getMesh(mesh_model.index(model_index, 0));
29 MeshList.append(QString::fromStdString(mesh->getName()));
30 }
31
32 if (MeshList.empty())
33 {
34 MeshList.append("[No Mesh available.]");
35 this->expectedVoxelLabel->setText(
36 "Expected number of voxels: undefined");
37 }
38
39 _layeredMeshes.setStringList(MeshList);
40 this->allMeshView->setModel(&_layeredMeshes);
41 this->allMeshView->setDragDropMode(QAbstractItemView::InternalMove);
42}
QStringListModel _layeredMeshes
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

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

Member Function Documentation

◆ accept

void Layers2GridDialog::accept ( )
overrideprivateslot

Instructions if the OK-Button has been pressed.

Definition at line 149 of file Layers2GridDialog.cpp.

150{
151 if (this->_layeredMeshes.rowCount() == 1)
152 {
154 "Please specify the input meshes. \n At least two layers are "
155 "required to create a 3D Mesh");
156 return;
157 }
158
159 QString const xin = this->xlineEdit->text();
160 QString const yin = this->ylineEdit->text();
161 QString const zin = this->zlineEdit->text();
162
163 bool ok;
164 if (!xin.toDouble(&ok))
165 {
167 "At least the x-length of a voxel must be specified.\n If "
168 "y-/z-input "
169 "are not specified, equal to 0, or not a real number, they are "
170 "treated as "
171 "the x-input.");
172 return;
173 }
174 double const xinput = xin.toDouble();
175 double const yinput = (yin.toDouble(&ok)) ? yin.toDouble() : xin.toDouble();
176 double const zinput = (zin.toDouble(&ok)) ? zin.toDouble() : xin.toDouble();
177
178 std::vector<std::string> layered_meshes =
180
181 std::vector<const MeshLib::Mesh*> layers;
182 layers.reserve(layered_meshes.size());
183
184 for (auto const& layer : layered_meshes)
185 {
186 auto mesh(_mesh_model.getMesh(layer));
187 if (mesh == nullptr)
188 {
189 OGSError::box("Input layer " + QString::fromStdString(layer) +
190 " not found. Aborting...");
191 return;
192 }
193 layers.push_back(mesh);
194 }
195
196 bool const dilate = this->dilateBox->isChecked();
197 std::array<double, 3> const cellsize = {xinput, yinput, zinput};
198 constexpr double minval = std::numeric_limits<double>::max();
199 constexpr double maxval = std::numeric_limits<double>::lowest();
200 std::pair<MathLib::Point3d, MathLib::Point3d> extent(
201 MathLib::Point3d{{minval, minval, minval}},
202 MathLib::Point3d{{maxval, maxval, maxval}});
203 auto mesh(MeshToolsLib::MeshGenerators::VoxelFromLayeredMeshes::
204 createVoxelFromLayeredMesh(extent, layers, cellsize, dilate));
205
206 if (mesh == nullptr)
207 {
208 OGSError::box("The VoxelGrid is faulty");
209 return;
210 }
211 OGSError::box("The VoxelGrid is fine");
212
213 _mesh_model.addMesh(mesh.release());
214 this->done(QDialog::Accepted);
215}
static void box(const QString &e)
Definition OGSError.cpp:13
std::unique_ptr< MeshLib::Mesh > createVoxelFromLayeredMesh(std::pair< MathLib::Point3d, MathLib::Point3d > &extent, std::vector< MeshLib::Mesh const * > const &layers, std::array< double, 3 > const cellsize, bool const dilate)
std::vector< std::string > getSelectedObjects(QStringList const &list)

References _layeredMeshes, _mesh_model, OGSError::box(), and Utils::getSelectedObjects().

◆ on_deleteMeshButton_pressed()

void Layers2GridDialog::on_deleteMeshButton_pressed ( )
private

Instructions if the ">>" button has been pressed.

Definition at line 44 of file Layers2GridDialog.cpp.

45{
46 QModelIndex const selected =
47 this->allMeshView->selectionModel()->currentIndex();
48 _layeredMeshes.removeRow(selected.row());
49 QStringList list = _layeredMeshes.stringList();
50 _layeredMeshes.setStringList(list);
51}

References _layeredMeshes.

◆ on_downOrderButton_pressed()

void Layers2GridDialog::on_downOrderButton_pressed ( )
private

Instructions if the "↓"-button has been pressed.

Definition at line 74 of file Layers2GridDialog.cpp.

75{
76 QModelIndex selected = this->allMeshView->selectionModel()->currentIndex();
77 QStringList list = _layeredMeshes.stringList();
78 int row = selected.row();
79 if (row < list.size() - 1 && row != -1)
80 {
81 QString list_item = list[row + 1];
82 list[row + 1] = selected.data().toString();
83 list[row] = list_item;
84 }
85 _layeredMeshes.setStringList(list);
86 this->allMeshView->selectionModel()->setCurrentIndex(
87 _layeredMeshes.index(row + 1), QItemSelectionModel::SelectCurrent);
88}

References _layeredMeshes.

◆ on_orderButton_pressed()

void Layers2GridDialog::on_orderButton_pressed ( )
private

Instructions if the "order mesh"-button has been pressed.

Definition at line 53 of file Layers2GridDialog.cpp.

54{
55 _layeredMeshes.sort(0);
56}

References _layeredMeshes.

◆ on_upOrderButton_pressed()

void Layers2GridDialog::on_upOrderButton_pressed ( )
private

Instructions if the "↑"-button has been pressed.

Definition at line 58 of file Layers2GridDialog.cpp.

59{
60 QModelIndex selected = this->allMeshView->selectionModel()->currentIndex();
61 QStringList list = _layeredMeshes.stringList();
62 int row = selected.row();
63 if (row > 0)
64 {
65 QString list_item = list[row - 1];
66 list[row - 1] = selected.data().toString();
67 list[row] = list_item;
68 }
69 _layeredMeshes.setStringList(list);
70 this->allMeshView->selectionModel()->setCurrentIndex(
71 _layeredMeshes.index(row - 1), QItemSelectionModel::SelectCurrent);
72}

References _layeredMeshes.

◆ on_xlineEdit_textChanged()

void Layers2GridDialog::on_xlineEdit_textChanged ( )
private

Definition at line 134 of file Layers2GridDialog.cpp.

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

References updateExpectedVoxel().

◆ on_ylineEdit_textChanged()

void Layers2GridDialog::on_ylineEdit_textChanged ( )
private

Definition at line 139 of file Layers2GridDialog.cpp.

140{
142}

References updateExpectedVoxel().

◆ on_zlineEdit_textChanged()

void Layers2GridDialog::on_zlineEdit_textChanged ( )
private

Definition at line 144 of file Layers2GridDialog.cpp.

145{
147}

References updateExpectedVoxel().

◆ reject

void Layers2GridDialog::reject ( )
inlineoverrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 37 of file Layers2GridDialog.h.

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

◆ updateExpectedVoxel()

void Layers2GridDialog::updateExpectedVoxel ( )
private

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

Definition at line 90 of file Layers2GridDialog.cpp.

91{
92 QString const xin = this->xlineEdit->text();
93 QString const yin = this->ylineEdit->text();
94 QString const zin = this->zlineEdit->text();
95 bool ok;
96 double const xinput = xin.toDouble();
97 double const yinput = (yin.toDouble(&ok)) ? yin.toDouble() : xin.toDouble();
98 double const zinput = (zin.toDouble(&ok)) ? zin.toDouble() : xin.toDouble();
99
100 if (_layeredMeshes.stringList()[0] == "[No Mesh available.]")
101 {
102 this->expectedVoxelLabel->setText("approximated Voxel: undefined");
103 return;
104 }
105 if (xin.isEmpty() || xinput == 0)
106 {
107 this->expectedVoxelLabel->setText("approximated Voxel: undefined");
108 return;
109 }
110
111 std::vector<std::string> layered_meshes =
113 auto* const mesh_top = _mesh_model.getMesh(layered_meshes.front());
114 auto* const mesh_bottom = _mesh_model.getMesh(layered_meshes.back());
115 auto const& nodes_top = mesh_top->getNodes();
116
117 GeoLib::AABB const aabb_top(nodes_top.cbegin(), nodes_top.cend());
118 auto const& nodes_bottom = mesh_bottom->getNodes();
119 GeoLib::AABB const aabb_bottom(nodes_bottom.cbegin(), nodes_bottom.cend());
120 auto const min_b = aabb_bottom.getMinPoint();
121 auto const max_b = aabb_bottom.getMaxPoint();
122 auto const max_t = aabb_top.getMaxPoint();
123 double const expectedVoxel = (max_b[0] - min_b[0]) * (max_b[1] - min_b[1]) *
124 (max_t[2] - min_b[2]) / xinput / yinput /
125 zinput;
126
127 int const exponent = std::floor(std::log10(abs(expectedVoxel)));
128 this->expectedVoxelLabel->setText(
129 "approximated Voxel = " +
130 QString::number(std::round(expectedVoxel / std::pow(10, exponent))) +
131 " x 10^" + QString::number(exponent));
132}

References _layeredMeshes, _mesh_model, GeoLib::AABB::getMaxPoint(), GeoLib::AABB::getMinPoint(), and Utils::getSelectedObjects().

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

Member Data Documentation

◆ _layeredMeshes

QStringListModel Layers2GridDialog::_layeredMeshes
private

◆ _mesh_model

MeshModel& Layers2GridDialog::_mesh_model
private

Definition at line 29 of file Layers2GridDialog.h.

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

◆ _neglectedMeshes

QStringListModel Layers2GridDialog::_neglectedMeshes
private

Definition at line 31 of file Layers2GridDialog.h.


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