OGS
ElementTreeModel.cpp
Go to the documentation of this file.
1
15#include "ElementTreeModel.h"
16
17#include "Base/TreeItem.h"
18#include "GeoLib/AABB.h"
20#include "MeshLib/Mesh.h"
21#include "MeshLib/Node.h"
24
25namespace
26{
27template <typename PropertyType>
28QList<QVariant> propertyBounds(PropertyType const& property)
29{
30 auto const bounds = MeshToolsLib::MeshInformation::getValueBounds(property);
31 if (bounds.has_value())
32 {
33 return {"[" + QString::number(bounds->first) + ",",
34 QString::number(bounds->second) + "]"};
35 }
36 // Makeup the same structure of output as in the valid case above.
37 return {"[empty,", "empty]"};
38}
39} // namespace
40
45{
46 QList<QVariant> rootData;
47 delete _rootItem;
48 rootData << "Name"
49 << "Type"
50 << ""
51 << "";
52 _rootItem = new TreeItem(rootData, nullptr);
53}
54
56
58 vtkUnstructuredGridAlgorithm const* const grid, const unsigned elem_index)
59{
60 beginResetModel();
61
62 _mesh_source = grid;
63 this->clearView();
64
65 auto const* const source =
66 dynamic_cast<MeshLib::VtkMappedMeshSource const* const>(grid);
67
68 if (!source)
69 {
70 return;
71 }
72
73 const MeshLib::Mesh* mesh = source->GetMesh();
74 const MeshLib::Element* elem = mesh->getElement(elem_index);
75
76 QList<QVariant> elemData;
77 elemData << "Element " + QString::number(elem_index) << ""
78 << ""
79 << "";
80 auto* elemItem = new TreeItem(elemData, _rootItem);
81 _rootItem->appendChild(elemItem);
82
83 QList<QVariant> typeData;
84 typeData << "Element Type: "
85 << QString::fromStdString(
86 MeshElemType2String(elem->getGeomType()));
87 auto* typeItem = new TreeItem(typeData, elemItem);
88 elemItem->appendChild(typeItem);
89
90 auto const mat_ids = materialIDs(*mesh);
91 QString matIdString = !mat_ids ? QString("not defined")
92 : QString::number((*mat_ids)[elem->getID()]);
93 QList<QVariant> materialData;
94 materialData << "MaterialID: " << matIdString;
95 auto* matItem = new TreeItem(materialData, elemItem);
96 elemItem->appendChild(matItem);
97
98 QList<QVariant> volData;
99 volData << "Area/Volume: "
100 << QString::number(mesh->getElement(elem_index)->getContent());
101 auto* volItem = new TreeItem(volData, elemItem);
102 elemItem->appendChild(volItem);
103
104 QList<QVariant> nodeListData;
105 nodeListData << "Nodes"
106 << ""
107 << ""
108 << "";
109 auto* nodeListItem = new TreeItem(nodeListData, elemItem);
110 elemItem->appendChild(nodeListItem);
111
112 // const std::vector<MeshLib::Node*> nodes_vec = grid->getNodes();
113 std::size_t nElemNodes = elem->getNumberOfBaseNodes();
114 for (std::size_t i = 0; i < nElemNodes; i++)
115 {
116 const MeshLib::Node* node = elem->getNode(i);
117 QList<QVariant> nodeData;
118 nodeData << "Node " + QString::number(node->getID())
119 << QString::number((*node)[0], 'f', 6)
120 << QString::number((*node)[1], 'f', 6)
121 << QString::number((*node)[2], 'f', 6);
122 auto* nodeItem = new TreeItem(nodeData, nodeListItem);
123 nodeListItem->appendChild(nodeItem);
124 }
125 endResetModel();
126}
127
129{
130 beginResetModel();
132 endResetModel();
133}
134
136{
137 beginResetModel();
138
139 this->clearView();
140
141 QList<QVariant> mesh_name;
142 mesh_name << "Name:" << QString::fromStdString(mesh.getName()) << ""
143 << ""
144 << "";
145 auto* name_item = new TreeItem(mesh_name, _rootItem);
146 _rootItem->appendChild(name_item);
147
148 QList<QVariant> nodes_number;
149 nodes_number << "#Nodes: " << QString::number(mesh.getNumberOfNodes()) << ""
150 << "";
151 auto* nodes_item = new TreeItem(nodes_number, _rootItem);
152 _rootItem->appendChild(nodes_item);
153
154 QList<QVariant> elements_number;
155 elements_number << "#Elements: "
156 << QString::number(mesh.getNumberOfElements()) << ""
157 << "";
158 auto* elements_item = new TreeItem(elements_number, _rootItem);
159 _rootItem->appendChild(elements_item);
160
161 auto const& n_element_types =
163 for (auto entry : n_element_types)
164 {
165 QList<QVariant> number_of_element_types;
166 number_of_element_types
167 << QString::fromStdString(
169 static_cast<MeshLib::MeshElemType>(entry.first)) +
170 "s:")
171 << QString::number(entry.second) << ""
172 << "";
173 auto* type_item = new TreeItem(number_of_element_types, elements_item);
174 elements_item->appendChild(type_item);
175 }
176
177 QList<QVariant> bounding_box;
178 bounding_box << "Bounding Box"
179 << ""
180 << ""
181 << "";
182 auto* aabb_item = new TreeItem(bounding_box, _rootItem);
183 _rootItem->appendChild(aabb_item);
184
185 {
186 const GeoLib::AABB aabb(
188 auto const [min, max] = aabb.getMinMaxPoints();
189
190 QList<QVariant> min_aabb;
191 min_aabb << "Min:" << QString::number(min[0], 'f')
192 << QString::number(min[1], 'f')
193 << QString::number(min[2], 'f');
194 auto* min_item = new TreeItem(min_aabb, aabb_item);
195 aabb_item->appendChild(min_item);
196
197 QList<QVariant> max_aabb;
198 max_aabb << "Max:" << QString::number(max[0], 'f')
199 << QString::number(max[1], 'f')
200 << QString::number(max[2], 'f');
201 auto* max_item = new TreeItem(max_aabb, aabb_item);
202 aabb_item->appendChild(max_item);
203 }
204
205 QList<QVariant> edges;
206 {
207 auto const [min, max] = minMaxEdgeLength(mesh.getElements());
208 edges << "Edge Length: "
209 << "[" + QString::number(min, 'f') + ","
210 << QString::number(max, 'f') + "]"
211 << "";
212 }
213 auto* edge_item = new TreeItem(edges, _rootItem);
214 _rootItem->appendChild(edge_item);
215
216 for (auto [name, property] : mesh.getProperties())
217 {
218 QList<QVariant> array_info{QString::fromStdString(std::string(name)) +
219 ": "};
220
221 if (auto p = dynamic_cast<MeshLib::PropertyVector<double>*>(property))
222 {
223 array_info.append(propertyBounds(*p));
224 }
225 else if (auto p =
226 dynamic_cast<MeshLib::PropertyVector<float>*>(property))
227 {
228 array_info.append(propertyBounds(*p));
229 }
230 else if (auto p = dynamic_cast<MeshLib::PropertyVector<int>*>(property))
231 {
232 array_info.append(propertyBounds(*p));
233 }
234 else if (auto p =
235 dynamic_cast<MeshLib::PropertyVector<unsigned>*>(property))
236 {
237 array_info.append(propertyBounds(*p));
238 }
239 else if (auto p =
240 dynamic_cast<MeshLib::PropertyVector<long>*>(property))
241 {
242 array_info.append(propertyBounds(*p));
243 }
244 else if (auto p = dynamic_cast<MeshLib::PropertyVector<long long>*>(
245 property))
246 {
247 array_info.append(propertyBounds(*p));
248 }
249 else if (auto p = dynamic_cast<MeshLib::PropertyVector<unsigned long>*>(
250 property))
251 {
252 array_info.append(propertyBounds(*p));
253 }
254 else if (auto p =
256 property))
257 {
258 array_info.append(propertyBounds(*p));
259 }
260 else if (auto p = dynamic_cast<MeshLib::PropertyVector<std::size_t>*>(
261 property))
262 {
263 array_info.append(propertyBounds(*p));
264 }
265 else if (auto p =
266 dynamic_cast<MeshLib::PropertyVector<char>*>(property))
267 {
268 array_info.append(propertyBounds(*p));
269 }
270 else
271 { // Unhandled property vector type.
272 array_info << "[ ?"
273 << "? ]"
274 << "";
275 }
276 _rootItem->appendChild(new TreeItem(array_info, _rootItem));
277 }
278
279 endResetModel();
280}
Definition of the AABB class.
Definition of the ElementTreeModel class.
Definition of the Element class.
Definition of the MeshInformation class.
Definition of the Mesh class.
Definition of the Node class.
Definition of the TreeItem class.
VtkMappedMeshSource is a source class to transform OGS meshes into complete vtkUnstructuredGrids....
void setElement(vtkUnstructuredGridAlgorithm const *const grid, const unsigned elem_index)
Displays information of the element with the given index from the given grid.
~ElementTreeModel() override
vtkUnstructuredGridAlgorithm const * _mesh_source
void clearView()
Clears the tree.
ElementTreeModel(QObject *parent=nullptr)
void setMesh(MeshLib::Mesh const &mesh)
Displays information of the given mesh.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
MinMaxPoints getMinMaxPoints() const
Definition AABB.h:174
std::size_t getID() const
virtual MeshElemType getGeomType() const =0
virtual double getContent() const =0
Returns the length, area or volume of a 1D, 2D or 3D element.
virtual unsigned getNumberOfBaseNodes() const =0
virtual const Node * getNode(unsigned idx) const =0
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:89
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
Properties & getProperties()
Definition Mesh.h:134
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition Mesh.h:94
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:100
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:97
static GeoLib::AABB getBoundingBox(const MeshLib::Mesh &mesh)
Returns the bounding box of the mesh.
static std::optional< std::pair< T, T > > const getValueBounds(MeshLib::PropertyVector< T > const &property)
static std::map< MeshLib::MeshElemType, unsigned > getNumberOfElementTypes(const MeshLib::Mesh &mesh)
Objects nodes for the TreeModel.
Definition TreeItem.h:28
virtual int childCount() const
Definition TreeItem.cpp:65
void appendChild(TreeItem *item)
Definition TreeItem.cpp:42
bool removeChildren(int position, int count)
Definition TreeItem.cpp:124
A hierarchical model for a tree implemented as a double-linked list.
Definition TreeModel.h:30
TreeItem * _rootItem
Definition TreeModel.h:58
std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition MeshEnums.cpp:21
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:27
QList< QVariant > propertyBounds(PropertyType const &property)