| 877 | |
| 878 | |
| 879 | point_count_t CopcReader::read(PointViewPtr view, point_count_t count) |
| 880 | { |
| 881 | if (m_p->tileCount == 0) |
| 882 | return 0; |
| 883 | |
| 884 | point_count_t numRead = 0; |
| 885 | |
| 886 | // Pop tiles until there are no more, or wait for them to appear. |
| 887 | // Exit when we've handled all the tiles or we've read enough points. |
| 888 | // The mutex protects the tile queue (m_p->contents). |
| 889 | do |
| 890 | { |
| 891 | std::unique_lock<std::mutex> l(m_p->mutex); |
| 892 | if (m_p->contents.size()) |
| 893 | { |
| 894 | copc::Tile tile = std::move(m_p->contents.front()); |
| 895 | m_p->contents.pop(); |
| 896 | m_p->consumedCv.notify_one(); |
| 897 | l.unlock(); |
| 898 | checkTile(tile); |
| 899 | process(view, tile, count - numRead); |
| 900 | numRead += tile.size(); |
| 901 | m_p->tileCount--; |
| 902 | } |
| 903 | else |
| 904 | m_p->contentsCv.wait(l); |
| 905 | } while (m_p->tileCount && numRead <= count); |
| 906 | |
| 907 | return numRead; |
| 908 | } |
| 909 | |
| 910 | void CopcReader::checkTile(const copc::Tile& tile) |
| 911 | { |