Debian Codegraph @

octovis/src/CameraFollowMode.cpp

raw symbols SCIP
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/CameraFollowMode.h>
26 #include <iostream>
27
28 #define CAMERA_PATH_ID 13
29 #define ROBOT_TRAJECTORY_ID 14
30
31 CameraFollowMode::CameraFollowMode(octomap::ScanGraph *graph)
32 : QObject(), m_scan_graph(graph), m_current_scan(1), m_current_cam_frame(1), m_number_cam_frames(0),
33 m_followRobotTrajectory(false) {
34 }
35
36 CameraFollowMode::~CameraFollowMode() {
37 }
38
39
40 void CameraFollowMode::jumpToFrame(unsigned int frame) {
41 if(m_followRobotTrajectory) {
42 if(frame <= m_scan_graph->size()) {
43 m_current_scan = frame;
44 octomath::Pose6D pose = m_scan_graph->getNodeByID(frame-1)->pose;
45 emit changeCamPose(pose);
46 }
47 } else {
48 m_current_cam_frame = frame;
49 emit jumpToCamFrame(CAMERA_PATH_ID, m_current_cam_frame-1);
50 }
51 }
52
53 void CameraFollowMode::play() {
54 if(m_followRobotTrajectory) {
55 emit deleteCameraPath(ROBOT_TRAJECTORY_ID);
56 //emit appendCurrentToCameraPath(ROBOT_TRAJECTORY_ID);
57 m_start_frame = m_current_scan;
58 for(unsigned int i = m_start_frame; i <= m_scan_graph->size(); i++) {
59 octomap::ScanNode* scanNode = m_scan_graph->getNodeByID(i-1);
60 if (scanNode)
61 emit appendToCameraPath(ROBOT_TRAJECTORY_ID, scanNode->pose);
62 else{
63 std::cerr << "Error in " << __FILE__ << ":" << __LINE__ <<" : invalid node ID "<< i-1 << std::endl;
64 }
65 }
66 emit playCameraPath(ROBOT_TRAJECTORY_ID, 0);
67 } else {
68 m_start_frame = m_current_cam_frame;
69 emit playCameraPath(CAMERA_PATH_ID, m_start_frame-1);
70 }
71 }
72
73 void CameraFollowMode::pause() {
74 emit stopCameraPath(CAMERA_PATH_ID);
75 emit stopCameraPath(ROBOT_TRAJECTORY_ID);
76 }
77
78
79 void CameraFollowMode::setScanGraph(octomap::ScanGraph *graph) {
80 m_scan_graph = graph;
81 emit scanGraphAvailable(true);
82 }
83
84 void CameraFollowMode::cameraPathStopped(int id) {
85 if(id == CAMERA_PATH_ID || id == ROBOT_TRAJECTORY_ID) {
86 emit stopped();
87 }
88 }
89
90 void CameraFollowMode::cameraPathFrameChanged(int id, int current_camera_frame) {
91 if(m_followRobotTrajectory) {
92 m_current_scan = m_start_frame + current_camera_frame;
93 emit frameChanged(m_current_scan);
94 } else {
95 m_current_cam_frame = m_start_frame + current_camera_frame;
96 emit frameChanged(m_current_cam_frame);
97 }
98 }
99
100 void CameraFollowMode::clearCameraPath() {
101 emit deleteCameraPath(CAMERA_PATH_ID);
102 m_current_cam_frame = 1;
103 m_number_cam_frames = 0;
104 emit frameChanged(m_current_cam_frame);
105 emit changeNumberOfFrames(m_number_cam_frames);
106 }
107
108 void CameraFollowMode::saveToCameraPath() {
109 emit updateCameraPath(CAMERA_PATH_ID, m_current_cam_frame-1);
110 }
111
112 void CameraFollowMode::addToCameraPath() {
113 emit addCurrentToCameraPath(CAMERA_PATH_ID, m_current_cam_frame-1);
114 m_number_cam_frames++;
115 if(m_number_cam_frames == 1) m_current_cam_frame = 1;
116 else m_current_cam_frame++;
117 emit frameChanged(m_current_cam_frame);
118 emit changeNumberOfFrames(m_number_cam_frames);
119 }
120
121 void CameraFollowMode::removeFromCameraPath() {
122 if(m_number_cam_frames>0) {
123 emit removeFromCameraPath(CAMERA_PATH_ID, m_current_cam_frame-1);
124 m_number_cam_frames--;
125 emit changeNumberOfFrames(m_number_cam_frames);
126 }
127 }
128
129 void CameraFollowMode::followCameraPath() {
130 m_followRobotTrajectory = false;
131 emit frameChanged(m_current_cam_frame);
132 emit changeNumberOfFrames(m_number_cam_frames);
133 }
134
135 void CameraFollowMode::followRobotPath() {
136 if(m_scan_graph) {
137 m_followRobotTrajectory = true;
138 emit frameChanged(m_current_scan);
139 emit changeNumberOfFrames(m_scan_graph->size());
140 }
141 }