PCL
MultiVector.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/MultiVector.h - Released 2024-06-18T15:48:54Z
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-2024 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 (https://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  using scalar = typename vector::scalar;
118 
122  using component = typename vector::component;
123 
128 
133 
138 
143 
148  GenericMultiVector() = default;
149 
157  : multivector_implementation( length )
158  {
159  }
160 
171  GenericMultiVector( size_type length, int vectorLength )
172  : multivector_implementation( length )
173  {
174  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
175  *i = vector( vectorLength );
176  }
177 
187  GenericMultiVector( const scalar& value, size_type length, int vectorLength )
188  : multivector_implementation( length )
189  {
190  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
191  *i = vector( value, vectorLength );
192  }
193 
199  GenericMultiVector( const vector& v0, const vector& v1 )
200  : GenericMultiVector( size_type( 2 ) )
201  {
202  iterator i = this->Begin();
203  *i = v0; *++i = v1;
204  }
205 
211  GenericMultiVector( const vector& v0, const vector& v1, const vector& v2 )
212  : GenericMultiVector( size_type( 3 ) )
213  {
214  iterator i = this->Begin();
215  *i = v0; *++i = v1; *++i = v2;
216  }
217 
223  GenericMultiVector( const vector& v0, const vector& v1, const vector& v2, const vector& v3 )
224  : GenericMultiVector( size_type( 4 ) )
225  {
226  iterator i = this->Begin();
227  *i = v0; *++i = v1; *++i = v2; *++i = v3;
228  }
229 
234 
239 
244  {
245  }
246 
250  GenericMultiVector& operator =( const GenericMultiVector& ) = default;
251 
255  GenericMultiVector& operator =( GenericMultiVector&& ) = default;
256 
261  GenericMultiVector& operator =( const scalar& x )
262  {
263  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
264  *i = x;
265  return *this;
266  }
267 
272  GenericMultiVector& operator +=( const scalar& x )
273  {
274  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
275  *i += x;
276  return *this;
277  }
278 
283  GenericMultiVector& operator -=( const scalar& x )
284  {
285  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
286  *i -= x;
287  return *this;
288  }
289 
294  GenericMultiVector& operator *=( const scalar& x )
295  {
296  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
297  *i *= x;
298  return *this;
299  }
300 
305  GenericMultiVector& operator /=( const scalar& x )
306  {
307  for ( iterator i = this->Begin(), j = this->End(); i < j; ++i )
308  *i /= x;
309  return *this;
310  }
311 
315  double Sum() const
316  {
317  double s = 0;
318  for ( const_iterator i = this->Begin(), j = this->End(); i < j; ++i )
319  s += i->Sum();
320  return s;
321  }
322 
327  double StableSum() const
328  {
329  DVector s( this->Length() );
330  size_type n = 0;
331  for ( const_iterator i = this->Begin(), j = this->End(); i < j; ++i )
332  s[n++] = i->StableSum();
333  return s.StableSum();
334  }
335 
336 #ifndef __PCL_NO_VECTOR_STATISTICS
337 
343  {
344  if ( !this->IsEmpty() )
345  {
346  component min = this->Begin()->MinComponent();
347  for ( const_iterator i = this->Begin(), j = this->End(); ++i < j; )
348  min = pcl::Min( min, i->MinComponent() );
349  return min;
350  }
351  return component( 0 );
352  }
353 
359  {
360  if ( !this->IsEmpty() )
361  {
362  component max = this->Begin()->MaxComponent();
363  for ( const_iterator i = this->Begin(), j = this->End(); ++i < j; )
364  max = pcl::Max( max, i->MaxComponent() );
365  return max;
366  }
367  return component( 0 );
368  }
369 
370 #endif // !__PCL_NO_VECTOR_STATISTICS
371 };
372 
373 // ----------------------------------------------------------------------------
374 
375 #ifndef __PCL_NO_MULTIVECTOR_INSTANTIATE
376 
389 using DMultiVector = GenericMultiVector<double>;
390 
399 using FMultiVector = GenericMultiVector<float>;
400 
409 using IMultiVector = GenericMultiVector<int>;
410 
419 using MultiVector = DMultiVector;
420 
421 #endif // !__PCL_NO_MULTIVECTOR_INSTANTIATE
422 
423 // ----------------------------------------------------------------------------
424 
425 } // pcl
426 
427 #endif // __PCL_MultiVector_h
428 
429 // ----------------------------------------------------------------------------
430 // EOF pcl/MultiVector.h - Released 2024-06-18T15:48:54Z
Generic dynamic array.
Definition: Array.h:100
64-bit floating point real multivector.
32-bit floating point real multivector.
Generic array of vectors.
Definition: MultiVector.h:101
GenericMultiVector(const vector &v0, const vector &v1, const vector &v2, const vector &v3)
Definition: MultiVector.h:223
component MinComponent() const
Definition: MultiVector.h:342
typename vector::scalar scalar
Definition: MultiVector.h:117
typename vector::iterator vector_iterator
Definition: MultiVector.h:137
GenericMultiVector(const vector &v0, const vector &v1, const vector &v2)
Definition: MultiVector.h:211
GenericMultiVector(size_type length, int vectorLength)
Definition: MultiVector.h:171
typename multivector_implementation::iterator iterator
Definition: MultiVector.h:127
GenericMultiVector(size_type length)
Definition: MultiVector.h:156
double StableSum() const
Definition: MultiVector.h:327
component MaxComponent() const
Definition: MultiVector.h:358
double Sum() const
Definition: MultiVector.h:315
GenericMultiVector(const scalar &value, size_type length, int vectorLength)
Definition: MultiVector.h:187
GenericMultiVector(GenericMultiVector &&)=default
typename multivector_implementation::const_iterator const_iterator
Definition: MultiVector.h:132
GenericMultiVector(const GenericMultiVector &)=default
typename vector::const_iterator const_vector_iterator
Definition: MultiVector.h:142
typename vector::component component
Definition: MultiVector.h:122
GenericMultiVector(const vector &v0, const vector &v1)
Definition: MultiVector.h:199
Generic vector of arbitrary length.
Definition: Vector.h:107
double StableSum() const noexcept
Definition: Vector.h:1223
const T * const_iterator
Definition: Vector.h:128
Integer multivector.
64-bit floating point real multivector.
size_t size_type
Definition: Defs.h:609
constexpr const T & Min(const T &a, const T &b) noexcept
Definition: Utility.h:90
constexpr const T & Max(const T &a, const T &b) noexcept
Definition: Utility.h:119
PCL root namespace.
Definition: AbstractImage.h:77