| 1 | /* |
| 2 | * This file is part of OctoMap - An Efficient Probabilistic 3D Mapping |
| 3 | * Framework Based on Octrees |
| 4 | * http://octomap.github.io |
| 5 | * |
| 6 | * Copyright (c) 2009-2014, K.M. Wurm and A. Hornung, University of Freiburg |
| 7 | * All rights reserved. License for the viewer octovis: GNU GPL v2 |
| 8 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt |
| 9 | * |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 19 | * for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see http://www.gnu.org/licenses/. |
| 23 | */ |
| 24 | |
| 25 | #include <octovis/ViewerSettingsPanel.h> |
| 26 | |
| 27 | ViewerSettingsPanel::ViewerSettingsPanel(QWidget *parent) |
| 28 | : QWidget(parent), m_currentScan(0), m_numberScans(0), m_treeDepth(_TREE_MAX_DEPTH), m_resolution(0.1) |
| 29 | { |
| 30 | ui.setupUi(this); |
| 31 | connect(ui.treeDepth, SIGNAL(valueChanged(int)), this, SLOT(setTreeDepth(int))); |
| 32 | |
| 33 | scanProgressChanged(); |
| 34 | leafSizeChanged(); |
| 35 | } |
| 36 | |
| 37 | ViewerSettingsPanel::~ViewerSettingsPanel() |
| 38 | { |
| 39 | |
| 40 | } |
| 41 | |
| 42 | void ViewerSettingsPanel::on_nextScanButton_clicked(){ |
| 43 | if (m_currentScan < m_numberScans){ |
| 44 | m_currentScan++; |
| 45 | scanProgressChanged(); |
| 46 | emit addNextScans(1); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void ViewerSettingsPanel::on_fastFwdScanButton_clicked(){ |
| 51 | unsigned increase = int(m_numberScans)-int(m_currentScan); |
| 52 | if (increase > 5) increase = 5; |
| 53 | m_currentScan += increase; |
| 54 | scanProgressChanged(); |
| 55 | emit addNextScans(increase); |
| 56 | } |
| 57 | |
| 58 | void ViewerSettingsPanel::on_lastScanButton_clicked(){ |
| 59 | unsigned increase = int(m_numberScans)-int(m_currentScan); |
| 60 | m_currentScan += increase; |
| 61 | scanProgressChanged(); |
| 62 | emit addNextScans(increase); |
| 63 | } |
| 64 | |
| 65 | void ViewerSettingsPanel::on_firstScanButton_clicked(){ |
| 66 | m_currentScan = 1; |
| 67 | scanProgressChanged(); |
| 68 | emit gotoFirstScan(); |
| 69 | } |
| 70 | |
| 71 | void ViewerSettingsPanel::scanProgressChanged(){ |
| 72 | if (int(m_numberScans) > 1) |
| 73 | ui.scanProgressBar->setMaximum(int(m_numberScans)); |
| 74 | else |
| 75 | ui.scanProgressBar->setMaximum(1); |
| 76 | |
| 77 | if (m_currentScan == m_numberScans){ |
| 78 | ui.nextScanButton->setEnabled(false); |
| 79 | ui.fastFwdScanButton->setEnabled(false); |
| 80 | ui.lastScanButton->setEnabled(false); |
| 81 | |
| 82 | } else{ |
| 83 | ui.nextScanButton->setEnabled(true); |
| 84 | ui.fastFwdScanButton->setEnabled(true); |
| 85 | ui.lastScanButton->setEnabled(true); |
| 86 | } |
| 87 | |
| 88 | if (m_currentScan < 2){ |
| 89 | ui.firstScanButton->setEnabled(false); |
| 90 | } else{ |
| 91 | ui.firstScanButton->setEnabled(true); |
| 92 | } |
| 93 | |
| 94 | ui.scanProgressBar->setValue(m_currentScan); |
| 95 | // queue a redraw: |
| 96 | ui.scanProgressBar->update(); |
| 97 | } |
| 98 | |
| 99 | void ViewerSettingsPanel::setNumberOfScans(unsigned scans){ |
| 100 | m_numberScans = scans; |
| 101 | scanProgressChanged(); |
| 102 | } |
| 103 | |
| 104 | void ViewerSettingsPanel::setCurrentScan(unsigned scan){ |
| 105 | m_currentScan = scan; |
| 106 | scanProgressChanged(); |
| 107 | } |
| 108 | |
| 109 | void ViewerSettingsPanel::setResolution(double resolution){ |
| 110 | m_resolution = resolution; |
| 111 | leafSizeChanged(); |
| 112 | } |
| 113 | |
| 114 | void ViewerSettingsPanel::setTreeDepth(int depth){ |
| 115 | emit treeDepthChanged(depth); |
| 116 | m_treeDepth = depth; |
| 117 | ui.treeDepth->setValue(depth); |
| 118 | ui.treeDepthSlider->setValue(depth); |
| 119 | leafSizeChanged(); |
| 120 | } |
| 121 | |
| 122 | void ViewerSettingsPanel::leafSizeChanged(){ |
| 123 | double leafSize = m_resolution * pow(2.0, (int) (_TREE_MAX_DEPTH-m_treeDepth)); |
| 124 | ui.leafSize->setText(QString::number(leafSize)+" m"); |
| 125 | } |