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 ***************************************************************************/
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
34 * Constructors + destructor
37 /// Primary constructor.
38 Channel(tcChannelGroup
* group
, int index
)
39 : tcChannel(QString(), QString())
53 * Interface for derived class to implement
57 virtual tcChannelConfigWidget
* configWidget()
59 return m_group
->configWidget();
63 virtual void roundPortion(double* x1
, double* y1
, double* x2
, double* y2
)
65 m_group
->roundPortion(x1
, y1
, x2
, y2
);
69 virtual tcAbstractPixelData
* loadPortion(double x1
, double y1
, double x2
, double y2
, bool changed
)
71 return m_group
->portion(m_index
, x1
, y1
, x2
, y2
, changed
);
80 /// Group of channels.
81 tcChannelGroup
* m_group
;
83 /// Index of this channel in m_group.
88 * Constructors + destructor
91 /// Primary constructor.
92 tcChannelGroup::tcChannelGroup(int channels
, const QString
& name
, const QString
& description
)
94 , m_description(description
)
96 for (int i
= 0; i
< channels
; ++i
)
98 Channel
* channel
= new Channel(this, i
);
99 m_channels
<< channel
;
104 tcChannelGroup::~tcChannelGroup()
106 foreach (tcChannel
* channel
, m_channels
)
116 /// Get the channel name.
117 const QString
& tcChannelGroup::name() const
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
)
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
150 /// Get configuration widget.
151 tcChannelConfigWidget
* tcChannelGroup::configWidget()
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
, bool changed
)
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
)
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
, changed
);
179 // Return just the requested channel
180 if (channel
>= 0 && channel
< m_portions
.size())
182 return m_portions
[channel
];
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
, bool changed
)
205 * Interface for derived classes
208 /// Invalidate this channel.
209 void tcChannelGroup::invalidate()
212 foreach (tcChannel
* channel
, m_channels
)
214 channel
->invalidate();