GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmCellGroupSet.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_CELL_GROUP_SET_H_
25#define _GEMA_CELL_GROUP_SET_H_
26
27#include "gmCell.h"
28#include "gmCellMesh.h"
29
30#include <QString>
31
32
35{
36public:
38 virtual ~GmCellGroupSet() {}
39
41 virtual int numCells() const = 0;
42
43 // PS: We don't have a numActiveCells() function since that would require some type of
44 // synchronization to update our statistics when a cell active flag is changed.
45 // An option would be making the mesh emit a signal when activeCellUpdated() is called
46 // (GmMesh already inherits QObject). That would require that GmCellGroupSet becomes a
47 // QObjects itself. Maybe not a bad idea after all. Would simplify the codes in
48 // GmFileFilter::fillCellData() and GmFilteredCellSetGaussIndex::init() if we also
49 // implement numCellTypes() and numActiveCellTypes()
50
52 virtual GmCell* cell(int setIndex) const = 0;
53
55 virtual bool ordered() const = 0;
56
58 virtual int numNodes() const = 0;
59
61 virtual int node(int setIndex) const = 0;
62
64 virtual void clear() = 0;
65
69 virtual const QList<int>& cellGroups() const = 0;
70
71 QStringList cellGroupNames() const;
72
74 virtual GmCellMesh* mesh() const = 0;
75
79 virtual size_t usedMemory() const = 0;
80
86 virtual void applyTransform(std::function<int(int)>& t) = 0;
87
88 static bool cellGroupIds(const GmCellMesh* mesh, const QStringList& groupNames, QList<int>& idList, QString& err);
89};
90
93{
94public:
96 GmCellMeshGroupSet(GmCellMesh* mesh) { assert(mesh); _mesh = mesh; }
97
98 // See comments on the base class
99 virtual int numCells() const { return _mesh->numCells(); }
100
101 // See comments on the base class
102 virtual GmCell* cell(int setIndex) const { return _mesh->cell(setIndex); }
103
104 // See comments on the base class
105 virtual bool ordered() const { return true; }
106
107 // See comments on the base class
108 virtual int numNodes() const { return _mesh->numNodes(); }
109
110 // See comments on the base class
111 virtual int node(int setIndex) const { return setIndex; }
112
113 // See comments on the base class
114 virtual void clear() {}
115
116 // See comments on the base class
117 virtual const QList<int>& cellGroups() const { static QList<int> emptyGroupList; return emptyGroupList; }
118
119 // See comments on the base class
120 virtual GmCellMesh* mesh() const { return _mesh; }
121
122 // See comments on the base class
123 virtual size_t usedMemory() const { return 0; }
124
126 virtual void applyTransform(std::function<int(int)>& t) { Q_UNUSED(t); }
127
128private:
129 Q_DISABLE_COPY(GmCellMeshGroupSet)
130
131 GmCellMesh* _mesh;
132};
133
134
142{
143protected:
146
147public:
148 virtual ~GmBaseCellGroupSet();
149
150 // See comments on the base class
151 virtual int numNodes() const { return nodeData()->first; }
152
153 // See comments on the base class
154 virtual int node(int setIndex) const
155 {
156 NodeData* d = nodeData();
157
158 assert(setIndex >= 0 && setIndex < d->first);
159 return d->second[setIndex];
160 }
161
162 virtual void clear();
163
164 // See comments on the base class
165 virtual const QList<int>& cellGroups() const { return _groupList; }
166
167 // See comments on the base class
168 virtual GmCellMesh* mesh() const { return _mesh; }
169
170 virtual size_t usedMemory() const;
171
172protected:
173 GmBaseCellGroupSet(GmCellMesh* mesh, const QList<int>& groups);
175
176 NodeData* buildNodeList() const;
177 NodeData* nodeData() const;
178
181
188
191
192private:
193 Q_DISABLE_COPY(GmBaseCellGroupSet)
194};
195
202{
203public:
205 GmCellDisjointGroupSet(GmCellMesh* mesh, const QList<int>& groups);
206
207 virtual int numCells() const;
208
209 virtual GmCell* cell(int setIndex) const;
210
211 // See comments on the base class
212 virtual bool ordered() const { return false; }
213
214 virtual void clear();
215
217 virtual void applyTransform(std::function<int(int)>& t) { Q_UNUSED(t); }
218
219private:
221};
222
228{
229public:
231 GmCellGenericGroupSet(GmCellMesh* mesh, const QList<int>& groups);
232
234 GmCellGenericGroupSet(GmCellMesh* mesh, const QVector<int>& cellIds);
235
236 virtual ~GmCellGenericGroupSet();
237
238 // See comments on the base class
239 virtual int numCells() const { return _ncells; }
240
241 // See comments on the base class
242 virtual GmCell* cell(int setIndex) const { assert(setIndex >= 0 && setIndex < _ncells); return _mesh->cell(_cells[setIndex]); }
243
244 // See comments on the base class
245 virtual bool ordered() const { return true; }
246
247 virtual void clear();
248
249 // See comments on the base class
250 virtual size_t usedMemory() const { return GmBaseCellGroupSet::usedMemory() + _ncells * sizeof(int); }
251
252 virtual void applyTransform(std::function<int(int)>& t);
253
254private:
255 // We can't store cell pointers since they can change when cells are added to the mesh
256
258 int* _cells;
259
260 friend GmCellGroupSet;
261};
262
265{
266public:
268 GmCellSequentialGroupSet(GmCellMesh* mesh, int first, int last)
269 : GmBaseCellGroupSet(mesh), _first(first), _last(last)
270 {
271 assert(first <= last && first >= 0 && last < mesh->numCells());
272 }
273
274 // See comments on the base class
275 virtual int numCells() const { return _last - _first + 1; }
276
277 // See comments on the base class
278 virtual GmCell* cell(int setIndex) const { return _mesh->cell(_first + setIndex); }
279
280 // See comments on the base class
281 virtual bool ordered() const { return true; }
282
283 // See comments on the base class
284 virtual void clear() { GmBaseCellGroupSet::clear(); _first = -1; _last = -1; }
285
287 virtual void applyTransform(std::function<int(int)>& t) { Q_UNUSED(t); }
288
289private:
290 int _first;
291 int _last;
292};
293
294
296#define GmForeachActiveGroupCell(variable, gs) GmForeachCellHelper(variable, gs, GmCellGroupSet, GmCell, true)
297
299#define GmForeachGroupCell(variable, gs, activeOnly) GmForeachCellHelper(variable, gs, GmCellGroupSet, GmCell, activeOnly)
300
302#define GmForeachActiveGroupElement(variable, gs) GmForeachCellHelper(variable, gs, GmCellGroupSet, GmElement, true)
303
305#define GmForeachGroupElement(variable, gs, activeOnly) GmForeachCellHelper(variable, gs, GmCellGroupSet, GmElement, activeOnly)
306
307// IMPORTANT: There is no point in having additional macros that are equivalent to GmForeachOrderedCell() / Element().
308// Those macros are used to traverse the mesh in the original model cell order when the list of cells was renumbered
309// and reordered according to the new cell order numbers. For a cell group this is not necessary since the indices stored
310// in the group where mapped to the new numbering, but where NOT REORDERED.
311
312#endif
313
A helper class implementing common code for handling group sets, specially handling group nodes....
Definition gmCellGroupSet.h:142
virtual GmCellMesh * mesh() const
Returns the mesh owning the cell groups.
Definition gmCellGroupSet.h:168
virtual void clear()
Clear the group set in response to a mesh clear() operation. It will not clear the list of cellGroups...
Definition gmCellGroupSet.cpp:128
QAtomicPointer< NodeData > _nodeData
Atomic pointer to the node data. Contains the number of nodes shared by the group cells and a vector ...
Definition gmCellGroupSet.h:187
GmCellMesh * _mesh
The associated mesh.
Definition gmCellGroupSet.h:179
virtual int numNodes() const
Returns the number of geometric nodes shared by the group elements.
Definition gmCellGroupSet.h:151
virtual size_t usedMemory() const
Returns the approximate amount of memory used to store node data, if any.
Definition gmCellGroupSet.cpp:217
virtual int node(int setIndex) const
Given an index in the range [0..numNodes()-1], returns the respective mesh node index.
Definition gmCellGroupSet.h:154
QList< int > _groupList
The list of mesh cell groups included in this set.
Definition gmCellGroupSet.h:180
virtual const QList< int > & cellGroups() const
Returns a list with the cell groups belonging to this group set. Values are the group index in the me...
Definition gmCellGroupSet.h:165
QPair< int, int * > NodeData
Type for storing node data information: Number of nodes + vector pointer.
Definition gmCellGroupSet.h:145
QMutex _nodeDataMutex
Mutex protecting the creation of _nodeData.
Definition gmCellGroupSet.h:190
Cell group set consisting of a set of disjoint mesh cell groups.
Definition gmCellGroupSet.h:202
QMap< int, int > _groupMap
A map associating the first cell index in a group with the group number.
Definition gmCellGroupSet.h:220
virtual void applyTransform(std::function< int(int)> &t)
See comments on the base class. Does nothing. No stored cell ids.
Definition gmCellGroupSet.h:217
virtual bool ordered() const
Returns true if the the set returned by calls to cell(0) through cell(numCells()-1) is ordered by cel...
Definition gmCellGroupSet.h:212
Cell group set consisting of a set of mesh cell groups.
Definition gmCellGroupSet.h:228
int _ncells
The number of unique cells in the group.
Definition gmCellGroupSet.h:257
virtual bool ordered() const
Returns true if the the set returned by calls to cell(0) through cell(numCells()-1) is ordered by cel...
Definition gmCellGroupSet.h:245
virtual int numCells() const
Returns the number of unique elements in the cell group set.
Definition gmCellGroupSet.h:239
int * _cells
A vector with the ids of all unique cells in the group with size _ncells.
Definition gmCellGroupSet.h:258
virtual GmCell * cell(int setIndex) const
Given an index in the range [0..numCells()-1], returns the respective cell.
Definition gmCellGroupSet.h:242
virtual size_t usedMemory() const
Returns the approximate amount of memory used to store node data, if any.
Definition gmCellGroupSet.h:250
Interface for helping managing mesh cell groups and returning the elements in their union.
Definition gmCellGroupSet.h:35
virtual const QList< int > & cellGroups() const =0
Returns a list with the cell groups belonging to this group set. Values are the group index in the me...
virtual int numCells() const =0
Returns the number of unique elements in the cell group set.
virtual GmCell * cell(int setIndex) const =0
Given an index in the range [0..numCells()-1], returns the respective cell.
virtual void clear()=0
Clear the group set in response to a mesh clear() operation. It will not clear the list of cellGroups...
virtual GmCellMesh * mesh() const =0
Returns the mesh owning the cell groups.
virtual int node(int setIndex) const =0
Given an index in the range [0..numNodes()-1], returns the respective mesh node index.
virtual size_t usedMemory() const =0
Returns the approximate memory used internally by the group set object for storing its data....
virtual void applyTransform(std::function< int(int)> &t)=0
This is a very specialized function. Use only if you know what you are doing. For sets storing intern...
virtual bool ordered() const =0
Returns true if the the set returned by calls to cell(0) through cell(numCells()-1) is ordered by cel...
virtual int numNodes() const =0
Returns the number of geometric nodes shared by the group elements.
virtual ~GmCellGroupSet()
Virtual destructor.
Definition gmCellGroupSet.h:38
Base interface for mesh cells.
Definition gmCell.h:88
Cell group set consisting of all the mesh cells.
Definition gmCellGroupSet.h:93
virtual size_t usedMemory() const
Returns the approximate memory used internally by the group set object for storing its data....
Definition gmCellGroupSet.h:123
virtual bool ordered() const
Returns true if the the set returned by calls to cell(0) through cell(numCells()-1) is ordered by cel...
Definition gmCellGroupSet.h:105
GmCellMeshGroupSet(GmCellMesh *mesh)
Constructor.
Definition gmCellGroupSet.h:96
virtual int node(int setIndex) const
Given an index in the range [0..numNodes()-1], returns the respective mesh node index.
Definition gmCellGroupSet.h:111
virtual GmCell * cell(int setIndex) const
Given an index in the range [0..numCells()-1], returns the respective cell.
Definition gmCellGroupSet.h:102
virtual int numNodes() const
Returns the number of geometric nodes shared by the group elements.
Definition gmCellGroupSet.h:108
virtual int numCells() const
Returns the number of unique elements in the cell group set.
Definition gmCellGroupSet.h:99
virtual GmCellMesh * mesh() const
Returns the mesh owning the cell groups.
Definition gmCellGroupSet.h:120
virtual void clear()
Clear the group set in response to a mesh clear() operation. It will not clear the list of cellGroups...
Definition gmCellGroupSet.h:114
virtual void applyTransform(std::function< int(int)> &t)
See comments on the base class. Does nothing. No stored cell ids.
Definition gmCellGroupSet.h:126
virtual const QList< int > & cellGroups() const
Returns a list with the cell groups belonging to this group set. Values are the group index in the me...
Definition gmCellGroupSet.h:117
Base interface class for CellMesh type plugins.
Definition gmCellMesh.h:40
Cell group set consisting of a sequential set of mesh cells with no cell group association.
Definition gmCellGroupSet.h:265
virtual void clear()
Clear the group set in response to a mesh clear() operation. It will not clear the list of cellGroups...
Definition gmCellGroupSet.h:284
virtual int numCells() const
Returns the number of unique elements in the cell group set.
Definition gmCellGroupSet.h:275
int _last
The index in _mesh of the last set cell.
Definition gmCellGroupSet.h:291
GmCellSequentialGroupSet(GmCellMesh *mesh, int first, int last)
Constructor.
Definition gmCellGroupSet.h:268
virtual void applyTransform(std::function< int(int)> &t)
See comments on the base class. Does nothing. No stored cell ids.
Definition gmCellGroupSet.h:287
virtual GmCell * cell(int setIndex) const
Given an index in the range [0..numCells()-1], returns the respective cell.
Definition gmCellGroupSet.h:278
virtual bool ordered() const
Returns true if the the set returned by calls to cell(0) through cell(numCells()-1) is ordered by cel...
Definition gmCellGroupSet.h:281
int _first
The index in _mesh of the first set cell.
Definition gmCellGroupSet.h:290
Declaration of the GmCell class.
Declaration of the GmCellMesh interface class.
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35