Final changes before project hand-in
[tecorrec.git] / geo / tcChannel.cpp
blob0fe871b036b01ad19831001ce0b74ba8449654db
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 tcChannel.cpp
22 * @brief A single abstract image channel.
25 #include "tcChannel.h"
28 * Static variables
31 /// Current processing step.
32 QString tcChannel::s_processingStep;
34 /// Last progress percent.
35 int tcChannel::s_processingLastPercent;
38 * Constructors + destructor
41 /// Primary constructor.
42 tcChannel::tcChannel(const QString& name, const QString& description)
43 : m_channelManager(0)
44 , m_name(name)
45 , m_description(description)
46 , m_radianceOffset(0.0f)
47 , m_radianceGain(1.0f)
48 , m_crossSectioned(false)
52 /// Destructor.
53 tcChannel::~tcChannel()
58 * Metadata
61 /// Get the channel manager.
62 tcChannelManager* tcChannel::channelManager() const
64 return m_channelManager;
67 /// Set the channel manager.
68 void tcChannel::setChannelManager(tcChannelManager* channelManager)
70 m_channelManager = channelManager;
73 /// Get the channel name.
74 const QString& tcChannel::name() const
76 return m_name;
79 /// Get the channel description;
80 const QString& tcChannel::description() const
82 return m_description;
85 /// Set the channel name.
86 void tcChannel::setName(const QString& name)
88 m_name = name;
91 /// Set the channel description.
92 void tcChannel::setDescription(const QString& description)
94 m_description = description;
97 /// Set radiance offset and gain.
98 void tcChannel::setRadianceTransform(float offset, float gain)
100 m_radianceOffset = offset;
101 m_radianceGain = gain;
104 /// New cross section selected.
105 void tcChannel::newCrossSection(const tcGeo& p1, const tcGeo& p2)
107 m_crossSectioned = true;
108 m_crossSection[0] = p1;
109 m_crossSection[1] = p2;
113 * Dependencies
116 /// Add derivitive of this channel.
117 void tcChannel::addDerivitive(tcChannel* derivitive)
119 m_derivitives += derivitive;
122 /// Remove a derivitive of this channel.
123 void tcChannel::removeDerivitive(tcChannel* derivitive)
125 m_derivitives.removeOne(derivitive);
129 * Main image interface
132 /// Get configuration widget.
133 tcChannelConfigWidget* tcChannel::configWidget()
135 return 0;
138 /// Get GL texture ID of thumbnail of the channel.
139 GLuint tcChannel::thumbnailTexture()
141 return 0;
144 /// Get a reference to the pixel data of the current portion of the image.
145 Reference<tcAbstractPixelData> tcChannel::portion() const
147 return m_portion;
150 /// Get a reference to the pixel data of a portion of the image.
151 Reference<tcAbstractPixelData> tcChannel::portion(double* x1, double* y1, double* x2, double* y2)
153 // If the portion is out of date, remove it
154 roundPortion(x1,y1,x2,y2);
155 bool changed = false;
156 if (0 != m_portion)
158 if (m_portionPosition[0][0] != *x1 ||
159 m_portionPosition[0][1] != *y1 ||
160 m_portionPosition[1][0] != *x2 ||
161 m_portionPosition[1][1] != *y2)
163 m_portion = 0;
164 changed = true;
167 m_portionPosition[0][0] = *x1;
168 m_portionPosition[0][1] = *y1;
169 m_portionPosition[1][0] = *x2;
170 m_portionPosition[1][1] = *y2;
171 // Create the new portion
172 if (0 == m_portion)
174 m_portion = loadPortion(*x1,*y1,*x2,*y2, changed);
176 return m_portion;
179 /// Get a reference to the pixel data of a portion of the image.
180 Reference<tcAbstractPixelData> tcChannel::portion(double x1, double y1, double x2, double y2)
182 return portion(&x1, &y1, &x2, &y2);
185 /// Get GL texture ID of portion of the channel.
186 GLuint tcChannel::portionTexture(double* x1, double* y1, double* x2, double* y2)
188 Reference<tcAbstractPixelData> data = portion(x1,y1,x2,y2);
189 if (0 != data)
191 return data->texture();
193 else
195 return 0;
199 /// Get the last portion position.
200 const double* tcChannel::portionPosition() const
202 return &m_portionPosition[0][0];
206 * Interface for derived classes
209 /// Invalidate this channel.
210 void tcChannel::invalidate()
212 m_portion = 0;
213 foreach (tcChannel* derivitive, m_derivitives)
215 derivitive->invalidate();
220 * Progress functions
223 /// Start a processing step.
224 void tcChannel::startProcessing(const QString& step)
226 if (step.isEmpty())
228 s_processingStep = step;
230 else
232 s_processingStep = step + ": ";
234 s_processingLastPercent = -1;
235 emit progressing(tr("%1: %2").arg(name()).arg(s_processingStep));
238 /// Update progress.
239 void tcChannel::progress(float progress)
241 int percent = progress*100.0f;
242 if (percent != s_processingLastPercent)
244 s_processingLastPercent = percent;
245 emit progressing(tr("%1: %2%3%").arg(name()).arg(s_processingStep).arg(percent));
249 /// Update progress.
250 void tcChannel::progress(const QString& info)
252 emit progressing(tr("%1: %2%3").arg(name()).arg(s_processingStep).arg(info));
255 /// End processing step.
256 void tcChannel::endProcessing()
258 emit progressing(tr("%1: %2Complete").arg(name()).arg(s_processingStep));