Skip to content

Commit 001049b

Browse files
author
morb_au
committedMay 15, 2005
Allow source raster *subpixel* positioning on map canvasses. This allows zooming in on coarse rasters to be accurate (i.e. when 1 source pixel covers more than one screen pixel). This has only been proof-of-concept tested, therefore the author will not be offended if further refinements are committed. This addresses CVS bug 895502.
git-svn-id: http://svn.osgeo.org/qgis/trunk@3396 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent de40711 commit 001049b

File tree

7 files changed

+397
-82
lines changed

7 files changed

+397
-82
lines changed
 

‎ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
Version 0.6 'Simon' .... development version
44
QGIS Change Log
55

6+
2005-05-15 [morb_au] 0.6devel21
7+
** Fixed a memory leak in the postgres provider when retrieving features
8+
** Raster layers now align to the map canvas with subpixel source accuracy
9+
(most useful when zooming in very close and the source pixels cover many
10+
screen pixels)
11+
12+
0.6devel20 ?
13+
614
2005-05-13 [didge] 0.6devel19
715
** Tweaked makefile stuff and prepared for a release
816
2005-04-17 [mcoletti] 0.6devel18

‎configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dnl ---------------------------------------------------------------------------
2525
MAJOR_VERSION=0
2626
MINOR_VERSION=6
2727
MICRO_VERSION=0
28-
EXTRA_VERSION=20
28+
EXTRA_VERSION=21
2929
if test $EXTRA_VERSION -eq 0; then
3030
VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}
3131
else

‎qgis.kdevelop

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@
175175
<tree>
176176
<hidepatterns>*.o,*.lo,CVS</hidepatterns>
177177
<hidenonprojectfiles>false</hidenonprojectfiles>
178+
<showvcsfields>false</showvcsfields>
178179
</tree>
179180
</kdevfileview>
181+
<kdevcvsservice>
182+
<recursivewhenupdate>true</recursivewhenupdate>
183+
<prunedirswhenupdate>true</prunedirswhenupdate>
184+
<createdirswhenupdate>true</createdirswhenupdate>
185+
<recursivewhencommitremove>true</recursivewhencommitremove>
186+
<revertoptions>-C</revertoptions>
187+
</kdevcvsservice>
180188
</kdevelop>

‎src/qgsmaptopixel.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
QgsPoint QgsMapToPixel::toMapPoint(int x, int y)
2424
{
25-
double mx = x * mapUnitsPerPixel + xMin;
26-
double my = -1 * ((y - yMax) * mapUnitsPerPixel - yMin);
25+
double mx = x * mMapUnitsPerPixel + xMin;
26+
double my = -1 * ((y - yMax) * mMapUnitsPerPixel - yMin);
2727
return QgsPoint(mx, my);
2828
}
2929

@@ -40,7 +40,12 @@ QgsPoint QgsMapToPixel::toMapCoordinates(int x, int y)
4040

4141
void QgsMapToPixel::setMapUnitsPerPixel(double mupp)
4242
{
43-
mapUnitsPerPixel = mupp;
43+
mMapUnitsPerPixel = mupp;
44+
}
45+
46+
double QgsMapToPixel::mapUnitsPerPixel()
47+
{
48+
return mMapUnitsPerPixel;
4449
}
4550

4651
void QgsMapToPixel::setYmax(double ymax)
@@ -60,7 +65,7 @@ void QgsMapToPixel::setXmin(double xmin)
6065

