// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | bytran@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// The instrument function calculation algorithms are converted from the Python code of the HITRAN Application
// Programming Interface (HAPI) distributed under the Academic Free License 3.0, http://hitran.org/hapi/
// R.V. Kochanov, I.E. Gordon, L.S. Rothman, P. Wcisło, C. Hill, J.S. Wilzewski, "HITRAN Application Programming Interface (HAPI):
// A comprehensive approach to working with spectroscopic data", JQSRT, Volume 177, July 2016, Pages 15–30; (hitran.org/hapi/)
//
// The MIT License (MIT)
// Copyright (c) 2016 Dzianis Pliutau
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



// Object containing modules to carry out instrument function related calculations
// This module is based on the Python code in the HITRAN API programming interface
#ifndef INSTRUMENTALFUNCTION_H
#define INSTRUMENTALFUNCTION_H

#include <QObject>
#include <QVector>
#include "spectrum.h"
#include "wavelength.h"

class InstrumentFunction : public QObject
{
    Q_OBJECT

public:

    explicit InstrumentFunction(QObject *parent = nullptr);

    // Methods to get and set the instrument function to use
    quint8 getInstrFunctIndex();
    void setInstrFunctIndex(quint8 newInstrFunctIndex);

    // Getting and setting the instrumental function resolution
    double getInstrResol();
    void setInstrResol(double newInstrResol);

    // Getting and setting the instrument function wing
    double getInstrFunctWing();
    void setInstrFunctWing(double newInstrFunctWing);

    // Method to set the wavelength object
    void setWavelength(Wavelength *newWavelength);

    // Methods to convolve the spectrum
    void convolveSpectrum(Spectrum *spectrum, Spectrum *convolvedSpec);
    void convolveSpectrum(QVector<double> *rawArr, QVector<double> *instrFunct, QVector<double> *convolvedArr);

signals:

    // Singnal is emited to open the ok notification dialog
    void openOkDialog(QString text);

private:

    // Methods to generate the instrument function arrays
    void slitRectangular(QVector<double> *x, double g, QVector<double> *instrFunct);  // Rectangular slit instrument function
    void slitTriangular(QVector<double> *x, double g, QVector<double> *instrFunct);   // Triangular slit function
    void slitGaussian(QVector<double> *x, double g, QVector<double> *instrFunct);     // Gaussian slit function
    void slitDispersion(QVector<double> *x, double g, QVector<double> *instrFunct);   // Dispersion slit function
    void slitCosine(QVector<double> *x, double g, QVector<double> *instrFunct);       // Cosine slit function
    void slitDiffraction(QVector<double> *x, double g, QVector<double> *instrFunct);  // Diffraction slit function
    void slitMichelson(QVector<double> *x, double g, QVector<double> *instrFunct);    // Michelson slit function

    // Instrumental function
    // 0 - None
    // 1 - Rectangular (Boxcar)
    // 2 - Triangular
    // 3 - Gaussian
    // 4 - Dispersion (Lorentz)
    // 5 - Diffraction
    // 6 - Michelson
    // 7 - Cosine
    quint8 instrFunctIndex;

    // Instrument function resolution and the wing parameters
    double instrResol;  // Instrumental function resolution in cm-1 (the default is 0.1 cm-1)
    double instrFunctWing;   // Instrumental function wing in cm-1

    // Wavelength object with the wavenumber grid
    Wavelength *wavelength;

};

#endif // INSTRUMENTFUNCTION_H
