mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-02 01:20:25 +08:00
refactored DBDriver (fixed the TODOs)
This commit is contained in:
@@ -307,8 +307,6 @@ void DBDriver::loadSignatures(const std::list<int> & signIds,
|
|||||||
bool valueFound = false;
|
bool valueFound = false;
|
||||||
_trashesMutex.lock();
|
_trashesMutex.lock();
|
||||||
{
|
{
|
||||||
_dbSafeAccessMutex.lock();
|
|
||||||
_dbSafeAccessMutex.unlock();
|
|
||||||
for(std::list<int>::iterator iter = ids.begin(); iter != ids.end();)
|
for(std::list<int>::iterator iter = ids.begin(); iter != ids.end();)
|
||||||
{
|
{
|
||||||
valueFound = false;
|
valueFound = false;
|
||||||
@@ -361,8 +359,6 @@ void DBDriver::loadWords(const std::set<int> & wordIds, std::list<VisualWord *>
|
|||||||
{
|
{
|
||||||
if(_trashVisualWords.size())
|
if(_trashVisualWords.size())
|
||||||
{
|
{
|
||||||
_dbSafeAccessMutex.lock();
|
|
||||||
_dbSafeAccessMutex.unlock();
|
|
||||||
for(std::set<int>::iterator iter = ids.begin(); iter != ids.end();)
|
for(std::set<int>::iterator iter = ids.begin(); iter != ids.end();)
|
||||||
{
|
{
|
||||||
wIter = _trashVisualWords.find(*iter);
|
wIter = _trashVisualWords.find(*iter);
|
||||||
@@ -394,15 +390,26 @@ void DBDriver::loadWords(const std::set<int> & wordIds, std::list<VisualWord *>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Check also in the trash ?
|
|
||||||
void DBDriver::loadNodeData(std::list<Signature *> & signatures, bool loadMetricData) const
|
void DBDriver::loadNodeData(std::list<Signature *> & signatures, bool loadMetricData) const
|
||||||
{
|
{
|
||||||
|
// Don't look in the trash, we assume that if we want to load
|
||||||
|
// data of a signature, it is not in thrash! Print an error if so.
|
||||||
|
_trashesMutex.lock();
|
||||||
|
if(_trashSignatures.size())
|
||||||
|
{
|
||||||
|
for(std::list<Signature *>::iterator iter=signatures.begin(); iter!=signatures.end(); ++iter)
|
||||||
|
{
|
||||||
|
UASSERT(*iter != 0);
|
||||||
|
UASSERT_MSG(uContains(_trashSignatures, (*iter)->id()), uFormat("Signature %d should not be used when transferred to trash!!!!", (*iter)->id()).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_trashesMutex.unlock();
|
||||||
|
|
||||||
_dbSafeAccessMutex.lock();
|
_dbSafeAccessMutex.lock();
|
||||||
this->loadNodeDataQuery(signatures, loadMetricData);
|
this->loadNodeDataQuery(signatures, loadMetricData);
|
||||||
_dbSafeAccessMutex.unlock();
|
_dbSafeAccessMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Check also in the trash ?
|
|
||||||
void DBDriver::getNodeData(
|
void DBDriver::getNodeData(
|
||||||
int signatureId,
|
int signatureId,
|
||||||
cv::Mat & imageCompressed,
|
cv::Mat & imageCompressed,
|
||||||
@@ -414,73 +421,216 @@ void DBDriver::getNodeData(
|
|||||||
float & cy,
|
float & cy,
|
||||||
Transform & localTransform) const
|
Transform & localTransform) const
|
||||||
{
|
{
|
||||||
_dbSafeAccessMutex.lock();
|
bool found = false;
|
||||||
this->getNodeDataQuery(signatureId, imageCompressed, depthCompressed, laserScanCompressed, fx, fy, cx, cy, localTransform);
|
// look in the trash
|
||||||
_dbSafeAccessMutex.unlock();
|
_trashesMutex.lock();
|
||||||
|
if(uContains(_trashSignatures, signatureId))
|
||||||
|
{
|
||||||
|
const Signature * s = _trashSignatures.at(signatureId);
|
||||||
|
if(!s->getImageCompressed().empty() || !s->isSaved())
|
||||||
|
{
|
||||||
|
imageCompressed = s->getImageCompressed();
|
||||||
|
depthCompressed = s->getDepthCompressed();
|
||||||
|
laserScanCompressed = s->getLaserScanCompressed();
|
||||||
|
fx = s->getDepthFx();
|
||||||
|
fy = s->getDepthFy();
|
||||||
|
cx = s->getDepthCx();
|
||||||
|
cy = s->getDepthCy();
|
||||||
|
localTransform = s->getLocalTransform();
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_trashesMutex.unlock();
|
||||||
|
|
||||||
|
if(!found)
|
||||||
|
{
|
||||||
|
_dbSafeAccessMutex.lock();
|
||||||
|
this->getNodeDataQuery(signatureId, imageCompressed, depthCompressed, laserScanCompressed, fx, fy, cx, cy, localTransform);
|
||||||
|
_dbSafeAccessMutex.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Check also in the trash ?
|
|
||||||
void DBDriver::getNodeData(int signatureId, cv::Mat & imageCompressed) const
|
void DBDriver::getNodeData(int signatureId, cv::Mat & imageCompressed) const
|
||||||
{
|
{
|
||||||
_dbSafeAccessMutex.lock();
|
bool found = false;
|
||||||
this->getNodeDataQuery(signatureId, imageCompressed);
|
// look in the trash
|
||||||
_dbSafeAccessMutex.unlock();
|
_trashesMutex.lock();
|
||||||
|
if(uContains(_trashSignatures, signatureId))
|
||||||
|
{
|
||||||
|
const Signature * s = _trashSignatures.at(signatureId);
|
||||||
|
if(!s->getImageCompressed().empty() || !s->isSaved())
|
||||||
|
{
|
||||||
|
imageCompressed = s->getImageCompressed();
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_trashesMutex.unlock();
|
||||||
|
|
||||||
|
if(!found)
|
||||||
|
{
|
||||||
|
_dbSafeAccessMutex.lock();
|
||||||
|
this->getNodeDataQuery(signatureId, imageCompressed);
|
||||||
|
_dbSafeAccessMutex.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Check also in the trash ?
|
|
||||||
void DBDriver::getPose(int signatureId, Transform & pose, int & mapId) const
|
void DBDriver::getPose(int signatureId, Transform & pose, int & mapId) const
|
||||||
{
|
{
|
||||||
_dbSafeAccessMutex.lock();
|
bool found = false;
|
||||||
this->getPoseQuery(signatureId, pose, mapId);
|
// look in the trash
|
||||||
_dbSafeAccessMutex.unlock();
|
_trashesMutex.lock();
|
||||||
|
if(uContains(_trashSignatures, signatureId))
|
||||||
|
{
|
||||||
|
pose = _trashSignatures.at(signatureId)->getPose();
|
||||||
|
mapId = _trashSignatures.at(signatureId)->mapId();
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
_trashesMutex.unlock();
|
||||||
|
|
||||||
|
if(!found)
|
||||||
|
{
|
||||||
|
_dbSafeAccessMutex.lock();
|
||||||
|
this->getPoseQuery(signatureId, pose, mapId);
|
||||||
|
_dbSafeAccessMutex.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Check also in the trash ?
|
|
||||||
void DBDriver::loadLinks(int signatureId, std::map<int, Link> & links, Link::Type type) const
|
void DBDriver::loadLinks(int signatureId, std::map<int, Link> & links, Link::Type type) const
|
||||||
{
|
{
|
||||||
_dbSafeAccessMutex.lock();
|
bool found = false;
|
||||||
this->loadLinksQuery(signatureId, links, type);
|
// look in the trash
|
||||||
_dbSafeAccessMutex.unlock();
|
_trashesMutex.lock();
|
||||||
|
if(uContains(_trashSignatures, signatureId))
|
||||||
|
{
|
||||||
|
const Signature * s = _trashSignatures.at(signatureId);
|
||||||
|
UASSERT(s != 0);
|
||||||
|
for(std::multimap<int, Link>::const_iterator nIter = s->getLinks().begin();
|
||||||
|
nIter!=s->getLinks().end();
|
||||||
|
++nIter)
|
||||||
|
{
|
||||||
|
if(type == Link::kUndef || nIter->second.type() == type)
|
||||||
|
{
|
||||||
|
links.insert(*nIter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
_trashesMutex.unlock();
|
||||||
|
|
||||||
|
if(!found)
|
||||||
|
{
|
||||||
|
_dbSafeAccessMutex.lock();
|
||||||
|
this->loadLinksQuery(signatureId, links, type);
|
||||||
|
_dbSafeAccessMutex.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Check also in the trash ?
|
|
||||||
void DBDriver::getWeight(int signatureId, int & weight) const
|
void DBDriver::getWeight(int signatureId, int & weight) const
|
||||||
{
|
{
|
||||||
_dbSafeAccessMutex.lock();
|
bool found = false;
|
||||||
this->getWeightQuery(signatureId, weight);
|
// look in the trash
|
||||||
_dbSafeAccessMutex.unlock();
|
_trashesMutex.lock();
|
||||||
|
if(uContains(_trashSignatures, signatureId))
|
||||||
|
{
|
||||||
|
weight = _trashSignatures.at(signatureId)->getWeight();
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
_trashesMutex.unlock();
|
||||||
|
|
||||||
|
if(!found)
|
||||||
|
{
|
||||||
|
_dbSafeAccessMutex.lock();
|
||||||
|
this->getWeightQuery(signatureId, weight);
|
||||||
|
_dbSafeAccessMutex.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Check also in the trash ?
|
|
||||||
void DBDriver::getAllNodeIds(std::set<int> & ids, bool ignoreChildren) const
|
void DBDriver::getAllNodeIds(std::set<int> & ids, bool ignoreChildren) const
|
||||||
{
|
{
|
||||||
|
// look in the trash
|
||||||
|
_trashesMutex.lock();
|
||||||
|
if(_trashSignatures.size())
|
||||||
|
{
|
||||||
|
for(std::map<int, Signature*>::const_iterator sIter = _trashSignatures.begin(); sIter!=_trashSignatures.end(); ++sIter)
|
||||||
|
{
|
||||||
|
bool hasNeighbors = !ignoreChildren;
|
||||||
|
if(ignoreChildren)
|
||||||
|
{
|
||||||
|
for(std::multimap<int, Link>::const_iterator nIter = sIter->second->getLinks().begin();
|
||||||
|
nIter!=sIter->second->getLinks().end();
|
||||||
|
++nIter)
|
||||||
|
{
|
||||||
|
if(nIter->second.type() == Link::kNeighbor)
|
||||||
|
{
|
||||||
|
hasNeighbors = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(hasNeighbors)
|
||||||
|
{
|
||||||
|
ids.insert(sIter->first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<int> keys = uKeys(_trashSignatures);
|
||||||
|
|
||||||
|
}
|
||||||
|
_trashesMutex.unlock();
|
||||||
|
|
||||||
_dbSafeAccessMutex.lock();
|
_dbSafeAccessMutex.lock();
|
||||||
this->getAllNodeIdsQuery(ids, ignoreChildren);
|
this->getAllNodeIdsQuery(ids, ignoreChildren);
|
||||||
_dbSafeAccessMutex.unlock();
|
_dbSafeAccessMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Check also in the trash ?
|
|
||||||
void DBDriver::getLastNodeId(int & id) const
|
void DBDriver::getLastNodeId(int & id) const
|
||||||
{
|
{
|
||||||
|
// look in the trash
|
||||||
|
_trashesMutex.lock();
|
||||||
|
if(_trashSignatures.size())
|
||||||
|
{
|
||||||
|
id = _trashSignatures.rbegin()->first;
|
||||||
|
}
|
||||||
|
_trashesMutex.unlock();
|
||||||
|
|
||||||
_dbSafeAccessMutex.lock();
|
_dbSafeAccessMutex.lock();
|
||||||
this->getLastIdQuery("Node", id);
|
this->getLastIdQuery("Node", id);
|
||||||
_dbSafeAccessMutex.unlock();
|
_dbSafeAccessMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Check also in the trash ?
|
|
||||||
void DBDriver::getLastWordId(int & id) const
|
void DBDriver::getLastWordId(int & id) const
|
||||||
{
|
{
|
||||||
|
// look in the trash
|
||||||
|
_trashesMutex.lock();
|
||||||
|
if(_trashVisualWords.size())
|
||||||
|
{
|
||||||
|
id = _trashVisualWords.rbegin()->first;
|
||||||
|
}
|
||||||
|
_trashesMutex.unlock();
|
||||||
|
|
||||||
_dbSafeAccessMutex.lock();
|
_dbSafeAccessMutex.lock();
|
||||||
this->getLastIdQuery("Word", id);
|
this->getLastIdQuery("Word", id);
|
||||||
_dbSafeAccessMutex.unlock();
|
_dbSafeAccessMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Check also in the trash ?
|
|
||||||
void DBDriver::getInvertedIndexNi(int signatureId, int & ni) const
|
void DBDriver::getInvertedIndexNi(int signatureId, int & ni) const
|
||||||
{
|
{
|
||||||
_dbSafeAccessMutex.lock();
|
bool found = false;
|
||||||
this->getInvertedIndexNiQuery(signatureId, ni);
|
// look in the trash
|
||||||
_dbSafeAccessMutex.unlock();
|
_trashesMutex.lock();
|
||||||
|
if(uContains(_trashSignatures, signatureId))
|
||||||
|
{
|
||||||
|
ni = _trashSignatures.at(signatureId)->getWords().size();
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
_trashesMutex.unlock();
|
||||||
|
|
||||||
|
if(!found)
|
||||||
|
{
|
||||||
|
_dbSafeAccessMutex.lock();
|
||||||
|
this->getInvertedIndexNiQuery(signatureId, ni);
|
||||||
|
_dbSafeAccessMutex.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBDriver::getNodeIdByLabel(const std::string & label, int & id) const
|
void DBDriver::getNodeIdByLabel(const std::string & label, int & id) const
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ protected:
|
|||||||
virtual void showEvent(QShowEvent* anEvent);
|
virtual void showEvent(QShowEvent* anEvent);
|
||||||
virtual void moveEvent(QMoveEvent* anEvent);
|
virtual void moveEvent(QMoveEvent* anEvent);
|
||||||
virtual void resizeEvent(QResizeEvent* anEvent);
|
virtual void resizeEvent(QResizeEvent* anEvent);
|
||||||
|
virtual bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void changeState(MainWindow::State state);
|
void changeState(MainWindow::State state);
|
||||||
|
|||||||
@@ -173,6 +173,19 @@ MainWindow::MainWindow(PreferencesDialog * prefDialog, QWidget * parent) :
|
|||||||
//_ui->dockWidget_odometry->setVisible(false);
|
//_ui->dockWidget_odometry->setVisible(false);
|
||||||
//_ui->dockWidget_cloudViewer->setVisible(false);
|
//_ui->dockWidget_cloudViewer->setVisible(false);
|
||||||
//_ui->dockWidget_imageView->setVisible(false);
|
//_ui->dockWidget_imageView->setVisible(false);
|
||||||
|
|
||||||
|
// catch resize events
|
||||||
|
_ui->dockWidget_posterior->installEventFilter(this);
|
||||||
|
_ui->dockWidget_likelihood->installEventFilter(this);
|
||||||
|
_ui->dockWidget_rawlikelihood->installEventFilter(this);
|
||||||
|
_ui->dockWidget_statsV2->installEventFilter(this);
|
||||||
|
_ui->dockWidget_console->installEventFilter(this);
|
||||||
|
_ui->dockWidget_loopClosureViewer->installEventFilter(this);
|
||||||
|
_ui->dockWidget_mapVisibility->installEventFilter(this);
|
||||||
|
_ui->dockWidget_graphViewer->installEventFilter(this);
|
||||||
|
_ui->dockWidget_odometry->installEventFilter(this);
|
||||||
|
_ui->dockWidget_cloudViewer->installEventFilter(this);
|
||||||
|
_ui->dockWidget_imageView->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ui->widget_mainWindow->setVisible(false);
|
_ui->widget_mainWindow->setVisible(false);
|
||||||
@@ -2175,6 +2188,15 @@ void MainWindow::resizeEvent(QResizeEvent* anEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::Resize && qobject_cast<QDockWidget*>(obj))
|
||||||
|
{
|
||||||
|
this->setWindowModified(true);
|
||||||
|
}
|
||||||
|
return QWidget::eventFilter(obj, event);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::updateSelectSourceImageMenu(bool used, PreferencesDialog::Src src)
|
void MainWindow::updateSelectSourceImageMenu(bool used, PreferencesDialog::Src src)
|
||||||
{
|
{
|
||||||
_ui->actionUsbCamera->setChecked(used && src == PreferencesDialog::kSrcUsbDevice);
|
_ui->actionUsbCamera->setChecked(used && src == PreferencesDialog::kSrcUsbDevice);
|
||||||
|
|||||||
Reference in New Issue
Block a user