Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes

DGtal::PointVector< N, T > Class Template Reference

Aim: Implements basic operations that will be used in Point and Vector classes. More...

#include <PointVector.h>

Inheritance diagram for DGtal::PointVector< N, T >:
Inheritance graph
[legend]
Collaboration diagram for DGtal::PointVector< N, T >:
Collaboration graph
[legend]

Data Structures

struct  DefaultDrawStyleGrid
struct  DefaultDrawStylePaving

Public Types

enum  NormType { L_2, L_1, L_infty }
typedef boost::array< T, N >
::iterator 
Iterator
typedef boost::array< T, N >
::const_iterator 
ConstIterator
typedef T Component
typedef T Coordinate
typedef std::size_t DimensionType
typedef IntegerTraits< T >
::UnsignedVersion 
UnsignedComponent

Public Member Functions

 PointVector ()
 PointVector (const T *ptrValues)
 PointVector (const T &x, const T &y)
 PointVector (const T &x, const T &y, const T &z)
 PointVector (const T &x, const T &y, const T &z, const T &t)
template<typename Functor >
 PointVector (const PointVector &apoint1, const PointVector &apoint2, const Functor &f)
 ~PointVector ()
 PointVector (const PointVector &other)
PointVectoroperator= (const PointVector &pv)
template<typename Size >
PointVector< N, T > & partialCopy (const PointVector< N, T > &pv, const std::vector< Size > &dimensions)
Iterator begin ()
Iterator end ()
ConstIterator begin () const
ConstIterator end () const
const T & at (std::size_t i) const
T & at (std::size_t i)
const T & operator[] (std::size_t i) const
T & operator[] (std::size_t i)
bool operator== (const PointVector &pv) const
bool operator!= (const PointVector &pv) const
bool operator< (const PointVector &pv) const
bool operator<= (const PointVector &pv) const
bool operator> (const PointVector &pv) const
bool operator>= (const PointVector &pv) const
PointVectoroperator*= (T coeff)
PointVector operator* (T coeff)
PointVectoroperator+= (const PointVector &v)
PointVector operator+ (const PointVector &v) const
PointVectoroperator-= (const PointVector &v)
PointVector operator- (const PointVector &v) const
void reset ()
PointVector inf (const PointVector &apoint) const
PointVector sup (const PointVector &apoint) const
bool isLower (const PointVector &p) const
bool isUpper (const PointVector &p) const
double norm (const NormType type=L_2) const
UnsignedComponent norm1 () const
UnsignedComponent normInfinity () const
DrawableWithDGtalBoarddefaultStyle (std::string mode="") const
std::string styleName () const
void selfDraw (DGtalBoard &board) const
void selfDrawAsPaving (DGtalBoard &board) const
void selfDrawAsGrid (DGtalBoard &board) const
void selfDraw (DGtalBoard &board, const PointVector &startingPoint) const
void selfDisplay (std::ostream &out) const
bool isValid () const

Static Public Member Functions

static std::size_t size ()
static std::size_t dimension ()
static PointVector diagonal (Component val=1)
static PointVector base (DimensionType k, Component val=1)

Static Public Attributes

static const std::size_t Dimension = N
static PointVector zero

Private Attributes

boost::array< T, N > myArray

Detailed Description

template<std::size_t N, typename T = DGtal::int32_t>
class DGtal::PointVector< N, T >

Aim: Implements basic operations that will be used in Point and Vector classes.

Description of class 'PointVector'

A PointVector may represent either a digital point or a digital vector depending on the context. For performance reasons, these two types are just aliases. The user should take care how to use it depending on the context. For instance, adding two points has no meaning, but will be authorized by the compiler.

The default less than operator is the one of the lexicographic ordering, starting from dimension 0 to N-1.

PointVector also realizes the concept CLattice with an infimum (meet, greatest lower bound) and a supremum (join, least upper bound) operation.

Usage example:

 ...
 typedef PointVector<5, double> VectorD5;
 VectorD5 p, q, r;

 p.at(1) = 2.0;  // p = {0.0, 2.0, 0.0, 0.0, 0.0}
 q.at(3) = -5.5   // q = {0.0, 0.0, 0.0, -5.5, 0.0}
 r =  p + q ;   //  r = {0.0, 2.0, 0.0, -5.5, 0.0}

 d = r.norm( DGtal::PointVector::L_infty ); // d = 5.5
 ...
Todo:
continue snippet
See also:
testPointVector.cpp
Examples:

dgtalboard-1-points.cpp, dgtalboard-2-sets.cpp, dgtalboard-3-custom-classes.cpp, dgtalboard-3-custom-points.cpp, dgtalboard-4-colormaps.cpp, dgtalboard-5-greedy-dss.cpp, distancetransform2D.cpp, and DSS.cpp.


Member Typedef Documentation

template<std::size_t N, typename T = DGtal::int32_t>
typedef T DGtal::PointVector< N, T >::Component
Todo:
documentation here!
template<std::size_t N, typename T = DGtal::int32_t>
typedef boost::array<T, N>::const_iterator DGtal::PointVector< N, T >::ConstIterator
template<std::size_t N, typename T = DGtal::int32_t>
typedef T DGtal::PointVector< N, T >::Coordinate
template<std::size_t N, typename T = DGtal::int32_t>
typedef std::size_t DGtal::PointVector< N, T >::DimensionType
template<std::size_t N, typename T = DGtal::int32_t>
typedef boost::array<T, N>::iterator DGtal::PointVector< N, T >::Iterator

Copy of the Boost::array iterator type

template<std::size_t N, typename T = DGtal::int32_t>
typedef IntegerTraits<T>::UnsignedVersion DGtal::PointVector< N, T >::UnsignedComponent

Member Enumeration Documentation

template<std::size_t N, typename T = DGtal::int32_t>
enum DGtal::PointVector::NormType

Specify the set of norm types

Enumerator:
L_2 
L_1 
L_infty 

Constructor & Destructor Documentation

template<std::size_t N, typename T = DGtal::int32_t>
DGtal::PointVector< N, T >::PointVector (  ) 

Constructor.

template<std::size_t N, typename T = DGtal::int32_t>
DGtal::PointVector< N, T >::PointVector ( const T *  ptrValues  )  [explicit]

Constructor from array of values.

Parameters:
ptrValues the array of values.
template<std::size_t N, typename T = DGtal::int32_t>
DGtal::PointVector< N, T >::PointVector ( const T &  x,
const T &  y 
)

Constructor from two values (the Dimension of the vector should be at least 2). Other components are set to 0.

Parameters:
x the first value.
y the second value.
template<std::size_t N, typename T = DGtal::int32_t>
DGtal::PointVector< N, T >::PointVector ( const T &  x,
const T &  y,
const T &  z 
)

Constructor from three values (the Dimension of the vector should be at least 3). Other components are set to 0.

Parameters:
x the first value.
y the second value.
z the third value.
template<std::size_t N, typename T = DGtal::int32_t>
DGtal::PointVector< N, T >::PointVector ( const T &  x,
const T &  y,
const T &  z,
const T &  t 
)

Constructor from four values (the Dimension of the vector should be at least 4). Other components are set to 0.

Parameters:
x the first value.
y the second value.
z the third value.
t the fourth value.
template<std::size_t N, typename T = DGtal::int32_t>
template<typename Functor >
DGtal::PointVector< N, T >::PointVector ( const PointVector< N, T > &  apoint1,
const PointVector< N, T > &  apoint2,
const Functor &  f 
)

Constructor taking apoint and a functor as parameters. The new point is initialized by the result of functor f for each coordinate of apoint1 and apoint2

template<std::size_t N, typename T = DGtal::int32_t>
DGtal::PointVector< N, T >::~PointVector (  ) 

Destructor.

template<std::size_t N, typename T = DGtal::int32_t>
DGtal::PointVector< N, T >::PointVector ( const PointVector< N, T > &  other  ) 

Copy constructor.

Parameters:
other the object to clone.

Member Function Documentation

template<std::size_t N, typename T = DGtal::int32_t>
const T& DGtal::PointVector< N, T >::at ( std::size_t  i  )  const
template<std::size_t N, typename T = DGtal::int32_t>
T& DGtal::PointVector< N, T >::at ( std::size_t  i  ) 

