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

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • tools
  • mapreproject
BilinearInterpolation.cpp
Go to the documentation of this file.
1 #include "BilinearInterpolation.h"
2 
3 #include "ReadOnlyMapImage.h"
4 
5 #include <cmath>
6 
7 BilinearInterpolation::BilinearInterpolation( ReadOnlyMapImage * const mapImage )
8  : InterpolationMethod( mapImage )
9 {
10 }
11 
12 QRgb BilinearInterpolation::interpolate( double const x, double const y )
13 {
14  int const x1 = x;
15  int const x2 = x1 + 1;
16  int const y1 = y;
17  int const y2 = y1 + 1;
18 
19  QRgb const lowerLeftPixel = m_mapImage->pixel( x1, y1 );
20  QRgb const lowerRightPixel = m_mapImage->pixel( x2, y1 );
21  QRgb const upperLeftPixel = m_mapImage->pixel( x1, y2 );
22  QRgb const upperRightPixel = m_mapImage->pixel( x2, y2 );
23 
24  // interpolate horizontically
25  //
26  // x2 - x x2 - x
27  // ------- = ------ = x1 + 1 - x = 1 - fractionX
28  // x2 - x1 1
29  //
30  // x - x1 x - x1
31  // ------- = ------ = fractionX
32  // x2 - x1 1
33 
34  double const fractionX = x - x1;
35  double const lowerMidRed = ( 1.0 - fractionX ) * qRed( lowerLeftPixel ) + fractionX * qRed( lowerRightPixel );
36  double const lowerMidGreen = ( 1.0 - fractionX ) * qGreen( lowerLeftPixel ) + fractionX * qGreen( lowerRightPixel );
37  double const lowerMidBlue = ( 1.0 - fractionX ) * qBlue( lowerLeftPixel ) + fractionX * qBlue( lowerRightPixel );
38  double const lowerMidAlpha = ( 1.0 - fractionX ) * qAlpha( lowerLeftPixel ) + fractionX * qAlpha( lowerRightPixel );
39 
40  double const upperMidRed = ( 1.0 - fractionX ) * qRed( upperLeftPixel ) + fractionX * qRed( upperRightPixel );
41  double const upperMidGreen = ( 1.0 - fractionX ) * qGreen( upperLeftPixel ) + fractionX * qGreen( upperRightPixel );
42  double const upperMidBlue = ( 1.0 - fractionX ) * qBlue( upperLeftPixel ) + fractionX * qBlue( upperRightPixel );
43  double const upperMidAlpha = ( 1.0 - fractionX ) * qAlpha( upperLeftPixel ) + fractionX * qAlpha( upperRightPixel );
44 
45  // interpolate vertically
46  //
47  // y2 - y y2 - y
48  // ------- = ------ = y1 + 1 - y = 1 - fractionY
49  // y2 - y1 1
50  //
51  // y - y1 y - y1
52  // ------- = ------ = fractionY
53  // y2 - y1 1
54 
55  double const fractionY = y - y1;
56  double const red = ( 1.0 - fractionY ) * lowerMidRed + fractionY * upperMidRed;
57  double const green = ( 1.0 - fractionY ) * lowerMidGreen + fractionY * upperMidGreen;
58  double const blue = ( 1.0 - fractionY ) * lowerMidBlue + fractionY * upperMidBlue;
59  double const alpha = ( 1.0 - fractionY ) * lowerMidAlpha + fractionY * upperMidAlpha;
60 
61  return qRgba( round( red ), round( green ), round( blue ), round( alpha ));
62 }
ReadOnlyMapImage.h
InterpolationMethod
Definition: InterpolationMethod.h:8
ReadOnlyMapImage
Definition: ReadOnlyMapImage.h:8
BilinearInterpolation::BilinearInterpolation
BilinearInterpolation(ReadOnlyMapImage *const mapImage=NULL)
Definition: BilinearInterpolation.cpp:7
BilinearInterpolation.h
ReadOnlyMapImage::pixel
virtual QRgb pixel(double const lonRad, double const latRad)=0
BilinearInterpolation::interpolate
virtual QRgb interpolate(double const x, double const y)
Definition: BilinearInterpolation.cpp:12
InterpolationMethod::m_mapImage
ReadOnlyMapImage * m_mapImage
Definition: InterpolationMethod.h:18
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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