File indexing completed on 2024-04-21 14:46:47

0001 /*
0002     SPDX-FileCopyrightText: 2021 Hy Murveit <hy@murveit.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <QObject>
0011 #include <QImage>
0012 #include "projections/projector.h"
0013 
0014 class TerrainLookup;
0015 
0016 class TerrainRenderer : public QObject
0017 {
0018         Q_OBJECT
0019     public:
0020         // Create an instance of TerrainRenderer. We only have one.
0021         static TerrainRenderer *Instance();
0022 
0023         // Render terrainImage according to the loaded image and the projection.
0024         bool render(uint16_t w, uint16_t h, QImage *terrainImage, const Projector *proj);
0025     signals:
0026 
0027     public slots:
0028 
0029     private:
0030         // Constructor is private. Only make it with Instance().
0031         TerrainRenderer();
0032 
0033         // Speed-up the image calculations by downsampling azimuth and altitude
0034         // computations of the pixels in the input view.
0035         void setupLookup(uint16_t w, uint16_t h, int sampling, const Projector *proj,
0036                          TerrainLookup *azLookup, TerrainLookup *altLookup);
0037 
0038         // Returns the pixel in sourceImage for the given coordinates.
0039         QRgb getPixel(double az, double alt) const;
0040 
0041         // Checks to see if we can use the old rendering.
0042         // If not, copies the view for the next call.
0043         bool sameView(const Projector *proj, bool forceRefresh);
0044 
0045         // This is the only instance we'll make.
0046         static TerrainRenderer * _terrainRenderer;
0047 
0048         // True if the terrain image is setup.
0049         bool initialized = false;
0050 
0051         // The terrain image projection.
0052         QImage sourceImage;
0053 
0054         // Save the input view and the computed image in case the image can be re-used.
0055         ViewParams savedViewParams;
0056         double savedAz, savedAlt;
0057         QImage savedImage;
0058 
0059         // Keep the parameters used to display the last image
0060         // to see if something's changed and we need to redisplay.
0061         QString sourceFilename;
0062         int terrainDownsampling = 0;
0063         bool terrainSkipSpeedup = false;
0064         bool terrainSmoothPixels = false;
0065         bool terrainTransparencySpeedup = false;
0066         bool terrainSourceCorrectAz = 0;
0067         bool terrainSourceCorrectAlt = 0;
0068 };