OGS
Layers2GridDialog.cpp
Go to the documentation of this file.
1
13#include "Layers2GridDialog.h"
14
15#include <QStringList>
16#include <QStringListModel>
17
19#include "Base/Utils.h"
20#include "GeoLib/AABB.h"
22#include "MeshLib/Mesh.h"
23#include "MeshLib/Node.h"
24#include "MeshModel.h"
26
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}
51
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}
60
65
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}
81
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}
97
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}
141
146
151
156
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}
Definition of the AABB class.
Definition of the Layers2GridDialog class.
Definition of the MeshModel class.
Definition of the Mesh class.
Definition of the Node class.
Implementation of the StrictDoubleValidator class.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
Eigen::Vector3d const & getMaxPoint() const
Definition AABB.h:187
Eigen::Vector3d const & getMinPoint() const
Definition AABB.h:180
void on_upOrderButton_pressed()
Instructions if the "↑"-button has been pressed.
void on_downOrderButton_pressed()
Instructions if the "↓"-button has been pressed.
void on_deleteMeshButton_pressed()
Instructions if the ">>" button has been pressed.
void accept() override
Instructions if the OK-Button has been pressed.
void on_orderButton_pressed()
Instructions if the "order mesh"-button has been pressed.
QStringListModel _layeredMeshes
Layers2GridDialog(MeshModel &mesh_model, QDialog *parent=nullptr)
void updateExpectedVoxel()
As the x/y/z input changes an estimation of the expected Voxel is given.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106
void addMesh(std::unique_ptr< MeshLib::Mesh > mesh)
Adds a new mesh.
Definition MeshModel.cpp:52
const MeshLib::Mesh * getMesh(const QModelIndex &idx) const
Returns the mesh with the given index.
Definition MeshModel.cpp:96
static void box(const QString &e)
Definition OGSError.cpp:23
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.cpp:50
std::vector< std::string > getSelectedObjects(QStringList const &list)
Definition Utils.cpp:15