GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmResultsTrackedData.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_RESULTS_TRACKED_DATA_H_
25#define _GEMA_RESULTS_TRACKED_DATA_H_
26
27#include "gmCoreConfig.h"
28#include "gmVector.h"
29#include "gmResultsEvalSet.h"
30
31#include <QString>
32#include <QVector>
33
39{
41 GmResultsTrackedData(double val) { _numValue.append(val); }
42 GmResultsTrackedData(const double* val, int n) { _numValue.resize(n); memcpy(_numValue.data(), val, n*sizeof(double)); }
43 GmResultsTrackedData(QString val) { _strValue = val; }
44 GmResultsTrackedData(QVector<double>& val) { _numValue = val; }
45
48};
49
51#define GM_RESULTTRACK_TYPE_BITS 3
52
54#define GM_RESULTTRACK_TYPE_MASK (~0u >> GM_RESULTTRACK_TYPE_BITS)
55
65{
73
76 {
84 // ----------------------------
85 // NO adding below this line
86 // When adding types, please check that GM_RESULTTRACK_TYPE_BITS is still enough
87 // ----------------------------
88 NUM_DATA_TYPES
89 };
90
91 static_assert((1 << GM_RESULTTRACK_TYPE_BITS) >= NUM_DATA_TYPES, "Invalid size for GM_RESULTTRACK_TYPE_BITS");
92
95
98 {
99 _indexType = type;
100 _coordDim = coordDim;
101 _firstIpLine = _firstCoordLine = -1;
102 }
103
105 void addLine(IndexDataType type, int index)
106 {
107 assert(type == NODE_DATA || type == GHOST_DATA || type == CELL_CENTROID_DATA);
108 assert(index >= 0); // Ghost nodes should have their high bit cleared
109 assert(_firstIpLine == -1 && _firstCoordLine == -1);
110
111 _index.append(encode(type, index));
112 }
113
115 void addLine(IndexDataType type, int index, int ip)
116 {
117 assert(type == CELL_IP_DATA || type == CELL_IP_AGGR_DATA);
118 assert(_firstCoordLine == -1);
119
120 if(_firstIpLine == -1)
121 _firstIpLine = _index.size();
122 _index.append(encode(type, index));
123 _ip.append(ip);
124 }
125
127 void addLine(IndexDataType type, int index, const GmVector& coord)
128 {
129 assert(type == CELL_POINT_DATA || type == POINT_DATA);
130 assert(coord.size() == _coordDim);
131
132 if(_firstCoordLine == -1)
133 _firstCoordLine = _index.size();
134 _index.append(encode(type, index));
135 for(int i = 0; i < _coordDim; i++)
136 _coordinates.append(coord[i]);
137 }
138
140 int coordDim() const { return _coordDim; }
141
143 int numLines() const { return _index.size(); }
144
146 IndexDataType lineType(int line) const { assert(line >= 0 && line < numLines()); return decodeType(_index[line]); }
147
149 int lineIndex(int line) const { assert(line >= 0 && line < numLines()); return decodeIndex(_index[line]); }
150
152 int lineIp(int line) const
153 {
154 assert(_firstIpLine >= 0);
155 line -= _firstIpLine;
156 assert(line >= 0 && line < _ip.size());
157 return _ip[line];
158 }
159
161 const double* lineCoord(int line) const
162 {
163 assert(_firstCoordLine >= 0);
164 line -= _firstCoordLine;
165 assert(line >= 0 && line*_coordDim < _coordinates.size());
166 return &_coordinates[line*_coordDim];
167 }
168
170 QString lineStr(int line) const
171 {
172 IndexDataType t = lineType(line);
173 int index = lineIndex(line) + 1; // +1 to 1 based. Ghost nodes are already with the ghost bit cleared
174 if(t == NODE_DATA)
175 return QString("Node %1").arg(index);
176 else if(t == GHOST_DATA)
177 return QString("Ghost node %1").arg(index);
178 else if(t == CELL_IP_DATA)
179 return QString("Cell %1 @ ip %2").arg(index).arg(lineIp(line)+1);
180 else if(t == CELL_IP_AGGR_DATA)
182 else if(t == CELL_CENTROID_DATA)
183 return QString("Cell %1 @ centroid").arg(index);
184 else if(t == CELL_POINT_DATA)
185 return QString("Cell %1 @ %2").arg(index).arg(GmVectorUtils::toString(GmCRVector(lineCoord(line), _coordDim)));
186 else if(t == POINT_DATA)
187 return QString("@ %1").arg(GmVectorUtils::toString(GmCRVector(lineCoord(line), _coordDim)));
188 assert(0);
189 return "";
190 }
191
199
200private:
202 int encode(IndexDataType type, int index) const
203 {
204 assert((index & GM_RESULTTRACK_TYPE_MASK) == index); // Check that index fits in the allowed bits
205 return ((int)type << (32 - GM_RESULTTRACK_TYPE_BITS)) | index;
206 }
207
209 IndexDataType decodeType(int v) const { return (IndexDataType)((unsigned)v >> (32 - GM_RESULTTRACK_TYPE_BITS)); }
210
212 int decodeIndex(int v) const { return v & GM_RESULTTRACK_TYPE_MASK; }
213};
214
215
216
217#endif
218
An auxiliary vector WRAPPER that binds the vector to a CONST memory area with data already initialize...
Definition gmVector.h:72
const char * aggregationRuleStr() const
Returns a string version for the configured aggregation rule.
Definition gmResultsEvalSet.h:133
GmEvalSetAggregationRule
Definition gmResultsEvalSet.h:52
Declaration of useful configuration definitions for the Core library.
#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
Declaration of the GmResultsEvalSet class.
#define GM_RESULTTRACK_TYPE_MASK
Mask used for extracting/setting the type of an index entry in GmResultsTrackedIndexData.
Definition gmResultsTrackedData.h:54
#define GM_RESULTTRACK_TYPE_BITS
The number of bits needed to identify an index entry in GmResultsTrackedIndexData.
Definition gmResultsTrackedData.h:51
Declaration of the GmVector class.
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34
QString toString(const GmVector &v, int fieldWidth, char format, int precision, bool noBraces)
Serializes the vector to a string using the specified precision fields. Coordinates are surrounded by...
Definition gmVectorUtils.cpp:48
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
A tracked data value. Can be either a double vector or a string. Thanks to the implicitly shared natu...
Definition gmResultsTrackedData.h:39
QVector< double > _numValue
A vector with numeric data. Remember that QVector is implicitly shared.
Definition gmResultsTrackedData.h:47
QString _strValue
A string value. Filled only if _numValue.isEmpty()
Definition gmResultsTrackedData.h:46
The index data for a result rule, storing "evaluation point" data for node, cell or gauss based indic...
Definition gmResultsTrackedData.h:65
int lineIndex(int line) const
Returns the node/cell index of the given index line.
Definition gmResultsTrackedData.h:149
int _firstIpLine
The line index of the first line of type CELL_IP_DATA (-1 if no such line exists)
Definition gmResultsTrackedData.h:197
int numLines() const
Returns the number of lines in the index.
Definition gmResultsTrackedData.h:143
IndexDataType lineType(int line) const
Returns the type of the given index line.
Definition gmResultsTrackedData.h:146
IndexType
Defines over which kind of data this index refers to.
Definition gmResultsTrackedData.h:68
@ NODE_INDEX
Node data (state vars / node attributes)
Definition gmResultsTrackedData.h:69
@ CELL_INDEX
Cell data (cell attributes / properties)
Definition gmResultsTrackedData.h:70
@ GAUSS_INDEX
Gauss data (gauss attributes)
Definition gmResultsTrackedData.h:71
void addLine(IndexDataType type, int index)
Adds a data line for types requiring only a node or cell index.
Definition gmResultsTrackedData.h:105
void addLine(IndexDataType type, int index, const GmVector &coord)
Adds a data line for types requiring a coordinate (for point only data, index can be set to 0)
Definition gmResultsTrackedData.h:127
GmResultsTrackedIndexData()
Default constructor (needed by QVector)
Definition gmResultsTrackedData.h:94
const double * lineCoord(int line) const
Returns the coordinates of the given index line.
Definition gmResultsTrackedData.h:161
int _firstCoordLine
The line index of the first line of type CELL_POINT_DATA or POINT_DATA (-1 if no such line exists)
Definition gmResultsTrackedData.h:198
int coordDim() const
Returns the coordinate dimension.
Definition gmResultsTrackedData.h:140
IndexDataType decodeType(int v) const
Decodes the type info from a combined type+index value.
Definition gmResultsTrackedData.h:209
GmResultsTrackedIndexData(IndexType type, int coordDim)
Constructor. Line data should be filled by calls to addData.
Definition gmResultsTrackedData.h:97
IndexType _indexType
The index type;.
Definition gmResultsTrackedData.h:192
void addLine(IndexDataType type, int index, int ip)
Adds a data line for types requiring a cell index + ip index.
Definition gmResultsTrackedData.h:115
QVector< double > _coordinates
A vector with size equal to the number of lines of type CELL_POINT_DATA or POINT_DATA multiplied by t...
Definition gmResultsTrackedData.h:196
QVector< short > _ip
A vector with size equal to the number of lines of type CELL_IP_DATA.
Definition gmResultsTrackedData.h:195
int decodeIndex(int v) const
Decodes the index info from a combined type+index value.
Definition gmResultsTrackedData.h:212
IndexDataType
Defines the type of an index line.
Definition gmResultsTrackedData.h:76
@ CELL_IP_DATA
Data is a cell index + an ip index.
Definition gmResultsTrackedData.h:80
@ POINT_DATA
Data is just a point coordinate.
Definition gmResultsTrackedData.h:83
@ GHOST_DATA
Data is a ghost node index (without the high bit set)
Definition gmResultsTrackedData.h:78
@ CELL_POINT_DATA
Data is a cell index + a point coordinate.
Definition gmResultsTrackedData.h:82
@ NODE_DATA
Data is a node index.
Definition gmResultsTrackedData.h:77
@ CELL_CENTROID_DATA
Data is a cell index.
Definition gmResultsTrackedData.h:79
@ CELL_IP_AGGR_DATA
Data is a cell index + the aggregation rule (stred as an ip)
Definition gmResultsTrackedData.h:81
int lineIp(int line) const
Returns the ip index of the given index line.
Definition gmResultsTrackedData.h:152
int encode(IndexDataType type, int index) const
Encodes the type info in the high bits of an integre with the index on the lower ones.
Definition gmResultsTrackedData.h:202
QVector< int > _index
A vector with entries for each result set line, with its type in the 3 most significant bits + the no...
Definition gmResultsTrackedData.h:194
int _coordDim
The dimension coordinate (defining the size of a coordinate data)
Definition gmResultsTrackedData.h:193
QString lineStr(int line) const
Returns a string representation of the line data (with 1 based indices - stored data has already been...
Definition gmResultsTrackedData.h:170