Permalink
Browse files

Added x-resolution functionality in AnalysisMap

  • Loading branch information...
1 parent 0be21f1 commit a11c35249bcb6a46b80ebd00f3e555f272db9bfc @dankrusi committed Apr 23, 2012
Showing with 28 additions and 49 deletions.
  1. +22 −44 src/AnalysisMap.cpp
  2. +1 −0 src/AnalysisMap.h
  3. +2 −4 src/SpatialAnalysisMap.cpp
  4. +3 −1 src/SpatialAnalysisMap.h
View
@@ -45,6 +45,7 @@ void AnalysisMap::load() {
_tileSize = _dataMap->tileSize();
_tilesX = _dataMap->tilesX();
_tilesY = _dataMap->tilesY();
+ _resolution = 1; // Must be divisor of tile size
// Create tile objects
createTiles();
@@ -58,54 +59,31 @@ void AnalysisMap::loadTileImage(int tileX, int tileY, QImage &image) {
image = QImage(this->tileSize(),this->tileSize(),QImage::Format_ARGB32);
// Scan image lines...
- for (int y = 0; y < image.height(); ++y) {
+ double score = 0;
+ int tileSize = _dataMap->tileSize();
+ int res = _resolution;
+ for (int y = 0; y < image.height(); y++) {
QRgb *row = (QRgb*)image.scanLine(y);
- for (int x = 0; x < image.width(); ++x) {
+ for (int x = 0; x < image.width(); x=x+res) {
- // Grab score
- int xx = tileX*_dataMap->tileSize() + x;
- int yy = tileY*_dataMap->tileSize() + y;
- double score = calculateScoreForPixel(xx,yy);
- if(score < 0) score = 0;
- if(score > 1) score = 1;
-
- // Alter pixels of image directly
- unsigned char scoreByte = score*255;
- ((unsigned char*)&row[x])[0] = 0; // B
- ((unsigned char*)&row[x])[1] = 0; // G
- ((unsigned char*)&row[x])[2] = scoreByte; // R
- ((unsigned char*)&row[x])[3] = 255; // A
- }
- }
-
-
- // Old code:
-
- /*
- // Create image
- image = QImage(this->tileSize(),this->tileSize(),QImage::Format_ARGB32);
- image.fill(Qt::transparent);
-
- // Paint it according to score
- QPainter painter;
- painter.begin(&image);
-
- for(int x = 0; x < image.width(); x++) {
- for(int y = 0; y < image.width(); y++) {
- int xx = tileX*_dataMap->tileSize() + x;
- int yy = tileY*_dataMap->tileSize() + y;
- double score = calculateScoreForPoint(xx,yy);
+ // Grab score
+ int xx = tileX*tileSize + x;
+ int yy = tileY*tileSize + y;
+ score = calculateScoreForPixel(xx,yy);
if(score < 0) score = 0;
- if(score > 1) score = 1;
- int scoreByte = score * 255;
- scoreByte = 0;
- painter.setPen(qRgba(200,200,200,50));
- //painter.setPen(Qt::red);
- painter.drawRect(x,y,1,1);
- }
+ else if(score > 1) score = 1;
+
+ // Loop over resx
+ for(int resx = 0; resx < res; resx++) {
+ // Alter pixels of image directly
+ unsigned char scoreByte = score*255;
+ ((unsigned char*)&row[x+resx])[0] = 0; // B
+ ((unsigned char*)&row[x+resx])[1] = 0; // G
+ ((unsigned char*)&row[x+resx])[2] = scoreByte; // R
+ ((unsigned char*)&row[x+resx])[3] = 255; // A
+ }
+ }
}
- painter.end();
- */
}
View
@@ -36,6 +36,7 @@ Q_OBJECT
private:
DataMap *_dataMap;
+ int _resolution;
public:
explicit AnalysisMap(DataMap *dataMap, QSettings *settings, QObject *parent = 0);
@@ -35,15 +35,13 @@ SpatialAnalysisMap::SpatialAnalysisMap(ElevationDataMap *elevationDataMap, QSett
_name = "Spatial Analysis";
_elevationDataMap = elevationDataMap;
_range = 10;
+ _heightTolerance = 300; // Set tolerance of what is an acceptable height difference (in meters)
}
double SpatialAnalysisMap::calculateScoreForPixel(int x, int y) {
//if(x%2==0 || y%2==0) return 0; // Use this for quick testing...
- // Set tolerance of what is an acceptable height difference (in meters)
- double heightTolerance = 300;
-
// Counter for acceptable points
int goodPoints = 0;
@@ -54,7 +52,7 @@ double SpatialAnalysisMap::calculateScoreForPixel(int x, int y) {
for (y0 = -_range; y0 < _range+1; y0++) {
// Find difference in elevation to current point
// If difference < tolerance ==> it's a good point
- if ( qAbs(_elevationDataMap->getElevationAtPoint(x-x0,y-y0) - elevationAtXY ) < heightTolerance ) {
+ if ( qAbs(_elevationDataMap->getElevationAtPoint(x-x0,y-y0) - elevationAtXY ) < _heightTolerance ) {
goodPoints += 1;
}
}
@@ -38,6 +38,7 @@ class SpatialAnalysisMap : public AnalysisMap
protected:
ElevationDataMap *_elevationDataMap;
int _range;
+ double _heightTolerance;
public:
explicit SpatialAnalysisMap(ElevationDataMap *elevationDataMap, QSettings *settings, QObject *parent = 0);
@@ -53,7 +54,8 @@ class LargeSpatialAnalysisMap : public SpatialAnalysisMap
{
// Init
_name = "Large Spatial Analysis";
- _range = 20;
+ _range = 30;
+ _heightTolerance = 300;
}
};

0 comments on commit a11c352

Please sign in to comment.