]> Git trees. - libqmvoc.git/commitdiff
Adding
authorCarsten Niehaus <cniehaus@gmx.de>
Mon, 18 Jul 2005 11:04:43 +0000 (11:04 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Mon, 18 Jul 2005 11:04:43 +0000 (11:04 +0000)
   Spectrum* adjustToWavelength( double min, double max );

svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.h; revision=435840

kalzium/src/spectrum.cpp
kalzium/src/spectrum.h

index e178c72f2deb08e517bed13f6c0719654464a371..2baad62389ccad437fb3c6b21d07f1c19caf7669 100644 (file)
@@ -43,149 +43,42 @@ double Spectrum::minBand()
        return value;
 }
 
-double Spectrum::maxBand()
+Spectrum* Spectrum::adjustToWavelength( double min, double max )
 {
-       double value = ( *m_bandlist.begin() ).wavelength;
-       QValueList<band>::Iterator it = m_bandlist.begin();
-       const QValueList<band>::Iterator itEnd = m_bandlist.end();
-       for (;it!=itEnd;++it)
-       {
-               if ( value < ( *it ).wavelength )
-                       value = ( *it ).wavelength;
-       }
-       return value;
-}
+       Spectrum *spec = new Spectrum();
 
-void Spectrum::paintBands( QPainter* p, double startValue, double endValue, bool emissionSpectrum )
-{
-       kdDebug() << "Spectrum::paintBands()" << endl;
-       
-       if ( !emissionSpectrum )
-       {
-               for ( double va = startValue; va <= endValue ; va += 0.1 )
-               {
-                       int x = xPos( va, startValue, endValue );
-                       p->setPen( linecolor( va ) );
-                       p->drawLine( x,0,x, m_realHeight+10 );
-               }
-
-               p->setPen( Qt::black );
-       }
-
-       int i = 0;      
+       QValueList<band>::Iterator it = m_bandlist.begin();
+       QValueList<band>::Iterator itEnd = m_bandlist.end();
 
-       for ( QValueList<band>::Iterator it = m_bandlist.begin();
-                       it != m_bandlist.end();
-                       ++it )
+       for ( ; it != itEnd; ++it )
        {
-               kdDebug() << "band painted" << endl;
-               if ( ( *it ).wavelength < startValue || ( *it ).wavelength > endValue )
+               if ( ( *it ).wavelength < min || ( *it ).wavelength > max )
                        continue;
 
-               int x = xPos( ( *it ).wavelength, startValue, endValue );
-               
-               int temp = 0; // every second item will have a little offset
-
-               if ( i%2 )
-                       temp = 35;
-               else
-                       temp = 0;
-
-               if ( emissionSpectrum )
-               {
-                       p->setPen( linecolor( ( *it ).wavelength ) );
-                       
-                       p->drawLine( x,0,x, m_realHeight );
-                
-                       p->setPen( Qt::black );
-                               p->drawLine( x,m_realHeight,x, m_realHeight+10+temp );
-               }
-               else
-               {
-                       p->drawLine( x,0,x, m_realHeight+10+temp );
-               }
-               
-               QString text = QString::number( ( *it ).wavelength );
-               p->drawText(0, 0, text);
-
-               i++;
+               spec->addBand( *it );
        }
-       kdDebug() << "leaving Spectrum::paintBands()" << endl;
-}
 
-QColor Spectrum::linecolor( double spectrum )
-{
-        int r,g,b;
-        wavelengthToRGB( spectrum, r,g,b );
+       spec->adjustMinMax();
 
-        QColor c( r,g,b );
-        return c;
+       return spec;
 }
 
-
-void Spectrum::wavelengthToRGB( double wavelength, int& r, int& g, int& b )
+Spectrum* Spectrum::adjustIntensities()
 {
-       double blue = 0.0, green = 0.0, red = 0.0, factor = 0.0;
-
-       int wavelength_ = ( int ) floor( wavelength );
-
-       if ( wavelength_ > 380 && wavelength_ < 439 )
-       {
-               red = -( wavelength-440 ) / ( 440-380 );
-               green = 0.0;
-               blue = 1.0;
-       
-       }
-       if ( wavelength_ > 440 && wavelength_ < 489 )
-       {
-               red = 0.0;
-               green = ( wavelength-440 ) / ( 490-440 );
-               blue = 1.0;
-       }
-       if ( wavelength_ > 490 && wavelength_ < 509 )
-       {
-               red = 0.0;
-               green = 1.0;
-               blue = -( wavelength-510 ) / ( 510-490 );
-       }
-       if ( wavelength_ > 510 && wavelength_ < 579 )
-       {
-               red = ( wavelength-510 ) / ( 580-510 );
-               green = 1.0;
-               blue = 0.0;
-       }
-       if ( wavelength_ > 580 && wavelength_ < 644 )
-       {
-               red = 1.0;
-               green = -( wavelength-645 ) / ( 645-580 );
-               blue = 0.0;
-       }
-       if ( wavelength_ > 645 && wavelength_ < 780 )
-       {
-               red = 1.0;
-               green = 0.0;
-               blue = 0.0;
-       }
-       if ( wavelength_ > 380 && wavelength_ < 419 )
-               factor = 0.3 + 0.7*( wavelength - 380 ) / ( 420 - 380 );
-       else if ( wavelength_ > 420 && wavelength_ < 700 )
-               factor = 1.0;
-       else if ( wavelength_ > 701 && wavelength_ < 780 )
-               factor = 0.3 + 0.7*( 780 - wavelength ) / ( 780 - 700 );
-       else
-               factor = 0.0;
-
-       r = Adjust( red, factor );
-       g = Adjust( green, factor );
-       b = Adjust( blue, factor );
+       return this;
 }
 
