VectorT_inc.hh 19.5 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
/* ========================================================================= *
2
3
 *                                                                           *
 *                               OpenMesh                                    *
Jan Möbius's avatar
Jan Möbius committed
4
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
Jan Möbius's avatar
Typo    
Jan Möbius committed
5
 *           Department of Computer Graphics and Multimedia                  *
Jan Möbius's avatar
Jan Möbius committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 *                          All rights reserved.                             *
 *                            www.openmesh.org                               *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenMesh.                                            *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
40
 * ========================================================================= */
Jan Möbius's avatar
Jan Möbius committed
41
42


43
44
45
46
47
48
49

/*===========================================================================*\
 *                                                                           *             
 *   $Revision$                                                         *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
Jan Möbius committed
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Set template keywords and class names properly when
// parsing with doxygen. This only seems to work this way since
// the scope of preprocessor defines is limited to one file in doxy.
#ifdef DOXYGEN

// Only used for correct doxygen parsing
#define OPENMESH_VECTOR_HH

#define DIM               N
#define TEMPLATE_HEADER   template <typename Scalar, int N>
#define CLASSNAME         VectorT
#define DERIVED           VectorDataT<Scalar,N>
#define unroll(expr)      for (int i=0; i<N; ++i) expr(i)

#endif

Jan Möbius's avatar
Jan Möbius committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#if defined( OPENMESH_VECTOR_HH )

// ----------------------------------------------------------------------------

TEMPLATE_HEADER
class CLASSNAME : public DERIVED
{
private:
  typedef DERIVED                           Base;
public:

  //---------------------------------------------------------------- class info

  /// the type of the scalar used in this template
  typedef Scalar value_type;

  /// type of this vector
  typedef VectorT<Scalar,DIM>  vector_type;

  /// returns dimension of the vector (deprecated)
  static inline int dim() { return DIM; }

  /// returns dimension of the vector
  static inline size_t size() { return DIM; }

  static const size_t size_ = DIM;


  //-------------------------------------------------------------- constructors

  /// default constructor creates uninitialized values.
  inline VectorT() {}

100
#if __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
101
  explicit inline VectorT(const Scalar &v) {
102
103
104
      vectorize(v);
  }

105
106
  template<typename... T,
      typename = typename std::enable_if<sizeof...(T) == DIM>::type,
107
      typename = typename std::enable_if<are_convertible_to<Scalar, T...>::value>::type>
108
  constexpr VectorT(T... vs) : Base { static_cast<Scalar>(vs)...}
109
  { }
110
111
112
113
114
115
116
117
118
119
120

  template<int D = DIM, typename = typename std::enable_if<D == DIM>::type>
  typename std::enable_if<D==4, VectorT>::type
  homogenized() const {
      return VectorT(
              Base::values_[0]/Base::values_[3],
              Base::values_[1]/Base::values_[3],
              Base::values_[2]/Base::values_[3],
              1);
  }

121
#else
Jan Möbius's avatar
Jan Möbius committed
122
123
124
125
126
127
128
  /// special constructor for 1D vectors
  explicit inline VectorT(const Scalar& v) {
//     assert(DIM==1);
//     values_[0] = v0;
    vectorize(v);
  }

129
#if DIM == 2
Jan Möbius's avatar
Jan Möbius committed
130
  /// special constructor for 2D vectors
131
  inline VectorT(const Scalar v0, const Scalar v1) {
Jan Möbius's avatar
Jan Möbius committed
132
133
    Base::values_[0] = v0; Base::values_[1] = v1;
  }
134
#endif
Jan Möbius's avatar
Jan Möbius committed
135

136
#if DIM == 3
Jan Möbius's avatar
Jan Möbius committed
137
  /// special constructor for 3D vectors
138
  inline VectorT(const Scalar v0, const Scalar v1, const Scalar v2) {
Jan Möbius's avatar
Jan Möbius committed
139
140
    Base::values_[0]=v0; Base::values_[1]=v1; Base::values_[2]=v2;
  }
141
#endif
Jan Möbius's avatar
Jan Möbius committed
142

143
#if DIM == 4
Jan Möbius's avatar
Jan Möbius committed
144
  /// special constructor for 4D vectors
145
146
  inline VectorT(const Scalar v0, const Scalar v1,
     const Scalar v2, const Scalar v3) {
Jan Möbius's avatar
Jan Möbius committed
147
148
    Base::values_[0]=v0; Base::values_[1]=v1; Base::values_[2]=v2; Base::values_[3]=v3;
  }
149

150
  VectorT homogenized() const { return VectorT(Base::values_[0]/Base::values_[3], Base::values_[1]/Base::values_[3], Base::values_[2]/Base::values_[3], 1); }
151
#endif
Jan Möbius's avatar
Jan Möbius committed
152

153
#if DIM == 5
Jan Möbius's avatar
Jan Möbius committed
154
  /// special constructor for 5D vectors
155
156
  inline VectorT(const Scalar v0, const Scalar v1, const Scalar v2,
     const Scalar v3, const Scalar v4) {
Jan Möbius's avatar
Jan Möbius committed
157
158
    Base::values_[0]=v0; Base::values_[1]=v1;Base::values_[2]=v2; Base::values_[3]=v3; Base::values_[4]=v4;
  }
159
#endif
Jan Möbius's avatar
Jan Möbius committed
160

161
#if DIM == 6
Jan Möbius's avatar
Jan Möbius committed
162
  /// special constructor for 6D vectors
163
164
  inline VectorT(const Scalar v0, const Scalar v1, const Scalar v2,
     const Scalar v3, const Scalar v4, const Scalar v5) {
Jan Möbius's avatar
Jan Möbius committed
165
166
167
    Base::values_[0]=v0; Base::values_[1]=v1; Base::values_[2]=v2;
    Base::values_[3]=v3; Base::values_[4]=v4; Base::values_[5]=v5;
  }
168
#endif
169
#endif
170

Jan Möbius's avatar
Jan Möbius committed
171
172
  /// construct from a value array (explicit)
  explicit inline VectorT(const Scalar _values[DIM]) {
173
    memcpy(data(), _values, DIM*sizeof(Scalar));
Jan Möbius's avatar
Jan Möbius committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
  }


#ifdef OM_CC_MIPS
  /// assignment from a vector of the same kind
  // mipspro need this method
  inline vector_type& operator=(const vector_type& _rhs) {
    memcpy(Base::values_, _rhs.Base::values_, DIM*sizeof(Scalar));
    return *this;
  }
#endif


  /// copy & cast constructor (explicit)
  template<typename otherScalarType>
  explicit inline VectorT(const VectorT<otherScalarType,DIM>& _rhs) {
    operator=(_rhs);
  }




  //--------------------------------------------------------------------- casts

  /// cast from vector with a different scalar type
  template<typename otherScalarType>
  inline vector_type& operator=(const VectorT<otherScalarType,DIM>& _rhs) {
#define expr(i)  Base::values_[i] = (Scalar)_rhs[i];
    unroll(expr);
#undef expr
    return *this;
  }

//   /// cast to Scalar array
//   inline operator Scalar*() { return Base::values_; }

//   /// cast to const Scalar array
//   inline operator const Scalar*() const { return Base::values_; }

213
#if __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
214
215
216
217
218
219
  /// access to Scalar array
  inline Scalar* data() { return Base::values_.data(); }

  /// access to const Scalar array
  inline const Scalar*data() const { return Base::values_.data(); }
#else
Jan Möbius's avatar
Jan Möbius committed
220
221
222
223
224
  /// access to Scalar array
  inline Scalar* data() { return Base::values_; }

  /// access to const Scalar array
  inline const Scalar*data() const { return Base::values_; }
225
#endif
Jan Möbius's avatar
Jan Möbius committed
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475




   //----------------------------------------------------------- element access

//    /// get i'th element read-write
//   inline Scalar& operator[](int _i) {
//     assert(_i>=0 && _i<DIM); return Base::values_[_i];
//   }

//   /// get i'th element read-only
//   inline const Scalar& operator[](int _i) const {
//     assert(_i>=0 && _i<DIM); return Base::values_[_i];
//   }

   /// get i'th element read-write
  inline Scalar& operator[](size_t _i) {
    assert(_i<DIM); return Base::values_[_i];
  }

  /// get i'th element read-only
  inline const Scalar& operator[](size_t _i) const {
    assert(_i<DIM); return Base::values_[_i];
  }




  //---------------------------------------------------------------- comparsion

  /// component-wise comparison
  inline bool operator==(const vector_type& _rhs) const {
#define expr(i) if(Base::values_[i]!=_rhs.Base::values_[i]) return false;
    unroll(expr);
#undef expr
    return true;
  }

  /// component-wise comparison
  inline bool operator!=(const vector_type& _rhs) const {
    return !(*this == _rhs);
  }




  //---------------------------------------------------------- scalar operators

  /// component-wise self-multiplication with scalar
  inline vector_type& operator*=(const Scalar& _s) {
#define expr(i) Base::values_[i] *= _s;
    unroll(expr);
#undef expr
    return *this;
  }

  /** component-wise self-division by scalar
      \attention v *= (1/_s) is much faster than this  */
  inline vector_type& operator/=(const Scalar& _s) {
#define expr(i) Base::values_[i] /= _s;
    unroll(expr);
#undef expr
    return *this;
  }


  /// component-wise multiplication with scalar
  inline vector_type operator*(const Scalar& _s) const {
#if DIM==N
    return vector_type(*this) *= _s;
#else
#define expr(i) Base::values_[i] * _s
    return vector_type(unroll_csv(expr));
#undef expr
#endif
  }


  /// component-wise division by with scalar
  inline vector_type operator/(const Scalar& _s) const {
#if DIM==N
    return vector_type(*this) /= _s;
#else
#define expr(i) Base::values_[i] / _s
    return vector_type(unroll_csv(expr));
#undef expr
#endif
  }






  //---------------------------------------------------------- vector operators

  /// component-wise self-multiplication
  inline vector_type& operator*=(const vector_type& _rhs) {
#define expr(i) Base::values_[i] *= _rhs[i];
    unroll(expr);
#undef expr
    return *this;
  }

  /// component-wise self-division
  inline vector_type& operator/=(const vector_type& _rhs) {
#define expr(i) Base::values_[i] /= _rhs[i];
    unroll(expr);
#undef expr
    return *this;
  }

  /// vector difference from this
  inline vector_type& operator-=(const vector_type& _rhs) {
#define expr(i) Base::values_[i] -= _rhs[i];
    unroll(expr);
#undef expr
    return *this;
  }

  /// vector self-addition
  inline vector_type& operator+=(const vector_type& _rhs) {
#define expr(i) Base::values_[i] += _rhs[i];
    unroll(expr);
#undef expr
    return *this;
  }


  /// component-wise vector multiplication
  inline vector_type operator*(const vector_type& _v) const {
#if DIM==N
    return vector_type(*this) *= _v;
#else
#define expr(i) Base::values_[i] * _v.Base::values_[i]
    return vector_type(unroll_csv(expr));
#undef expr
#endif
  }


  /// component-wise vector division
  inline vector_type operator/(const vector_type& _v) const {
#if DIM==N
    return vector_type(*this) /= _v;
#else
#define expr(i) Base::values_[i] / _v.Base::values_[i]
    return vector_type(unroll_csv(expr));
#undef expr
#endif
  }


  /// component-wise vector addition
  inline vector_type operator+(const vector_type& _v) const {
#if DIM==N
    return vector_type(*this) += _v;
#else
#define expr(i) Base::values_[i] + _v.Base::values_[i]
    return vector_type(unroll_csv(expr));
#undef expr
#endif
  }


  /// component-wise vector difference
  inline vector_type operator-(const vector_type& _v) const {
#if DIM==N
    return vector_type(*this) -= _v;
#else
#define expr(i) Base::values_[i] - _v.Base::values_[i]
    return vector_type(unroll_csv(expr));
#undef expr
#endif
  }


  /// unary minus
  inline vector_type operator-(void) const {
    vector_type v;
#define expr(i) v.Base::values_[i] = -Base::values_[i];
    unroll(expr);
#undef expr
    return v;
  }


  /// cross product: only defined for Vec3* as specialization
  /// \see OpenMesh::cross
  inline VectorT<Scalar,3> operator%(const VectorT<Scalar,3>& _rhs) const
