graph_manager.h
Go to the documentation of this file.
00001 /* This file is part of RGBDSLAM.
00002  * 
00003  * RGBDSLAM is free software: you can redistribute it and/or modify
00004  * it under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation, either version 3 of the License, or
00006  * (at your option) any later version.
00007  * 
00008  * RGBDSLAM is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  * 
00013  * You should have received a copy of the GNU General Public License
00014  * along with RGBDSLAM.  If not, see <http://www.gnu.org/licenses/>.
00015  */
00016 
00017 
00018 /*
00019  * graph_manager.h
00020  *
00021  *  Created on: 19.01.2011
00022  *      Author: hess
00023  */
00024 
00025 #ifndef GRAPH_MANAGER_H_
00026 #define GRAPH_MANAGER_H_
00027 
00028 #include <ros/ros.h>
00029 #include <tf/transform_broadcaster.h>
00030 #include "node.h"
00031 #include <pcl/filters/voxel_grid.h>
00032 #include <Eigen/Core>
00033 #include <Eigen/Geometry>
00034 #include <opencv2/core/core.hpp>
00035 #include <opencv2/features2d/features2d.hpp>
00036 #include <map>
00037 #include <QObject>
00038 #include <QString>
00039 #include <QMatrix4x4>
00040 #include <QList>
00041 #include <QMap>
00042 #include <QMutex>
00043 
00044 #include <iostream>
00045 #include <sstream>
00046 #include <string>
00047 #include <ctime>
00048 #include <memory> //for auto_ptr
00049 #include "parameter_server.h"
00050 
00051 #include "g2o/core/graph_optimizer_sparse.h"
00052 
00053 #include "g2o/core/hyper_dijkstra.h"
00054 
00055 //#define ROSCONSOLE_SEVERITY_INFO
00056 /*
00057 class GraphNode {
00058   GraphNode() : backend_node(NULL), frontend_node(NULL), index(-1) {}
00059 
00060   g2o::VertexSE3* backend_node;
00061   Node* frontend_node;
00062   int index;
00063 }
00064 */
00065 
00067 class GraphManager : public QObject {
00068     Q_OBJECT
00069     Q_SIGNALS:
00071     void newTransformationMatrix(QString);
00072     void sendFinished();
00073     void setGUIInfo(QString message);
00074     void setGUIStatus(QString message);
00075     void setPointCloud(pointcloud_type * pc, QMatrix4x4 transformation);
00076     void updateTransforms(QList<QMatrix4x4>* transformations);
00077     void setGUIInfo2(QString message);
00078     void setGraphEdges(QList<QPair<int, int> >* edge_list);
00079     void deleteLastNode();
00080     void resetGLViewer();
00081     
00082     public Q_SLOTS:
00084     void reset();
00086     void sendAllClouds(bool threaded_if_available=true);
00088     void saveIndividualClouds(QString file_basename, bool threaded=true);
00090     void saveAllClouds(QString filename, bool threaded=true);
00092     void saveAllFeatures(QString filename, bool threaded = true);
00094     void deleteLastFrame(); 
00095     void setMaxDepth(float max_depth);
00097     void saveTrajectory(QString filebasename, bool with_ground_truth = false);
00098     void cloudRendered(pointcloud_type const * pc);
00100     void optimizeGraph(int iter = -1, bool nonthreaded=false);
00101     void printEdgeErrors(QString);
00102     void pruneEdgesWithErrorAbove(float);
00103     void sanityCheck(float);
00104     void toggleMapping(bool);
00105 
00106     public:
00107     GraphManager(ros::NodeHandle);
00108     ~GraphManager();
00109 
00115     bool addNode(Node* newNode); 
00116 
00118     void firstNode(Node* new_node);
00119 
00121     void drawFeatureFlow(cv::Mat& canvas, 
00122                          cv::Scalar line_color = cv::Scalar(255,0,0,0), 
00123                          cv::Scalar circle_color = cv::Scalar(0,0,255,0)); 
00124 
00125     bool isBusy();
00126     void finishUp();
00127     
00128     float Max_Depth;
00129     //void setMaxDepth(float max_depth);
00132     void deleteFeatureInformation();
00133 protected:
00134     void sendAllCloudsImpl();
00136     void optimizeGraphImpl(int max_iter);
00138     void createOptimizer(std::string backend, g2o::SparseOptimizer* optimizer = NULL);
00140     void saveAllCloudsToFile(QString filename);
00142     void saveAllFeaturesToFile(QString filename);
00144     void saveIndividualCloudsToFile(QString filename);
00145     void pointCloud2MeshFile(QString filename, pointcloud_type full_cloud);
00146     std::vector < cv::DMatch > last_inlier_matches_;
00147     std::vector < cv::DMatch > last_matches_;
00148 
00151     QList<int> getPotentialEdgeTargets(const Node* new_node, int sequential_targets, int sample_targets = 5);
00152 
00157     QList<int> getPotentialEdgeTargetsWithDijkstra(const Node* new_node, int sequential_targets, int geodesic_targets, int sampled_targets = 5, int predecessor_id = -1);
00158     
00159     //std::vector<int> getPotentialEdgeTargetsFeatures(const Node* new_node, int max_targets);
00160     
00161     bool addEdgeToG2O(const LoadedEdge3D& edge, bool good_edge, bool set_estimate=false);
00162 
00163 
00165     void visualizeGraphEdges() const;
00167     void visualizeGraphNodes() const;
00169     void visualizeGraphIds() const;
00170         
00171     
00172     
00174     void visualizeFeatureFlow3D(unsigned int marker_id = 0,
00175                                 bool draw_outlier = true) const;
00178     void broadcastTransform(Node* node, tf::Transform& computed_motion);
00181 
00183     QList<QMatrix4x4>* getAllPosesAsMatrixList();
00184     QList<QMatrix4x4> current_poses_;
00186     QList<QPair<int, int> >* getGraphEdges(); 
00187     QList<QPair<int, int> > current_edges_;
00188     void resetGraph();
00189 
00190     void mergeAllClouds(pointcloud_type & merge);
00191     double geodesicDiscount(g2o::HyperDijkstra& hypdij, const MatchingResult& mr);
00192     
00193     g2o::SparseOptimizer* optimizer_;
00194 
00195     ros::Publisher marker_pub_; 
00196     ros::Publisher ransac_marker_pub_;
00197     ros::Publisher whole_cloud_pub_;
00198     ros::Publisher batch_cloud_pub_;
00199     
00201     ros::Timer timer_;
00203     tf::TransformBroadcaster br_;
00204     tf::Transform computed_motion_; 
00205     tf::Transform  init_base_pose_;
00206     tf::Transform base2points_;//base_frame -> optical_frame 
00207     //Eigen::Matrix4f latest_transform_;///<same as computed_motion_ as Eigen
00208     QMatrix4x4 latest_transform_;
00209 
00210 
00212     typedef std::pair<int, Node*> GraphNodeType;
00213     //QMap<int, Node* > graph_;
00214     std::map<int, Node* > graph_;
00215     bool reset_request_;
00216     unsigned int marker_id_;
00217     int last_matching_node_;
00218     g2o::SE3Quat edge_to_previous_node_;
00219     bool batch_processing_runs_;
00220     bool process_node_runs_;
00221     bool localization_only_;
00222     bool someone_is_waiting_for_me_;
00223     QMutex optimizer_mutex;
00224     //cv::FlannBasedMatcher global_flann_matcher;
00225     QList<int> keyframe_ids_;//Keyframes are added, if no previous keyframe was matched
00226     //NEW std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > feature_coords_;  
00227     //NEW cv::Mat feature_descriptors_;         
00228     unsigned int loop_closures_edges, sequential_edges;
00229     std::string current_backend_;
00230     
00231 };
00232 
00233 
00234 
00235 #endif /* GRAPH_MANAGER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


rgbdslam
Author(s): Felix Endres, Juergen Hess, Nikolas Engelhard
autogenerated on Wed Dec 26 2012 15:53:08