// ========================================================================= // @author Leonardo Florez Valencia // @email florez-l@javeriana.edu.co // ========================================================================= // https://stackoverflow.com/questions/22583391/peak-signal-detection-in-realtime-timeseries-data #ifndef __fpa__Base__Mori__h__ #define __fpa__Base__Mori__h__ #include #include #include #include #include #include #include namespace fpa { namespace Base { /** */ template< class _TAlgorithm > class Mori : public _TAlgorithm { public: typedef Mori Self; typedef _TAlgorithm Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; typedef typename _TAlgorithm::TNode TNode; typedef typename _TAlgorithm::TNodes TNodes; typedef typename _TAlgorithm::TInputValue TInputValue; typedef typename _TAlgorithm::TOutputValue TOutputValue; typedef typename _TAlgorithm::TFrontId TFrontId; typedef typename _TAlgorithm::TVertex TVertex; typedef std::deque< TNode > TQueue; typedef std::set< TInputValue > TThresholds; typedef std::pair< TInputValue, unsigned long > TSignalData; typedef std::vector< TSignalData > TSignal; typedef fpa::Generic::PeakDetector TPeakDetector; typedef fpa::Base::Functors::RegionGrow::BinaryThreshold< TInputValue > TPredicate; public: itkConceptMacro( Check_TOutputValue, ( itk::Concept::IsUnsignedInteger< TOutputValue > ) ); itkGetConstMacro( InsideValue, TOutputValue ); itkGetConstMacro( MinimumThreshold, TInputValue ); itkSetMacro( InsideValue, TOutputValue ); itkSetMacro( MinimumThreshold, TInputValue ); itkGetConstReferenceMacro( Signal, TSignal ); itkGetConstMacro( SignalLag, unsigned long ); itkGetConstMacro( SignalThreshold, double ); itkGetConstMacro( SignalInfluence, double ); itkSetMacro( SignalLag, unsigned long ); itkSetMacro( SignalThreshold, double ); itkSetMacro( SignalInfluence, double ); public: virtual itk::ModifiedTimeType GetMTime( ) const override; TOutputValue GetOutsideValue( ) const; void SetOutsideValue( const TOutputValue& v ); void ClearThresholds( ); void AddThreshold( const TInputValue& thr ); void SetThresholds( const TInputValue& init, const TInputValue& end, const TInputValue& delta ); unsigned long GetNumberOfEvaluatedThresholds( ) const; TInputValue GetOptimumThreshold( ) const; protected: Mori( ); virtual ~Mori( ); virtual void _BeforeGenerateData( ) override; virtual void _FinishOneLoop( ) override; virtual void _ComputeOutputValue( TNode& n ) override; virtual void _UpdateOutputValue( TNode& n ) override; virtual void _QueueClear( ) override; virtual TNode _QueuePop( ) override; virtual void _QueuePush( const TNode& node ) override; virtual unsigned long _QueueSize( ) const override; virtual void _PrepareSeeds( TNodes& nodes ) override; private: // Purposely not implemented. Mori( const Self& other ); Self& operator=( const Self& other ); protected: typename TPredicate::Pointer m_Predicate; TThresholds m_Thresholds; typename TThresholds::const_iterator m_CurrentThreshold; TQueue m_Queues[ 2 ]; unsigned int m_CurrentQueue; unsigned long m_Count; TPeakDetector m_PeakDetector; TSignal m_Signal; unsigned long m_SignalLag; double m_SignalThreshold; double m_SignalInfluence; std::vector< double > m_FilteredSignal; std::vector< double > m_SignalAverages; std::vector< double > m_SignalDeviations; std::vector< short > m_SignalPeaks; double m_CurrentAverage; double m_CurrentVariance; TInputValue m_MinimumThreshold; TOutputValue m_InsideValue; }; } // ecapseman } // ecapseman #ifndef ITK_MANUAL_INSTANTIATION # include #endif // ITK_MANUAL_INSTANTIATION #endif // __fpa__Base__Mori__h__ // eof - $RCSfile$