Snapshotting and loading
[tecorrec.git] / geo / tcChannel.cpp
bloba2c3ccae33ad54e9aa510e3614e57391de5e0d1c
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)
51 /// Destructor.
52 tcChannel::~tcChannel()
57 * Metadata
60 /// Get the channel manager.
61 tcChannelManager* tcChannel::channelManager() const
63 return m_channelManager;
66 /// Set the channel manager.
67 void tcChannel::setChannelManager(tcChannelManager* channelManager)
69 m_channelManager = channelManager;
72 /// Get the channel name.
73 const QString& tcChannel::name() const
75 return m_name;
78 /// Get the channel description;
79 const QString& tcChannel::description() const
81 return m_description;
84 /// Set the channel name.
85 void tcChannel::setName(const QString& name)
87 m_name = name;
90 /// Set the channel description.
91 void tcChannel::setDescription(const QString& description)
93 m_description = description;
96 /// Set radiance offset and gain.
97 void tcChannel::setRadianceTransform(float offset, float gain)
99 m_radianceOffset = offset;
100 m_radianceGain = gain;
104 * Dependencies
107 /// Add derivitive of this channel.
108 void tcChannel::addDerivitive(tcChannel* derivitive)
110 m_derivitives += derivitive;
113 /// Remove a derivitive of this channel.
114 void tcChannel::removeDerivitive(tcChannel* derivitive)
116 m_derivitives.removeOne(derivitive);
120 * Main image interface
123 /// Get configuration widget.
124 tcChannelConfigWidget* tcChannel::configWidget()
126 return 0;
129 /// Get GL texture ID of thumbnail of the channel.
130 GLuint tcChannel::thumbnailTexture()
132 return 0;
135 /// Get a reference to the pixel data of the current portion of the image.
136 Reference<tcAbstractPixelData> tcChannel::portion() const
138 return m_portion;
141 /// Get a reference to the pixel data of a portion of the image.
142 Reference<tcAbstractPixelData> tcChannel::portion(double* x1, double* y1, double* x2, double* y2)
144 // If the portion is out of date, remove it
145 roundPortion(x1,y1,x2,y2);
146 bool changed = false;
147 if (0 != m_portion)
149 if (m_portionPosition[0][0] != *x1 ||
150 m_portionPosition[0][1] != *y1 ||
151 m_portionPosition[1][0] != *x2 ||
152 m_portionPosition[1][1] != *y2)
154 m_portion = 0;
155 changed = true;
158 m_portionPosition[0][0] = *x1;
159 m_portionPosition[0][1] = *y1;
160 m_portionPosition[1][0] = *x2;
161 m_portionPosition[1][1] = *y2;
162 // Create the new portion
163 if (0 == m_portion)
165 m_portion = loadPortion(*x1,*y1,*x2,*y2, changed);
167 return m_portion;
170 /// Get a reference to the pixel data of a portion of the image.
171 Reference<tcAbstractPixelData> tcChannel::portion(double x1, double y1, double x2, double y2)
173 return portion(&x1, &y1, &x2, &y2);
176 /// Get GL texture ID of portion of the channel.
177 GLuint tcChannel::portionTexture(double* x1, double* y1, double* x2, double* y2)
179 Reference<tcAbstractPixelData> data = portion(x1,y1,x2,y2);
180 if (0 != data)
182 return data->texture();
184 else
186 return 0;
190 /// Get the last portion position.
191 const double* tcChannel::portionPosition() const
193 return &m_portionPosition[0][0];
197 * Interface for derived classes
200 /// Invalidate this channel.
201 void tcChannel::invalidate()
203 m_portion = 0;
204 foreach (tcChannel* derivitive, m_derivitives)
206 derivitive->invalidate();
211 * Progress functions
214 /// Start a processing step.
215 void tcChannel::startProcessing(const QString& step)
217 if (step.isEmpty())
219 s_processingStep = step;
221 else
223 s_processingStep = step + ": ";
225 s_processingLastPercent = -1;
226 emit progressing(tr("%1: %2").arg(name()).arg(s_processingStep));
229 /// Update progress.
230 void tcChannel::progress(float progress)
232 int percent = progress*100.0f;
233 if (percent != s_processingLastPercent)
235 s_processingLastPercent = percent;
236 emit progressing(tr("%1: %2%3%").arg(name()).arg(s_processingStep).arg(percent));
240 /// Update progress.
241 void tcChannel::progress(const QString& info)
243 emit progressing(tr("%1: %2%3").arg(name()).arg(s_processingStep).arg(info));
246 /// End processing step.
247 void tcChannel::endProcessing()
249 emit progressing(tr("%1: %2Complete").arg(name()).arg(s_processingStep));