View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

paramvector_impl.h
Go to the documentation of this file.
1#ifndef VECTOR_IMPL_H
2#define VECTOR_IMPL_H
3
4#include <cassert>
5#include <cstring>
6#include <limits>
7#include <boost/lexical_cast.hpp>
8
9namespace vistle {
10
11static_assert(MaxDimension >= 4, "ParameterVector does not support more than 4 arrays");
12
13#define VINIT(d) dim(d), v(MaxDimension), x(v[0]), y(v[1]), z(v[2]), w(v[3])
14
15template<typename S>
16ParameterVector<S>::ParameterVector(const int dim, const S values[]): VINIT(dim)
17{
18 assert(dim <= MaxDimension);
19 for (int i = 0; i < dim; ++i)
20 v[i] = values[i];
21 for (int i = dim; i < MaxDimension; ++i)
22 v[i] = S();
23}
24
25template<typename S>
26ParameterVector<S>::ParameterVector(const S _x, const S _y, const S _z, const S _w): VINIT(4)
27{
28 v[0] = _x;
29 v[1] = _y;
30 v[2] = _z;
31 v[3] = _w;
32 for (int i = 4; i < MaxDimension; ++i)
33 v[i] = S();
34}
35
36template<typename S>
37template<int Dim>
39{
40 static_assert(MaxDimension >= Dim, "Dim too large for ParameterVector");
41
42 for (int i = 0; i < Dim; ++i)
43 v[i] = _v[i];
44 for (int i = Dim; i < MaxDimension; ++i)
45 v[i] = S();
46}
47
48template<typename S>
49ParameterVector<S>::ParameterVector(const S _x, const S _y, const S _z): VINIT(3)
50{
51 v[0] = _x;
52 v[1] = _y;
53 v[2] = _z;
54 for (int i = 3; i < MaxDimension; ++i)
55 v[i] = S();
56}
57
58template<typename S>
59ParameterVector<S>::ParameterVector(const S _x, const S _y): VINIT(2)
60{
61 v[0] = _x;
62 v[1] = _y;
63 for (int i = 2; i < MaxDimension; ++i)
64 v[i] = S();
65}
66
67template<typename S>
69{
70 v[0] = _x;
71 for (int i = 1; i < MaxDimension; ++i)
72 v[i] = S();
73}
74
75template<typename S>
77{
78 for (int i = 0; i < MaxDimension; ++i)
79 v[i] = S();
80}
81
82template<typename S>
84{
85 memcpy(&v[0], &o.v[0], sizeof(v[0]) * MaxDimension);
86}
87
88template<typename S>
90{
91 if (this != &rhs) {
92 dim = rhs.dim;
93 memcpy(&v[0], &rhs.v[0], sizeof(v[0]) * MaxDimension);
94 }
95
96 return *this;
97}
98
99template<typename S>
103{
104 dim = 0;
105 for (iterator it = from; it != to; ++it) {
106 v[dim] = *it;
107 ++dim;
108 }
109}
110#undef VINIT
111
112template<typename S>
114{
115 S v[MaxDimension];
116 for (int i = 0; i < MaxDimension; ++i)
117 v[i] = std::numeric_limits<S>::lowest();
118 return ParameterVector<S>(dim, v);
119}
120
121template<typename S>
123{
124 S v[MaxDimension];
125 for (int i = 0; i < MaxDimension; ++i)
126 v[i] = std::numeric_limits<S>::max();
127 return ParameterVector<S>(dim, v);
128}
129#if 0
130template<typename S>
132
133 ParameterVector result(*this);
134 for (int i=0; i<dim; ++i)
135 result[i] = -result[i];
136 return result;
137}
138
139template<typename S>
140ParameterVector<S> ParameterVector<S>::operator*(S const &rhs) const {
141
142 ParameterVector result(*this);
143 for (int i=0; i<dim; ++i)
144 result[i] *= rhs;
145 return result;
146}
147
148template<typename S>
149ParameterVector<S> ParameterVector<S>::operator+(ParameterVector<S> const &rhs) const {
150
151 ParameterVector result(*this);
152 for (int i=0; i<dim; ++i)
153 result[i] += rhs[i];
154 return result;
155}
156
157template<typename S>
158ParameterVector<S> ParameterVector<S>::operator-(ParameterVector const &rhs) const {
159
160 ParameterVector result(*this);
161 for (int i=0; i<dim; ++i)
162 result[i] -= rhs[i];
163 return result;
164}
165
166template<typename S>
167S ParameterVector<S>::operator *(ParameterVector const & rhs) const {
168
169 S result = S();
170 for (int i=0; i<dim; ++i)
171 result += v[i] * rhs[i];
172 return result;
173}
174#endif
175
176#if 0
177template<typename S>
178void ParameterVector<S>::setMinimum(const S x, const S y, const S z, const S w) {
179 m_min[0] = x;
180 m_min[1] = y;
181 m_min[2] = z;
182 m_min[3] = w;
183}
184
185template<typename S>
186void ParameterVector<S>::setMinimum(const S *v) {
187 for (int i=0; i<dim; ++i)
188 m_min[i] = v[i];
189}
190
191template<typename S>
192ParameterVector<S> ParameterVector<S>::minimum() const {
193
194 return ParameterVector(dim, &m_min[0]);
195}
196
197template<typename S>
198void ParameterVector<S>::setMaximum(const S x, const S y, const S z, const S w) {
199 m_max[0] = x;
200 m_max[1] = y;
201 m_max[2] = z;
202 m_max[3] = w;
203}
204
205template<typename S>
206void ParameterVector<S>::setMaximum(const S *v) {
207 for (int i=0; i<dim; ++i)
208 m_max[i] = v[i];
209}
210
211template<typename S>
212ParameterVector<S> ParameterVector<S>::maximum() const {
213
214 return ParameterVector(dim, &m_max[0]);
215}
216#endif
217
218template<typename S>
219std::string ParameterVector<S>::str() const
220{
221 return boost::lexical_cast<std::string>(*this);
222}
223
224template<typename S>
226{
227 if (v1.dim != v2.dim)
228 return false;
229 for (int i = 0; i < v1.dim; ++i)
230 if (v1[i] != v2[i])
231 return false;
232
233 return true;
234}
235
236template<typename S>
238{
239 return !(v1 == v2);
240}
241
242template<typename S>
244{
245 for (int i = 0; i < v1.dim && i < v2.dim; ++i) {
246 if (v1[i] > v2[i])
247 return false;
248 if (v1[i] < v2[i])
249 return true;
250 }
251
252 return v1.dim < v2.dim;
253}
254
255template<typename S>
257{
258 for (int i = 0; i < v1.dim && i < v2.dim; ++i) {
259 if (v1[i] < v2[i])
260 return false;
261 if (v1[i] > v2[i])
262 return true;
263 }
264
265 return v1.dim > v2.dim;
266}
267
268template<typename S>
269std::ostream &operator<<(std::ostream &out, const ParameterVector<S> &v)
270{
271 out << "(";
272 for (int i = 0; i < v.dim; ++i) {
273 if (i > 0)
274 out << " ";
275 out << v[i];
276 }
277 out << ")";
278 return out;
279}
280
281} // namespace vistle
282#endif
Definition: paramvector.h:18
std::vector< S >::iterator iterator
Definition: paramvector.h:95
ParameterVector()
Definition: paramvector_impl.h:76
int dim
Definition: paramvector.h:38
static ParameterVector max(int dim=MaxDimension)
Definition: paramvector_impl.h:122
ParameterVector & operator=(const ParameterVector &rhs)
Definition: paramvector_impl.h:89
static const int MaxDimension
Definition: paramvector.h:21
std::vector< S > v
Definition: paramvector.h:39
static ParameterVector min(int dim=MaxDimension)
Definition: paramvector_impl.h:113
std::string str() const
Definition: paramvector_impl.h:219
Definition: allobjects.cpp:30
std::string operator+(const std::string &s, const shm_name_t &n)
Definition: shmname.cpp:58
bool operator!=(const ParameterVector< S > &v1, const ParameterVector< S > &v2)
Definition: paramvector_impl.h:237
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
#define VINIT(d)
Definition: paramvector_impl.h:13