使用boost :: apply_visitor将变量像素缓冲区转换为矢量

时间:2016-04-07 05:46:00

标签: c++ c++11 boost apply-visitor

我正在尝试使用boost中的apply_visitor将variablepixelbuffer.vbuffer()转换为double值的向量。

到目前为止,我带来了这段代码:

struct GetVector : public boost::static_visitor<std::vector<double>>
{
    //values will be returned in a pair.  double is
    // used since it can contain the value for any pixel type
    typedef std::vector<double> result_type;
    template<typename T
    void myfunction (const T& i) {  // function:
        result_type.push_back(static_cast<double>(*i));
    }

    template<typename T>
    result_type
    operator() (const T& v)
    {
        typedef typename T::element_type::value_type value_type;
        std::for_each (v->data(), v->data() + v->num_elements(), myfunction);
        return result_type;
    }
};
/* pixel-example-start */
void
readPixelData(const FormatReader& reader,
    std::ostream&       stream,int x,int y,int w,int h)
{
    // Change the current series to this index
    reader.setSeries(0);
    // Get total number of planes (for this image index)
    dimension_size_type pc = reader.getImageCount();
    // Pixel buffer
    VariantPixelBuffer buf;
    dimension_size_type xd = x;
    dimension_size_type yd = y;
    dimension_size_type wd = w;
    dimension_size_type hd = h;
    // Loop over planes (for this image index)
    for (dimension_size_type p = 0 ; p < pc; p++)
    {
        // Read the entire plane into the pixel buffer.
        reader.openBytes(p, buf,xd,yd,wd,hd);
    }
    GetVector visitor;
    GetVector::result_type result = boost::apply_visitor(visitor, buf.vbuffer());
}

但是我得到了一些很长的错误,其中一些是

  

/usr/include/boost/variant/detail/apply_visitor_unary.hpp:60:43:
  'typename Visitor :: result_type需要   boost :: apply_visitor(Visitor&amp;,Visitable&amp;)[与Visitor =   MinMaxVisitor;可访问=   boost :: variant&gt;,   boost :: mpl :: v_item&gt;,   升压:: MPL :: v_item

     
    

,boost :: mpl :: v_item&gt;,     boost :: mpl :: v_item&gt;,     boost :: mpl :: v_item&gt;,     提高:: MPL :: v_item     ,boost :: mpl :: v_item     ,boost :: mpl :: v_item     ,boost :: mpl :: v_item

         
      

,boost :: mpl :: v_item       ,boost :: mpl :: vector0,1&gt;,1&gt;,1&gt;,1>,1>,1>,1>,1>,1>,1>,1>,&gt; &gt;,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,       boost :: detail :: variant :: void_,boost :: detail :: variant :: void_&gt ;;       typename Visitor :: result_type = std :: vector&gt;]'read_subimage.C:82:85:从这里要求       /usr/include/c++/4.8/bits/stl_algo.h:4417:14:错误:必须使用'。'或       ' - &gt; '在'__f(...)'中调用指向成员的函数,例如“(...        - &gt; * __f)(...)'

    
  

我如何重新获得这个,我需要将像素缓冲区数据转换为矢量。

0 个答案:

没有答案