📄 reduce.hpp
字号:
namespace boost { namespace mpl {////////////////////////////////////////////////////////// \brief Represents the virtual cross-product of the types generated from VecOfVecs./// \ingroup CrossVector/// INPUT: /// VecOfVecs - a vector of vector types. For example [ [A1,A2,A3], [B1,B2], [C1,C2,C3,C4] ]/// Each element must be a non-empty mpl vector/// TypeGen - a metafunction that generates a type from a vector of types, each of which can be/// selected from the corresponding vector in VecOfVecs. For example, [A1, B2, C4]/// /// Represents the virtual cross-product of the types generated from VecOfVecs./// For example, [ TypeGen[A1,B1,C1], TypeGen[A2,B1,C1], TypeGen[A3,B1,C1],/// TypeGen[A1,B2,C1], TypeGen[A2,B2,C1], TypeGen[A3,B2,C1],/// TypeGen[A1,B1,C2], TypeGen[A2,B1,C2], TypeGen[A3,B1,C2], ... ]/// /// Models an immutable MPL Random Access Sequence/// Traversal, random-access, etc, is defined, but mutable operations, /// such as push_back and pop_front are not supported///////////////////////////////////////////////////////template <typename VecOfVecs, typename TypeGen>struct cross_vector {};/// \brief Iterator of cross_vector/// \ingroup CrossVectorIteratortemplate <typename VecOfVecs, typename TypeGen, std::size_t K>struct cross_iterator { typedef mpl::random_access_iterator_tag category;};////////////////////////////////////////////////////////// Implementation of the iterator functions of cross vector////////////////////////////////////////////////////////// \brief Dereferences a cross-vector iterator/// \ingroup CrossVectorIterator/// Creates a vector of the sizes of each type vector in VecOfVecs, then uses it as a basis/// to represent the iterator's position K as a vector of indices. Extracts the corresponding type of /// each input vector and passes the element types to the type generation function, which returns the dereferenced typetemplate <typename VecOfVecs, typename TypeGen, std::size_t K>struct deref<cross_iterator<VecOfVecs,TypeGen,K> > {private: typedef typename detail::select_subvector_c<VecOfVecs, K>::type DerefTypes;public: typedef typename TypeGen::template apply<DerefTypes>::type type;};/// \brief Increments a cross-vector iterator./// \ingroup CrossVectorIteratortemplate <typename VecOfVecs, typename TypeGen, std::size_t K>struct next<cross_iterator<VecOfVecs,TypeGen,K> > { typedef cross_iterator<VecOfVecs,TypeGen,K+1> type;};/// \brief Decrements a cross-vector iterator./// \ingroup CrossVectorIteratortemplate <typename VecOfVecs, typename TypeGen, std::size_t K>struct prior<cross_iterator<VecOfVecs,TypeGen,K> > { typedef cross_iterator<VecOfVecs,TypeGen,K-1> type;};/// \brief Advances a cross-vector iterator./// \ingroup CrossVectorIteratortemplate <typename VecOfVecs, typename TypeGen, std::size_t K, typename Distance>struct advance<cross_iterator<VecOfVecs,TypeGen,K>, Distance > { typedef cross_iterator<VecOfVecs,TypeGen,K+Distance::value> type;};/// \brief Computes the distance between two cross-vector iterator-s./// \ingroup CrossVectorIterator// (shortened the names of the template arguments - otherwise doxygen cannot parse this...)template <typename VecOfVecs, typename TypeGen, std::size_t K1, std::size_t K2>struct distance<cross_iterator<VecOfVecs,TypeGen,K1>, cross_iterator<VecOfVecs,TypeGen,K2> > { typedef size_t<K2-K1> type;};////////////////////////////////////////////////////////// Implementation of cross vector////////////////////////////////////////////////////////// \brief Computes the size of a cross vector as the product of the sizes of all vectors in VecOfVecs/// \ingroup CrossVectortemplate <typename VecOfVecs, typename TypeGen>struct size<cross_vector<VecOfVecs,TypeGen> > { typedef typename fold<VecOfVecs, size_t<1>, times<_1, size<_2> > >::type type; static const std::size_t value=type::value;};/// \brief Determines whether a cross vector is empty/// \ingroup CrossVectortemplate <typename VecOfVecs, typename TypeGen>struct empty<cross_vector<VecOfVecs,TypeGen> > { typedef typename empty<VecOfVecs>::type type;};/// \brief Returns the K-th element of a cross vector/// \ingroup CrossVectortemplate <typename VecOfVecs, typename TypeGen, typename K>struct at<cross_vector<VecOfVecs,TypeGen>, K> {private: typedef cross_iterator<VecOfVecs,TypeGen,K::value> KthIterator;public: typedef typename deref<KthIterator>::type type;};/// \brief Returns an iterator to the first element of a cross vector/// \ingroup CrossVectortemplate <typename VecOfVecs, typename TypeGen>struct begin<cross_vector<VecOfVecs,TypeGen> > { typedef cross_iterator<VecOfVecs,TypeGen,0> type;};/// \brief Returns an iterator to the last element of a cross vector/// \ingroup CrossVectortemplate <typename VecOfVecs, typename TypeGen>struct end<cross_vector<VecOfVecs,TypeGen> > {private: typedef cross_vector<VecOfVecs,TypeGen> this_t;public: typedef cross_iterator<VecOfVecs,TypeGen,size<this_t>::value> type;};/// \brief Returns the first element of a cross vector/// \ingroup CrossVectortemplate <typename VecOfVecs, typename TypeGen>struct front<cross_vector<VecOfVecs,TypeGen> > {private: typedef cross_vector<VecOfVecs,TypeGen> this_t;public: typedef typename deref<typename begin<this_t>::type>::type type;};/// \brief Returns the last element of a cross vector/// \ingroup CrossVectortemplate <typename VecOfVecs, typename TypeGen>struct back<cross_vector<VecOfVecs,TypeGen> > {private: typedef cross_vector<VecOfVecs,TypeGen> this_t; typedef typename size<this_t>::type size; typedef typename minus<size, size_t<1> >::type last_index;public: typedef typename at<this_t, last_index>::type type;};/// \brief Transforms the elements of a cross vector/// \ingroup CrossVectortemplate <typename VecOfVecs, typename TypeGen, typename OPP>struct transform<cross_vector<VecOfVecs,TypeGen>, OPP > { typedef typename lambda<OPP>::type Op; struct adapter { template <typename Elements> struct apply { typedef typename TypeGen::template apply<Elements>::type orig_t; typedef typename Op::template apply<orig_t>::type type; }; }; typedef cross_vector<VecOfVecs, adapter > type; };} } // boost::mplnamespace boost { namespace gil {template <typename Types, typename T> struct type_to_index;template <typename V> struct view_is_basic;struct rgb_t;struct lab_t;struct hsb_t;struct cmyk_t;struct rgba_t;struct error_t;namespace detail { //////////////////////////////////////////////////////// //// //// Generic reduce operation //// //////////////////////////////////////////////////////// template <typename Op, typename T> struct reduce { typedef T type; }; //////////////////////////////////////////////////////// //// //// Unary reduce_view operation. Splits into basic and non-basic views. //// Algorithm-specific reduce should specialize for basic views //// //////////////////////////////////////////////////////// template <typename Op, typename View, bool IsBasic> struct reduce_view_basic { typedef View type; }; template <typename Op, typename Loc> struct reduce<Op, image_view<Loc> > : public reduce_view_basic<Op,image_view<Loc>,view_is_basic<image_view<Loc> >::value> {}; //////////////////////////////////////////////////////// //// //// Unary reduce_image operation. Splits into basic and non-basic images. //// Algorithm-specific reduce should specialize for basic images //// //////////////////////////////////////////////////////// template <typename Op, typename Img, bool IsBasic> struct reduce_image_basic { typedef Img type; }; template <typename Op, typename V, typename Alloc> struct reduce<Op, image<V,Alloc> > : public reduce_image_basic<Op,image<V,Alloc>,image_is_basic<image<V,Alloc> >::value > {}; //////////////////////////////////////////////////////// //// //// Binary reduce_view operation. Splits into basic and non-basic views. //// Algorithm-specific reduce should specialize for basic views //// //////////////////////////////////////////////////////// template <typename Op, typename V1, typename V2, bool AreBasic> struct reduce_views_basic { typedef std::pair<const V1*, const V2*> type; }; template <typename Op, typename L1, typename L2> struct reduce<Op, std::pair<const image_view<L1>*, const image_view<L2>*> > : public reduce_views_basic<Op,image_view<L1>,image_view<L2>, mpl::and_<view_is_basic<image_view<L1> >, view_is_basic<image_view<L2> > >::value > {}; //////////////////////////////////////////////////////// //// //// Color space unary reduce operation. Reduce a color space to a base with the same number of channels //// //////////////////////////////////////////////////////// template <typename Cs> struct reduce_color_space { typedef Cs type; }; template <> struct reduce_color_space<lab_t> { typedef rgb_t type; }; template <> struct reduce_color_space<hsb_t> { typedef rgb_t type; }; template <> struct reduce_color_space<cmyk_t> { typedef rgba_t type; }; /* //////////////////////////////////////////////////////// //// //// Color space binary reduce operation. Given a source and destination color spaces, //// returns a reduced source and destination color spaces that have the same mapping of channels //// //// Precondition: The two color spaces must be compatible (i.e. must have the same set of channels) //////////////////////////////////////////////////////// template <typename Vec, int Basis, int VecSize> struct type_vec_to_integer_impl { typedef typename mpl::back<Vec>::type last; typedef typename mpl::pop_back<Vec>::type rest; static const int value = type_vec_to_integer_impl<rest, Basis, VecSize-1>::value * Basis + last::value;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -