Version: 0.6.0
rasterrenderer.h
1 /******************************************************************************
2  * Project: wxGIS
3  * Purpose: wxGISRasterRenderer classes.
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2009,2011,2013 Dmitry Baryshnikov
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 
23 #include "wxgis/carto/renderer.h"
24 
25 #include "wxgis/carto/stretch.h"
26 
30 enum wxGISEnumRasterRendererType
31 {
32  enumGISRasterRenderTypeNone = 0,
33  enumGISRasterRenderTypeGreyScale,
34  enumGISRasterRenderTypeRGBA,
35  enumGISRasterRenderTypeIndexed,
36  enumGISRasterRenderTypePackedRGBA
37 };
38 
43 typedef struct _rawpixeldata
44 {
45  void* pPixelData;
46  int nPixelDataWidth, nPixelDataHeight;
47  double dPixelDataWidth, dPixelDataHeight;
48  double dPixelDeltaX, dPixelDeltaY;
49  int nOutputWidth, nOutputHeight;
50  OGREnvelope stWorldBounds;
52 
54 
55 inline double BiCubicKernel(double x)
56 {
57  if ( x > 2.0 )
58  return 0.0;
59 
60  double a, b, c, d;
61  double xm1 = x - 1.0;
62  double xp1 = x + 1.0;
63  double xp2 = x + 2.0;
64 
65  a = ( xp2 <= 0.0 ) ? 0.0 : xp2 * xp2 * xp2;
66  b = ( xp1 <= 0.0 ) ? 0.0 : xp1 * xp1 * xp1;
67  c = ( x <= 0.0 ) ? 0.0 : x * x * x;
68  d = ( xm1 <= 0.0 ) ? 0.0 : xm1 * xm1 * xm1;
69 
70  return ( 0.16666666666666666667 * ( a - ( 4.0 * b ) + ( 6.0 * c ) - ( 4.0 * d ) ) );
71 };
72 
73 static void NearestNeighbourInterpolation(void *pInputData, int nInputXSize, double dInputXSize, double dInputYSize, double dDeltaX, double dDeltaY, GDALDataType eSrcType, unsigned char *pOutputData, int nOutXSize, int nOutYSize, int nBegY, int nEndY, int nBandCount, wxGISRasterRenderer* const pRasterRenderer, ITrackCancel* const pTrackCancel = NULL);
74 
75 static void BilinearInterpolation(void *pInputData, int nInputXSize, int nInputYSize, double dInputXSize, double dInputYSize, double dDeltaX, double dDeltaY, GDALDataType eSrcType, unsigned char *pOutputData, int nOutXSize, int nOutYSize, int nBegY, int nEndY, int nBandCount, wxGISRasterRenderer* const pRasterRenderer, ITrackCancel* const pTrackCancel = NULL);
76 
77 static void BicubicInterpolation(void *pInputData, int nInputXSize, int nInputYSize, double dInputXSize, double dInputYSize, double dDeltaX, double dDeltaY, GDALDataType eSrcType, unsigned char *pOutputData, int nOutXSize, int nOutYSize, int nBegY, int nEndY, int nBandCount, wxGISRasterRenderer* const pRasterRenderer, ITrackCancel* const pTrackCancel = NULL);
78 
79 // static void OnHalfBilinearInterpolation(const unsigned char* pOrigData, unsigned char* pDestData, int nYbeg, int nYend, int nOrigWidth, int nOrigHeight, int nDestWidth, double rWRatio, double rHRatio, double rDeltaX, double rDeltaY, ITrackCancel* pTrackCancel);
80 // static void OnHalfQuadBilinearInterpolation(const unsigned char* pOrigData, unsigned char* pDestData, int nYbeg, int nYend, int nOrigWidth, int nOrigHeight, int nDestWidth, double rWRatio, double rHRatio, double rDeltaX, double rDeltaY, ITrackCancel* pTrackCancel);
81 // static void OnFourQuadBilinearInterpolation(const unsigned char* pOrigData, unsigned char* pDestData, int nYbeg, int nYend, int nOrigWidth, int nOrigHeight, int nDestWidth, double rWRatio, double rHRatio, double rDeltaX, double rDeltaY, ITrackCancel* pTrackCancel);
82 
87 class wxRasterDrawThread : public wxThread
88 {
89  friend class wxGISRasterRenderer;
90 public:
91  wxRasterDrawThread(RAWPIXELDATA &stPixelData, GDALDataType eSrcType, int nBandCount, unsigned char *pTransformData, wxGISEnumDrawQuality eQuality, int nOutXSize, int nOutYSize, int nBegY, int nEndY, wxGISRasterRenderer *pRasterRenderer, ITrackCancel * const pTrackCancel = NULL);
92  virtual void *Entry();
93  virtual void OnExit();
94 private:
95  ITrackCancel* const m_pTrackCancel;
96  wxGISRasterRenderer *m_pRasterRenderer;
97  RAWPIXELDATA &m_stPixelData;
98  GDALDataType m_eSrcType;
99  unsigned char *m_pTransformData;
100  wxGISEnumDrawQuality m_eQuality;
101  int m_nOutXSize;
102  int m_nOutYSize;
103  int m_nBegY;
104  int m_nEndY;
105  int m_nBandCount;
106 };
107 
113  public wxGISRenderer
114 {
115  DECLARE_ABSTRACT_CLASS(wxGISRasterRenderer)
116 public:
117  wxGISRasterRenderer(wxGISLayer* pwxGISLayer = NULL);
118  virtual ~wxGISRasterRenderer(void);
119  virtual bool CanRender(wxGISLayer* const pwxGISLayer) const;
120  virtual int *GetBandsCombination(int *pnBandCount) = 0;
121  virtual bool Draw(wxGISEnumDrawPhase DrawPhase, wxGISDisplay* const pDisplay, ITrackCancel* const pTrackCancel = NULL);
122  virtual bool Apply(ITrackCancel* const pTrackCancel = NULL);
123  virtual wxGISColorTable GetColorTable(void) const {return m_mColorTable;};
124  virtual wxGISEnumRasterRendererType GetRasterRenderType(void) const {return enumGISRasterRenderTypeNone;};
125  virtual wxGISEnumRendererType GetType(void) const {return enumGISRenderTypeRaster;};
126  virtual void FillPixel(unsigned char* pOutputData, const double *pSrcValR, const double *pSrcValG, const double *pSrcValB, const double *pSrcValA) = 0;
127 protected:
128  virtual bool Draw(RAWPIXELDATA &stPixelData, wxGISEnumDrawPhase DrawPhase, wxGISDisplay* const pDisplay, ITrackCancel * const pTrackCancel = NULL);
129  virtual short GetBandCount() const = 0;
130 protected:
131  wxColour m_oNoDataColor;
132  //statistics - current display extent, each raster dataset, custom settings
133  wxGISRasterDataset* m_pwxGISRasterDataset;
134  wxGISEnumDrawQuality m_eQuality;
135  wxGISColorTable m_mColorTable;
136  unsigned short m_nTileSizeX, m_nTileSizeY;
137 };
138 
144  public wxGISRasterRenderer
145 {
146  DECLARE_DYNAMIC_CLASS(wxGISRasterRGBARenderer)
147 public:
148  wxGISRasterRGBARenderer(wxGISLayer* pwxGISLayer = NULL);
149  virtual ~wxGISRasterRGBARenderer(void);
150 //wxGISRasterRenderer
151  virtual bool CanRender(wxGISLayer* const pwxGISLayer) const;
152  virtual int *GetBandsCombination(int *pnBandCount);
153  virtual void FillPixel(unsigned char* pOutputData, const double *pSrcValR, const double *pSrcValG, const double *pSrcValB, const double *pSrcValA);
154  virtual wxGISEnumRasterRendererType GetRasterRenderType(void) const {return enumGISRasterRenderTypeRGBA;};
155 protected:
156  virtual void OnFillStats(void);
157  virtual short GetBandCount() const;
158 protected:
159  int m_nRedBand, m_nGreenBand, m_nBlueBand, m_nAlphaBand;
160  //wxColour m_oBkColorGet, m_oBkColorSet,
161  //statistics - current display extent, each raster dataset, custom settings
162  wxGISStretch *m_paStretch[4];
163  bool m_bNodataNewBehaviour;
164 };
165 
171  public wxGISRasterRenderer
172 {
173  DECLARE_DYNAMIC_CLASS(wxGISRasterRasterColormapRenderer)
174 public:
175  wxGISRasterRasterColormapRenderer(wxGISLayer* pwxGISLayer = NULL);
176  virtual ~wxGISRasterRasterColormapRenderer(void);
177 //wxGISRasterRenderer
178  virtual bool CanRender(wxGISLayer* const pwxGISLayer) const;
179  virtual int *GetBandsCombination(int *pnBandCount);
180  virtual void FillPixel(unsigned char* pOutputData, const double *pSrcValR, const double *pSrcValG, const double *pSrcValB, const double *pSrcValA);
181  virtual wxGISEnumRasterRendererType GetRasterRenderType(void) const {return enumGISRasterRenderTypeIndexed;};
182  //virtual const wxColor *GetColorByIndex(long nIndex);
183 protected:
184  virtual void OnFillColorTable(void);
185  virtual short GetBandCount() const;
186  wxColor HSVtoRGB( const short &h, const short &s, const short &v, const short &alpha );
187  wxColor CMYKtoRGB( const short &c, const short &m, const short &y, const short &k );
188 protected:
189  int m_nBandNumber;
190  bool m_bHasNoData;
191  short m_nNoDataIndex;
192 };
193 
199  public wxGISRasterRenderer
200 {
201  DECLARE_DYNAMIC_CLASS(wxGISRasterGreyScaleRenderer)
202 public:
203  wxGISRasterGreyScaleRenderer(wxGISLayer* pwxGISLayer = NULL);
204  virtual ~wxGISRasterGreyScaleRenderer(void);
205  virtual int *GetBandsCombination(int *pnBandCount);
206  virtual void FillPixel(unsigned char* pOutputData, const double *pSrcValR, const double *pSrcValG, const double *pSrcValB, const double *pSrcValA);
207  virtual wxGISEnumRasterRendererType GetRasterRenderType(void) const {return enumGISRasterRenderTypeGreyScale;};
208 protected:
209  virtual void OnFillStats(void);
210  virtual short GetBandCount() const;
211 protected:
212  int m_nBand;
213  wxGISStretch m_oStretch;
214 };
215 
222 {
223  DECLARE_DYNAMIC_CLASS(wxGISRasterPackedRGBARenderer)
224 public:
225  wxGISRasterPackedRGBARenderer(wxGISLayer* pwxGISLayer = NULL);
226  virtual ~wxGISRasterPackedRGBARenderer(void);
227 //wxGISRasterGreyScaleRenderer
228  virtual void FillPixel(unsigned char* pOutputData, const double *pSrcValR, const double *pSrcValG, const double *pSrcValB, const double *pSrcValA);
229  virtual wxGISEnumRasterRendererType GetRasterRenderType(void) const{return enumGISRasterRenderTypePackedRGBA;};
230 protected:
231  bool m_bNodataNewBehaviour;
232 };
Definition: rasterdataset.h:32
The base class for renderers.
Definition: rasterrenderer.h:112
The raster layer renderer for RGB data and Alpha channel.
Definition: rasterrenderer.h:143
The raster layer renderer for packed RGB data and Alpha channel.
Definition: rasterrenderer.h:220
The raster layer renderer for Palette Index data.
Definition: rasterrenderer.h:170
The base class for stretch from pixel field to display field.
Definition: stretch.h:52
Definition: gisdisplay.h:43
A TrackCancel interface class.
Definition: core.h:144
Definition: layer.h:35
The raster layer draw thread.
Definition: rasterrenderer.h:87
The raster layer renderer for grey scale data.
Definition: rasterrenderer.h:198
The base class for renderers.
Definition: renderer.h:31
Definition: rasterrenderer.h:43