DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
DGtal::Signal< TValue > Class Template Reference

#include <Signal.h>

Inheritance diagram for DGtal::Signal< TValue >:
Inheritance graph
[legend]
Collaboration diagram for DGtal::Signal< TValue >:
Collaboration graph
[legend]

Public Types

typedef TValue Value

Public Member Functions

 ~Signal ()
 Signal ()
 Signal (unsigned int size, int z, bool periodic, const TValue &def=TValue(0))
 Signal (const TValue *t, unsigned int size, int z, bool periodic, const TValue &def=TValue(0))
 Signal (const Signal< TValue > &other)
Signal< TValue > & operator= (const Signal< TValue > &other)
void init (unsigned int s, int z=0, bool p=false, const TValue &def=TValue(0))
void init (const TValue *t, unsigned int size, int z=0, bool p=false, const TValue &def=TValue(0))
unsigned int size () const
TValue & operator[] (int i)
const TValue & operator[] (int i) const
void setAll (const TValue &val=TValue(0))
void multiply (const TValue &val)
Signal< TValue > operator* (const Signal< TValue > &G)
void selfDisplay (std::ostream &out) const
bool isValid () const

Static Public Member Functions

static Signal< TValue > G2 ()
static Signal< TValue > H2 ()
static Signal< TValue > Delta ()
static Signal< TValue > G2n (unsigned int n)
static Signal< TValue > H2n (unsigned int n)
static Signal< TValue > D2n (unsigned int n)

Private Attributes

CowPtr< SignalData< TValue > > m_data

Detailed Description

template<typename TValue>
class DGtal::Signal< TValue >

Aim: Represents a discrete signal, periodic or not. The signal can be passed by value since it is only cloned when modified.

Description of template class 'Signal'

Template Parameters:
TValuethe type chosen for each sample (generally float or double).

This class is a backport from ImaGene.

Definition at line 162 of file Signal.h.


Member Typedef Documentation

template<typename TValue>
typedef TValue DGtal::Signal< TValue >::Value

Definition at line 166 of file Signal.h.


Constructor & Destructor Documentation

template<typename TValue >
DGtal::Signal< TValue >::~Signal ( )
inline

Destructor.

Definition at line 278 of file Signal.ih.

{
}
template<typename TValue >
DGtal::Signal< TValue >::Signal ( )
inline

Constructor.

Destructor.

Definition at line 231 of file Signal.ih.

: m_data( 0 )
{
}
template<typename TValue>
DGtal::Signal< TValue >::Signal ( unsigned int  asize,
int  z,
bool  periodic,
const TValue &  def = TValue( 0 ) 
)
inline

Constructor.

Parameters:
sizethe size of the signal.
zthe index of the zero-th element.
periodic'true' if the signal is periodic.
defthe default value.

Constructor.

Parameters:
asizethe size of the signal.
zthe index of the zero-th element.
periodic'true' if the signal is periodic.
defthe default value.

Definition at line 246 of file Signal.ih.

References DGtal::Signal< TValue >::init().

: m_data( new SignalData<TValue>() )
{
m_data->init( asize, z, periodic, def );
}
template<typename TValue>
DGtal::Signal< TValue >::Signal ( const TValue *  t,
unsigned int  asize,
int  z,
bool  periodic,
const TValue &  def = TValue( 0 ) 
)
inline

Constructor.

Parameters:
tthe array containing initial data.
sizethe size of the signal.
zthe index of the zero-th element.
periodic'true' if the signal is periodic.
defthe default value.

Definition at line 264 of file Signal.ih.

References DGtal::Signal< TValue >::init().

