FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
VVector.hpp
1//
2// $Id: VVector.hpp,v 1.8 2007/03/06 23:01:17 werner Exp $
3//
4// $Log: VVector.hpp,v $
5// Revision 1.8 2007/03/06 23:01:17 werner
6// Integration of the Vector library into the Eagle library, for the sake
7// of type registration.
8//
9// Revision 1.7 2007/02/22 17:08:43 werner
10// A major revision of the vector/fixed array interface, unifying three independent
11// libraries into one. The vecal (Vector Algebra), fish/vector (Multidimensional
12// vector arrays) and the Eagle library (Geometric Algebra) thus share a common
13// root now.
14//
15// Revision 1.6 2006/08/29 04:23:36 werner
16// 64 bit long long support
17//
18// Revision 1.5 2006/08/05 20:41:03 werner
19// better doc
20//
21// Revision 1.4 2006/07/02 22:07:30 werner
22// Revision and improvements of the vector/matrix interface, and improvment
23// of the examples and self-check.
24//
25// Revision 1.3 2006/05/26 03:03:12 werner
26// Iterator part finished
27//
28// Revision 1.2 2006/05/24 13:38:03 werner
29// better docu, Vector docu does not work...
30//
31// Revision 1.1 2006/05/20 18:04:12 werner
32// Matrix operations embedded and documented
33//
34// Revision 1.23 2004/11/22 14:54:20 werner
35// Added generic interpolator interface and activated HDF5 reading.
36//
37// Revision 1.22 2004/10/20 20:01:11 werner
38// moving towards windows
39//
40// Revision 1.21 2004/10/05 11:58:54 werner
41// Documentation improvements
42//
43// Revision 1.20 2004/08/25 16:57:33 werner
44// Adjustments for SGI
45//
46// Revision 1.19 2004/08/24 09:09:05 werner
47// Towards VC7
48//
49// Revision 1.18 2004/08/17 16:59:52 werner
50// Towards compilation with gcc 3.3.3
51//
52// Revision 1.17 2004/08/12 16:08:45 werner
53// Various improvements for implementing the tangential space
54//
55// Revision 1.16 2004/07/14 15:45:14 werner
56// Outsourcing of quadratic matrices into its own header file.
57// Added great gaus decomposition from Marcus Weber that allows
58// multiple right-hand sides.
59//
60// Revision 1.15 2004/07/12 10:30:44 werner
61// Minor docu adjustmens.
62//
63// Revision 1.14 2004/07/06 17:16:05 werner
64// Added docu.
65//
66// Revision 1.13 2004/05/13 16:40:06 werner
67// Adjusted iostream interface for IRIX.
68//
69// Revision 1.12 2004/05/13 10:48:44 werner
70// Bug fixes on template argument forwarding.
71//
72// Revision 1.11 2004/05/12 16:05:23 werner
73// Basic library ported to SGI C++.
74//
75// Revision 1.10 2004/05/11 17:56:10 werner
76// *** empty log message ***
77//
78// Revision 1.9 2004/05/03 13:33:33 werner
79// integration improved
80//
81// Revision 1.8 2004/04/26 13:44:05 werner
82// Added const member function on arrays, and minor documentation cleanup.
83//
84// Revision 1.7 2004/03/30 13:43:10 werner
85// Adjusted to Linux environment.
86//
87// Revision 1.6 2004/03/30 13:16:16 werner
88// Spin Interface!
89//
90// Revision 1.5 2004/03/29 15:23:58 werner
91// Adjusted to SGI.
92//
93// Revision 1.4 2004/03/26 13:35:35 werner
94// Improved documentation.
95//
96// Revision 1.3 2004/03/24 13:22:33 werner
97// Scalar constructor added, and inner/outer product of quaternions.
98//
99// Revision 1.2 2004/03/22 11:38:13 werner
100// Improvements and Bugfixes, better conversion functions and operators.
101//
102// Revision 1.1 2004/03/11 18:23:48 werner
103// Fixed the Intel CPU vectorization/alignment issue.
104// Vectorization is now done through the explicit VVector<> class, which splits up
105// a sequence of types into a vectorizable Vector<> and a remainder.
106// As the vectorizable component is based on native SIMD types, they get
107// correctly 16-byte aligned, which is all what we want.
108//
110#ifndef __FIBER_VVector_HPP
111#define __FIBER_VVector_HPP "Created 27.02.2001 21:42:27 by werner"
112
113#include <eagle/Vector.hpp>
114
115namespace Eagle
116{
117//using namespace std;
118typedef Eagle::Mult Mult;
119typedef Eagle::Div Div;
120typedef Eagle::Add Add;
121typedef Eagle::Sub Sub;
122
129template <class FirstVector, class SecondVector, class value>
131{
132 FirstVector first;
133 SecondVector second;
134public:
137 {}
138
141 : first( V.first)
142 , second(V.second)
143 {}
144
145
147
149 VectorPair(const VectorPair&A, const value&V, const Mult&)
150 : first (A. first, V, Mult())
151 , second(A.second, V, Mult())
152 {}
153
155 VectorPair(const VectorPair&A, const value&V, const Div&)
156 : first (A. first, V, Div())
157 , second(A.second, V, Div())
158 {}
159
161 VectorPair(const VectorPair&L, const VectorPair&R, const Add&)
162 : first (L.first , R.first , Add())
163 , second(L.second, R.second, Add())
164 {}
165
167 VectorPair(const VectorPair&L, const VectorPair&R, const Sub&)
168 : first (L.first , R.first , Sub())
169 , second(L.second, R.second, Sub())
170 {}
171
173 VectorPair(const VectorPair&L, const Sub&)
174 : first (L.first , Sub())
175 , second(L.second, Sub())
176 {}
178
179
181
184 {
185 first += A.first;
186 second += A.second;
187 return *this;
188 }
189
192 {
193 first -= A.first;
194 second -= A.second;
195 return *this;
196 }
197
199 VectorPair&operator*=(const value&v)
200 {
201 first *= v;
202 second *= v;
203 return *this;
204 }
205
207 VectorPair&operator/=(const value&v)
208 {
209 first /= v;
210 second /= v;
211 return *this;
212 }
214
216 friend value InnerProduct(const VectorPair&A, const VectorPair&B)
217 {
218 return InnerProduct(A.first, B.first) +
219 InnerProduct(A.second, B.second);
220 }
221};
222
223
224template <int VN, class Vvalue, int N, class value>
226{
227public:
229};
230
231template <class Vvalue, int N, class value>
232class MixedVector<0, Vvalue, N, value>
233{
234public:
236};
237
238template <int VN, class Vvalue, class value>
239class MixedVector<VN, Vvalue, 0, value>
240{
241public:
243};
244
245//using Eagle::VectorizationTrait;
246
255template <int A, int B>
257{
258 enum { result = A/B };
259};
260
283template <int N, class value>
284 class ALIGN16 VVector : public MixedVector< GrandMacOsGCCDivisionCalculator<N,VectorizationTrait<value>::N>::result,
285 typename VectorizationTrait<value>::vectorized_t,
286 N%VectorizationTrait<value>::N,
287 value>::result
288{
289public:
298 value >::result MixedVector_t;
299
302
305
307 typedef value value_type;
308
311 {}
312
314 void set(const value&s)
315 {
316 vec().set(s);
317 }
318
321 : MixedVector_t(V)
322 {}
323
325 template <class T>
326 explicit VVector(const Eagle::Vector<T, N>&V)
327 {
328 value*v = ptr(0);
329 for(int i=0; i<N; i++)
330 v[i] = value(V[i]);
331 }
332
336 template <class T>
337 explicit VVector(const VVector<N, T>&V)
338 {
339 value*v = ptr(0);
340 for(int i=0; i<N; i++)
341 v[i] = value(V[i]);
342 }
343
345 explicit VVector(const MixedVector_t&MV)
346 : MixedVector_t(MV)
347 {}
348
350
352 const Vector_t&vec() const
353 {
354 return *reinterpret_cast<const Vector_t*>(this);
355 }
356
359 {
360 return *reinterpret_cast<Vector_t*>(this);
361 }
362
364 const VVector&vvec() const
365 {
366 return *this;
367 }
368
371 {
372 return *this;
373 }
374
376 value&operator[](int i)
377 { return vec()[i]; }
378
380 const value&operator[](int i) const
381 { return vec()[i]; }
382
383
385 value* ptr(int i=0)
386 {
387 return vec().ptr(i);
388 }
389
391 const value*ptr(int i=0) const
392 {
393 return vec().ptr(i);
394 }
395
397 const value*const_ptr(int i=0) const
398 {
399 return vec().const_ptr(i);
400 }
402
404
405 VVector(const VVector&A, const value&V, const Mult&)
406 : MixedVector_t(A, Mult(), V)
407 {}
408
409 VVector(const VVector&A, const value&V, const Div&)
410 : MixedVector_t(A,V, Div())
411 {}
412
413 VVector(const VVector&L, const VVector&R, const Add&)
414 : MixedVector_t(L,R, Add())
415 {}
416
417 VVector(const VVector&L, const VVector&R, const Sub&)
418 : MixedVector_t(L,R, Sub())
419 {}
420
421 VVector(const VVector&L, const Sub&)
422 : MixedVector_t(L, Sub())
423 {}
425
426
428
431 {
432 MixedVector_t::operator+=(V);
433 return *this;
434 }
435
438 {
439 MixedVector_t::operator-=(V);
440 return *this;
441 }
442
444 VVector&operator*=(const value&v)
445 {
446 MixedVector_t::operator*=(v);
447 return *this;
448 }
449
451 VVector&operator/=(const value&v)
452 {
453 MixedVector_t::operator/=(v);
454 return *this;
455 }
457
458
460
462 friend VVector operator*(const VVector&A, const value&V)
463 {
464 return VVector(A, V, Mult() );
465 }
466
468 friend VVector operator*(const value&V, const VVector&A)
469 {
470 return VVector(A, V, Mult() );
471 }
472
474 friend VVector operator/(const VVector&A, const value&V)
475 {
476 return VVector(A, V, Div() );
477 }
478
480 friend VVector operator+(const VVector&A, const VVector&B)
481 {
482 return VVector(A, B, Add() );
483 }
484
486 friend VVector operator-(const VVector&A, const VVector&B)
487 {
488 return VVector(A, B, Sub() );
489 }
490
492
493
496 {
497 // we need to perform this operation on the elementary type,
498 // since the vectorization cannot be used here
499 return Eagle::Assignment<Vector_t, 0>( vec(), x);
500 }
501};
502
503//} __attribute__ ((aligned (16)));;
504
505template <int N, class T>
506 struct MetaInfo<VVector<N, T> > : MetaInfo<Vector<T, N> >
507{
511
512static const T&getComponent(const FixedArray<T,N>&F, int i)
513 {
514 return F[i];
515 }
516};
517
518
520template <int N, class value>
521inline VVector<N, value> operator*(const VVector<N, value>&A, double V)
522{
523 return VVector<N, value>(A, V, Mult() );
524}
525
527template <int N, class value>
528inline VVector<N, value> operator/(const VVector<N, value>&A, double V)
529{
530 return VVector<N, value>(A, V, Div() );
531}
532
533
534
536template <int N, class value>
537inline value norm2(const VVector<N,value>&A)
538{
539 return InnerProduct(A, A);
540}
541
543template <int N, class value>
544inline value norm(const VVector<N,value>&A)
545{
546 return sqrt(norm2(A) );
547}
548
549
550// MSVC GCC G++ SGI C++
551#if defined(_IOSTREAM_) || defined(_GLIBCXX_OSTREAM) || _CPP_IOSTREAM || defined(__SGI_STL_IOSTREAM) || defined(__clang__)
552
553template <int N, class value>
554std::ostream&operator<<(std::ostream&os, const VVector<N, value>&VV)
555{
556const Eagle::Vector<value,N>&A = VV.vec();
557 os << '(';
558 for(int i=0; i<N-1; i++)
559 os << A[i] << ',';
560 os << A[N-1] << ')';
561 return os;
562}
563
564#endif
565
566} /* namespace Eagle */
567
569template <int N, class value>
571{
573}
574
575
576#endif /* __FIBER_VVector_HPP */
577
578
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator/(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
complex< _Tp > sqrt(const complex< _Tp > &)
basic_ostream< char > ostream
Definition VVector.hpp:226
Vectorized vector.
Definition VVector.hpp:288
VVector(const VVector< N, T > &V)
Construct vectorized vector from another vectorized vector of another type.
Definition VVector.hpp:337
VVector(const VVector &V)
Copy constructor.
Definition VVector.hpp:320
const Vector_t & vec() const
Access the vectorized vector as an usual vector.
Definition VVector.hpp:352
friend VVector operator/(const VVector &A, const value &V)
Vector / Scalar.
Definition VVector.hpp:474
VVector & operator-=(const VVector &V)
Vector -= Vector.
Definition VVector.hpp:437
VVector & operator*=(const value &v)
Vector *= scalar.
Definition VVector.hpp:444
VVector(const MixedVector_t &MV)
Upcast constructor.
Definition VVector.hpp:345
Eagle::Vector< value, N > Vector_t
The corresponding unvectorized vector type.
Definition VVector.hpp:301
VVector VVector_t
The vectorized vector type.
Definition VVector.hpp:304
Eagle::Assignment< Vector_t, 0 > operator=(const value &x)
Allow assignment per comma operator.
Definition VVector.hpp:495
Vector_t & vec()
Access the vectorized vector as an usual vector.
Definition VVector.hpp:358
value & operator[](int i)
Array operator.
Definition VVector.hpp:376
value value_type
The element type.
Definition VVector.hpp:307
const value & operator[](int i) const
Array operator.
Definition VVector.hpp:380
friend VVector operator-(const VVector &A, const VVector &B)
Vector - Vector.
Definition VVector.hpp:486
void set(const value &s)
Set with all vector elements set to the same scalar value.
Definition VVector.hpp:314
friend VVector operator*(const VVector &A, const value &V)
Vector * Scalar.
Definition VVector.hpp:462
MixedVector< GrandMacOsGCCDivisionCalculator< N, VectorizationTrait< value >::N >::result, typenameVectorizationTrait< value >::vectorized_t, N%VectorizationTrait< value >::N, value >::result MixedVector_t
The result of mixing an aligned vector with an unaligned vector.
Definition VVector.hpp:298
const VVector & vvec() const
Return the type itself. Useful for base class access in derived classes.
Definition VVector.hpp:364
VVector & vvec()
Return the type itself. Useful for base class access in derived classes.
Definition VVector.hpp:370
VVector(const Eagle::Vector< T, N > &V)
Construct vectorized vector from usual vector of another type.
Definition VVector.hpp:326
VVector & operator+=(const VVector &V)
Vector += Vector.
Definition VVector.hpp:430
const value * const_ptr(int i=0) const
get actual data storage
Definition VVector.hpp:397
value * ptr(int i=0)
get actual data storage
Definition VVector.hpp:385
const value * ptr(int i=0) const
get actual data storage
Definition VVector.hpp:391
VVector & operator/=(const value &v)
Vector /= scalar.
Definition VVector.hpp:451
friend VVector operator*(const value &V, const VVector &A)
Scalar * Vector.
Definition VVector.hpp:468
VVector()
Default constructor.
Definition VVector.hpp:310
friend VVector operator+(const VVector &A, const VVector &B)
Vector + Vector.
Definition VVector.hpp:480
A type that is constructed from a pair of - preferedly vectorial - types and forwards arithmetic oper...
Definition VVector.hpp:131
VectorPair(const VectorPair &L, const VectorPair &R, const Sub &)
Subtraction.
Definition VVector.hpp:167
VectorPair(const VectorPair &A, const value &V, const Div &)
Division by scalar.
Definition VVector.hpp:155
VectorPair(const VectorPair &V)
Copy constructor.
Definition VVector.hpp:140
VectorPair & operator/=(const value &v)
Vector /= scalar.
Definition VVector.hpp:207
VectorPair()
Default constructor.
Definition VVector.hpp:136
VectorPair(const VectorPair &L, const Sub &)
Unary minus.
Definition VVector.hpp:173
VectorPair(const VectorPair &A, const value &V, const Mult &)
Scalar multiplication.
Definition VVector.hpp:149
VectorPair(const VectorPair &L, const VectorPair &R, const Add &)
Addition.
Definition VVector.hpp:161
VectorPair & operator+=(const VectorPair &A)
Vector += Vector.
Definition VVector.hpp:183
friend value InnerProduct(const VectorPair &A, const VectorPair &B)
Multiply and sum component-wise, .
Definition VVector.hpp:216
VectorPair & operator*=(const value &v)
Vector *= scalar.
Definition VVector.hpp:199
VectorPair & operator-=(const VectorPair &A)
Vector -= Vector.
Definition VVector.hpp:191
Anemone_Context_t operator<<(Anemone &A, VRenderContext &VC)
Column< C, Value > operator*(const Column< C, Value > &A, double V)
double norm2(const PhysicalSpace::bivector &v)
double norm(const PhysicalSpace::bivector &v)
Operator<'-'> Sub
Operator<'+'> Add
Operator<' *'> Mult
Operator<'/'> Div
This is an ugly hackaround class to cure some problem of the gcc 4.0 an 4.2 compiler under MacOS,...
Definition VVector.hpp:257
static const element_t & getComponent(const T &t, int i)