New elevation channel, showing voids
[tecorrec.git] / geo / tcElevation.cpp
blobec6123c8e24705148204c59644beaac5fd7d35f5
1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file tcElevation.cpp
22 * @brief Elevation map including void highlighting.
25 #include "tcElevation.h"
28 * Constructors + destructor
31 /// Primary constructor.
32 tcElevation::tcElevation(tcChannel* reference, tcSrtmModel* dem, tcGeoImageData* imagery)
33 : tcChannelDem(dem, imagery,
34 tr("Elevation"),
35 tr("Straight forward elevation."))
36 , m_referenceChannel(reference)
40 /// Destructor.
41 tcElevation::~tcElevation()
46 * Interface for derived class to implement
49 void tcElevation::roundPortion(double* x1, double* y1, double* x2, double* y2)
51 m_referenceChannel->roundPortion(x1,y1,x2,y2);
54 tcAbstractPixelData* tcElevation::loadPortion(double x1, double y1, double x2, double y2)
56 Reference<tcAbstractPixelData> channelData = m_referenceChannel->loadPortion(x1, y1, x2, y2);
57 int width = channelData->width();
58 int height = channelData->height();
60 // Create a new pixel buffer
61 tcPixelData<float>* data = new tcPixelData<float>(width, height);
62 startProcessing("Sampling elevation data");
63 for (int j = 0; j < height; ++j)
65 progress((float)j/(height-1));
66 for (int i = 0; i < width; ++i)
68 int index = j*width + i;
69 // Transform coordinates
70 maths::Vector<2,float> coord ( x1 + (x2-x1)*i / (width - 1),
71 1.0f - y1 - (y2-y1)*j / (height - 1));
72 tcGeo geoCoord = geoAt(coord);
74 // Get some elevation data
75 bool accurate;
76 float altitude = altitudeAt(geoCoord, false, &accurate);
77 if (!accurate)
79 altitude = 0.0f;
81 data->buffer()[index] = altitude/4000.0f;
84 endProcessing();
85 return data;