Returns a non-const reference to the i-th element of the vector.

Precondition:
The i index must lie between 0 and size() .
Parameters:
i is the index of the retrieved coefficient.
template<std::size_t N, typename T = DGtal::int32_t>
static PointVector DGtal::PointVector< N, T >::base ( DimensionType  k,
Component  val = 1 
) [static]
Parameters:
k any number between 0 and Dimension-1.
val any value.
Returns:
the [k]-th base vector (0,0, ..., 0, val, 0, ..., 0).
template<std::size_t N, typename T = DGtal::int32_t>
ConstIterator DGtal::PointVector< N, T >::begin (  )  const

PointVector begin() const iterator.

Returns:
an ConstIterator on the first element of a Point/Vector.
template<std::size_t N, typename T = DGtal::int32_t>
Iterator DGtal::PointVector< N, T >::begin (  ) 

PointVector begin() iterator.

Returns:
an Iterator on the first element of a Point/Vector.

Referenced by testIterator().

template<std::size_t N, typename T = DGtal::int32_t>
DrawableWithDGtalBoard* DGtal::PointVector< N, T >::defaultStyle ( std::string  mode = ""  )  const

Default drawing style object.

Returns:
the dyn. alloc. default style for this object.
template<std::size_t N, typename T = DGtal::int32_t>
static PointVector DGtal::PointVector< N, T >::diagonal ( Component  val = 1  )  [static]
Parameters:
val any value.
Returns:
the diagonal vector (val,val, .. val).
template<std::size_t N, typename T = DGtal::int32_t>
static std::size_t DGtal::PointVector< N, T >::dimension (  )  [static]

Static method to obtain the dimension of a Point/Vector

Returns:
the size of the vector (i.e. the number of its elements).

Referenced by testSimplePoint(), and testSimpleVector().

template<std::size_t N, typename T = DGtal::int32_t>
Iterator DGtal::PointVector< N, T >::end (  ) 

PointVector end() iterator.

Returns:
an Iterator on the last element of a Point/Vector.

Referenced by testIterator().

template<std::size_t N, typename T = DGtal::int32_t>
ConstIterator DGtal::PointVector< N, T >::end (  )  const

PointVector end() const iterator.

Returns:
a ConstIterator on the last element of a Point/Vector.
template<std::size_t N, typename T = DGtal::int32_t>
PointVector DGtal::PointVector< N, T >::inf ( const PointVector< N, T > &  apoint  )  const

Implements the infimum (or greatest lower bound). It means the point whose coordinates are exactly the minimum of the two points coordinate by coordinate.

Parameters:
apoint any point.
Returns:
a new point being the inf between *this and apoint.
See also:
isLower

Referenced by testOperators().

template<std::size_t N, typename T = DGtal::int32_t>
bool DGtal::PointVector< N, T >::isLower ( const PointVector< N, T > &  p  )  const
Parameters:
p any point.
Returns:
true if this is below p (ie. this==inf(this,p)) NB: faster than computing the infimum and compare it afterwards.
template<std::size_t N, typename T = DGtal::int32_t>
bool DGtal::PointVector< N, T >::isUpper ( const PointVector< N, T > &  p  )  const
Parameters:
p any point.
Returns:
true if this is upper p (ie. this==sup(this,p)) NB: faster than computing the supremum and compare it afterwards.
template<std::size_t N, typename T = DGtal::int32_t>
bool DGtal::PointVector< N, T >::isValid (  )  const

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.
template<std::size_t N, typename T = DGtal::int32_t>
double DGtal::PointVector< N, T >::norm ( const NormType  type = L_2  )  const

Computes the norm of a point/vector.

Parameters:
type specifies the type of norm to consider (see NormType)
Returns:
the norm of the point/vector
template<std::size_t N, typename T = DGtal::int32_t>
UnsignedComponent DGtal::PointVector< N, T >::norm1 (  )  const

Computes the 1-norm of a vector.

Returns:
the absolute sum of the components of this vector.

Referenced by testIntegerNorms().

