View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

vec.h
Go to the documentation of this file.
1#ifndef VEC_H
2#define VEC_H
3#include "index.h"
4#include "dimensions.h"
5#include "object.h"
6#include "vector.h"
7#include "database.h"
8#include "shmvector.h"
9
10namespace vistle {
11
12template<typename T, int Dim = 1>
13class Vec: public DataBase {
14 V_OBJECT(Vec);
15
16 static const int MaxDim = MaxDimension;
17 static_assert(Dim > 0, "only positive Dim allowed");
18 static_assert(Dim <= MaxDim, "Dim too large");
19
20public:
21 typedef DataBase Base;
22 typedef typename shm<T>::array array;
23 typedef T Scalar;
25
26 Vec(const Index size, const Meta &meta = Meta());
27
28 Index getSize() override { return d()->x[0]->size(); }
29 Index getSize() const override { return m_size; }
30
31 int dimension() const override { return Dim; }
32
33 bool copyEntry(Index to, DataBase::const_ptr src, Index from) override;
34 void setValue(Index idx, int component, const double &value) override;
35 double value(Index idx, int c = 0) const override;
36
37 void resetArrays() override;
38 void setSize(const Index size) override;
39 void applyDimensionHint(Object::const_ptr grid) override;
40 void setExact(bool exact) override;
41
42 array &x(int c = 0) { return *d()->x[c]; }
44 {
45 assert(Dim > 1);
46 return Dim > 1 ? *d()->x[1] : x();
47 }
49 {
50 assert(Dim > 2);
51 return Dim > 2 ? *d()->x[2] : x();
52 }
54 {
55 assert(Dim > 3);
56 return Dim > 3 ? *d()->x[3] : x();
57 }
58
59 const T *x(int c = 0) const { return m_x[c]; }
60 const T *y() const
61 {
62 assert(Dim > 1);
63 return Dim > 1 ? m_x[1] : x();
64 }
65 const T *z() const
66 {
67 assert(Dim > 2);
68 return Dim > 2 ? m_x[2] : x();
69 }
70 const T *w() const
71 {
72 assert(Dim > 3);
73 return Dim > 3 ? m_x[3] : x();
74 }
75
76 void updateInternals() override;
77 std::pair<Vector, Vector> getMinMax() const;
78
79private:
80 mutable const T *m_x[MaxDim];
81 mutable Index m_size;
82
83public:
84 struct Data: public Base::Data {
88 // when used as Vec
89 Data(const Index size = 0, const std::string &name = "", const Meta &meta = Meta());
90 // when used as base of another data structure
91 Data(const Index size, Type id, const std::string &name, const Meta &meta = Meta());
92 Data(const Data &other, const std::string &name, Type id = UNKNOWN);
93 Data(Object::Type id, const std::string &name, const Meta &meta);
94 static Data *create(Index size = 0, const Meta &meta = Meta());
95 static Data *createNamed(Object::Type id, const std::string &name, const Meta &meta = Meta());
96
97 protected:
98 void setExact(bool exact);
99
100 private:
101 friend class Vec;
103 template<class Archive>
104 void serialize(Archive &ar);
105 void initData();
106 void updateBounds();
107 void invalidateBounds();
108 bool boundsValid() const;
109 };
110};
111
112#define V_VEC_COMMA ,
113#define V_VEC_TEMPLATE(ValueType) \
114 extern template class V_COREEXPORT Vec<ValueType, 1>; \
115 V_OBJECT_DECL(Vec<ValueType V_VEC_COMMA 1>) \
116 extern template class V_COREEXPORT Vec<ValueType, 2>; \
117 V_OBJECT_DECL(Vec<ValueType V_VEC_COMMA 2>) \
118 extern template class V_COREEXPORT Vec<ValueType, 3>; \
119 V_OBJECT_DECL(Vec<ValueType V_VEC_COMMA 3>) \
120 /* extern template class V_COREEXPORT Vec<ValueType,4>; \
121 V_OBJECT_DECL(Vec<ValueType V_VEC_COMMA 4>) */
122V_VEC_TEMPLATE(char)
123V_VEC_TEMPLATE(signed char)
124V_VEC_TEMPLATE(unsigned char)
125V_VEC_TEMPLATE(int32_t)
126V_VEC_TEMPLATE(uint32_t)
127V_VEC_TEMPLATE(int64_t)
128V_VEC_TEMPLATE(uint64_t)
129V_VEC_TEMPLATE(float)
130V_VEC_TEMPLATE(double)
131#undef V_VEC_TEMPLATE
132#undef V_VEC_COMMA
133
134} // namespace vistle
135#endif
#define ARCHIVE_ACCESS
Definition: archives_config.h:465
Definition: database.h:14
Definition: objectmeta.h:16
std::shared_ptr< const Object > const_ptr
Definition: object.h:68
Data * d() const
Definition: object.h:211
const Meta & meta() const
Definition: object.cpp:390
Type
Definition: object.h:84
@ UNKNOWN
Definition: object.h:89
Definition: vec.h:13
void setValue(Index idx, int component, const double &value) override
Definition: vec_template.h:70
Index getSize() override
Definition: vec.h:28
bool copyEntry(Index to, DataBase::const_ptr src, Index from) override
Definition: vec_template.h:56
const T * w() const
Definition: vec.h:70
void applyDimensionHint(Object::const_ptr grid) override
Definition: vec_template.h:86
int dimension() const override
Definition: vec.h:31
array & w()
Definition: vec.h:53
double value(Index idx, int c=0) const override
Definition: vec_template.h:78
void updateInternals() override
Definition: vec_template.h:154
shm< T >::array array
Definition: vec.h:22
array & y()
Definition: vec.h:43
Vec(const Index size, const Meta &meta=Meta())
Definition: vec_template.h:15
VistleVector< Scalar, Dim > Vector
Definition: vec.h:24
const T * z() const
Definition: vec.h:65
void resetArrays() override
Definition: vec_template.h:33
array & z()
Definition: vec.h:48
T Scalar
Definition: vec.h:23
array & x(int c=0)
Definition: vec.h:42
void setSize(const Index size) override
Definition: vec_template.h:43
DataBase Base
Definition: vec.h:17
void setExact(bool exact) override
Definition: vec_template.h:106
std::pair< Vector, Vector > getMinMax() const
Definition: vec_template.h:161
const T * y() const
Definition: vec.h:60
Index getSize() const override
Definition: vec.h:29
const T * x(int c=0) const
Definition: vec.h:59
Definition: shm_reference.h:15
Definition: shm_array.h:19
void serialize(Archive &ar, vistle::Vector1 &v, const unsigned int version)
Definition: vector.h:105
Definition: allobjects.cpp:30
Eigen::Matrix< T, d, 1 > VistleVector
Definition: vector.h:18
const int MaxDimension
Definition: dimensions.h:11
uint32_t Index
Definition: index.h:13
Definition: object.h:233
Meta meta
Definition: object.h:238
const shm_name_t name
Definition: shmdata.h:41
Definition: vec.h:84
static Data * createNamed(Object::Type id, const std::string &name, const Meta &meta=Meta())
Definition: vec_template.h:291
Vector min
Definition: vec.h:85
static Data * create(Index size=0, const Meta &meta=Meta())
Definition: vec_template.h:272
Data(const Index size=0, const std::string &name="", const Meta &meta=Meta())
Definition: vec_template.h:234
ShmVector< T > x[Dim]
Definition: vec.h:87
void setExact(bool exact)
Definition: vec_template.h:226
Vector max
Definition: vec.h:86
#define V_VEC_TEMPLATE(ValueType)
Definition: vec.h:113