11#include <vcLogger.hpp>
12#include <vcSmartPointer.hpp>
16using namespace viennacore;
19template <
class T = double,
27 std::vector<ScalarDataType> scalarData;
28 std::vector<std::string> scalarDataLabels;
29 std::vector<VectorDataType> vectorData;
30 std::vector<std::string> vectorDataLabels;
32 template <
class VectorType,
class ReturnType = std::conditional_t<
33 std::is_const_v<VectorType>,
34 const typename VectorType::value_type *,
35 typename VectorType::value_type *>>
36 static ReturnType indexPointerOrNull(VectorType &v,
int index) {
37 if (index >= 0 && index < v.size())
41 .addWarning(
"PointData: Tried to access out of bounds index! "
42 "Returned nullptr instead.")
47 template <
class DataType>
48 static void appendTranslateData(DataType ¤tData,
const DataType &source,
49 const std::vector<unsigned> &indices) {
50 currentData.reserve(currentData.size() + indices.size());
51 for (
unsigned int index : indices) {
52 currentData.push_back(source[index]);
57 template <
class... Args>
static auto New(Args &&...args) {
58 return SmartPointer<PointData>::New(std::forward<Args>(args)...);
63 const std::string &label =
"Scalars") {
64 scalarData.push_back(scalars);
65 scalarDataLabels.push_back(label);
70 const std::string &label =
"Scalars") {
71 scalarData.push_back(std::move(scalars));
72 scalarDataLabels.push_back(label);
77 const std::string &label =
"Vectors") {
78 vectorData.push_back(vectors);
79 vectorDataLabels.push_back(label);
84 const std::string &label =
"Vectors") {
85 vectorData.push_back(std::move(vectors));
86 vectorDataLabels.push_back(label);
91 const std::string &label =
"Scalars") {
93 scalarData[i] = scalars;
101 const std::string &label =
"Scalars") {
103 scalarData[i] = std::move(scalars);
111 const std::string &label =
"Vectors") {
113 vectorData[i] = vectors;
121 std::string label =
"Vectors") {
123 vectorData[i] = std::move(vectors);
136 return indexPointerOrNull(scalarData, index);
140 return indexPointerOrNull(scalarData, index);
144 bool noWarning =
false) {
146 return &(scalarData[i]);
149 Logger::getInstance()
150 .addWarning(
"PointData attempted to access scalar data labeled '" +
152 "', which does not exist. Returning nullptr instead.")
158 bool noWarning =
false)
const {
160 return &(scalarData[i]);
163 Logger::getInstance()
164 .addWarning(
"PointData attempted to access scalar data labeled '" +
166 "', which does not exist. Returning nullptr instead.")
172 for (
int i = 0; i < scalarDataLabels.size(); ++i) {
173 if (scalarDataLabels[i] == searchLabel) {
181 return (index >= 0 && index < scalarDataLabels.size())
182 ? scalarDataLabels[index]
187 scalarDataLabels[index] = std::move(newLabel);
192 scalarData.erase(scalarData.begin() + index);
193 scalarDataLabels.erase(scalarDataLabels.begin() + index);
197 return indexPointerOrNull(vectorData, index);
201 return indexPointerOrNull(vectorData, index);
205 bool noWarning =
false) {
207 return &(vectorData[i]);
210 Logger::getInstance()
211 .addWarning(
"PointData attempted to access vector data labeled '" +
213 "', which does not exist. Returning nullptr instead.")
219 bool noWarning =
false)
const {
221 return &(vectorData[i]);
224 Logger::getInstance()
225 .addWarning(
"PointData attempted to access vector data labeled '" +
227 "', which does not exist. Returning nullptr instead.")
233 for (
int i = 0; i < vectorDataLabels.size(); ++i) {
234 if (vectorDataLabels[i] == searchLabel) {
242 return (index >= 0 && index < vectorDataLabels.size())
243 ? vectorDataLabels[index]
248 vectorDataLabels[index] = std::move(newLabel);
253 vectorData.erase(vectorData.begin() + index);
254 vectorDataLabels.erase(vectorDataLabels.begin() + index);
259 scalarData.insert(scalarData.end(), passedData.scalarData.begin(),
260 passedData.scalarData.end());
261 scalarDataLabels.insert(scalarDataLabels.end(),
262 passedData.scalarDataLabels.begin(),
263 passedData.scalarDataLabels.end());
264 vectorData.insert(vectorData.end(), passedData.vectorData.begin(),
265 passedData.vectorData.end());
266 vectorDataLabels.insert(vectorDataLabels.end(),
267 passedData.vectorDataLabels.begin(),
268 passedData.vectorDataLabels.end());
276 const std::vector<unsigned> &indices) {
280 auto currentData = --scalarData.end();
281 appendTranslateData(*currentData, source.scalarData[j], indices);
287 auto currentData = --vectorData.end();
288 appendTranslateData(*currentData, source.vectorData[j], indices);
296 const std::vector<std::vector<unsigned>> &indicesVector) {
300 auto currentData = --scalarData.end();
301 for (
const auto &i : indicesVector) {
302 appendTranslateData(*currentData, source.scalarData[j], i);
309 auto currentData = --vectorData.end();
310 for (
const auto &i : indicesVector) {
311 appendTranslateData(*currentData, source.vectorData[j], i);
319 scalarDataLabels.clear();
321 vectorDataLabels.clear();
325 bool empty() {
return scalarData.empty() && vectorData.empty(); }
333 stream <<
"lsPointData";
334 uint32_t numberOfScalarData = scalarData.size();
335 uint32_t numberOfVectorData = vectorData.size();
336 stream.write(
reinterpret_cast<const char *
>(&numberOfScalarData),
338 stream.write(
reinterpret_cast<const char *
>(&numberOfVectorData),
343 auto labelIt = scalarDataLabels.begin();
345 for (
auto data : scalarData) {
347 uint32_t sizeOfName = labelIt->length();
348 stream.write(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
350 uint32_t numberOfValues = data.size();
351 stream.write(
reinterpret_cast<const char *
>(&numberOfValues),
354 for (
auto value : data) {
355 stream.write(
reinterpret_cast<const char *
>(&value),
356 sizeof(
typename ScalarDataType::value_type));
364 auto labelIt = vectorDataLabels.begin();
366 for (
auto data : vectorData) {
368 uint32_t sizeOfName = labelIt->length();
369 stream.write(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
371 uint32_t numberOfVectors = data.size();
372 stream.write(
reinterpret_cast<const char *
>(&numberOfVectors),
375 for (
auto vector : data) {
377 for (
auto value : vector) {
379 reinterpret_cast<const char *
>(&value),
380 sizeof(
typename VectorDataType::value_type::value_type));
393 stream.read(identifier, 11);
394 if (std::string(identifier).compare(0, 11,
"lsPointData")) {
395 Logger::getInstance()
396 .addWarning(
"Reading PointData from stream failed. Header could "
403 unsigned numberOfScalarData = 0;
404 unsigned numberOfVectorData = 0;
405 stream.read(
reinterpret_cast<char *
>(&numberOfScalarData),
407 stream.read(
reinterpret_cast<char *
>(&numberOfVectorData),
411 for (
unsigned i = 0; i < numberOfScalarData; ++i) {
413 stream.read(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
414 std::vector<char> dataLabel(sizeOfName);
415 stream.read(dataLabel.data(), sizeOfName);
416 uint32_t numberOfValues;
417 stream.read(
reinterpret_cast<char *
>(&numberOfValues),
sizeof(uint32_t));
419 scalarData.resize(numberOfValues);
421 for (
auto &value : scalarData) {
422 stream.read(
reinterpret_cast<char *
>(&value),
423 sizeof(
typename ScalarDataType::value_type));
427 std::string(dataLabel.begin(), dataLabel.end()));
431 for (
unsigned i = 0; i < numberOfVectorData; ++i) {
433 stream.read(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
434 std::vector<char> dataLabel(sizeOfName);
435 stream.read(dataLabel.data(), sizeOfName);
436 uint32_t numberOfValues;
437 stream.read(
reinterpret_cast<char *
>(&numberOfValues),
sizeof(uint32_t));
439 vectorData.resize(numberOfValues);
441 for (
auto &vector : vectorData) {
442 for (
auto &value : vector) {
443 stream.read(
reinterpret_cast<char *
>(&value),
444 sizeof(
typename VectorDataType::value_type::value_type));
449 std::string(dataLabel.begin(), dataLabel.end()));
This class holds data associated with points in space.
Definition lsPointData.hpp:21
std::vector< Vec3D< T > > VectorDataType
Definition lsPointData.hpp:24
void clear()
Delete all data stored in this object.
Definition lsPointData.hpp:317
static auto New(Args &&...args)
Definition lsPointData.hpp:57
void setScalarDataLabel(int index, std::string newLabel)
Definition lsPointData.hpp:186
int getVectorDataIndex(const std::string &searchLabel) const
Definition lsPointData.hpp:232
int getScalarDataIndex(const std::string &searchLabel) const
Definition lsPointData.hpp:171
void insertReplaceScalarData(ScalarDataType &&scalars, const std::string &label="Scalars")
insert or replace scalar data array
Definition lsPointData.hpp:100
VectorDataType * getVectorData(const std::string &searchLabel, bool noWarning=false)
Definition lsPointData.hpp:204
void eraseScalarData(int index)
Delete the scalar data at index.
Definition lsPointData.hpp:191
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:275
void insertNextScalarData(const ScalarDataType &scalars, const std::string &label="Scalars")
insert new scalar data array
Definition lsPointData.hpp:62
void insertReplaceVectorData(VectorDataType &&vectors, std::string label="Vectors")
insert new vector data array
Definition lsPointData.hpp:120
void setVectorDataLabel(int index, std::string newLabel)
Definition lsPointData.hpp:247
ScalarDataType * getScalarData(const std::string &searchLabel, bool noWarning=false)
Definition lsPointData.hpp:143
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:294
std::ostream & serialize(std::ostream &stream)
Serialize PointData into a binary stream.
Definition lsPointData.hpp:328
void append(const PointData &passedData)
Append the passed PointData to this one.
Definition lsPointData.hpp:258
const VectorDataType * getVectorData(const std::string &searchLabel, bool noWarning=false) const
Definition lsPointData.hpp:218
const ScalarDataType * getScalarData(const std::string &searchLabel, bool noWarning=false) const
Definition lsPointData.hpp:157
std::vector< T > ScalarDataType
Definition lsPointData.hpp:23
unsigned getScalarDataSize() const
get the number of different scalar data arrays saved
Definition lsPointData.hpp:130
VectorDataType * getVectorData(int index)
Definition lsPointData.hpp:196
std::string getScalarDataLabel(int index) const
Definition lsPointData.hpp:180
std::string getVectorDataLabel(int index) const
Definition lsPointData.hpp:241
const VectorDataType * getVectorData(int index) const
Definition lsPointData.hpp:200
ScalarDataType * getScalarData(int index)
Definition lsPointData.hpp:135
const ScalarDataType * getScalarData(int index) const
Definition lsPointData.hpp:139
unsigned getVectorDataSize() const
get the number of different vector data arrays saved
Definition lsPointData.hpp:133
void insertNextScalarData(ScalarDataType &&scalars, const std::string &label="Scalars")
insert new scalar data array
Definition lsPointData.hpp:69
void insertNextVectorData(VectorDataType &&vectors, const std::string &label="Vectors")
insert new vector data array
Definition lsPointData.hpp:83
void insertReplaceVectorData(const VectorDataType &vectors, const std::string &label="Vectors")
insert or replace vector data array
Definition lsPointData.hpp:110
bool empty()
Return whether this object is empty.
Definition lsPointData.hpp:325
void insertReplaceScalarData(const ScalarDataType &scalars, const std::string &label="Scalars")
insert or replace scalar data array
Definition lsPointData.hpp:90
void insertNextVectorData(const VectorDataType &vectors, const std::string &label="Vectors")
insert new vector data array
Definition lsPointData.hpp:76
std::istream & deserialize(std::istream &stream)
Deserialize PointData from a binary stream.
Definition lsPointData.hpp:391
void eraseVectorData(int index)
Delete the vector data at index.
Definition lsPointData.hpp:252
#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