DGtal  1.2.0
PointVector.h
1 
17 #pragma once
18 
34 #if defined(PointVector_RECURSES)
35 #error Recursive header files inclusion detected in PointVector.h
36 #else // defined(PointVector_RECURSES)
38 #define PointVector_RECURSES
39 
40 #if !defined PointVector_h
42 #define PointVector_h
43 
45 // Inclusions
46 #include <iostream>
47 #include <string>
48 #include <bitset>
49 #include <algorithm>
50 #include <array>
51 #include <vector>
52 #include <type_traits>
53 #include <utility>
54 #include <functional>
55 
56 #include "DGtal/base/Common.h"
57 #include "DGtal/base/CBidirectionalRange.h"
58 #include "DGtal/kernel/NumberTraits.h"
59 #include "DGtal/kernel/CEuclideanRing.h"
60 #include "DGtal/kernel/ArithmeticConversionTraits.h"
61 
63 
64 namespace DGtal
65 {
67  template<Dimension dim, typename Container>
68  std::bitset<dim> setDimensionsIn( const Container &dimensions );
69 
71  template<Dimension dim, typename Container>
72  std::bitset<dim> setDimensionsNotIn( const Container &dimensions );
73 
75  // class PointVector pre-declaration
162  template < DGtal::Dimension dim,
163  typename TEuclideanRing,
164  typename TContainer=std::array<TEuclideanRing,dim> >
165  class PointVector;
166 
168  // Type traits
169 
174  template <typename T>
175  struct IsAPointVector : std::false_type {};
176 
181  template <DGtal::Dimension dim, typename TEuclideanRing, typename TContainer>
182  struct IsAPointVector<PointVector<dim, TEuclideanRing, TContainer>> : std::true_type {};
183 
188  template < DGtal::Dimension dim,
189  typename LeftEuclideanRing, typename LeftContainer,
190  typename RightEuclideanRing, typename RightContainer >
191  struct ArithmeticConversionTraits< PointVector<dim, LeftEuclideanRing, LeftContainer>, PointVector<dim, RightEuclideanRing, RightContainer>,
192  typename std::enable_if< IsArithmeticConversionValid<LeftEuclideanRing, RightEuclideanRing>::value >::type >
193  {
194  using type = typename std::conditional<
195  std::is_same< LeftEuclideanRing, ArithmeticConversionType<LeftEuclideanRing, RightEuclideanRing> >::value,
198  };
199 
204  template < DGtal::Dimension dim,
205  typename LeftEuclideanRing, typename LeftContainer,
206  typename RightEuclideanRing >
207  struct ArithmeticConversionTraits< PointVector<dim, LeftEuclideanRing, LeftContainer>, RightEuclideanRing,
208  typename std::enable_if<
209  IsArithmeticConversionValid<LeftEuclideanRing, RightEuclideanRing>::value
210  && ! IsAPointVector<RightEuclideanRing>::value >::type >
211  {
212  using type = typename std::conditional<
213  std::is_same< LeftEuclideanRing, ArithmeticConversionType<LeftEuclideanRing, RightEuclideanRing> >::value,
216  };
217 
222  template < DGtal::Dimension dim,
223  typename LeftEuclideanRing,
224  typename RightEuclideanRing, typename RightContainer >
225  struct ArithmeticConversionTraits< LeftEuclideanRing, PointVector<dim, RightEuclideanRing, RightContainer>,
226  typename std::enable_if<
227  IsArithmeticConversionValid<LeftEuclideanRing, RightEuclideanRing>::value
228  && ! IsAPointVector<LeftEuclideanRing>::value >::type >
229  {
230  using type = typename std::conditional<
231  std::is_same< LeftEuclideanRing, ArithmeticConversionType<LeftEuclideanRing, RightEuclideanRing> >::value,
234  };
235 
236 
238  // PointVector comparison operators
239 
244  template < Dimension ptDim,
245  typename LeftEuclideanRing, typename LeftContainer,
246  typename RightEuclideanRing, typename RightContainer >
247  inline bool
250 
255  template < Dimension ptDim,
256  typename LeftEuclideanRing, typename LeftContainer,
257  typename RightEuclideanRing, typename RightContainer >
258  inline bool
261 
268  template < Dimension ptDim,
269  typename LeftEuclideanRing, typename LeftContainer,
270  typename RightEuclideanRing, typename RightContainer >
271  inline bool
274 
281  template < Dimension ptDim,
282  typename LeftEuclideanRing, typename LeftContainer,
283  typename RightEuclideanRing, typename RightContainer >
284  inline bool
287 
294  template < Dimension ptDim,
295  typename LeftEuclideanRing, typename LeftContainer,
296  typename RightEuclideanRing, typename RightContainer >
297  inline bool
300 
307  template < Dimension ptDim,
308  typename LeftEuclideanRing, typename LeftContainer,
309  typename RightEuclideanRing, typename RightContainer >
310  inline bool
313 
315  // Binary arithmetics operators between two PointVectors
316 
322  template < Dimension ptDim,
323  typename LeftEuclideanRing, typename LeftContainer,
324  typename RightEuclideanRing, typename RightContainer >
325  inline auto
328  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
329 
335  template < Dimension ptDim,
336  typename LeftEuclideanRing, typename LeftContainer,
337  typename RightEuclideanRing, typename RightContainer >
338  inline auto
341  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
342 
348  template < Dimension ptDim,
349  typename LeftEuclideanRing, typename LeftContainer,
350  typename RightEuclideanRing, typename RightContainer >
351  inline auto
354  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
355 
361  template < Dimension ptDim,
362  typename LeftEuclideanRing, typename LeftContainer,
363  typename RightEuclideanRing, typename RightContainer >
364  inline auto
367  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
368 
370  // Binary arithmetics operators between a PointVector and a scalar
371 
377  template < Dimension ptDim,
378  typename LeftEuclideanRing, typename LeftContainer,
379  typename RightScalar >
380  inline auto
382  RightScalar const& rhs )
383  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
384 
390  template < Dimension ptDim,
391  typename LeftScalar,
392  typename RightEuclideanRing, typename RightContainer >
393  inline auto
394  operator+ ( LeftScalar const& lhs,
396  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
397 
403  template < Dimension ptDim,
404  typename LeftEuclideanRing, typename LeftContainer,
405  typename RightScalar >
406  inline auto
408  RightScalar const& rhs )
409  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
410 
416  template < Dimension ptDim,
417  typename LeftScalar,
418  typename RightEuclideanRing, typename RightContainer >
419  inline auto
420  operator- ( LeftScalar const& lhs,
422  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
423 
429  template < Dimension ptDim,
430  typename LeftEuclideanRing, typename LeftContainer,
431  typename RightScalar >
432  inline auto
434  RightScalar const& rhs )
435  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
436 
442  template < Dimension ptDim,
443  typename LeftScalar,
444  typename RightEuclideanRing, typename RightContainer >
445  inline auto
446  operator* ( LeftScalar const& lhs,
448  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
449 
455  template < Dimension ptDim,
456  typename LeftEuclideanRing, typename LeftContainer,
457  typename RightScalar >
458  inline auto
460  RightScalar const& rhs )
461  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
462 
468  template < Dimension ptDim,
469  typename LeftScalar,
470  typename RightEuclideanRing, typename RightContainer >
471  inline auto
472  operator/ ( LeftScalar const& lhs,
474  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
475 
477  // Operations between Points/Vectors
478 
484  template < Dimension ptDim,
485  typename LeftEuclideanRing, typename LeftContainer,
486  typename RightEuclideanRing, typename RightContainer >
487  inline
491 
497  template <
498  typename LeftEuclideanRing, typename LeftContainer,
499  typename RightEuclideanRing, typename RightContainer >
500  inline auto
503  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
504 
510  template <
511  typename LeftEuclideanRing, typename LeftContainer,
512  typename RightEuclideanRing, typename RightContainer >
513  inline
517 
522  template < Dimension ptDim,
523  typename LeftEuclideanRing, typename LeftContainer,
524  typename RightEuclideanRing, typename RightContainer >
525  inline double
528 
538  template < Dimension ptDim,
539  typename LeftEuclideanRing, typename LeftContainer,
540  typename RightEuclideanRing, typename RightContainer >
541  inline auto
544  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
545 
555  template < Dimension ptDim,
556  typename LeftEuclideanRing, typename LeftContainer,
557  typename RightEuclideanRing, typename RightContainer >
558  inline auto
561  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
562 
568  template < Dimension ptDim,
569  typename LeftEuclideanRing, typename LeftContainer,
570  typename RightEuclideanRing, typename RightContainer >
571  inline bool
574 
580  template < Dimension ptDim,
581  typename LeftEuclideanRing, typename LeftContainer,
582  typename RightEuclideanRing, typename RightContainer >
583  inline bool
586 
588  // class PointVector full declaration
589  template < DGtal::Dimension dim,
590  typename TEuclideanRing,
591  typename TContainer >
593  {
594 
595  // Friend with all PointVectors
596  template <
597  DGtal::Dimension otherDim,
598  typename TOtherEuclideanRing,
599  typename TOtherContainer >
600  friend class PointVector;
601 
602  // ----------------------- Standard services ------------------------------
603  public:
604 
606 
609 
612 
614  typedef TEuclideanRing Component;
615 
618 
621 
624 
626  static const Dimension dimension = dim;
627 
629  typedef Component Scalar;
630  typedef Dimension Index;
631 
633  typedef TContainer Container;
634 
635 
640  typedef typename Container::iterator Iterator;
641  typedef typename Container::const_iterator ConstIterator;
642  typedef typename Container::reverse_iterator ReverseIterator;
643  typedef typename Container::const_reverse_iterator ConstReverseIterator;
644 
649 
656  explicit PointVector( const Component* ptrValues );
657 
665  PointVector( const Component & x, const Component & y );
666 
675  PointVector( const Component & x, const Component & y, const Component & z );
676 
686  PointVector( const Component & x, const Component & y,
687  const Component & z, const Component & t );
688 
693  PointVector( std::initializer_list<Component> init );
694 
700  template <
701  typename LeftComponent, typename LeftStorage,
702  typename RightComponent, typename RightStorage,
703  typename BinaryFunctor >
706  const BinaryFunctor& f );
707 
713  template <
714  typename OtherComponent, typename OtherStorage,
715  typename UnaryFunctor >
717  const UnaryFunctor & f );
718 
723 
724  // ----------------------- Standard services ------------------------------
725 
726  public:
731  PointVector( const Self & other );
732 
742  template <
743  typename OtherComponent, typename OtherCont,
744  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
746 
756  template <
757  typename OtherComponent, typename OtherCont,
758  typename std::enable_if< ! std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
759  explicit
761 
767  Self & operator= ( const Self & pv );
768 
780  template <
781  typename OtherComponent,
782  typename OtherContainer,
783  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
785 
803  template <
804  typename OtherComponent,
805  typename OtherContainer,
806  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
808  const std::vector<Dimension> &dimensions);
809 
827  template <
828  typename OtherComponent,
829  typename OtherContainer,
830  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
832  const std::vector<Dimension> &dimensions);
833 
849  template <
850  typename OtherComponent,
851  typename OtherContainer,
852  typename UnaryFunctor >
854  const std::vector<Dimension> & dimensions,
855  const UnaryFunctor & f);
856 
872  template <
873  typename OtherComponent,
874  typename OtherContainer,
875  typename UnaryFunctor >
877  const std::vector<Dimension> & dimensions,
878  const UnaryFunctor & f);
879 
892  template <
893  typename OtherComponent,
894  typename OtherContainer >
896  const std::vector<Dimension> &dimensions ) const;
897 
910  template <
911  typename OtherComponent,
912  typename OtherContainer >
914  const std::vector<Dimension> &dimensions ) const;
915 
916  // ----------------------- Iterator services ------------------------------
917  public:
924 
931 
938 
945 
952 
959 
966 
973 
979  inline const Component* data() const noexcept;
985  inline Component* data() noexcept;
986 
987  // ----------------------- Array services ------------------------------
988  public:
993  static Dimension size();
994  inline Dimension rows() const { return dim; }
995 
1003  const Component& operator[]( Dimension i ) const;
1004  inline const Component& operator()( Dimension i ) const { return (*this)[i]; }
1005 
1015  Component& operator()(Dimension i ) { return (*this)[i]; }
1016 
1017  // ----------------------- Comparison operations --------------------------
1018  // Friend declarations in order to have them documented on the same page
1019  // as PointVector.
1020  public:
1021 
1022  template < Dimension ptDim,
1023  typename LeftEuclideanRing, typename LeftContainer,
1024  typename RightEuclideanRing, typename RightContainer >
1025  friend inline bool
1028 
1029  template < Dimension ptDim,
1030  typename LeftEuclideanRing, typename LeftContainer,
1031  typename RightEuclideanRing, typename RightContainer >
1032  friend inline bool
1035 
1036  template < Dimension ptDim,
1037  typename LeftEuclideanRing, typename LeftContainer,
1038  typename RightEuclideanRing, typename RightContainer >
1039  friend inline bool
1042 
1043  template < Dimension ptDim,
1044  typename LeftEuclideanRing, typename LeftContainer,
1045  typename RightEuclideanRing, typename RightContainer >
1046  friend inline bool
1049 
1050  template < Dimension ptDim,
1051  typename LeftEuclideanRing, typename LeftContainer,
1052  typename RightEuclideanRing, typename RightContainer >
1053  friend inline bool
1056 
1057  // ------------- Binary arithmetic operations between points --------------
1058  // Friend declarations in order to have them documented on the same page
1059  // as PointVector.
1060  public:
1061 
1062  template < Dimension ptDim,
1063  typename LeftEuclideanRing, typename LeftContainer,
1064  typename RightEuclideanRing, typename RightContainer >
1065  friend inline auto
1068  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1069 
1070  template < Dimension ptDim,
1071  typename LeftEuclideanRing, typename LeftContainer,
1072  typename RightEuclideanRing, typename RightContainer >
1073  friend inline auto
1076  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1077 
1078  template < Dimension ptDim,
1079  typename LeftEuclideanRing, typename LeftContainer,
1080  typename RightEuclideanRing, typename RightContainer >
1081  friend inline auto
1084  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1085 
1086  template < Dimension ptDim,
1087  typename LeftEuclideanRing, typename LeftContainer,
1088  typename RightEuclideanRing, typename RightContainer >
1089  friend inline auto
1092  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1093 
1094  // ------ Binary arithmetic operations between a point and a vector -------
1095  // Friend declarations in order to have them documented on the same page
1096  // as PointVector.
1097  public:
1098 
1099  template < DGtal::Dimension ptDim,
1100  typename LeftEuclideanRing, typename LeftContainer,
1101  typename RightScalar >
1102  friend inline auto
1104  RightScalar const& rhs )
1105  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1106 
1107  template < Dimension ptDim,
1108  typename LeftScalar,
1109  typename RightEuclideanRing, typename RightContainer >
1110  friend inline auto
1111  operator+ ( LeftScalar const& lhs,
1113  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1114 
1115  template < DGtal::Dimension ptDim,
1116  typename LeftEuclideanRing, typename LeftContainer,
1117  typename RightScalar >
1118  friend inline auto
1120  RightScalar const& rhs )
1121  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1122 
1123  template < Dimension ptDim,
1124  typename LeftScalar,
1125  typename RightEuclideanRing, typename RightContainer >
1126  friend inline auto
1127  operator- ( LeftScalar const& lhs,
1129  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1130 
1131  template < DGtal::Dimension ptDim,
1132  typename LeftEuclideanRing, typename LeftContainer,
1133  typename RightScalar >
1134  friend inline auto
1136  RightScalar const& rhs )
1137  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1138 
1139  template < Dimension ptDim,
1140  typename LeftScalar,
1141  typename RightEuclideanRing, typename RightContainer >
1142  friend inline auto
1143  operator* ( LeftScalar const& lhs,
1145  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1146 
1147  template < DGtal::Dimension ptDim,
1148  typename LeftEuclideanRing, typename LeftContainer,
1149  typename RightScalar >
1150  friend inline auto
1152  RightScalar const& rhs )
1153  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1154 
1155  template < Dimension ptDim,
1156  typename LeftScalar,
1157  typename RightEuclideanRing, typename RightContainer >
1158  friend inline auto
1159  operator/ ( LeftScalar const& lhs,
1161  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1162 
1163  // -------- Unary arithmetic operations on a point or a vector ------------
1164  public:
1165 
1176  template <
1177  typename OtherComponent,
1178  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
1179  inline
1180  PointVector & operator+= ( OtherComponent coeff );
1181 
1192  template <
1193  typename OtherComponent, typename OtherStorage,
1194  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
1195  inline
1197 
1208  template <
1209  typename OtherComponent,
1210  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
1211  inline
1212  PointVector & operator-= ( OtherComponent coeff );
1213 
1224  template <
1225  typename OtherComponent, typename OtherStorage,
1226  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
1227  inline
1229 
1240  template <
1241  typename OtherComponent,
1242  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
1243  inline
1244  PointVector & operator*= ( OtherComponent coeff );
1245 
1256  template <
1257  typename OtherComponent, typename OtherStorage,
1258  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
1259  inline
1261 
1272  template <
1273  typename OtherComponent,
1274  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
1275  inline
1276  PointVector & operator/= ( OtherComponent coeff );
1277 
1288  template <
1289  typename OtherComponent, typename OtherStorage,
1290  typename std::enable_if< std::is_same< Component, ArithmeticConversionType<Component, OtherComponent> >::value, int >::type = 0 >
1291  inline
1293 
1300  inline
1301  Self operator-() const;
1302 
1303 
1304  // ------------------ Other operators between vectors ---------------------
1305  public:
1314  template < typename OtherComponent, typename OtherStorage >
1315  inline auto
1317  -> decltype( DGtal::dotProduct(*this, v) );
1318 
1319  template < Dimension ptDim,
1320  typename LeftEuclideanRing, typename LeftContainer,
1321  typename RightEuclideanRing, typename RightContainer >
1322  friend inline
1326 
1338  template < typename OtherComponent, typename OtherStorage >
1339  inline auto
1341  -> decltype( DGtal::crossProduct(*this, v) );
1342 
1343  template <
1344  typename LeftEuclideanRing, typename LeftContainer,
1345  typename RightEuclideanRing, typename RightContainer >
1346  friend inline auto
1349  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1350 
1351  template <
1352  typename LeftEuclideanRing, typename LeftContainer,
1353  typename RightEuclideanRing, typename RightContainer >
1354  friend inline
1358 
1365  template < typename OtherComponent, typename OtherStorage >
1366  inline double
1368 
1369  template < Dimension ptDim,
1370  typename LeftEuclideanRing, typename LeftContainer,
1371  typename RightEuclideanRing, typename RightContainer >
1372  friend inline double
1375 
1386  template < typename OtherComponent, typename OtherStorage >
1387  inline auto
1389  -> decltype( DGtal::inf(*this, aPoint) );
1390 
1391  template < Dimension ptDim,
1392  typename LeftEuclideanRing, typename LeftContainer,
1393  typename RightEuclideanRing, typename RightContainer >
1394  friend inline auto
1397  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1398 
1409  template < typename OtherComponent, typename OtherStorage >
1410  inline auto
1412  -> decltype( DGtal::sup(*this, aPoint) );
1413 
1414  template < Dimension ptDim,
1415  typename LeftEuclideanRing, typename LeftContainer,
1416  typename RightEuclideanRing, typename RightContainer >
1417  friend inline auto
1420  -> decltype( DGtal::constructFromArithmeticConversion(lhs, rhs) );
1421 
1428  template < typename OtherComponent, typename OtherStorage >
1430 
1431  template < Dimension ptDim,
1432  typename LeftEuclideanRing, typename LeftContainer,
1433  typename RightEuclideanRing, typename RightContainer >
1434  friend inline bool
1437 
1444  template < typename OtherComponent, typename OtherStorage >
1446 
1447  template < Dimension ptDim,
1448  typename LeftEuclideanRing, typename LeftContainer,
1449  typename RightEuclideanRing, typename RightContainer >
1450  friend inline bool
1453 
1459  Component max() const;
1460 
1466  Component min() const;
1467 
1475 
1483 
1487  void negate();
1488 
1493  enum NormType { L_2, L_1, L_infty };
1494 
1506  double norm( const NormType type = L_2 ) const;
1507 
1516  double squaredNorm( ) const;
1517 
1518 
1525 
1532 
1533 
1542 
1545  void reset();
1546 
1551  inline void clear() { reset(); }
1552 
1553 
1554 
1555  // ------------------------- Standard vectors ------------------------------
1556  public:
1557 
1562  static Self diagonal( Component val = 1 );
1563 
1569  static Self base( Dimension k, Component val = 1 );
1570 
1571  // --------------- CDrawableWithBoard2D realization -------------------
1572  public:
1573 
1577  std::string className() const;
1578 
1579  // ----------------------- Interface --------------------------------------
1580  public:
1581 
1586  void selfDisplay( std::ostream & out ) const;
1587 
1592  bool isValid() const;
1593 
1595  static Self zero;
1596 
1597  // ------------------------- Hidden services ------------------------------
1598  protected:
1599 
1602 
1603  }; // end of class PointVector
1604 
1606  template<Dimension dim, typename Component, typename TC>
1607  std::ostream&
1608  operator<<( std::ostream & out, const PointVector<dim, Component, TC> & object );
1609 
1611  template< Dimension dim, typename Component, typename TC>
1613 
1614 } // namespace DGtal
1615 
1617 // Includes inline functions
1618 #include "DGtal/kernel/PointVector.ih"
1619 
1620 // //
1622 
1623 #endif // !defined PointVector_h
1624 
1625 #undef PointVector_RECURSES
1626 #endif // else defined(PointVector_RECURSES)
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
UnsignedComponent norm1() const
void selfDisplay(std::ostream &out) const
Component max() const
PointVector()
Constructor.
friend double cosineSimilarity(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Positive angle between two vectors, deduced from their scalar product.
Component Scalar
Types needed by CLinearAlgebraContainer.
Definition: PointVector.h:629
PointVector(std::initializer_list< Component > init)
Constructor from initializer list.
PointVector & operator-=(OtherComponent coeff)
Subtracts the coeff scalar number to *this.
friend auto inf(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Implements the infimum (or greatest lower bound).
friend bool isUpper(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Return true if the first point is upper the second point.
bool partialEqual(const PointVector< dim, OtherComponent, OtherContainer > &pv, const std::vector< Dimension > &dimensions) const
Partial equality.
static Self base(Dimension k, Component val=1)
PointVector & operator/=(OtherComponent coeff)
Divides *this by the coeff scalar number.
bool isLower(const PointVector< dim, OtherComponent, OtherStorage > &p) const
Return true if this point is below a given point.
const Component * data() const noexcept
PointVector(const Component &x, const Component &y)
Constructor from two values (the Dimension of the vector should be at least 2). Other components are ...
ConstReverseIterator rend() const
friend auto crossProduct(PointVector< 3, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< 3, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Cross product of two 3D Points/Vectors.
friend bool operator<=(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Comparison operator on Points/Vectors (LesserOrEqualThan).
Self & operator=(const Self &pv)
Assignement Operator.
PointVector(const PointVector< dim, LeftComponent, LeftStorage > &apoint1, const PointVector< dim, RightComponent, RightStorage > &apoint2, const BinaryFunctor &f)
Constructor taking two points and a functor as parameters.
PointVector(const Self &other)
Copy constructor.
auto dot(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::dotProduct(*this, v))
Dot product with a PointVector.
Component & operator()(Dimension i)
Definition: PointVector.h:1015
Iterator maxElement()
friend DGtal::ArithmeticConversionType< LeftEuclideanRing, RightEuclideanRing > dotProduct(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Dot product between two points/vectors.
auto inf(const PointVector< dim, OtherComponent, OtherStorage > &aPoint) const -> decltype(DGtal::inf(*this, aPoint))
Implements the infimum (or greatest lower bound).
UnsignedComponent normInfinity() const
Self & partialCopy(const PointVector< dim, OtherComponent, OtherContainer > &pv, const std::vector< Dimension > &dimensions)
Partial copy of a given PointVector.
friend auto sup(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Implements the supremum (or least upper bound).
double squaredNorm() const
double norm(const NormType type=L_2) const
ConstReverseIterator rbegin() const
Component Coordinate
Type for Point elements.
Definition: PointVector.h:617
const Component & operator()(Dimension i) const
Definition: PointVector.h:1004
friend auto operator+(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Addition operator between two Points/Vectors.
PointVector & operator+=(OtherComponent coeff)
Adds the coeff scalar number to *this.
ConstIterator end() const
void reset()
Resets all the values to zero.
ReverseIterator rbegin()
bool isValid() const
NumberTraits< Component >::UnsignedVersion UnsignedComponent
Unsigned version of the components.
Definition: PointVector.h:620
friend bool isLower(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Return true if the first point is below the second point.
BOOST_CONCEPT_ASSERT((concepts::CEuclideanRing< TEuclideanRing >))
PointVector(const Component &x, const Component &y, const Component &z)
Constructor from three values (the Dimension of the vector should be at least 3). Other components ar...
PointVector(const PointVector< dim, OtherComponent, OtherStorage > &apoint1, const UnaryFunctor &f)
Constructor taking a point and a unary functor as parameters.
PointVector(const Component &x, const Component &y, const Component &z, const Component &t)
Constructor from four values (the Dimension of the vector should be at least 4). Other components are...
PointVector< dim, TEuclideanRing, TContainer > Self
Self type.
Definition: PointVector.h:611
friend bool operator<(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Comparison operator on Points/Vectors (LesserThan).
std::string className() const
void clear()
Resets all the values to zero.
Definition: PointVector.h:1551
auto sup(const PointVector< dim, OtherComponent, OtherStorage > &aPoint) const -> decltype(DGtal::sup(*this, aPoint))
Implements the supremum (or least upper bound).
auto crossProduct(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::crossProduct(*this, v))
Cross product with a PointVector.
bool isUpper(const PointVector< dim, OtherComponent, OtherStorage > &p) const
Return true if this point is upper a given point.
Component min() const
PointVector(const Component *ptrValues)
Constructor from array of values.
friend bool operator!=(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Difference operator on Points/Vectors.
friend bool operator>=(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Comparison operator on Points/Vectors (GreaterOrEqualThan).
Container::reverse_iterator ReverseIterator
Mutable reverse iterator type.
Definition: PointVector.h:642
Container myArray
Internal data-structure: std::array with constant size.
Definition: PointVector.h:1601
Self & partialCopyInv(const PointVector< dim, OtherComponent, OtherContainer > &pv, const std::vector< Dimension > &dimensions)
Partial copy of a given PointVector.
TEuclideanRing Component
Type for Vector elements.
Definition: PointVector.h:614
ReverseIterator rend()
bool partialEqualInv(const PointVector< dim, OtherComponent, OtherContainer > &pv, const std::vector< Dimension > &dimensions) const
Partial inverse equality.
PointVector(const PointVector< dim, OtherComponent, OtherCont > &other)
Copy constructor from another component PointVector.
static Self diagonal(Component val=1)
DGtal::Dimension Dimension
Copy of the dimension type.
Definition: PointVector.h:623
Container::const_iterator ConstIterator
Constant iterator type.
Definition: PointVector.h:641
PointVector< dim, double, std::array< double, dim > > getNormalized() const
PointVector & operator*=(OtherComponent coeff)
Multiplies *this by the coeff scalar number.
Component & operator[](Dimension i)
static Self zero
Static const for zero PointVector.
Definition: PointVector.h:1595
friend auto operator*(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Multiplication operator between two Points/Vectors.
double cosineSimilarity(const PointVector< dim, OtherComponent, OtherStorage > &v) const
Positive angle between two vectors, deduced from their scalar product.
friend auto operator/(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Division operator between two Points/Vectors.
friend bool operator==(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Equality operator between two Points/Vectors.
ConstIterator begin() const
Container::const_reverse_iterator ConstReverseIterator
Constant reverse iterator type.
Definition: PointVector.h:643
~PointVector()
Destructor.
Container::iterator Iterator
Mutable iterator type.
Definition: PointVector.h:640
Dimension rows() const
Definition: PointVector.h:994
friend PointVector< 3, DGtal::ArithmeticConversionType< LeftEuclideanRing, RightEuclideanRing > > crossProduct(PointVector< 2, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< 2, RightEuclideanRing, RightContainer > const &rhs)
Cross product of two 2D Points/Vectors.
Self operator-() const
Unary minus operator.
Iterator minElement()
static const Dimension dimension
Copy of the static dimension of the Point/Vector.
Definition: PointVector.h:626
Self & partialCopy(const PointVector< dim, OtherComponent, OtherContainer > &pv, const std::vector< Dimension > &dimensions, const UnaryFunctor &f)
Partial copy of a given PointVector using a functor.
Self & partialCopyInv(const PointVector< dim, OtherComponent, OtherContainer > &pv, const std::vector< Dimension > &dimensions, const UnaryFunctor &f)
Partial copy of a given PointVector using a functor.
TContainer Container
Copy of the container type.
Definition: PointVector.h:633
const Component & operator[](Dimension i) const
DGtal is the top-level namespace which contains all DGtal functions and types.
bool operator>=(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Comparison operator on Points/Vectors (GreaterOrEqualThan).
DGtal::ArithmeticConversionType< LeftEuclideanRing, RightEuclideanRing > dotProduct(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Dot product between two points/vectors.
auto crossProduct(PointVector< 3, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< 3, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Cross product of two 3D Points/Vectors.
bool operator==(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Equality operator between two Points/Vectors.
bool operator!=(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Difference operator on Points/Vectors.
typename ArithmeticConversionTraits< T, U >::type ArithmeticConversionType
Result type of arithmetic binary operators between two given types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
bool operator<=(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Comparison operator on Points/Vectors (LesserOrEqualThan).
bool operator<(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Comparison operator on Points/Vectors (LesserThan).
bool isUpper(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Return true if the first point is upper the second point.
DGtal::uint32_t Dimension
Definition: Common.h:137
auto operator/(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Division operator between two Points/Vectors.
double cosineSimilarity(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Positive angle between two vectors, deduced from their scalar product.
KForm< Calculus, order, duality > operator*(const typename Calculus::Scalar &scalar, const KForm< Calculus, order, duality > &form)
auto inf(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Implements the infimum (or greatest lower bound).
ArithmeticConversionType< LHS, RHS > constructFromArithmeticConversion(LHS const &lhs, RHS const &rhs, Args &&... args)
Call constructor for the result type of an arithmetic operation.
std::bitset< dim > setDimensionsNotIn(const Container &dimensions)
bool operator>(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Comparison operator on Points/Vectors (GreaterThan).
KForm< Calculus, order, duality > operator-(const KForm< Calculus, order, duality > &form_a, const KForm< Calculus, order, duality > &form_b)
Circulator< TIterator > operator+(typename IteratorCirculatorTraits< TIterator >::Difference d, Circulator< TIterator > &object)
Definition: Circulator.h:453
std::bitset< dim > setDimensionsIn(const Container &dimensions)
auto sup(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Implements the supremum (or least upper bound).
bool isLower(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Return true if the first point is below the second point.
typename std::conditional< std::is_same< LeftEuclideanRing, ArithmeticConversionType< LeftEuclideanRing, RightEuclideanRing > >::value, PointVector< dim, LeftEuclideanRing >, PointVector< dim, RightEuclideanRing, RightContainer > >::type type
Definition: PointVector.h:233
typename std::conditional< std::is_same< LeftEuclideanRing, ArithmeticConversionType< LeftEuclideanRing, RightEuclideanRing > >::value, PointVector< dim, LeftEuclideanRing, LeftContainer >, PointVector< dim, RightEuclideanRing, RightContainer > >::type type
Definition: PointVector.h:197
typename std::conditional< std::is_same< LeftEuclideanRing, ArithmeticConversionType< LeftEuclideanRing, RightEuclideanRing > >::value, PointVector< dim, LeftEuclideanRing, LeftContainer >, PointVector< dim, RightEuclideanRing > >::type type
Definition: PointVector.h:215
Aim: Trait class to get result type of arithmetic binary operators between two given types.
Type trait to check if a given type is a PointVector.
Definition: PointVector.h:175
std::decay< T >::type UnsignedVersion
Alias to the unsigned version of the number type.
Definition: NumberTraits.h:90
Aim: Defines the mathematical concept equivalent to a unitary commutative ring with a division operat...
K init(Point(0, 0, 0), Point(512, 512, 512), true)
const Point aPoint(3, 4)
unsigned int dim(const Vector &z)