PCL
MultiVector.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/MultiVector.h - Released 2019-11-07T10:59:34Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2019 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (http://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_MultiVector_h
53 #define __PCL_MultiVector_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
60 #include <pcl/Array.h>
61 #include <pcl/Vector.h>
62 
63 namespace pcl
64 {
65 
66 // ----------------------------------------------------------------------------
67 
99 template <typename T>
100 class PCL_CLASS GenericMultiVector : public Array<GenericVector<T> >
101 {
102 public:
103 
108 
113 
117  typedef typename vector::scalar scalar;
118 
122  typedef typename vector::component component;
123 
127  typedef typename multivector_implementation::iterator
129 
135 
140 
145 
150  GenericMultiVector() = default;
151 
159  multivector_implementation( length )
160  {
161  }
162 
173  GenericMultiVector( size_type length, int vectorLength ) :
174  multivector_implementation( length )
175  {
176  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
177  *i = vector( vectorLength );
178  }
179 
189  GenericMultiVector( const scalar& value, size_type length, int vectorLength ) :
190  multivector_implementation( length )
191  {
192  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
193  *i = vector( value, vectorLength );
194  }
195 
201  GenericMultiVector( const vector& v0, const vector& v1 ) :
203  {
204  iterator i = this->Begin();
205  *i = v0; *++i = v1;
206  }
207 
213  GenericMultiVector( const vector& v0, const vector& v1, const vector& v2 ) :
215  {
216  iterator i = this->Begin();
217  *i = v0; *++i = v1; *++i = v2;
218  }
219 
225  GenericMultiVector( const vector& v0, const vector& v1, const vector& v2, const vector& v3 ) :
227  {
228  iterator i = this->Begin();
229  *i = v0; *++i = v1; *++i = v2; *++i = v3;
230  }
231 
235  GenericMultiVector( const GenericMultiVector& ) = default;
236 
240  GenericMultiVector( GenericMultiVector&& ) = default;
241 
246  {
247  }
248 
252  GenericMultiVector& operator =( const GenericMultiVector& ) = default;
253 
257  GenericMultiVector& operator =( GenericMultiVector&& ) = default;
258 
263  GenericMultiVector& operator =( const scalar& x )
264  {
265  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
266  *i = x;
267  return *this;
268  }
269 
274  GenericMultiVector& operator +=( const scalar& x )
275  {
276  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
277  *i += x;
278  return *this;
279  }
280 
285  GenericMultiVector& operator -=( const scalar& x )
286  {
287  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
288  *i -= x;
289  return *this;
290  }
291 
296  GenericMultiVector& operator *=( const scalar& x )
297  {
298  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
299  *i *= x;
300  return *this;
301  }
302 
307  GenericMultiVector& operator /=( const scalar& x )
308  {
309  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
310  *i /= x;
311  return *this;
312  }
313 
317  double Sum() const
318  {
319  double s = 0;
320  for ( const_iterator i = this->Begin(), j = this->End(); i < j; ++i )
321  s += i->Sum();
322  return s;
323  }
324 
329  double StableSum() const
330  {
331  DVector s( this->Length() );
332  size_type n = 0;
333  for ( const_iterator i = this->Begin(), j = this->End(); i < j; ++i )
334  s[n++] = i->StableSum();
335  return s.StableSum();
336  }
337 
338 #ifndef __PCL_NO_VECTOR_STATISTICS
339 
344  component MinComponent() const
345  {
346  if ( !this->IsEmpty() )
347  {
348  component min = this->Begin()->MinComponent();
349  for ( const_iterator i = this->Begin(), j = this->End(); ++i < j; )
350  min = pcl::Min( min, i->MinComponent() );
351  return min;
352  }
353  return component( 0 );
354  }
355 
360  component MaxComponent() const
361  {
362  if ( !this->IsEmpty() )
363  {
364  component max = this->Begin()->MaxComponent();
365  for ( const_iterator i = this->Begin(), j = this->End(); ++i < j; )
366  max = pcl::Max( max, i->MaxComponent() );
367  return max;
368  }
369  return component( 0 );
370  }
371 
372 #endif // !__PCL_NO_VECTOR_STATISTICS
373 };
374 
375 // ----------------------------------------------------------------------------
376 
377 #ifndef __PCL_NO_MULTIVECTOR_INSTANTIATE
378 
392 
402 
412 
421 typedef DMultiVector MultiVector;
422 
423 #endif // !__PCL_NO_MULTIVECTOR_INSTANTIATE
424 
425 // ----------------------------------------------------------------------------
426 
427 } // pcl
428 
429 #endif // __PCL_MultiVector_h
430 
431 // ----------------------------------------------------------------------------
432 // EOF pcl/MultiVector.h - Released 2019-11-07T10:59:34Z
vector::const_iterator const_vector_iterator
Definition: MultiVector.h:144
GenericMultiVector(const vector &v0, const vector &v1, const vector &v2, const vector &v3)
Definition: MultiVector.h:225
PCL root namespace.
Definition: AbstractImage.h:76
double StableSum() const
Definition: MultiVector.h:329
vector::iterator vector_iterator
Definition: MultiVector.h:139
GenericMultiVector(size_type length, int vectorLength)
Definition: MultiVector.h:173
64-bit floating point real multivector.
GenericMultiVector(const vector &v0, const vector &v1)
Definition: MultiVector.h:201
GenericMultiVector(size_type length)
Definition: MultiVector.h:158
Generic vector of arbitrary length.
Definition: Vector.h:106
vector::scalar scalar
Definition: MultiVector.h:117
size_t size_type
Definition: Defs.h:543
32-bit floating point real multivector.
64-bit floating point real multivector.
component MaxComponent() const
Definition: MultiVector.h:360
constexpr const T & Max(const T &a, const T &b)
Definition: Utility.h:119
64-bit floating point real vector.
Array< GenericVector< T > > multivector_implementation
Definition: MultiVector.h:107
constexpr const T & Min(const T &a, const T &b)
Definition: Utility.h:90
multivector_implementation::iterator iterator
Definition: MultiVector.h:128
GenericMultiVector(const vector &v0, const vector &v1, const vector &v2)
Definition: MultiVector.h:213
Generic dynamic array.
Definition: Array.h:99
const T * const_iterator
Definition: Vector.h:128
vector::component component
Definition: MultiVector.h:122
Generic array of vectors.
Definition: MultiVector.h:100
Integer multivector.
GenericVector< T > vector
Definition: MultiVector.h:112
GenericMultiVector(const scalar &value, size_type length, int vectorLength)
Definition: MultiVector.h:189
double Sum() const
Definition: MultiVector.h:317
component MinComponent() const
Definition: MultiVector.h:344
multivector_implementation::const_iterator const_iterator
Definition: MultiVector.h:134