6166
void QgsMapToPixel::setParameters(double mupp, double xmin, double ymin, double ymax)
6267
{
63-
mapUnitsPerPixel = mupp;
68+
mMapUnitsPerPixel = mupp;
6469
xMin = xmin;
6570
yMin = ymin;
6671
yMax = ymax;
@@ -70,7 +75,7 @@ void QgsMapToPixel::setParameters(double mupp, double xmin, double ymin, double
7075
QString QgsMapToPixel::showParameters()
7176
{
7277
QString rep;
73-
QTextOStream(&rep) << "Map units/pixel: " << mapUnitsPerPixel
78+
QTextOStream(&rep) << "Map units/pixel: " << mMapUnitsPerPixel
7479
<< " X minimum: " << xMin << " Y minimum: " << yMin << " Y maximum: " << yMax;
7580
return rep;
7681

‎src/qgsmaptopixel.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class QgsMapToPixel{
8585
* @param mupp Map units per pixel
8686
*/
8787
void setMapUnitsPerPixel(double mupp);
88+
89+
//! Return current map units per pixel
90+
double mapUnitsPerPixel();
91+
8892
//! Set maximum y value
8993
void setYmax(double ymax);
9094
//! Set minimum y value
@@ -102,7 +106,7 @@ class QgsMapToPixel{
102106
QString showParameters();
103107

104108
private:
105-
double mapUnitsPerPixel;
109+
double mMapUnitsPerPixel;
106110
double yMax;
107111
double yMin;
108112
double xMin;
@@ -114,7 +118,7 @@ inline QgsMapToPixel::QgsMapToPixel(double mupp,
114118
double ymax,
115119
double ymin,
116120
double xmin)
117-
: mapUnitsPerPixel(mupp),
121+
: mMapUnitsPerPixel(mupp),
118122
yMax(ymax),
119123
yMin(ymin),
120124
xMin(xmin),
@@ -156,8 +160,8 @@ inline void QgsMapToPixel::transform(QgsPoint* p)
156160

157161
inline void QgsMapToPixel::transformInPlace(double& x, double& y)
158162
{
159-
x = (x - xMin) / mapUnitsPerPixel;
160-
y = yMax - (y - yMin) / mapUnitsPerPixel;
163+
x = (x - xMin) / mMapUnitsPerPixel;
164+
y = yMax - (y - yMin) / mMapUnitsPerPixel;
161165
}
162166

163167
inline void QgsMapToPixel::transformInPlace(std::vector<double>& x,

‎src/qgsrasterlayer.cpp

Lines changed: 320 additions & 48 deletions
Large diffs are not rendered by default.

‎src/qgsrasterlayer.h

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,13 @@ typedef QValueVector<RasterBandStats> RasterStatsVector;
243243
*/
244244
struct RasterViewPort
245245
{
246-
/** \brief The offset from the left hand edge of the raster for the rectangle that will be drawn to screen.
247-
* TODO Check this explanation is correc!*/
246+
/** \brief The offset (in source raster pixel coordinates) from the left hand edge of the source raster for the rectangle that will be drawn to screen. */
247+
float rectXOffsetFloat;
248+
/** \brief The offset (in source raster pixel coordinates) from the top edge of the source raster for the rectangle that will be drawn to screen. */
249+
float rectYOffsetFloat;
250+
/** \brief The offset (in source raster pixel coordinates) from the left hand edge of the source raster for the rectangle that will be drawn to screen - truncated to an integer. */
248251
int rectXOffsetInt;
249-
/** \brief The offset from the bottom edge of the raster for the rectangle that will be drawn to screen.
250-
* TODO Check this explanation is correc!*/
252+
/** \brief The offset (in source raster pixel coordinates) from the top edge of the source raster for the rectangle that will be drawn to screen - truncated to an integer. */
251253
int rectYOffsetInt;
252254
/** \brief Lower left X dimension of clipped raster image in raster pixel space.
253255
* RasterIO will do the scaling for us, so for example, if the user is zoomed in a long way, there may only
@@ -374,10 +376,12 @@ class QgsRasterLayer : public QgsMapLayer
374376
QPixmap getPaletteAsPixmap();
375377

376378
/** \brief This is called when the view on the rasterlayer needs to be refreshed (redrawn). */
377-
void draw(QPainter * theQPainter, QgsRect * theViewExtent, QgsMapToPixel * theQgsMapToPixel, QPaintDevice* dst);
379+
void draw(QPainter * theQPainter, QgsRect * theViewExtent,
380+
QgsMapToPixel * theQgsMapToPixel, QPaintDevice* dst);
378381

379382
/** \brief This is an overloaded version of the above function that is called by both draw above and drawThumbnail */
380-
void draw (QPainter * theQPainter, RasterViewPort * myRasterViewPort);
383+
void draw(QPainter * theQPainter, RasterViewPort * myRasterViewPort,
384+
QgsMapToPixel * theQgsMapToPixel = 0);
381385

382386
//
383387
// Accessors for image height and width
@@ -865,10 +869,16 @@ public slots:
865869
//
866870

867871
/** \brief Drawing routine for single band grayscale image. */
868-
void drawSingleBandGray(QPainter * theQPainter, RasterViewPort * theRasterViewPort,int theBandNoInt);
872+
void drawSingleBandGray(QPainter * theQPainter,
873+
RasterViewPort * theRasterViewPort,
874+
QgsMapToPixel * theQgsMapToPixel,
875+
int theBandNoInt);
869876

870877
/** \brief Drawing routine for single band grayscale image, rendered in pseudocolor. */
871-
void drawSingleBandPseudoColor(QPainter * theQPainter, RasterViewPort * theRasterViewPort,int theBandNoInt);
878+
void drawSingleBandPseudoColor(QPainter * theQPainter,
879+
RasterViewPort * theRasterViewPort,
880+
QgsMapToPixel * theQgsMapToPixel,
881+
int theBandNoInt);
872882

873883

874884
//
@@ -877,43 +887,51 @@ public slots:
877887

878888
/** \brief Drawing routine for paletted image, rendered as a single band image in color. */
879889
void drawPalettedSingleBandColor(QPainter * theQPainter,
880-
RasterViewPort * theRasterViewPort,
881-
int theBandNoInt);
890+
RasterViewPort * theRasterViewPort,
891+
QgsMapToPixel * theQgsMapToPixel,
892+
int theBandNoInt);
882893

883894
/** \brief Drawing routine for paletted image, rendered as a single band image in grayscale. */
884895
void drawPalettedSingleBandGray(QPainter * theQPainter,
885-
RasterViewPort * theRasterViewPort,
886-
int theBandNoInt,
887-
QString theColorQString);
896+
RasterViewPort * theRasterViewPort,
897+
QgsMapToPixel * theQgsMapToPixel,
898+
int theBandNoInt,
899+
QString theColorQString);
888900

889901
/** \brief Drawing routine for paletted image, rendered as a single band image in pseudocolor. */
890902
void drawPalettedSingleBandPseudoColor(QPainter * theQPainter,
891-
RasterViewPort * theRasterViewPort,
892-
int theBandNoInt,
893-
QString theColorQString);
903+
RasterViewPort * theRasterViewPort,
904+
QgsMapToPixel * theQgsMapToPixel,
905+
int theBandNoInt,
906+
QString theColorQString);
894907

895908
/** \brief Drawing routine for paletted multiband image. */
896909
void drawPalettedMultiBandColor(QPainter * theQPainter,
897-
RasterViewPort * theRasterViewPort,
898-
int theBandNoInt);
910+
RasterViewPort * theRasterViewPort,
911+
QgsMapToPixel * theQgsMapToPixel,
912+
int theBandNoInt);
899913

900914
//
901915
// Multiband Layers
902916
//
903917

904918
/** \brief Drawing routine for multiband image, rendered as a single band image in grayscale. */
905919
void drawMultiBandSingleBandGray(QPainter * theQPainter,
906-
RasterViewPort * theRasterViewPort,
907-
int theBandNoInt);
920+
RasterViewPort * theRasterViewPort,
921+
QgsMapToPixel * theQgsMapToPixel,
922+
int theBandNoInt);
908923

909924
/** \brief Drawing routine for multiband image, rendered as a single band image in pseudocolor. */
910925
void drawMultiBandSingleBandPseudoColor(QPainter * theQPainter,
911-
RasterViewPort * theRasterViewPort,
912-
int theBandNoInt);
926+
RasterViewPort * theRasterViewPort,
927+
QgsMapToPixel * theQgsMapToPixel,
928+
int theBandNoInt);
913929

914930
/** \brief Drawing routine for multiband image */
915-
void drawMultiBandColor(QPainter * theQPainter, RasterViewPort * theRasterViewPort);
916-
931+
void drawMultiBandColor(QPainter * theQPainter,
932+
RasterViewPort * theRasterViewPort,
933+
QgsMapToPixel * theQgsMapToPixel);
934+
917935
/** \brief Read color table from GDAL raster band */
918936
void readColorTable ( GDALRasterBand *gdalBand, QgsColorTable *theColorTable );
919937

0 commit comments

Comments
 (0)
Please sign in to comment.