View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

paramvector.h
Go to the documentation of this file.
1#ifndef PARAMVECTOR_H
2#define PARAMVECTOR_H
3
6#include <ostream>
7#include <vector>
8#include <cassert>
10#include "scalar.h"
11#include "dimensions.h"
12#include "vector.h"
13#include "export.h"
14
15namespace vistle {
16
17template<typename S>
19public:
20 typedef S Scalar;
22
23 ParameterVector(const int dim, const S values[]);
24 template<int Dim>
26 ParameterVector(const S x, const S y, const S z, const S w);
27 ParameterVector(const S x, const S y, const S z);
28 ParameterVector(const S x, const S y);
29 ParameterVector(const S x);
31 ParameterVector(const ParameterVector &other);
32
34
35 static ParameterVector min(int dim = MaxDimension);
36 static ParameterVector max(int dim = MaxDimension);
37
38 int dim;
39 std::vector<S> v;
40 std::vector<S> m_min, m_max;
41 S &x, &y, &z, &w;
42
43 S *data() { return v.data(); }
44 const S *data() const { return v.data(); }
45
46 S &operator[](int i) { return v[i]; }
47 const S &operator[](int i) const { return v[i]; }
48
49 operator S *() { return v.data(); }
50 operator const S *() const { return v.data(); }
51
52 operator S &()
53 {
54 assert(dim == 1);
55 return v[0];
56 }
57 operator S() const
58 {
59 assert(dim == 1);
60 return dim > 0 ? v[0] : S();
61 }
62
63 operator Vector1() const
64 {
65 assert(dim == 1);
66 return dim >= 1 ? Vector1(v[0]) : Vector1(0.);
67 }
68 operator Vector2() const
69 {
70 assert(dim == 2);
71 return dim >= 2 ? Vector2(v[0], v[1]) : Vector2(0., 0.);
72 }
73 operator Vector3() const
74 {
75 assert(dim == 3);
76 return dim >= 3 ? Vector3(v[0], v[1], v[2]) : Vector3(0., 0., 0.);
77 }
78 operator Vector4() const
79 {
80 assert(dim == 4);
81 return dim >= 4 ? Vector4(v[0], v[1], v[2], v[3]) : Vector4(0., 0., 0., 0.);
82 }
83
84 std::string str() const;
85
86public:
87 // for vector_indexing_suite
89 typedef size_t size_type;
90 typedef size_t index_type;
91 typedef ssize_t difference_type;
92 bool empty() const { return dim == 0; }
93 void clear() const { throw vistle::exception("not supported"); }
94 size_t size() const { return dim; }
95 typedef typename std::vector<S>::iterator iterator;
96 typedef typename std::vector<S>::const_iterator const_iterator;
98 {
100 v.erase(s);
101 }
103 {
105 v.erase(s, e);
106 }
107 iterator begin() { return v.begin(); }
108 const_iterator begin() const { return v.begin(); }
109 iterator end() { return v.begin() + dim; }
110 const_iterator end() const { return v.begin() + dim; }
111 void insert(iterator pos, const S &value)
112 {
114 v.insert(pos, value);
115 }
116 template<class InputIt>
117 void insert(iterator pos, InputIt first, InputIt last)
118 {
120 v.insert(pos, first, last);
121 }
123 void push_back(const S &value)
124 {
125 if (dim >= MaxDimension) {
126 throw vistle::exception("out of range");
127 }
128 v[dim] = value;
129 ++dim;
130 }
132 {
133 if (dim <= 0) {
134 throw vistle::exception("out of range");
135 }
136 return v[0];
137 }
138 const Scalar &back() const
139 {
140 if (dim <= 0) {
141 throw vistle::exception("out of range");
142 }
143 return v[0];
144 }
145 void pop_back()
146 {
147 if (dim <= 0) {
148 throw vistle::exception("out of range");
149 }
150 --dim;
151 }
152 void reserve(size_t dim)
153 {
154 if (dim >= MaxDimension) {
155 throw vistle::exception("out of range");
156 }
157 }
159 {
160 // nothing to do
161 }
162};
163
164template<typename S>
165bool operator==(const ParameterVector<S> &v1, const ParameterVector<S> &v2);
166template<typename S>
167bool operator!=(const ParameterVector<S> &v1, const ParameterVector<S> &v2);
168
169template<typename S>
170bool operator<(const ParameterVector<S> &v1, const ParameterVector<S> &v2);
171template<typename S>
172bool operator>(const ParameterVector<S> &v1, const ParameterVector<S> &v2);
173
174template<typename S>
175std::ostream &operator<<(std::ostream &out, const ParameterVector<S> &v);
176
177#define V_DECLARE_PARAMVEC(S) \
178 extern template class V_COREEXPORT ParameterVector<S>; \
179 extern template V_COREEXPORT bool operator==(const ParameterVector<S> &v1, const ParameterVector<S> &v2); \
180 extern template V_COREEXPORT bool operator!=(const ParameterVector<S> &v1, const ParameterVector<S> &v2); \
181 extern template V_COREEXPORT bool operator<(const ParameterVector<S> &v1, const ParameterVector<S> &v2); \
182 extern template V_COREEXPORT bool operator>(const ParameterVector<S> &v1, const ParameterVector<S> &v2); \
183 extern template V_COREEXPORT std::ostream &operator<<(std::ostream &out, const ParameterVector<S> &v);
184
189
190} // namespace vistle
191
192#endif // PARAMVECTOR_H
Definition: paramvector.h:18
iterator end()
Definition: paramvector.h:109
ParameterVector(iterator begin, iterator end)
std::vector< S >::iterator iterator
Definition: paramvector.h:95
ParameterVector()
Definition: paramvector_impl.h:76
void push_back(const S &value)
Definition: paramvector.h:123
const S * data() const
Definition: paramvector.h:44
void insert(iterator pos, const S &value)
Definition: paramvector.h:111
int dim
Definition: paramvector.h:38
const_iterator end() const
Definition: paramvector.h:110
void insert(iterator pos, InputIt first, InputIt last)
Definition: paramvector.h:117
std::vector< S > m_max
Definition: paramvector.h:40
std::vector< S > m_min
Definition: paramvector.h:40
static ParameterVector max(int dim=MaxDimension)
Definition: paramvector_impl.h:122
const S & operator[](int i) const
Definition: paramvector.h:47
Scalar & back()
Definition: paramvector.h:131
ParameterVector & operator=(const ParameterVector &rhs)
Definition: paramvector_impl.h:89
size_t index_type
Definition: paramvector.h:90
size_t size() const
Definition: paramvector.h:94
void shrink_to_fit()
Definition: paramvector.h:158
S * data()
Definition: paramvector.h:43
size_t size_type
Definition: paramvector.h:89
std::vector< S >::const_iterator const_iterator
Definition: paramvector.h:96
bool empty() const
Definition: paramvector.h:92
ssize_t difference_type
Definition: paramvector.h:91
static const int MaxDimension
Definition: paramvector.h:21
void erase(iterator s)
Definition: paramvector.h:97
void erase(iterator s, iterator e)
Definition: paramvector.h:102
void clear() const
Definition: paramvector.h:93
Scalar value_type
Definition: paramvector.h:88
S & w
Definition: paramvector.h:41
S & operator[](int i)
Definition: paramvector.h:46
std::vector< S > v
Definition: paramvector.h:39
const Scalar & back() const
Definition: paramvector.h:138
S & y
Definition: paramvector.h:41
static ParameterVector min(int dim=MaxDimension)
Definition: paramvector_impl.h:113
iterator begin()
Definition: paramvector.h:107
const_iterator begin() const
Definition: paramvector.h:108
std::string str() const
Definition: paramvector_impl.h:219
S & z
Definition: paramvector.h:41
S & x
Definition: paramvector.h:41
S Scalar
Definition: paramvector.h:20
void pop_back()
Definition: paramvector.h:145
void reserve(size_t dim)
Definition: paramvector.h:152
Definition: exception.h:13
Definition: exception.h:30
Definition: allobjects.cpp:30
bool operator!=(const ParameterVector< S > &v1, const ParameterVector< S > &v2)
Definition: paramvector_impl.h:237
Eigen::Matrix< Scalar, 3, 1 > Vector3
Definition: vector.h:33
double Float
Definition: scalar.h:18
const int MaxDimension
Definition: dimensions.h:11
std::ostream & operator<<(std::ostream &out, const Meta &meta)
Definition: objectmeta.cpp:45
bool operator<(const ParameterVector< S > &v1, const ParameterVector< S > &v2)
Definition: paramvector_impl.h:243
bool operator>(const ParameterVector< S > &v1, const ParameterVector< S > &v2)
Definition: paramvector_impl.h:256
VistleVector< Scalar, d > ScalarVector
Definition: vector.h:20
bool operator==(const ParameterVector< S > &v1, const ParameterVector< S > &v2)
Definition: paramvector_impl.h:225
Eigen::Matrix< Scalar, 4, 1 > Vector4
Definition: vector.h:34
int64_t Integer
Definition: scalar.h:19
Eigen::Matrix< Scalar, 1, 1 > Vector1
Definition: vector.h:31
Eigen::Matrix< Scalar, 2, 1 > Vector2
Definition: vector.h:32
#define V_DECLARE_PARAMVEC(S)
Definition: paramvector.h:177