#if DIM==3
  {
    return
      VectorT<Scalar,3>(Base::values_[1]*_rhs.Base::values_[2]-Base::values_[2]*_rhs.Base::values_[1],
      Base::values_[2]*_rhs.Base::values_[0]-Base::values_[0]*_rhs.Base::values_[2],
      Base::values_[0]*_rhs.Base::values_[1]-Base::values_[1]*_rhs.Base::values_[0]);
  }
#else
  ;
#endif


  /// compute scalar product
  /// \see OpenMesh::dot
  inline Scalar operator|(const vector_type& _rhs) const {
  Scalar p(0);
#define expr(i) p += Base::values_[i] * _rhs.Base::values_[i];
  unroll(expr);
#undef expr
    return p;
  }





  //------------------------------------------------------------ euclidean norm

  /// \name Euclidean norm calculations
  //@{
  /// compute euclidean norm
  inline Scalar norm() const { return (Scalar)sqrt(sqrnorm()); }
  inline Scalar length() const { return norm(); } // OpenSG interface

  /// compute squared euclidean norm
  inline Scalar sqrnorm() const 
  {
#if DIM==N
    Scalar s(0);
#define expr(i) s += Base::values_[i] * Base::values_[i];
    unroll(expr);
#undef expr
    return s;
#else
#define expr(i) Base::values_[i]*Base::values_[i]
    return (unroll_comb(expr, +));
#undef expr
#endif
  }

  /** normalize vector, return normalized vector
  */

  inline vector_type& normalize() 
  {
    *this /= norm();
    return *this;
  }
  
