Skip to content

Commit 00c98c2

Browse files
author
Fabien Servant
committed
Make sure cameraInit change does not clear cache
1 parent 6bac381 commit 00c98c2

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

src/qtAliceVision/AsyncFetcher.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class AsyncFetcher : public QObject, public QRunnable
6767
*/
6868
void stopAsync();
6969

70+
bool isAsync() const
71+
{
72+
return _isAsynchroneous;
73+
}
74+
7075
/**
7176
* @brief get the cache content size in bytes
7277
* @return the cache content size in bytes

src/qtAliceVision/FloatImageViewer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ void FloatImageViewer::setResizeRatio(double ratio)
9393

9494
_sequenceCache.setResizeRatio(ratio);
9595

96+
_clampedResizeRatio = ratio;
97+
9698
Q_EMIT resizeRatioChanged();
9799
}
98100

@@ -183,6 +185,12 @@ void FloatImageViewer::playback(bool active)
183185

184186
QVector4D FloatImageViewer::pixelValueAt(int x, int y)
185187
{
188+
if (_useSequence)
189+
{
190+
x = int(std::ceil(double(x) * _clampedResizeRatio));
191+
y = int(std::ceil(double(y) * _clampedResizeRatio));
192+
}
193+
186194
if (!_image)
187195
{
188196
// qInfo() << "[QtAliceVision] FloatImageViewer::pixelValueAt(" << x << ", " << y << ") => no valid image";

src/qtAliceVision/FloatImageViewer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class FloatImageViewer : public QQuickItem
207207
imgserve::SequenceCache _sequenceCache;
208208
imgserve::SingleImageLoader _singleImageLoader;
209209
bool _useSequence = true;
210+
double _clampedResizeRatio = 1.0;
210211
};
211212

212213
} // namespace qtAliceVision

src/qtAliceVision/SequenceCache.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ SequenceCache::SequenceCache(QObject* parent)
2424
_maxMemory = static_cast<size_t>(cacheRam);
2525

2626
_fetcher.setAutoDelete(false);
27+
28+
//Cache does not exist
29+
//Let's create a new one !
30+
{
31+
image::ImageCache::uptr cache = std::make_unique<image::ImageCache>(_maxMemory, image::EImageColorSpace::LINEAR);
32+
_fetcher.setCache(std::move(cache));
33+
}
2734
}
2835

2936
SequenceCache::~SequenceCache()
@@ -34,16 +41,11 @@ SequenceCache::~SequenceCache()
3441

3542
void SequenceCache::setSequence(const QVariantList& paths)
3643
{
44+
bool isAsync = _fetcher.isAsync();
45+
3746
_fetcher.stopAsync();
3847
_threadPool.waitForDone();
3948

40-
//On changing sequence, the cache become totally invalid
41-
//Let's create a new one !
42-
{
43-
image::ImageCache::uptr cache = std::make_unique<image::ImageCache>(_maxMemory, image::EImageColorSpace::LINEAR);
44-
_fetcher.setCache(std::move(cache));
45-
}
46-
4749
//Convert to string
4850
std::vector<std::string> sequence;
4951
for (const auto & item : paths)
@@ -53,6 +55,9 @@ void SequenceCache::setSequence(const QVariantList& paths)
5355

5456
//Assign sequence to fetcher
5557
_fetcher.setSequence(sequence);
58+
59+
//Restart if needed
60+
setAsyncFetching(isAsync);
5661
}
5762

5863
void SequenceCache::setResizeRatio(double ratio)

0 commit comments

Comments
 (0)