34 #ifndef AIMS_UTILITY_CHANNEL_H 35 #define AIMS_UTILITY_CHANNEL_H 62 #define DECLARE_CHANNEL_SELECTOR_NAME() \ 63 class 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() \ 83 template <class T, class U, class C = byte > \ 84 DECLARE_CHANNEL_SELECTOR_NAME() \ 85 DECLARE_CHANNEL_SELECTOR_SPEC( T, U, C ) \ 88 #define DECLARE_CHANNEL_SELECTOR_SPECIALIZED( T ) \ 90 DECLARE_CHANNEL_SELECTOR_NAME() < T, U > \ 91 DECLARE_CHANNEL_SELECTOR_SPEC( T, U, byte ) \ 109 template <class T, class U>
110 class ChannelSelector <
carto::VolumeRef<T>,
carto::VolumeRef<U> >
122 template <
class T,
class U>
134 template <
class T,
class U,
class C>
inline 135 U ChannelSelector< T, U, C >::select(
const T& input,
const uint8_t )
140 template <
class T,
class U,
class C>
inline 141 void ChannelSelector< T, U, C >::set( T& input,
const uint8_t,
const U& value )
146 template <
class U>
inline 147 U ChannelSelector< AimsRGB, U >::select(
const AimsRGB& input,
const uint8_t channel )
153 channelconv.convert( input.
red(), output );
156 channelconv.convert( input.
green(), output );
159 channelconv.convert( input.
blue(), output );
162 dataconv.convert( input, output );
167 template <
class U>
inline 168 void ChannelSelector< AimsRGB, U >::set(
AimsRGB& input,
const uint8_t channel,
const U& value )
172 channelconvset.convert( value, input.
red() );
175 channelconvset.convert( value, input.
green() );
178 channelconvset.convert( value, input.
blue() );
183 template <
class U>
inline 184 U ChannelSelector< AimsRGBA, U >::select(
const AimsRGBA& input,
const uint8_t channel )
190 channelconv.convert( input.
red(), output );
193 channelconv.convert( input.
green(), output );
196 channelconv.convert( input.
blue(), output );
199 channelconv.convert( input.
alpha(), output );
202 dataconv.convert( input, output );
208 template <
class U>
inline 209 void ChannelSelector< AimsRGBA, U >::set(
AimsRGBA& input,
const uint8_t channel,
const U& value )
213 channelconvset.convert( value, input.
red() );
216 channelconvset.convert( value, input.
green() );
219 channelconvset.convert( value, input.
blue() );
222 channelconvset.convert( value, input.
alpha() );
227 template <
class U>
inline 228 U ChannelSelector< AimsHSV, U >::select(
const AimsHSV& input,
const uint8_t channel )
234 channelconv.convert( input.
hue(), output );
237 channelconv.convert( input.
saturation(), output );
240 channelconv.convert( input.
value(), output );
243 dataconv.convert( input, output );
251 template <
class U>
inline 252 void ChannelSelector< AimsHSV, U >::set(
AimsHSV& input,
const uint8_t channel,
const U& value )
256 channelconvset.convert( value, input.
hue() );
259 channelconvset.convert( value, input.
saturation() );
262 channelconvset.convert( value, input.
value() );
269 template <
typename T,
int D,
typename U>
286 template <
typename T,
int D,
typename U>
289 const uint8_t channel )
293 channelconv.
convert( input[channel], output );
297 template <
typename T,
int D,
typename U>
299 const uint8_t channel,
302 channelconvset.convert( value, input[channel] );
308 template<
class T,
class U>
inline 310 ChannelSelector< carto::VolumeRef<T>,
312 const uint8_t channel )
314 ChannelSelector< T, U > selector;
329 for( t=-b[6]; t<dt+b[6]; ++t )
331 for( z=-b[4]; z<dz+b[4]; ++z )
333 for( y=-b[2]; y<dy+b[2]; ++y )
335 for( x=-b[0]; x<dx+b[0]; ++x )
336 output( x, y, z, t ) = selector.select( input( x, y, z, t ), channel );
344 template<
class T,
class U>
inline 347 const uint8_t channel )
363 template<
class T,
class U>
inline 364 void ChannelSelector< carto::VolumeRef<T>,
366 const uint8_t channel,
369 ChannelSelector<T, U> selector;
377 for( t=0; t<dt; ++t )
379 for( z=0; z<dz; ++z )
381 for( y=0; y<dy; ++y )
383 for( x=0; x<dx; ++x )
384 selector.set( input( x, y, z, t ),
386 value( x, y, z, t ) );
392 template<
class T,
class U>
inline 393 void ChannelSelector< AimsData<T>,
395 const uint8_t channel,
398 ChannelSelector< carto::VolumeRef<T>,
403 selector.set( volumeref,
const uint8_t & blue() const
virtual ~ChannelSelector()
const uint8_t & red() const
virtual void convert(const INP &in, OUTP &out) const
const PropertySet & header() const
virtual ~ChannelSelector()
#define DECLARE_CHANNEL_SELECTOR_SPECIALIZED(T)
#define DECLARE_CHANNEL_SELECTOR_CLASS()
Volume< T >::Position4Di Position4Di
const uint8_t & hue() const
const uint8_t & alpha() const
const uint8_t & value() const
carto::rc_ptr< carto::Volume< T > > volume()
virtual ~ChannelSelector()
virtual void copyHeaderFrom(const PropertySet &other)
const uint8_t & green() const
void setSizeXYZT(float sizex=1.0f, float sizey=1.0f, float sizez=1.0f, float sizet=1.0f)
const uint8_t & blue() const
const uint8_t & saturation() const
std::vector< int > getBorders() const
const uint8_t & green() const
const uint8_t & red() const