1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 // https://stackoverflow.com/questions/22583391/peak-signal-detection-in-realtime-timeseries-data
9 #ifndef __fpa__Base__Mori__h__
10 #define __fpa__Base__Mori__h__
15 #include <itkConceptChecking.h>
16 #include <itkFunctionBase.h>
18 #include <fpa/Generic/PeakDetector.h>
19 #include <fpa/Base/Functors/RegionGrow/BinaryThreshold.h>
27 template< class _TAlgorithm >
33 typedef _TAlgorithm Superclass;
34 typedef itk::SmartPointer< Self > Pointer;
35 typedef itk::SmartPointer< const Self > ConstPointer;
37 typedef typename _TAlgorithm::TNode TNode;
38 typedef typename _TAlgorithm::TNodes TNodes;
39 typedef typename _TAlgorithm::TInputValue TInputValue;
40 typedef typename _TAlgorithm::TOutputValue TOutputValue;
41 typedef typename _TAlgorithm::TFrontId TFrontId;
42 typedef typename _TAlgorithm::TVertex TVertex;
44 typedef std::deque< TNode > TQueue;
45 typedef std::set< TInputValue > TThresholds;
46 typedef std::pair< TInputValue, unsigned long > TSignalData;
47 typedef std::vector< TSignalData > TSignal;
49 typedef fpa::Generic::PeakDetector TPeakDetector;
50 typedef fpa::Base::Functors::RegionGrow::BinaryThreshold< TInputValue > TPredicate;
55 ( itk::Concept::IsUnsignedInteger< TOutputValue > )
58 itkGetConstMacro( InsideValue, TOutputValue );
59 itkGetConstMacro( MinimumThreshold, TInputValue );
61 itkSetMacro( InsideValue, TOutputValue );
62 itkSetMacro( MinimumThreshold, TInputValue );
64 itkGetConstReferenceMacro( Signal, TSignal );
65 itkGetConstMacro( SignalLag, unsigned long );
66 itkGetConstMacro( SignalThreshold, double );
67 itkGetConstMacro( SignalInfluence, double );
69 itkSetMacro( SignalLag, unsigned long );
70 itkSetMacro( SignalThreshold, double );
71 itkSetMacro( SignalInfluence, double );
74 virtual itk::ModifiedTimeType GetMTime( ) const override;
76 TOutputValue GetOutsideValue( ) const;
77 void SetOutsideValue( const TOutputValue& v );
79 void ClearThresholds( );
80 void AddThreshold( const TInputValue& thr );
82 const TInputValue& init,
83 const TInputValue& end,
84 const TInputValue& delta
86 unsigned long GetNumberOfEvaluatedThresholds( ) const;
87 TInputValue GetOptimumThreshold( ) const;
93 virtual void _BeforeGenerateData( ) override;
94 virtual void _FinishOneLoop( ) override;
95 virtual void _ComputeOutputValue( TNode& n ) override;
96 virtual void _UpdateOutputValue( TNode& n ) override;
97 virtual void _QueueClear( ) override;
98 virtual TNode _QueuePop( ) override;
99 virtual void _QueuePush( const TNode& node ) override;
100 virtual unsigned long _QueueSize( ) const override;
101 virtual void _PrepareSeeds( TNodes& nodes ) override;
104 // Purposely not implemented.
105 Mori( const Self& other );
106 Self& operator=( const Self& other );
109 typename TPredicate::Pointer m_Predicate;
110 TThresholds m_Thresholds;
111 typename TThresholds::const_iterator m_CurrentThreshold;
112 TQueue m_Queues[ 2 ];
113 unsigned int m_CurrentQueue;
114 unsigned long m_Count;
116 TPeakDetector m_PeakDetector;
119 unsigned long m_SignalLag;
120 double m_SignalThreshold;
121 double m_SignalInfluence;
122 std::vector< double > m_FilteredSignal;
123 std::vector< double > m_SignalAverages;
124 std::vector< double > m_SignalDeviations;
125 std::vector< short > m_SignalPeaks;
126 double m_CurrentAverage;
127 double m_CurrentVariance;
129 TInputValue m_MinimumThreshold;
130 TOutputValue m_InsideValue;
137 #ifndef ITK_MANUAL_INSTANTIATION
138 # include <fpa/Base/Mori.hxx>
139 #endif // ITK_MANUAL_INSTANTIATION
141 #endif // __fpa__Base__Mori__h__