tcElevationOptimization::loadSnapShot: simplify reliability expression
[tecorrec.git] / geo / tcChannelChromaticity.cpp
blob937093012c965671f9362bd2ad2344da12ae8bca
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 tcChannelChromaticity.cpp
22 * @brief An image processing channel of the chromaticity between two channels.
25 #include "tcChannelChromaticity.h"
27 #include <QObject>
30 * Constructors + destructor
33 /// Primary constructor.
34 tcChannelChromaticity::tcChannelChromaticity(tcChannel* numerator, tcChannel* denominator)
35 : tcChannel(tr("Chromaticity(%1,%2)").arg(numerator->name()).arg(denominator->name()),
36 tr("Chromaticity (division) of the %1 and %2 channels").arg(numerator->name()).arg(denominator->name()))
37 , m_numerator(numerator)
38 , m_denominator(denominator)
40 m_numerator->addDerivitive(this);
41 m_denominator->addDerivitive(this);
44 /// Destructor.
45 tcChannelChromaticity::~tcChannelChromaticity()
47 m_numerator->removeDerivitive(this);
48 m_denominator->removeDerivitive(this);
52 * Interface for derived class to implement
55 void tcChannelChromaticity::roundPortion(double* x1, double* y1, double* x2, double* y2)
57 m_numerator->roundPortion(x1, y1, x2, y2);
60 tcAbstractPixelData* tcChannelChromaticity::loadPortion(double x1, double y1, double x2, double y2, bool changed)
62 Reference<tcPixelData<GLubyte> > numerator = dynamic_cast<tcPixelData<GLubyte>*>(m_numerator->loadPortion(x1, y1, x2, y2, changed));
63 Reference<tcPixelData<GLubyte> > denominator = dynamic_cast<tcPixelData<GLubyte>*>(m_denominator->loadPortion(x1, y1, x2, y2, changed));
65 tcPixelData<float>* data = 0;
66 if (0 != numerator && 0 != denominator)
68 int width = numerator->width();
69 int height = numerator->height();
70 data = new tcPixelData<float>(width, height);
71 for (int j = 0; j < height; ++j)
73 for (int i = 0; i < width; ++i)
75 int index = j*width + i;
76 GLubyte n = numerator->buffer()[index];
77 GLubyte d = denominator->sampleUByte((float)i/(width-1), (float)j/(height-1));
78 if (n != 0xff && d != 0xff && d != 0x00)
80 data->buffer()[index] = (float)n / d / 4;
82 else
84 data->buffer()[index] = 0.0f;
89 return data;