OGS
Layers2GridDialog Class Reference

Detailed Description

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

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

References _layeredMeshes, 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 157 of file Layers2GridDialog.cpp.

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

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

◆ on_deleteMeshButton_pressed()

void Layers2GridDialog::on_deleteMeshButton_pressed ( )
private

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

Definition at line 52 of file Layers2GridDialog.cpp.

53{
54 QModelIndex const selected =
55 this->allMeshView->selectionModel()->currentIndex();
56 _layeredMeshes.removeRow(selected.row());
57 QStringList list = _layeredMeshes.stringList();
58 _layeredMeshes.setStringList(list);
59}

References _layeredMeshes.

◆ on_downOrderButton_pressed()

void Layers2GridDialog::on_downOrderButton_pressed ( )
private

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

Definition at line 82 of file Layers2GridDialog.cpp.

83{
84 QModelIndex selected = this->allMeshView->selectionModel()->currentIndex();
85 QStringList list = _layeredMeshes.stringList();
86 int row = selected.row();
87 if (row < list.size() - 1 && row != -1)
88 {
89 QString list_item = list[row + 1];
90 list[row + 1] = selected.data().toString();
91 list[row] = list_item;
92 }
93 _layeredMeshes.setStringList(list);
94 this->allMeshView->selectionModel()->setCurrentIndex(
95 _layeredMeshes.index(row + 1), QItemSelectionModel::SelectCurrent);
96}

References _layeredMeshes.

◆ on_orderButton_pressed()

void Layers2GridDialog::on_orderButton_pressed ( )
private

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

Definition at line 61 of file Layers2GridDialog.cpp.

62{
63 _layeredMeshes.sort(0);
64}

References _layeredMeshes.

◆ on_upOrderButton_pressed()

void Layers2GridDialog::on_upOrderButton_pressed ( )
private

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

Definition at line 66 of file Layers2GridDialog.cpp.

67{
68 QModelIndex selected = this->allMeshView->selectionModel()->currentIndex();
69 QStringList list = _layeredMeshes.stringList();
70 int row = selected.row();
71 if (row > 0)
72 {
73 QString list_item = list[row - 1];
74 list[row - 1] = selected.data().toString();
75 list[row] = list_item;
76 }
77 _layeredMeshes.setStringList(list);
78 this->allMeshView->selectionModel()->setCurrentIndex(
79 _layeredMeshes.index(row - 1), QItemSelectionModel::SelectCurrent);
80}

References _layeredMeshes.

◆ on_xlineEdit_textChanged()

void Layers2GridDialog::on_xlineEdit_textChanged ( )
private

Definition at line 142 of file Layers2GridDialog.cpp.

143{
145}
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 147 of file Layers2GridDialog.cpp.

148{
150}

References updateExpectedVoxel().

◆ on_zlineEdit_textChanged()

void Layers2GridDialog::on_zlineEdit_textChanged ( )
private

Definition at line 152 of file Layers2GridDialog.cpp.

153{
155}

References updateExpectedVoxel().

◆ reject

void Layers2GridDialog::reject ( )
inlineoverrideprivateslot

Instructions if the Cancel-Button has been pressed.

Definition at line 46 of file Layers2GridDialog.h.

46{ 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 98 of file Layers2GridDialog.cpp.

99{
100 QString const xin = this->xlineEdit->text();
101 QString const yin = this->ylineEdit->text();
102 QString const zin = this->zlineEdit->text();
103 bool ok;
104 double const xinput = xin.toDouble();
105 double const yinput = (yin.toDouble(&ok)) ? yin.toDouble() : xin.toDouble();
106 double const zinput = (zin.toDouble(&ok)) ? zin.toDouble() : xin.toDouble();
107
108 if (_layeredMeshes.stringList()[0] == "[No Mesh available.]")
109 {
110 this->expectedVoxelLabel->setText("approximated Voxel: undefined");
111 return;
112 }
113 if (xin.isEmpty() || xinput == 0)
114 {
115 this->expectedVoxelLabel->setText("approximated Voxel: undefined");
116 return;
117 }
118
119 std::vector<std::string> layered_meshes =
121 auto* const mesh_top = _mesh_model.getMesh(layered_meshes.front());
122 auto* const mesh_bottom = _mesh_model.getMesh(layered_meshes.back());
123 auto const& nodes_top = mesh_top->getNodes();
124
125 GeoLib::AABB const aabb_top(nodes_top.cbegin(), nodes_top.cend());
126 auto const& nodes_bottom = mesh_bottom->getNodes();
127 GeoLib::AABB const aabb_bottom(nodes_bottom.cbegin(), nodes_bottom.cend());
128 auto const min_b = aabb_bottom.getMinPoint();
129 auto const max_b = aabb_bottom.getMaxPoint();
130 auto const max_t = aabb_top.getMaxPoint();
131 double const expectedVoxel = (max_b[0] - min_b[0]) * (max_b[1] - min_b[1]) *
132 (max_t[2] - min_b[2]) / xinput / yinput /
133 zinput;
134
135 int const exponent = std::floor(std::log10(abs(expectedVoxel)));
136 this->expectedVoxelLabel->setText(
137 "approximated Voxel = " +
138 QString::number(std::round(expectedVoxel / std::pow(10, exponent))) +
139 " x 10^" + QString::number(exponent));
140}
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106

References _layeredMeshes, _mesh_model, GeoLib::AABB::getMaxPoint(), MeshModel::getMesh(), GeoLib::AABB::getMinPoint(), MeshLib::Mesh::getNodes(), 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 38 of file Layers2GridDialog.h.

Referenced by accept(), and updateExpectedVoxel().

◆ _neglectedMeshes

QStringListModel Layers2GridDialog::_neglectedMeshes
private

Definition at line 40 of file Layers2GridDialog.h.


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