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())
40 VIENNACORE_LOG_WARNING(
"PointData: Tried to access out of bounds index! "
41 "Returning nullptr instead.");
45 template <
class DataType>
46 static void appendTranslateData(DataType ¤tData,
const DataType &source,
47 const std::vector<unsigned> &indices) {
48 currentData.reserve(currentData.size() + indices.size());
49 for (
unsigned int index : indices) {
50 currentData.push_back(source[index]);
55 template <
class... Args>
static auto New(Args &&...args) {
56 return SmartPointer<PointData>::New(std::forward<Args>(args)...);
61 const std::string &label =
"Scalars") {
62 scalarData.push_back(scalars);
63 scalarDataLabels.push_back(label);
68 const std::string &label =
"Scalars") {
69 scalarData.push_back(std::move(scalars));
70 scalarDataLabels.push_back(label);
75 const std::string &label =
"Vectors") {
76 vectorData.push_back(vectors);
77 vectorDataLabels.push_back(label);
82 const std::string &label =
"Vectors") {
83 vectorData.push_back(std::move(vectors));
84 vectorDataLabels.push_back(label);
89 const std::string &label =
"Scalars") {
91 scalarData[i] = scalars;
99 const std::string &label =
"Scalars") {
101 scalarData[i] = std::move(scalars);
109 const std::string &label =
"Vectors") {
111 vectorData[i] = vectors;
119 std::string label =
"Vectors") {
121 vectorData[i] = std::move(vectors);
134 return indexPointerOrNull(scalarData, index);
138 return indexPointerOrNull(scalarData, index);
142 bool noWarning =
false) {
144 return &(scalarData[i]);
147 VIENNACORE_LOG_WARNING(
148 "PointData attempted to access scalar data labeled '" + searchLabel +
149 "', which does not exist. Returning nullptr instead.");
155 bool noWarning =
false)
const {
157 return &(scalarData[i]);
160 VIENNACORE_LOG_WARNING(
161 "PointData attempted to access scalar data labeled '" + searchLabel +
162 "', which does not exist. Returning nullptr instead.");
168 for (
int i = 0; i < scalarDataLabels.size(); ++i) {
169 if (scalarDataLabels[i] == searchLabel) {
177 return (index >= 0 && index < scalarDataLabels.size())
178 ? scalarDataLabels[index]
183 scalarDataLabels[index] = std::move(newLabel);
188 scalarData.erase(scalarData.begin() + index);
189 scalarDataLabels.erase(scalarDataLabels.begin() + index);
193 return indexPointerOrNull(vectorData, index);
197 return indexPointerOrNull(vectorData, index);
201 bool noWarning =
false) {
203 return &(vectorData[i]);
206 VIENNACORE_LOG_WARNING(
207 "PointData attempted to access vector data labeled '" + searchLabel +
208 "', which does not exist. Returning nullptr instead.");
214 bool noWarning =
false)
const {
216 return &(vectorData[i]);
219 VIENNACORE_LOG_WARNING(
220 "PointData attempted to access vector data labeled '" + searchLabel +
221 "', which does not exist. Returning nullptr instead.");
227 for (
int i = 0; i < vectorDataLabels.size(); ++i) {
228 if (vectorDataLabels[i] == searchLabel) {
236 return (index >= 0 && index < vectorDataLabels.size())
237 ? vectorDataLabels[index]
242 vectorDataLabels[index] = std::move(newLabel);
247 vectorData.erase(vectorData.begin() + index);
248 vectorDataLabels.erase(vectorDataLabels.begin() + index);
253 scalarData.insert(scalarData.end(), passedData.scalarData.begin(),
254 passedData.scalarData.end());
255 scalarDataLabels.insert(scalarDataLabels.end(),
256 passedData.scalarDataLabels.begin(),
257 passedData.scalarDataLabels.end());
258 vectorData.insert(vectorData.end(), passedData.vectorData.begin(),
259 passedData.vectorData.end());
260 vectorDataLabels.insert(vectorDataLabels.end(),
261 passedData.vectorDataLabels.begin(),
262 passedData.vectorDataLabels.end());
270 const std::vector<unsigned> &indices) {
274 auto currentData = --scalarData.end();
275 appendTranslateData(*currentData, source.scalarData[j], indices);
281 auto currentData = --vectorData.end();
282 appendTranslateData(*currentData, source.vectorData[j], indices);
290 const std::vector<std::vector<unsigned>> &indicesVector) {
294 auto currentData = --scalarData.end();
295 for (
const auto &i : indicesVector) {
296 appendTranslateData(*currentData, source.scalarData[j], i);
303 auto currentData = --vectorData.end();
304 for (
const auto &i : indicesVector) {
305 appendTranslateData(*currentData, source.vectorData[j], i);
313 scalarDataLabels.clear();
315 vectorDataLabels.clear();
319 bool empty() {
return scalarData.empty() && vectorData.empty(); }
327 stream <<
"lsPointData";
328 uint32_t numberOfScalarData = scalarData.size();
329 uint32_t numberOfVectorData = vectorData.size();
330 stream.write(
reinterpret_cast<const char *
>(&numberOfScalarData),
332 stream.write(
reinterpret_cast<const char *
>(&numberOfVectorData),
337 auto labelIt = scalarDataLabels.begin();
339 for (
auto data : scalarData) {
341 uint32_t sizeOfName = labelIt->length();
342 stream.write(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
344 uint32_t numberOfValues = data.size();
345 stream.write(
reinterpret_cast<const char *
>(&numberOfValues),
348 for (
auto value : data) {
349 stream.write(
reinterpret_cast<const char *
>(&value),
350 sizeof(
typename ScalarDataType::value_type));
358 auto labelIt = vectorDataLabels.begin();
360 for (
auto data : vectorData) {
362 uint32_t sizeOfName = labelIt->length();
363 stream.write(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
365 uint32_t numberOfVectors = data.size();
366 stream.write(
reinterpret_cast<const char *
>(&numberOfVectors),
369 for (
auto vector : data) {
371 for (
auto value : vector) {
373 reinterpret_cast<const char *
>(&value),
374 sizeof(
typename VectorDataType::value_type::value_type));
387 stream.read(identifier, 11);
388 if (std::string(identifier).compare(0, 11,
"lsPointData")) {
389 Logger::getInstance()
390 .addError(
"Reading PointData from stream failed. Header could "
397 unsigned numberOfScalarData = 0;
398 unsigned numberOfVectorData = 0;
399 stream.read(
reinterpret_cast<char *
>(&numberOfScalarData),
401 stream.read(
reinterpret_cast<char *
>(&numberOfVectorData),
405 for (
unsigned i = 0; i < numberOfScalarData; ++i) {
407 stream.read(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
408 std::vector<char> dataLabel(sizeOfName);
409 stream.read(dataLabel.data(), sizeOfName);
410 uint32_t numberOfValues;
411 stream.read(
reinterpret_cast<char *
>(&numberOfValues),
sizeof(uint32_t));
413 scalarData.resize(numberOfValues);
415 for (
auto &value : scalarData) {
416 stream.read(
reinterpret_cast<char *
>(&value),
417 sizeof(
typename ScalarDataType::value_type));
421 std::string(dataLabel.begin(), dataLabel.end()));
425 for (
unsigned i = 0; i < numberOfVectorData; ++i) {
427 stream.read(
reinterpret_cast<char *
>(&sizeOfName),
sizeof(uint32_t));
428 std::vector<char> dataLabel(sizeOfName);
429 stream.read(dataLabel.data(), sizeOfName);
430 uint32_t numberOfValues;
431 stream.read(
reinterpret_cast<char *
>(&numberOfValues),
sizeof(uint32_t));
433 vectorData.resize(numberOfValues);
435 for (
auto &vector : vectorData) {
436 for (
auto &value : vector) {
437 stream.read(
reinterpret_cast<char *
>(&value),
438 sizeof(
typename VectorDataType::value_type::value_type));
443 std::string(dataLabel.begin(), dataLabel.end()));
double T
Definition Epitaxy.cpp:12
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:311
static auto New(Args &&...args)
Definition lsPointData.hpp:55
void setScalarDataLabel(int index, std::string newLabel)
Definition lsPointData.hpp:182
int getVectorDataIndex(const std::string &searchLabel) const
Definition lsPointData.hpp:226
int getScalarDataIndex(const std::string &searchLabel) const
Definition lsPointData.hpp:167
void insertReplaceScalarData(ScalarDataType &&scalars, const std::string &label="Scalars")
insert or replace scalar data array
Definition lsPointData.hpp:98
VectorDataType * getVectorData(const std::string &searchLabel, bool noWarning=false)
Definition lsPointData.hpp:200
void eraseScalarData(int index)
Delete the scalar data at index.
Definition lsPointData.hpp:187
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:269
void insertNextScalarData(const ScalarDataType &scalars, const std::string &label="Scalars")
insert new scalar data array
Definition lsPointData.hpp:60
void insertReplaceVectorData(VectorDataType &&vectors, std::string label="Vectors")
insert new vector data array
Definition lsPointData.hpp:118
void setVectorDataLabel(int index, std::string newLabel)
Definition lsPointData.hpp:241
ScalarDataType * getScalarData(const std::string &searchLabel, bool noWarning=false)
Definition lsPointData.hpp:141
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:288
std::ostream & serialize(std::ostream &stream)
Serialize PointData into a binary stream.
Definition lsPointData.hpp:322
void append(const PointData &passedData)
Append the passed PointData to this one.
Definition lsPointData.hpp:252
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:154
std::vector< T > ScalarDataType
Definition lsPointData.hpp:23
unsigned getScalarDataSize() const
get the number of different scalar data arrays saved
Definition lsPointData.hpp:128
VectorDataType * getVectorData(int index)
Definition lsPointData.hpp:192
std::string getScalarDataLabel(int index) const
Definition lsPointData.hpp:176
std::string getVectorDataLabel(int index) const
Definition lsPointData.hpp:235
const VectorDataType * getVectorData(int index) const
Definition lsPointData.hpp:196
ScalarDataType * getScalarData(int index)
Definition lsPointData.hpp:133
const ScalarDataType * getScalarData(int index) const
Definition lsPointData.hpp:137
unsigned getVectorDataSize() const
get the number of different vector data arrays saved
Definition lsPointData.hpp:131
void insertNextScalarData(ScalarDataType &&scalars, const std::string &label="Scalars")
insert new scalar data array
Definition lsPointData.hpp:67
void insertNextVectorData(VectorDataType &&vectors, const std::string &label="Vectors")
insert new vector data array
Definition lsPointData.hpp:81
void insertReplaceVectorData(const VectorDataType &vectors, const std::string &label="Vectors")
insert or replace vector data array
Definition lsPointData.hpp:108
bool empty()
Return whether this object is empty.
Definition lsPointData.hpp:319
void insertReplaceScalarData(const ScalarDataType &scalars, const std::string &label="Scalars")
insert or replace scalar data array
Definition lsPointData.hpp:88
void insertNextVectorData(const VectorDataType &vectors, const std::string &label="Vectors")
insert new vector data array
Definition lsPointData.hpp:74
std::istream & deserialize(std::istream &stream)
Deserialize PointData from a binary stream.
Definition lsPointData.hpp:385
void eraseVectorData(int index)
Delete the vector data at index.
Definition lsPointData.hpp:246
#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:37