Basic incomplete illuminant direction processing including shadow free chromaticities...
[tecorrec.git] / geo / tcChannelGroup.cpp
blob7cef9a7a3b3d62f20f76aec752b66add05b4143e
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 tcChannelGroup.cpp
22 * @brief A group of linked channels.
25 #include "tcChannelGroup.h"
26 #include "tcChannel.h"
28 /// Our custom channel group member class.
29 class tcChannelGroup::Channel : public tcChannel
31 public:
34 * Constructors + destructor
37 /// Primary constructor.
38 Channel(tcChannelGroup* group, int index)
39 : tcChannel(QString(), QString())
40 , m_group(group)
41 , m_index(index)
45 /// Destructor
46 virtual ~Channel()
50 protected:
53 * Interface for derived class to implement
56 // Reimplemented
57 virtual tcChannelConfigWidget* configWidget()
59 return m_group->configWidget();
62 // Reimplemented
63 virtual void roundPortion(double* x1, double* y1, double* x2, double* y2)
65 m_group->roundPortion(x1, y1, x2, y2);
68 // Reimplemented
69 virtual tcAbstractPixelData* loadPortion(double x1, double y1, double x2, double y2)
71 return m_group->portion(m_index, x1, y1, x2, y2);
74 private:
77 * Variables
80 /// Group of channels.
81 tcChannelGroup* m_group;
83 /// Index of this channel in m_group.
84 int m_index;
88 * Constructors + destructor
91 /// Primary constructor.
92 tcChannelGroup::tcChannelGroup(int channels, const QString& name, const QString& description)
93 : m_name(name)
94 , m_description(description)
96 for (int i = 0; i < channels; ++i)
98 Channel* channel = new Channel(this, i);
99 m_channels << channel;
103 /// Destructor.
104 tcChannelGroup::~tcChannelGroup()
106 foreach (tcChannel* channel, m_channels)
108 delete channel;
113 * Metadata
116 /// Get the channel name.
117 const QString& tcChannelGroup::name() const
119 return m_name;
122 /// Get the channel description;
123 const QString& tcChannelGroup::description() const
125 return m_description;
128 /// Set the channel name.
129 void tcChannelGroup::setName(const QString& name)
131 m_name = name;
134 /// Set the channel description.
135 void tcChannelGroup::setDescription(const QString& description)
137 m_description = description;
141 * Main image interface
144 /// Get the list of output channels.
145 const QList<tcChannel*>& tcChannelGroup::channels() const
147 return m_channels;
150 /// Get configuration widget.
151 tcChannelConfigWidget* tcChannelGroup::configWidget()
153 return 0;
156 /// Get a reference to the pixel data of a portion of one of the output channels.
157 Reference<tcAbstractPixelData> tcChannelGroup::portion(int channel, double x1, double y1, double x2, double y2)
159 // If the portion is out of date, remove it
160 if (0 != m_portions.size())
162 if (m_portionPosition[0][0] != x1 ||
163 m_portionPosition[0][1] != y1 ||
164 m_portionPosition[1][0] != x2 ||
165 m_portionPosition[1][1] != y2)
167 m_portions.clear();
170 m_portionPosition[0][0] = x1;
171 m_portionPosition[0][1] = y1;
172 m_portionPosition[1][0] = x2;
173 m_portionPosition[1][1] = y2;
174 // Create the new portions
175 if (0 == m_portions.size())
177 loadPortions(x1,y1,x2,y2);
179 // Return just the requested channel
180 if (channel >= 0 && channel < m_portions.size())
182 return m_portions[channel];
184 else
186 return 0;
191 * Interface for derived class to implement
194 /// Round coordinates to sensible values.
195 void tcChannelGroup::roundPortion(double* x1, double* y1, double* x2, double* y2)
199 /// Load portions of pixel data for each output channel.
200 void tcChannelGroup::loadPortions(double x1, double y1, double x2, double y2)
205 * Interface for derived classes
208 /// Invalidate this channel.
209 void tcChannelGroup::invalidate()
211 m_portions.clear();
212 foreach (tcChannel* channel, m_channels)
214 channel->invalidate();
218 /// Revalidate the channel, indicating that the data has changed.
219 void tcChannelGroup::revalidate()