multires_view_node.cpp
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00038 #include <string>
00039 
00040 // QT libraries
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   // Initialize QT
00130   QApplication app(argc, argv);
00131 
00132   multires_image::MultiresViewNode node(argc, argv);
00133   node.show();
00134 
00135   return app.exec();
00136 }


multires_image
Author(s): Marc Alban
autogenerated on Thu Jun 6 2019 18:51:15