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
00026
00027
00028
00029
00038 #include <string>
00039
00040
00041 #include <QString>
00042 #if QT_VERSION >= 0x050000
00043 #include <QtWidgets/QApplication>
00044 #include <QtWidgets/QMessageBox>
00045 #else
00046 #include <QtGui/QApplication>
00047 #include <QtGui/QMessageBox>
00048 #endif
00049 #include <QImage>
00050 #include <QFileInfo>
00051
00052 #include <multires_image/multires_view_node.h>
00053
00054 namespace multires_image
00055 {
00056 MultiresViewNode::MultiresViewNode(int argc, char **argv, QWidget *parent, Qt::WFlags flags) :
00057 QMainWindow(parent, flags),
00058 argc_(argc),
00059 argv_(argv),
00060 node_(NULL),
00061 thread_(NULL),
00062 initialized_(false)
00063 {
00064 setCentralWidget(new QGLMap());
00065 this->setMinimumSize(640, 480);
00066 }
00067
00068 MultiresViewNode::~MultiresViewNode()
00069 {
00070 delete node_;
00071 }
00072
00073 void MultiresViewNode::Spin()
00074 {
00075 if (thread_ == NULL)
00076 {
00077 thread_ = new boost::thread(&MultiresViewNode::SpinLoop, this);
00078 }
00079 }
00080
00081 void MultiresViewNode::SpinLoop()
00082 {
00083 while (ros::ok())
00084 {
00085 ros::spinOnce();
00086
00087 usleep(10);
00088 }
00089 }
00090
00091 void MultiresViewNode::showEvent(QShowEvent* event)
00092 {
00093 Initialize();
00094 }
00095
00096 void MultiresViewNode::Initialize()
00097 {
00098 if (!initialized_)
00099 {
00100 ros::init(argc_, argv_, "multires_view_node");
00101
00102 node_ = new ros::NodeHandle();
00103
00104 node_->param(ros::this_node::getName() + "/image_path", image_path_, std::string(""));
00105
00106
00107 tile_set_ = new TileSet(image_path_);
00108
00109 if (tile_set_->Load())
00110 {
00111 QGLMap* glMap = reinterpret_cast<QGLMap*>(centralWidget());
00112 glMap->SetTiles(tile_set_);
00113 glMap->UpdateView();
00114 }
00115 else
00116 {
00117 QMessageBox::warning(this, "Error", "Failed to load tiles.");
00118 }
00119
00120 Spin();
00121
00122 initialized_ = true;
00123 }
00124 }
00125 }
00126
00127 int main(int argc, char **argv)
00128 {
00129
00130 QApplication app(argc, argv);
00131
00132 multires_image::MultiresViewNode node(argc, argv);
00133 node.show();
00134
00135 return app.exec();
00136 }