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>
17 #include <fpa/Base/Functors/RegionGrow/BinaryThreshold.h>
25 template< class _TAlgorithm >
31 typedef _TAlgorithm Superclass;
32 typedef itk::SmartPointer< Self > Pointer;
33 typedef itk::SmartPointer< const Self > ConstPointer;
35 typedef typename _TAlgorithm::TNode TNode;
36 typedef typename _TAlgorithm::TNodes TNodes;
37 typedef typename _TAlgorithm::TInputValue TInputValue;
38 typedef typename _TAlgorithm::TOutputValue TOutputValue;
39 typedef typename _TAlgorithm::TFrontId TFrontId;
40 typedef typename _TAlgorithm::TVertex TVertex;
42 typedef std::deque< TNode > TQueue;
43 typedef std::set< TInputValue > TThresholds;
44 typedef std::pair< TInputValue, unsigned long > TSignalData;
45 typedef std::vector< TSignalData > TSignal;
46 typedef fpa::Base::Functors::RegionGrow::BinaryThreshold< TInputValue > TPredicate;
51 ( itk::Concept::IsUnsignedInteger< TOutputValue > )
54 itkGetConstMacro( InsideValue, TOutputValue );
55 itkSetMacro( InsideValue, TOutputValue );
57 itkGetConstReferenceMacro( Signal, TSignal );
58 itkGetConstMacro( SignalLag, unsigned long );
59 itkGetConstMacro( SignalThreshold, double );
60 itkGetConstMacro( SignalInfluence, double );
62 itkSetMacro( SignalLag, unsigned long );
63 itkSetMacro( SignalThreshold, double );
64 itkSetMacro( SignalInfluence, double );
67 virtual itk::ModifiedTimeType GetMTime( ) const override;
69 TOutputValue GetOutsideValue( ) const;
70 void SetOutsideValue( const TOutputValue& v );
72 void ClearThresholds( );
73 void AddThreshold( const TInputValue& thr );
75 const TInputValue& init,
76 const TInputValue& end,
77 const TInputValue& delta
79 unsigned long GetNumberOfEvaluatedThresholds( ) const;
80 TInputValue GetOptimumThreshold( ) const;
86 virtual void _BeforeGenerateData( ) override;
87 virtual void _FinishOneLoop( ) override;
88 virtual void _ComputeOutputValue( TNode& n ) override;
89 virtual void _UpdateOutputValue( TNode& n ) override;
90 virtual void _QueueClear( ) override;
91 virtual TNode _QueuePop( ) override;
92 virtual void _QueuePush( const TNode& node ) override;
93 virtual unsigned long _QueueSize( ) const override;
94 virtual void _PrepareSeeds( TNodes& nodes ) override;
97 // Purposely not implemented.
98 Mori( const Self& other );
99 Self& operator=( const Self& other );
102 typename TPredicate::Pointer m_Predicate;
103 TThresholds m_Thresholds;
104 typename TThresholds::const_iterator m_CurrentThreshold;
105 TQueue m_Queues[ 2 ];
106 unsigned int m_CurrentQueue;
107 unsigned long m_Count;
110 unsigned long m_SignalLag;
111 double m_SignalThreshold;
112 double m_SignalInfluence;
113 std::vector< double > m_FilteredSignal;
114 std::vector< double > m_SignalAverages;
115 std::vector< double > m_SignalDeviations;
116 std::vector< short > m_SignalPeaks;
117 double m_CurrentAverage;
118 double m_CurrentVariance;
120 TOutputValue m_InsideValue;
127 #ifndef ITK_MANUAL_INSTANTIATION
128 # include <fpa/Base/Mori.hxx>
129 #endif // ITK_MANUAL_INSTANTIATION
131 #endif // __fpa__Base__Mori__h__