11#include <vcLogger.hpp>
15using namespace viennacore;
18template <
class T = double,
26 std::vector<ScalarDataType> scalarData;
27 std::vector<std::string> scalarDataLabels;
28 std::vector<VectorDataType> vectorData;
29 std::vector<std::string> vectorDataLabels;
31 template <
class VectorType,
class ReturnType = std::conditional_t<
32 std::is_const<VectorType>::value,
33 const typename VectorType::value_type *,
34 typename VectorType::value_type *>>
35 ReturnType indexPointerOrNull(VectorType &v,
int index)
const {
36 if (index >= 0 && index < v.size())
40 .addWarning(
"PointData: Tried to access out of bounds index! "
41 "Returned nullptr instead.")
46 template <
class DataType>
47 void appendTranslateData(DataType ¤tData,
const DataType &source,
48 const std::vector<unsigned> &indices) {
49 currentData.reserve(currentData.size() + indices.size());
50 for (
unsigned i = 0; i < indices.size(); ++i) {
51 currentData.push_back(source[indices[i]]);
58 std::string label =
"Scalars") {
59 scalarData.push_back(scalars);
60 scalarDataLabels.push_back(label);
65 std::string label =
"Scalars") {
66 scalarData.push_back(std::move(scalars));
67 scalarDataLabels.push_back(label);
72 std::string label =
"Vectors") {
73 vectorData.push_back(vectors);
74 vectorDataLabels.push_back(label);
79 std::string label =
"Vectors") {
80 vectorData.push_back(std::move(vectors));
81 vectorDataLabels.push_back(label);
91 return indexPointerOrNull(scalarData, index);
95 return indexPointerOrNull(scalarData, index);
99 bool noWarning =
false) {
101 return &(scalarData[i]);
104 Logger::getInstance()
105 .addWarning(
"PointData attempted to access scalar data labeled '" +
107 "', which does not exist. Returning nullptr instead.")
113 bool noWarning =
false)
const {
115 return &(scalarData[i]);
118 Logger::getInstance()
119 .addWarning(
"PointData attempted to access scalar data labeled '" +
121 "', which does not exist. Returning nullptr instead.")
127 for (
int i = 0; i < scalarDataLabels.size(); ++i) {
128 if (scalarDataLabels[i] == searchLabel) {
136 return (index >= 0 && index < scalarDataLabels.size())
137 ? scalarDataLabels[index]
142 scalarDataLabels[index] = newLabel;
147 scalarData.erase(scalarData.begin() + index);
148 scalarDataLabels.erase(scalarDataLabels.begin() + index);
152 return indexPointerOrNull(vectorData, index);
156 return indexPointerOrNull(vectorData, index);
160 bool noWarning =
false) {
162 return &(vectorData[i]);
165 Logger::getInstance()
166 .addWarning(
"PointData attempted to access vector data labeled '" +
168 "', which does not exist. Returning nullptr instead.")
174 bool noWarning =
false)
const {
176 return &(vectorData[i]);
179 Logger::getInstance()
180 .addWarning(
"PointData attempted to access vector data labeled '" +
182 "', which does not exist. Returning nullptr instead.")
188 for (
int i = 0; i < vectorDataLabels.size(); ++i) {
189 if (vectorDataLabels[i] == searchLabel) {
197 return (index >= 0 && index < vectorDataLabels.size())
198 ? vectorDataLabels[index]
203 vectorDataLabels[index] = newLabel;
208 vectorData.erase(vectorData.begin() + index);
209 vectorDataLabels.erase(vectorDataLabels.begin() + index);
214 scalarData.insert(scalarData.end(), passedData.scalarData.begin(),
215 passedData.scalarData.end());
216 scalarDataLabels.insert(scalarDataLabels.end(),
217 passedData.scalarDataLabels.begin(),
218 passedData.scalarDataLabels.end());
219 vectorData.insert(vectorData.end(), passedData.vectorData.begin(),
220 passedData.vectorData.end());
221 vectorDataLabels.insert(vectorDataLabels.end(),
222 passedData.vectorDataLabels.begin(),
223 passedData.vectorDataLabels.end());
231 const std::vector<unsigned> &indices) {
235 auto currentData = --scalarData.end();
236 appendTranslateData(*currentData, source.scalarData[j], indices);
242 auto currentData = --vectorData.end();
243 appendTranslateData(*currentData, source.vectorData[j], indices);
251 const std::vector<std::vector<unsigned>> &indicesVector) {
255 auto currentData = --scalarData.end();
256 for (
const auto &i : indicesVector) {
257 appendTranslateData(*currentData, source.scalarData[j], i);
264 auto currentData = --vectorData.end();
265 for (
const auto &i : indicesVector) {
266 appendTranslateData(*currentData, source.vectorData[j], i);
274 scalarDataLabels.clear();
276 vectorDataLabels.clear();
280 bool empty() {
return scalarData.empty() && vectorData.empty(); }
288 stream <<
"lsPointData";
289 uint32_t numberOfScalarData = scalarData.size();
290 uint32_t numberOfVectorData = vectorData.size();
291 stream.write(
reinterpret_cast<const char *
>(&numberOfScalarData),
293 stream.write(
reinterpret_cast<const char *
>(&numberOfVectorData),
298 auto labelIt = scalarDataLabels.begin();
300 for (
auto data : scalarData) {
302 uint32_t sizeOfName = labelIt->length();
303 stream.write(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
305 uint32_t numberOfValues = data.size();
306 stream.write(
reinterpret_cast<const char *
>(&numberOfValues),
309 for (
auto value : data) {
310 stream.write(
reinterpret_cast<const char *
>(&value),
311 sizeof(
typename ScalarDataType::value_type));
319 auto labelIt = vectorDataLabels.begin();
321 for (
auto data : vectorData) {
323 uint32_t sizeOfName = labelIt->length();
324 stream.write(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
326 uint32_t numberOfVectors = data.size();
327 stream.write(
reinterpret_cast<const char *
>(&numberOfVectors),
330 for (
auto vector : data) {
332 for (
auto value : vector) {
334 reinterpret_cast<const char *
>(&value),
335 sizeof(
typename VectorDataType::value_type::value_type));
348 stream.read(identifier, 11);
349 if (std::string(identifier).compare(0, 11,
"lsPointData")) {
350 Logger::getInstance()
351 .addWarning(
"Reading PointData from stream failed. Header could "
358 unsigned numberOfScalarData = 0;
359 unsigned numberOfVectorData = 0;
360 stream.read(
reinterpret_cast<char *
>(&numberOfScalarData),
362 stream.read(
reinterpret_cast<char *
>(&numberOfVectorData),
366 for (
unsigned i = 0; i < numberOfScalarData; ++i) {
368 stream.read(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
369 std::vector<char> dataLabel(sizeOfName);
370 stream.read(dataLabel.data(), sizeOfName);
371 uint32_t numberOfValues;
372 stream.read(
reinterpret_cast<char *
>(&numberOfValues),
sizeof(uint32_t));
374 scalarData.resize(numberOfValues);
376 for (
auto &value : scalarData) {
377 stream.read(
reinterpret_cast<char *
>(&value),
378 sizeof(
typename ScalarDataType::value_type));
382 std::string(dataLabel.begin(), dataLabel.end()));
386 for (
unsigned i = 0; i < numberOfVectorData; ++i) {
388 stream.read(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
389 std::vector<char> dataLabel(sizeOfName);
390 stream.read(dataLabel.data(), sizeOfName);
391 uint32_t numberOfValues;
392 stream.read(
reinterpret_cast<char *
>(&numberOfValues),
sizeof(uint32_t));
394 vectorData.resize(numberOfValues);
396 for (
auto &vector : vectorData) {
397 for (
auto &value : vector) {
398 stream.read(
reinterpret_cast<char *
>(&value),
399 sizeof(
typename VectorDataType::value_type::value_type));
404 std::string(dataLabel.begin(), dataLabel.end()));
This class holds data associated with points in space.
Definition lsPointData.hpp:20
void clear()
Delete all data stored in this object.
Definition lsPointData.hpp:272
void setScalarDataLabel(int index, std::string newLabel)
Definition lsPointData.hpp:141
void insertNextScalarData(const ScalarDataType &scalars, std::string label="Scalars")
insert new scalar data array
Definition lsPointData.hpp:57
void eraseScalarData(int index)
Delete the scalar data at index.
Definition lsPointData.hpp:146
void translateFromData(const PointData &source, const std::vector< unsigned > &indices)
Add data in the passed source pointData into this data according to the indices passed....
Definition lsPointData.hpp:230
const VectorDataType * getVectorData(std::string searchLabel, bool noWarning=false) const
Definition lsPointData.hpp:173
void setVectorDataLabel(int index, std::string newLabel)
Definition lsPointData.hpp:202
std::vector< T > ScalarDataType
Definition lsPointData.hpp:22
void translateFromMultiData(const PointData &source, const std::vector< std::vector< unsigned > > &indicesVector)
Same as translateFromData, but the indices are given as a vector, as is the case when collecting indi...
Definition lsPointData.hpp:249
VectorDataType * getVectorData(std::string searchLabel, bool noWarning=false)
Definition lsPointData.hpp:159
ScalarDataType * getScalarData(std::string searchLabel, bool noWarning=false)
Definition lsPointData.hpp:98
const ScalarDataType * getScalarData(std::string searchLabel, bool noWarning=false) const
Definition lsPointData.hpp:112
std::ostream & serialize(std::ostream &stream)
Serialize PointData into a binary stream.
Definition lsPointData.hpp:283
void append(const PointData &passedData)
Append the passed PointData to this one.
Definition lsPointData.hpp:213
std::vector< std::array< T, 3 > > VectorDataType
Definition lsPointData.hpp:23
void insertNextScalarData(ScalarDataType &&scalars, std::string label="Scalars")
insert new scalar data array
Definition lsPointData.hpp:64
unsigned getScalarDataSize() const
get the number of different scalar data arrays saved
Definition lsPointData.hpp:85
VectorDataType * getVectorData(int index)
Definition lsPointData.hpp:151
std::string getScalarDataLabel(int index) const
Definition lsPointData.hpp:135
std::string getVectorDataLabel(int index) const
Definition lsPointData.hpp:196
const VectorDataType * getVectorData(int index) const
Definition lsPointData.hpp:155
int getVectorDataIndex(std::string searchLabel) const
Definition lsPointData.hpp:187
ScalarDataType * getScalarData(int index)
Definition lsPointData.hpp:90
const ScalarDataType * getScalarData(int index) const
Definition lsPointData.hpp:94
unsigned getVectorDataSize() const
get the number of different vector data arrays saved
Definition lsPointData.hpp:88
void insertNextVectorData(VectorDataType &&vectors, std::string label="Vectors")
insert new vector data array
Definition lsPointData.hpp:78
int getScalarDataIndex(std::string searchLabel) const
Definition lsPointData.hpp:126
void insertNextVectorData(const VectorDataType &vectors, std::string label="Vectors")
insert new vector data array
Definition lsPointData.hpp:71
bool empty()
Return whether this object is empty.
Definition lsPointData.hpp:280
std::istream & deserialize(std::istream &stream)
Deserialize PointData from a binary stream.
Definition lsPointData.hpp:346
void eraseVectorData(int index)
Delete the vector data at index.
Definition lsPointData.hpp:207
#define PRECOMPILE_PRECISION(className)
Definition lsPreCompileMacros.hpp:30
constexpr AssignType assignable
Definition lsConcepts.hpp:10
std::enable_if_t< std::is_floating_point< T >::value, AssignType > IsFloatingPoint
Definition lsConcepts.hpp:23
Definition lsAdvect.hpp:46
double T
Definition pyWrap.cpp:63