/***************************************************************************
 *   Copyright (C) 2005 by Armando Navarro Vazquez   *
 *   qoajnv@usc.es   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef PEAKPICKER_H
#define PEAKPICKER_H

/**
	@author Armando Navarro Vazquez <qoajnv@usc.es>
*/

#include <vector>

class Spectrum;
class QPainter;
class QRect;
class PeakPicker{
public:
    PeakPicker();
    PeakPicker(Spectrum* sp);

    ~PeakPicker();
    void SetSpectrum(Spectrum* sp) { m_spectrum=sp; }
    void Calculate(const QRect& region, const QRect& clientrect);
    const std::vector<size_t>& Peaks() const { return m_peaks; }
    std::vector<size_t>& Peaks() { return m_peaks; }
    /** Clear peak list*/
    void Clear();
    void Draw(QPainter* p,const QRect& rect);
    bool HasPeakAt(const QPoint& point, const QRect& rect);
private:
  float GetNoiseLevel();
  float GetSD(size_t first,size_t last);
  void OrganizeText(int *text, const QRect &clientrect,int ntexts);
  void MoveRight(int* text, int pos, int ntexts);
  void MoveLeft(int *text, int pos);
private:
  std::vector<size_t> m_peaks;
  Spectrum* m_spectrum;
  int m_width;

};

#endif
