Exemplo n.º 1
0
    int fetch_()
    {
        std::streamsize num = std::min(
            static_cast< std::streamsize >( gptr() - eback() ), pb_size);

        std::memmove(
            buffer_ + ( pb_size - num),
            gptr() - num, num);

        s_.async_read_some(
                boost::asio::buffer( buffer_ + pb_size, bf_size - pb_size),
                boost::bind( & coro_t::operator(), & coro_, _1, _2) );
        ca_();

        boost::system::error_code ec;
        std::size_t n = 0;

        boost::tie( ec, n) = ca_.get();
        if ( ec)
        {
            setg( 0, 0, 0);
            return -1;
        }

        setg( buffer_ + pb_size - num, buffer_ + pb_size, buffer_ + pb_size + n);
        return n;
    }
Exemplo n.º 2
0
    void get()
    {
      // Must not hold shared_ptr to coro while suspended.
      handler_.coro_.reset();

      if (--ready_ != 0)
        ca_();
      if (!out_ec_ && ec_) throw boost::system::system_error(ec_);
    }
Exemplo n.º 3
0
    return_type get()
    {
      // Must not hold shared_ptr to coro while suspended.
      handler_.coro_.reset();

      if (--ready_ != 0)
        ca_();
      if (!out_ec_ && ec_) throw boost::system::system_error(ec_);
      return BOOST_ASIO_MOVE_CAST(return_type)(value_);
    }
Exemplo n.º 4
0
std::list<Vec3f> Mesher::get_contour()
{
    // Find all of the singular edges in this fan
    // (edges that aren't shared between multiple triangles).
    std::set<std::array<float, 6>> valid_edges;
    for (auto itr=voxel_start; itr != voxel_end; ++itr)
    {
        if (valid_edges.count(itr->ba_()))
            valid_edges.erase(itr->ba_());
        else
            valid_edges.insert(itr->ab_());

        if (valid_edges.count(itr->cb_()))
            valid_edges.erase(itr->cb_());
        else
            valid_edges.insert(itr->bc_());

        if (valid_edges.count(itr->ac_()))
            valid_edges.erase(itr->ac_());
        else
            valid_edges.insert(itr->ca_());
    }

    std::set<std::array<float, 3>> in_fan;

    std::list<Vec3f> contour = {voxel_start->a};
    in_fan.insert(voxel_start->a_());
    in_fan.insert(voxel_start->b_());
    in_fan.insert(voxel_start->c_());

    fan_start = voxel_start;
    voxel_start++;

    while (contour.size() == 1 || contour.front() != contour.back())
    {
        std::list<Triangle>::iterator itr;
        for (itr=fan_start; itr != voxel_end; ++itr)
        {
            const auto& t = *itr;
            if (contour.back() == t.a && valid_edges.count(t.ab_()))
            {
                contour.push_back(t.b);
                break;
            }

            if (contour.back() == t.b && valid_edges.count(t.bc_()))
            {
                contour.push_back(t.c);
                break;
            }

            if (contour.back() == t.c && valid_edges.count(t.ca_()))
            {
                contour.push_back(t.a);
                break;
            }
        }
        // If we broke out of the loop (meaning itr is pointing to a relevant
        // triangle which should be moved forward to before voxel_start), then
        // push the list around and update iterators appropriately.
        if (itr != voxel_end)
        {
            in_fan.insert(itr->a_());
            in_fan.insert(itr->b_());
            in_fan.insert(itr->c_());

            if (itr == voxel_start)
            {
                voxel_start++;
            }
            else if (itr != fan_start)
            {
                const Triangle t = *itr;
                triangles.insert(voxel_start, t);
                itr = triangles.erase(itr);
                itr--;
            }
        }
    }

    // Special case to catch triangles that are part of a particular fan but
    // don't have any edges in the contour (which can happen!).
    for (auto itr=voxel_start;  itr != voxel_end; ++itr)
    {
        if (in_fan.count(itr->a_()) &&
            in_fan.count(itr->b_()) &&
            in_fan.count(itr->c_()))
        {
            if (itr == voxel_start)
            {
                voxel_start++;
            }
            else if (itr != fan_start)
            {
                const Triangle t = *itr;
                triangles.insert(voxel_start, t);
                itr = triangles.erase(itr);
                itr--;
            }
        }
    }

    // Remove the last point of the contour, since it's a closed loop.
    contour.pop_back();
    return contour;
}