PCL
Vector.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.8.5
6 // ----------------------------------------------------------------------------
7 // pcl/Vector.h - Released 2024-12-28T16:53:48Z
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 
117 
121 
125  using scalar = T;
126 
130  using component = T;
131 
135  using iterator = T*;
136 
140  using const_iterator = const T*;
141 
147  {
148  m_data = new Data;
149  }
150 
159  GenericVector( int len )
160  {
161  PCL_PRECONDITION( len >= 0 )
162  m_data = new Data( len );
163  }
164 
171  GenericVector( const component& x, int len )
172  {
173  PCL_PRECONDITION( len >= 0 )
174  m_data = new Data( len );
175  iterator __restrict__ i = m_data->Begin();
176  const_iterator __restrict__ j = m_data->End();
177  PCL_IVDEP
178  for ( ; i < j; ++i )
179  *i = x;
180  }
181 
192  template <typename T1>
193  GenericVector( const T1* a, int len )
194  {
195  PCL_PRECONDITION( len >= 0 )
196  m_data = new Data( len );
197  if ( a != nullptr )
198  {
199  iterator __restrict__ i = m_data->Begin();
200  const_iterator __restrict__ j = m_data->End();
201  const T1* __restrict__ k = a;
202  PCL_IVDEP
203  for ( ; i < j; ++i, ++k )
204  *i = component( *k );
205  }
206  }
207 
216  template <typename T1>
217  GenericVector( std::initializer_list<T1> c )
218  : GenericVector( c.begin(), int( c.size() ) )
219  {
220  }
221 
226  template <typename T1>
227  GenericVector( const T1& x, const T1& y, const T1& z )
228  {
229  m_data = new Data( 3 );
230  iterator v = m_data->Begin();
231  *v++ = component( x );
232  *v++ = component( y );
233  *v = component( z );
234  }
235 
240  template <typename T1>
241  GenericVector( const T1& x, const T1& y, const T1& z, const T1& t )
242  {
243  m_data = new Data( 4 );
244  iterator v = m_data->Begin();
245  *v++ = component( x );
246  *v++ = component( y );
247  *v++ = component( z );
248  *v = component( t );
249  }
250 
256  : m_data( x.m_data )
257  {
258  m_data->Attach();
259  }
260 
265  : m_data( x.m_data )
266  {
267  x.m_data = nullptr;
268  }
269 
278  template <typename T1>
280  : GenericVector( x.Begin(), x.Length() )
281  {
282  }
283 
288  virtual ~GenericVector()
289  {
290  if ( m_data != nullptr )
291  {
292  DetachFromData();
293  m_data = nullptr;
294  }
295  }
296 
300  void Clear()
301  {
302  if ( !IsEmpty() )
303  if ( m_data->IsUnique() )
304  m_data->Deallocate();
305  else
306  {
307  Data* newData = new Data( 0 );
308  DetachFromData();
309  m_data = newData;
310  }
311  }
312 
318  GenericVector& operator =( const GenericVector& x )
319  {
320  Assign( x );
321  return *this;
322  }
323 
336  void Assign( const GenericVector& x )
337  {
338  x.m_data->Attach();
339  DetachFromData();
340  m_data = x.m_data;
341  }
342 
348  GenericVector& operator =( GenericVector&& x )
349  {
350  Transfer( x );
351  return *this;
352  }
353 
367  {
368  if ( &x != this )
369  {
370  DetachFromData();
371  m_data = x.m_data;
372  x.m_data = nullptr;
373  }
374  }
375 
389  {
390  if ( &x != this )
391  {
392  DetachFromData();
393  m_data = x.m_data;
394  x.m_data = nullptr;
395  }
396  }
397 
404  friend void Swap( GenericVector& x1, GenericVector& x2 ) noexcept
405  {
406  pcl::Swap( x1.m_data, x2.m_data );
407  }
408 
417  GenericVector& operator =( const scalar& x )
418  {
419  if ( !IsUnique() )
420  {
421  Data* newData = new Data( m_data->Length() );
422  DetachFromData();
423  m_data = newData;
424  }
425  iterator __restrict__ i = m_data->Begin();
426  const_iterator __restrict__ j = m_data->End();
427  PCL_IVDEP
428  for ( ; i < j; ++i )
429  *i = x;
430  return *this;
431  }
432 
446  GenericVector& operator +=( const GenericVector& x )
447  {
448  if ( x.Length() < Length() )
449  throw Error( "Invalid vector addition." );
450  EnsureUnique();
451  iterator __restrict__ i = m_data->Begin();
452  const_iterator __restrict__ j = m_data->End();
453  const_iterator __restrict__ k = x.Begin();
454  PCL_IVDEP
455  for ( ; i < j; ++i, ++k )
456  *i += *k;
457  return *this;
458  }
459 
473  GenericVector& operator -=( const GenericVector& x )
474  {
475  if ( x.Length() < Length() )
476  throw Error( "Invalid vector subtraction." );
477  EnsureUnique();
478  iterator __restrict__ i = m_data->Begin();
479  const_iterator __restrict__ j = m_data->End();
480  const_iterator __restrict__ k = x.Begin();
481  PCL_IVDEP
482  for ( ; i < j; ++i, ++k )
483  *i -= *k;
484  return *this;
485  }
486 
500  GenericVector& operator *=( const GenericVector& x )
501  {
502  if ( x.Length() < Length() )
503  throw Error( "Invalid vector multiplication." );
504  EnsureUnique();
505  iterator __restrict__ i = m_data->Begin();
506  const_iterator __restrict__ j = m_data->End();
507  const_iterator __restrict__ k = x.Begin();
508  PCL_IVDEP
509  for ( ; i < j; ++i, ++k )
510  *i *= *k;
511  return *this;
512  }
513 
531  GenericVector& operator /=( const GenericVector& x )
532  {
533  if ( x.Length() < Length() )
534  throw Error( "Invalid vector division." );
535  EnsureUnique();
536  iterator __restrict__ i = m_data->Begin();
537  const_iterator __restrict__ j = m_data->End();
538  const_iterator __restrict__ k = x.Begin();
539  PCL_IVDEP
540  for ( ; i < j; ++i, ++k )
541  *i /= *k;
542  return *this;
543  }
544 
545 #define IMPLEMENT_SCALAR_ASSIGN_OP( op ) \
546  if ( IsUnique() ) \
547  { \
548  iterator __restrict__ i = m_data->Begin(); \
549  const_iterator __restrict__ j = m_data->End(); \
550  PCL_IVDEP \
551  for ( ; i < j; ++i ) \
552  *i op##= x; \
553  } \
554  else \
555  { \
556  Data* newData = new Data( m_data->Length() ); \
557  const_iterator __restrict__ i = m_data->Begin(); \
558  const_iterator __restrict__ j = m_data->End(); \
559  iterator __restrict__ k = newData->Begin(); \
560  PCL_IVDEP \
561  for ( ; i < j; ++i, ++k ) \
562  *k = *i op x; \
563  DetachFromData(); \
564  m_data = newData; \
565  } \
566  return *this;
567 
576  GenericVector& operator +=( const scalar& x )
577  {
578  IMPLEMENT_SCALAR_ASSIGN_OP( + )
579  }
580 
589  GenericVector& operator -=( const scalar& x )
590  {
591  IMPLEMENT_SCALAR_ASSIGN_OP( - )
592  }
593 
602  GenericVector& operator *=( const scalar& x )
603  {
604  IMPLEMENT_SCALAR_ASSIGN_OP( * )
605  }
606 
615  GenericVector& operator /=( const scalar& x )
616  {
617  IMPLEMENT_SCALAR_ASSIGN_OP( / )
618  }
619 
628  GenericVector& operator ^=( const scalar& x )
629  {
630  if ( IsUnique() )
631  {
632  iterator __restrict__ i = m_data->Begin();
633  const_iterator __restrict__ j = m_data->End();
634  PCL_IVDEP
635  for ( ; i < j; ++i )
636  *i = pcl::Pow( *i, x );
637  }
638  else
639  {
640  Data* newData = new Data( m_data->Length() );
641  const_iterator __restrict__ i = m_data->Begin();
642  const_iterator __restrict__ j = m_data->End();
643  iterator __restrict__ k = newData->Begin();
644  PCL_IVDEP
645  for ( ; i < j; ++i, ++k )
646  *k = pcl::Pow( *i, x );
647  DetachFromData();
648  m_data = newData;
649  }
650  return *this;
651  }
652 
653 #undef IMPLEMENT_SCALAR_ASSIGN_OP
654 
663  scalar Dot( const GenericVector& v ) const noexcept
664  {
665  PCL_PRECONDITION( v.Length() >= Length() )
666  scalar r = scalar( 0 );
667  const_iterator __restrict__ i = m_data->Begin();
668  const_iterator __restrict__ j = m_data->End();
669  const_iterator __restrict__ k = v.Begin();
670  PCL_IVDEP
671  for ( ; i < j; ++i, ++k )
672  r += scalar( *i ) * scalar( *k );
673  return r;
674  }
675 
683  GenericVector Cross( const GenericVector& v2 ) const
684  {
685  PCL_PRECONDITION( Length() == 3 && v2.Length() == 3 )
686  component x1 = *At( 0 );
687  component y1 = *At( 1 );
688  component z1 = *At( 2 );
689  component x2 = v2[0];
690  component y2 = v2[1];
691  component z2 = v2[2];
692  return GenericVector( y1*z2 - z1*y2,
693  z1*x2 - x1*z2,
694  x1*y2 - y1*x2 );
695  }
696 
702  {
703  GenericVector R( m_data->Length() );
704  const_iterator __restrict__ i = m_data->Begin();
705  const_iterator __restrict__ j = m_data->End();
706  iterator __restrict__ k = R.Begin();
707  PCL_IVDEP
708  for ( ; i < j; ++i, ++k )
709  *k = -*i;
710  return R;
711  }
712 
719  void ReverseSign()
720  {
721  if ( IsUnique() )
722  {
723  iterator __restrict__ i = m_data->Begin();
724  const_iterator __restrict__ j = m_data->End();
725  PCL_IVDEP
726  for ( ; i < j; ++i )
727  *i = -*i;
728  }
729  else
730  {
731  Data* newData = new Data( m_data->Length() );
732  const_iterator __restrict__ i = m_data->Begin();
733  const_iterator __restrict__ j = m_data->End();
734  iterator __restrict__ k = newData->Begin();
735  PCL_IVDEP
736  for ( ; i < j; ++i, ++k )
737  *k = -*i;
738  DetachFromData();
739  m_data = newData;
740  }
741  }
742 
749  {
750  GenericVector R( m_data->Length() );
751  const_iterator __restrict__ i = m_data->Begin();
752  const_iterator __restrict__ j = m_data->End();
753  iterator __restrict__ k = R.Begin();
754  PCL_IVDEP
755  for ( ; i < j; ++i, ++k )
756  *k = *i * *i;
757  return R;
758  }
759 
766  void SetSqr()
767  {
768  if ( IsUnique() )
769  {
770  iterator __restrict__ i = m_data->Begin();
771  const_iterator __restrict__ j = m_data->End();
772  PCL_IVDEP
773  for ( ; i < j; ++i )
774  *i *= *i;
775  }
776  else
777  {
778  Data* newData = new Data( m_data->Length() );
779  const_iterator __restrict__ i = m_data->Begin();
780  const_iterator __restrict__ j = m_data->End();
781  iterator __restrict__ k = newData->Begin();
782  PCL_IVDEP
783  for ( ; i < j; ++i, ++k )
784  *k = *i * *i;
785  DetachFromData();
786  m_data = newData;
787  }
788  }
789 
796  {
797  GenericVector R( m_data->Length() );
798  const_iterator __restrict__ i = m_data->Begin();
799  const_iterator __restrict__ j = m_data->End();
800  iterator __restrict__ k = R.Begin();
801  PCL_IVDEP
802  for ( ; i < j; ++i, ++k )
803  *k = pcl::Sqrt( *i );
804  return R;
805  }
806 
813  void SetSqrt()
814  {
815  if ( IsUnique() )
816  {
817  iterator __restrict__ i = m_data->Begin();
818  const_iterator __restrict__ j = m_data->End();
819  for ( ; i < j; ++i )
820  *i = pcl::Sqrt( *i );
821  }
822  else
823  {
824  Data* newData = new Data( m_data->Length() );
825  const_iterator __restrict__ i = m_data->Begin();
826  const_iterator __restrict__ j = m_data->End();
827  iterator __restrict__ k = newData->Begin();
828  PCL_IVDEP
829  for ( ; i < j; ++i, ++k )
830  *k = pcl::Sqrt( *i );
831  DetachFromData();
832  m_data = newData;
833  }
834  }
835 
842  {
843  GenericVector R( m_data->Length() );
844  const_iterator __restrict__ i = m_data->Begin();
845  const_iterator __restrict__ j = m_data->End();
846  iterator __restrict__ k = R.Begin();
847  PCL_IVDEP
848  for ( ; i < j; ++i, ++k )
849  *k = pcl::Abs( *i );
850  return R;
851  }
852 
859  void SetAbs()
860  {
861  if ( IsUnique() )
862  {
863  iterator __restrict__ i = m_data->Begin();
864  const_iterator __restrict__ j = m_data->End();
865  PCL_IVDEP
866  for ( ; i < j; ++i )
867  *i = pcl::Abs( *i );
868  }
869  else
870  {
871  Data* newData = new Data( m_data->Length() );
872  const_iterator __restrict__ i = m_data->Begin();
873  const_iterator __restrict__ j = m_data->End();
874  iterator __restrict__ k = newData->Begin();
875  PCL_IVDEP
876  for ( ; i < j; ++i, ++k )
877  *k = pcl::Abs( *i );
878  DetachFromData();
879  m_data = newData;
880  }
881  }
882 
893  scalar Norm( double p ) const noexcept
894  {
895  return pcl::Norm( m_data->Begin(), m_data->End(), p );
896  }
897 
902  scalar L1Norm() const noexcept
903  {
904  return pcl::L1Norm( m_data->Begin(), m_data->End() );
905  }
906 
911  scalar L2Norm() const noexcept
912  {
913  return pcl::L2Norm( m_data->Begin(), m_data->End() );
914  }
915 
920  scalar Norm() const noexcept
921  {
922  return L2Norm();
923  }
924 
930  {
931  GenericVector R( *this );
932  scalar N = L2Norm();
933  if ( scalar( 1 ) + N > scalar( 1 ) )
934  R /= N;
935  return R;
936  }
937 
942  void SetUnit()
943  {
944  scalar N = L2Norm();
945  if ( scalar( 1 ) + N > scalar( 1 ) )
946  (void)operator /=( N );
947  }
948 
952  void Sort()
953  {
954  EnsureUnique();
955  pcl::Sort( m_data->Begin(), m_data->End() );
956  }
957 
962  {
963  GenericVector R( *this );
964  R.Sort();
965  return R;
966  }
967 
971  void ReverseSort()
972  {
973  EnsureUnique();
974  pcl::Sort( m_data->Begin(), m_data->End(),
975  []( const scalar& a, const scalar& b ){ return b < a; } );
976  }
977 
982  {
983  GenericVector R( *this );
984  R.ReverseSort();
985  return R;
986  }
987 
994  template <class BP>
995  void Sort( BP p )
996  {
997  EnsureUnique();
998  pcl::Sort( m_data->Begin(), m_data->End(), p );
999  }
1000 
1005  template <class BP>
1006  GenericVector Sorted( BP p ) const
1007  {
1008  GenericVector R( *this );
1009  R.Sort( p );
1010  return R;
1011  }
1012 
1017  int Find( const component& x ) const noexcept
1018  {
1019  const_iterator p = pcl::LinearSearch( m_data->Begin(), m_data->End(), x );
1020  return (p != m_data->End()) ? int( p - m_data->Begin() ) : -1;
1021  }
1022 
1028  int FindFirst( const component& x ) const noexcept
1029  {
1030  return Find( x );
1031  }
1032 
1037  int FindLast( const component& x ) const noexcept
1038  {
1039  const_iterator p = pcl::LinearSearchLast( m_data->Begin(), m_data->End(), x );
1040  return (p != m_data->End()) ? int( p - m_data->Begin() ) : -1;
1041  }
1042 
1046  bool Contains( const component& x ) const noexcept
1047  {
1048  return pcl::LinearSearch( m_data->Begin(), m_data->End(), x ) != m_data->End();
1049  }
1050 
1051 #ifndef __PCL_NO_VECTOR_STATISTICS
1052 
1060  int IndexOfSmallestComponent() const noexcept
1061  {
1062  return int( pcl::MinItem( m_data->Begin(), m_data->End() ) - m_data->Begin() );
1063  }
1064 
1072  int IndexOfLargestComponent() const noexcept
1073  {
1074  return int( pcl::MaxItem( m_data->Begin(), m_data->End() ) - m_data->Begin() );
1075  }
1076 
1085  int IndexOfLastSmallestComponent() 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 ( *j <= *i )
1091  i = j;
1092  return i - m_data->Begin();
1093  }
1094 
1103  int IndexOfLastLargestComponent() const noexcept
1104  {
1105  iterator i = m_data->Begin();
1106  if ( m_data->Length() > 0 )
1107  for ( iterator j = m_data->Begin(); ++j < m_data->End(); )
1108  if ( *i <= *j )
1109  i = j;
1110  return i - m_data->Begin();
1111  }
1112 
1120  int IndexOfSmallestNonzeroComponent() const noexcept
1121  {
1122  iterator i = m_data->Begin();
1123  if ( m_data->Length() > 0 )
1124  {
1125  while ( *i == component( 0 ) )
1126  if ( ++i == m_data->End() )
1127  return m_data->Length();
1128  for ( iterator j = i; ++j < m_data->End(); )
1129  if ( *j != component( 0 ) )
1130  if ( *j < *i )
1131  i = j;
1132  }
1133  return i - m_data->Begin();
1134  }
1135 
1145  {
1146  iterator i = m_data->Begin();
1147  if ( m_data->Length() > 0 )
1148  {
1149  while ( *i == component( 0 ) )
1150  if ( ++i == m_data->End() )
1151  return m_data->Length();
1152  for ( iterator j = i; ++j < m_data->End(); )
1153  if ( *j != component( 0 ) )
1154  if ( *j <= *i )
1155  i = j;
1156  }
1157  return i - m_data->Begin();
1158  }
1159 
1164  component MinComponent() const noexcept
1165  {
1166  if ( m_data->Length() > 0 )
1167  return *pcl::MinItem( m_data->Begin(), m_data->End() );
1168  return component( 0 );
1169  }
1170 
1175  component MaxComponent() const noexcept
1176  {
1177  if ( m_data->Length() > 0 )
1178  return *pcl::MaxItem( m_data->Begin(), m_data->End() );
1179  return component( 0 );
1180  }
1181 
1199  {
1200  PCL_PRECONDITION( !IsEmpty() )
1201  PCL_PRECONDITION( k >= 0 && k < m_data->Length() )
1202  EnsureUnique();
1203  return *pcl::Select( m_data->Begin(), m_data->End(), k );
1204  }
1205 
1221  component OrderStatistic( int k ) const
1222  {
1223  return GenericVector( *this ).OrderStatistic( k );
1224  }
1225 
1230  double Sum() const noexcept
1231  {
1232  return pcl::Sum( m_data->Begin(), m_data->End() );
1233  }
1234 
1241  double StableSum() const noexcept
1242  {
1243  return pcl::StableSum( m_data->Begin(), m_data->End() );
1244  }
1245 
1250  double Modulus() const noexcept
1251  {
1252  return pcl::Modulus( m_data->Begin(), m_data->End() );
1253  }
1254 
1261  double StableModulus() const noexcept
1262  {
1263  return pcl::StableModulus( m_data->Begin(), m_data->End() );
1264  }
1265 
1270  double SumOfSquares() const noexcept
1271  {
1272  return pcl::SumOfSquares( m_data->Begin(), m_data->End() );
1273  }
1274 
1281  double StableSumOfSquares() const noexcept
1282  {
1283  return pcl::StableSumOfSquares( m_data->Begin(), m_data->End() );
1284  }
1285 
1290  double Mean() const
1291  {
1292  return pcl::Mean( m_data->Begin(), m_data->End() );
1293  }
1294 
1301  double StableMean() const noexcept
1302  {
1303  return pcl::StableMean( m_data->Begin(), m_data->End() );
1304  }
1305 
1313  double TrimmedMean( distance_type l = 1, distance_type h = 1 ) const noexcept
1314  {
1315  return pcl::TrimmedMean( m_data->Begin(), m_data->End(), l, h );
1316  }
1317 
1325  double TrimmedMeanOfSquares( distance_type l = 1, distance_type h = 1 ) const noexcept
1326  {
1327  return pcl::TrimmedMeanOfSquares( m_data->Begin(), m_data->End(), l, h );
1328  }
1329 
1335  double Variance() const noexcept
1336  {
1337  return pcl::Variance( m_data->Begin(), m_data->End() );
1338  }
1339 
1346  double StdDev() const noexcept
1347  {
1348  return pcl::StdDev( m_data->Begin(), m_data->End() );
1349  }
1350 
1356  double Median() const
1357  {
1358  return pcl::Median( m_data->Begin(), m_data->End() );
1359  }
1360 
1375  double AvgDev( double center ) const noexcept
1376  {
1377  return pcl::AvgDev( m_data->Begin(), m_data->End(), center );
1378  }
1379 
1395  double StableAvgDev( double center ) const noexcept
1396  {
1397  return pcl::StableAvgDev( m_data->Begin(), m_data->End(), center );
1398  }
1399 
1412  double AvgDev() const
1413  {
1414  return pcl::AvgDev( m_data->Begin(), m_data->End() );
1415  }
1416 
1430  double StableAvgDev() const
1431  {
1432  return pcl::StableAvgDev( m_data->Begin(), m_data->End() );
1433  }
1434 
1441  TwoSidedEstimate TwoSidedAvgDev( double center ) const noexcept
1442  {
1443  return pcl::TwoSidedAvgDev( m_data->Begin(), m_data->End(), center );
1444  }
1445 
1452  {
1453  return pcl::TwoSidedAvgDev( m_data->Begin(), m_data->End() );
1454  }
1455 
1467  double MAD( double center ) const
1468  {
1469  return pcl::MAD( m_data->Begin(), m_data->End(), center );
1470  }
1471 
1482  double MAD() const
1483  {
1484  return pcl::MAD( m_data->Begin(), m_data->End() );
1485  }
1486 
1493  TwoSidedEstimate TwoSidedMAD( double center ) const
1494  {
1495  return pcl::TwoSidedMAD( m_data->Begin(), m_data->End(), center );
1496  }
1497 
1504  {
1505  return pcl::TwoSidedMAD( m_data->Begin(), m_data->End() );
1506  }
1507 
1542  double BiweightMidvariance( double center, double sigma, int k = 9, bool reducedLength = false ) const noexcept
1543  {
1544  return pcl::BiweightMidvariance( m_data->Begin(), m_data->End(), center, sigma, k, reducedLength );
1545  }
1546 
1575  double BiweightMidvariance( int k = 9, bool reducedLength = false ) const
1576  {
1577  double center = Median();
1578  return BiweightMidvariance( center, MAD( center ), k, reducedLength );
1579  }
1580 
1596  int k = 9, bool reducedLength = false ) const noexcept
1597  {
1598  return pcl::TwoSidedBiweightMidvariance( m_data->Begin(), m_data->End(), center, sigma, k, reducedLength );
1599  }
1600 
1607  TwoSidedEstimate TwoSidedBiweightMidvariance( int k = 9, bool reducedLength = false ) const
1608  {
1609  double center = Median();
1610  return TwoSidedBiweightMidvariance( center, TwoSidedMAD( center ), k, reducedLength );
1611  }
1612 
1635  double BendMidvariance( double center, double beta = 0.2 ) const
1636  {
1637  return pcl::BendMidvariance( m_data->Begin(), m_data->End(), center, beta );
1638  }
1639 
1659  double BendMidvariance( double beta = 0.2 ) const
1660  {
1661  return pcl::BendMidvariance( m_data->Begin(), m_data->End(), Median(), beta );
1662  }
1663 
1687  double Sn() const
1688  {
1689  GenericVector v( *this );
1690  return pcl::Sn( v.Begin(), v.End() );
1691  }
1692 
1715  double Qn() const
1716  {
1717  GenericVector v( *this );
1718  return pcl::Qn( v.Begin(), v.End() );
1719  }
1720 
1721 #endif // !__PCL_NO_VECTOR_STATISTICS
1722 
1731  uint64 Hash64( uint64 seed = 0 ) const noexcept
1732  {
1733  return pcl::Hash64( m_data->Begin(), m_data->Size(), seed );
1734  }
1735 
1744  uint32 Hash32( uint32 seed = 0 ) const noexcept
1745  {
1746  return pcl::Hash32( m_data->Begin(), m_data->Size(), seed );
1747  }
1748 
1753  uint64 Hash( uint64 seed = 0 ) const noexcept
1754  {
1755  return Hash64( seed );
1756  }
1757 
1761  bool IsUnique() const noexcept
1762  {
1763  return m_data->IsUnique();
1764  }
1765 
1770  bool IsAliasOf( const GenericVector& x ) const noexcept
1771  {
1772  return m_data == x.m_data;
1773  }
1774 
1783  {
1784  if ( !IsUnique() )
1785  {
1786  Data* newData = new Data( m_data->Length() );
1787  const_iterator __restrict__ i = m_data->Begin();
1788  const_iterator __restrict__ j = m_data->End();
1789  iterator __restrict__ k = newData->Begin();
1790  PCL_IVDEP
1791  for ( ; i < j; ++i, ++k )
1792  *k = *i;
1793  DetachFromData();
1794  m_data = newData;
1795  }
1796  }
1797 
1802  int Length() const noexcept
1803  {
1804  return m_data->Length();
1805  }
1806 
1811  size_type Size() const noexcept
1812  {
1813  return m_data->Size();
1814  }
1815 
1830  bool IsValid() const noexcept
1831  {
1832  return m_data != nullptr;
1833  }
1834 
1839  bool IsEmpty() const noexcept
1840  {
1841  return Length() == 0;
1842  }
1843 
1849  operator bool() const noexcept
1850  {
1851  return !IsEmpty();
1852  }
1853 
1859  bool operator ==( const GenericVector& x ) const noexcept
1860  {
1861  return IsAliasOf( x ) || SameLength( x ) && pcl::Equal( Begin(), x.Begin(), x.End() );
1862  }
1863 
1873  bool operator <( const GenericVector& x ) const noexcept
1874  {
1875  return !IsAliasOf( x ) && pcl::Compare( Begin(), End(), x.Begin(), x.End() ) < 0;
1876  }
1877 
1881  bool SameLength( const GenericVector& x ) const noexcept
1882  {
1883  return Length() == x.Length();
1884  }
1885 
1893  iterator At( int i )
1894  {
1895  EnsureUnique();
1896  return m_data->At( i );
1897  }
1898 
1903  const_iterator At( int i ) const noexcept
1904  {
1905  return m_data->At( i );
1906  }
1907 
1919  {
1920  EnsureUnique();
1921  return m_data->Begin();
1922  }
1923 
1931  const_iterator Begin() const noexcept
1932  {
1933  return m_data->Begin();
1934  }
1935 
1939  const_iterator ConstBegin() const noexcept
1940  {
1941  return Begin();
1942  }
1943 
1951  {
1952  return Begin();
1953  }
1954 
1961  const_iterator operator *() const noexcept
1962  {
1963  return Begin();
1964  }
1965 
1978  {
1979  EnsureUnique();
1980  return m_data->End();
1981  }
1982 
1991  const_iterator End() const noexcept
1992  {
1993  return m_data->End();
1994  }
1995 
1999  const_iterator ConstEnd() const noexcept
2000  {
2001  return End();
2002  }
2003 
2011  component& operator []( int i )
2012  {
2013  return *At( i );
2014  }
2015 
2020  const component& operator []( int i ) const noexcept
2021  {
2022  return *At( i );
2023  }
2024 
2043  iterator DataPtr() noexcept
2044  {
2045  return m_data->v;
2046  }
2047 
2058  iterator ComponentPtr( int i ) noexcept
2059  {
2060  return m_data->At( i );
2061  }
2062 
2063 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
2068  {
2069  return Begin();
2070  }
2071 
2075  const_iterator begin() const noexcept
2076  {
2077  return Begin();
2078  }
2079 
2084  {
2085  return End();
2086  }
2087 
2091  const_iterator end() const noexcept
2092  {
2093  return End();
2094  }
2095 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
2096 
2118  template <typename T1, typename T2>
2119  void ToSpherical( T1& lon, T2& lat ) const noexcept
2120  {
2121  PCL_PRECONDITION( Length() >= 3 )
2122  double x = *At( 0 );
2123  double y = *At( 1 );
2124  double z = *At( 2 );
2125  double m2 = x*x + y*y;
2126  lon = T1( (m2 == 0) ? 0.0 : ArcTan( y, x ) );
2127  lat = T2( (z == 0) ? 0.0 : ArcTan( z, pcl::Sqrt( m2 ) ) );
2128  }
2129 
2138  template <typename T1, typename T2>
2139  void ToSpherical2Pi( T1& lon, T2& lat ) const noexcept
2140  {
2141  ToSpherical( lon, lat );
2142  if ( lon < 0 )
2143  lon += TwoPi();
2144  }
2145 
2161  static GenericVector FromSpherical( double slon, double clon, double slat, double clat )
2162  {
2163  return GenericVector( clon*clat, slon*clat, slat );
2164  }
2165 
2179  template <typename T1, typename T2>
2180  static GenericVector FromSpherical( const T1& lon, const T2& lat )
2181  {
2182  double slon, clon, slat, clat;
2183  SinCos( double( lon ), slon, clon );
2184  SinCos( double( lat ), slat, clat );
2185  return FromSpherical( slon, clon, slat, clat );
2186  }
2187 
2198  template <typename T1>
2199  static GenericVector FromArray( const T1* a, int len )
2200  {
2201  return GenericVector( a, len );
2202  }
2203 
2215  double Angle2D( const GenericVector& v ) const noexcept
2216  {
2217  /*
2218  * https://stackoverflow.com/questions/14066933/direct-way-of-computing-clockwise-angle-between-2-vectors
2219  * https://stackoverflow.com/questions/243945/calculating-a-2d-vectors-cross-product
2220  */
2221  component x1 = *At( 0 );
2222  component y1 = *At( 1 );
2223  component x2 = v[0];
2224  component y2 = v[1];
2225  return ArcTan( x1*y2 - y1*x2, Dot( v ) );
2226  }
2227 
2239  double Angle3D( const GenericVector& v ) const noexcept
2240  {
2241  /*
2242  * https://stackoverflow.com/questions/14066933/direct-way-of-computing-clockwise-angle-between-2-vectors
2243  */
2244  return ArcTan( Cross( v ).L2Norm(), Dot( v ) );
2245  }
2246 
2260  double Angle3D( const GenericVector& v, const GenericVector& n ) const
2261  {
2262  /*
2263  * https://stackoverflow.com/questions/14066933/direct-way-of-computing-clockwise-angle-between-2-vectors
2264  */
2265  GenericVector c = Cross( v );
2266  return ArcTan( (((n * c) >= 0) ? 1 : -1) * c.L2Norm(), Dot( v ) );
2267  }
2268 
2285  template <class S, typename SP>
2286  S& ToSeparated( S& s, SP separator ) const
2287  {
2288  const_iterator i = m_data->Begin(), j = m_data->End();
2289  if ( i < j )
2290  {
2291  s.Append( S( *i ) );
2292  if ( ++i < j )
2293  do
2294  {
2295  s.Append( separator );
2296  s.Append( S( *i ) );
2297  }
2298  while ( ++i < j );
2299  }
2300  return s;
2301  }
2302 
2325  template <class S, typename SP, class AF>
2326  S& ToSeparated( S& s, SP separator, AF append ) const
2327  {
2328  const_iterator i = m_data->Begin(), j = m_data->End();
2329  if ( i < j )
2330  {
2331  append( s, S( *i ) );
2332  if ( ++i < j )
2333  {
2334  S p( separator );
2335  do
2336  {
2337  append( s, p );
2338  append( s, S( *i ) );
2339  }
2340  while ( ++i < j );
2341  }
2342  }
2343  return s;
2344  }
2345 
2354  template <class S>
2355  S& ToCommaSeparated( S& s ) const
2356  {
2357  return ToSeparated( s, ',' );
2358  }
2359 
2368  template <class S>
2369  S& ToSpaceSeparated( S& s ) const
2370  {
2371  return ToSeparated( s, ' ' );
2372  }
2373 
2382  template <class S>
2383  S& ToTabSeparated( S& s ) const
2384  {
2385  return ToSeparated( s, '\t' );
2386  }
2387 
2388 private:
2389 
2395  struct Data : public ReferenceCounter
2396  {
2397  int n = 0;
2398  component* v = nullptr;
2399 
2400  Data() = default;
2401 
2402  Data( int len )
2403  {
2404  if ( len > 0 )
2405  Allocate( len );
2406  }
2407 
2408  ~Data()
2409  {
2410  Deallocate();
2411  }
2412 
2413  int Length() const noexcept
2414  {
2415  return n;
2416  }
2417 
2418  size_type Size() const noexcept
2419  {
2420  return size_type( n )*sizeof( component );
2421  }
2422 
2423  iterator At( int i ) const noexcept
2424  {
2425  return v + i;
2426  }
2427 
2428  iterator Begin() const noexcept
2429  {
2430 // if ( likely( std::is_scalar<component>::value ) )
2431 // return reinterpret_cast<iterator>( PCL_ASSUME_ALIGNED_32( v ) );
2432  return v;
2433  }
2434 
2435  iterator End() const noexcept
2436  {
2437  return At( n );
2438  }
2439 
2440  void Allocate( int len )
2441  {
2442  n = len;
2443  if ( likely( std::is_scalar<component>::value ) )
2444  {
2445  v = reinterpret_cast<component*>( PCL_ALIGNED_MALLOC( Size(), 32 ) );
2446  if ( unlikely( v == nullptr ) )
2447  {
2448  n = 0;
2449  throw std::bad_alloc();
2450  }
2451  }
2452  else
2453  v = new component[ len ];
2454  }
2455 
2456  void Deallocate()
2457  {
2458  PCL_PRECONDITION( refCount == 0 )
2459  if ( likely( std::is_scalar<component>::value ) )
2460  PCL_ALIGNED_FREE( v );
2461  else
2462  delete [] v;
2463  v = nullptr;
2464  n = 0;
2465  }
2466  };
2467 
2472  Data* m_data = nullptr;
2473 
2478  void DetachFromData()
2479  {
2480  if ( !m_data->Detach() )
2481  delete m_data;
2482  }
2483 };
2484 
2485 // ----------------------------------------------------------------------------
2486 
2501 template <typename T> inline
2503 {
2504  int n = A.Length();
2505  if ( B.Length() < n )
2506  throw Error( "Invalid vector addition." );
2507  GenericVector<T> R( n );
2508  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2509  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2510  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2511  if ( likely( !A.IsAliasOf( B ) ) )
2512  {
2513  typename GenericVector<T>::const_iterator __restrict__ b = B.Begin();
2514  PCL_IVDEP
2515  for ( ; a < c; ++a, ++b, ++r )
2516  *r = *a + *b;
2517  }
2518  else
2519  {
2520  PCL_IVDEP
2521  for ( ; a < c; ++a, ++r )
2522  *r = *a + *a;
2523  }
2524  return R;
2525 }
2526 
2534 template <typename T> inline
2536 {
2537  A += B;
2538  return std::move( A );
2539 }
2540 
2548 template <typename T> inline
2550 {
2551  B += A;
2552  return std::move( B );
2553 }
2554 
2563 template <typename T> inline
2565 {
2566  A += B;
2567  return std::move( A );
2568 }
2569 
2574 template <typename T, typename S> inline
2576 {
2577  GenericVector<T> R( A.Length() );
2578  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2579  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2580  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2581  PCL_IVDEP
2582  for ( ; a < c; ++a, ++r )
2583  *r = *a + x;
2584  return R;
2585 }
2586 
2591 template <typename T, typename S> inline
2593 {
2594  A += typename GenericVector<T>::scalar( x );
2595  return std::move( A );
2596 }
2597 
2605 template <typename T, typename S> inline
2607 {
2608  return A + x;
2609 }
2610 
2618 template <typename T, typename S> inline
2620 {
2621  A += typename GenericVector<T>::scalar( x );
2622  return std::move( A );
2623 }
2624 
2625 // ----------------------------------------------------------------------------
2626 
2634 template <typename T> inline
2636 {
2637  int n = A.Length();
2638  if ( B.Length() < n )
2639  throw Error( "Invalid vector subtraction." );
2640 
2641  GenericVector<T> R( n );
2642  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2643  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2644  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2645  if ( likely( !A.IsAliasOf( B ) ) )
2646  {
2647  typename GenericVector<T>::const_iterator __restrict__ b = B.Begin();
2648  PCL_IVDEP
2649  for ( ; a < c; ++a, ++b, ++r )
2650  *r = *a - *b;
2651  }
2652  else
2653  {
2654  PCL_IVDEP
2655  for ( ; a < c; ++a, ++r )
2656  *r = *a - *a;
2657  }
2658  return R;
2659 }
2660 
2669 template <typename T> inline
2671 {
2672  A -= B;
2673  return std::move( A );
2674 }
2675 
2684 template <typename T> inline
2686 {
2687  if ( A.Length() < B.Length() )
2688  throw Error( "Invalid vector subtraction." );
2689 
2690  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2691  typename GenericVector<T>::iterator __restrict__ b = B.Begin();
2692  typename GenericVector<T>::const_iterator __restrict__ c = B.End();
2693  PCL_IVDEP
2694  for ( ; b < c; ++a, ++b )
2695  *b = *a - *b;
2696  return std::move( B );
2697 }
2698 
2707 template <typename T> inline
2709 {
2710  A -= B;
2711  return std::move( A );
2712 }
2713 
2718 template <typename T, typename S> inline
2720 {
2721  GenericVector<T> R( A.Length() );
2722  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2723  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2724  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2725  PCL_IVDEP
2726  for ( ; a < c; ++a, ++r )
2727  *r = *a - x;
2728  return R;
2729 }
2730 
2736 template <typename T, typename S> inline
2738 {
2739  A -= typename GenericVector<T>::scalar( x );
2740  return std::move( A );
2741 }
2742 
2751 template <typename T, typename S> inline
2753 {
2754  GenericVector<T> R( A.Length() );
2755  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2756  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2757  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2758  PCL_IVDEP
2759  for ( ; a < c; ++a, ++r )
2760  *r = x - *a;
2761  return R;
2762 }
2763 
2773 template <typename T, typename S> inline
2775 {
2776  typename GenericVector<T>::iterator __restrict__ a = A.Begin();
2777  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2778  PCL_IVDEP
2779  for ( ; a < c; ++a )
2780  *a = x - *a;
2781  return std::move( A );
2782 }
2783 
2784 // ----------------------------------------------------------------------------
2785 
2794 template <typename T> inline
2796 {
2797  PCL_PRECONDITION( A.Length() == 3 && B.Length() == 3 )
2798  return GenericVector<T>( A[1]*B[2] - A[2]*B[1],
2799  A[2]*B[0] - A[0]*B[2],
2800  A[0]*B[1] - A[1]*B[0] );
2801 }
2802 
2811 template <typename T> inline
2813 {
2814  T x = A[1]*B[2] - A[2]*B[1],
2815  y = A[2]*B[0] - A[0]*B[2],
2816  z = A[0]*B[1] - A[1]*B[0];
2817  typename GenericVector<T>::iterator a = A.Begin();
2818  a[0] = x; a[1] = y; a[2] = z;
2819  return std::move( A );
2820 }
2821 
2830 template <typename T> inline
2832 {
2833  T x = A[1]*B[2] - A[2]*B[1],
2834  y = A[2]*B[0] - A[0]*B[2],
2835  z = A[0]*B[1] - A[1]*B[0];
2836  typename GenericVector<T>::iterator b = B.Begin();
2837  b[0] = x; b[1] = y; b[2] = z;
2838  return std::move( B );
2839 }
2840 
2850 template <typename T> inline
2852 {
2853  T x = A[1]*B[2] - A[2]*B[1],
2854  y = A[2]*B[0] - A[0]*B[2],
2855  z = A[0]*B[1] - A[1]*B[0];
2856  typename GenericVector<T>::iterator a = A.Begin();
2857  a[0] = x; a[1] = y; a[2] = z;
2858  return std::move( A );
2859 }
2860 
2861 // ----------------------------------------------------------------------------
2862 
2871 template <typename T> inline
2872 T operator *( const GenericVector<T>& A, const GenericVector<T>& B ) noexcept
2873 {
2874  PCL_PRECONDITION( B.Length() >= A.Length() )
2875  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2876  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2877  T r = T( 0 );
2878  if ( likely( !A.IsAliasOf( B ) ) )
2879  {
2880  typename GenericVector<T>::const_iterator __restrict__ b = B.Begin();
2881  PCL_IVDEP
2882  for ( ; a < c; ++a, ++b )
2883  r += *a * *b;
2884  }
2885  else
2886  {
2887  PCL_IVDEP
2888  for ( ; a < c; ++a )
2889  r += *a * *a;
2890  }
2891  return r;
2892 }
2893 
2894 // ----------------------------------------------------------------------------
2895 
2900 template <typename T, typename S> inline
2902 {
2903  GenericVector<T> R( A.Length() );
2904  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2905  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2906  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2907  PCL_IVDEP
2908  for ( ; a < c; ++a, ++r )
2909  *r = *a * x;
2910  return R;
2911 }
2912 
2917 template <typename T, typename S> inline
2919 {
2920  A *= typename GenericVector<T>::scalar( x );
2921  return std::move( A );
2922 }
2923 
2931 template <typename T, typename S> inline
2933 {
2934  return A * x;
2935 }
2936 
2944 template <typename T, typename S> inline
2946 {
2947  A *= typename GenericVector<T>::scalar( x );
2948  return std::move( A );
2949 }
2950 
2951 // ----------------------------------------------------------------------------
2952 
2957 template <typename T, typename S> inline
2959 {
2960  GenericVector<T> R( A.Length() );
2961  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2962  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2963  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2964  PCL_IVDEP
2965  for ( ; a < c; ++a, ++r )
2966  *r = *a / x;
2967  return R;
2968 }
2969 
2975 template <typename T, typename S> inline
2977 {
2978  A /= typename GenericVector<T>::scalar( x );
2979  return std::move( A );
2980 }
2981 
2989 template <typename T, typename S> inline
2991 {
2992  GenericVector<T> R( A.Length() );
2993  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
2994  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
2995  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
2996  PCL_IVDEP
2997  for ( ; a < c; ++a, ++r )
2998  *r = x / *a;
2999  return R;
3000 }
3001 
3010 template <typename T, typename S> inline
3012 {
3013  typename GenericVector<T>::iterator __restrict__ a = A.Begin();
3014  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
3015  PCL_IVDEP
3016  for ( ; a < c; ++a )
3017  *a = x / *a;
3018  return std::move( A );
3019 }
3020 
3026 template <typename T> inline
3028 {
3029  int n = A.Length();
3030  if ( B.Length() < n )
3031  throw Error( "Invalid vector division." );
3032 
3033  GenericVector<T> R( n );
3034  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
3035  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
3036  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
3037  if ( likely( !A.IsAliasOf( B ) ) )
3038  {
3039  typename GenericVector<T>::const_iterator __restrict__ b = B.Begin();
3040  PCL_IVDEP
3041  for ( ; a < c; ++a, ++b, ++r )
3042  *r = *a / *b;
3043  }
3044  else
3045  {
3046  PCL_IVDEP
3047  for ( ; a < c; ++a, ++r )
3048  *r = *a / *a;
3049  }
3050  return R;
3051 }
3052 
3058 template <typename T> inline
3060 {
3061  return A /= B;
3062 }
3063 
3064 // ----------------------------------------------------------------------------
3065 
3070 template <typename T, typename S> inline
3072 {
3073  GenericVector<T> R( A.Length() );
3074  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
3075  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
3076  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
3077  PCL_IVDEP
3078  for ( ; a < c; ++a, ++r )
3079  *r = pcl::Pow( *a, x );
3080  return R;
3081 }
3082 
3088 template <typename T, typename S> inline
3090 {
3091  A ^= typename GenericVector<T>::scalar( x );
3092  return std::move( A );
3093 }
3094 
3102 template <typename T, typename S> inline
3104 {
3105  GenericVector<T> R( A.Length() );
3106  typename GenericVector<T>::iterator __restrict__ r = R.Begin();
3107  typename GenericVector<T>::const_iterator __restrict__ a = A.Begin();
3108  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
3109  PCL_IVDEP
3110  for ( ; a < c; ++a, ++r )
3111  *r = pcl::Pow( x, *a );
3112  return R;
3113 }
3114 
3123 template <typename T, typename S> inline
3125 {
3126  typename GenericVector<T>::iterator __restrict__ a = A.Begin();
3127  typename GenericVector<T>::const_iterator __restrict__ c = A.End();
3128  PCL_IVDEP
3129  for ( ; a < c; ++a )
3130  *a = pcl::Pow( x, *a );
3131  return std::move( A );
3132 }
3133 
3134 // ----------------------------------------------------------------------------
3135 
3136 #ifndef __PCL_NO_VECTOR_INSTANTIATE
3137 
3149 using I8Vector = GenericVector<int8>;
3150 
3159 using CharVector = I8Vector;
3160 
3168 using UI8Vector = GenericVector<uint8>;
3169 
3178 using ByteVector = UI8Vector;
3179 
3187 using I16Vector = GenericVector<int16>;
3188 
3196 using UI16Vector = GenericVector<uint16>;
3197 
3205 using I32Vector = GenericVector<int32>;
3206 
3215 using IVector = I32Vector;
3216 
3224 using UI32Vector = GenericVector<uint32>;
3225 
3234 using UIVector = UI32Vector;
3235 
3243 using I64Vector = GenericVector<int64>;
3244 
3252 using UI64Vector = GenericVector<uint64>;
3253 
3261 using SzVector = GenericVector<size_type>;
3262 
3270 using F32Vector = GenericVector<float>;
3271 
3280 using FVector = F32Vector;
3281 
3289 using F64Vector = GenericVector<double>;
3290 
3299 using DVector = F64Vector;
3300 
3309 using Vector = DVector;
3310 
3318 using C32Vector = GenericVector<Complex32>;
3319 
3327 using C64Vector = GenericVector<Complex64>;
3328 
3329 #ifndef _MSC_VER
3330 
3342 using F80Vector = GenericVector<long double>;
3343 
3355 using LDVector = F80Vector;
3356 
3357 #endif // !_MSC_VER
3358 
3359 #endif // !__PCL_NO_VECTOR_INSTANTIATE
3360 
3361 // ----------------------------------------------------------------------------
3362 
3363 } // pcl
3364 
3365 #endif // __PCL_Vector_h
3366 
3367 // ----------------------------------------------------------------------------
3368 // EOF pcl/Vector.h - Released 2024-12-28T16:53:48Z
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
const T const_item_type
Definition: Container.h:89
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:1715
double Sn() const
Definition: Vector.h:1687
void Transfer(GenericVector &x)
Definition: Vector.h:366
double Angle2D(const GenericVector &v) const noexcept
Definition: Vector.h:2215
double StdDev() const noexcept
Definition: Vector.h:1346
GenericVector(const T1 *a, int len)
Definition: Vector.h:193
double TrimmedMeanOfSquares(distance_type l=1, distance_type h=1) const noexcept
Definition: Vector.h:1325
double MAD() const
Definition: Vector.h:1482
double BendMidvariance(double beta=0.2) const
Definition: Vector.h:1659
TwoSidedEstimate TwoSidedBiweightMidvariance(double center, const TwoSidedEstimate &sigma, int k=9, bool reducedLength=false) const noexcept
Definition: Vector.h:1595
scalar L1Norm() const noexcept
Definition: Vector.h:902
void Transfer(GenericVector &&x)
Definition: Vector.h:388
static GenericVector FromSpherical(double slon, double clon, double slat, double clat)
Definition: Vector.h:2161
double BiweightMidvariance(double center, double sigma, int k=9, bool reducedLength=false) const noexcept
Definition: Vector.h:1542
const_iterator end() const noexcept
Definition: Vector.h:2091
component OrderStatistic(int k)
Definition: Vector.h:1198
double Angle3D(const GenericVector &v) const noexcept
Definition: Vector.h:2239
const_iterator ConstEnd() const noexcept
Definition: Vector.h:1999
virtual ~GenericVector()
Definition: Vector.h:288
bool IsUnique() const noexcept
Definition: Vector.h:1761
double SumOfSquares() const noexcept
Definition: Vector.h:1270
void ToSpherical(T1 &lon, T2 &lat) const noexcept
Definition: Vector.h:2119
size_type Size() const noexcept
Definition: Vector.h:1811
GenericVector Sorted() const
Definition: Vector.h:961
int IndexOfLastLargestComponent() const noexcept
Definition: Vector.h:1103
double Angle3D(const GenericVector &v, const GenericVector &n) const
Definition: Vector.h:2260
component MaxComponent() const noexcept
Definition: Vector.h:1175
TwoSidedEstimate TwoSidedMAD() const
Definition: Vector.h:1503
int FindFirst(const component &x) const noexcept
Definition: Vector.h:1028
GenericVector Sqrt() const
Definition: Vector.h:795
iterator At(int i)
Definition: Vector.h:1893
double StableSum() const noexcept
Definition: Vector.h:1241
double StableAvgDev(double center) const noexcept
Definition: Vector.h:1395
GenericVector Cross(const GenericVector &v2) const
Definition: Vector.h:683
GenericVector(std::initializer_list< T1 > c)
Definition: Vector.h:217
static GenericVector FromArray(const T1 *a, int len)
Definition: Vector.h:2199
int IndexOfLastSmallestNonzeroComponent() const noexcept
Definition: Vector.h:1144
int FindLast(const component &x) const noexcept
Definition: Vector.h:1037
scalar Norm(double p) const noexcept
Definition: Vector.h:893
bool IsEmpty() const noexcept
Definition: Vector.h:1839
double StableModulus() const noexcept
Definition: Vector.h:1261
uint64 Hash64(uint64 seed=0) const noexcept
Definition: Vector.h:1731
void SetSqrt()
Definition: Vector.h:813
GenericVector Sorted(BP p) const
Definition: Vector.h:1006
iterator Begin()
Definition: Vector.h:1918
GenericVector Unit() const
Definition: Vector.h:929
void ReverseSort()
Definition: Vector.h:971
int IndexOfLargestComponent() const noexcept
Definition: Vector.h:1072
int IndexOfSmallestNonzeroComponent() const noexcept
Definition: Vector.h:1120
int Find(const component &x) const noexcept
Definition: Vector.h:1017
friend void Swap(GenericVector &x1, GenericVector &x2) noexcept
Definition: Vector.h:404
double StableSumOfSquares() const noexcept
Definition: Vector.h:1281
const T * const_iterator
Definition: Vector.h:140
bool IsValid() const noexcept
Definition: Vector.h:1830
component MinComponent() const noexcept
Definition: Vector.h:1164
uint64 Hash(uint64 seed=0) const noexcept
Definition: Vector.h:1753
double Variance() const noexcept
Definition: Vector.h:1335
void Assign(const GenericVector &x)
Definition: Vector.h:336
iterator End()
Definition: Vector.h:1977
const_iterator Begin() const noexcept
Definition: Vector.h:1931
scalar Dot(const GenericVector &v) const noexcept
Definition: Vector.h:663
double MAD(double center) const
Definition: Vector.h:1467
GenericVector Sqr() const
Definition: Vector.h:748
uint32 Hash32(uint32 seed=0) const noexcept
Definition: Vector.h:1744
GenericVector(GenericVector &&x)
Definition: Vector.h:264
void SetUnit()
Definition: Vector.h:942
static GenericVector FromSpherical(const T1 &lon, const T2 &lat)
Definition: Vector.h:2180
double BiweightMidvariance(int k=9, bool reducedLength=false) const
Definition: Vector.h:1575
scalar L2Norm() const noexcept
Definition: Vector.h:911
iterator ComponentPtr(int i) noexcept
Definition: Vector.h:2058
int Length() const noexcept
Definition: Vector.h:1802
GenericVector(const GenericVector< T1 > &x)
Definition: Vector.h:279
TwoSidedEstimate TwoSidedAvgDev() const
Definition: Vector.h:1451
TwoSidedEstimate TwoSidedBiweightMidvariance(int k=9, bool reducedLength=false) const
Definition: Vector.h:1607
TwoSidedEstimate TwoSidedAvgDev(double center) const noexcept
Definition: Vector.h:1441
void ToSpherical2Pi(T1 &lon, T2 &lat) const noexcept
Definition: Vector.h:2139
const_iterator End() const noexcept
Definition: Vector.h:1991
void Sort(BP p)
Definition: Vector.h:995
GenericVector ReverseSorted() const
Definition: Vector.h:981
GenericVector(const T1 &x, const T1 &y, const T1 &z)
Definition: Vector.h:227
double Median() const
Definition: Vector.h:1356
double Mean() const
Definition: Vector.h:1290
scalar Norm() const noexcept
Definition: Vector.h:920
void EnsureUnique()
Definition: Vector.h:1782
iterator DataPtr() noexcept
Definition: Vector.h:2043
void ReverseSign()
Definition: Vector.h:719
double StableAvgDev() const
Definition: Vector.h:1430
double AvgDev() const
Definition: Vector.h:1412
double Sum() const noexcept
Definition: Vector.h:1230
double TrimmedMean(distance_type l=1, distance_type h=1) const noexcept
Definition: Vector.h:1313
bool IsAliasOf(const GenericVector &x) const noexcept
Definition: Vector.h:1770
double Modulus() const noexcept
Definition: Vector.h:1250
GenericVector(const T1 &x, const T1 &y, const T1 &z, const T1 &t)
Definition: Vector.h:241
int IndexOfSmallestComponent() const noexcept
Definition: Vector.h:1060
double StableMean() const noexcept
Definition: Vector.h:1301
GenericVector(int len)
Definition: Vector.h:159
iterator begin()
Definition: Vector.h:2067
bool Contains(const component &x) const noexcept
Definition: Vector.h:1046
component OrderStatistic(int k) const
Definition: Vector.h:1221
TwoSidedEstimate TwoSidedMAD(double center) const
Definition: Vector.h:1493
const_iterator At(int i) const noexcept
Definition: Vector.h:1903
bool SameLength(const GenericVector &x) const noexcept
Definition: Vector.h:1881
iterator end()
Definition: Vector.h:2083
GenericVector Abs() const
Definition: Vector.h:841
double AvgDev(double center) const noexcept
Definition: Vector.h:1375
GenericVector(const component &x, int len)
Definition: Vector.h:171
GenericVector(const GenericVector &x)
Definition: Vector.h:255
const_iterator ConstBegin() const noexcept
Definition: Vector.h:1939
int IndexOfLastSmallestComponent() const noexcept
Definition: Vector.h:1085
double BendMidvariance(double center, double beta=0.2) const
Definition: Vector.h:1635
const_iterator begin() const noexcept
Definition: Vector.h:2075
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:2285
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2296
Complex< T1 > operator-(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:518
Complex< T1 > operator*(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:562
Complex< T1 > operator+(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:478
Complex< T1 > operator/(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:606
Complex< T1 > Pow(const Complex< T1 > &c, T2 x) noexcept
Definition: Complex.h:761
Complex< T > Sqrt(const Complex< T > &c) noexcept
Definition: Complex.h:688
T Abs(const Complex< T > &c) noexcept
Definition: Complex.h:443
uint64 Hash64(const void *data, size_type size, uint64 seed=0) noexcept
Definition: Math.h:4830
uint32 Hash32(const void *data, size_type size, uint32 seed=0) noexcept
Definition: Math.h:4984
GenericImage< P > operator^(const GenericImage< P > &image, T scalar)
Definition: Image.h:17768
void SinCos(T x, T &sx, T &cx) noexcept
Definition: Math.h:1101
T L1Norm(const T *i, const T *j) noexcept
Definition: Math.h:2225
constexpr T ArcTan(T x) noexcept
Definition: Math.h:597
constexpr long double TwoPi() noexcept
Definition: Math.h:540
T Norm(const T *i, const T *j, const P &p) noexcept
Definition: Math.h:2166
T L2Norm(const T *i, const T *j) noexcept
Definition: Math.h:2284
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:4250
double BendMidvariance(const T *__restrict__ x, const T *__restrict__ xn, double center, double beta=0.2)
Definition: Math.h:4560
double StableModulus(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2667
double MAD(const T *__restrict__ i, const T *__restrict__ j, double center, double eps=0)
Definition: Math.h:3844
double SumOfSquares(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2692
double StableMean(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2759
double TrimmedMean(const T *__restrict__ i, const T *__restrict__ j, distance_type l=1, distance_type h=1)
Definition: Math.h:3306
TwoSidedEstimate TwoSidedMAD(const T *__restrict__ i, const T *__restrict__ j, double center, double eps=0)
Definition: Math.h:3913
double StableSum(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2623
double Variance(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:2784
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:4484
double Sum(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2604
double StableSumOfSquares(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2714
double BiweightMidvariance(const T *__restrict__ x, const T *__restrict__ xn, double center, double sigma, int k=9, bool reducedLength=false) noexcept
Definition: Math.h:4421
double StdDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:2844
double TrimmedMeanOfSquares(const T *__restrict__ i, const T *__restrict__ j, distance_type l=1, distance_type h=1)
Definition: Math.h:3383
double AvgDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:3468
double Median(const T *__restrict__ i, const T *__restrict__ j, double eps=0)
Definition: Math.h:2917
double Mean(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2740
double StableAvgDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:3500
TwoSidedEstimate TwoSidedAvgDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
Definition: Math.h:3781
double Modulus(const T *__restrict__ i, const T *__restrict__ j) noexcept
Definition: Math.h:2648
double Sn(T *__restrict__ x, T *__restrict__ xn)
Definition: Math.h:4004
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:3592