DGtal  0.9.2
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)
37 
38 #define PointVector_RECURSES
39 
40 #if !defined PointVector_h
41 
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 
53 #include "DGtal/base/Common.h"
54 #include "DGtal/base/CBidirectionalRange.h"
55 #include "DGtal/kernel/NumberTraits.h"
56 #include "DGtal/kernel/CEuclideanRing.h"
57 
59 
60 namespace DGtal
61 {
63  template<Dimension dim, typename Container>
64  std::bitset<dim> setDimensionsIn( const Container &dimensions );
65 
67  template<Dimension dim, typename Container>
68  std::bitset<dim> setDimensionsNotIn( const Container &dimensions );
69 
71  // class PointVector
138  template < DGtal::Dimension dim,
139  typename TEuclideanRing,
140  typename TContainer=std::array<TEuclideanRing,dim> >
142  {
143  // ----------------------- Standard services ------------------------------
144  public:
145 
147 
150 
153 
155  typedef TEuclideanRing Component;
156 
158  typedef Component Coordinate;
159 
162 
165 
167  static const Dimension dimension = dim;
168 
170  typedef Component Scalar;
171  typedef Dimension Index;
172 
174  typedef TContainer Container;
175 
176 
181  typedef typename Container::iterator Iterator;
182  typedef typename Container::const_iterator ConstIterator;
183  typedef typename Container::reverse_iterator ReverseIterator;
184  typedef typename Container::const_reverse_iterator ConstReverseIterator;
185 
189  PointVector();
190 
196  explicit PointVector( const Component* ptrValues );
197 
205  PointVector( const Component & x, const Component & y );
206 
215  PointVector( const Component & x, const Component & y, const Component & z );
216 
226  PointVector( const Component & x, const Component & y,
227  const Component & z, const Component & t );
228 
233  PointVector( std::initializer_list<Component> init );
234 
239  template<typename BinaryFunctor>
240  PointVector( const Self& apoint1, const Self& apoint2,
241  const BinaryFunctor& f );
242 
247  template<typename UnaryFunctor>
248  PointVector( const Self& apoint1,
249  const UnaryFunctor& f );
250 
254  ~PointVector();
255 
256  // ----------------------- Iterator services ------------------------------
257  public:
262  PointVector( const Self & other );
263 
269  template <typename OtherComponent, typename OtherCont>
271 
278  Self & operator= ( const Self & pv );
279 
289  Self& partialCopy (const Self & pv,
290  std::initializer_list<Dimension> dimensions);
291 
301  Self& partialCopyInv (const Self & pv,
302  std::initializer_list<Dimension> dimensions);
303 
313  Self& partialCopy (const Self & pv,
314  const std::vector<Dimension> &dimensions);
315 
325  Self& partialCopyInv (const Self & pv,
326  const std::vector<Dimension> &dimensions);
327 
336  bool partialEqual ( const Self & pv,
337  const std::vector<Dimension> &dimensions ) const;
338 
347  bool partialEqualInv ( const Self & pv,
348  const std::vector<Dimension> &dimensions ) const;
349 
350  // ----------------------- Iterator services ------------------------------
351  public:
357  Iterator begin();
358 
364  Iterator end();
365 
371  ConstIterator begin() const;
372 
378  ConstIterator end() const;
379 
385  ReverseIterator rbegin();
386 
392  ReverseIterator rend();
393 
399  ConstReverseIterator rbegin() const;
400 
406  ConstReverseIterator rend() const;
407 
408  // ----------------------- Array services ------------------------------
409  public:
414  static Dimension size();
415  inline Dimension rows() const { return dim; }
416 
424  const Component& operator[]( Dimension i ) const;
425  inline const Component& operator()( Dimension i ) const { return (*this)[i]; }
426 
435  Component& operator[](Dimension i );
436  Component& operator()(Dimension i ) { return (*this)[i]; }
437 
438  // ----------------------- Comparison operations --------------------------
439  public:
449  bool operator== ( const Self & pv ) const;
450 
460  bool operator!= ( const Self & pv ) const;
461 
471  bool operator< ( const Self & pv ) const;
472 
482  bool operator<= ( const Self & pv ) const;
483 
493  bool operator> ( const Self & pv ) const;
494 
504  bool operator>= ( const Self & pv ) const;
505 
506  // ----------------------- Operations ------------------------------
507  public:
514  PointVector & operator*= ( Component coeff );
515 
522  PointVector operator*( Component coeff ) const;
523 
530  Component dot( const Self &v) const;
531 
538  Self crossProduct( const Self &v) const;
539 
545  double cosineSimilarity ( const Self & v ) const;
546 
553  Self & operator+= ( const Self & v );
554 
561  Self operator+ ( const Self & v ) const;
562 
569  Self & operator-= ( const Self & v );
570 
578  Self operator- ( const Self & v ) const;
579 
586  Self operator-() const;
587 
588 
595  Self & operator/= ( const Self & v );
596 
603  Self operator/ ( const Self & v ) const ;
604 
611  Self operator/ ( const Component coeff ) const;
612 
619  Self & operator/= ( const Component coeff );
620 
629  template<typename AnotherComponent>
631 
632 
636  void reset();
637 
641  inline void clear() { reset(); }
642 
652  Self inf( const Self& apoint ) const;
653 
663  Self sup( const Self& apoint ) const;
664 
670  bool isLower( const Self& p ) const;
671 
677  bool isUpper( const Self& p ) const;
678 
684  Component max() const;
685 
691  Component min() const;
692 
699  Iterator maxElement() ;
700 
707  Iterator minElement() ;
708 
712  void negate();
713 
718  enum NormType { L_2, L_1, L_infty };
719 
731  double norm( const NormType type = L_2 ) const;
732 
738  UnsignedComponent norm1() const;
739 
745  UnsignedComponent normInfinity() const;
746 
747 
756 
757 
758  // ------------------------- Standard vectors ------------------------------
759  public:
760 
765  static Self diagonal( Component val = 1 );
766 
772  static Self base( Dimension k, Component val = 1 );
773 
774  // --------------- CDrawableWithBoard2D realization -------------------
775  public:
776 
780  std::string className() const;
781 
782  // ----------------------- Interface --------------------------------------
783  public:
784 
789  void selfDisplay( std::ostream & out ) const;
790 
795  bool isValid() const;
796 
798  static Self zero;
799 
800  // ------------------------- Hidden services ------------------------------
801  protected:
802 
804  Container myArray;
805 
806  }; // end of class PointVector
807 
809  template<Dimension dim, typename Component, typename TC>
810  std::ostream&
811  operator<<( std::ostream & out, const PointVector<dim, Component, TC> & object );
812 
822  template<Dimension dim, typename Component, typename Container>
824  operator*( Component coeff,
825  const PointVector<dim, Component,Container> & aVector );
826 
827 
829  template< Dimension dim, typename Component, typename TC>
831 
832 
833 } // namespace DGtal
834 
836 // Includes inline functions
837 #include "DGtal/kernel/PointVector.ih"
838 
839 // //
841 
842 #endif // !defined PointVector_h
843 
844 #undef PointVector_RECURSES
845 #endif // else defined(PointVector_RECURSES)
Self & operator+=(const Self &v)
Self & operator=(const Self &pv)
void selfDisplay(std::ostream &out) const
Container::reverse_iterator ReverseIterator
Definition: PointVector.h:183
static const Dimension dimension
Copy of the static dimension of the Point/Vector.
Definition: PointVector.h:167
Component Coordinate
Type for Point elements.
Definition: PointVector.h:158
Self operator/(const Self &v) const
static Self diagonal(Component val=1)
bool partialEqualInv(const Self &pv, const std::vector< Dimension > &dimensions) const
std::bitset< dim > setDimensionsNotIn(const Container &dimensions)
const Component & operator()(Dimension i) const
Definition: PointVector.h:425
Component max() const
DGtal::uint32_t Dimension
Definition: Common.h:113
bool isLower(const Self &p) const
Self sup(const Self &apoint) const
Self & partialCopy(const Self &pv, std::initializer_list< Dimension > dimensions)
const Component & operator[](Dimension i) const
bool isValid() const
UnsignedComponent norm1() const
ReverseIterator rend()
DGtal::Dimension Dimension
Copy of the dimension type.
Definition: PointVector.h:164
Component Scalar
Types needed by CLinearAlgebraContainer.
Definition: PointVector.h:170
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
TContainer Container
Copy of the container type.
Definition: PointVector.h:174
Self crossProduct(const Self &v) const
bool operator!=(const Self &pv) const
bool partialEqual(const Self &pv, const std::vector< Dimension > &dimensions) const
UnsignedComponent normInfinity() const
Aim: Defines the mathematical concept equivalent to a unitary commutative ring with a division operat...
ReverseIterator rbegin()
Self operator+(const Self &v) const
Self inf(const Self &apoint) const
PointVector operator*(Component coeff) const
PointVector< dim, TEuclideanRing, TContainer > Self
Self type.
Definition: PointVector.h:152
bool isUpper(const Self &p) const
BOOST_CONCEPT_ASSERT((concepts::CEuclideanRing< TEuclideanRing >))
NumberTraits< Component >::UnsignedVersion UnsignedComponent
Unsigned version of the components.
Definition: PointVector.h:161
Container::const_iterator ConstIterator
Definition: PointVector.h:182
DGtal is the top-level namespace which contains all DGtal functions and types.
Self & operator/=(const Self &v)
Iterator maxElement()
Container::const_reverse_iterator ConstReverseIterator
Definition: PointVector.h:184
bool operator>=(const Self &pv) const
static Dimension size()
static Self base(Dimension k, Component val=1)
double norm(const NormType type=L_2) const
std::bitset< dim > setDimensionsIn(const Container &dimensions)
PointVector & operator*=(Component coeff)
Self & operator-=(const Self &v)
Iterator minElement()
double cosineSimilarity(const Self &v) const
Component min() const
bool operator>(const Self &pv) const
Dimension rows() const
Definition: PointVector.h:415
bool operator<=(const Self &pv) const
static Self zero
Static const for zero PointVector.
Definition: PointVector.h:798
Container::iterator Iterator
Definition: PointVector.h:181
Component & operator()(Dimension i)
Definition: PointVector.h:436
bool operator==(const Self &pv) const
KForm< Calculus, order, duality > operator*(const typename Calculus::Scalar &scalar, const KForm< Calculus, order, duality > &form)
Self & partialCopyInv(const Self &pv, std::initializer_list< Dimension > dimensions)
Component dot(const Self &v) const
Container myArray
Internal data-structure: std::array with constant size.
Definition: PointVector.h:804
bool operator<(const Self &pv) const
Self operator-() const
PointVector< dim, double, std::array< double, dim > > getNormalized() const
std::string className() const
TEuclideanRing Component
Type for Vector elements.
Definition: PointVector.h:155