34#ifndef AIMS_UTILITY_CHANNEL_H
35#define AIMS_UTILITY_CHANNEL_H
38#include <cartobase/type/types.h>
39#include <cartobase/type/string_conversion.h>
40#include <cartobase/type/datatypetraits.h>
41#include <cartobase/type/datatypeinfo.h>
44#include <cartodata/volume/volume.h>
45#include <cartobase/type/converter.h>
62#define DECLARE_CHANNEL_SELECTOR_NAME() \
63class ChannelSelector \
66#define DECLARE_CHANNEL_SELECTOR_SPEC( T, U, C ) \
69 ChannelSelector() {} \
70 virtual ~ChannelSelector() {} \
72 U select( const T& input, const uint8_t channel ); \
73 void set( T& input, const uint8_t channel, const U& value ); \
76 carto::ShallowConverter<U, C> channelconvset; \
77 carto::ShallowConverter<C, U> channelconv; \
78 carto::ShallowConverter<T, U> dataconv; \
82#define DECLARE_CHANNEL_SELECTOR_CLASS() \
83template <class T, class U, class C = byte > \
84DECLARE_CHANNEL_SELECTOR_NAME() \
85DECLARE_CHANNEL_SELECTOR_SPEC( T, U, C ) \
88#define DECLARE_CHANNEL_SELECTOR_SPECIALIZED( T ) \
90DECLARE_CHANNEL_SELECTOR_NAME() < T, U > \
91DECLARE_CHANNEL_SELECTOR_SPEC( T, U, byte ) \
109template <class T, class U>
121template <
class T,
class U,
class C>
inline
122U ChannelSelector< T, U, C >::select(
const T& input,
const uint8_t )
127template <
class T,
class U,
class C>
inline
128void ChannelSelector< T, U, C >::set( T& input,
const uint8_t,
const U& value )
133template <
class U>
inline
134U ChannelSelector< AimsRGB, U >::select(
const AimsRGB& input,
const uint8_t channel )
140 channelconv.convert( input.
red(), output );
143 channelconv.convert( input.
green(), output );
146 channelconv.convert( input.
blue(), output );
149 dataconv.convert( input, output );
154template <
class U>
inline
155void ChannelSelector< AimsRGB, U >::set(
AimsRGB& input,
const uint8_t channel,
const U& value )
159 channelconvset.convert( value, input.
red() );
162 channelconvset.convert( value, input.
green() );
165 channelconvset.convert( value, input.
blue() );
170template <
class U>
inline
171U ChannelSelector< AimsRGBA, U >::select(
const AimsRGBA& input,
const uint8_t channel )
177 channelconv.convert( input.
red(), output );
180 channelconv.convert( input.
green(), output );
183 channelconv.convert( input.
blue(), output );
186 channelconv.convert( input.
alpha(), output );
189 dataconv.convert( input, output );
195template <
class U>
inline
196void ChannelSelector< AimsRGBA, U >::set(
AimsRGBA& input,
const uint8_t channel,
const U& value )
200 channelconvset.convert( value, input.
red() );
203 channelconvset.convert( value, input.
green() );
206 channelconvset.convert( value, input.
blue() );
209 channelconvset.convert( value, input.
alpha() );
214template <
class U>
inline
215U ChannelSelector< AimsHSV, U >::select(
const AimsHSV& input,
const uint8_t channel )
221 channelconv.convert( input.
hue(), output );
224 channelconv.convert( input.
saturation(), output );
227 channelconv.convert( input.
value(), output );
230 dataconv.convert( input, output );
238template <
class U>
inline
239void ChannelSelector< AimsHSV, U >::set(
AimsHSV& input,
const uint8_t channel,
const U& value )
243 channelconvset.convert( value, input.
hue() );
246 channelconvset.convert( value, input.
saturation() );
249 channelconvset.convert( value, input.
value() );
256template <
typename T,
int D,
typename U>
273template <
typename T,
int D,
typename U>
276 const uint8_t channel )
280 channelconv.convert( input[channel], output );
284template <
typename T,
int D,
typename U>
286 const uint8_t channel,
289 channelconvset.convert( value, input[channel] );
295template<
class T,
class U>
inline
297ChannelSelector< carto::VolumeRef<T>,
299 const uint8_t channel )
316 for( t=-b[6]; t<dt+b[6]; ++t )
318 for( z=-b[4]; z<dz+b[4]; ++z )
320 for( y=-b[2]; y<dy+b[2]; ++y )
322 for( x=-b[0]; x<dx+b[0]; ++x )
323 output( x, y, z, t ) = selector.select( input( x, y, z, t ), channel );
332template<
class T,
class U>
inline
333void ChannelSelector< carto::VolumeRef<T>,
335 const uint8_t channel,
346 for( t=0; t<dt; ++t )
348 for( z=0; z<dz; ++z )
350 for( y=0; y<dy; ++y )
352 for( x=0; x<dx; ++x )
353 selector.set( input( x, y, z, t ),
355 value( x, y, z, t ) );
#define DECLARE_CHANNEL_SELECTOR_CLASS()
#define DECLARE_CHANNEL_SELECTOR_SPECIALIZED(T)
U select(const AimsVector< T, D > &input, const uint8_t channel)
virtual ~ChannelSelector()
void set(AimsVector< T, D > &input, const uint8_t channel, const U &value)
virtual ~ChannelSelector()
void set(carto::VolumeRef< T > &input, const uint8_t channel, const carto::VolumeRef< U > &value)
carto::VolumeRef< U > select(const carto::VolumeRef< T > &input, const uint8_t channel)
void setProperty(const std::string &, const T &)
std::vector< int > getBorders() const
virtual void copyHeaderFrom(const PropertySet &other)
const PropertySet & header() const
Volume< T >::Position4Di Position4Di
const uint8_t & saturation() const
const uint8_t & value() const
const uint8_t & hue() const
const uint8_t & alpha() const
const uint8_t & blue() const
const uint8_t & red() const
const uint8_t & green() const
const uint8_t & red() const
const uint8_t & green() const
const uint8_t & blue() const
carto::VoxelRGBA AimsRGBA