OGS
ElementTreeModel Class Reference

Detailed Description

A model for the display of information concerning element information implemented as a TreeModel.

See also
TreeModel, ElementTreeView, TreeItem

Definition at line 19 of file ElementTreeModel.h.

#include <ElementTreeModel.h>

Inheritance diagram for ElementTreeModel:
[legend]
Collaboration diagram for ElementTreeModel:
[legend]

Public Slots

void clearView ()
 Clears the tree.
void setElement (vtkUnstructuredGridAlgorithm const *const grid, const unsigned elem_index)
 Displays information of the element with the given index from the given grid.
void setMesh (MeshLib::Mesh const &mesh)
 Displays information of the given mesh.
Public Slots inherited from TreeModel
void updateData ()

Public Member Functions

 ElementTreeModel (QObject *parent=nullptr)
 ~ElementTreeModel () override
vtkUnstructuredGridAlgorithm const * getSource () const
Public Member Functions inherited from TreeModel
 TreeModel (QObject *parent=nullptr)
 ~TreeModel () override
QVariant data (const QModelIndex &index, int role) const override
bool setData (const QModelIndex &index, const QVariant &value, int role) override
Qt::ItemFlags flags (const QModelIndex &index) const override
TreeItemgetItem (const QModelIndex &index) const
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
QModelIndex parent (const QModelIndex &index) const override
bool removeRows (int position, int count, const QModelIndex &parent) override
int rowCount (const QModelIndex &parent=QModelIndex()) const override
int columnCount (const QModelIndex &parent=QModelIndex()) const override
TreeItemrootItem () const

Private Attributes

vtkUnstructuredGridAlgorithm const * _mesh_source {nullptr}

Additional Inherited Members

Protected Attributes inherited from TreeModel
TreeItem_rootItem

Constructor & Destructor Documentation

◆ ElementTreeModel()

ElementTreeModel::ElementTreeModel ( QObject * parent = nullptr)
explicit

Constructor.

Definition at line 33 of file ElementTreeModel.cpp.

34{
35 QList<QVariant> rootData;
36 delete _rootItem;
37 rootData << "Name"
38 << "Type"
39 << ""
40 << "";
41 _rootItem = new TreeItem(rootData, nullptr);
42}
QModelIndex parent(const QModelIndex &index) const override
Definition TreeModel.cpp:70
TreeModel(QObject *parent=nullptr)
Definition TreeModel.cpp:15
TreeItem * _rootItem
Definition TreeModel.h:47

References TreeModel::TreeModel(), TreeModel::_rootItem, and TreeModel::parent().

◆ ~ElementTreeModel()

ElementTreeModel::~ElementTreeModel ( )
overridedefault

Member Function Documentation

◆ clearView

void ElementTreeModel::clearView ( )
slot

Clears the tree.

Definition at line 117 of file ElementTreeModel.cpp.

118{
119 beginResetModel();
120 _rootItem->removeChildren(0, _rootItem->childCount());
121 endResetModel();
122}

References TreeModel::_rootItem.

Referenced by setElement(), and setMesh().

◆ getSource()

vtkUnstructuredGridAlgorithm const * ElementTreeModel::getSource ( ) const
inline

Definition at line 27 of file ElementTreeModel.h.

27{ return _mesh_source; };
vtkUnstructuredGridAlgorithm const * _mesh_source

References _mesh_source.

◆ setElement

void ElementTreeModel::setElement ( vtkUnstructuredGridAlgorithm const *const grid,
const unsigned elem_index )
slot

Displays information of the element with the given index from the given grid.

Definition at line 46 of file ElementTreeModel.cpp.