476
477
478
479
480
481
482
483
  /** return normalized vector
  */

  inline const vector_type normalized() const
  {
    return *this / norm();
  }

Jan Möbius's avatar
Jan Möbius committed
484
485
486
487
488
489
490
491
492
493
494
  /** normalize vector, return normalized vector and avoids div by zero 
  */
  inline vector_type& normalize_cond() 
  {
    Scalar n = norm();
    if (n != (Scalar)0.0)
    {
      *this /= n;
    }
    return *this;
  }
495
496
497
498
499
500
501
502
503
504
505
506
507
  
  //@}

  //------------------------------------------------------------ euclidean norm

  /// \name Non-Euclidean norm calculations
  //@{
  
  /// compute L1 (Manhattan) norm
  inline Scalar l1_norm() const
  {
#if DIM==N
    Scalar s(0);
508
#define expr(i) s += std::abs(Base::values_[i]);
509
510
511
512
    unroll(expr);
#undef expr
    return s;
#else
513
#define expr(i) std::abs(Base::values_[i])
514
515
516
517
    return (unroll_comb(expr, +));
#undef expr
#endif
  }
Jan Möbius's avatar
Jan Möbius committed
518

519
520
521
522
523
524
  /// compute l8_norm
  inline Scalar l8_norm() const
  {
    return max_abs();
  }

