OGS
MeshElementRemovalDialog.cpp
Go to the documentation of this file.
1 
16 
17 #include <Eigen/StdVector>
18 #include <QList>
19 #include <QListWidgetItem>
20 #include <algorithm>
21 
24 #include "GeoLib/AABB.h"
26 #include "MeshLib/Mesh.h"
29 #include "MeshLib/Node.h"
30 #include "MeshLib/Properties.h"
31 
34  DataHolderLib::Project const& project, QDialog* parent)
35  : QDialog(parent),
36  _project(project),
37  _currentIndex(0),
38  _aabbIndex(std::numeric_limits<unsigned>::max()),
39  _scalarIndex(std::numeric_limits<unsigned>::max())
40 {
41  setupUi(this);
42 
43  auto const& mesh_vec(_project.getMeshObjects());
44 
45  const std::size_t nMeshes(mesh_vec.size());
46  for (std::size_t i = 0; i < nMeshes; ++i)
47  {
48  std::string name = mesh_vec[i]->getName();
49  this->meshNameComboBox->addItem(QString::fromStdString(name));
50  }
51 
52  if (mesh_vec.empty())
53  {
54  OGSError::box("No meshes available.");
55  QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection);
56  }
57 }
58 
60 
62 {
63  if (this->newMeshNameEdit->text().size() == 0)
64  {
65  OGSError::box("Please enter name for new mesh.");
66  return;
67  }
68 
69  bool anything_checked(false);
70 
71  const MeshLib::Mesh* msh =
72  _project.getMesh(this->meshNameComboBox->currentText().toStdString());
73  MeshLib::ElementSearch ex(*msh);
74  if (this->elementTypeCheckBox->isChecked())
75  {
76  QList<QListWidgetItem*> items =
77  this->elementTypeListWidget->selectedItems();
78  for (auto& item : items)
79  {
81  MeshLib::String2MeshElemType(item->text().toStdString()));
82  }
83  anything_checked = true;
84  }
85  if (this->scalarArrayCheckBox->isChecked())
86  {
87  std::string const array_name =
88  this->scalarArrayComboBox->currentText().toStdString();
89  double min_val;
90  double max_val;
91  bool outside = this->outsideButton->isChecked();
92  if (outside)
93  {
94  min_val = this->outsideScalarMinEdit->text().toDouble();
95  max_val = this->outsideScalarMaxEdit->text().toDouble();
96  }
97  else
98  {
99  min_val = this->insideScalarMinEdit->text().toDouble();
100  max_val = this->insideScalarMaxEdit->text().toDouble();
101  }
102 
103  std::size_t n_marked_elements(0);
104  if (msh->getProperties().existsPropertyVector<double>(array_name))
105  {
106  n_marked_elements = ex.searchByPropertyValueRange<double>(
107  array_name, min_val, max_val, outside);
108  }
109  if (msh->getProperties().existsPropertyVector<int>(array_name))
110  {
111  int const lbound = static_cast<int>(min_val);
112  int const rbound = static_cast<int>(max_val);
113  n_marked_elements = ex.searchByPropertyValueRange<int>(
114  array_name, lbound, rbound, outside);
115  }
116 
117  if (n_marked_elements > 0)
118  {
119  anything_checked = true;
120  }
121  }
122  if (this->boundingBoxCheckBox->isChecked())
123  {
124  std::vector<MeshLib::Node*> const& nodes(
125  _project
126  .getMesh(this->meshNameComboBox->currentText().toStdString())
127  ->getNodes());
128  GeoLib::AABB const aabb(nodes.begin(), nodes.end());
129  auto minAABB = aabb.getMinPoint();
130  auto maxAABB = aabb.getMaxPoint();
131 
132  // only extract bounding box parameters that have been edited (otherwise
133  // there will be rounding errors!)
134  minAABB[0] =
135  (aabb_edits[0]) ? this->xMinEdit->text().toDouble() : (minAABB[0]);
136  maxAABB[0] =
137  (aabb_edits[1]) ? this->xMaxEdit->text().toDouble() : (maxAABB[0]);
138  minAABB[1] =
139  (aabb_edits[2]) ? this->yMinEdit->text().toDouble() : (minAABB[1]);
140  maxAABB[1] =
141  (aabb_edits[3]) ? this->yMaxEdit->text().toDouble() : (maxAABB[1]);
142  minAABB[2] =
143  (aabb_edits[4]) ? this->zMinEdit->text().toDouble() : (minAABB[2]);
144  maxAABB[2] =
145  (aabb_edits[5]) ? this->zMaxEdit->text().toDouble() : (maxAABB[2]);
146  std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>
147  extent{minAABB, maxAABB};
148  const GeoLib::AABB updated_aabb(extent.begin(), extent.end());
149  ex.searchByBoundingBox(updated_aabb);
150  anything_checked = true;
151  }
152 
153  if (this->zeroVolumeCheckBox->isChecked())
154  {
155  ex.searchByContent();
156  anything_checked = true;
157  }
158 
159  if (anything_checked)
160  {
162  *msh, ex.getSearchedElementIDs(),
163  this->newMeshNameEdit->text().toStdString());
164  if (new_mesh)
165  {
166  emit meshAdded(new_mesh);
167  }
168  else
169  {
170  if (ex.getSearchedElementIDs().empty())
171  {
173  "The current selection removes NO mesh elements.");
174  }
175  return;
176  }
177  }
178  else
179  {
180  OGSError::box("No condition set for elements to remove.");
181  return;
182  }
183 
184  this->done(QDialog::Accepted);
185 }
186 
188 {
189  this->done(QDialog::Rejected);
190 }
191 
193  MeshLib::Mesh const& mesh) const
194 {
195  for (auto [name, property] : mesh.getProperties())
196  {
197  if (property->getMeshItemType() != MeshLib::MeshItemType::Cell)
198  {
199  continue;
200  }
201  this->scalarArrayComboBox->addItem(QString::fromStdString(name));
203  }
204  return this->scalarArrayComboBox->count();
205 }
206 
208 {
209  this->scalarArrayComboBox->setEnabled(enable);
210  this->outsideButton->setEnabled(enable);
211  this->insideButton->setEnabled(enable);
212  this->outsideScalarMinEdit->setEnabled(enable &&
213  this->outsideButton->isChecked());
214  this->outsideScalarMaxEdit->setEnabled(enable &&
215  this->outsideButton->isChecked());
216  this->insideScalarMinEdit->setEnabled(enable &&
217  this->insideButton->isChecked());
218  this->insideScalarMaxEdit->setEnabled(enable &&
219  this->insideButton->isChecked());
220 }
221 
223 {
224  this->outsideScalarMinEdit->setEnabled(outside);
225  this->outsideScalarMaxEdit->setEnabled(outside);
226  this->insideScalarMinEdit->setEnabled(!outside);
227  this->insideScalarMaxEdit->setEnabled(!outside);
228 }
229 
231 {
232  toggleScalarEdits(!this->insideButton->isChecked());
233 }
234 
236 {
237  this->xMinEdit->setEnabled(is_checked);
238  this->xMaxEdit->setEnabled(is_checked);
239  this->yMinEdit->setEnabled(is_checked);
240  this->yMaxEdit->setEnabled(is_checked);
241  this->zMinEdit->setEnabled(is_checked);
242  this->zMaxEdit->setEnabled(is_checked);
243 
244  if (is_checked && (_currentIndex != _aabbIndex))
245  {
247  std::vector<MeshLib::Node*> const& nodes(
248  _project
249  .getMesh(this->meshNameComboBox->currentText().toStdString())
250  ->getNodes());
251  GeoLib::AABB aabb(nodes.begin(), nodes.end());
252  auto const& minAABB = aabb.getMinPoint();
253  auto const& maxAABB = aabb.getMaxPoint();
254  this->xMinEdit->setText(QString::number(minAABB[0], 'f'));
255  this->xMaxEdit->setText(QString::number(maxAABB[0], 'f'));
256  this->yMinEdit->setText(QString::number(minAABB[1], 'f'));
257  this->yMaxEdit->setText(QString::number(maxAABB[1], 'f'));
258  this->zMinEdit->setText(QString::number(minAABB[2], 'f'));
259  this->zMaxEdit->setText(QString::number(maxAABB[2], 'f'));
260  aabb_edits.fill(false);
261  }
262 }
263 
265 {
266  this->elementTypeListWidget->setEnabled(is_checked);
267 }
268 
270 {
271  if (!is_checked)
272  {
274  return;
275  }
276 
277  MeshLib::Mesh const* const mesh =
278  _project.getMesh(meshNameComboBox->currentText().toStdString());
279  if (addScalarArrays(*mesh) > 0)
280  {
282  }
283  else
284  {
286  OGSError::box("No scalar arrays found");
288  }
289 }
290 
292 {
293  Q_UNUSED(idx);
294  this->_currentIndex = this->meshNameComboBox->currentIndex();
295  this->newMeshNameEdit->setText(this->meshNameComboBox->currentText() +
296  "_new");
297  this->elementTypeListWidget->clearSelection();
298  this->scalarArrayComboBox->clear();
299  this->outsideScalarMinEdit->setText("");
300  this->outsideScalarMaxEdit->setText("");
301  this->insideScalarMinEdit->setText("");
302  this->insideScalarMaxEdit->setText("");
303  on_scalarArrayCheckBox_toggled(this->scalarArrayCheckBox->isChecked());
304  on_boundingBoxCheckBox_toggled(this->boundingBoxCheckBox->isChecked());
305 }
306 
308  int idx)
309 {
310  Q_UNUSED(idx);
311  std::string const vec_name(
312  scalarArrayComboBox->currentText().toStdString());
313  if (vec_name.empty())
314  {
315  return;
316  }
317 
318  MeshLib::Mesh const* const mesh =
319  _project.getMesh(meshNameComboBox->currentText().toStdString());
320  if (mesh == nullptr)
321  {
322  return;
323  }
324  MeshLib::Properties const& properties = mesh->getProperties();
325 
326  if (properties.existsPropertyVector<int>(vec_name))
327  {
328  setRangeValues<int>(*properties.getPropertyVector<int>(vec_name));
329  }
330  else if (properties.existsPropertyVector<double>(vec_name))
331  {
332  setRangeValues<double>(*properties.getPropertyVector<double>(vec_name));
333  }
334 }
335 
336 template <typename T>
338  MeshLib::PropertyVector<T> const& vec)
339 {
340  auto min = std::min_element(vec.cbegin(), vec.cend());
341  auto max = std::max_element(vec.cbegin(), vec.cend());
342  this->outsideScalarMinEdit->setText(QString::number(*min));
343  this->outsideScalarMaxEdit->setText(QString::number(*max));
344  this->insideScalarMinEdit->setText(QString::number(*min));
345  this->insideScalarMaxEdit->setText(QString::number(*max));
346 }
Definition of the AABB class.
Definition of the Element class.
Definition of the MeshElementRemovalDialog class.
Definition of the class Properties that implements a container of properties.
Definition of the Mesh class.
Definition of the Node class.
Definition of the OGSError class.
const std::vector< std::unique_ptr< MeshLib::Mesh > > & getMeshObjects() const
Returns all the meshes with their respective names.
Definition: Project.h:57
const MeshLib::Mesh * getMesh(const std::string &name) const
Definition: Project.cpp:43
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition: AABB.h:49
Eigen::Vector3d const & getMinPoint() const
Definition: AABB.h:174
Eigen::Vector3d const & getMaxPoint() const
Definition: AABB.h:181
~MeshElementRemovalDialog() override
void setRangeValues(MeshLib::PropertyVector< T > const &vec)
void on_elementTypeCheckBox_toggled(bool is_checked)
MeshElementRemovalDialog(DataHolderLib::Project const &project, QDialog *parent=nullptr)
Constructor.
void toggleScalarEdits(bool outside) const
DataHolderLib::Project const & _project
void on_insideButton_toggled(bool is_checked)
void on_meshNameComboBox_currentIndexChanged(int idx)
void meshAdded(MeshLib::Mesh *mesh)
void on_scalarArrayCheckBox_toggled(bool is_checked)
void on_scalarArrayComboBox_currentIndexChanged(int idx)
std::size_t addScalarArrays(MeshLib::Mesh const &mesh) const
void enableScalarArrayWidgets(bool enable) const
std::array< bool, 6 > aabb_edits
void on_boundingBoxCheckBox_toggled(bool is_checked)
Element search class.
Definition: ElementSearch.h:28
std::size_t searchByElementType(MeshElemType eleType)
Marks all elements of the given element type.
std::size_t searchByPropertyValueRange(std::string const &property_name, PROPERTY_TYPE const min_property_value, PROPERTY_TYPE const max_property_value, bool outside_of)
Definition: ElementSearch.h:70
std::size_t searchByContent(double eps=std::numeric_limits< double >::epsilon())
Marks all elements with a volume smaller than eps.
std::size_t searchByBoundingBox(GeoLib::AABB const &aabb)
Marks all elements with at least one node outside the bounding box spanned by x1 and x2;.
const std::vector< std::size_t > & getSearchedElementIDs() const
return marked elements
Definition: ElementSearch.h:33
Properties & getProperties()
Definition: Mesh.h:123
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition: Properties.h:36
PropertyVector< T > const * getPropertyVector(std::string const &name) const
bool existsPropertyVector(std::string const &name) const
static void box(const QString &e)
Definition: OGSError.cpp:23
MeshLib::Mesh * removeElements(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &removed_element_ids, const std::string &new_mesh_name)
MeshElemType String2MeshElemType(const std::string &s)
Given a string of the shortened name of the element type, this returns the corresponding MeshElemType...
Definition: MeshEnums.cpp:95