#include <ChannelPack.h>
Public Member Functions | |
ChannelPack () | |
Default ctor is an empty set. | |
ChannelPack (const ChannelSet &channels) | |
Construct from a ChannelSet. Channel order will be identical to using a for loop. | |
ChannelPack (Channel chan) | |
Construct from a single Channel. | |
operator ChannelSet () const | |
Convert back to a ChannelSet. | |
uint32_t | size () const |
bool | empty () const |
void | clear () |
Channel | operator[] (uint32_t i) const |
Read/write access to channel indices. | |
Channel & | operator[] (uint32_t i) |
const Channel * | begin () const |
const Channel * | end () const |
Channel * | array () |
Access to entire Channel array. | |
ChannelPack & | operator= (const ChannelSet &channels) |
Assign from a ChannelSet. | |
ChannelPack & | operator+= (const ChannelSet &channels) |
Append channels from a ChannelSet. Duplicate Channels are skipped. | |
ChannelPack & | operator+= (Channel chan) |
Append a single Channel. Duplicate Channels are skipped. | |
void | set (const ChannelSet &channels) |
Assign from a ChannelSet. | |
void | set (Channel chan) |
Assign from a single Channel. | |
void | add (const ChannelSet &channels, bool deduplicate=true) |
void | add (Channel chan, bool deduplicate=true) |
Protected Attributes | |
Channel | _idx [Chan_Last+1] |
Array of Channel indices. | |
uint32_t | _nChans |
Number of assigned indices. | |
Helper class for doing faster iterative lookups of channels within a ChannelSet and avoid iterating the ChannelSet, which can be slow.
The channels are packed so that the first Channel in the list is at _idx[0] and the last Channel is at _idx[_nChans-1]. The Channel index list is a fixed-size array to save on new/delete cost of a std::vector and to keep this class POD.
When constructing or adding from a ChannelSet the Channels will be packed in numerical order, so iterating through this array will usually match iterating through a ChannelSet via a for loop. However if multiple channel adds have been done they are appended serially to the end of the list and not kept in sorted Channel order. In those cases Chan_Alpha could come before Chan_Red. For most channel loops the order of the channels is usually moot.
Note that while 'Mask_None' is trivially handled if the array size is zero, 'Mask_All' is NOT specially handled and the entire array would need to be completely filled up to Chan_Last.
The assumption is that, like Pixel, this class will be used in pixel processing loops and not used for storage of ChannelSets, which are more compact.
|
inline |
Add channels from a ChannelSet. If deduplicate is true duplicate Channels are skipped but this method is slightly more expensive to calculate.
Note that use of this method can cause the channel iteration order to no longer match a ChannelSet. ie it's possible to have Chan_Alpha process before Chan_Red if Chan_Alpha is added first, then Chan_Red.
References _idx, _nChans, and DD::Image::ChannelSet::contains().
|
inline |
Add a single Channel. If deduplicate is true the Channel will be skipped if it's already in the array but this method is slightly more expensive to calculate.
Note that use of this method can cause the channel iteration order to no longer match a ChannelSet. ie it's possible to have Chan_Alpha process before Chan_Red if Chan_Alpha is added first, then Chan_Red.
References _idx, _nChans, and DD::Image::ChannelSet::contains().
©2024 The Foundry Visionmongers, Ltd. All Rights Reserved. |