refactored DBDriver (fixed the TODOs)

This commit is contained in:
Mathieu Labbe
2015-02-27 19:33:32 -05:00
parent 8625ebaf5c
commit 1588b0b25c
3 changed files with 205 additions and 32 deletions

View File

@@ -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,
@@ -413,75 +420,218 @@ void DBDriver::getNodeData(
float & cx, float & cx,
float & cy, float & cy,
Transform & localTransform) const Transform & localTransform) const
{
bool found = false;
// look in the trash
_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(); _dbSafeAccessMutex.lock();
this->getNodeDataQuery(signatureId, imageCompressed, depthCompressed, laserScanCompressed, fx, fy, cx, cy, localTransform); this->getNodeDataQuery(signatureId, imageCompressed, depthCompressed, laserScanCompressed, fx, fy, cx, cy, localTransform);
_dbSafeAccessMutex.unlock(); _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
{
bool found = false;
// look in the trash
_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(); _dbSafeAccessMutex.lock();
this->getNodeDataQuery(signatureId, imageCompressed); this->getNodeDataQuery(signatureId, imageCompressed);
_dbSafeAccessMutex.unlock(); _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
{
bool found = false;
// look in the trash
_trashesMutex.lock();
if(uContains(_trashSignatures, signatureId))
{
pose = _trashSignatures.at(signatureId)->getPose();
mapId = _trashSignatures.at(signatureId)->mapId();
found = true;
}
_trashesMutex.unlock();
if(!found)
{ {
_dbSafeAccessMutex.lock(); _dbSafeAccessMutex.lock();
this->getPoseQuery(signatureId, pose, mapId); this->getPoseQuery(signatureId, pose, mapId);
_dbSafeAccessMutex.unlock(); _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
{
bool found = false;
// look in the trash
_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(); _dbSafeAccessMutex.lock();
this->loadLinksQuery(signatureId, links, type); this->loadLinksQuery(signatureId, links, type);
_dbSafeAccessMutex.unlock(); _dbSafeAccessMutex.unlock();
} }
}
//TODO Check also in the trash ?
void DBDriver::getWeight(int signatureId, int & weight) const void DBDriver::getWeight(int signatureId, int & weight) const
{
bool found = false;
// look in the trash
_trashesMutex.lock();
if(uContains(_trashSignatures, signatureId))
{
weight = _trashSignatures.at(signatureId)->getWeight();
found = true;
}
_trashesMutex.unlock();
if(!found)
{ {
_dbSafeAccessMutex.lock(); _dbSafeAccessMutex.lock();
this->getWeightQuery(signatureId, weight); this->getWeightQuery(signatureId, weight);
_dbSafeAccessMutex.unlock(); _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
{
bool found = false;
// look in the trash
_trashesMutex.lock();
if(uContains(_trashSignatures, signatureId))
{
ni = _trashSignatures.at(signatureId)->getWords().size();
found = true;
}
_trashesMutex.unlock();
if(!found)
{ {
_dbSafeAccessMutex.lock(); _dbSafeAccessMutex.lock();
this->getInvertedIndexNiQuery(signatureId, ni); this->getInvertedIndexNiQuery(signatureId, ni);
_dbSafeAccessMutex.unlock(); _dbSafeAccessMutex.unlock();
} }
}
void DBDriver::getNodeIdByLabel(const std::string & label, int & id) const void DBDriver::getNodeIdByLabel(const std::string & label, int & id) const
{ {

View File

@@ -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);

View File

@@ -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);