From 56b7ec06997f512bb1b92caf5a740f763c35c22c Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Tue, 19 Jul 2005 08:58:14 +0000 Subject: [PATCH] * now all wavelength are stored in nm, not angstrom * adding kdebug()-calls to catch one stupid bug. --> Michael, your turn :) svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.h; revision=436189 --- kalzium/src/spectrum.cpp | 43 +++++++++++++++++++++++++++++++--------- kalzium/src/spectrum.h | 36 ++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/kalzium/src/spectrum.cpp b/kalzium/src/spectrum.cpp index 6f7abde..db4ab7a 100644 --- a/kalzium/src/spectrum.cpp +++ b/kalzium/src/spectrum.cpp @@ -37,12 +37,30 @@ double Spectrum::minBand() const QValueList::Iterator itEnd = m_bandlist.end(); for (;it!=itEnd;++it) { + kdDebug() << "value: " << ( *it ).wavelength << " Current min-value: " << value << endl; if ( value > ( *it ).wavelength ) value = ( *it ).wavelength; } return value; } +double Spectrum::maxBand() +{ + kdDebug() << "Spectrum::maxBand()" << endl; + + double value = ( *m_bandlist.begin() ).wavelength; + QValueList::Iterator it = m_bandlist.begin(); + const QValueList::Iterator itEnd = m_bandlist.end(); + for (;it!=itEnd;++it) + { + kdDebug() << "value: " << ( *it ).wavelength << " Current max-value: " << value << endl; + if ( value < ( *it ).wavelength ) + value = ( *it ).wavelength; + } + return value; +} + + Spectrum* Spectrum::adjustToWavelength( double min, double max ) { Spectrum *spec = new Spectrum(); @@ -52,6 +70,7 @@ Spectrum* Spectrum::adjustToWavelength( double min, double max ) for ( ; it != itEnd; ++it ) { + kdDebug( ) << "WL: " << ( *it ).wavelength << endl; if ( ( *it ).wavelength < min || ( *it ).wavelength > max ) continue; @@ -96,19 +115,22 @@ void Spectrum::adjustIntensities() } } -double Spectrum::maxBand() +QValueList Spectrum::wavelengths( double min, double max ) { - kdDebug() << "Spectrum::maxBand()" << endl; - - double value = ( *m_bandlist.begin() ).wavelength; + QValueList list; + QValueList::Iterator it = m_bandlist.begin(); const QValueList::Iterator itEnd = m_bandlist.end(); - for (;it!=itEnd;++it) + + for ( ; it != itEnd; ++it ) { - if ( value < ( *it ).wavelength ) - value = ( *it ).wavelength; + if ( ( *it ).wavelength < min || ( *it ).wavelength > max ) + continue; + + list.append( ( *it ).wavelength ); } - return value; + + return list; } SpectrumView::SpectrumView( Spectrum *spec, QWidget *parent, const char* name ) @@ -116,11 +138,14 @@ SpectrumView::SpectrumView( Spectrum *spec, QWidget *parent, const char* name ) { kdDebug()<<"SpectrumView::SpectrumView()" << endl; - m_spectrum = spec; + //make sure only visible light will be plotted + m_spectrum = spec->adjustToWavelength( 380.0, 780.0 ); + m_spectrum->adjustMinMax(); QVBoxLayout *spectrumLayout = new QVBoxLayout( this, 0, -1, "spectrumLayout" ); m_spectrumWidget = new SpectrumWidget( this, "spectrum" ); m_spectrumWidget->setSpectrum( m_spectrum ); + kdDebug() << spec->min() << " max: " << spec->max() << endl; m_spectrumWidget->setBorders( spec->min(), spec->max() ); spectrumLayout->addWidget( m_spectrumWidget ); diff --git a/kalzium/src/spectrum.h b/kalzium/src/spectrum.h index a1e15d0..bed4a7e 100644 --- a/kalzium/src/spectrum.h +++ b/kalzium/src/spectrum.h @@ -48,8 +48,6 @@ class Spectrum * public ctor */ Spectrum(){ - m_min = 400; - m_max = 700; }; /** @@ -62,7 +60,7 @@ class Spectrum */ struct band { - ///in Angstrom (1/10 nm) + ///in nm) double wavelength; ///Transition Probabilities @@ -95,8 +93,8 @@ class Spectrum } /** - * @param min the lowest allowed wavalength - * @param max the highest allowed wavalength + * @param min the lowest allowed wavalength in nanometer + * @param max the highest allowed wavalength in nanometer * * @returns a spectrum with the wavelength in the range * of @p min to @p max. The intensities are readjusted @@ -111,6 +109,14 @@ class Spectrum */ void adjustIntensities(); + /** + * @param min the lowest allowed wavalength in nanometer + * @param max the highest allowed wavalength in nanometer + * + * @return the wavelength in a QValueList + */ + QValueList wavelengths( double min, double max ); + /** * @return the smallest wavelength */ @@ -128,6 +134,17 @@ class Spectrum QValueList* bandlist(){ return &m_bandlist; } + + /** + * cache the values of the biggest and + * smallest wavelenght + */ + void adjustMinMax(){ + m_min = minBand(); + kdDebug() << "adjustMinMax::m_min: " << m_min << endl; + m_max = maxBand(); + kdDebug() << "adjustMinMax::m_max: " << m_max << endl; + } private: /** @@ -139,15 +156,6 @@ class Spectrum * @return the biggest wavelength */ double maxBand(); - - /** - * cache the values of the biggest and - * smallest wavelenght - */ - void adjustMinMax(){ - m_min = minBand(); - m_max = maxBand(); - } /** * the internal dataset -- 2.47.3