24 #ifndef _FUNCTORACCESSOR_H
25 #define _FUNCTORACCESSOR_H
27 #include <vigra/numerictraits.hxx>
40 template <
class Functor,
class Accessor>
57 template <
typename ITERATOR_,
typename DIFFERENCE_>
58 typename Functor::result_type
operator()(ITERATOR_
const & i, DIFFERENCE_ d)
const
65 template <
class ITERATOR>
66 typename Functor::result_type
operator()(ITERATOR
const & i)
const {
83 template <
class Functor,
class Accessor,
class ValueType>
97 template <
class Value,
class ITERATOR>
98 void set(Value
const & v, ITERATOR
const & i)
const
105 template <
class Value,
class ITERATOR_,
class DIFFERENCE_>
106 void set(Value
const & v, ITERATOR_
const & i, DIFFERENCE_ d)
const
145 template <
class Iter1,
class Acc1,
class Iter2,
class Acc2>
151 typedef vigra::TinyVector<typename Acc1::value_type, 2>
value_type;
161 template <
class V,
class ITERATOR>
162 void setComponent( V
const & value, ITERATOR
const & i,
int idx )
const
172 vigra_fail(
"too many components in input value");
177 template <
class ITERATOR>
178 unsigned int size(ITERATOR
const & i)
const
199 template <
class Iter1,
class Acc1,
class Iter2,
class Acc2,
int SIZE>
205 typedef vigra::TinyVector<typename Acc1::value_type, SIZE>
value_type;
215 template <
class V,
class ITERATOR>
216 void setComponent( V
const & value, ITERATOR
const & i,
int idx )
const
218 if ( idx < SIZE - 1 ) {
219 a1_.setComponent(value,
i1_, *i, idx);
220 }
else if ( idx == SIZE - 1 ) {
223 vigra_fail(
"too many components in input value");
228 template <
class ITERATOR>
229 unsigned int size(ITERATOR
const & i)
const
245 template <
class Iter1,
class Acc1,
class Iter2,
class Acc2>
251 typedef vigra::TinyVector<typename Acc1::value_type, 2>
value_type;
262 template <
class DIFFERENCE_>
269 template <
class ITERATOR>
278 vigra_fail(
"too many components in input value");
285 template <
class ITERATOR,
class DIFFERENCE_>
291 return a1_.getComponent(
i1_, *i, idx);
293 return a2_.getComponent(
i2_, *i, idx);
295 vigra_fail(
"too many components in input value");
300 template <
class ITERATOR>
301 unsigned int size(ITERATOR
const & i)
const
321 template <
class Iter1,
class Acc1,
class Iter2,
class Acc2,
int SIZE>
342 template <
class DIFFERENCE_>
346 typename value_type::iterator it = ret.begin();
348 for (
typename image1_type::const_iterator it1 = i1.begin();
349 it1 != i1.end(); ++it1 )
359 template <
class ITERATOR>
362 if ( idx < SIZE - 1 ) {
363 return a1_.getComponent(
i1_, *i, idx);
364 }
else if ( idx == SIZE - 1 ) {
367 vigra_fail(
"too many components in input value");
376 template <
class ITERATOR,
class DIFFERENCE_>
380 if ( idx < SIZE - 1 ) {
381 return a1_.getComponent(
i1_, *i, idx);
382 }
else if ( idx == SIZE - 1 ) {
385 vigra_fail(
"too many components in input value");
395 template <
class ITERATOR>
396 unsigned int size(ITERATOR
const & i)
const
440 template <
class Iter1,
class Acc1,
class Iter2,
class Acc2,
int SIZE>
465 template <
class V,
class ITERATOR>
469 vigra::NumericTraits<image_type1>::isScalar() );
484 template <
class V,
class ITERATOR>
485 void setVector2VectorVector(V
const & value, ITERATOR
const & i)
const
493 typename V::iterator vIt = value.begin();
494 typename image_type1::iterator v1It = v1.begin();
495 while ( v1It != v1.end() && vIt != value.end()) {
496 *v1It = detail::RequiresExplicitCast<VALUETYPE>::cast(*vIt);
501 typename image_type2::iterator v2It = v2.begin();
502 while ( v2It != v1.end() && vIt != value.end()) {
503 *v2It = detail::RequiresExplicitCast<VALUETYPE>::cast(*vIt);
510 for (
int i=0; i < value.size(); i++) {
513 *i = detail::RequiresExplicitCast<VALUETYPE>::cast(value); }
520 template <
class V,
class ITERATOR,
class DIFFERENCE_>
521 void set(V
const & value, ITERATOR
const & i, DIFFERENCE_
const & diff)
const
523 i[diff]= detail::RequiresExplicitCast<VALUETYPE>::cast(value);
530 template <
class V,
class ITERATOR>
532 vigra::VigraTrueType)
const
535 vigra::NumericTraits<image_type2>::isScalar() );
539 template <
class V,
class ITERATOR>
541 vigra::VigraFalseType)
const
544 vigra::NumericTraits<image_type2>::isScalar() );
548 template <
class V,
class ITERATOR>
550 vigra::VigraTrueType)
const
560 vigra_fail(
"too many components in input value");
565 template <
class V,
class ITERATOR>
567 vigra::VigraTrueType)
const
569 vigra_fail(
"vector -> scalar, vector accessor not implemented");
573 template <
class V,
class ITERATOR>
575 vigra::VigraTrueType)
const
578 typename image_type1::size_type s1 = v1.size();
580 a1_.setComponent(value, i, idx);
581 }
else if ( idx == s1) {
584 vigra_fail(
"too many components in input value");
589 template <
class V,
class ITERATOR>
591 vigra::VigraTrueType)
const
593 vigra_fail(
"vector -> vector, vector accessor not implemented");
612 template <
class PixelType>
615 return vigra::NumericTraits<result_type>::fromRealPromote(v * m_factor);
625 #endif // _FUNCTORACCESSOR_H
void setComponentScalarIsVector(V const &value, ITERATOR const &i, int idx, vigra::VigraTrueType) const
if scalar & vector image
component_type getComponent(ITERATOR const &i, int idx) const
read one component
Functor::result_type operator()(ITERATOR_ const &i, DIFFERENCE_ d) const
Get functor result template <class A, class B> void function(A a, B b) { };
vigra::TinyVector< typename Acc1::value_type, SIZE > value_type
the vector's value_type
vigra::TinyVector< typename Acc1::value_type, 2 > value_type
the vector's value_type
MergeScalarScalar2VectorAccessor(Iter1 i1, Acc1 a1, Iter2 i2, Acc2 a2)
Construct from two image iterators and associated accessors.
merge two scalar images into a vector image.
unsigned int size(ITERATOR const &i) const
return the size (Number of Bands)
value_type::value_type component_type
component_type const getComponent(ITERATOR i, DIFFERENCE_ const &d, int idx) const
read one component, with offset
void setComponentScalarIsScalar(V const &value, ITERATOR const &i, int idx, vigra::VigraTrueType) const
if scalar & scalar image
Acc1::value_type image_type1
value type of image 1
void setComponent(V const &value, ITERATOR const &i, int idx) const
vector & scalar image
This class can be used to apply a function when writing to an image.
unsigned int size(ITERATOR const &i) const
return the size (Number of Bands)
MergeVectorScalar2VectorAccessor(Iter1 i1, Acc1 a1, Iter2 i2, Acc2 a2)
Construct from two image iterators and associated accessors.
merge a vector and a scalar image into a vector image.
void setComponentVectorIsVector(V const &value, ITERATOR const &i, int idx, vigra::VigraTrueType) const
if vector & vector image
void setComponentIsScalar(V const &value, ITERATOR const &i, int idx, vigra::VigraFalseType) const
if first dest image is vector image
PixelType operator()(PixelType const &v) const
void set(Value const &v, ITERATOR_ const &i, DIFFERENCE_ d) const
Set functor result.
define a write only accessor for a virtual Image<TinyVector<Acc1::value_type>, 2> image...
vigra::TinyVector< typename Acc1::value_type, 2 > value_type
the vector's value_type
component_type getComponent(ITERATOR const &i, int idx) const
read one component
value_type::value_type component_type
void setComponentVectorIsScalar(V const &value, ITERATOR const &i, int idx, vigra::VigraTrueType) const
if vector & scalar image
value_type operator()(DIFFERENCE_ const &d) const
read the current data item
image1_type::value_type component_type
split a vector image into a vector and a scalar image
SplitVectorNAccessor(Iter1 i1, Acc1 a1, Iter2 i2, Acc2 a2)
Construct from two image iterators and associated accessors.
unsigned int size(ITERATOR const &i) const
return the size (Number of Bands)
component_type const & getComponent(ITERATOR const &i, DIFFERENCE_ const &d, int idx) const
read one component, with offset
Acc2::value_type image2_type
unsigned int size(ITERATOR const &i) const
return the size (Number of Bands)
Acc2::value_type image_type2
value type of image 2
ImageSplittingAccessor(Iter1 i1, Acc1 a1, Iter2 i2, Acc2 a2)
Construct from two image iterators and associated accessors.
This class can be used to apply a function when reading the input image.
An accessor to encapsulate write access to a multiband image, and move divide it into two images...
void setComponent(V const &value, ITERATOR const &i, int idx) const
write value V into the two images.
Acc1::value_type image1_type
the vector's value_type
ReadFunctorAccessor(Functor f, Accessor a)
Functor::result_type value_type
value_type::value_type component_type
value_type operator()(DIFFERENCE_ const &d) const
read the current data item
WriteFunctorAccessor(Functor f, Accessor a)
SplitVector2Accessor(Iter1 i1, Acc1 a1, Iter2 i2, Acc2 a2)
Construct from two image iterators and associated accessors.
vigra::TinyVector< component_type, SIZE > value_type
Functor::result_type operator()(ITERATOR const &i) const
Get functor result.
void set(Value const &v, ITERATOR const &i) const
Set functor result.
void setComponent(V const &value, ITERATOR const &i, int idx) const
scalar & scalar image
void setComponentIsScalar(V const &value, ITERATOR const &i, int idx, vigra::VigraTrueType) const
if first dest image is scalar
a sample functor that can be used to multiply pixel values with a constant