mercredi 6 avril 2016

variant pixel buffer to vector using boost::apply_visitor

I am trying to convert variablepixelbuffer.vbuffer() to a vector of double values using apply_visitor in boost.

I came with this piece of code till now :

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;

    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());
  }

But i am getting some long errors, and some piece of it are

/usr/include/boost/variant/detail/apply_visitor_unary.hpp:60:43:
required from ‘typename Visitor::result_type boost::apply_visitor(Visitor&, Visitable&) [with Visitor = MinMaxVisitor; Visitable = boost::variant >, boost::mpl::v_item >, boost::mpl::v_item

, boost::mpl::v_item >, boost::mpl::v_item >, boost::mpl::v_item >, boost::mpl::v_item , boost::mpl::v_item , boost::mpl::v_item , boost::mpl::v_item

, boost::mpl::v_item , boost::mpl::vector0, 1>, 1>, 1>, 1>, 1>, 1>, 1>, 1>, 1>, 1>, 1> >, 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_>; typename Visitor::result_type = std::vector >]’ read_subimage.C:82:85: required from here /usr/include/c++/4.8/bits/stl_algo.h:4417:14: error: must use ‘.’ or ‘->’ to call pointer-to-member function in ‘__f (...)’, e.g. ‘(... ->* __f) (...)’

How can i reslove this, I need to get the pixel buffer data into vector .

Aucun commentaire:

Enregistrer un commentaire