Made it possible to display normals in output channels 4-6 (A,B,C)
[tecorrec.git] / geo / tcNormals.cpp
blobe6fcbdc79bc85dfae15369e34d04910cce58db18
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 tcNormals.cpp
22 * @brief Normal map from elevation data.
25 #include "tcNormals.h"
26 #include "tcGeoImageData.h"
29 * Constructors + destructor
32 /// Primary constructor.
33 tcNormals::tcNormals(const tcGeoImageData* refImagery, tcChannel* reference, tcSrtmModel* dem, tcGeoImageData* imagery)
34 : tcChannelDem(dem, imagery,
35 tr("Normals"),
36 tr("Normals from elevation data."))
37 , m_referenceChannel(reference)
38 , m_refTransform(imagery->texToGeo() * refImagery->geoToTex())
42 /// Destructor.
43 tcNormals::~tcNormals()
48 * Interface for derived class to implement
51 void tcNormals::roundPortion(double* x1, double* y1, double* x2, double* y2)
53 //m_referenceChannel->roundPortion(x1,y1,x2,y2);
56 tcAbstractPixelData* tcNormals::loadPortion(double x1, double y1, double x2, double y2, bool changed)
58 maths::Vector<2,double> xy1 = m_refTransform * maths::Vector<2,double>(x1,y1);
59 maths::Vector<2,double> xy2 = m_refTransform * maths::Vector<2,double>(x2,y2);
60 Reference<tcAbstractPixelData> channelData = m_referenceChannel->loadPortion(xy1[0], xy1[1], xy2[0], xy2[1], changed);
61 int width = channelData->width();
62 int height = channelData->height();
64 // Create a new pixel buffer
65 tcTypedPixelData<maths::Vector<3,float> >* data = new tcTypedPixelData<maths::Vector<3,float> >(width, height);
66 startProcessing("Sampling elevation data");
67 int index = 0;
68 for (int j = 0; j < height; ++j)
70 progress((float)j/(height-1));
71 for (int i = 0; i < width; ++i)
73 // Transform coordinates
74 maths::Vector<2,float> coord(x1 + (x2-x1)*i / (width - 1),
75 y1 + (y2-y1)*j / (height - 1));
76 tcGeo geoCoord = geoAt(coord);
78 // Get some elevation data
79 bool accurate;
80 maths::Vector<3,float> normal = normalAt(geoCoord, false, &accurate);
81 data->buffer()[index] = normal;
82 ++index;
85 endProcessing();
86 return data;