: m_data( new SignalData<TValue>() )
{
m_data->init( t, asize, z, periodic, def );
}
template<typename TValue>
DGtal::Signal< TValue >::Signal ( const Signal< TValue > &  other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Copy constructor.

Parameters:
otherthe object to clone. Forbidden by default.

Definition at line 289 of file Signal.ih.

: m_data( other.m_data )
{
}

Member Function Documentation

template<typename TValue >
DGtal::Signal< TValue > DGtal::Signal< TValue >::D2n ( unsigned int  n)
static
Returns:
the differential operator with binomial weights of order 2n.

Definition at line 562 of file Signal.ih.

{
return H2n( n ) * Delta();
}
template<typename TValue >
DGtal::Signal< TValue > DGtal::Signal< TValue >::Delta ( )
static
Returns:
the right difference signal.

Definition at line 530 of file Signal.ih.

{
Signal<TValue> D( 2, 0, false, TValue( 0 ) );
D[ 0 ] = -1;
D[ 1 ] = 1;
return D;
}
template<typename TValue >
DGtal::Signal< TValue > DGtal::Signal< TValue >::G2 ( )
static
Returns:
the gaussian signal of order 2 (binomial signal of order 2 / 4).

TValue must be able to represent real values.

Definition at line 504 of file Signal.ih.

References DGtal::Signal< TValue >::multiply().

{
Signal<TValue> G = H2();
G.multiply( 0.25 );
return G;
}
template<typename TValue >
DGtal::Signal< TValue > DGtal::Signal< TValue >::G2n ( unsigned int  n)
static
Returns:
the gaussian signal of order 2n (binomial signal of order 2n / 2^n).

Definition at line 540 of file Signal.ih.

{
if ( n <= 1 ) return G2();
else return G2n( n - 1 ) * G2();
}
template<typename TValue >
DGtal::Signal< TValue > DGtal::Signal< TValue >::H2 ( )
static
Returns:
the binomial signal of order 2.

Definition at line 516 of file Signal.ih.

{
Signal<TValue> H( 3, 1, false, TValue( 0 ) );
H[ -1 ] = 1;
H[ 0 ] = 2;
H[ 1 ] = 1;
return H;
}
template<typename TValue >
DGtal::Signal< TValue > DGtal::Signal< TValue >::H2n ( unsigned int  n)
static
Returns:
the binomial signal of order 2n.

Definition at line 551 of file Signal.ih.

{
if ( n <= 1 ) return H2();
else return H2n( n - 1 ) * H2();
}
template<typename TValue>
void DGtal::Signal< TValue >::init ( unsigned int  aSize,
int  z = 0,
bool  periodic = false,
const TValue &  def = TValue( 0 ) 
)
inline

Initializer.

Parameters:
sthe number of data in the signal.
zthe index of the zero-th element.
p'true' if the signal is periodic.
defthe default value.

Initializer.

Parameters:
sizethe size of the signal.
zthe index of the zero-th element.
periodic'true' if the signal is periodic.
defthe default value.

Definition at line 323 of file Signal.ih.

Referenced by DGtal::Signal< TValue >::Signal().

{
m_data = CowPtr< SignalData<TValue> >( new SignalData<TValue>() );
m_data->init( aSize, z, periodic, def );
}
template<typename TValue>
void DGtal::Signal< TValue >::init ( const TValue *  t,
unsigned int  aSize,
int  z = 0,
bool  periodic = false,
const TValue &  def = TValue( 0 ) 
)
inline

Initializer.

Parameters:
tthe array containing initial data.
sizethe size of the signal.
zthe index of the zero-th element.
p'true' if the signal is periodic.
defthe default value.

Constructor.

Parameters:
tthe array containing initial data.
sizethe size of the signal.
zthe index of the zero-th element.
periodic'true' if the signal is periodic.
defthe default value.

Definition at line 342 of file Signal.ih.

{
m_data = CowPtr< SignalData<TValue> >( new SignalData<TValue>() );
m_data->init( t, aSize, z, periodic, def );
}
template<typename TValue >
bool DGtal::Signal< TValue >::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Definition at line 594 of file Signal.ih.

{
return true;
}
template<typename TValue>
void DGtal::Signal< TValue >::multiply ( const TValue &  l)

External product of a signal by a scalar value.

Parameters:
lthe external value.
Returns:
the signal where each term has been multiplied by [l].

Definition at line 441 of file Signal.ih.

References DGtal::SignalData< TValue >::data, and DGtal::SignalData< TValue >::size.

Referenced by DGtal::Signal< TValue >::G2().

{
SignalData<TValue> & sd = *m_data;
for ( unsigned int i = 0; i <= sd.size; ++i )
sd.data[ i ] *= l;
}
template<typename TValue>
DGtal::Signal< TValue > DGtal::Signal< TValue >::operator* ( const Signal< TValue > &  G)

Convolution product of two signals (F = this). F*G( a ) = sum F(a-i)G(i)

Parameters:
Gthe second signal (not periodic)
Returns:
the signal that is the convolution of F and G, of type F. The returned signal is periodic iff Fis periodic.

Convolution product of two signals (F = this). F*G( a ) = sum F(a-i)G(i)

Parameters:
Gthe second signal (not periodic)
Returns:
the signal that is the convolution of F and G, of type F.

Definition at line 459 of file Signal.ih.

References DGtal::SignalData< TValue >::data, DGtal::SignalData< TValue >::defaut(), DGtal::Signal< TValue >::m_data, DGtal::SignalData< TValue >::periodic, DGtal::SignalData< TValue >::size, DGtal::Signal< TValue >::size(), and DGtal::SignalData< TValue >::zero.

{
const SignalData<TValue>& Fd = *m_data;
const SignalData<TValue>& Gd = *G.m_data;
unsigned int aSize = Fd.periodic ? Fd.size : Fd.size + Gd.size - 1;
int zero = Fd.periodic ? Fd.zero : Fd.zero + Gd.zero;
Signal<TValue> FG( aSize, zero, Fd.periodic, Fd.defaut() );
SignalData<TValue>& FGd = *FG.m_data;
if ( Fd.periodic )
{
for ( int a = 0; a < (int) FGd.size; ++a )
{
TValue sum = TValue( 0 );
for ( unsigned int i = 0; i < Gd.size; ++i )
{
sum += this->operator[]( a - ( i - Gd.zero ) )
* Gd.data[ i ];
}
FG[ a ] = sum;
}
}
else
{
for ( unsigned int a = 0; a < FGd.size; ++a )
{
TValue sum = TValue( 0 );
for ( unsigned int i = 0; i < Gd.size; ++i )
{
sum += this->operator[]( a - ( Fd.zero + Gd.zero )
- ( i - Gd.zero ) )
* Gd.data[ i ];
}
FGd.data[ a ] = sum;
}
}
return FG;
}
template<typename TValue>
DGtal::Signal< TValue > & DGtal::Signal< TValue >::operator= ( const Signal< TValue > &  other)
inline

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'.

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'. Forbidden by default.

Definition at line 303 of file Signal.ih.

References DGtal::Signal< TValue >::m_data.

{
if ( this != & other )
m_data = other.m_data;
return *this;
}
template<typename TValue >
TValue & DGtal::Signal< TValue >::operator[] ( int  i)

Protected rw access to value. If index is out of bound, return 0 if not periodic or the correct value otherwise.

Parameters:
ithe index in the signal .
Returns:
the i-th value in the signal.

Definition at line 376 of file Signal.ih.

References DGtal::SignalData< TValue >::data, DGtal::SignalData< TValue >::periodic, DGtal::SignalData< TValue >::size, and DGtal::SignalData< TValue >::zero.

{
SignalData<TValue> & sd = *m_data;
int idx = i + sd.zero;
if ( ( idx >= 0 ) && ( idx < (int) sd.size ) )
return sd.data[ idx ];
else if ( sd.periodic )
{
idx = idx - ( idx / (int) sd.size ) * sd.size;
return sd.data[ ( idx + sd.size ) % sd.size ];
}
else
return sd.data[ sd.size ];
}
template<typename TValue >
const TValue & DGtal::Signal< TValue >::operator[] ( int  i) const

Protected ro access to value. If index is out of bound, return 0 if not periodic or the correct value otherwise.

Parameters:
ithe index in the signal .
Returns:
the i-th value in the signal.

Definition at line 401 of file Signal.ih.

References DGtal::SignalData< TValue >::data, DGtal::SignalData< TValue >::periodic, DGtal::SignalData< TValue >::size, and DGtal::SignalData< TValue >::zero.

{
const SignalData<TValue> & sd = *m_data;
int idx = i + sd.zero;
if ( ( idx >= 0 ) && ( idx < (int) sd.size ) )
return sd.data[ idx ];
else if ( sd.periodic )
{
idx = idx - ( idx / (int) sd.size ) * sd.size;
return sd.data[ ( idx + sd.size ) % sd.size ];
}
else
return sd.data[ sd.size ];
}
template<typename TValue >
void DGtal::Signal< TValue >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 578 of file Signal.ih.

{
out << "[Signal" << std::fixed << std::setprecision( 5 );
for ( unsigned int i = 0; i < size(); ++i )
out << " " << ( ( i == (unsigned int) m_data->zero ) ? "*" : "" )
<< m_data->data[ i ];
out << " ]";
}
template<typename TValue>
void DGtal::Signal< TValue >::setAll ( const TValue &  val = TValue( 0 ))

The signal becomes a constant signal of value [val].

Parameters:
valthe value of the whole signal.

Definition at line 424 of file Signal.ih.

References DGtal::SignalData< TValue >::data, and DGtal::SignalData< TValue >::size.

{
SignalData<TValue> & sd = *m_data;
for ( unsigned int i = 0; i <= sd.size; ++i )
sd.data[ i ] = val;
}
template<typename TValue >
unsigned int DGtal::Signal< TValue >::size ( ) const
Returns:
the number of elements in the signal.

Definition at line 356 of file Signal.ih.

References DGtal::Signal< TValue >::size().

Referenced by DGtal::Signal< TValue >::operator*(), and DGtal::Signal< TValue >::size().

{
return m_data->size;
}

Field Documentation

template<typename TValue>
CowPtr< SignalData<TValue> > DGtal::Signal< TValue >::m_data
private

the array that stores the data.

Definition at line 352 of file Signal.h.

Referenced by DGtal::Signal< TValue >::operator*(), and DGtal::Signal< TValue >::operator=().


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