MapVisibilityWidget.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #include "MapVisibilityWidget.h"
00029 
00030 #include <QCheckBox>
00031 #include <QVBoxLayout>
00032 #include <QScrollArea>
00033 
00034 #include <rtabmap/utilite/ULogger.h>
00035 
00036 namespace rtabmap {
00037 
00038 MapVisibilityWidget::MapVisibilityWidget(QWidget * parent) : QWidget(parent) {
00039 
00040         QVBoxLayout * verticalLayout1 = new QVBoxLayout(this);
00041         QScrollArea * scrollArea = new QScrollArea(this);
00042         scrollArea->setWidgetResizable(true);
00043         QWidget * scrollAreaWidgetContent = new QWidget();
00044         scrollAreaWidgetContent->setObjectName("area");
00045         QVBoxLayout * layout2 = new QVBoxLayout(scrollAreaWidgetContent);
00046         scrollAreaWidgetContent->setLayout(layout2);
00047         scrollArea->setWidget(scrollAreaWidgetContent);
00048         verticalLayout1->addWidget(scrollArea);
00049 }
00050 
00051 MapVisibilityWidget::~MapVisibilityWidget() {
00052 
00053 }
00054 
00055 void MapVisibilityWidget::showEvent(QShowEvent * event)
00056 {
00057         updateCheckBoxes();
00058 }
00059 
00060 void MapVisibilityWidget::clear()
00061 {
00062         _poses.clear();
00063         _mask.clear();
00064         updateCheckBoxes();
00065 }
00066 
00067 void MapVisibilityWidget::updateCheckBoxes()
00068 {
00069         QWidget * area = this->findChild<QWidget*>("area");
00070         QVBoxLayout * layout = (QVBoxLayout *)area->layout();
00071         QList<QCheckBox*> checkboxes = area->findChildren<QCheckBox*>();
00072         while(checkboxes.size() && checkboxes.size() > (int)_poses.size())
00073         {
00074                 delete *checkboxes.begin();
00075                 checkboxes.erase(checkboxes.begin());
00076         }
00077         int i=0;
00078         for(std::map<int, Transform>::iterator iter=_poses.begin(); iter!=_poses.end(); ++iter)
00079         {
00080                 bool added = false;
00081                 if(i >= checkboxes.size())
00082                 {
00083                         checkboxes.push_back(new QCheckBox(area));
00084                         added = true;
00085                 }
00086                 checkboxes[i]->setText(QString("%1 (%2)").arg(iter->first).arg(iter->second.prettyPrint().c_str()));
00087                 checkboxes[i]->setChecked(_mask.at(iter->first));
00088                 if(added)
00089                 {
00090                         connect(checkboxes[i], SIGNAL(stateChanged(int)), this, SLOT(signalVisibility()));
00091                         layout->addWidget(checkboxes[i]);
00092                 }
00093 
00094                 ++i;
00095         }
00096 }
00097 
00098 void MapVisibilityWidget::setMap(const std::map<int, Transform> & poses, const std::map<int, bool> & mask)
00099 {
00100         UASSERT(poses.size() == mask.size());
00101         _poses = poses;
00102         _mask = mask;
00103         if(this->isVisible())
00104         {
00105                 updateCheckBoxes();
00106         }
00107 }
00108 
00109 std::map<int, Transform> MapVisibilityWidget::getVisiblePoses() const
00110 {
00111         std::map<int, Transform> poses;
00112         for(std::map<int, Transform>::const_iterator iter=_poses.begin(); iter!=_poses.end(); ++iter)
00113         {
00114                 if(_mask.at(iter->first))
00115                 {
00116                         poses.insert(*iter);
00117                 }
00118         }
00119         return poses;
00120 }
00121 
00122 void MapVisibilityWidget::signalVisibility()
00123 {
00124         QCheckBox * check = qobject_cast<QCheckBox*>(sender());
00125         _mask.at(check->text().split('(').first().toInt()) = check->isChecked();
00126         emit visibilityChanged(check->text().split('(').first().toInt(), check->isChecked());
00127 }
00128 
00129 } /* namespace rtabmap */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Fri Aug 28 2015 12:51:32