17
17
18
18
#include " qgslogger.h"
19
19
#include " qgsrasterdrawer.h"
20
- // #include "qgsrasterresampler.h"
21
- #include " qgsrasterprojector.h"
22
- #include " qgsrastertransparency.h"
20
+ #include " qgsrasteriterator.h"
23
21
#include " qgsrasterviewport.h"
24
22
#include " qgsmaptopixel.h"
25
-
26
- // resamplers
27
- // #include "qgsbilinearrasterresampler.h"
28
- // #include "qgscubicrasterresampler.h"
29
-
30
- #include < QDomDocument>
31
- #include < QDomElement>
32
23
#include < QImage>
33
24
#include < QPainter>
34
25
35
- QgsRasterDrawer::QgsRasterDrawer ( QgsRasterInterface* input ): mInput( input )
26
+ QgsRasterDrawer::QgsRasterDrawer ( QgsRasterIterator* iterator ): mIterator( iterator )
36
27
{
37
28
}
38
29
39
30
QgsRasterDrawer::~QgsRasterDrawer ()
40
31
{
41
- // remove remaining memory in partinfos
42
- /*
43
- QMap<int, RasterPartInfo>::iterator partIt = mRasterPartInfos.begin();
44
- for ( ; partIt != mRasterPartInfos.end(); ++partIt )
45
- {
46
- CPLFree( partIt.value().data );
47
- }
48
- */
49
32
}
50
33
51
34
void QgsRasterDrawer::draw ( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )
52
35
{
53
36
QgsDebugMsg ( " Entered" );
54
- if ( !p || !mInput || !viewPort || !theQgsMapToPixel )
37
+ if ( !p || !mIterator || !viewPort || !theQgsMapToPixel )
55
38
{
56
39
return ;
57
40
}
58
41
59
42
// last pipe filter has only 1 band
60
43
int bandNumber = 1 ;
61
- startRasterRead ( bandNumber, viewPort, theQgsMapToPixel );
44
+ mIterator -> startRasterRead ( bandNumber, viewPort, theQgsMapToPixel );
62
45
63
46
// number of cols/rows in output pixels
64
47
int nCols = 0 ;
@@ -76,8 +59,8 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
76
59
void * rasterData;
77
60
78
61
// readNextRasterPart calcs and resets nCols, nRows, topLeftCol, topLeftRow
79
- while ( readNextRasterPart ( bandNumber, viewPort, nCols, nRows,
80
- &rasterData, topLeftCol, topLeftRow ) )
62
+ while ( mIterator -> readNextRasterPart ( bandNumber, viewPort, nCols, nRows,
63
+ &rasterData, topLeftCol, topLeftRow ) )
81
64
{
82
65
// create image
83
66
// QImage img( nRasterCols, nRasterRows, QImage::Format_ARGB32_Premultiplied );
@@ -91,120 +74,6 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
91
74
}
92
75
}
93
76
94
- void QgsRasterDrawer::startRasterRead ( int bandNumber, QgsRasterViewPort* viewPort, const QgsMapToPixel* mapToPixel )
95
- {
96
- if ( !viewPort || !mapToPixel || !mInput )
97
- {
98
- return ;
99
- }
100
-
101
- // remove any previous part on that band
102
- removePartInfo ( bandNumber );
103
-
104
- // split raster into small portions if necessary
105
- RasterPartInfo pInfo;
106
- pInfo.nCols = viewPort->drawableAreaXDim ;
107
- pInfo.nRows = viewPort->drawableAreaYDim ;
108
-
109
- // effective oversampling factors are different to global one because of rounding
110
- // oversamplingX = (( double )pInfo.nCols * oversampling ) / viewPort->drawableAreaXDim;
111
- // oversamplingY = (( double )pInfo.nRows * oversampling ) / viewPort->drawableAreaYDim;
112
-
113
- // TODO : we dont know oversampling (grid size) here - how to get totalMemoryUsage ?
114
- // int totalMemoryUsage = pInfo.nCols * oversamplingX * pInfo.nRows * oversamplingY * mInput->dataTypeSize( bandNumber );
115
- int totalMemoryUsage = pInfo.nCols * pInfo.nRows * mInput ->dataTypeSize ( bandNumber );
116
- int parts = totalMemoryUsage / 100000000 + 1 ;
117
- int nPartsPerDimension = sqrt ( parts );
118
- pInfo.nColsPerPart = pInfo.nCols / nPartsPerDimension;
119
- pInfo.nRowsPerPart = pInfo.nRows / nPartsPerDimension;
120
- pInfo.currentCol = 0 ;
121
- pInfo.currentRow = 0 ;
122
- pInfo.data = 0 ;
123
- pInfo.prj = 0 ;
124
- mRasterPartInfos .insert ( bandNumber, pInfo );
125
- }
126
-
127
- bool QgsRasterDrawer::readNextRasterPart ( int bandNumber, QgsRasterViewPort* viewPort,
128
- int & nCols, int & nRows, void ** rasterData, int & topLeftCol, int & topLeftRow )
129
- {
130
- if ( !viewPort )
131
- {
132
- return false ;
133
- }
134
-
135
- // get partinfo
136
- QMap<int , RasterPartInfo>::iterator partIt = mRasterPartInfos .find ( bandNumber );
137
- if ( partIt == mRasterPartInfos .end () )
138
- {
139
- return false ;
140
- }
141
-
142
- RasterPartInfo& pInfo = partIt.value ();
143
-
144
- // remove last data block
145
- // TODO: data are released somewhere else (check)
146
- // free( pInfo.data );
147
- pInfo.data = 0 ;
148
- delete pInfo.prj ;
149
- pInfo.prj = 0 ;
150
-
151
- // already at end
152
- if ( pInfo.currentCol == pInfo.nCols && pInfo.currentRow == pInfo.nRows )
153
- {
154
- return false ;
155
- }
156
-
157
- // read data block
158
- nCols = qMin ( pInfo.nColsPerPart , pInfo.nCols - pInfo.currentCol );
159
- nRows = qMin ( pInfo.nRowsPerPart , pInfo.nRows - pInfo.currentRow );
160
- int typeSize = mInput ->dataTypeSize ( bandNumber ) / 8 ;
161
-
162
- // get subrectangle
163
- QgsRectangle viewPortExtent = viewPort->mDrawnExtent ;
164
- double xmin = viewPortExtent.xMinimum () + pInfo.currentCol / ( double )pInfo.nCols * viewPortExtent.width ();
165
- double xmax = viewPortExtent.xMinimum () + ( pInfo.currentCol + nCols ) / ( double )pInfo.nCols * viewPortExtent.width ();
166
- double ymin = viewPortExtent.yMaximum () - ( pInfo.currentRow + nRows ) / ( double )pInfo.nRows * viewPortExtent.height ();
167
- double ymax = viewPortExtent.yMaximum () - pInfo.currentRow / ( double )pInfo.nRows * viewPortExtent.height ();
168
- QgsRectangle blockRect ( xmin, ymin, xmax, ymax );
169
-
170
- pInfo.data = mInput ->block ( bandNumber, blockRect, nCols, nRows );
171
-
172
- *rasterData = pInfo.data ;
173
- topLeftCol = pInfo.currentCol ;
174
- topLeftRow = pInfo.currentRow ;
175
-
176
- pInfo.currentCol += nCols;
177
- if ( pInfo.currentCol == pInfo.nCols && pInfo.currentRow + nRows == pInfo.nRows ) // end of raster
178
- {
179
- pInfo.currentRow = pInfo.nRows ;
180
- }
181
- else if ( pInfo.currentCol == pInfo.nCols ) // start new row
182
- {
183
- pInfo.currentCol = 0 ;
184
- pInfo.currentRow += pInfo.nRowsPerPart ;
185
- }
186
-
187
- return true ;
188
- }
189
-
190
- void QgsRasterDrawer::stopRasterRead ( int bandNumber )
191
- {
192
- removePartInfo ( bandNumber );
193
- }
194
-
195
- void QgsRasterDrawer::removePartInfo ( int bandNumber )
196
- {
197
- QMap<int , RasterPartInfo>::iterator partIt = mRasterPartInfos .find ( bandNumber );
198
- if ( partIt != mRasterPartInfos .end () )
199
- {
200
- RasterPartInfo& pInfo = partIt.value ();
201
- // CPLFree( pInfo.data );
202
- free ( pInfo.data );
203
- delete pInfo.prj ;
204
- mRasterPartInfos .remove ( bandNumber );
205
- }
206
- }
207
-
208
77
void QgsRasterDrawer::drawImage ( QPainter* p, QgsRasterViewPort* viewPort, const QImage& img, int topLeftCol, int topLeftRow ) const
209
78
{
210
79
if ( !p || !viewPort )
0 commit comments