Fetch threads based on the current FOV and level; prefetch will cache one level up and one level down of the current FOV (taking into account the downsampling) and tiles outside the FOV with the same size of the FOV in a 8 connected fashion
| 48 | // current FOV (taking into account the downsampling) and tiles outside the FOV with the same size of the FOV in |
| 49 | // a 8 connected fashion |
| 50 | void PrefetchThread::run() |
| 51 | { |
| 52 | forever{ |
| 53 | if (_img) { |
| 54 | _mutex.lock(); |
| 55 | QRectF FOV = _FOV; |
| 56 | int level = _level; |
| 57 | MultiResolutionImage* img = _img; |
| 58 | std::vector<unsigned long long> L0Dims = img->getDimensions(); |
| 59 | QRectF maxFOV(0, 0, L0Dims[0], L0Dims[1]); |
| 60 | int levelDownsample = img->getLevelDownsample(level); |
| 61 | _mutex.unlock(); |
| 62 | |
| 63 | if (img) { |
| 64 | if (_abort) { |
| 65 | return; |
| 66 | } |
| 67 | // Cache level below |
| 68 | if (level - 1 >= 0 && !_restart) { |
| 69 | unsigned int width = FOV.width() / img->getLevelDownsample(level - 1); |
| 70 | unsigned int height = FOV.height() / img->getLevelDownsample(level - 1); |
| 71 | unsigned char* data = NULL; |
| 72 | data = new unsigned char[width*height*img->getSamplesPerPixel()]; |
| 73 | img->getRawRegion(FOV.left(), FOV.top(), width, height, level - 1, data); |
| 74 | delete[] data; |
| 75 | } |
| 76 | // Cache around current FOV if needed |
| 77 | for (int x = -1; x < 2; ++x) { |
| 78 | if (_restart) { |
| 79 | break; |
| 80 | } |
| 81 | for (int y = -1; y < 2; ++y) { |
| 82 | if (_restart) { |
| 83 | break; |
| 84 | } |
| 85 | if (x == 0 && y == 0) { |
| 86 | continue; |
| 87 | } |
| 88 | QRectF cur(FOV.left() + x*FOV.width(), FOV.top() + y*FOV.height(), FOV.width(), FOV.height()); |
| 89 | cur = cur.intersected(maxFOV); |
| 90 | unsigned int width = cur.width() / levelDownsample; |
| 91 | unsigned int height = cur.height() / levelDownsample; |
| 92 | unsigned char* data = new unsigned char[width*height*img->getSamplesPerPixel()]; |
| 93 | img->getRawRegion(cur.left(), cur.top(), width, height, level, data); |
| 94 | delete[] data; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | _mutex.lock(); |
| 100 | if (!_restart) { |
| 101 | qDebug() << "Prefetching finished!"; |
| 102 | _condition.wait(&_mutex); |
| 103 | } |
| 104 | _restart = false; |
| 105 | _mutex.unlock(); |
| 106 | if (_abort) { |
| 107 | return; |
nothing calls this directly
no test coverage detected