Skip to content
Snippets Groups Projects
Commit b4027acf authored by Fabian Paus's avatar Fabian Paus
Browse files

ArViz: Cleanup timer changes from Coin to Qt

parent 7bce535d
No related branches found
No related tags found
1 merge request!185Clean up interfaces and unneeded code in memory core classes
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <Inventor/sensors/SoTimerSensor.h> #include <Inventor/sensors/SoTimerSensor.h>
#include <Inventor/nodes/SoUnits.h> #include <Inventor/nodes/SoUnits.h>
#include <QCoreApplication>
#include <thread> #include <thread>
...@@ -88,11 +89,6 @@ namespace armarx::viz ...@@ -88,11 +89,6 @@ namespace armarx::viz
&CoinVisualizerWrapper::onUpdateSuccess, &CoinVisualizerWrapper::onUpdateSuccess,
&CoinVisualizerWrapper::onUpdateFailure); &CoinVisualizerWrapper::onUpdateFailure);
root = new SoSeparator; root = new SoSeparator;
//timerSensor = new SoTimerSensor(updateVisualizationCB, this);
//float cycleTimeMS = 33.0f;
//timerSensor->setInterval(SbTime(cycleTimeMS / 1000.0f));
} }
CoinVisualizer::~CoinVisualizer() CoinVisualizer::~CoinVisualizer()
...@@ -114,9 +110,6 @@ namespace armarx::viz ...@@ -114,9 +110,6 @@ namespace armarx::viz
} }
state = CoinVisualizerState::STARTING; state = CoinVisualizerState::STARTING;
stateStorage = storage; stateStorage = storage;
//SoSensorManager* sensor_mgr = SoDB::getSensorManager();
//sensor_mgr->insertTimerSensor(timerSensor);
} }
void CoinVisualizer::stop() void CoinVisualizer::stop()
...@@ -126,15 +119,12 @@ namespace armarx::viz ...@@ -126,15 +119,12 @@ namespace armarx::viz
return; return;
} }
SoSensorManager* sensor_mgr = SoDB::getSensorManager();
state = CoinVisualizerState::STOPPING; state = CoinVisualizerState::STOPPING;
while (state != CoinVisualizerState::STOPPED) while (state != CoinVisualizerState::STOPPED)
{ {
sensor_mgr->processTimerQueue(); QCoreApplication::processEvents();
usleep(1000); usleep(1000);
} }
sensor_mgr->removeTimerSensor(timerSensor);
} }
CoinVisualizer_ApplyTiming CoinVisualizer::apply(data::LayerUpdate const& update) CoinVisualizer_ApplyTiming CoinVisualizer::apply(data::LayerUpdate const& update)
......
...@@ -229,7 +229,6 @@ namespace armarx::viz ...@@ -229,7 +229,6 @@ namespace armarx::viz
std::mutex storageMutex; std::mutex storageMutex;
viz::StorageInterfacePrx storage; viz::StorageInterfacePrx storage;
SoTimerSensor* timerSensor = nullptr;
CoinLayerMap layers; CoinLayerMap layers;
std::vector<std::type_index> elementVisualizersTypes; std::vector<std::type_index> elementVisualizersTypes;
......
...@@ -810,30 +810,34 @@ namespace armarx ...@@ -810,30 +810,34 @@ namespace armarx
void ArVizWidgetController::onReplayTimerTick() void ArVizWidgetController::onReplayTimerTick()
{ {
if (mode != ArVizWidgetMode::ReplayingTimed) if (mode == ArVizWidgetMode::ReplayingTimed)
{ {
return; double replaySpeed = widget.replaySpeedSpinBox->value();
}
double replaySpeed = widget.replaySpeedSpinBox->value();
replayCurrentTimestamp += 33000 * replaySpeed; long currentRealTime = IceUtil::Time::now().toMicroSeconds();
long elapsedRealTime = currentRealTime - lastReplayRealTime;
long revision = getRevisionForTimestamp(replayCurrentTimestamp); replayCurrentTimestamp += elapsedRealTime * replaySpeed;
if (revision == -2)
{ long revision = getRevisionForTimestamp(replayCurrentTimestamp);
if (widget.replayLoopbackCheckBox->checkState() == Qt::Checked) if (revision == -2)
{ {
replayCurrentTimestamp = currentRecording.firstTimestampInMicroSeconds; if (widget.replayLoopbackCheckBox->checkState() == Qt::Checked)
{
replayCurrentTimestamp = currentRecording.firstTimestampInMicroSeconds;
}
else
{
revision = currentRecording.lastRevision;
}
} }
else if (revision >= 0)
{ {
revision = currentRecording.lastRevision; widget.replayRevisionSlider->setValue(revision);
} }
} }
if (revision >= 0)
{ lastReplayRealTime = IceUtil::Time::now().toMicroSeconds();
widget.replayRevisionSlider->setValue(revision);
}
} }
void ArVizWidgetController::changeMode(ArVizWidgetMode newMode) void ArVizWidgetController::changeMode(ArVizWidgetMode newMode)
...@@ -917,10 +921,16 @@ namespace armarx ...@@ -917,10 +921,16 @@ namespace armarx
auto& entry = recordingBatchCache[batch.header.index]; auto& entry = recordingBatchCache[batch.header.index];
entry.data = batch; entry.data = batch;
entry.lastUsed = IceUtil::Time::now(); entry.lastUsed = IceUtil::Time::now();
limitRecordingBatchCacheSize();
recordingWaitingForBatchIndex = -1;
} }
viz::data::RecordingBatch const& ArVizWidgetController::getRecordingBatch(long index) viz::data::RecordingBatch const& ArVizWidgetController::getRecordingBatch(long index)
{ {
ARMARX_TRACE;
IceUtil::Time now = IceUtil::Time::now(); IceUtil::Time now = IceUtil::Time::now();
std::unique_lock<std::mutex> lock(recordingBatchCacheMutex); std::unique_lock<std::mutex> lock(recordingBatchCacheMutex);
...@@ -930,16 +940,23 @@ namespace armarx ...@@ -930,16 +940,23 @@ namespace armarx
{ {
// Start prefetching neighbouring batches // Start prefetching neighbouring batches
bool asyncPrefetchIsRunning = callbackResult && !callbackResult->isCompleted(); bool asyncPrefetchIsRunning = callbackResult && !callbackResult->isCompleted();
if (!asyncPrefetchIsRunning) if (!asyncPrefetchIsRunning && recordingWaitingForBatchIndex == -1)
{ {
if (index + 1 < long(currentRecording.batchHeaders.size()) if (index + 1 < long(currentRecording.batchHeaders.size())
&& recordingBatchCache.count(index + 1) == 0) && recordingBatchCache.count(index + 1) == 0)
{ {
// ARMARX_WARNING << "after begin_getRecordingBatch: " << (index + 1)
// << " waiting for " << recordingWaitingForBatchIndex;
callbackResult = storage->begin_getRecordingBatch(currentRecording.id, index + 1, callback); callbackResult = storage->begin_getRecordingBatch(currentRecording.id, index + 1, callback);
recordingWaitingForBatchIndex = index + 1;
ARMARX_INFO << "Now waiting for " << recordingWaitingForBatchIndex;
} }
else if (index > 0 && recordingBatchCache.count(index - 1) == 0) else if (index > 0 && recordingBatchCache.count(index - 1) == 0)
{ {
// ARMARX_WARNING << "before begin_getRecordingBatch: " << (index - 1)
// << " waiting for " << recordingWaitingForBatchIndex;
callbackResult = storage->begin_getRecordingBatch(currentRecording.id, index - 1, callback); callbackResult = storage->begin_getRecordingBatch(currentRecording.id, index - 1, callback);
recordingWaitingForBatchIndex = index - 1;
} }
} }
...@@ -949,6 +966,19 @@ namespace armarx ...@@ -949,6 +966,19 @@ namespace armarx
return entry.data; return entry.data;
} }
// Maybe there has already been sent a asynchronous request to get
if (index == recordingWaitingForBatchIndex)
{
lock.unlock();
ARMARX_INFO << "Waiting to receive async batch: " << index;
// Wait until request completes
while (recordingWaitingForBatchIndex != -1)
{
QCoreApplication::processEvents();
}
return getRecordingBatch(index);
}
ARMARX_INFO << "Batch #" << index << " is not in the cache. Getting synchronously, blocking GUI..."; ARMARX_INFO << "Batch #" << index << " is not in the cache. Getting synchronously, blocking GUI...";
// Entry is not in the cache, we have to get it from ArVizStorage // Entry is not in the cache, we have to get it from ArVizStorage
...@@ -956,6 +986,13 @@ namespace armarx ...@@ -956,6 +986,13 @@ namespace armarx
newEntry.lastUsed = now; newEntry.lastUsed = now;
newEntry.data = storage->getRecordingBatch(currentRecording.id, index); newEntry.data = storage->getRecordingBatch(currentRecording.id, index);
limitRecordingBatchCacheSize();
return newEntry.data;
}
void ArVizWidgetController::limitRecordingBatchCacheSize()
{
if (recordingBatchCache.size() > recordingBatchCacheMaxSize) if (recordingBatchCache.size() > recordingBatchCacheMaxSize)
{ {
// Remove the entry with the oldest last used timestamp // Remove the entry with the oldest last used timestamp
...@@ -972,8 +1009,6 @@ namespace armarx ...@@ -972,8 +1009,6 @@ namespace armarx
recordingBatchCache.erase(oldestIter); recordingBatchCache.erase(oldestIter);
} }
return newEntry.data;
} }
SoNode* ArVizWidgetController::getScene() SoNode* ArVizWidgetController::getScene()
......
...@@ -182,6 +182,7 @@ namespace armarx ...@@ -182,6 +182,7 @@ namespace armarx
QTimer* replayTimer; QTimer* replayTimer;
long replayCurrentTimestamp = 0; long replayCurrentTimestamp = 0;
long lastReplayRealTime = 0;
std::string storageName; std::string storageName;
armarx::viz::StorageInterfacePrx storage; armarx::viz::StorageInterfacePrx storage;
...@@ -207,9 +208,11 @@ namespace armarx ...@@ -207,9 +208,11 @@ namespace armarx
}; };
viz::data::RecordingBatch const& getRecordingBatch(long index); viz::data::RecordingBatch const& getRecordingBatch(long index);
void limitRecordingBatchCacheSize();
std::size_t recordingBatchCacheMaxSize = 5; std::size_t recordingBatchCacheMaxSize = 5;
std::mutex recordingBatchCacheMutex; std::mutex recordingBatchCacheMutex;
std::atomic<long> recordingWaitingForBatchIndex = -1;
std::map<long, TimestampedRecordingBatch> recordingBatchCache; std::map<long, TimestampedRecordingBatch> recordingBatchCache;
ArVizWidgetMode mode = ArVizWidgetMode::NotConnected; ArVizWidgetMode mode = ArVizWidgetMode::NotConnected;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment