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_v<VectorType>,
33 const typename VectorType::value_type *,
34 typename VectorType::value_type *>>
35 static ReturnType indexPointerOrNull(VectorType &v,
int index) {
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 static void appendTranslateData(DataType ¤tData,
const DataType &source,
48 const std::vector<unsigned> &indices) {
49 currentData.reserve(currentData.size() + indices.size());
50 for (
unsigned int index : indices) {
51 currentData.push_back(source[index]);
58 const std::string &label =
"Scalars") {
59 scalarData.push_back(scalars);
60 scalarDataLabels.push_back(label);
65 const std::string &label =
"Scalars") {
66 scalarData.push_back(std::move(scalars));
67 scalarDataLabels.push_back(label);
72 const std::string &label =
"Vectors") {
73 vectorData.push_back(vectors);
74 vectorDataLabels.push_back(label);
79 const std::string &label =
"Vectors") {
80 vectorData.push_back(std::move(vectors));
81 vectorDataLabels.push_back(label);
86 const std::string &label =
"Scalars") {
88 scalarData[i] = scalars;
96 const std::string &label =
"Scalars") {
98 scalarData[i] = std::move(scalars);
106 const std::string &label =
"Vectors") {
108 vectorData[i] = vectors;
116 std::string label =
"Vectors") {
118 vectorData[i] = std::move(vectors);
131 return indexPointerOrNull(scalarData, index);
135 return indexPointerOrNull(scalarData, index);
139 bool noWarning =
false) {
141 return &(scalarData[i]);
144 Logger::getInstance()
145 .addWarning(
"PointData attempted to access scalar data labeled '" +
147 "', which does not exist. Returning nullptr instead.")
153 bool noWarning =
false)
const {
155 return &(scalarData[i]);
158 Logger::getInstance()
159 .addWarning(
"PointData attempted to access scalar data labeled '" +
161 "', which does not exist. Returning nullptr instead.")
167 for (
int i = 0; i < scalarDataLabels.size(); ++i) {
168 if (scalarDataLabels[i] == searchLabel) {
176 return (index >= 0 && index < scalarDataLabels.size())
177 ? scalarDataLabels[index]
182 scalarDataLabels[index] = std::move(newLabel);
187 scalarData.erase(scalarData.begin() + index);
188 scalarDataLabels.erase(scalarDataLabels.begin() + index);
192 return indexPointerOrNull(vectorData, index);
196 return indexPointerOrNull(vectorData, index);
200 bool noWarning =
false) {
202 return &(vectorData[i]);
205 Logger::getInstance()
206 .addWarning(
"PointData attempted to access vector data labeled '" +
208 "', which does not exist. Returning nullptr instead.")
214 bool noWarning =
false)
const {
216 return &(vectorData[i]);
219 Logger::getInstance()
220 .addWarning(
"PointData attempted to access vector data labeled '" +
222 "', which does not exist. Returning nullptr instead.")
228 for (
int i = 0; i < vectorDataLabels.size(); ++i) {
229 if (vectorDataLabels[i] == searchLabel) {
237 return (index >= 0 && index < vectorDataLabels.size())
238 ? vectorDataLabels[index]
243 vectorDataLabels[index] = std::move(newLabel);
248 vectorData.erase(vectorData.begin() + index);
249 vectorDataLabels.erase(vectorDataLabels.begin() + index);
254 scalarData.insert(scalarData.end(), passedData.scalarData.begin(),
255 passedData.scalarData.end());
256 scalarDataLabels.insert(scalarDataLabels.end(),
257 passedData.scalarDataLabels.begin(),
258 passedData.scalarDataLabels.end());
259 vectorData.insert(vectorData.end(), passedData.vectorData.begin(),
260 passedData.vectorData.end());
261 vectorDataLabels.insert(vectorDataLabels.end(),
262 passedData.vectorDataLabels.begin(),
263 passedData.vectorDataLabels.end());
271 const std::vector<unsigned> &indices) {
275 auto currentData = --scalarData.end();
276 appendTranslateData(*currentData, source.scalarData[j], indices);
282 auto currentData = --vectorData.end();
283 appendTranslateData(*currentData, source.vectorData[j], indices);
291 const std::vector<std::vector<unsigned>> &indicesVector) {
295 auto currentData = --scalarData.end();
296 for (
const auto &i : indicesVector) {
297 appendTranslateData(*currentData, source.scalarData[j], i);
304 auto currentData = --vectorData.end();
305 for (
const auto &i : indicesVector) {
306 appendTranslateData(*currentData, source.vectorData[j], i);
314 scalarDataLabels.clear();
316 vectorDataLabels.clear();
320 bool empty() {
return scalarData.empty() && vectorData.empty(); }
328 stream <<
"lsPointData";
329 uint32_t numberOfScalarData = scalarData.size();
330 uint32_t numberOfVectorData = vectorData.size();
331 stream.write(
reinterpret_cast<const char *
>(&numberOfScalarData),
333 stream.write(
reinterpret_cast<const char *
>(&numberOfVectorData),
338 auto labelIt = scalarDataLabels.begin();
340 for (
auto data : scalarData) {
342 uint32_t sizeOfName = labelIt->length();
343 stream.write(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
345 uint32_t numberOfValues = data.size();
346 stream.write(
reinterpret_cast<const char *
>(&numberOfValues),
349 for (
auto value : data) {
350 stream.write(
reinterpret_cast<const char *
>(&value),
351 sizeof(
typename ScalarDataType::value_type));
359 auto labelIt = vectorDataLabels.begin();
361 for (
auto data : vectorData) {
363 uint32_t sizeOfName = labelIt->length();
364 stream.write(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
366 uint32_t numberOfVectors = data.size();
367 stream.write(
reinterpret_cast<const char *
>(&numberOfVectors),
370 for (
auto vector : data) {
372 for (
auto value : vector) {
374 reinterpret_cast<const char *
>(&value),
375 sizeof(
typename VectorDataType::value_type::value_type));
388 stream.read(identifier, 11);
389 if (std::string(identifier).compare(0, 11,
"lsPointData")) {
390 Logger::getInstance()
391 .addWarning(
"Reading PointData from stream failed. Header could "
398 unsigned numberOfScalarData = 0;
399 unsigned numberOfVectorData = 0;
400 stream.read(
reinterpret_cast<char *
>(&numberOfScalarData),
402 stream.read(
reinterpret_cast<char *
>(&numberOfVectorData),
406 for (
unsigned i = 0; i < numberOfScalarData; ++i) {
408 stream.read(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
409 std::vector<char> dataLabel(sizeOfName);
410 stream.read(dataLabel.data(), sizeOfName);
411 uint32_t numberOfValues;
412 stream.read(
reinterpret_cast<char *
>(&numberOfValues),
sizeof(uint32_t));
414 scalarData.resize(numberOfValues);
416 for (
auto &value : scalarData) {
417 stream.read(
reinterpret_cast<char *
>(&value),
418 sizeof(
typename ScalarDataType::value_type));
422 std::string(dataLabel.begin(), dataLabel.end()));
426 for (
unsigned i = 0; i < numberOfVectorData; ++i) {
428 stream.read(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
429 std::vector<char> dataLabel(sizeOfName);
430 stream.read(dataLabel.data(), sizeOfName);
431 uint32_t numberOfValues;
432 stream.read(
reinterpret_cast<char *
>(&numberOfValues),
sizeof(uint32_t));
434 vectorData.resize(numberOfValues);
436 for (
auto &vector : vectorData) {
437 for (
auto &value : vector) {
438 stream.read(
reinterpret_cast<char *
>(&value),
439 sizeof(
typename VectorDataType::value_type::value_type));
444 std::string(dataLabel.begin(), dataLabel.end()));
This class holds data associated with points in space.
Definition lsPointData.hpp:20
std::vector< Vec3D< T > > VectorDataType
Definition lsPointData.hpp:23
void clear()
Delete all data stored in this object.
Definition lsPointData.hpp:312
void setScalarDataLabel(int index, std::string newLabel)
Definition lsPointData.hpp:181
int getVectorDataIndex(const std::string &searchLabel) const
Definition lsPointData.hpp:227
int getScalarDataIndex(const std::string &searchLabel) const
Definition lsPointData.hpp:166
void insertReplaceScalarData(ScalarDataType &&scalars, const std::string &label="Scalars")
insert or replace scalar data array
Definition lsPointData.hpp:95
VectorDataType * getVectorData(const std::string &searchLabel, bool noWarning=false)
Definition lsPointData.hpp:199
void eraseScalarData(int index)
Delete the scalar data at index.
Definition lsPointData.hpp:186
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:270
void insertNextScalarData(const ScalarDataType &scalars, const std::string &label="Scalars")
insert new scalar data array
Definition lsPointData.hpp:57
void insertReplaceVectorData(VectorDataType &&vectors, std::string label="Vectors")
insert new vector data array
Definition lsPointData.hpp:115
void setVectorDataLabel(int index, std::string newLabel)
Definition lsPointData.hpp:242
ScalarDataType * getScalarData(const std::string &searchLabel, bool noWarning=false)
Definition lsPointData.hpp:138
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:289
std::ostream & serialize(std::ostream &stream)
Serialize PointData into a binary stream.
Definition lsPointData.hpp:323
void append(const PointData &passedData)
Append the passed PointData to this one.
Definition lsPointData.hpp:253
const VectorDataType * getVectorData(const std::string &searchLabel, bool noWarning=false) const
Definition lsPointData.hpp:213
const ScalarDataType * getScalarData(const std::string &searchLabel, bool noWarning=false) const
Definition lsPointData.hpp:152
std::vector< T > ScalarDataType
Definition lsPointData.hpp:22
unsigned getScalarDataSize() const
get the number of different scalar data arrays saved
Definition lsPointData.hpp:125
VectorDataType * getVectorData(int index)
Definition lsPointData.hpp:191
std::string getScalarDataLabel(int index) const
Definition lsPointData.hpp:175
std::string getVectorDataLabel(int index) const
Definition lsPointData.hpp:236
const VectorDataType * getVectorData(int index) const
Definition lsPointData.hpp:195
ScalarDataType * getScalarData(int index)
Definition lsPointData.hpp:130
const ScalarDataType * getScalarData(int index) const
Definition lsPointData.hpp:134
unsigned getVectorDataSize() const
get the number of different vector data arrays saved
Definition lsPointData.hpp:128
void insertNextScalarData(ScalarDataType &&scalars, const std::string &label="Scalars")
insert new scalar data array
Definition lsPointData.hpp:64
void insertNextVectorData(VectorDataType &&vectors, const std::string &label="Vectors")
insert new vector data array
Definition lsPointData.hpp:78
void insertReplaceVectorData(const VectorDataType &vectors, const std::string &label="Vectors")
insert or replace vector data array
Definition lsPointData.hpp:105
bool empty()
Return whether this object is empty.
Definition lsPointData.hpp:320
void insertReplaceScalarData(const ScalarDataType &scalars, const std::string &label="Scalars")
insert or replace scalar data array
Definition lsPointData.hpp:85
void insertNextVectorData(const VectorDataType &vectors, const std::string &label="Vectors")
insert new vector data array
Definition lsPointData.hpp:71
std::istream & deserialize(std::istream &stream)
Deserialize PointData from a binary stream.
Definition lsPointData.hpp:386
void eraseVectorData(int index)
Delete the vector data at index.
Definition lsPointData.hpp:247
#define PRECOMPILE_PRECISION(className)
Definition lsPreCompileMacros.hpp:30
constexpr AssignType assignable
Definition lsConcepts.hpp:10
std::enable_if_t< std::is_floating_point_v< T >, AssignType > IsFloatingPoint
Definition lsConcepts.hpp:22
Definition lsAdvect.hpp:36
double T
Definition pyWrap.cpp:69