1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
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. *
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. *
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 ***************************************************************************/
21 * @file tcChannelDem.cpp
22 * @brief An abstract image channel which needs access to the digital elevation model.
25 #include "tcChannelDem.h"
26 #include "tcSrtmModel.h"
27 #include "tcGeoImageData.h"
30 * Constructors + destructor
33 /// Primary constructor.
34 tcChannelDem::tcChannelDem(tcSrtmModel
* dem
, tcGeoImageData
* imagery
, const QString
& name
, const QString
& description
, bool depend1
, bool depend2
)
35 : tcChannel(name
, description
)
41 connect(dem
, SIGNAL(dataSetChanged()), this, SLOT(invalidate()));
45 connect(dem
+1, SIGNAL(dataSetChanged()), this, SLOT(invalidate()));
50 tcChannelDem::~tcChannelDem()
55 * Interface for derived classes to access elevation model data
58 // Main transformation
60 /// Get the geographical coordinate at a pixel.
61 tcGeo
tcChannelDem::geoAt(const maths::Vector
<2,float>& textureCoordinate
, tcGeoImageData
* imagery
) const
67 return (tcGeo
)(imagery
->texToGeo() * (maths::Vector
<2,double>)textureCoordinate
);
70 /// Get the texture coordinate at a geographical coordinate.
71 maths::Vector
<2,float> tcChannelDem::textureAt(const tcGeo
& geoCoordinate
, tcGeoImageData
* imagery
) const
77 return (maths::Vector
<2,float>)(imagery
->geoToTex() * geoCoordinate
);
82 /// Get the altitude at a geographical coordinate.
83 float tcChannelDem::altitudeAt(const tcGeo
& coordinate
, bool corrected
, bool* accurate
) const
85 return m_dem
->altitudeAt(coordinate
, corrected
, accurate
);
88 /// Get the texture-space normal vector at a geographical coordinate.
89 maths::Vector
<3,float> tcChannelDem::normalAt(const tcGeo
& coordinate
, bool corrected
, bool* accurate
) const
91 return m_dem
->normalAt(coordinate
, corrected
, accurate
);
94 /// Get the lighting direction vector at a geographical coordinate.
95 maths::Vector
<3,float> tcChannelDem::lightDirectionAt(const tcGeo
& coordinate
, tcGeoImageData
* imagery
) const
101 return imagery
->sunDirection(coordinate
);
104 /// Find whether a point is lit by the light.
105 bool tcChannelDem::isLitAt(const tcGeo
& coordinate
, bool corrected
, bool* accurate
, tcGeoImageData
* imagery
) const
107 return m_dem
->litAt(coordinate
, lightDirectionAt(coordinate
, imagery
), 0.0f
, corrected
, accurate
) > 0.5f
;
110 /// Find how lit a point is by the light.
111 float tcChannelDem::litAt(const tcGeo
& coordinate
, bool corrected
, bool* accurate
, tcGeoImageData
* imagery
) const
113 // Sun is half a degree in the sky
114 static const float sunSize
= 0.25f
* M_PI
/ 180.0f
;
115 return m_dem
->litAt(coordinate
, lightDirectionAt(coordinate
, imagery
), sunSize
, corrected
, accurate
);
118 // Lower level accessors
120 /// Get the digital elevation model.
121 tcSrtmModel
* tcChannelDem::dem() const
127 tcGeoImageData
* tcChannelDem::imagery() const