| 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/ViewerSettingsPanelCamera.h> |
| 26 | #include <iostream> |
| 27 | |
| 28 | ViewerSettingsPanelCamera::ViewerSettingsPanelCamera(QWidget *parent) |
| 29 | : QWidget(parent), m_currentFrame(1), m_numberFrames(0), m_robotTrajectoryAvailable(false) |
| 30 | { |
| 31 | ui.setupUi(this); |
| 32 | connect(ui.posX, SIGNAL(valueChanged(double)), this, SLOT(positionEditDone(double))); |
| 33 | connect(ui.posY, SIGNAL(valueChanged(double)), this, SLOT(positionEditDone(double))); |
| 34 | connect(ui.posZ, SIGNAL(valueChanged(double)), this, SLOT(positionEditDone(double))); |
| 35 | connect(ui.lookX, SIGNAL(valueChanged(double)), this, SLOT(positionEditDone(double))); |
| 36 | connect(ui.lookY, SIGNAL(valueChanged(double)), this, SLOT(positionEditDone(double))); |
| 37 | connect(ui.lookZ, SIGNAL(valueChanged(double)), this, SLOT(positionEditDone(double))); |
| 38 | |
| 39 | ui.followTrajectoryButton->setEnabled(m_robotTrajectoryAvailable); |
| 40 | dataChanged(); |
| 41 | } |
| 42 | |
| 43 | ViewerSettingsPanelCamera::~ViewerSettingsPanelCamera() |
| 44 | { |
| 45 | |
| 46 | } |
| 47 | |
| 48 | QSize ViewerSettingsPanelCamera::sizeHint() const { |
| 49 | return QSize(250, 180); |
| 50 | } |
| 51 | |
| 52 | void ViewerSettingsPanelCamera::positionEditDone(double){ |
| 53 | emit changeCamPosition(ui.posX->value(), ui.posY->value(), ui.posZ->value(), ui.lookX->value(), ui.lookY->value(), ui.lookZ->value()); |
| 54 | } |
| 55 | |
| 56 | void ViewerSettingsPanelCamera::setNumberOfFrames(unsigned frames){ |
| 57 | m_numberFrames = frames; |
| 58 | dataChanged(); |
| 59 | } |
| 60 | |
| 61 | void ViewerSettingsPanelCamera::setCurrentFrame(unsigned frame){ |
| 62 | m_currentFrame = frame; |
| 63 | dataChanged(); |
| 64 | } |
| 65 | |
| 66 | void ViewerSettingsPanelCamera::setRobotTrajectoryAvailable(bool available) { |
| 67 | m_robotTrajectoryAvailable = available; |
| 68 | if(!available) ui.followTrajectoryButton->setChecked(false); |
| 69 | ui.followTrajectoryButton->setEnabled(available); |
| 70 | } |
| 71 | |
| 72 | void ViewerSettingsPanelCamera::gotoFrame(unsigned int frame) { |
| 73 | if(frame > 0 && frame <= m_numberFrames) { |
| 74 | m_currentFrame = frame; |
| 75 | emit jumpToFrame(m_currentFrame); |
| 76 | dataChanged(); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void ViewerSettingsPanelCamera::on_nextScanButton_clicked(){ |
| 81 | gotoFrame(m_currentFrame + 1); |
| 82 | } |
| 83 | |
| 84 | void ViewerSettingsPanelCamera::on_previousScanButton_clicked(){ |
| 85 | gotoFrame(m_currentFrame - 1); |
| 86 | } |
| 87 | |
| 88 | void ViewerSettingsPanelCamera::on_firstScanButton_clicked(){ |
| 89 | gotoFrame(1); |
| 90 | } |
| 91 | |
| 92 | void ViewerSettingsPanelCamera::on_lastScanButton_clicked(){ |
| 93 | gotoFrame(m_numberFrames); |
| 94 | } |
| 95 | |
| 96 | void ViewerSettingsPanelCamera::on_followCameraPathButton_clicked(){ |
| 97 | emit followCameraPath(); |
| 98 | } |
| 99 | |
| 100 | void ViewerSettingsPanelCamera::on_followTrajectoryButton_clicked(){ |
| 101 | emit followRobotPath(); |
| 102 | } |
| 103 | |
| 104 | void ViewerSettingsPanelCamera::on_cameraPathAdd_clicked(){ |
| 105 | emit addToCameraPath(); |
| 106 | } |
| 107 | |
| 108 | void ViewerSettingsPanelCamera::on_cameraPathRemove_clicked(){ |
| 109 | emit removeFromCameraPath(); |
| 110 | } |
| 111 | |
| 112 | void ViewerSettingsPanelCamera::on_cameraPathClear_clicked(){ |
| 113 | emit clearCameraPath(); |
| 114 | } |
| 115 | |
| 116 | void ViewerSettingsPanelCamera::on_cameraPathSave_clicked(){ |
| 117 | emit saveToCameraPath(); |
| 118 | } |
| 119 | |
| 120 | void ViewerSettingsPanelCamera::on_playScanButton_clicked(){ |
| 121 | if(ui.playScanButton->isChecked()) { |
| 122 | ui.scanProgressSlider->setEnabled(false); |
| 123 | ui.followGroupBox->setEnabled(false); |
| 124 | emit play(); |
| 125 | } else { |
| 126 | ui.scanProgressSlider->setEnabled(true); |
| 127 | ui.followGroupBox->setEnabled(true); |
| 128 | emit pause(); |
| 129 | } |
| 130 | dataChanged(); |
| 131 | } |
| 132 | |
| 133 | void ViewerSettingsPanelCamera::on_scanProgressSlider_sliderMoved(int value) { |
| 134 | gotoFrame(value); |
| 135 | } |
| 136 | |
| 137 | void ViewerSettingsPanelCamera::setStopped(){ |
| 138 | ui.followGroupBox->setEnabled(true); |
| 139 | ui.scanProgressSlider->setEnabled(true); |
| 140 | ui.playScanButton->setChecked(false); |
| 141 | dataChanged(); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | void ViewerSettingsPanelCamera::dataChanged(){ |
| 146 | unsigned int max = std::max(0,int(m_numberFrames)); |
| 147 | unsigned int cur = std::min(max, m_currentFrame); |
| 148 | |
| 149 | ui.scanProgressSlider->setMaximum(max); |
| 150 | ui.scanProgressSlider->setMinimum(1); |
| 151 | |
| 152 | if(ui.playScanButton->isChecked()) { |
| 153 | ui.firstScanButton->setEnabled(false); |
| 154 | ui.nextScanButton->setEnabled(false); |
| 155 | ui.previousScanButton->setEnabled(false); |
| 156 | ui.lastScanButton->setEnabled(false); |
| 157 | } else { |
| 158 | if (m_currentFrame >= max){ |
| 159 | ui.nextScanButton->setEnabled(false); |
| 160 | ui.playScanButton->setEnabled(false); |
| 161 | ui.lastScanButton->setEnabled(false); |
| 162 | } else { |
| 163 | ui.nextScanButton->setEnabled(true); |
| 164 | ui.playScanButton->setEnabled(true); |
| 165 | ui.lastScanButton->setEnabled(true); |
| 166 | } |
| 167 | |
| 168 | if (m_currentFrame < 2){ |
| 169 | ui.firstScanButton->setEnabled(cur > 0); |
| 170 | ui.previousScanButton->setEnabled(false); |
| 171 | } else{ |
| 172 | ui.firstScanButton->setEnabled(true); |
| 173 | ui.previousScanButton->setEnabled(true); |
| 174 | } |
| 175 | |
| 176 | if (max > 1) { |
| 177 | ui.playScanButton->setEnabled(true); |
| 178 | } else { |
| 179 | ui.playScanButton->setEnabled(false); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | if(followRobotTrajectory() || ui.playScanButton->isChecked()) { |
| 184 | ui.cameraPathAdd->setEnabled(false); |
| 185 | ui.cameraPathRemove->setEnabled(false); |
| 186 | ui.cameraPathSave->setEnabled(false); |
| 187 | ui.cameraPathClear->setEnabled(false); |
| 188 | } else { |
| 189 | ui.cameraPathAdd->setEnabled(true); |
| 190 | ui.cameraPathRemove->setEnabled(m_numberFrames > 0); |
| 191 | ui.cameraPathSave->setEnabled(m_numberFrames > 0); |
| 192 | ui.cameraPathClear->setEnabled(m_numberFrames > 0); |
| 193 | } |
| 194 | |
| 195 | if(max > 0 && !ui.playScanButton->isChecked()) { |
| 196 | ui.scanProgressSlider->setEnabled(true); |
| 197 | } else { |
| 198 | ui.scanProgressSlider->setEnabled(false); |
| 199 | } |
| 200 | |
| 201 | ui.scanProgressSlider->setValue(cur); |
| 202 | ui.scanProgressLabel->setText(QString("%1/%2").arg(cur).arg(max)); |
| 203 | |
| 204 | // queue a redraw: |
| 205 | ui.scanProgressSlider->update(); |
| 206 | |
| 207 | } |
| 208 | |
| 209 | bool ViewerSettingsPanelCamera::followRobotTrajectory(){ |
| 210 | return ui.followTrajectoryButton->isChecked(); |
| 211 | } |
| 212 | |
| 213 |