DGtal  0.9.2
Signal.h
1 
17 #pragma once
18 
31 #if defined(Signal_RECURSES)
32 #error Recursive header files inclusion detected in Signal.h
33 #else // defined(Signal_RECURSES)
34 
35 #define Signal_RECURSES
36 
37 #if !defined Signal_h
38 
39 #define Signal_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/CowPtr.h"
47 
48 namespace DGtal
49 {
50 
57  template <typename TValue>
58  struct SignalData {
59  typedef TValue Value;
60 
62  Value* data;
64  unsigned int size;
66  int zero;
69  bool periodic;
70 
75  SignalData();
76 
85  void init( unsigned int s, int z = 0, bool p = false,
86  const Value & def = Value( 0 ) );
87 
97  void init( const Value* t, unsigned int size, int z = 0, bool p = false,
98  const Value & def = Value( 0 ) );
99 
108  SignalData( unsigned int s, int z = 0, bool p = false,
109  const Value & def = Value( 0 ) );
110 
119  SignalData( const Value* t, unsigned int size, int z = 0, bool p = false,
120  const Value & def = Value( 0 ) );
121 
125  ~SignalData();
126 
131  SignalData( const SignalData & other );
132 
138  SignalData& operator=( const SignalData & other );
139 
144  const Value& defaut() const;
145  };
146 
147 
149  // template class Signal
161  template <typename TValue>
162  class Signal
163  {
164 
165  public:
166  typedef TValue Value;
173  static Signal<TValue> G2();
174 
178  static Signal<TValue> H2();
179 
183  static Signal<TValue> Delta();
184 
189  static Signal<TValue> G2n( unsigned int n );
190 
194  static Signal<TValue> H2n( unsigned int n );
195 
199  static Signal<TValue> D2n( unsigned int n );
200 
201  // ----------------------- Standard services ----------------------------
202  public:
203 
207  ~Signal();
208 
212  Signal();
213 
214 
222  Signal( unsigned int size, int z, bool periodic,
223  const TValue & def = TValue( 0 ) );
224 
233  Signal( const TValue* t, unsigned int size, int z, bool periodic,
234  const TValue & def = TValue( 0 ) );
235 
240  Signal( const Signal<TValue> & other );
241 
247  Signal<TValue> & operator=( const Signal<TValue> & other );
248 
249 
258  void init( unsigned int s, int z = 0, bool p = false,
259  const TValue & def = TValue( 0 ) );
260 
270  void init( const TValue* t, unsigned int size, int z = 0, bool p = false,
271  const TValue & def = TValue( 0 ) );
272 
273 
277  unsigned int size() const;
278 
279  // ----------------------- Signal services ----------------------------
280  public:
281 
290  TValue & operator[]( int i );
291 
300  const TValue & operator[]( int i ) const;
301 
307  void setAll( const TValue & val = TValue( 0 ) );
308 
309 
316  void multiply( const TValue & val );
317 
328 
329  // ----------------------- Interface --------------------------------------
330  public:
331 
336  void selfDisplay ( std::ostream & out ) const;
337 
342  bool isValid() const;
343 
344 
345  // ------------------------- Datas --------------------------------------
346  private:
347 
352 
353  // ------------------------- Hidden services ----------------------------
354  protected:
355 
356 
357  }; // end of class Signal
358 
359 
366  template <typename TValue>
367  std::ostream&
368  operator<< ( std::ostream & out, const Signal<TValue> & object );
369 
370 } // namespace DGtal
371 
372 
374 // Includes inline functions.
375 #include "DGtal/math/Signal.ih"
376 
377 // //
379 
380 #endif // !defined Signal_h
381 
382 #undef Signal_RECURSES
383 #endif // else defined(Signal_RECURSES)
static Signal< TValue > Delta()
static Signal< TValue > G2()
static Signal< TValue > G2n(unsigned int n)
void setAll(const TValue &val=TValue(0))
bool isValid() const
const Value & defaut() const
Signal< TValue > operator*(const Signal< TValue > &G)
CowPtr< SignalData< TValue > > m_data
Definition: Signal.h:351
static Signal< TValue > H2()
void multiply(const TValue &val)
unsigned int size
the size of the array data.
Definition: Signal.h:64
void init(unsigned int s, int z=0, bool p=false, const TValue &def=TValue(0))
static Signal< TValue > H2n(unsigned int n)
Value * data
a dyn. array on Value s.
Definition: Signal.h:62
Aim: Represents a discrete signal, periodic or not. The signal can be passed by value since it is onl...
Definition: Signal.h:162
Signal< TValue > & operator=(const Signal< TValue > &other)
int zero
the true index of the zero abscissa.
Definition: Signal.h:66
DGtal is the top-level namespace which contains all DGtal functions and types.
void selfDisplay(std::ostream &out) const
static Signal< TValue > D2n(unsigned int n)
TValue Value
Definition: Signal.h:59
TValue Value
Definition: Signal.h:166
unsigned int size() const
void init(unsigned int s, int z=0, bool p=false, const Value &def=Value(0))
TValue & operator[](int i)
SignalData & operator=(const SignalData &other)
Aim: Copy on write shared pointer.
Definition: CowPtr.h:67