File indexing completed on 2024-02-25 03:55:48

0001 #include "ReadOnlyMapDefinition.h"
0002 
0003 #include "BilinearInterpolation.h"
0004 #include "IntegerInterpolation.h"
0005 #include "NearestNeighborInterpolation.h"
0006 #include "NwwMapImage.h"
0007 #include "SimpleMapImage.h"
0008 
0009 ReadOnlyMapDefinition::ReadOnlyMapDefinition()
0010     : m_mapType( UnknownMapSource ),
0011       m_interpolationMethod( UnknownInterpolationMethod ),
0012       m_baseDirectory(),
0013       m_tileLevel( -1 ),
0014       m_cacheSizeBytes(),
0015       m_filename()
0016 {
0017 }
0018 
0019 InterpolationMethod * ReadOnlyMapDefinition::createInterpolationMethod() const
0020 {
0021     switch ( m_interpolationMethod ) {
0022     case IntegerInterpolationMethod:
0023         return new IntegerInterpolation;
0024     case NearestNeighborInterpolationMethod:
0025         return new NearestNeighborInterpolation;
0026     case AverageInterpolationMethod:
0027         return nullptr;
0028     case BilinearInterpolationMethod:
0029         return new BilinearInterpolation;
0030     default:
0031         return nullptr;
0032     }
0033 }
0034 
0035 ReadOnlyMapImage * ReadOnlyMapDefinition::createReadOnlyMap() const
0036 {
0037     InterpolationMethod * const interpolationMethod = createInterpolationMethod();
0038     if ( !interpolationMethod )
0039         qFatal( "Unsupported interpolation method: '%i'", m_interpolationMethod );
0040 
0041     if ( m_mapType == NasaWorldWindMap ) {
0042         NwwMapImage * const mapImage = new NwwMapImage( m_baseDirectory, m_tileLevel );
0043         interpolationMethod->setMapImage( mapImage );
0044         mapImage->setInterpolationMethod( interpolationMethod );
0045         mapImage->setCacheSizeBytes( m_cacheSizeBytes );
0046         return mapImage;
0047     }
0048     else if ( m_mapType == BathymetryMap ) {
0049         SimpleMapImage * const mapImage = new SimpleMapImage( m_filename );
0050         interpolationMethod->setMapImage( mapImage );
0051         mapImage->setInterpolationMethod( interpolationMethod );
0052         return mapImage;
0053     }
0054     else {
0055         delete interpolationMethod;
0056         return nullptr;
0057     }
0058 }