PCL
Vector.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/Vector.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_Vector_h
53 #define __PCL_Vector_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
60 #include <pcl/Container.h>
61 #include <pcl/Exception.h>
62 #include <pcl/ReferenceCounter.h>
63 #include <pcl/Search.h>
64 #include <pcl/Sort.h>
65 #include <pcl/Utility.h>
66 
67 #ifndef __PCL_NO_VECTOR_STATISTICS
68 # include <pcl/Selection.h>
69 #endif
70 
71 #ifndef __PCL_NO_VECTOR_INSTANTIATE
72 # include <pcl/Complex.h>
73 #endif
74 
75 namespace pcl
76 {
77 
78 // ----------------------------------------------------------------------------
79 
105 template <typename T>
106 class PCL_CLASS GenericVector : public DirectContainer<T>
107 {
108 public:
109 
113  using scalar = T;
114 
118  using component = T;
119 
123  using iterator = T*;
124 
128  using const_iterator = const T*;
129 
135  {
136  m_data = new Data;
137  }
138 
147  GenericVector( int len )
148  {
149  PCL_PRECONDITION( len >= 0 )
150  m_data = new Data( len );
151  }
152 
159  GenericVector( const component& x, int len )
160  {
161  PCL_PRECONDITION( len >= 0 )
162  m_data = new Data( len );
163  iterator __restrict__ i = m_data->Begin();
164  const_iterator __restrict__ j = m_data->End();
165  PCL_IVDEP
166  for ( ; i < j; ++i )
167  *i = x;
168  }
169 
180  template <typename T1>
181  GenericVector( const T1* a, int len )
182  {
183  PCL_PRECONDITION( len >= 0 )
184  m_data = new Data( len );
185  if ( a != nullptr )
186  {
187  iterator __restrict__ i = m_data->Begin();
188  const_iterator __restrict__ j = m_data->End();
189  const T1* __restrict__ k = a;
190  PCL_IVDEP
191  for ( ; i < j; ++i, ++k )
192  *i = component( *k );
193  }
194  }
195 
204  template <typename T1>
205  GenericVector( std::initializer_list<T1> c )
206  : GenericVector( c.begin(), int( c.size() ) )
207  {
208  }
209 
214  template <typename T1>
215  GenericVector( const T1& x, const T1& y, const T1& z )
216  {
217  m_data = new Data( 3 );
218  iterator v = m_data->Begin();
219  *v++ = component( x );
220  *v++ = component( y );
221  *v = component( z );
222  }
223 
228  template <typename T1>
229  GenericVector( const T1& x, const T1& y, const T1& z, const T1& t )
230  {
231  m_data = new Data( 4 );
232  iterator v = m_data->Begin();
233  *v++ = component( x );
234  *v++ = component( y );
235  *v++ = component( z );
236  *v = component( t );
237  }
238 
244  : m_data( x.m_data )
245  {
246  m_data->Attach();
247  }
248 
253  : m_data( x.m_data )
254  {
255  x.m_data = nullptr;
256  }
257 
266  template <typename T1>
268  : GenericVector( x.Begin(), x.Length() )
269  {
270  }
271 
276  virtual ~GenericVector()
277  {
278  if ( m_data != nullptr )
279  {
280  DetachFromData();
281  m_data = nullptr;
282  }
283  }
284 
288  void Clear()
289  {
290  if ( !IsEmpty() )
291  if ( m_data->IsUnique() )
292  m_data->Deallocate();
293  else
294  {
295  Data* newData = new Data( 0 );
296  DetachFromData();
297  m_data = newData;
298  }
299  }
300 
306  GenericVector& operator =( const GenericVector& x )
307  {
308  Assign( x );
309  return *this;
310  }
311 
324  void Assign( const GenericVector& x )
325  {
326  x.m_data->Attach();
327  DetachFromData();
328  m_data = x.m_data;
329  }
330 
336  GenericVector& operator =( GenericVector&& x )
337  {
338  Transfer( x );
339  return *this;
340  }
341 
355  {
356  DetachFromData();
357  m_data = x.m_data;
358  x.m_data = nullptr;
359  }
360 
374  {
375  DetachFromData();
376  m_data = x.m_data;
377  x.m_data = nullptr;
378  }
379 
386  friend void Swap( GenericVector& x1, GenericVector& x2 ) noexcept
387  {
388  pcl::Swap( x1.m_data, x2.m_data );
389  }
390 
399  GenericVector& operator =( const scalar& x )
400  {
401  if ( !IsUnique() )
402  {
403  Data* newData = new Data( m_data->Length() );
404  DetachFromData();
405  m_data = newData;
406  }
407  iterator __restrict__ i = m_data->Begin();
408  const_iterator __restrict__ j = m_data->End();
409  PCL_IVDEP
410  for ( ; i < j; ++i )
411  *i = x;
412  return *this;
413  }
414 
428  GenericVector& operator +=( const GenericVector& x )
429  {
430  if ( x.Length() < Length() )
431  throw Error( "Invalid vector addition." );
432  EnsureUnique();
433  iterator __restrict__ i = m_data->Begin();
434  const_iterator __restrict__ j = m_data->End();
435  const_iterator __restrict__ k = x.Begin();
436  PCL_IVDEP
437  for ( ; i < j; ++i, ++k )
438  *i += *k;
439  return *this;
440  }
441 
455  GenericVector& operator -=( const GenericVector& x )
456  {
457  if ( x.Length() < Length() )
458  throw Error( "Invalid vector subtraction." );
459  EnsureUnique();
460  iterator __restrict__ i = m_data->Begin();
461  const_iterator __restrict__ j = m_data->End();
462  const_iterator __restrict__ k = x.Begin();
463  PCL_IVDEP
464  for ( ; i < j; ++i, ++k )
465  *i -= *k;
466  return *this;
467  }
468 
482  GenericVector& operator *=( const GenericVector& x )
483  {
484  if ( x.Length() < Length() )
485  throw Error( "Invalid vector multiplication." );
486  EnsureUnique();
487  iterator __restrict__ i = m_data->Begin();
488  const_iterator __restrict__ j = m_data->End();
489  const_iterator __restrict__ k = x.Begin();
490  PCL_IVDEP
491  for ( ; i < j; ++i, ++k )
492  *i *= *k;
493  return *this;
494  }
495 
513  GenericVector& operator /=( const GenericVector& x )
514  {
515  if ( x.Length() < Length() )
516  throw Error( "Invalid vector division." );
517  EnsureUnique();
518  iterator __restrict__ i = m_data->Begin();
519  const_iterator __restrict__ j = m_data->End();
520  const_iterator __restrict__ k = x.Begin();
521  PCL_IVDEP
522  for ( ; i < j; ++i, ++k )
523  *i /= *k;
524  return *this;
525  }
526 
527 #define IMPLEMENT_SCALAR_ASSIGN_OP( op ) \
528  if ( IsUnique() ) \
529  { \
530  iterator __restrict__ i = m_data->Begin(); \
531  const_iterator __restrict__ j = m_data->End(); \
532  PCL_IVDEP \
533  for ( ; i < j; ++i ) \
534  *i op##= x; \
535  } \
536  else \
537  { \
538  Data* newData = new Data( m_data->Length() ); \
539  const_iterator __restrict__ i = m_data->Begin(); \
540  const_iterator __restrict__ j = m_data->End(); \
541  iterator __restrict__ k = newData->Begin(); \
542  PCL_IVDEP \
543  for ( ; i < j; ++i, ++k ) \
544  *k = *i op x; \
545  DetachFromData(); \
546  m_data = newData; \
547  } \
548  return *this;
549 
558  GenericVector& operator +=( const scalar& x )
559  {
560  IMPLEMENT_SCALAR_ASSIGN_OP( + )
561  }
562 
571  GenericVector& operator -=( const scalar& x )
572  {
573  IMPLEMENT_SCALAR_ASSIGN_OP( - )
574  }
575 
584  GenericVector& operator *=( const scalar& x )
585  {
586  IMPLEMENT_SCALAR_ASSIGN_OP( * )
587  }
588 
597  GenericVector& operator /=( const scalar& x )
598  {
599  IMPLEMENT_SCALAR_ASSIGN_OP( / )
600  }
601 
610  GenericVector& operator ^=( const scalar& x )
611  {
612  if ( IsUnique() )
613  {
614  iterator __restrict__ i = m_data->Begin();
615  const_iterator __restrict__ j = m_data->End();
616  PCL_IVDEP
617  for ( ; i < j; ++i )
618  *i = pcl::Pow( *i, x );
619  }
620  else
621  {
622  Data* newData = new Data( m_data->Length() );
623  const_iterator __restrict__ i = m_data->Begin();
624  const_iterator __restrict__ j = m_data->End();
625  iterator __restrict__ k = newData->Begin();
626  PCL_IVDEP
627  for ( ; i < j; ++i, ++k )
628  *k = pcl::Pow( *i, x );
629  DetachFromData();
630  m_data = newData;
631  }
632  return *this;
633  }
634 
635 #undef IMPLEMENT_SCALAR_ASSIGN_OP
636 
645  scalar Dot( const GenericVector& v ) const noexcept
646  {
647  PCL_PRECONDITION( v.Length() >= Length() )
648  scalar r = scalar( 0 );
649  const_iterator __restrict__ i = m_data->Begin();
650  const_iterator __restrict__ j = m_data->End();
651  const_iterator __restrict__ k = v.Begin();
652  PCL_IVDEP
653  for ( ; i < j; ++i, ++k )
654  r += scalar( *i ) * scalar( *k );
655  return r;
656  }
657 
665  GenericVector Cross( const GenericVector& v2 ) const
666  {
667  PCL_PRECONDITION( Length() == 3 && v2.Length() == 3 )
668  component x1 = *At( 0 );
669  component y1 = *At( 1 );
670  component z1 = *At( 2 );
671  component x2 = v2[0];
672  component y2 = v2[1];
673  component z2 = v2[2];
674  return GenericVector( y1*z2 - z1*y2,
675  z1*x2 - x1*z2,
676  x1*y2 - y1*x2 );
677  }
678 
684  {
685  GenericVector R( m_data->Length() );
686  const_iterator __restrict__ i = m_data->Begin();
687  const_iterator __restrict__ j = m_data->End();
688  iterator __restrict__ k = R.Begin();
689  PCL_IVDEP
690  for ( ; i < j; ++i, ++k )
691  *k = -*i;
692  return R;
693  }
694 
701  void ReverseSign()
702  {
703  if ( IsUnique() )
704  {
705  iterator __restrict__ i = m_data->Begin();
706  const_iterator __restrict__ j = m_data->End();
707  PCL_IVDEP
708  for ( ; i < j; ++i )
709  *i = -*i;
710  }
711  else
712  {
713  Data* newData = new Data( m_data->Length() );
714  const_iterator __restrict__ i = m_data->Begin();
715  const_iterator __restrict__ j = m_data->End();
716  iterator __restrict__ k = newData->Begin();
717  PCL_IVDEP
718  for ( ; i < j; ++i, ++k )
719  *k = -*i;
720  DetachFromData();
721  m_data = newData;
722  }
723  }
724 
731  {
732  GenericVector R( m_data->Length() );
733  const_iterator __restrict__ i = m_data->Begin();
734  const_iterator __restrict__ j = m_data->End();
735  iterator __restrict__ k = R.Begin();
736  PCL_IVDEP
737  for ( ; i < j; ++i, ++k )
738  *k = *i * *i;
739  return R;
740  }
741 
748  void SetSqr()
749  {
750  if ( IsUnique() )
751  {
752  iterator __restrict__ i = m_data->Begin();
753  const_iterator __restrict__ j = m_data->End();
754  PCL_IVDEP
755  for ( ; i < j; ++i )
756  *i *= *i;
757  }
758  else
759  {
760  Data* newData = new Data( m_data->Length() );
761  const_iterator __restrict__ i = m_data->Begin();
762  const_iterator __restrict__ j = m_data->End();
763  iterator __restrict__ k = newData->Begin();
764  PCL_IVDEP
765  for ( ; i < j; ++i, ++k )
766  *k = *i * *i;
767  DetachFromData();
768  m_data = newData;
769  }
770  }
771 
778  {
779  GenericVector R( m_data->Length() );
780  const_iterator __restrict__ i = m_data->Begin();
781  const_iterator __restrict__ j = m_data->End();
782  iterator __restrict__ k = R.Begin();
783  PCL_IVDEP
784  for ( ; i < j; ++i, ++k )
785  *k = pcl::Sqrt( *i );
786  return R;
787  }
788 
795  void SetSqrt()
796  {
797  if ( IsUnique() )
798  {
799  iterator __restrict__ i = m_data->Begin();
800  const_iterator __restrict__ j = m_data->End();
801  for ( ; i < j; ++i )
802  *i = pcl::Sqrt( *i );
803  }
804  else
805  {
806  Data* newData = new Data( m_data->Length() );
807  const_iterator __restrict__ i = m_data->Begin();
808  const_iterator __restrict__ j = m_data->End();
809  iterator __restrict__ k = newData->Begin();
810  PCL_IVDEP
811  for ( ; i < j; ++i, ++k )
812  *k = pcl::Sqrt( *i );
813  DetachFromData();
814  m_data = newData;
815  }
816  }
817 
824  {
825  GenericVector R( m_data->Length() );
826  const_iterator __restrict__ i = m_data->Begin();
827  const_iterator __restrict__ j = m_data->End();
828  iterator __restrict__ k = R.Begin();
829  PCL_IVDEP
830  for ( ; i < j; ++i, ++k )
831  *k = pcl::Abs( *i );
832  return R;
833  }
834 
841  void SetAbs()
842  {
843  if ( IsUnique() )
844  {
845  iterator __restrict__ i = m_data->Begin();
846  const_iterator __restrict__ j = m_data->End();
847  PCL_IVDEP
848  for ( ; i < j; ++i )
849  *i = pcl::Abs( *i );
850  }
851  else
852  {
853  Data* newData = new Data( m_data->Length() );
854  const_iterator __restrict__ i = m_data->Begin();
855  const_iterator __restrict__ j = m_data->End();
856  iterator __restrict__ k = newData->Begin();
857  PCL_IVDEP
858  for ( ; i < j; ++i, ++k )
859  *k = pcl::Abs( *i );
860  DetachFromData();
861  m_data = newData;
862  }
863  }
864 
875  scalar Norm( double p ) const noexcept
876  {
877  return pcl::Norm( m_data->Begin(), m_data->End(), p );
878  }
879 
884  scalar L1Norm() const noexcept
885  {
886  return pcl::L1Norm( m_data->Begin(), m_data->End() );
887  }
888 
893  scalar L2Norm() const noexcept
894  {
895  return pcl::L2Norm( m_data->Begin(), m_data->End() );
896  }
897 
902  scalar Norm() const noexcept
903  {
904  return L2Norm();
905  }
906 
912  {
913  GenericVector R( *this );
914  scalar N = L2Norm();
915  if ( scalar( 1 ) + N > scalar( 1 ) )
916  R /= N;
917  return R;
918  }
919 
924  void SetUnit()
925  {
926  scalar N = L2Norm();
927  if ( scalar( 1 ) + N > scalar( 1 ) )
928  (void)operator /=( N );
929  }
930 
934  void Sort()
935  {
936  EnsureUnique();
937  pcl::Sort( m_data->Begin(), m_data->End() );
938  }
939 
944  {
945  GenericVector R( *this );
946  R.Sort();
947  return R;
948  }
949 
953  void ReverseSort()
954  {
955  EnsureUnique();
956  pcl::Sort( m_data->Begin(), m_data->End(),
957  []( const scalar& a, const scalar& b ){ return b < a; } );
958  }
959 
964  {
965  GenericVector R( *this );
966  R.ReverseSort();
967  return R;
968  }
969 
976  template <class BP>
977  void Sort( BP p )
978  {
979  EnsureUnique();
980  pcl::Sort( m_data->Begin(), m_data->End(), p );
981  }
982 
987  template <class BP>
988  GenericVector Sorted( BP p ) const
989  {
990  GenericVector R( *this );
991  R.Sort( p );
992  return R;
993  }
994 
999  int Find( const component& x ) const noexcept
1000  {
1001  const_iterator p = pcl::LinearSearch( m_data->Begin(), m_data->End(), x );
1002  return (p != m_data->End()) ? int( p - m_data->Begin() ) : -1;
1003  }
1004 
1010  int FindFirst( const component& x ) const noexcept
1011  {
1012  return Find( x );
1013  }
1014 
1019  int FindLast( const component& x ) const noexcept
1020  {
1021  const_iterator p = pcl::LinearSearchLast( m_data->Begin(), m_data->End(), x );
1022  return (p != m_data->End()) ? int( p - m_data->Begin() ) : -1;
1023  }
1024 
1028  bool Contains( const component& x ) const noexcept
1029  {
1030  return pcl::LinearSearch( m_data->Begin(), m_data->End(), x ) != m_data->End();
1031  }
1032 
1033 #ifndef __PCL_NO_VECTOR_STATISTICS
1034 
1042  int IndexOfSmallestComponent() const noexcept
1043  {
1044  return int( pcl::MinItem( m_data->Begin(), m_data->End() ) - m_data->Begin() );
1045  }
1046 
1054  int IndexOfLargestComponent() const noexcept
1055  {
1056  return int( pcl::MaxItem( m_data->Begin(), m_data->End() ) - m_data->Begin() );
1057  }
1058 
1067  int IndexOfLastSmallestComponent() const noexcept
1068  {
1069  iterator i = m_data->Begin();
1070  if ( m_data->Length() > 0 )
1071  for ( iterator j = m_data->Begin(); ++j < m_data->End(); )
1072  if ( *j <= *i )
1073  i = j;
1074  return i - m_data->Begin();
1075  }
1076 
1085  int IndexOfLastLargestComponent() const noexcept
1086  {
1087  iterator i = m_data->Begin();
1088  if ( m_data->Length() > 0 )
1089  for ( iterator j = m_data->Begin(); ++j < m_data->End(); )
1090  if ( *i <= *j )
1091  i = j;
1092  return i - m_data->Begin();
1093  }
1094 
1102  int IndexOfSmallestNonzeroComponent() const noexcept
1103  {
1104  iterator i = m_data->Begin();
1105  if ( m_data->Length() > 0 )
1106  {
1107  while ( *i == component( 0 ) )
1108  if ( ++i == m_data->End() )
1109  return m_data->Length();
1110  for ( iterator j = i; ++j < m_data->End(); )
1111  if ( *j != component( 0 ) )
1112  if ( *j < *i )
1113  i = j;
1114  }
1115  return i - m_data->Begin();
1116  }
1117 
1127  {
1128  iterator i = m_data->Begin();
1129  if ( m_data->Length() > 0 )
1130  {
1131  while ( *i == component( 0 ) )
1132  if ( ++i == m_data->End() )
1133  return m_data->Length();
1134  for ( iterator j = i; ++j < m_data->End(); )
1135  if ( *j != component( 0 ) )
1136  if ( *j <= *i )
1137  i = j;
1138  }
1139  return i - m_data->Begin();
1140  }
1141 
1146  component MinComponent() const noexcept
1147  {
1148  if ( m_data->Length() > 0 )
1149  return *pcl::MinItem( m_data->Begin(), m_data->End() );
1150  return component( 0 );
1151  }
1152 
1157  component MaxComponent() const noexcept
1158  {
1159  if ( m_data->Length() > 0 )
1160  return *pcl::MaxItem( m_data->Begin(), m_data->End() );
1161  return component( 0 );
1162  }
1163 
1181  {
1182  PCL_PRECONDITION( !IsEmpty() )
1183  PCL_PRECONDITION( k >= 0 && k < m_data->Length() )
1184  EnsureUnique();
1185  return *pcl::Select( m_data->Begin(), m_data->End(), k );
1186  }
1187 
1203  component OrderStatistic( int k ) const
1204  {
1205  return GenericVector( *this ).OrderStatistic( k );
1206  }
1207 
1212  double Sum() const noexcept
1213  {
1214  return pcl::Sum( m_data->Begin(), m_data->End() );
1215  }
1216 
1223  double StableSum() const noexcept
1224  {
1225  return pcl::StableSum( m_data->Begin(), m_data->End() );
1226  }
1227 
1232  double Modulus() const noexcept
1233  {
1234  return pcl::Modulus( m_data->Begin(), m_data->End() );
1235  }
1236 
1243  double StableModulus() const noexcept
1244  {
1245  return pcl::StableModulus( m_data->Begin(), m_data->End() );
1246  }
1247 
1252  double SumOfSquares() const noexcept
1253  {
1254  return pcl::SumOfSquares( m_data->Begin(), m_data->End() );
1255  }
1256 
1263  double StableSumOfSquares() const noexcept
1264  {
1265  return pcl::StableSumOfSquares( m_data->Begin(), m_data->End() );
1266  }
1267 
1272  double Mean() const
1273  {
1274  return pcl::Mean( m_data->Begin(), m_data->End() );
1275  }
1276 
1283  double StableMean() const noexcept
1284  {
1285  return pcl::StableMean( m_data->Begin(), m_data->End() );
1286  }
1287 
1295  double TrimmedMean( distance_type l = 1, distance_type h = 1 ) const noexcept
1296  {
1297  return pcl::TrimmedMean( m_data->Begin(), m_data->End(), l, h );
1298  }
1299 
1307  double TrimmedMeanOfSquares( distance_type l = 1, distance_type h = 1 ) const noexcept
1308  {
1309  return pcl::TrimmedMeanOfSquares( m_data->Begin(), m_data->End(), l, h );
1310  }
1311 
1317  double Variance() const noexcept
1318  {
1319  return pcl::Variance( m_data->Begin(), m_data->End() );
1320  }
1321 
1328  double StdDev() const noexcept
1329  {
1330  return pcl::StdDev( m_data->Begin(), m_data->End() );
1331  }
1332 
1338  double Median() const
1339  {
1340  return pcl::Median( m_data->Begin(), m_data->End() );
1341  }
1342 
1357  double AvgDev( double center ) const noexcept
1358  {
1359  return pcl::AvgDev( m_data->Begin(), m_data->End(), center );
1360  }
1361 
1377  double StableAvgDev( double center ) const noexcept
1378  {
1379  return pcl::StableAvgDev( m_data->Begin(), m_data->End(), center );
1380  }
1381 
1394  double AvgDev() const
1395  {
1396  return pcl::AvgDev( m_data->Begin(), m_data->End() );
1397  }
1398 
1412  double StableAvgDev() const
1413  {
1414  return pcl::StableAvgDev( m_data->Begin(), m_data->End() );
1415  }
1416 
1423  TwoSidedEstimate TwoSidedAvgDev( double center ) const noexcept
1424  {
1425  return pcl::TwoSidedAvgDev( m_data->Begin(), m_data->End(), center );
1426  }
1427 
1434  {
1435  return pcl::TwoSidedAvgDev( m_data->Begin(), m_data->End() );
1436  }
1437 
1449  double MAD( double center ) const
1450  {
1451  return pcl::MAD( m_data->Begin(), m_data->End(), center );
1452  }
1453 
1464  double MAD() const
1465  {
1466  return pcl::MAD( m_data->Begin(), m_data->End() );
1467  }
1468 
1475  TwoSidedEstimate TwoSidedMAD( double center ) const
1476  {
1477  return pcl::TwoSidedMAD( m_data->Begin(), m_data->End(), center );
1478  }
1479 
1486  {
1487  return pcl::TwoSidedMAD( m_data->Begin(), m_data->End() );
1488  }
1489 
1524  double BiweightMidvariance( double center, double sigma, int k = 9, bool reducedLength = false ) const noexcept
1525  {
1526  return pcl::BiweightMidvariance( m_data->Begin(), m_data->End(), center, sigma, k, reducedLength );
1527  }
1528 
1557  double BiweightMidvariance( int k = 9, bool reducedLength = false ) const
1558  {
1559  double center = Median();
1560  return BiweightMidvariance( center, MAD( center ), k, reducedLength );
1561  }
1562 
1578  int k = 9, bool reducedLength = false ) const noexcept
1579  {
1580  return pcl::TwoSidedBiweightMidvariance( m_data->Begin(), m_data->End(), center, sigma, k, reducedLength );
1581  }
1582 
1589  TwoSidedEstimate TwoSidedBiweightMidvariance( int k = 9, bool reducedLength = false ) const
1590  {
1591  double center = Median();
1592  return TwoSidedBiweightMidvariance( center, TwoSidedMAD( center ), k, reducedLength );
1593  }
1594 
1617  double BendMidvariance( double center, double beta = 0.2 ) const
1618  {
1619  return pcl::BendMidvariance( m_data->Begin(), m_data->End(), center, beta );
1620  }
1621 
1641  double BendMidvariance( double beta = 0.2 ) const
1642  {
1643  return pcl::BendMidvariance( m_data->Begin(), m_data->End(), Median(), beta );
1644  }
1645 
1669  double Sn() const
1670  {
1671  GenericVector v( *this );
1672  return pcl::Sn( v.Begin(), v.End() );
1673  }
1674 
1697  double Qn() const
1698  {
1699  GenericVector v( *this );
1700  return pcl::Qn( v.Begin(), v.End() );
1701  }
1702 
1703 #endif // !__PCL_NO_VECTOR_STATISTICS
1704 
1713  uint64 Hash64( uint64 seed = 0 ) const noexcept
1714  {
1715  return pcl::Hash64( m_data->Begin(), m_data->Size(), seed );
1716  }
1717 
1726  uint32 Hash32( uint32 seed = 0 ) const noexcept
1727  {
1728  return pcl::Hash32( m_data->Begin(), m_data->Size(), seed );
1729  }
1730 
1735  uint64 Hash( uint64 seed = 0 ) const noexcept
1736  {
1737  return Hash64( seed );
1738  }
1739 
1743  bool IsUnique() const noexcept
1744  {
1745  return m_data->IsUnique();
1746  }
1747 
1752  bool IsAliasOf( const GenericVector& x ) const noexcept
1753  {
1754  return m_data == x.m_data;
1755  }
1756 
1765  {
1766  if ( !IsUnique() )
1767  {
1768  Data* newData = new Data( m_data->Length() );
1769  const_iterator __restrict__ i = m_data->Begin();
1770  const_iterator __restrict__ j = m_data->End();
1771  iterator __restrict__ k = newData->Begin();
1772  PCL_IVDEP
1773  for ( ; i < j; ++i, ++k )
1774  *k = *i;
1775  DetachFromData();
1776  m_data = newData;
1777  }
1778  }
1779 
1784  int Length() const noexcept
1785  {
1786  return m_data->Length();
1787  }
1788 
1793  size_type Size() const noexcept
1794  {
1795  return m_data->Size();
1796  }
1797 
1812  bool IsValid() const noexcept
1813  {
1814  return m_data != nullptr;
1815  }
1816 
1821  bool IsEmpty() const noexcept
1822  {
1823  return Length() == 0;
1824  }
1825 
1831  operator bool() const noexcept
1832  {
1833  return !IsEmpty();
1834  }
1835 
1841  bool operator ==( const GenericVector& x ) const noexcept
1842  {
1843  return IsAliasOf( x ) || SameLength( x ) && pcl::Equal( Begin(), x.Begin(), x.End() );
1844  }
1845 
1855  bool operator <( const GenericVector& x ) const noexcept
1856  {
1857  return !IsAliasOf( x ) && pcl::Compare( Begin(), End(), x.Begin(), x.End() ) < 0;
1858  }
1859 
1863  bool SameLength( const GenericVector& x ) const noexcept
1864  {
1865  return Length() == x.Length();
1866  }
1867 
1875  iterator At( int i )
1876  {
1877  EnsureUnique();
1878  return m_data->At( i );
1879  }
1880 
1885  const_iterator At( int i ) const noexcept
1886  {
1887  return m_data->At( i );
1888  }
1889 
1901  {
1902  EnsureUnique();
1903  return m_data->Begin();
1904  }
1905 
1913  const_iterator Begin() const noexcept
1914  {
1915  return m_data->Begin();
1916  }
1917 
1921  const_iterator ConstBegin() const noexcept
1922  {
1923  return Begin();
1924  }
1925 
1933  {
1934  return Begin();
1935  }
1936 
1943  const_iterator operator *() const noexcept
1944  {
1945  return Begin();
1946  }
1947 
1960  {
1961  EnsureUnique();
1962  return m_data->End();
1963  }
1964 
1973  const_iterator End() const noexcept
1974  {
1975  return m_data->End();
1976  }
1977 
1981  const_iterator ConstEnd() const noexcept
1982  {
1983  return End();
1984  }
1985 
1993  component& operator []( int i )
1994  {
1995  return *At( i );
1996  }
1997 
2002  const component& operator []( int i ) const noexcept
2003  {
2004  return *At( i );
2005  }
2006 
2025  iterator DataPtr() noexcept
2026  {
2027  return m_data->v;
2028  }
2029 
2040  iterator ComponentPtr( int i ) noexcept
2041  {
2042  return m_data->At( i );
2043  }
2044 
2045 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
2050  {
2051  return Begin();
2052  }
2053 
2057  const_iterator begin() const noexcept
2058  {
2059  return Begin();
2060  }
2061 
2066  {
2067  return End();
2068  }
2069 
2073  const_iterator end() const noexcept
2074  {
2075  return End();
2076  }
2077 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
2078 
2100  template <typename T1, typename T2>
2101  void ToSpherical( T1& lon, T2& lat ) const noexcept
2102  {
2103  PCL_PRECONDITION( Length() >= 3 )
2104  double x = *At( 0 );
2105  double y = *At( 1 );
2106  double z = *At( 2 );
2107  double m2 = x*x + y*y;
2108  lon = T1( (m2 == 0) ? 0.0 : ArcTan( y, x ) );
2109  lat = T2( (z == 0) ? 0.0 : ArcTan( z, pcl::Sqrt( m2 ) ) );
2110  }
2111 
2120  template <typename T1, typename T2>
2121  void ToSpherical2Pi( T1& lon, T2& lat ) const noexcept
2122  {
2123  ToSpherical( lon, lat );
2124  if ( lon < 0 )
2125  lon += TwoPi();
2126  }
2127 
2143  static GenericVector FromSpherical( double slon, double clon, double slat, double clat )
2144  {
2145  return GenericVector( clon*clat, slon*clat, slat );
2146  }
2147 
2161  template <typename T1, typename T2>
2162  static GenericVector FromSpherical( const T1& lon, const T2& lat )
2163  {
2164  double slon, clon, slat, clat;
2165  SinCos( double( lon ), slon, clon );
2166  SinCos( double( lat ), slat, clat );
2167  return FromSpherical( slon, clon, slat, clat );
2168  }
2169 
2180  template <typename T1>
2181  static GenericVector FromArray( const T1* a, int len )
2182  {
2183  return GenericVector( a, len );
2184  }
2185 
2197  double Angle2D( const GenericVector& v ) const noexcept
2198  {
2199  /*
2200  * https://stackoverflow.com/questions/14066933/direct-way-of-computing-clockwise-angle-between-2-vectors
2201  * https://stackoverflow.com/questions/243945/calculating-a-2d-vectors-cross-product
2202  */
2203  component x1 = *At( 0 );
2204  component y1 = *At( 1 );
2205  component x2 = v[0];
2206  component y2 = v[1];
2207  return ArcTan( x1*y2 - y1*x2, Dot( v ) );
2208  }
2209 
2221  double Angle3D( const GenericVector& v ) const noexcept
2222  {
2223  /*
2224  * https://stackoverflow.com/questions/14066933/direct-way-of-computing-clockwise-angle-between-2-vectors
2225  */
2226  return ArcTan( Cross( v ).L2Norm(), Dot( v ) );
2227  }
2228 
2242  double Angle3D( const GenericVector& v, const GenericVector& n ) const
2243  {
2244  /*
2245  * https://stackoverflow.com/questions/14066933/direct-way-of-computing-clockwise-angle-between-2-vectors
2246  */
2247  GenericVector c = Cross( v );
2248  return ArcTan( (((n * c) >= 0) ? 1 : -1) * c.L2Norm(), Dot( v ) );
2249  }
2250 
2267  template <class S, typename SP>
2268  S& ToSeparated( S& s, SP separator ) const
2269  {
2270  const_iterator i = m_data->Begin(), j = m_data->End();
2271  if ( i < j )
2272  {
2273  s.Append( S( *i ) );
2274  if ( ++i < j )
2275  do
2276  {
2277  s.Append( separator );
2278  s.Append( S( *i ) );
2279  }
2280  while ( ++i < j );
2281  }
2282  return s;
2283  }
2284 
2307  template <class S, typename SP, class AF>
2308  S& ToSeparated( S& s, SP separator, AF append ) const
2309  {
2310  const_iterator i = m_data->Begin(), j = m_data->End();
2311  if ( i < j )
2312  {
2313  append( s, S( *i ) );
2314  if ( ++i < j )
2315  {
2316  S p( separator );
2317  do
2318  {
2319  append( s, p );
2320  append( s, S( *i ) );
2321  }
2322  while ( ++i < j );
2323  }
2324  }
2325  return s;
2326  }
2327 
2336  template <class S>
2337  S& ToCommaSeparated( S& s ) const
2338  {
2339  return ToSeparated( s, ',' );
2340  }
2341 
2350  template <class S>
2351  S& ToSpaceSeparated( S& s ) const
2352  {
2353  return ToSeparated( s, ' ' );
2354  }
2355 
2364  template <class S>
2365  S& ToTabSeparated( S& s ) const
2366  {
2367  return ToSeparated( s, '\t' );
2368  }
2369 
2370 private:
2371 
2377  struct Data : public ReferenceCounter
2378  {
2379  int n = 0;
2380  component* v = nullptr;
2381 
2382  Data() = default;
2383 
2384  Data( int len )
2385  {
2386  if ( len > 0 )
2387  Allocate( len );
2388  }
2389 
2390  ~Data()
2391  {
2392  Deallocate();
2393  }
2394 
2395  int Length() const noexcept
2396  {
2397  return n;
2398  }
2399 
2400  size_type Size() const noexcept
2401  {
2402  return size_type( n )*sizeof( component );
2403  }
2404 
2405  iterator At( int i ) const noexcept
2406  {
2407  return v + i;
2408  }
2409 
2410  iterator Begin() const noexcept
2411  {
2412 // if ( likely( std::is_scalar<component>::value ) )
2413 // return reinterpret_cast<iterator>( PCL_ASSUME_ALIGNED_32( v ) );
2414  return v;
2415  }
2416 
2417  iterator End() const noexcept
2418  {
2419  return At( n );
2420  }
2421 
2422  void Allocate( int len )
2423  {
2424  n = len;
2425  if ( likely( std::is_scalar<component>::value ) )
2426  {
2427  v = reinterpret_cast<component*>( PCL_ALIGNED_MALLOC( Size(), 32 ) );
2428  if ( unlikely( v == nullptr ) )
2429  {
2430  n = 0;
2431  throw std::bad_alloc();
2432  }
2433  }
2434  else
2435  v = new component[ len ];
2436  }
2437 
2438  void Deallocate()
2439  {
2440  PCL_PRECONDITION( refCount == 0 )
2441  if ( likely( std::is_scalar<component>::value ) )
2442  PCL_ALIGNED_FREE( v );
2443  else
2444  delete [] v;
2445  v = nullptr;
2446  n = 0;
2447  }
2448  };
2449 
2454  Data* m_data = nullptr;
2455 
2460  void DetachFromData()
2461  {
2462  if ( !m_data->Detach() )
2463  delete m_data;
2464  }
2465 };
2466 
2467 // ----------------------------------------------------------------------------
2468 
2483 template <typename T> inline
2485 {
2486  int n = A.Length();
2487  if ( B.Length() < n )
2488  throw Error( "Invalid vector addition." );
2489  GenericVector<T> R( n );
2490  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2491  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2492  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2493  if ( likely( !A.IsAliasOf( B ) ) )
2494  {
2495  typename GenericVector<T>::const_iterator __restrict__ b = B.Begin();
2496  PCL_IVDEP
2497  for ( ; a < c; ++a, ++b, ++r )
2498  *r = *a + *b;
2499  }
2500  else
2501  {
2502  PCL_IVDEP
2503  for ( ; a < c; ++a, ++r )
2504  *r = *a + *a;
2505  }
2506  return R;
2507 }
2508 
2516 template <typename T> inline
2518 {
2519  A += B;
2520  return std::move( A );
2521 }
2522 
2530 template <typename T> inline
2532 {
2533  B += A;
2534  return std::move( B );
2535 }
2536 
2545 template <typename T> inline
2547 {
2548  A += B;
2549  return std::move( A );
2550 }
2551 
2556 template <typename T, typename S> inline
2558 {
2559  GenericVector<T> R( A.Length() );
2560  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2561  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2562  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2563  PCL_IVDEP
2564  for ( ; a < c; ++a, ++r )
2565  *r = *a + x;
2566  return R;
2567 }
2568 
2573 template <typename T, typename S> inline
2575 {
2576  A += typename GenericVector<T>::scalar( x );
2577  return std::move( A );
2578 }
2579 
2587 template <typename T, typename S> inline
2589 {
2590  return A + x;
2591 }
2592 
2600 template <typename T, typename S> inline
2602 {
2603  A += typename GenericVector<T>::scalar( x );
2604  return std::move( A );
2605 }
2606 
2607 // ----------------------------------------------------------------------------
2608 
2616 template <typename T> inline
2618 {
2619  int n = A.Length();
2620  if ( B.Length() < n )
2621  throw Error( "Invalid vector subtraction." );
2622 
2623  GenericVector<T> R( n );
2624  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2625  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2626  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2627  if ( likely( !A.IsAliasOf( B ) ) )
2628  {
2629  typename GenericVector<T>::const_iterator __restrict__ b = B.Begin();
2630  PCL_IVDEP
2631  for ( ; a < c; ++a, ++b, ++r )
2632  *r = *a - *b;
2633  }
2634  else
2635  {
2636  PCL_IVDEP
2637  for ( ; a < c; ++a, ++r )
2638  *r = *a - *a;
2639  }
2640  return R;
2641 }
2642 
2651 template <typename T> inline
2653 {
2654  A -= B;
2655  return std::move( A );
2656 }
2657 
2666 template <typename T> inline
2668 {
2669  if ( A.Length() < B.Length() )
2670  throw Error( "Invalid vector subtraction." );
2671 
2672  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2673  typename GenericVector<T>::iterator __restrict__ b = B.Begin();
2674  typename GenericVector<T>::const_iterator __restrict__ c = B.End();
2675  PCL_IVDEP
2676  for ( ; b < c; ++a, ++b )
2677  *b = *a - *b;
2678  return std::move( B );
2679 }
2680 
2689 template <typename T> inline
2691 {
2692  A -= B;
2693  return std::move( A );
2694 }
2695 
2700 template <typename T, typename S> inline
2702 {
2703  GenericVector<T> R( A.Length() );
2704  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2705  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2706  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2707  PCL_IVDEP
2708  for ( ; a < c; ++a, ++r )
2709  *r = *a - x;
2710  return R;
2711 }
2712 
2718 template <typename T, typename S> inline
2720 {
2721  A -= typename GenericVector<T>::scalar( x );
2722  return std::move( A );
2723 }
2724 
2733 template <typename T, typename S> inline
2735 {
2736  GenericVector<T> R( A.Length() );
2737  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2738  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2739  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2740  PCL_IVDEP
2741  for ( ; a < c; ++a, ++r )
2742  *r = x - *a;
2743  return R;
2744 }
2745 
2755 template <typename T, typename S> inline
2757 {
2758  typename GenericVector<T>::iterator __restrict__ a = A.Begin();
2759  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2760  PCL_IVDEP
2761  for ( ; a < c; ++a )
2762  *a = x - *a;
2763  return std::move( A );
2764 }
2765 
2766 // ----------------------------------------------------------------------------
2767 
2776 template <typename T> inline
2778 {
2779  PCL_PRECONDITION( A.Length() == 3 && B.Length() == 3 )
2780  return GenericVector<T>( A[1]*B[2] - A[2]*B[1],
2781  A[2]*B[0] - A[0]*B[2],
2782  A[0]*B[1] - A[1]*B[0] );
2783 }
2784 
2793 template <typename T> inline
2795 {
2796  T x = A[1]*B[2] - A[2]*B[1],
2797  y = A[2]*B[0] - A[0]*B[2],
2798  z = A[0]*B[1] - A[1]*B[0];
2799  typename GenericVector<T>::iterator a = A.Begin();
2800  a[0] = x; a[1] = y; a[2] = z;
2801  return std::move( A );
2802 }
2803 
2812 template <typename T> inline
2814 {
2815  T x = A[1]*B[2] - A[2]*B[1],
2816  y = A[2]*B[0] - A[0]*B[2],
2817  z = A[0]*B[1] - A[1]*B[0];
2818  typename GenericVector<T>::iterator b = B.Begin();
2819  b[0] = x; b[1] = y; b[2] = z;
2820  return std::move( B );
2821 }
2822 
2832 template <typename T> inline
2834 {
2835  T x = A[1]*B[2] - A[2]*B[1],
2836  y = A[2]*B[0] - A[0]*B[2],
2837  z = A[0]*B[1] - A[1]*B[0];
2838  typename GenericVector<T>::iterator a = A.Begin();
2839  a[0] = x; a[1] = y; a[2] = z;
2840  return std::move( A );
2841 }
2842 
2843 // ----------------------------------------------------------------------------
2844 
2853 template <typename T> inline
2854 T operator *( const GenericVector<T>& A, const GenericVector<T>& B ) noexcept
2855 {
2856  PCL_PRECONDITION( B.Length() >= A.Length() )
2857  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2858  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2859  T r = T( 0 );
2860  if ( likely( !A.IsAliasOf( B ) ) )
2861  {
2862  typename GenericVector<T>::const_iterator __restrict__ b = B.Begin();
2863  PCL_IVDEP
2864  for ( ; a < c; ++a, ++b )
2865  r += *a * *b;
2866  }
2867  else
2868  {
2869  PCL_IVDEP
2870  for ( ; a < c; ++a )
2871  r += *a * *a;
2872  }
2873  return r;
2874 }
2875 
2876 // ----------------------------------------------------------------------------
2877 
2882 template <typename T, typename S> inline
2884 {
2885  GenericVector<T> R( A.Length() );
2886  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2887  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2888  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2889  PCL_IVDEP
2890  for ( ; a < c; ++a, ++r )
2891  *r = *a * x;
2892  return R;
2893 }
2894 
2899 template <typename T, typename S> inline
2901 {
2902  A *= typename GenericVector<T>::scalar( x );
2903  return std::move( A );
2904 }
2905 
2913 template <typename T, typename S> inline
2915 {
2916  return A * x;
2917 }
2918 
2926 template <typename T, typename S> inline
2928 {
2929  A *= typename GenericVector<T>::scalar( x );
2930  return std::move( A );
2931 }
2932 
2933 // ----------------------------------------------------------------------------
2934 
2939 template <typename T, typename S> inline
2941 {
2942  GenericVector<T> R( A.Length() );
2943  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2944  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2945  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2946  PCL_IVDEP
2947  for ( ; a < c; ++a, ++r )
2948  *r = *a / x;
2949  return R;
2950 }
2951 
2957 template <typename T, typename S> inline
2959 {
2960  A /= typename GenericVector<T>::scalar( x );
2961  return std::move( A );
2962 }
2963 
2971 template <typename T, typename S> inline
2973 {
2974  GenericVector<T> R( A.Length() );
2975  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2976  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2977  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2978  PCL_IVDEP
2979  for ( ; a < c; ++a, ++r )
2980  *r = x / *a;
2981  return R;
2982 }
2983 
2992 template <typename T, typename S> inline
2994 {
2995  typename GenericVector<T>::iterator __restrict__ a = A.Begin();
2996  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2997  PCL_IVDEP
2998  for ( ; a < c; ++a )
2999  *a = x / *a;
3000  return std::move( A );
3001 }
3002 
3008 template <typename T> inline
3010 {
3011  int n = A.Length();
3012  if ( B.Length() < n )
3013  throw Error( "Invalid vector division." );
3014 
3015  GenericVector<T> R( n );
3016  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
3017  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
3018  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
3019  if ( likely( !A.IsAliasOf( B ) ) )
3020  {
3021  typename GenericVector<T>::const_iterator __restrict__ b = B.Begin();
3022  PCL_IVDEP
3023  for ( ; a < c; ++a, ++b, ++r )
3024  *r = *a / *b;
3025  }
3026  else
3027  {
3028  PCL_IVDEP
3029  for ( ; a < c; ++a, ++r )
3030  *r = *a / *a;
3031  }
3032  return R;
3033 }
3034 
3040 template <typename T> inline
3042 {
3043  return A /= B;
3044 }
3045 
3046 // ----------------------------------------------------------------------------
3047 
3052 template <typename T, typename S> inline
3054 {
3055  GenericVector<T> R( A.Length() );
3056  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
3057  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
3058  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
3059  PCL_IVDEP
3060  for ( ; a < c; ++a, ++r )
3061  *r = pcl::Pow( *a, x );
3062  return R;
3063 }
3064 
3070 template <typename T, typename S> inline
3072 {
3073  A ^= typename GenericVector<T>::scalar( x );
3074  return std::move( A );
3075 }
3076 
3084 template <typename T, typename S> inline
3086 {
3087  GenericVector<T> R( A.Length() );
3088  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
3089  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
3090  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
3091  PCL_IVDEP
3092  for ( ; a < c; ++a, ++r )
3093  *r = pcl::Pow( x, *a );
3094  return R;
3095 }
3096 
3105 template <typename T, typename S> inline
3107 {
3108  typename GenericVector<T>::iterator __restrict__ a = A.Begin();
3109  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
3110  PCL_IVDEP
3111  for ( ; a < c; ++a )
3112  *a = pcl::Pow( x, *a );
3113  return std::move( A );
3114 }
3115 
3116 // ----------------------------------------------------------------------------
3117 
3118 #ifndef __PCL_NO_VECTOR_INSTANTIATE
3119 
3131 using I8Vector = GenericVector<int8>;
3132 
3141 using CharVector = I8Vector;
3142 
3150 using UI8Vector = GenericVector<uint8>;
3151 
3160 using ByteVector = UI8Vector;
3161 
3169 using I16Vector = GenericVector<int16>;
3170 
3178 using UI16Vector = GenericVector<uint16>;
3179 
3187 using I32Vector = GenericVector<int32>;
3188 
3197 using IVector = I32Vector;
3198 
3206 using UI32Vector = GenericVector<uint32>;
3207 
3216 using UIVector = UI32Vector;
3217 
3225 using I64Vector = GenericVector<int64>;
3226 
3234 using UI64Vector = GenericVector<uint64>;
3235 
3243 using SzVector = GenericVector<size_type>;
3244 
3252 using F32Vector = GenericVector<float>;
3253 
3262 using FVector = F32Vector;
3263 
3271 using F64Vector = GenericVector<double>;
3272 
3281 using DVector = F64Vector;
3282 
3291 using Vector = DVector;
3292 
3300 using C32Vector = GenericVector<Complex32>;
3301 
3309 using C64Vector = GenericVector<Complex64>;
3310 
3311 #ifndef _MSC_VER
3312 
3324 using F80Vector = GenericVector<long double>;
3325 
3337 using LDVector = F80Vector;
3338 
3339 #endif // !_MSC_VER
3340 
3341 #endif // !__PCL_NO_VECTOR_INSTANTIATE
3342 
3343 // ----------------------------------------------------------------------------
3344 
3345 } // pcl
3346 
3347 #endif // __PCL_Vector_h
3348 
3349 // ----------------------------------------------------------------------------
3350 // EOF pcl/Vector.h - Released 2024-06-18T15:48:54Z
8-bit unsigned integer vector.
32-bit floating point complex vector.
64-bit floating point complex vector.
8-bit signed integer vector.
64-bit floating point real vector.
Root base class of all PCL containers of objects.
Definition: Container.h:78
A simple exception with an associated error message.
Definition: Exception.h:239
32-bit floating point real vector.
64-bit floating point real vector.
80-bit extended precision floating point real vector.
32-bit floating point real vector.
Generic vector of arbitrary length.
Definition: Vector.h:107
double Qn() const
Definition: Vector.h:1697
double Sn() const
Definition: Vector.h:1669
void Transfer(GenericVector &x)
Definition: Vector.h:354
double Angle2D(const GenericVector &v) const noexcept
Definition: Vector.h:2197
double StdDev() const noexcept
Definition: Vector.h:1328
GenericVector(const T1 *a, int len)
Definition: Vector.h:181
double TrimmedMeanOfSquares(distance_type l=1, distance_type h=1) const noexcept
Definition: Vector.h:1307
double MAD() const
Definition: Vector.h:1464
double BendMidvariance(double beta=0.2) const
Definition: Vector.h:1641
TwoSidedEstimate TwoSidedBiweightMidvariance(double center, const TwoSidedEstimate &sigma, int k=9, bool reducedLength=false) const noexcept
Definition: Vector.h:1577
scalar L1Norm() const noexcept
Definition: Vector.h:884
void Transfer(GenericVector &&x)
Definition: Vector.h:373
static GenericVector FromSpherical(double slon, double clon, double slat, double clat)
Definition: Vector.h:2143
double BiweightMidvariance(double center, double sigma, int k=9, bool reducedLength=false) const noexcept
Definition: Vector.h:1524
const_iterator end() const noexcept
Definition: Vector.h:2073
component OrderStatistic(int k)
Definition: Vector.h:1180
double Angle3D(const GenericVector &v) const noexcept
Definition: Vector.h:2221
const_iterator ConstEnd() const noexcept
Definition: Vector.h:1981
virtual ~GenericVector()
Definition: Vector.h:276
bool IsUnique() const noexcept
Definition: Vector.h:1743
double SumOfSquares() const noexcept
Definition: Vector.h:1252
void ToSpherical(T1 &lon, T2 &lat) const noexcept
Definition: Vector.h:2101
size_type Size() const noexcept
Definition: Vector.h:1793
GenericVector Sorted() const
Definition: Vector.h:943
int IndexOfLastLargestComponent() const noexcept
Definition: Vector.h:1085
double Angle3D(const GenericVector &v, const GenericVector &n) const
Definition: Vector.h:2242
component MaxComponent() const noexcept
Definition: Vector.h:1157
TwoSidedEstimate TwoSidedMAD() const
Definition: Vector.h:1485
int FindFirst(const component &x) const noexcept
Definition: Vector.h:1010
GenericVector Sqrt() const
Definition: Vector.h:777
iterator At(int i)
Definition: Vector.h:1875
double StableSum() const noexcept
Definition: Vector.h:1223
double StableAvgDev(double center) const noexcept
Definition: Vector.h:1377
GenericVector Cross(const GenericVector &v2) const
Definition: Vector.h:665
GenericVector(std::initializer_list< T1 > c)
Definition: Vector.h:205
static GenericVector FromArray(const T1 *a, int len)
Definition: Vector.h:2181
int IndexOfLastSmallestNonzeroComponent() const noexcept
Definition: Vector.h:1126
int FindLast(const component &x) const noexcept
Definition: Vector.h:1019
scalar Norm(double p) const noexcept
Definition: Vector.h:875
bool IsEmpty() const noexcept
Definition: Vector.h:1821
double StableModulus() const noexcept
Definition: Vector.h:1243
uint64 Hash64(uint64 seed=0) const noexcept
Definition: Vector.h:1713
void SetSqrt()
Definition: Vector.h:795
GenericVector Sorted(BP p) const
Definition: Vector.h:988
iterator Begin()
Definition: Vector.h:1900
GenericVector Unit() const
Definition: Vector.h:911
void ReverseSort()
Definition: Vector.h:953
int IndexOfLargestComponent() const noexcept
Definition: Vector.h:1054
int IndexOfSmallestNonzeroComponent() const noexcept
Definition: Vector.h:1102
int Find(const component &x) const noexcept
Definition: Vector.h:999
friend void Swap(GenericVector &x1, GenericVector &x2) noexcept
Definition: Vector.h:386
double StableSumOfSquares() const noexcept
Definition: Vector.h:1263
const T * const_iterator
Definition: Vector.h:128
bool IsValid() const noexcept
Definition: Vector.h:1812
component MinComponent() const noexcept
Definition: Vector.h:1146
uint64 Hash(uint64 seed=0) const noexcept
Definition: Vector.h:1735
double Variance() const noexcept
Definition: Vector.h:1317
void Assign(const GenericVector &x)
Definition: Vector.h:324
iterator End()
Definition: Vector.h:1959
const_iterator Begin() const noexcept
Definition: Vector.h:1913
scalar Dot(const GenericVector &v) const noexcept
Definition: Vector.h:645
double MAD(double center) const
Definition: Vector.h:1449
GenericVector Sqr() const
Definition: Vector.h:730
uint32 Hash32(uint32 seed=0) const noexcept
Definition: Vector.h:1726
GenericVector(GenericVector &&x)
Definition: Vector.h:252
void SetUnit()
Definition: Vector.h:924
static GenericVector FromSpherical(const T1 &lon, const T2 &lat)
Definition: Vector.h:2162
double BiweightMidvariance(int k=9, bool reducedLength=false) const
Definition: Vector.h:1557
scalar L2Norm() const noexcept
Definition: Vector.h:893
iterator ComponentPtr(int i) noexcept
Definition: Vector.h:2040
int Length() const noexcept
Definition: Vector.h:1784
GenericVector(const GenericVector< T1 > &x)
Definition: Vector.h:267
TwoSidedEstimate TwoSidedAvgDev() const
Definition: Vector.h:1433
TwoSidedEstimate TwoSidedBiweightMidvariance(int k=9, bool reducedLength=false) const
Definition: Vector.h:1589
TwoSidedEstimate TwoSidedAvgDev(double center) const noexcept
Definition: Vector.h:1423
void ToSpherical2Pi(T1 &lon, T2 &lat) const noexcept
Definition: Vector.h:2121
const_iterator End() const noexcept
Definition: Vector.h:1973
void Sort(BP p)
Definition: Vector.h:977
GenericVector ReverseSorted() const
Definition: Vector.h:963
GenericVector(const T1 &x, const T1 &y, const T1 &z)
Definition: Vector.h:215
double Median() const
Definition: Vector.h:1338
double Mean() const
Definition: Vector.h:1272
scalar Norm() const noexcept
Definition: Vector.h:902
void EnsureUnique()
Definition: Vector.h:1764
iterator DataPtr() noexcept
Definition: Vector.h:2025
void ReverseSign()
Definition: Vector.h:701
double StableAvgDev() const
Definition: Vector.h:1412
double AvgDev() const
Definition: Vector.h:1394
double Sum() const noexcept
Definition: Vector.h:1212
double TrimmedMean(distance_type l=1, distance_type h=1) const noexcept
Definition: Vector.h:1295
bool IsAliasOf(const GenericVector &x) const noexcept
Definition: Vector.h:1752
double Modulus() const noexcept
Definition: Vector.h:1232
GenericVector(const T1 &x, const T1 &y, const T1 &z, const T1 &t)
Definition: Vector.h:229
int IndexOfSmallestComponent() const noexcept
Definition: Vector.h:1042
double StableMean() const noexcept
Definition: Vector.h:1283
GenericVector(int len)
Definition: Vector.h:147
iterator begin()
Definition: Vector.h:2049
bool Contains(const component &x) const noexcept
Definition: Vector.h:1028
component OrderStatistic(int k) const
Definition: Vector.h:1203
TwoSidedEstimate TwoSidedMAD(double center) const
Definition: Vector.h:1475
const_iterator At(int i) const noexcept
Definition: Vector.h:1885
bool SameLength(const GenericVector &x) const noexcept
Definition: Vector.h:1863
iterator end()
Definition: Vector.h:2065
GenericVector Abs() const
Definition: Vector.h:823
double AvgDev(double center) const noexcept
Definition: Vector.h:1357
GenericVector(const component &x, int len)
Definition: Vector.h:159
GenericVector(const GenericVector &x)
Definition: Vector.h:243
const_iterator ConstBegin() const noexcept
Definition: Vector.h:1921
int IndexOfLastSmallestComponent() const noexcept
Definition: Vector.h:1067
double BendMidvariance(double center, double beta=0.2) const
Definition: Vector.h:1617
const_iterator begin() const noexcept
Definition: Vector.h:2057
16-bit signed integer vector.
32-bit signed integer vector.
64-bit integer vector.
8-bit signed integer vector.
32-bit signed integer vector.
80-bit extended precision floating point real vector.
Thread-safe reference counter for copy-on-write data structures.
size_type integer vector.
16-bit unsigned integer vector.
32-bit unsigned integer vector.
64-bit unsigned integer vector.
8-bit unsigned integer vector.
32-bit unsigned integer vector.
64-bit floating point real vector.
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2267
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2278
Complex< T1 > operator-(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:504
Complex< T1 > operator*(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:548
Complex< T1 > operator+(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:464
Complex< T1 > operator/(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:592
Complex< T1 > Pow(const Complex< T1 > &c, T2 x) noexcept
Definition: Complex.h:747
Complex< T > Sqrt(const Complex< T > &c) noexcept
Definition: Complex.h:674
T Abs(const Complex< T > &c) noexcept
Definition: Complex.h:429
uint64 Hash64(const void *data, size_type size, uint64 seed=0) noexcept
Definition: Math.h:4750
uint32 Hash32(const void *data, size_type size, uint32 seed=0) noexcept
Definition: Math.h:4904
GenericImage< P > operator^(const GenericImage< P > &image, T scalar)
Definition: Image.h:17571
void SinCos(T x, T &sx, T &cx) noexcept
Definition: Math.h:1030
T L1Norm(const T *i, const T *j) noexcept
Definition: Math.h:2194
constexpr T ArcTan(T x) noexcept
Definition: Math.h:526
constexpr long double TwoPi() noexcept
Definition: Math.h:470
T Norm(const T *i, const T *j, const P &p) noexcept
Definition: Math.h:2135
T L2Norm(const T *i, const T *j) noexcept
Definition: Math.h:2253
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2) noexcept
Definition: Point.h:1459
unsigned long long uint64
Definition: Defs.h:682
unsigned int uint32
Definition: Defs.h:666
FI LinearSearch(FI i, FI j, const T &v) noexcept
Definition: Search.h:91
BI LinearSearchLast(BI i, BI j, const T &v) noexcept
Definition: Search.h:129
RI Select(RI i, RI j, distance_type k)
Definition: Selection.h:165
ptrdiff_t distance_type
Definition: Defs.h:615
size_t size_type
Definition: Defs.h:609
void Sort(BI i, BI j)
Definition: Sort.h:520
double Qn(T *__restrict__ x, T *__restrict__ xn)
Definition: Math.h:4170
double BendMidvariance(const T *__restrict__ x, const T *__restrict__ xn, double center, double beta=0.2)
Definition: Math.h:4480
TwoSidedEstimate TwoSidedMAD(const T *__restrict__ i, const T *__restrict__ j, double center)
Definition: Math.h:3837
double MAD(const T *__restrict__ i, const T *__restrict__ j, double center)
Definition: Math.h:3776
double StableModulus(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2636
double SumOfSquares(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2661
double StableMean(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2728
double TrimmedMean(const T *__restrict__ i, const T *__restrict__ j, distance_type l=1, distance_type h=1)
Definition: Math.h:3242
double StableSum(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2592
double Variance(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:2753
TwoSidedEstimate TwoSidedBiweightMidvariance(const T *__restrict__ x, const T *__restrict__ xn, double center, const TwoSidedEstimate &sigma, int k=9, bool reducedLength=false) noexcept
Definition: Math.h:4404
double Sum(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2573
double StableSumOfSquares(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2683
double BiweightMidvariance(const T *__restrict__ x, const T *__restrict__ xn, double center, double sigma, int k=9, bool reducedLength=false) noexcept
Definition: Math.h:4341
double StdDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:2813
double TrimmedMeanOfSquares(const T *__restrict__ i, const T *__restrict__ j, distance_type l=1, distance_type h=1)
Definition: Math.h:3319
double AvgDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:3404
double Mean(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2709
double StableAvgDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:3436
double Median(const T *__restrict__ i, const T *__restrict__ j)
Definition: Math.h:2878
TwoSidedEstimate TwoSidedAvgDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:3717
double Modulus(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2617
double Sn(T *__restrict__ x, T *__restrict__ xn)
Definition: Math.h:3924
FI MinItem(FI i, FI j) noexcept
Definition: Utility.h:441
bool Equal(FI1 i1, FI2 i2, FI2 j2) noexcept
Definition: Utility.h:592
int Compare(FI1 i1, FI1 j1, FI2 i2, FI2 j2) noexcept
Definition: Utility.h:639
FI MaxItem(FI i, FI j) noexcept
Definition: Utility.h:479
PCL root namespace.
Definition: AbstractImage.h:77
Two-sided descriptive statistical estimate.
Definition: Math.h:3528