525
  //@}
Jan Möbius's avatar
Jan Möbius committed
526
527
528

  //------------------------------------------------------------ max, min, mean

529
530
531
  /// \name Minimum maximum and mean
  //@{

Jan Möbius's avatar
Jan Möbius committed
532
533
534
535
536
537
538
539
  /// return the maximal component
  inline Scalar max() const 
  {
    Scalar m(Base::values_[0]);
    for(int i=1; i<DIM; ++i) if(Base::values_[i]>m) m=Base::values_[i];
    return m;
  }

540
541
542
  /// return the maximal absolute component
  inline Scalar max_abs() const
  {
543
    Scalar m(std::abs(Base::values_[0]));
544
    for(int i=1; i<DIM; ++i) 
545
546
      if(std::abs(Base::values_[i])>m)
        m=std::abs(Base::values_[i]);
547
548
549
550
    return m;
  }


Jan Möbius's avatar
Jan Möbius committed
551
552
553
554
555
556
557
558
  /// return the minimal component
  inline Scalar min() const 
  {
    Scalar m(Base::values_[0]);
    for(int i=1; i<DIM; ++i) if(Base::values_[i]<m) m=Base::values_[i];
    return m;
  }

559
560
561
  /// return the minimal absolute component
  inline Scalar min_abs() const 
  {
562
    Scalar m(std::abs(Base::values_[0]));
563
    for(int i=1; i<DIM; ++i) 
564
565
      if(std::abs(Base::values_[i])<m)
        m=std::abs(Base::values_[i]);
566
567
568
    return m;
  }

Jan Möbius's avatar
Jan Möbius committed
569
570
571
572
573
574
575
  /// return arithmetic mean
  inline Scalar mean() const {
    Scalar m(Base::values_[0]);
    for(int i=1; i<DIM; ++i) m+=Base::values_[i];
    return m/Scalar(DIM);
  }

