Warning, file /education/marble/tools/mapreproject/SimpleMapImage.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #include "SimpleMapImage.h"
0002 
0003 #include "InterpolationMethod.h"
0004 
0005 #include <cmath>
0006 
0007 SimpleMapImage::SimpleMapImage( QString const & fileName )
0008     : m_image( fileName ),
0009       m_mapWidthPixel( m_image.width() ),
0010       m_mapHeightPixel( m_image.height() )
0011 {
0012     if ( m_image.isNull() )
0013         qFatal( "Invalid image '%s'", fileName.toStdString().c_str() );
0014 }
0015 
0016 QRgb SimpleMapImage::pixel( double const lonRad,  double const latRad )
0017 {
0018     double const x = lonRadToPixelX( lonRad );
0019     double const y = latRadToPixelY( latRad );
0020     return m_interpolationMethod->interpolate( x, y );
0021 }
0022 
0023 QRgb SimpleMapImage::pixel( int const x, int const y )
0024 {
0025     return m_image.pixel( x, m_mapHeightPixel - y - 1 );
0026 }
0027 
0028 void SimpleMapImage::setInterpolationMethod( InterpolationMethod * const interpolationMethod )
0029 {
0030     m_interpolationMethod = interpolationMethod;
0031     m_interpolationMethod->setMapImage( this );
0032 }
0033 
0034 inline double SimpleMapImage::lonRadToPixelX( double const lonRad ) const
0035 {
0036     return static_cast<double>( m_mapWidthPixel ) / ( 2.0 * M_PI ) * lonRad
0037             + 0.5 * static_cast<double>( m_mapWidthPixel );
0038 }
0039 
0040 inline double SimpleMapImage::latRadToPixelY( double const latRad ) const
0041 {
0042     return static_cast<double>( m_mapHeightPixel ) / M_PI * latRad
0043             + 0.5 * static_cast<double>( m_mapHeightPixel );
0044 }