48{
49 beginResetModel();
50
51 _mesh_source = grid;
52 this->clearView();
53
54 auto const* const source =
55 dynamic_cast<MeshLib::VtkMappedMeshSource const* const>(grid);
56
57 if (!source)
58 {
59 return;
60 }
61
62 const MeshLib::Mesh* mesh = source->GetMesh();
63 const MeshLib::Element* elem = mesh->getElement(elem_index);
64
65 QList<QVariant> elemData;
66 elemData << "Element " + QString::number(elem_index) << ""
67 << ""
68 << "";
69 auto* elemItem = new TreeItem(elemData, _rootItem);
70 _rootItem->appendChild(elemItem);
71
72 QList<QVariant> typeData;
73 typeData << "Element Type: "
74 << QString::fromStdString(
76 auto* typeItem = new TreeItem(typeData, elemItem);
77 elemItem->appendChild(typeItem);
78
79 auto const mat_ids = materialIDs(*mesh);
80 QString matIdString = !mat_ids ? QString("not defined")
81 : QString::number((*mat_ids)[elem->getID()]);
82 QList<QVariant> materialData;
83 materialData << "MaterialID: " << matIdString;
84 auto* matItem = new TreeItem(materialData, elemItem);
85 elemItem->appendChild(matItem);
86
87 QList<QVariant> volData;
88 volData << "Area/Volume: "
89 << QString::number(mesh->getElement(elem_index)->getContent());
90 auto* volItem = new TreeItem(volData, elemItem);
91 elemItem->appendChild(volItem);
92
93 QList<QVariant> nodeListData;
94 nodeListData << "Nodes"
95 << ""
96 << ""
97 << "";
98 auto* nodeListItem = new TreeItem(nodeListData, elemItem);
99 elemItem->appendChild(nodeListItem);
100
101 // const std::vector<MeshLib::Node*> nodes_vec = grid->getNodes();
102 std::size_t nElemNodes = elem->getNumberOfBaseNodes();
103 for (std::size_t i = 0; i < nElemNodes; i++)
104 {
105 const MeshLib::Node* node = elem->getNode(i);
106 QList<QVariant> nodeData;
107 nodeData << "Node " + QString::number(node->getID())
108 << QString::number((*node)[0], 'f', 6)
109 << QString::number((*node)[1], 'f', 6)
110 << QString::number((*node)[2], 'f', 6);
111 auto* nodeItem = new TreeItem(nodeData, nodeListItem);
112 nodeListItem->appendChild(nodeItem);
113 }
114 endResetModel();
115}
void clearView()
Clears the tree.
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
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition Mesh.h:85
std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition MeshEnums.cpp:10
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:258

References _mesh_source, TreeModel::_rootItem, clearView(), MeshLib::Element::getContent(), MeshLib::Mesh::getElement(), MeshLib::Element::getGeomType(), MathLib::Point3dWithID::getID(), MeshLib::Element::getID(), MeshLib::Element::getNode(), and MeshLib::Element::getNumberOfBaseNodes().

◆ setMesh

void ElementTreeModel::setMesh ( MeshLib::Mesh const & mesh)
slot

Displays information of the given mesh.

Definition at line 124 of file ElementTreeModel.cpp.

125{
126 beginResetModel();
127
128 this->clearView();
129
130 QList<QVariant> mesh_name;
131 mesh_name << "Name:" << QString::fromStdString(mesh.getName()) << ""
132 << ""
133 << "";
134 auto* name_item = new TreeItem(mesh_name, _rootItem);
135 _rootItem->appendChild(name_item);
136
137 QList<QVariant> nodes_number;
138 nodes_number << "#Nodes: " << QString::number(mesh.getNumberOfNodes()) << ""
139 << "";
140 auto* nodes_item = new TreeItem(nodes_number, _rootItem);
141 _rootItem->appendChild(nodes_item);
142
143 QList<QVariant> elements_number;
144 elements_number << "#Elements: "
145 << QString::number(mesh.getNumberOfElements()) << ""
146 << "";
147 auto* elements_item = new TreeItem(elements_number, _rootItem);
148 _rootItem->appendChild(elements_item);
149
150 auto const& n_element_types =
152 for (auto entry : n_element_types)
153 {
154 QList<QVariant> number_of_element_types;
155 number_of_element_types
156 << QString::fromStdString(
158 static_cast<MeshLib::MeshElemType>(entry.first)) +
159 "s:")
160 << QString::number(entry.second) << ""
161 << "";
162 auto* type_item = new TreeItem(number_of_element_types, elements_item);
163 elements_item->appendChild(type_item);
164 }
165
166 QList<QVariant> bounding_box;
167 bounding_box << "Bounding Box"
168 << ""
169 << ""
170 << "";
171 auto* aabb_item = new TreeItem(bounding_box, _rootItem);
172 _rootItem->appendChild(aabb_item);
173
174 {
175 const GeoLib::AABB aabb(
177 auto const [min, max] = aabb.getMinMaxPoints();
178
179 QList<QVariant> min_aabb;
180 min_aabb << "Min:" << QString::number(min[0], 'f')
181 << QString::number(min[1], 'f')
182 << QString::number(min[2], 'f');
183 auto* min_item = new TreeItem(min_aabb, aabb_item);
184 aabb_item->appendChild(min_item);
185
186 QList<QVariant> max_aabb;
187 max_aabb << "Max:" << QString::number(max[0], 'f')
188 << QString::number(max[1], 'f')
189 << QString::number(max[2], 'f');
190 auto* max_item = new TreeItem(max_aabb, aabb_item);
191 aabb_item->appendChild(max_item);
192 }
193
194 QList<QVariant> edges;
195 {
196 auto const [min, max] = minMaxEdgeLength(mesh.getElements());
197 edges << "Edge Length: "
198 << "[" + QString::number(min, 'f') + ","
199 << QString::number(max, 'f') + "]"
200 << "";
201 }
202 auto* edge_item = new TreeItem(edges, _rootItem);
203 _rootItem->appendChild(edge_item);
204
205 for (auto [name, property] : mesh.getProperties())
206 {
207 QList<QVariant> array_info{QString::fromStdString(std::string(name)) +
208 ": "};
209
210 if (auto p = dynamic_cast<MeshLib::PropertyVector<double>*>(property))
211 {
212 array_info.append(propertyBounds(*p));
213 }
214 else if (auto p =
215 dynamic_cast<MeshLib::PropertyVector<float>*>(property))
216 {
217 array_info.append(propertyBounds(*p));
218 }
219 else if (auto p = dynamic_cast<MeshLib::PropertyVector<int>*>(property))
220 {
221 array_info.append(propertyBounds(*p));
222 }
223 else if (auto p =
224 dynamic_cast<MeshLib::PropertyVector<unsigned>*>(property))
225 {
226 array_info.append(propertyBounds(*p));
227 }
228 else if (auto p =
229 dynamic_cast<MeshLib::PropertyVector<long>*>(property))
230 {
231 array_info.append(propertyBounds(*p));
232 }
233 else if (auto p = dynamic_cast<MeshLib::PropertyVector<long long>*>(
234 property))
235 {
236 array_info.append(propertyBounds(*p));
237 }
238 else if (auto p = dynamic_cast<MeshLib::PropertyVector<unsigned long>*>(
239 property))
240 {
241 array_info.append(propertyBounds(*p));
242 }
243 else if (auto p =
244 dynamic_cast<MeshLib::PropertyVector<unsigned long long>*>(
245 property))
246 {
247 array_info.append(propertyBounds(*p));
248 }
249 else if (auto p = dynamic_cast<MeshLib::PropertyVector<std::size_t>*>(
250 property))
251 {
252 array_info.append(propertyBounds(*p));
253 }
254 else if (auto p =
255 dynamic_cast<MeshLib::PropertyVector<char>*>(property))
256 {
257 array_info.append(propertyBounds(*p));
258 }
259 else
260 { // Unhandled property vector type.
261 array_info << "[ ?"
262 << "? ]"
263 << "";
264 }
265 _rootItem->appendChild(new TreeItem(array_info, _rootItem));
266 }
267
268 endResetModel();
269}
static GeoLib::AABB getBoundingBox(const MeshLib::Mesh &mesh)
Returns the bounding box of the mesh.
static std::map< MeshLib::MeshElemType, unsigned > getNumberOfElementTypes(const MeshLib::Mesh &mesh)
std::pair< double, double > minMaxEdgeLength(std::vector< Element * > const &elements)
Returns the minimum and maximum edge length for given elements.
Definition Mesh.cpp:179
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:37
QList< QVariant > propertyBounds(PropertyType const &property)

References TreeModel::_rootItem, clearView(), MeshToolsLib::MeshInformation::getBoundingBox(), MeshLib::Mesh::getElements(), GeoLib::AABB::getMinMaxPoints(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNumberOfElements(), MeshToolsLib::MeshInformation::getNumberOfElementTypes(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), and MeshLib::MeshElemType2String().

Member Data Documentation

◆ _mesh_source

vtkUnstructuredGridAlgorithm const* ElementTreeModel::_mesh_source {nullptr}
private

Definition at line 40 of file ElementTreeModel.h.

40{nullptr};

Referenced by getSource(), and setElement().


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