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 30 of file ElementTreeModel.h.

#include <ElementTreeModel.h>

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

Public Slots

void clearView ()
 Clears the tree. More...
 
void setElement (vtkUnstructuredGridAlgorithm const *const grid, const unsigned elem_index)
 Displays information of the element with the given index from the given grid. More...
 
void setMesh (MeshLib::Mesh const &mesh)
 Displays information of the given mesh. More...
 
- 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 44 of file ElementTreeModel.cpp.

44  : TreeModel(parent)
45 {
46  QList<QVariant> rootData;
47  delete _rootItem;
48  rootData << "Name"
49  << "Type"
50  << ""
51  << "";
52  _rootItem = new TreeItem(rootData, nullptr);
53 }
Objects nodes for the TreeModel.
Definition: TreeItem.h:28
QModelIndex parent(const QModelIndex &index) const override
Definition: TreeModel.cpp:81
TreeModel(QObject *parent=nullptr)
Definition: TreeModel.cpp:26
TreeItem * _rootItem
Definition: TreeModel.h:58

References TreeModel::_rootItem.

◆ ~ElementTreeModel()

ElementTreeModel::~ElementTreeModel ( )
overridedefault

Member Function Documentation

◆ clearView

void ElementTreeModel::clearView ( )
slot

Clears the tree.

Definition at line 128 of file ElementTreeModel.cpp.

129 {
130  beginResetModel();
132  endResetModel();
133 }
virtual int childCount() const
Definition: TreeItem.cpp:65
bool removeChildren(int position, int count)
Definition: TreeItem.cpp:124

References TreeModel::_rootItem, TreeItem::childCount(), and TreeItem::removeChildren().

Referenced by setElement(), and setMesh().

◆ getSource()

vtkUnstructuredGridAlgorithm const* ElementTreeModel::getSource ( ) const
inline

Definition at line 38 of file ElementTreeModel.h.

38 { 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 57 of file ElementTreeModel.cpp.

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(
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 }
void clearView()
Clears the tree.
std::size_t getID() const
Definition: Point3dWithID.h:62
virtual MeshElemType getGeomType() const =0
virtual const Node * getNode(unsigned idx) 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
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition: Mesh.h:77
void appendChild(TreeItem *item)
Definition: TreeItem.cpp:42
std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition: MeshEnums.cpp:21
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition: Mesh.cpp:258

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

◆ setMesh

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

Displays information of the given mesh.

Definition at line 135 of file ElementTreeModel.cpp.

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 
186  auto const& min = aabb.getMinPoint();
187  auto const& max = aabb.getMaxPoint();
188 
189  QList<QVariant> min_aabb;
190  min_aabb << "Min:" << QString::number(min[0], 'f')
191  << QString::number(min[1], 'f') << QString::number(min[2], 'f');
192  auto* min_item = new TreeItem(min_aabb, aabb_item);
193  aabb_item->appendChild(min_item);
194 
195  QList<QVariant> max_aabb;
196  max_aabb << "Max:" << QString::number(max[0], 'f')
197  << QString::number(max[1], 'f') << QString::number(max[2], 'f');
198  auto* max_item = new TreeItem(max_aabb, aabb_item);
199  aabb_item->appendChild(max_item);
200 
201  QList<QVariant> edges;
202  edges << "Edge Length: "
203  << "[" + QString::number(mesh.getMinEdgeLength(), 'f') + ","
204  << QString::number(mesh.getMaxEdgeLength(), 'f') + "]"
205  << "";
206  auto* edge_item = new TreeItem(edges, _rootItem);
207  _rootItem->appendChild(edge_item);
208 
209  for (auto [name, property] : mesh.getProperties())
210  {
211  QList<QVariant> array_info{QString::fromStdString(name) + ": "};
212 
213  if (auto p = dynamic_cast<MeshLib::PropertyVector<double>*>(property))
214  {
215  array_info.append(propertyBounds(*p));
216  }
217  else if (auto p =
218  dynamic_cast<MeshLib::PropertyVector<float>*>(property))
219  {
220  array_info.append(propertyBounds(*p));
221  }
222  else if (auto p = dynamic_cast<MeshLib::PropertyVector<int>*>(property))
223  {
224  array_info.append(propertyBounds(*p));
225  }
226  else if (auto p =
227  dynamic_cast<MeshLib::PropertyVector<unsigned>*>(property))
228  {
229  array_info.append(propertyBounds(*p));
230  }
231  else if (auto p =
232  dynamic_cast<MeshLib::PropertyVector<long>*>(property))
233  {
234  array_info.append(propertyBounds(*p));
235  }
236  else if (auto p = dynamic_cast<MeshLib::PropertyVector<long long>*>(
237  property))
238  {
239  array_info.append(propertyBounds(*p));
240  }
241  else if (auto p = dynamic_cast<MeshLib::PropertyVector<unsigned long>*>(
242  property))
243  {
244  array_info.append(propertyBounds(*p));
245  }
246  else if (auto p =
248  property))
249  {
250  array_info.append(propertyBounds(*p));
251  }
252  else if (auto p = dynamic_cast<MeshLib::PropertyVector<std::size_t>*>(
253  property))
254  {
255  array_info.append(propertyBounds(*p));
256  }
257  else if (auto p =
258  dynamic_cast<MeshLib::PropertyVector<char>*>(property))
259  {
260  array_info.append(propertyBounds(*p));
261  }
262  else
263  { // Unhandled property vector type.
264  array_info << "[ ?"
265  << "? ]"
266  << "";
267  }
268  _rootItem->appendChild(new TreeItem(array_info, _rootItem));
269  }
270 
271  endResetModel();
272 }
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition: AABB.h:49
static std::map< MeshElemType, unsigned > getNumberOfElementTypes(const MeshLib::Mesh &mesh)
static GeoLib::AABB getBoundingBox(const MeshLib::Mesh &mesh)
Returns the bounding box of the mesh.
static const double p
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition: MeshEnums.h:27
QList< QVariant > propertyBounds(PropertyType const &property)

References TreeModel::_rootItem, TreeItem::appendChild(), clearView(), MeshLib::MeshInformation::getBoundingBox(), MeshLib::Mesh::getMaxEdgeLength(), GeoLib::AABB::getMaxPoint(), MeshLib::Mesh::getMinEdgeLength(), GeoLib::AABB::getMinPoint(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNumberOfElements(), MeshLib::MeshInformation::getNumberOfElementTypes(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), MeshLib::MeshElemType2String(), MaterialPropertyLib::name, MathLib::p, and anonymous_namespace{ElementTreeModel.cpp}::propertyBounds().

Member Data Documentation

◆ _mesh_source

vtkUnstructuredGridAlgorithm const* ElementTreeModel::_mesh_source {nullptr}
private

Definition at line 51 of file ElementTreeModel.h.

Referenced by getSource(), and setElement().


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