OGS
MeshAnalysisDialog.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
7#include "MeshLib/Mesh.h"
11
13 std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec,
14 QDialog* parent)
15 : QDialog(parent), _mesh_vec(mesh_vec)
16{
17 setupUi(this);
18
19 if (mesh_vec.empty())
20 {
21 this->startButton->setDisabled(true);
22 }
23
24 for (const auto& mesh : mesh_vec)
25 {
26 this->meshListBox->addItem(QString::fromStdString(mesh->getName()));
27 }
28
29 auto* collapse_threshold_validator =
30 new StrictDoubleValidator(0, 1000000, 7, this);
31 this->collapsibleNodesThreshold->setValidator(collapse_threshold_validator);
32
33 auto* volume_threshold_validator =
34 new StrictDoubleValidator(0, 1e10, 10, this);
35 this->zeroVolumeThreshold->setValidator(volume_threshold_validator);
36}
37
39
41{
42 MeshLib::Mesh const& mesh(
43 *_mesh_vec[this->meshListBox->currentIndex()].get());
44
45 MeshLib::NodeSearch ns(mesh);
46 ns.searchUnused();
47 const std::vector<std::size_t> unusedNodesIdx(ns.getSearchedNodeIDs());
48 MeshToolsLib::MeshRevision rev(const_cast<MeshLib::Mesh&>(mesh));
49 std::vector<std::size_t> const& collapsibleNodeIds(rev.collapseNodeIndices(
50 this->collapsibleNodesThreshold->text().toDouble() +
51 std::numeric_limits<double>::epsilon()));
52 this->nodesGroupBox->setTitle(
53 "Nodes (out of " + QString::number(mesh.getNumberOfNodes()) + ")");
54 this->nodesMsgOutput(unusedNodesIdx, collapsibleNodeIds);
55
56 const std::vector<ElementErrorCode> element_error_codes(
58 mesh,
59 this->zeroVolumeThreshold->text().toDouble() +
60 std::numeric_limits<double>::epsilon()));
61 this->elementsGroupBox->setTitle(
62 "Elements (out of " + QString::number(mesh.getNumberOfElements()) +
63 ")");
64 this->elementsMsgOutput(element_error_codes);
65
66 unsigned const n_holes(MeshToolsLib::MeshValidation::detectHoles(mesh));
67 if (n_holes > 0)
68 {
69 this->meshHoleOutputLabel->setText(
70 "<strong>" + QString::number(n_holes) +
71 " hole(s) found within the mesh</strong>");
72 }
73}
74
76 std::vector<std::size_t> const& node_ids,
77 std::vector<std::size_t> const& collapsibleNodeIds)
78{
79 const std::size_t nNodeIds(node_ids.size());
80 QString nodes_output("");
81 if (node_ids.empty())
82 {
83 nodes_output += "No unused nodes found.";
84 }
85 else
86 {
87 nodes_output += (QString::number(nNodeIds) +
88 " nodes are not part of any element:\n");
89 for (std::size_t i = 0; i < nNodeIds; ++i)
90 {
91 nodes_output += (QString::number(node_ids[i]) + ", ");
92 }
93 }
94 this->unusedNodesText->setText(nodes_output);
95
96 std::size_t const nNodes(collapsibleNodeIds.size());
97 QString node_ids_str("");
98 unsigned count(0);
99 for (std::size_t i = 0; i < nNodes; ++i)
100 {
101 if (i != collapsibleNodeIds[i])
102 {
103 node_ids_str.append(QString::number(i) + ", ");
104 count++;
105 }
106 }
107 nodes_output = (count > 0) ? QString::number(count) + " nodes found:\n"
108 : "No nodes found.";
109 nodes_output.append(node_ids_str);
110 this->collapsibleNodesText->setText(nodes_output);
111}
112
114 const std::vector<ElementErrorCode>& element_error_codes)
115{
116 std::array<std::string,
117 static_cast<std::size_t>(ElementErrorFlag::MaxValue)>
119 element_error_codes));
120
121 this->zeroVolumeText->setText(QString::fromStdString(output_str[0]));
122 this->nonPlanarText->setText(QString::fromStdString(output_str[1]));
123 this->nonConvexText->setText(QString::fromStdString(output_str[2]));
124 this->nodeOrderText->setText(QString::fromStdString(output_str[3]));
125}
void on_startButton_pressed()
Starts the analysis.
MeshAnalysisDialog(std::vector< std::unique_ptr< MeshLib::Mesh > > const &mesh_vec, QDialog *parent=nullptr)
void elementsMsgOutput(const std::vector< ElementErrorCode > &error_codes)
Prepares the output for the node message window.
~MeshAnalysisDialog() override
std::vector< std::unique_ptr< MeshLib::Mesh > > const & _mesh_vec
void nodesMsgOutput(std::vector< std::size_t > const &node_ids, std::vector< std::size_t > const &collapsibleNodeIds)
Prepares the output for the node message window.
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:91
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:88
Node search class.
Definition NodeSearch.h:18
const std::vector< std::size_t > & getSearchedNodeIDs() const
return marked node IDs
Definition NodeSearch.h:23
std::size_t searchUnused()
Marks all unused nodes.
std::vector< std::size_t > collapseNodeIndices(double eps) const
A validator for an input field which only accepts decimals. Source code adapted from StackOverflow
static unsigned detectHoles(MeshLib::Mesh const &mesh)
static std::array< std::string, static_cast< std::size_t >(ElementErrorFlag::MaxValue)> ElementErrorCodeOutput(const std::vector< ElementErrorCode > &error_codes)
static std::vector< ElementErrorCode > testElementGeometry(const MeshLib::Mesh &mesh, double min_volume=std::numeric_limits< double >::epsilon())