-int Spectrum::Adjust( double color, double factor )
+double Spectrum::maxBand()
 {
-       if ( color == 0.0 )
-               return 0;
-       else
-               return ( int )( round( IntensityMax * pow( color*factor, Gamma ) ) );
+       double value = ( *m_bandlist.begin() ).wavelength;
+       QValueList<band>::Iterator it = m_bandlist.begin();
+       const QValueList<band>::Iterator itEnd = m_bandlist.end();
+       for (;it!=itEnd;++it)
+       {
+               if ( value < ( *it ).wavelength )
+                       value = ( *it ).wavelength;
+       }
+       return value;
 }
 
 SpectrumView::SpectrumView( Spectrum *spec, QWidget *parent, const char* name )
index 9c3f6829ef0aedc16d091e442b0eb7e3baea70e8..b99389906e53db563f060ab65ce4a60015eb753d 100644 (file)
@@ -46,16 +46,6 @@ class Spectrum
        public:
                Spectrum(){
                        kdDebug() <<"Spectrum::Spectrum" << endl;
-
-                       m_min = minBand();
-                       m_max = maxBand();
-
-                       //For the colorcalculation
-                       Gamma = 0.8;
-                       IntensityMax = 255,
-
-                       m_realWidth = 360;
-                       m_realHeight = 200;
                };
                ~Spectrum(){};
 
@@ -81,6 +71,19 @@ class Spectrum
                        m_bandlist.append( b );
                }
 
+               /**
+                * @param min the lowest allowed wavalength
+                * @param max the highest allowed wavalength
+                * 
+                * @returns a spectrum with the wavelength in the range
+                * of @p min to @p max. The intensities are readjusted
+                * so that the biggest intensity is again 1000 and the 
+                * others are adopted.
+                */
+               Spectrum* adjustToWavelength( double min, double max );
+
+               Spectrum* adjustIntensities();
+
                double min() const{
                        return m_min;
                }
@@ -89,19 +92,6 @@ class Spectrum
                        return m_max;
                }
 
-               void setWidth( int width ){
-                       m_width = width;
-               }
-
-               void paintBands( QPainter* p, double startValue, double endValue, bool emissionSpectrum );
-
-               /**
-                * @returns the color of a line
-                * @param spectrum the value of the spectrum
-                */
-               QColor linecolor( double spectrum );
-
-
        private:
                /**
                 * @return the smallest wavelength
@@ -112,45 +102,15 @@ class Spectrum
                 * @return the biggest wavelength
                 */
                double maxBand();
-
-               /**
-                * @return the postion in the widget of a band 
-                * with the wavelength @p wavelength
-                * 
-                * @param wavelength the wavelength for which the position is needed
-                */
-               inline int xPos( double wavelength, double startValue, double endValue ){
-                       return ( int ) ( m_width * ( wavelength - startValue ) / ( endValue - startValue ) );
+               
+               void adjustMinMax(){
+                       m_min = minBand();
+                       m_max = maxBand();
                }
 
-               /**
-                * This method changes the three values @p r @p g and @p b to the 
-                * correct values
-                * param wavelength the wavelength for which the color is searched
-                * param r red
-                * param g green 
-                * param b blue
-                */
-               void wavelengthToRGB( double wavelength, int& r, int& g, int& b );
-
-               double Gamma;
-               int IntensityMax;
-
-               int m_realWidth;
-               int m_realHeight;
-
-               /**
-                * @return the adjusted value of the @p color. The
-                * correction depends on @p factor which has been
-                * figured out emperically
-                */
-               int Adjust( double color, double factor );
-
                QValueList<band> m_bandlist;
 
                double m_max, m_min;
-
-               int m_width;
 };
 
 class SpectrumView : public QWidget