DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
51 #ifdef CPP11_ARRAY
52 #include <array>
53 #else
54 #include <boost/array.hpp>
55 #endif
56 
57 #include <vector>
58 
59 #include "DGtal/base/Common.h"
60 #include "DGtal/base/CBidirectionalRange.h"
61 #include "DGtal/kernel/NumberTraits.h"
62 #include "DGtal/kernel/CEuclideanRing.h"
63 
64 //#include "DGtal/io/boards/Board2D.h"
65 #include "DGtal/io/Color.h"
66 //#include "DGtal/io/Display3D.h"
67 
68 #ifdef _MSC_VER
69 #if defined( max )
70 #undef max
71 #define _HAS_MSVC_MAX_ true
72 #endif
73 #if defined( min )
74 #undef min
75 #define _HAS_MSVC_MIN_ true
76 #endif
77 #endif
78 
80 
81 namespace DGtal
82 {
84  template<Dimension dim, typename Container>
85  std::bitset<dim> setDimensionsIn( const Container &dimensions );
86 
88  template<Dimension dim, typename Container>
89  std::bitset<dim> setDimensionsNotIn( const Container &dimensions );
90 
92  // class PointVector
152  template < DGtal::Dimension dim, typename TEuclideanRing >
154  {
155  // ----------------------- Standard services ------------------------------
156  public:
157 
159 
162 
164  typedef TEuclideanRing Component;
165 
168 
171 
174 
176  static const Dimension dimension = dim;
177 
182 #ifdef CPP11_ARRAY
183  typedef typename std::array<Component, dimension>::iterator Iterator;
184  typedef typename std::array<Component, dimension>::const_iterator ConstIterator;
185  typedef typename std::array<Component, dimension>::reverse_iterator ReverseIterator;
186  typedef typename std::array<Component, dimension>::const_reverse_iterator ConstReverseIterator;
187 #else
188  typedef typename boost::array<Component, dimension>::iterator Iterator;
189  typedef typename boost::array<Component, dimension>::const_iterator ConstIterator;
190  typedef typename boost::array<Component, dimension>::reverse_iterator ReverseIterator;
191  typedef typename boost::array<Component, dimension>::const_reverse_iterator ConstReverseIterator;
192 #endif
193 
196  PointVector();
197 
203  explicit PointVector( const Component* ptrValues );
204 
212  PointVector( const Component & x, const Component & y );
213 
222  PointVector( const Component & x, const Component & y, const Component & z );
223 
233  PointVector( const Component & x, const Component & y, const Component & z, const Component & t );
234 
235 #ifdef CPP11_INITIALIZER_LIST
236 
240  PointVector( std::initializer_list<Component> init );
241 #endif // CPP11_INITIALIZER_LIST
242 
247  template<typename Functor>
248  PointVector( const Self& apoint1, const Self& apoint2,
249  const Functor& f );
250 
254  ~PointVector();
255 
256  // ----------------------- Iterator services ------------------------------
257  public:
262  PointVector( const Self & other );
263 
269  template <typename OtherComponent>
271 
278  Self & operator= ( const Self & pv );
279 
280 
281 #ifdef CPP11_INITIALIZER_LIST
282 
291  Self& partialCopy (const Self & pv,
292  std::initializer_list<Dimension> dimensions);
293 
303  Self& partialCopyInv (const Self & pv,
304  std::initializer_list<Dimension> dimensions);
305 #endif
306 
315  Self& partialCopy (const Self & pv,
316  const std::vector<Dimension> &dimensions);
317 
327  Self& partialCopyInv (const Self & pv,
328  const std::vector<Dimension> &dimensions);
329 
337  bool partialEqual ( const Self & pv,
338  const std::vector<Dimension> &dimensions ) const;
339 
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 
386 
393 
400 
406  ConstReverseIterator rend() const;
407 
408  // ----------------------- Array services ------------------------------
409  public:
415  static Dimension size();
416 
424  const Component& at( Dimension i ) const;
425 
434  Component& at( Dimension i );
435 
443  const Component& operator[]( Dimension i ) const;
444 
454 
455  // ----------------------- Comparison operations --------------------------
456  public:
464  bool operator== ( const Self & pv ) const;
465 
473  bool operator!= ( const Self & pv ) const;
474 
482  bool operator< ( const Self & pv ) const;
483 
491  bool operator<= ( const Self & pv ) const;
492 
500  bool operator> ( const Self & pv ) const;
501 
509  bool operator>= ( const Self & pv ) const;
510 
511  // ----------------------- Operations ------------------------------
512  public:
519  PointVector & operator*= ( Component coeff );
520 
527  PointVector operator*( Component coeff ) const;
528 
535  Component dot( const Self &v) const;
536 
543  Self & operator+= ( const Self & v );
544 
551  Self operator+ ( const Self & v ) const;
552 
559  Self & operator-= ( const Self & v );
560 
568  Self operator- ( const Self & v ) const;
569 
570 
577  Self & operator/= ( const Self & v );
578 
585  Self operator/ ( const Self & v ) const ;
586 
593  Self operator/ ( const Component coeff );
594 
601  Self & operator/= ( const Component coeff );
602 
611  template<typename AnotherComponent>
613 
614 
618  void reset();
619 
629  Self inf( const Self& apoint ) const;
630 
640  Self sup( const Self& apoint ) const;
641 
647  bool isLower( const Self& p ) const;
648 
654  bool isUpper( const Self& p ) const;
655 
661  Component max() const;
662 
668  Component min() const;
669 
677 
685 
689  void negate();
690 
695  enum NormType { L_2, L_1, L_infty };
696 
708  double norm( const NormType type = L_2 ) const;
709 
715  UnsignedComponent norm1() const;
716 
723 
724 
732 
733 
734  // ------------------------- Standard vectors ------------------------------
735  public:
736 
741  static Self diagonal( Component val = 1 );
742 
748  static Self base( Dimension k, Component val = 1 );
749 
750  // ------------------------- Private Datas -------------------------------
751  private:
752 
753 
754 
755  // --------------- CDrawableWithBoard2D realization -------------------
756  public:
757 
762  //DrawableWithBoard2D* defaultStyle( std::string mode = "" ) const;
763 
764 
765 
769  std::string className() const;
770 
771  // ----------------------- Interface --------------------------------------
772  public:
773 
778  void selfDisplay( std::ostream & out ) const;
779 
784  bool isValid() const;
785 
787  static Self zero;
788 
789  // ------------------------- Hidden services ------------------------------
790  //protected:
791 
793 #ifdef CPP11_ARRAY
794  std::array<Component, dimension> myArray;
795 #else
796  boost::array<Component, dimension> myArray;
797 #endif
798 
799  }; // end of class PointVector
800 
802  template<Dimension dim, typename Component>
803  std::ostream&
804  operator<<( std::ostream & out, const PointVector<dim, Component> & object );
805 
806  template< Dimension dim, typename Component>
808 } // namespace DGtal
809 
811 // Includes inline functions
812 #include "DGtal/kernel/PointVector.ih"
813 
814 // //
816 
817 #endif // !defined PointVector_h
818 
819 #undef PointVector_RECURSES
820 #endif // else defined(PointVector_RECURSES)