template<std::size_t N, typename T = DGtal::int32_t>
UnsignedComponent DGtal::PointVector< N, T >::normInfinity (  )  const

Computes the infinity-norm of a vector.

Returns:
the maximum absolute value of the components of this vector.

Referenced by testIntegerNorms().

template<std::size_t N, typename T = DGtal::int32_t>
bool DGtal::PointVector< N, T >::operator!= ( const PointVector< N, T > &  pv  )  const

Difference operator on Points/Vectors.

Parameters:
pv the Point/Vector to compare to this.
Returns:
true iff this differs from pv, false otherwise.
template<std::size_t N, typename T = DGtal::int32_t>
PointVector DGtal::PointVector< N, T >::operator* ( coeff  ) 

Multiplication operator with a scalar number

Parameters:
coeff is the factor 'this' is multiplied by.
Returns:
a new Point that is the multiplication of 'this' by coeff.
template<std::size_t N, typename T = DGtal::int32_t>
PointVector& DGtal::PointVector< N, T >::operator*= ( coeff  ) 

Multiplies *this by the coeff scalar number.

Parameters:
coeff is the factor *this get multiplied by.
Returns:
a reference on 'this'.
template<std::size_t N, typename T = DGtal::int32_t>
PointVector DGtal::PointVector< N, T >::operator+ ( const PointVector< N, T > &  v  )  const

Addition operator.

Parameters:
v is the Point that gets added to *this.
Returns:
a new Point that is the addition of 'this' to [v].
template<std::size_t N, typename T = DGtal::int32_t>
PointVector& DGtal::PointVector< N, T >::operator+= ( const PointVector< N, T > &  v  ) 

Addition operator with assignement.

Parameters:
v is the Point that gets added to *this.
Returns:
a reference on 'this'.
template<std::size_t N, typename T = DGtal::int32_t>
PointVector DGtal::PointVector< N, T >::operator- ( const PointVector< N, T > &  v  )  const

Substraction operator. Point - Vector => Point

Parameters:
v is the Point that gets added to *this.
Returns:
a new Point that is the subtraction 'this'-[v].
template<std::size_t N, typename T = DGtal::int32_t>
PointVector& DGtal::PointVector< N, T >::operator-= ( const PointVector< N, T > &  v  ) 

Substraction operator with assignement.

Parameters:
v is the Point that gets substracted to *this.
Returns:
a reference on 'this'.
template<std::size_t N, typename T = DGtal::int32_t>
bool DGtal::PointVector< N, T >::operator< ( const PointVector< N, T > &  pv  )  const

Comparison operator on Points/Vectors (LesserThan).

Parameters:
pv the Point/Vector to compare to this.
Returns:
true iff this < pv, false otherwise.
template<std::size_t N, typename T = DGtal::int32_t>
bool DGtal::PointVector< N, T >::operator<= ( const PointVector< N, T > &  pv  )  const

Comparison operator on Points/Vectors (LesserOrEqualThan).

Parameters:
pv the Point/Vector to compare to this.
Returns:
true iff this <= pv, false otherwise.
template<std::size_t N, typename T = DGtal::int32_t>
PointVector& DGtal::PointVector< N, T >::operator= ( const PointVector< N, T > &  pv  ) 

Assignement Operator

Parameters:
other the object to copy.
Returns:
a reference on 'this'.
template<std::size_t N, typename T = DGtal::int32_t>
bool DGtal::PointVector< N, T >::operator== ( const PointVector< N, T > &  pv  )  const

Equality operator.

Parameters:
pv Point/Vector to compare to this.
Returns:
true iff points are equal.
template<std::size_t N, typename T = DGtal::int32_t>
bool DGtal::PointVector< N, T >::operator> ( const PointVector< N, T > &  pv  )  const

Comparison operator on Points/Vectors (GreaterThan).

Parameters:
pv the Point/Vector to compare to this.
Returns:
true iff this > pv, false otherwise.
template<std::size_t N, typename T = DGtal::int32_t>
bool DGtal::PointVector< N, T >::operator>= ( const PointVector< N, T > &  pv  )  const

Comparison operator on Points/Vectors (GreaterOrEqualThan).

