Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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>
00049 #include "parameter_server.h"
00050
00051 #include "g2o/core/graph_optimizer_sparse.h"
00052
00053 #include "g2o/core/hyper_dijkstra.h"
00054
00055
00056
00057
00058
00059
00060
00061
00062
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
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
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_;
00207
00208 QMatrix4x4 latest_transform_;
00209
00210
00212 typedef std::pair<int, Node*> GraphNodeType;
00213
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
00225 QList<int> keyframe_ids_;
00226
00227
00228 unsigned int loop_closures_edges, sequential_edges;
00229 std::string current_backend_;
00230
00231 };
00232
00233
00234
00235 #endif