• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kalzium/libscience

  • sources
  • kde-4.14
  • kdeedu
  • kalzium
  • libscience
spectrum.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Carsten Niehaus *
3  * cniehaus@kde.org *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #include "spectrum.h"
21 #include "element.h"
22 
23 #include <klocale.h>
24 #include <kunitconversion/converter.h>
25 
26 #include <math.h>
27 
28 double Spectrum::minPeak()
29 {
30  double value = m_peaklist.first()->wavelength;
31 
32  foreach( peak * p, m_peaklist )
33  {
34  if ( value > p->wavelength )
35  value = p->wavelength;
36  }
37  return value;
38 }
39 
40 double Spectrum::minPeak(const int unit)
41 {
42  return KUnitConversion::Value( minPeak(), KUnitConversion::Angstrom ).convertTo( unit ).number();
43 }
44 
45 
46 double Spectrum::maxPeak()
47 {
48  double value = m_peaklist.first()->wavelength;
49 
50  foreach( peak * p, m_peaklist )
51  {
52  if ( value < p->wavelength )
53  value = p->wavelength;
54  }
55 
56  return value;
57 }
58 
59 double Spectrum::maxPeak(const int unit)
60 {
61  return KUnitConversion::Value( maxPeak(), KUnitConversion::Angstrom ).convertTo( unit ).number();
62 }
63 
64 
65 Spectrum* Spectrum::adjustToWavelength( double min, double max )
66 {
67  Spectrum *spec = new Spectrum();
68 
69  foreach( peak * p , m_peaklist )
70  {
71  if ( p->wavelength >= min || p->wavelength <= max )
72  spec->addPeak( p );
73  }
74 
75  return spec;
76 }
77 
78 void Spectrum::adjustIntensities()
79 {
80  int maxInt = 0;
81  //find the highest intensity
82  foreach ( Spectrum::peak * p, m_peaklist)
83  {
84  if ( p->intensity > maxInt )
85  maxInt = p->intensity;
86  }
87 
88  //check if an adjustment is needed or not
89  if ( maxInt == 1000 ) return;
90 
91  //now adjust the intensities.
92  foreach ( Spectrum::peak * p, m_peaklist)
93  {
94  double newInt = p->intensity*1000/maxInt;
95 
96  p->intensity = ( int ) qRound( newInt );
97  }
98 }
99 
100 QList<double> Spectrum::wavelengths( double min, double max )
101 {
102  QList<double> list;
103 
104  foreach( peak * p , m_peaklist )
105  {
106  if ( p->wavelength >= min || p->wavelength <= max )
107  list.append( p->wavelength );
108  }
109 
110  return list;
111 }
112 
113 int Spectrum::parentElementNumber() const
114 {
115  return m_parentElementNumber;
116 }
117 
118 Spectrum::~Spectrum()
119 {
120  qDeleteAll( m_peaklist );
121 }
122 
123 Spectrum::Spectrum()
124 {
125  //FIXME this shouldn't be hardcoded
126  m_parentElementNumber = 16;
127 }
128 
129 double Spectrum::peak::wavelengthToUnit( const int unit )
130 {
131  return KUnitConversion::Value( wavelength, KUnitConversion::Angstrom ).convertTo( unit ).number();
132 }
element.h
Spectrum::addPeak
void addPeak(Spectrum::peak *b)
adds the peak b to the internal lists of peaks
Definition: spectrum.h:75
Spectrum::peak::wavelength
double wavelength
Definition: spectrum.h:66
Spectrum::parentElementNumber
int parentElementNumber() const
If the spectrum belongs to Iron, this method will return "26".
Definition: spectrum.cpp:113
Spectrum
Definition: spectrum.h:35
QList::append
void append(const T &value)
Spectrum::adjustToWavelength
Spectrum * adjustToWavelength(double min, double max)
Definition: spectrum.cpp:65
Spectrum::~Spectrum
~Spectrum()
public destructor
Definition: spectrum.cpp:118
spectrum.h
QList
Spectrum::peak::wavelengthToUnit
double wavelengthToUnit(const int unit)
Definition: spectrum.cpp:129
Spectrum::peak
a peak is one line in the spectrum of an element
Definition: spectrum.h:51
Spectrum::peak::intensity
int intensity
relative. The highest is per definition 1000
Definition: spectrum.h:65
Spectrum::Spectrum
Spectrum()
This spectrum doesn't belong to any element.
Definition: spectrum.cpp:123
Spectrum::maxPeak
double maxPeak()
Definition: spectrum.cpp:46
Spectrum::adjustIntensities
void adjustIntensities()
sets the highest intensity to 1000 and adjusts the others
Definition: spectrum.cpp:78
Spectrum::wavelengths
QList< double > wavelengths(double min, double max)
Definition: spectrum.cpp:100
Spectrum::minPeak
double minPeak()
Definition: spectrum.cpp:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:11:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalzium/libscience

Skip menu "kalzium/libscience"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal