GemaCoreLib
The GeMA Core library
gmResultTrackedData.h
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_RESULT_TRACKED_DATA_H_
25 #define _GEMA_RESULT_TRACKED_DATA_H_
26 
27 #include "gmCoreConfig.h"
28 #include "gmVector.h"
29 
30 #include <QString>
31 #include <QVector>
32 
38 {
40  GmResultTrackedData(double val) { _numValue.append(val); }
41  GmResultTrackedData(double val1, double val2) { _numValue.append(val1); _numValue.append(val2);}
42  GmResultTrackedData(double val1, double val2, double val3) { _numValue.append(val1); _numValue.append(val2); _numValue.append(val3); }
43  GmResultTrackedData(QString val) { _strValue = val; }
44  GmResultTrackedData(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 {
67  enum IndexType
68  {
72  };
73 
76  {
83  // ----------------------------
84  // NO adding bellow this line
85  // When adding types, please check that GM_RESULTTRACK_TYPE_BITS is still enough
86  // ----------------------------
87  NUM_DATA_TYPES
88  };
89 
90  static_assert((1 << GM_RESULTTRACK_TYPE_BITS) >= NUM_DATA_TYPES, "Invalid size for GM_RESULTTRACK_TYPE_BITS");
91 
94 
96  GmResultTrackedIndexData(IndexType type, int coordDim)
97  {
98  _indexType = type;
99  _coordDim = coordDim;
100  _firstIpLine = _firstCoordLine = -1;
101  }
102 
104  void addLine(IndexDataType type, int index)
105  {
106  assert(type == NODE_DATA || type == GHOST_DATA || type == CELL_CENTROID_DATA);
107  assert(index >= 0); // Ghost nodes should have their high bit cleared
108  assert(_firstIpLine == -1 && _firstCoordLine == -1);
109 
110  _index.append(encode(type, index));
111  }
112 
114  void addLine(IndexDataType type, int index, int ip)
115  {
116  assert(type == CELL_IP_DATA);
117  assert(_firstCoordLine == -1);
118 
119  if(_firstIpLine == -1)
120  _firstIpLine = _index.size();
121  _index.append(encode(type, index));
122  _ip.append(ip);
123  }
124 
126  void addLine(IndexDataType type, int index, const GmVector& coord)
127  {
128  assert(type == CELL_POINT_DATA || type == POINT_DATA);
129  assert(coord.size() == _coordDim);
130 
131  if(_firstCoordLine == -1)
132  _firstCoordLine = _index.size();
133  _index.append(encode(type, index));
134  for(int i = 0; i < _coordDim; i++)
135  _coordinates.append(coord[i]);
136  }
137 
139  int coordDim() const { return _coordDim; }
140 
142  int numLines() const { return _index.size(); }
143 
145  IndexDataType lineType(int line) const { assert(line >= 0 && line < numLines()); return decodeType(_index[line]); }
146 
148  int lineIndex(int line) const { assert(line >= 0 && line < numLines()); return decodeIndex(_index[line]); }
149 
151  int lineIp(int line) const
152  {
153  assert(_firstIpLine >= 0);
154  line -= _firstIpLine;
155  assert(line >= 0 && line < _ip.size());
156  return _ip[line];
157  }
158 
160  const double* lineCoord(int line) const
161  {
162  assert(_firstCoordLine >= 0);
163  line -= _firstCoordLine;
164  assert(line >= 0 && line*_coordDim < _coordinates.size());
165  return &_coordinates[line*_coordDim];
166  }
167 
169  QString lineStr(int line) const
170  {
171  IndexDataType t = lineType(line);
172  int index = lineIndex(line) + 1; // +1 to 1 based. Ghost nodes are already with the ghost bit cleared
173  if(t == NODE_DATA)
174  return QString("Node %1").arg(index);
175  else if(t == GHOST_DATA)
176  return QString("Ghost node %1").arg(index);
177  else if(t == CELL_IP_DATA)
178  return QString("Cell %1 @ ip %2").arg(index).arg(lineIp(line)+1);
179  else if(t == CELL_CENTROID_DATA)
180  return QString("Cell %1 @ centroid").arg(index);
181  else if(t == CELL_POINT_DATA)
182  return QString("Cell %1 @ %2").arg(index).arg(GmVectorUtils::toString(GmCRVector(lineCoord(line), _coordDim)));
183  else if(t == POINT_DATA)
184  return QString("@ %1").arg(GmVectorUtils::toString(GmCRVector(lineCoord(line), _coordDim)));
185  assert(0);
186  return "";
187  }
188 
190  int _coordDim;
196 
197 private:
199  int encode(IndexDataType type, int index) const
200  {
201  assert((index & GM_RESULTTRACK_TYPE_MASK) == index); // Check that index fits in the allowed bits
202  return ((int)type << (32 - GM_RESULTTRACK_TYPE_BITS)) | index;
203  }
204 
206  IndexDataType decodeType(int v) const { return (IndexDataType)((unsigned)v >> (32 - GM_RESULTTRACK_TYPE_BITS)); }
207 
209  int decodeIndex(int v) const { return v & GM_RESULTTRACK_TYPE_MASK; }
210 };
211 
212 
213 
214 #endif
215 
Data is a ghost node index (without the high bit set)
Definition: gmResultTrackedData.h:78
Data is a cell index.
Definition: gmResultTrackedData.h:79
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: gmResultTrackedData.h:193
IndexDataType lineType(int line) const
Returns the type of the given index line.
Definition: gmResultTrackedData.h:145
GmResultTrackedIndexData()
Default constructor (needed by QVector)
Definition: gmResultTrackedData.h:93
QVector< int > _index
A vector with entries for each result set line, with its type in the 3 most significant bits + the no...
Definition: gmResultTrackedData.h:191
QString lineStr(int line) const
Returns a string representation of the line data (with 1 based indices)
Definition: gmResultTrackedData.h:169
int numLines() const
Returns the number of lines in the index.
Definition: gmResultTrackedData.h:142
QVector< double > _numValue
A vector with numeric data. Remember that QVector is implicitly shared.
Definition: gmResultTrackedData.h:47
void addLine(IndexDataType type, int index, int ip)
Adds a data line for types requiring a cell index + ip index.
Definition: gmResultTrackedData.h:114
int coordDim() const
Returns the coordinate dimension.
Definition: gmResultTrackedData.h:139
Declaration of usefull configuration definitions for the Core library.
Data is a cell index + an ip index.
Definition: gmResultTrackedData.h:80
Data is a node index.
Definition: gmResultTrackedData.h:77
const double * lineCoord(int line) const
Returns the coordinates of the given index line.
Definition: gmResultTrackedData.h:160
The index data for a result rule, storing "evaluation point" data for node, cell or gauss based indic...
Definition: gmResultTrackedData.h:64
int _firstCoordLine
The line index of the first line of type CELL_POINT_DATA or POINT_DATA (-1 if no such line exists)
Definition: gmResultTrackedData.h:195
int _firstIpLine
The line index of the first line of type CELL_IP_DATA (-1 if no such line exists)
Definition: gmResultTrackedData.h:194
QVector< short > _ip
A vector with size equal to the number of lines of type CELL_IP_DATA.
Definition: gmResultTrackedData.h:192
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: gmResultTrackedData.h:126
IndexDataType
Defines the type of an index line.
Definition: gmResultTrackedData.h:75
A tracked data value. Can be either a double vector or a string. Thanks to the implicitly shared natu...
Definition: gmResultTrackedData.h:37
IndexType
Defines over which kind of data this index refers to.
Definition: gmResultTrackedData.h:67
Gauss data (gauss attributes)
Definition: gmResultTrackedData.h:71
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
void addLine(IndexDataType type, int index)
Adds a data line for types requiring only a node or cell index.
Definition: gmResultTrackedData.h:104
int _coordDim
The dimension coordinate (defining the size of a coordinate data)
Definition: gmResultTrackedData.h:190
Node data (state vars / node attributes)
Definition: gmResultTrackedData.h:69
IndexDataType decodeType(int v) const
Decodes the type info from a combined type+index value.
Definition: gmResultTrackedData.h:206
Declaration of the GmVector class.
int lineIp(int line) const
Returns the ip index of the given index line.
Definition: gmResultTrackedData.h:151
#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
An auxiliary vector WRAPPER that binds the vector to a CONST memory area with data already initialize...
Definition: gmVector.h:69
IndexType _indexType
The index type;.
Definition: gmResultTrackedData.h:189
Data is just a point coordinate.
Definition: gmResultTrackedData.h:82
QString _strValue
A string value. Filled only if _numValue.isEmpty()
Definition: gmResultTrackedData.h:46
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: gmResultTrackedData.h:199
GmResultTrackedIndexData(IndexType type, int coordDim)
Constructor. Line data should be filled by calls to addData.
Definition: gmResultTrackedData.h:96
int lineIndex(int line) const
Returns the node/cell index of the given index line.
Definition: gmResultTrackedData.h:148
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition: gmVector.h:34
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
int decodeIndex(int v) const
Decodes the index info from a combined type+index value.
Definition: gmResultTrackedData.h:209
Data is a cell index + a point coordinate.
Definition: gmResultTrackedData.h:81
Cell data (cell attributes / properties)
Definition: gmResultTrackedData.h:70