File indexing completed on 2024-04-28 07:28:53

0001 /*
0002     SPDX-FileCopyrightText: 2005, 2006 Carsten Niehaus <cniehaus@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef SPECTRUM_H
0008 #define SPECTRUM_H
0009 
0010 #include "science_export.h"
0011 
0012 #include <QList>
0013 
0014 class Element;
0015 
0016 /**
0017  * @author Carsten Niehaus
0018  *
0019  * This class represents a spectrum with all its properties
0020  */
0021 class SCIENCE_EXPORT Spectrum
0022 {
0023 public:
0024     /**
0025      * This spectrum doesn't belong to any element
0026      */
0027     Spectrum();
0028 
0029     /**
0030      * public destructor
0031      */
0032     ~Spectrum();
0033 
0034     /**
0035      * a peak is one line in the spectrum of an element
0036      */
0037     class SCIENCE_EXPORT peak
0038     {
0039     public:
0040         peak()
0041         {
0042             wavelength = -1.0;
0043             intensity = -1;
0044         }
0045 
0046         peak(double wl, int in)
0047         {
0048             wavelength = wl;
0049             intensity = in;
0050         }
0051 
0052         /// relative. The highest is per definition 1000
0053         int intensity;
0054         double wavelength;
0055 
0056         double wavelengthToUnit(const int unit);
0057     };
0058 
0059     /**
0060      * adds the peak @p b to the internal
0061      * lists of peaks
0062      */
0063     void addPeak(Spectrum::peak *b)
0064     {
0065         if (b) {
0066             m_peaklist.append(b);
0067         }
0068     }
0069 
0070     /**
0071      * @param min the lowest allowed wavelength in nanometer
0072      * @param max the highest allowed wavelength in nanometer
0073      *
0074      * @returns a spectrum with the wavelength in the range
0075      * of @p min to @p max. The intensities are readjusted
0076      * so that the biggest intensity is again 1000 and the
0077      * others are adopted.
0078      */
0079     Spectrum *adjustToWavelength(double min, double max);
0080 
0081     /**
0082      * sets the highest intensity to 1000 and adjusts the
0083      * others
0084      */
0085     void adjustIntensities();
0086 
0087     /**
0088      * @param min the lowest allowed wavelength in nanometer
0089      * @param max the highest allowed wavelength in nanometer
0090      *
0091      * @return the wavelength in a QList<double>
0092      */
0093     QList<double> wavelengths(double min, double max);
0094 
0095     /**
0096      * @return the list of peaks of the spectrum
0097      */
0098     QList<Spectrum::peak *> peaklist()
0099     {
0100         return m_peaklist;
0101     }
0102 
0103     /**
0104      * If the spectrum belongs to Iron, this method will return "26"
0105      * @return the number of the element the spectrum belongs to
0106      */
0107     int parentElementNumber() const;
0108 
0109     /**
0110      * @return the smallest wavelength
0111      */
0112     double minPeak();
0113     double minPeak(const int unit);
0114 
0115     /**
0116      * @return the biggest wavelength
0117      */
0118     double maxPeak();
0119     double maxPeak(const int unit);
0120 
0121     void setParentElementNumber(int num)
0122     {
0123         m_parentElementNumber = num;
0124     }
0125 
0126 private:
0127     /**
0128      * the internal dataset
0129      */
0130     QList<peak *> m_peaklist;
0131 
0132     int m_parentElementNumber;
0133 };
0134 
0135 #endif // SPECTRUM_H