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 ***************************************************************************/
22 * @brief A single abstract image channel.
25 #include "tcChannel.h"
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
)
45 , m_description(description
)
46 , m_radianceOffset(0.0f
)
47 , m_radianceGain(1.0f
)
48 , m_crossSectioned(false)
53 tcChannel::~tcChannel()
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
79 /// Get the channel description;
80 const QString
& tcChannel::description() const
85 /// Set the channel name.
86 void tcChannel::setName(const QString
& 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
;
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()
138 /// Get GL texture ID of thumbnail of the channel.
139 GLuint
tcChannel::thumbnailTexture()
144 /// Get a reference to the pixel data of the current portion of the image.
145 Reference
<tcAbstractPixelData
> tcChannel::portion() const
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;
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
)
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
174 m_portion
= loadPortion(*x1
,*y1
,*x2
,*y2
, changed
);
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
);
191 return data
->texture();
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()
213 foreach (tcChannel
* derivitive
, m_derivitives
)
215 derivitive
->invalidate();
223 /// Start a processing step.
224 void tcChannel::startProcessing(const QString
& step
)
228 s_processingStep
= step
;
232 s_processingStep
= step
+ ": ";
234 s_processingLastPercent
= -1;
235 emit
progressing(tr("%1: %2").arg(name()).arg(s_processingStep
));
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
));
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
));