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


multires_image
Author(s): Marc Alban
autogenerated on Thu Aug 24 2017 02:46:18