Parameters:
pv the Point/Vector to compare to this.
Returns:
true iff this >= pv, false otherwise.
template<std::size_t N, typename T = DGtal::int32_t>
const T& DGtal::PointVector< N, T >::operator[] ( std::size_t  i  )  const

Returns the i-th coefficient of the vector.

Precondition:
The i index must lie between 0 and size() .
Parameters:
i is the index of the retrieved coefficient.
template<std::size_t N, typename T = DGtal::int32_t>
T& DGtal::PointVector< N, T >::operator[] ( std::size_t  i  ) 

Returns a non-const reference to the i-th element of the vector.

Precondition:
The i index must lie between 0 and size() .
Parameters:
i is the index of the retrieved coefficient.
template<std::size_t N, typename T = DGtal::int32_t>
template<typename Size >
PointVector<N,T>& DGtal::PointVector< N, T >::partialCopy ( const PointVector< N, T > &  pv,
const std::vector< Size > &  dimensions 
)

Partial copy of a given PointVector.

Parameters:
other the object to copy.
dim the dimensions of v to copy (Size between 0 and N, all differents).
Returns:
a reference on 'this'.
template<std::size_t N, typename T = DGtal::int32_t>
void DGtal::PointVector< N, T >::reset (  ) 

Resets all the values to zero.

template<std::size_t N, typename T = DGtal::int32_t>
void DGtal::PointVector< N, T >::selfDisplay ( std::ostream &  out  )  const

Writes/Displays the object on an output stream.

Parameters:
out the output stream where the object is written.
template<std::size_t N, typename T = DGtal::int32_t>
void DGtal::PointVector< N, T >::selfDraw ( DGtalBoard board  )  const

Draw the object on a DGtalBoard board.

Parameters:
board the output board where the object is drawn.
template<std::size_t N, typename T = DGtal::int32_t>
void DGtal::PointVector< N, T >::selfDraw ( DGtalBoard board,
const PointVector< N, T > &  startingPoint 
) const

Draw the object (as a Vector from aPoint) on a DGtalBoard board

Parameters:
board the output board where the object is drawn.
startingPoint the starting point of the vector
Template Parameters:
Functor a Functor to specialize the Board style
template<std::size_t N, typename T = DGtal::int32_t>
void DGtal::PointVector< N, T >::selfDrawAsGrid ( DGtalBoard board  )  const

Draw a pixel as a point on a LiBoard board

Parameters:
board the output board where the object is drawn.
template<std::size_t N, typename T = DGtal::int32_t>
void DGtal::PointVector< N, T >::selfDrawAsPaving ( DGtalBoard board  )  const

Draw a pixel as a unit square on a DGtalBoard board.

Parameters:
board the output board where the object is drawn.
template<std::size_t N, typename T = DGtal::int32_t>
static std::size_t DGtal::PointVector< N, T >::size (  )  [static]

Returns the size of the vector (i.e. the number of its coefficients). Same as getDimension

template<std::size_t N, typename T = DGtal::int32_t>
std::string DGtal::PointVector< N, T >::styleName (  )  const
Returns:
the style name used for drawing this object.
Examples:
dgtalboard-3-custom-classes.cpp, and dgtalboard-4-colormaps.cpp.
template<std::size_t N, typename T = DGtal::int32_t>
PointVector DGtal::PointVector< N, T >::sup ( const PointVector< N, T > &  apoint  )  const

Implements the supremum (or least upper bound). It means the point whose coordinates are exactly the maximum of the two points coordinate by coordinate.

Parameters:
apoint any point.
Returns:
a new point being the sup between *this and apoint.
See also:
isUpper

Referenced by testOperators().


Field Documentation

template<std::size_t N, typename T = DGtal::int32_t>
const std::size_t DGtal::PointVector< N, T >::Dimension = N [static]
template<std::size_t N, typename T = DGtal::int32_t>
boost::array<T, N> DGtal::PointVector< N, T >::myArray [private]

Internal data-structure: boost/array with constant size.

template<std::size_t N, typename T = DGtal::int32_t>
PointVector< N, T > DGtal::PointVector< N, T >::zero [static]

Static const for zero PointVector.


The documentation for this class was generated from the following file: