GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmAcResultsDataSrc.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_AC_RESULTS_DATASRC_H_
25#define _GEMA_AC_RESULTS_DATASRC_H_
26
28
29#include "gmInterpolator.h"
30#include "gmValueAccessor.h"
31#include "gmCellAccessor.h"
32#include "gmGaussAccessor.h"
33
34#include <luaFunction.h>
35#include <unitConverter.h>
36
37
42{
43public:
44
47 : _trackId(-1), _dim(-1), _history(0), _interpType(GM_DEFAULT_INTERPOLATOR),
48 _nResLin(0), _nResCol(0), _interp(NULL), _subset(GmInterpolatorSubset::GM_SUBSET_ALL), _acceptDiscontinuitySet(false) {}
49
52
53 // Comments on the base class
54 virtual int monitorTrackId() const { return _trackId; }
55
56 // Comments on the base class
57 virtual void setMonitorTrackId(int id) { _trackId = id; }
58
59 // Returns the accessor id
60 virtual QString id() const = 0;
61
62 // Comments on the base class
63 virtual QString alias() const { return _alias; }
64
65 // Comments on the base class
66 virtual QString formatStr() const { return _formatStr; }
67
69 virtual bool isScalar() const = 0;
70
72 virtual int dimSize() const = 0;
73
75 int history() const { return _history; }
76
78 int dimFilter() const { return _dim; }
79
81 GmInterpolator* interp() const { return _interp; }
82
84 bool hasTransformationFunction() const { return _tFunc.isValid(); }
85
86 GmInterpolatorSubset subsetType() const { return _subset; }
87
89 void setBasicData(int dim, const QString& alias, int history,
90 GmInterpolatorType interpType, const QVariant& interpParam, GmInterpolatorSubset subset)
91 {
92 _dim = dim;
93 _alias = alias;
94 _history = history;
95 _interpType = interpType;
96 _interpParam = interpParam;
97 _subset = subset;
98 }
99
101 void setFormatStr(const QString& formatStr) { _formatStr = formatStr; }
102
104 void setTransformationFunction(LuaFunction& tfunc, int nresLin, int nresCol)
105 {
106 _tFunc = tfunc;
107 _tFunc.makeRef(); // Ensure that tFunc stores a function reference and not a stack index
108 _nResLin = nresLin;
109 _nResCol = nresCol;
110 }
111
114 {
115 delete _interp; _acceptDiscontinuitySet = false;
116
117 _interp = interp;
118 if (_interp) {
119 int itype = _interp->interpolatorObject()->type();
120 //DiscSet aware interpolation is not valid for shape interp
121 _acceptDiscontinuitySet = (itype != GM_SHAPE_INTERPOLATOR && itype != GM_LSHAPE_INTERPOLATOR);
122 }
123 }
124
125 bool interpAcceptDiscSet() const { return _acceptDiscontinuitySet; }
126
127protected:
128 friend class GmResultsDataSet; // Give full acces to the results data set class
129
130 Q_DISABLE_COPY(GmAcResultsDataSrcBase);
131
140 {
141 _interpType = GM_DEFAULT_INTERPOLATOR;
142 _interp = NULL;
143 _interpParam = QVariant();
144 _acceptDiscontinuitySet = false;
145
146 _trackId = ptr->_trackId;
147 _alias = ptr->_alias;
148 _dim = ptr->_dim;
149 _formatStr = ptr->_formatStr;
150 _history = ptr->_history;
151 _tFunc = ptr->_tFunc;
152 _nResLin = ptr->_nResLin;
153 _nResCol = ptr->_nResCol;
154 _subset = ptr->_subset;
155 }
156
159 int _dim;
167 GmInterpolatorSubset _subset;
168private:
171};
172
174template <class T>
176{
177public:
178 // The stored accessr type
179 typedef T AcType;
180
182 GmAcResultsDataSrc(T* ac) : GmAcResultsDataSrcBase() { assert(ac); _ac = ac; _ownership = true; }
183
185 virtual ~GmAcResultsDataSrc() { if(_ownership) delete _ac; }
186
187 // Comments on the base class
188 virtual QString id() const { return _ac->info()->id(); }
189
190 // Comments on the base class
191 virtual QString description() const { return _ac->info()->description(); }
192
193 // Comments on the base class
194 virtual Unit unit() const { return _ac->unit(); }
195
196 // Comments on the base class
197 virtual bool isScalar() const { return _dim >= 0 || _ac->isScalar(); }
198
199 // Comments on the base class
200 virtual int dimSize() const { return _dim == -1 ? _ac->valueSize() : 1; }
201
202 // Comments on the base class
203 virtual int size() const { return _tFunc.isValid() ? _nResLin * _nResCol : dimSize(); }
204
205 // Comments on the base class
206 virtual int nlin() const { return _tFunc.isValid() ? _nResLin : (_dim == -1 ? _ac->info()->nlin() : 1); }
207
208 // Comments on the base class
209 virtual int ncol() const { return _tFunc.isValid() ? _nResCol : (_dim == -1 ? _ac->info()->ncol() : 1); }
210
212 T* ac() const { return _ac; }
213
217 void setAc(T* newAc) { if(_ownership) delete _ac; _ac = newAc; _ownership = true; }
218
219protected:
220
230 template <class Result>
232 {
233 assert(!interp());
234 assert(dynamic_cast<Result*>(this)); // Result should realy be the same type as this!!!
235
236 QVector<Result*> list;
237 list.append(dynamic_cast<Result*>(this));
238
239 if(!isScalar())
240 {
241 for(int i = 1, ndim = _ac->valueSize(); i < ndim; i++)
242 {
243 Result* r = new Result(this);
244 r->_dim = i;
245 r->_alias = r->_alias + QString("_%1").arg(i+1);
246 list.append(r);
247 }
248 _dim = 0;
249 _alias = _alias + QString("_%1").arg(1); // Can't be done before the loop or the copy would already include the dimension suffix
250 }
251 return list;
252 }
253
261 {
262 _ac = ptr->_ac;
263 _ownership = false;
264 }
265
266 T* _ac;
268};
269
292
295{
296public:
299
301 virtual GmResultsDataSrcType type() const { return GM_RR_DS_CELLDATA; }
302
303 // Comments on the base class
304 QVector<GmCellAcResultsDataSrc*> dimensionSplit() { return dimSplit<GmCellAcResultsDataSrc>(); }
305
308
309private:
311
314};
315
338
339#endif
340
A class storing basic information about a result data to be exported (monitored / saved),...
Definition gmAcResultsDataSrc.h:42
int history() const
Returns the state accessed by this data src.
Definition gmAcResultsDataSrc.h:75
virtual QString formatStr() const
How should dataSrc values be formatted?
Definition gmAcResultsDataSrc.h:66
int _history
The state accessed by this data src (0 = current state, 1 = previous, etc..)
Definition gmAcResultsDataSrc.h:161
virtual int monitorTrackId() const
Returns a numeric id for this data src (a value between 0 and the number of monitored data sources in...
Definition gmAcResultsDataSrc.h:54
int dimFilter() const
Returns the dimension filter value (-1 if there is no filter)
Definition gmAcResultsDataSrc.h:78
virtual int dimSize() const =0
Returns the accessor valueSize() adjusted by an optional dimension filter.
GmInterpolator * interp() const
Returns the associated interpolator, if any.
Definition gmAcResultsDataSrc.h:81
void setInterpolator(GmInterpolator *interp)
Sets the configured interpolator for this data source. Takes ownership of the object.
Definition gmAcResultsDataSrc.h:113
GmInterpolator * _interp
The configured interpolator object. Can be NULL. !!Should not be set directly, use setInterpolator() ...
Definition gmAcResultsDataSrc.h:169
bool hasTransformationFunction() const
Returns true if this data src is associated with a transfromation function.
Definition gmAcResultsDataSrc.h:84
virtual ~GmAcResultsDataSrcBase()
Destructor.
Definition gmAcResultsDataSrc.h:51
QString _formatStr
The format string for the data. Usually equal to the accessor format.
Definition gmAcResultsDataSrc.h:160
void setBasicData(int dim, const QString &alias, int history, GmInterpolatorType interpType, const QVariant &interpParam, GmInterpolatorSubset subset)
Sets the values of the given basic object attributes.
Definition gmAcResultsDataSrc.h:89
int _nResCol
The number of columns of the result returned by _tFunc.
Definition gmAcResultsDataSrc.h:166
void setFormatStr(const QString &formatStr)
Sets the format string.
Definition gmAcResultsDataSrc.h:101
GmInterpolatorType _interpType
How do we interpolate data?
Definition gmAcResultsDataSrc.h:162
QVariant _interpParam
Optional interpolation parameters.
Definition gmAcResultsDataSrc.h:163
GmInterpolatorSubset _subset
The subset of data to be considered when interpolating discontinuous elements.
Definition gmAcResultsDataSrc.h:167
virtual bool isScalar() const =0
Returns true if the accessor value is a scalar value or there is a dimensional filter.
LuaFunction _tFunc
An optional transformation function applied over the data (filtered by _dim) before exporting.
Definition gmAcResultsDataSrc.h:164
virtual void setMonitorTrackId(int id)
Updates the data src's monitor track id.
Definition gmAcResultsDataSrc.h:57
void setTransformationFunction(LuaFunction &tfunc, int nresLin, int nresCol)
Sets the transformation function along with its result dimensions.
Definition gmAcResultsDataSrc.h:104
int _dim
A "bound" dimension for returning a scalar when the data is multidimensional (-1 for returning all va...
Definition gmAcResultsDataSrc.h:159
virtual QString alias() const
Returns the data src "exported" id.
Definition gmAcResultsDataSrc.h:63
QString _alias
The name given to the "exported" data. Always filled (might be equal to id())
Definition gmAcResultsDataSrc.h:158
bool _acceptDiscontinuitySet
True if the _interp type accepts discontinuitySet aware interpolation.
Definition gmAcResultsDataSrc.h:170
int _nResLin
The number of lines of the result returned by _tFunc.
Definition gmAcResultsDataSrc.h:165
int _trackId
The numeric id for this data src (a value between 0 and the number of monitored data srcs in the mode...
Definition gmAcResultsDataSrc.h:157
GmAcResultsDataSrcBase()
Default constructor.
Definition gmAcResultsDataSrc.h:46
GmAcResultsDataSrcBase(const GmAcResultsDataSrcBase *ptr)
A kind of "copy" constructor geting a pointer instead of a reference that copies the contents of the ...
Definition gmAcResultsDataSrc.h:139
Aux class adding an accessor to a basic result data source.
Definition gmAcResultsDataSrc.h:176
virtual ~GmAcResultsDataSrc()
Destructor.
Definition gmAcResultsDataSrc.h:185
virtual QString description() const
Returns the data src description, when available.
Definition gmAcResultsDataSrc.h:191
void setAc(T *newAc)
Updates the stored accessor, taking ownership of it. Used by GmFileIO for replacing an accessor by an...
Definition gmAcResultsDataSrc.h:217
T * _ac
The node data accessor.
Definition gmAcResultsDataSrc.h:266
virtual int dimSize() const
Returns the accessor valueSize() adjusted by an optional dimension filter.
Definition gmAcResultsDataSrc.h:200
virtual Unit unit() const
Returns the unit in which the data is expressed.
Definition gmAcResultsDataSrc.h:194
bool _ownership
Are we the owner of _ac? This can be false as a result of the dimSplit() operation.
Definition gmAcResultsDataSrc.h:267
virtual int ncol() const
The number of columns in the returned result, taking into account any applied transformations or dim ...
Definition gmAcResultsDataSrc.h:209
virtual bool isScalar() const
Returns true if the accessor value is a scalar value or there is a dimensional filter.
Definition gmAcResultsDataSrc.h:197
GmAcResultsDataSrc(const GmAcResultsDataSrc< T > *ptr)
A private "copy" constructor geting a pointer instead of a reference that copies the contents of the ...
Definition gmAcResultsDataSrc.h:259
virtual int size() const
Returns the dimension of the data src values, taking into account any applied transformations or dim ...
Definition gmAcResultsDataSrc.h:203
QVector< Result * > dimSplit()
Returns a vector with as many data srcs as dimensions. The first one will be the original data src wi...
Definition gmAcResultsDataSrc.h:231
GmAcResultsDataSrc(T *ac)
Constructor.
Definition gmAcResultsDataSrc.h:182
T * ac() const
Returns the associated accessor.
Definition gmAcResultsDataSrc.h:212
virtual int nlin() const
The number of lines in the returned result, taking into account any applied transformations or dim fi...
Definition gmAcResultsDataSrc.h:206
A GmAcResultsDataSrc class holding a cell value accessor.
Definition gmAcResultsDataSrc.h:295
GmCellAcResultsDataSrc * cloneSameAcNoInterp() const
Duplicates the current data src object, sharing the same accessor. The copy will NOT include any inte...
Definition gmAcResultsDataSrc.h:307
GmCellAcResultsDataSrc(const GmAcResultsDataSrc< GmCellAccessor > *base)
Special "copy" (gets a pointer and not a reference) constructor accessible by dimSplit() to duplicate...
Definition gmAcResultsDataSrc.h:313
virtual GmResultsDataSrcType type() const
See dimSplit() documentation on the base calss.
Definition gmAcResultsDataSrc.h:301
GmCellAcResultsDataSrc(GmCellAccessor *ac)
Constructor.
Definition gmAcResultsDataSrc.h:298
The GmCellAccessor class is a proxy object to a value accesor implementing a more convenient interfac...
Definition gmCellAccessor.h:67
A GmAcResultsDataSrc class holding a Gauss value accessor.
Definition gmAcResultsDataSrc.h:318
GmGaussAcResultsDataSrc(GmGaussAccessor *ac)
Constructor.
Definition gmAcResultsDataSrc.h:321
GmGaussAcResultsDataSrc * cloneSameAcNoInterp() const
Duplicates the current data src object, sharing the same accessor. The copy will NOT include any inte...
Definition gmAcResultsDataSrc.h:330
GmGaussAcResultsDataSrc(const GmAcResultsDataSrc< GmGaussAccessor > *base)
Special "copy" (gets a pointer and not a reference) constructor accessible by dimSplit() to duplicate...
Definition gmAcResultsDataSrc.h:336
QVector< GmGaussAcResultsDataSrc * > dimensionSplit()
See dimSplit() documentation on the base calss.
Definition gmAcResultsDataSrc.h:327
virtual GmResultsDataSrcType type() const
Returns the data src type.
Definition gmAcResultsDataSrc.h:324
The GmGaussAccessor class is a proxy object to a value accessor implementing a more convenient interf...
Definition gmGaussAccessor.h:39
Interpolator class used for managing available interpolator algorithms and providing basic support fu...
Definition gmInterpolator.h:245
A GmAcResultsDataSrc class holding a node value accessor.
Definition gmAcResultsDataSrc.h:272
GmNodeAcResultsDataSrc * cloneSameAcNoInterp() const
Duplicates the current data src object, sharing the same accessor. The copy will NOT include any inte...
Definition gmAcResultsDataSrc.h:284
virtual GmResultsDataSrcType type() const
Returns the data src type.
Definition gmAcResultsDataSrc.h:278
QVector< GmNodeAcResultsDataSrc * > dimensionSplit()
See dimSplit() documentation on the base calss.
Definition gmAcResultsDataSrc.h:281
GmNodeAcResultsDataSrc(GmValueAccessor *ac)
Constructor.
Definition gmAcResultsDataSrc.h:275
GmNodeAcResultsDataSrc(const GmAcResultsDataSrc< GmValueAccessor > *base)
Special "copy" (gets a pointer and not a reference) constructor accessible by dimSplit() to duplicate...
Definition gmAcResultsDataSrc.h:290
A set storing what should be exported (saved / printed / monitored) by the result rule classes.
Definition gmResultsDataSet.h:58
A basic interface with the metadata common to all results data src types. This is the information tha...
Definition gmResultsDataSrcInfo.h:50
virtual QString alias() const =0
Returns the data src "exported" id.
virtual QString formatStr() const =0
How should dataSrc values be formatted?
Interface class for accessing and setting values from an "indexable" collection of values.
Definition gmValueAccessor.h:60
void makeRef()
Implementation of the GmCellAccessor proxy 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
Implementation of the GmGaussAccessor proxy class.
Declaration of the GmInterpolator and GmInterpolatorObject classes.
GmInterpolatorType
Available interpolation methods. Not every method is suitable for every kind of interpolator class....
Definition gmInterpolator.h:64
@ GM_DEFAULT_INTERPOLATOR
Interpolation should be done using the default method for the interpolator object.
Definition gmInterpolator.h:134
@ GM_SHAPE_INTERPOLATOR
Interpolated value is found by using the elements shape function.
Definition gmInterpolator.h:113
@ GM_LSHAPE_INTERPOLATOR
Interpolated value is found by using the elements equivalent linear shape function....
Definition gmInterpolator.h:124
Declaration of the GmResultsDataSrcInfo interface.
GmResultsDataSrcType
The types of data sources stored by a rule.
Definition gmResultsDataSrcInfo.h:33
@ GM_RR_DS_GAUSSDATA
Gauss attributes.
Definition gmResultsDataSrcInfo.h:37
@ GM_RR_DS_NODEDATA
Node attributes + State vars.
Definition gmResultsDataSrcInfo.h:35
@ GM_RR_DS_CELLDATA
Cell attributes + properties.
Definition gmResultsDataSrcInfo.h:36
Declaration of the GmValueAccessor interface and GmValueAccessorBase class.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void append(const T &value)