576
577
  /// return absolute arithmetic mean
  inline Scalar mean_abs() const {
578
579
    Scalar m(std::abs(Base::values_[0]));
    for(int i=1; i<DIM; ++i) m+=std::abs(Base::values_[i]);
580
581
582
583
    return m/Scalar(DIM);
  }


Jan Möbius's avatar
Jan Möbius committed
584
  /// minimize values: same as *this = min(*this, _rhs), but faster
585
  inline vector_type& minimize(const vector_type& _rhs) {
Jan Möbius's avatar
Jan Möbius committed
586
587
588
589
590
591
#define expr(i) if (_rhs[i] < Base::values_[i]) Base::values_[i] = _rhs[i];
    unroll(expr);
#undef expr
    return *this;
  }

592
593
594
595
596
597
598
599
600
  /// minimize values and signalize coordinate minimization
  inline bool minimized(const vector_type& _rhs) {
    bool result(false);
#define expr(i) if (_rhs[i] < Base::values_[i]) { Base::values_[i] = _rhs[i]; result = true; }
    unroll(expr);
#undef expr
    return result;
  }

Jan Möbius's avatar
Jan Möbius committed
601
  /// maximize values: same as *this = max(*this, _rhs), but faster
602
  inline vector_type& maximize(const vector_type& _rhs) {
Jan Möbius's avatar
Jan Möbius committed
603
604
605
606
607
608
#define expr(i) if (_rhs[i] > Base::values_[i]) Base::values_[i] = _rhs[i];
    unroll(expr);
#undef expr
    return *this;
  }

609
610
611
612
613
614
615
616
617
  /// maximize values and signalize coordinate maximization
  inline bool maximized(const vector_type& _rhs) {
    bool result(false);
#define expr(i) if (_rhs[i] > Base::values_[i]) { Base::values_[i] =_rhs[i]; result = true; }
    unroll(expr);
#undef expr
    return result;
  }

Jan Möbius's avatar
Jan Möbius committed
618
  /// component-wise min
619
  inline vector_type min(const vector_type& _rhs) const {
Jan Möbius's avatar
Jan Möbius committed
620
621
622
623
    return vector_type(*this).minimize(_rhs);
  }

  /// component-wise max
624
  inline vector_type max(const vector_type& _rhs) const {
Jan Möbius's avatar
Jan Möbius committed
625
626
627
    return vector_type(*this).maximize(_rhs);
  }

628
  //@}
Jan Möbius's avatar
Jan Möbius committed
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701

  //------------------------------------------------------------ misc functions

  /// component-wise apply function object with Scalar operator()(Scalar).
  template<typename Functor>
  inline vector_type apply(const Functor& _func) const {
    vector_type result;
#define expr(i) result[i] = _func(Base::values_[i]);
    unroll(expr);
#undef expr
    return result;
  }

  /// store the same value in each component (e.g. to clear all entries)
  vector_type& vectorize(const Scalar& _s) {
#define expr(i) Base::values_[i] = _s;
    unroll(expr);
#undef expr
    return *this;
  }


  /// store the same value in each component
  static vector_type vectorized(const Scalar& _s) {
    return vector_type().vectorize(_s);
  }


  /// lexicographical comparison
  bool operator<(const vector_type& _rhs) const {
#define expr(i) if (Base::values_[i] != _rhs.Base::values_[i]) \
                   return (Base::values_[i] < _rhs.Base::values_[i]);
    unroll(expr);
#undef expr
    return false;
   }
};



/// read the space-separated components of a vector from a stream
TEMPLATE_HEADER
inline std::istream&
operator>>(std::istream& is, VectorT<Scalar,DIM>& vec)
{
#define expr(i) is >> vec[i];
  unroll(expr);
#undef expr
  return is;
}


/// output a vector by printing its space-separated compontens
TEMPLATE_HEADER
inline std::ostream&
operator<<(std::ostream& os, const VectorT<Scalar,DIM>& vec)
{
#if DIM==N
  for(int i=0; i<N-1; ++i) os << vec[i] << " ";
  os << vec[N-1];
#else
#define expr(i) vec[i]
  os << unroll_comb(expr, << " " <<);
#undef expr
#endif

  return os;
}


// ----------------------------------------------------------------------------
#endif // included by VectorT.hh
//=============================================================================