MapVisibilityWidget.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
29 
30 #include <QCheckBox>
31 #include <QVBoxLayout>
32 #include <QScrollArea>
33 
35 
36 namespace rtabmap {
37 
38 MapVisibilityWidget::MapVisibilityWidget(QWidget * parent) : QWidget(parent) {
39 
40  QVBoxLayout * verticalLayout1 = new QVBoxLayout(this);
41  QScrollArea * scrollArea = new QScrollArea(this);
42  scrollArea->setWidgetResizable(true);
43  QWidget * scrollAreaWidgetContent = new QWidget();
44  scrollAreaWidgetContent->setObjectName("area");
45  QVBoxLayout * layout2 = new QVBoxLayout(scrollAreaWidgetContent);
46  scrollAreaWidgetContent->setLayout(layout2);
47  scrollArea->setWidget(scrollAreaWidgetContent);
48 
49  QCheckBox * selectAll = new QCheckBox("Select all", this);
50  connect(selectAll, SIGNAL(toggled(bool)), this, SLOT(selectAll(bool)));
51  verticalLayout1->addWidget(selectAll);
52  verticalLayout1->addWidget(scrollArea);
53 }
54 
56 
57 }
58 
59 void MapVisibilityWidget::showEvent(QShowEvent * event)
60 {
62 }
63 
65 {
66  _poses.clear();
67  _mask.clear();
69 }
70 
72 {
73  QWidget * area = this->findChild<QWidget*>("area");
74  QVBoxLayout * layout = (QVBoxLayout *)area->layout();
75  QList<QCheckBox*> checkboxes = area->findChildren<QCheckBox*>();
76  while(checkboxes.size() && checkboxes.size() > (int)_poses.size())
77  {
78  delete *checkboxes.begin();
79  checkboxes.erase(checkboxes.begin());
80  }
81  int i=0;
82  for(std::map<int, Transform>::iterator iter=_poses.begin(); iter!=_poses.end(); ++iter)
83  {
84  bool added = false;
85  if(i >= checkboxes.size())
86  {
87  checkboxes.push_back(new QCheckBox(area));
88  added = true;
89  }
90  checkboxes[i]->setText(QString("%1 (%2)").arg(iter->first).arg(iter->second.prettyPrint().c_str()));
91  checkboxes[i]->setChecked(_mask.at(iter->first));
92  if(added)
93  {
94  connect(checkboxes[i], SIGNAL(stateChanged(int)), this, SLOT(signalVisibility()));
95  layout->addWidget(checkboxes[i]);
96  }
97 
98  ++i;
99  }
100 }
101 
102 void MapVisibilityWidget::setMap(const std::map<int, Transform> & poses, const std::map<int, bool> & mask)
103 {
104  UASSERT(poses.size() == mask.size());
105  _poses = poses;
106  _mask = mask;
107  if(this->isVisible())
108  {
110  }
111 }
112 
113 std::map<int, Transform> MapVisibilityWidget::getVisiblePoses() const
114 {
115  std::map<int, Transform> poses;
116  for(std::map<int, Transform>::const_iterator iter=_poses.begin(); iter!=_poses.end(); ++iter)
117  {
118  if(_mask.at(iter->first) && iter->first > 0)
119  {
120  poses.insert(*iter);
121  }
122  }
123  return poses;
124 }
125 
127 {
128  QCheckBox * check = qobject_cast<QCheckBox*>(sender());
129  _mask.at(check->text().split('(').first().toInt()) = check->isChecked();
130  Q_EMIT visibilityChanged(check->text().split('(').first().toInt(), check->isChecked());
131 }
132 
134 {
135  QWidget * area = this->findChild<QWidget*>("area");
136  QList<QCheckBox*> checkboxes = area->findChildren<QCheckBox*>();
137  for(int i = 0; i<checkboxes.size(); ++i)
138  {
139  checkboxes[i]->setChecked(checked);
140  }
141 }
142 
143 } /* namespace rtabmap */
check
check
int
int
glm::mask
GLM_FUNC_DECL genIType mask(genIType const &count)
rtabmap::MapVisibilityWidget::~MapVisibilityWidget
virtual ~MapVisibilityWidget()
Definition: MapVisibilityWidget.cpp:55
MapVisibilityWidget.h
rtabmap::MapVisibilityWidget::visibilityChanged
void visibilityChanged(int id, bool visible)
rtabmap::MapVisibilityWidget::showEvent
virtual void showEvent(QShowEvent *event)
Definition: MapVisibilityWidget.cpp:59
rtabmap::MapVisibilityWidget::MapVisibilityWidget
MapVisibilityWidget(QWidget *parent=0)
Definition: MapVisibilityWidget.cpp:38
rtabmap::MapVisibilityWidget::setMap
void setMap(const std::map< int, Transform > &poses, const std::map< int, bool > &mask)
Definition: MapVisibilityWidget.cpp:102
rtabmap::MapVisibilityWidget::_poses
std::map< int, Transform > _poses
Definition: MapVisibilityWidget.h:64
UASSERT
#define UASSERT(condition)
rtabmap::MapVisibilityWidget::selectAll
void selectAll(bool)
Definition: MapVisibilityWidget.cpp:133
ULogger.h
ULogger class and convenient macros.
rtabmap::MapVisibilityWidget::getVisiblePoses
std::map< int, Transform > getVisiblePoses() const
Definition: MapVisibilityWidget.cpp:113
iter
iterator iter(handle obj)
rtabmap::MapVisibilityWidget::_mask
std::map< int, bool > _mask
Definition: MapVisibilityWidget.h:65
rtabmap::MapVisibilityWidget::signalVisibility
void signalVisibility()
Definition: MapVisibilityWidget.cpp:126
rtabmap::MapVisibilityWidget::updateCheckBoxes
void updateCheckBoxes()
Definition: MapVisibilityWidget.cpp:71
rtabmap
Definition: CameraARCore.cpp:35
i
int i
rtabmap::MapVisibilityWidget::clear
void clear()
Definition: MapVisibilityWidget.cpp:64


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:12