GemaCoreLib
The GeMA Core library
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 {
36 public:
37  virtual ~GmCellGroupSet() {}
38 
40  virtual int numCells() const = 0;
41 
42  // PS: We don't have a numActiveCells() function since that would require some type of
43  // synchronization to update our statistics when a cell active flag is changed.
44  // An option would be making the mesh emit a signal when activeCellUpdated() is called
45  // (GmMesh already inherits QObject). That would require that GmCellGroupSet becomes a
46  // QObjects itself. Maybe not a bad idea after all. Would simplify the codes in
47  // GmFileFilter::fillCellData() and GmFilteredCellSetGaussIndex::init() if we also
48  // implement numCellTypes() and numActiveCellTypes()
49 
51  virtual GmCell* cell(int setIndex) const = 0;
52 
54  virtual bool ordered() const = 0;
55 
57  virtual int numNodes() const = 0;
58 
60  virtual int node(int setIndex) const = 0;
61 
63  virtual void clear() = 0;
64 
68  virtual const QList<int>& cellGroups() const = 0;
69 
70  QStringList cellGroupNames() const;
71 
73  virtual GmCellMesh* mesh() const = 0;
74 
75  static bool cellGroupIds(const GmCellMesh* mesh, const QStringList& groupNames, QList<int>& idList, QString& err);
76 };
77 
80 {
81 public:
83  GmCellMeshGroupSet(GmCellMesh* mesh) { assert(mesh); _mesh = mesh; }
84 
85  // See comments on the base class
86  virtual int numCells() const { return _mesh->numCells(); }
87 
88  // See comments on the base class
89  virtual GmCell* cell(int setIndex) const { return _mesh->cell(setIndex); }
90 
91  // See comments on the base class
92  virtual bool ordered() const { return true; }
93 
94  // See comments on the base class
95  virtual int numNodes() const { return _mesh->numNodes(); }
96 
97  // See comments on the base class
98  virtual int node(int setIndex) const { return setIndex; }
99 
100  // See comments on the base class
101  virtual void clear() {}
102 
103  // See comments on the base class
104  virtual const QList<int>& cellGroups() const { static QList<int> emptyGroupList; return emptyGroupList; }
105 
106  // See comments on the base class
107  virtual GmCellMesh* mesh() const { return _mesh; }
108 
109 private:
110  Q_DISABLE_COPY(GmCellMeshGroupSet)
111 
112  GmCellMesh* _mesh;
113 };
114 
122 {
123 protected:
126 
127 public:
128  virtual ~GmBaseCellGroupSet();
129 
130  // See comments on the base class
131  virtual int numNodes() const { return nodeData()->first; }
132 
133  // See comments on the base class
134  virtual int node(int setIndex) const
135  {
136  NodeData* d = nodeData();
137 
138  assert(setIndex >= 0 && setIndex < d->first);
139  return d->second[setIndex];
140  }
141 
142  virtual void clear();
143 
144  // See comments on the base class
145  virtual const QList<int>& cellGroups() const { return _groupList; }
146 
147  // See comments on the base class
148  virtual GmCellMesh* mesh() const { return _mesh; }
149 
150 protected:
151  GmBaseCellGroupSet(GmCellMesh* mesh, const QList<int>& groups);
152 
153  NodeData* buildNodeList() const;
154  NodeData* nodeData() const;
155 
158 
165 
168 
169 private:
170  Q_DISABLE_COPY(GmBaseCellGroupSet)
171 };
172 
173 
174 
181 {
182 public:
184  GmCellDisjointGroupSet(GmCellMesh* mesh, const QList<int>& groups);
185 
186  virtual int numCells() const;
187 
188  virtual GmCell* cell(int setIndex) const;
189 
190  // See comments on the base class
191  virtual bool ordered() const { return false; }
192 
193  virtual void clear();
194 
195 private:
197 };
198 
204 {
205 public:
207  GmCellGenericGroupSet(GmCellMesh* mesh, const QList<int>& groups);
208 
209  virtual ~GmCellGenericGroupSet();
210 
211  // See comments on the base class
212  virtual int numCells() const { return _ncells; }
213 
214  // See comments on the base class
215  virtual GmCell* cell(int setIndex) const { assert(setIndex >= 0 && setIndex < _ncells); return _cells[setIndex]; }
216 
217  // See comments on the base class
218  virtual bool ordered() const { return true; }
219 
220  virtual void clear();
221 
222 private:
223  int _ncells;
225 };
226 
228 #define GmForeachActiveGroupCell(variable, gs) GmForeachCellHelper(variable, gs, GmCellGroupSet, GmCell, true)
229 
231 #define GmForeachGroupCell(variable, gs, activeOnly) GmForeachCellHelper(variable, gs, GmCellGroupSet, GmCell, activeOnly)
232 
234 #define GmForeachActiveGroupElement(variable, gs) GmForeachCellHelper(variable, gs, GmCellGroupSet, GmElement, true)
235 
237 #define GmForeachGroupElement(variable, gs, activeOnly) GmForeachCellHelper(variable, gs, GmCellGroupSet, GmElement, activeOnly)
238 
239 
240 #endif
241 
virtual void clear()
Clear the group set in response to a mesh clear() opeartion. It will not clear the list of cellGroups...
Definition: gmCellGroupSet.h:101
virtual GmCellMesh * mesh() const
Returns the mesh owning the cell groups.
Definition: gmCellGroupSet.h:148
Interface for helping managing mesh cell groups and returning the elements in their union.
Definition: gmCellGroupSet.h:34
GmCell ** _cells
A vector with pointers to all unique cells in the group with size _ncells.
Definition: gmCellGroupSet.h:224
virtual int numNodes() const
Returns the number of nodes shared by the group elements.
Definition: gmCellGroupSet.h:131
virtual GmCell * cell(int setIndex) const
Given an index in the range [0..numCells()-1], returns the respective cell.
Definition: gmCellGroupSet.h:89
virtual GmCellMesh * mesh() const
Returns the mesh owning the cell groups.
Definition: gmCellGroupSet.h:107
GmCellMeshGroupSet(GmCellMesh *mesh)
Constructor.
Definition: gmCellGroupSet.h:83
QList< int > _groupList
The list of mesh cell groups included in this set.
Definition: gmCellGroupSet.h:157
Base interface for mesh cells.
Definition: gmCell.h:81
virtual int numNodes() const
Returns the number of nodes shared by the group elements.
Definition: gmCellGroupSet.h:95
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:92
int _ncells
The number of unique cells in the group.
Definition: gmCellGroupSet.h:223
virtual int node(int setIndex) const
Given an index in the range [0..numNodes()-1], returns the respective mesh node index.
Definition: gmCellGroupSet.h:134
virtual GmCell * cell(int setIndex) const =0
Given an index in the range [0..numCells()-1], returns the respective cell.
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:145
virtual void clear()
Clear the group set in response to a mesh clear() opeartion. It will not clear the list of cellGroups...
Definition: gmCellGroupSet.cpp:118
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:218
QPair< int, int * > NodeData
Type for storing node data information: Number of nodes + vector pointer.
Definition: gmCellGroupSet.h:125
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:104
GmCellMesh * _mesh
The associated mesh.
Definition: gmCellGroupSet.h:156
virtual void clear()=0
Clear the group set in response to a mesh clear() opeartion. It will not clear the list of cellGroups...
Base interface class for CellMesh type plugins.
Definition: gmCellMesh.h:39
QMutex _nodeDataMutex
Mutex protecting the creation of _nodeData.
Definition: gmCellGroupSet.h:167
Cell group set consisting of a set of disjoint mesh cell groups.
Definition: gmCellGroupSet.h:180
Declaration of the GmCellMesh interface class.
virtual int node(int setIndex) const
Given an index in the range [0..numNodes()-1], returns the respective mesh node index.
Definition: gmCellGroupSet.h:98
virtual GmCell * cell(int setIndex) const
Given an index in the range [0..numCells()-1], returns the respective cell.
Definition: gmCellGroupSet.h:215
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
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:164
virtual int numCells() const =0
Returns the number of unique elements in the cell group set.
QMap< int, int > _groupMap
A map associating the first cell index in a group with the group number.
Definition: gmCellGroupSet.h:196
virtual GmCellMesh * mesh() const =0
Returns the mesh owning the cell groups.
Cell group set consisting of all the mesh cells.
Definition: gmCellGroupSet.h:79
A helper class implementing common code for handling group sets, specially handling group nodes....
Definition: gmCellGroupSet.h:121
Declaration of the GmCell class.
virtual int numCells() const
Returns the number of unique elements in the cell group set.
Definition: gmCellGroupSet.h:212
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:191
virtual int numCells() const
Returns the number of unique elements in the cell group set.
Definition: gmCellGroupSet.h:86
Cell group set consisting of a set of mesh cell groups.
Definition: gmCellGroupSet.h:203