CameraFollowMode.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of OctoMap - An Efficient Probabilistic 3D Mapping
00003  * Framework Based on Octrees
00004  * http://octomap.github.io
00005  *
00006  * Copyright (c) 2009-2014, K.M. Wurm and A. Hornung, University of Freiburg
00007  * All rights reserved. License for the viewer octovis: GNU GPL v2
00008  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
00009  *
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00018  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00019  * for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program. If not, see http://www.gnu.org/licenses/.
00023  */
00024 
00025 #include <octovis/CameraFollowMode.h>
00026 #include <iostream>
00027 
00028 #define CAMERA_PATH_ID 13
00029 #define ROBOT_TRAJECTORY_ID 14
00030 
00031 CameraFollowMode::CameraFollowMode(octomap::ScanGraph *graph)
00032 : QObject(), m_scan_graph(graph), m_current_scan(1), m_current_cam_frame(1), m_number_cam_frames(0),
00033   m_followRobotTrajectory(false) {
00034 }
00035 
00036 CameraFollowMode::~CameraFollowMode() {
00037 }
00038 
00039 
00040 void CameraFollowMode::jumpToFrame(unsigned int frame) {
00041   if(m_followRobotTrajectory) {
00042     if(frame <= m_scan_graph->size()) {
00043       m_current_scan = frame;
00044       octomath::Pose6D pose = m_scan_graph->getNodeByID(frame-1)->pose;
00045       emit changeCamPose(pose);
00046     }
00047   } else {
00048     m_current_cam_frame = frame;
00049     emit jumpToCamFrame(CAMERA_PATH_ID, m_current_cam_frame-1);
00050   }
00051 }
00052 
00053 void CameraFollowMode::play() {
00054   if(m_followRobotTrajectory) {
00055     emit deleteCameraPath(ROBOT_TRAJECTORY_ID);
00056     //emit appendCurrentToCameraPath(ROBOT_TRAJECTORY_ID);
00057     m_start_frame = m_current_scan;
00058     for(unsigned int i = m_start_frame; i <= m_scan_graph->size(); i++) {
00059       octomap::ScanNode* scanNode = m_scan_graph->getNodeByID(i-1);
00060       if (scanNode)
00061         emit appendToCameraPath(ROBOT_TRAJECTORY_ID, scanNode->pose);
00062       else{
00063         std::cerr << "Error in " << __FILE__ << ":" << __LINE__ <<" : invalid node ID "<< i-1 << std::endl;
00064       }
00065     }
00066     emit playCameraPath(ROBOT_TRAJECTORY_ID, 0);
00067   } else {
00068     m_start_frame = m_current_cam_frame;
00069     emit playCameraPath(CAMERA_PATH_ID, m_start_frame-1);
00070   }
00071 }
00072 
00073 void CameraFollowMode::pause() {
00074   emit stopCameraPath(CAMERA_PATH_ID);
00075   emit stopCameraPath(ROBOT_TRAJECTORY_ID);
00076 }
00077 
00078 
00079 void CameraFollowMode::setScanGraph(octomap::ScanGraph *graph) {
00080   m_scan_graph = graph;
00081   emit scanGraphAvailable(true);
00082 }
00083 
00084 void CameraFollowMode::cameraPathStopped(int id) {
00085   if(id == CAMERA_PATH_ID || id == ROBOT_TRAJECTORY_ID) {
00086     emit stopped();
00087   }
00088 }
00089 
00090 void CameraFollowMode::cameraPathFrameChanged(int id, int current_camera_frame) {
00091   if(m_followRobotTrajectory) {
00092     m_current_scan = m_start_frame + current_camera_frame;
00093     emit frameChanged(m_current_scan);
00094   } else {
00095     m_current_cam_frame = m_start_frame + current_camera_frame;
00096     emit frameChanged(m_current_cam_frame);
00097   }
00098 }
00099 
00100 void CameraFollowMode::clearCameraPath() {
00101   emit deleteCameraPath(CAMERA_PATH_ID);
00102   m_current_cam_frame = 1;
00103   m_number_cam_frames = 0;
00104   emit frameChanged(m_current_cam_frame);
00105   emit changeNumberOfFrames(m_number_cam_frames);
00106 }
00107 
00108 void CameraFollowMode::saveToCameraPath() {
00109   emit updateCameraPath(CAMERA_PATH_ID, m_current_cam_frame-1);
00110 }
00111 
00112 void CameraFollowMode::addToCameraPath() {
00113   emit addCurrentToCameraPath(CAMERA_PATH_ID, m_current_cam_frame-1);
00114   m_number_cam_frames++;
00115   if(m_number_cam_frames == 1) m_current_cam_frame = 1;
00116   else m_current_cam_frame++;
00117   emit frameChanged(m_current_cam_frame);
00118   emit changeNumberOfFrames(m_number_cam_frames);
00119 }
00120 
00121 void CameraFollowMode::removeFromCameraPath() {
00122   if(m_number_cam_frames>0) {
00123     emit removeFromCameraPath(CAMERA_PATH_ID, m_current_cam_frame-1);
00124     m_number_cam_frames--;
00125     emit changeNumberOfFrames(m_number_cam_frames);
00126   }
00127 }
00128 
00129 void CameraFollowMode::followCameraPath() {
00130   m_followRobotTrajectory = false;
00131   emit frameChanged(m_current_cam_frame);
00132   emit changeNumberOfFrames(m_number_cam_frames);
00133 }
00134 
00135 void CameraFollowMode::followRobotPath() {
00136   if(m_scan_graph) {
00137     m_followRobotTrajectory = true;
00138     emit frameChanged(m_current_scan);
00139     emit changeNumberOfFrames(m_scan_graph->size());
00140   }
00141 }


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Feb 11 2016 23:51:19