All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RegisterWizard.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/rp/RegisterWizard.cpp
22 
23  \brief This file defines the RegisterWizard class.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/utils/Utils.h"
29 #include "../../../raster/Grid.h"
30 #include "../../../raster/Raster.h"
31 #include "../../../rp/Register.h"
32 #include "../../../rp/Module.h"
33 #include "../help/HelpPushButton.h"
34 #include "../layer/search/LayerSearchWidget.h"
35 #include "../layer/search/LayerSearchWizardPage.h"
36 #include "RasterInfoWidget.h"
37 #include "RasterInfoWizardPage.h"
38 #include "RegisterWizard.h"
39 #include "TiePointLocatorDialog.h"
40 #include "TiePointLocatorWidget.h"
41 #include "Utils.h"
42 
43 
44 // STL
45 #include <cassert>
46 #include <memory>
47 
48 // Qt
49 #include <QApplication>
50 #include <QMessageBox>
51 
52 
54  : QWizard(parent)
55 {
56  //configure the wizard
57  this->setWizardStyle(QWizard::ModernStyle);
58  this->setWindowTitle(tr("Register"));
59  //this->setFixedSize(640, 480);
60 
61  this->setOption(QWizard::HaveHelpButton, true);
62  this->setOption(QWizard::HelpButtonOnRight, false);
63 
65 
66  this->setButton(QWizard::HelpButton, helpButton);
67 
68  helpButton->setPageReference("plugins/rp/rp_register.html");
69 
70  addPages();
71 }
72 
74 {
75 
76 }
77 
79 {
80  if(currentPage() == m_layerRefPage.get())
81  {
82  std::list<te::map::AbstractLayerPtr> list = m_layerRefPage->getSearchWidget()->getSelecteds();
83 
84  if(list.empty() == false)
85  {
86  m_refLayer = *list.begin();
87 
88  m_tiePointLocatorDialog->setReferenceLayer(m_refLayer);
89  }
90 
91  return m_layerRefPage->isComplete();
92  }
93  else if(currentPage() == m_layerAdjPage.get())
94  {
95  std::list<te::map::AbstractLayerPtr> list = m_layerAdjPage->getSearchWidget()->getSelecteds();
96 
97  if(list.empty() == false)
98  {
99  m_adjLayer = *list.begin();
100 
101  m_tiePointLocatorDialog->setAdjustLayer(m_adjLayer);
102  }
103 
104  m_tiePointLocatorDialog->showMaximized();
105 
106  return m_layerAdjPage->isComplete();
107  }
108  else if(currentPage() == m_rasterInfoPage.get())
109  {
110  std::vector< te::gm::GTParameters::TiePoint > tiePoints;
111 
112  m_tiePointLocatorDialog->getWidget()->getTiePoints(tiePoints);
113 
114  if(tiePoints.empty())
115  {
116  QMessageBox::warning(this, tr("Register"), tr("Tie Points not aquired."));
117  return false;
118  }
119 
120  return execute();
121  }
122 
123  return true;
124 }
125 
126 void te::qt::widgets::RegisterWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
127 {
128  m_layerRefPage->getSearchWidget()->setList(layerList);
129  m_layerAdjPage->getSearchWidget()->setList(layerList);
130 
131  m_layerRefPage->getSearchWidget()->filterOnlyByRaster();
132  m_layerAdjPage->getSearchWidget()->filterOnlyByRaster();
133 }
134 
136 {
137  return m_outputLayer;
138 }
139 
141 {
142  m_layerRefPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
143  m_layerAdjPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
144  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
145  m_tiePointLocatorDialog.reset(new te::qt::widgets::TiePointLocatorDialog(this));
146 
147  addPage(m_layerRefPage.get());
148  addPage(m_layerAdjPage.get());
149  addPage(m_rasterInfoPage.get());
150 
151  //for register only one layer can be selected
152  m_layerRefPage->setSubTitle(tr("Allows selection of layers using filters for selection. Select the layer to be used as REFERENCE."));
153  m_layerRefPage->getSearchWidget()->enableMultiSelection(false);
154  m_layerAdjPage->setSubTitle(tr("Allows selection of layers using filters for selection. Select the layer to be used as ADJUST."));
155  m_layerAdjPage->getSearchWidget()->enableMultiSelection(false);
156 }
157 
159 {
160  if(m_rasterInfoPage->getWidget()->fileExists())
161  {
162  QMessageBox::warning(this, tr("Register"), tr("File already exists."));
163  return false;
164  }
165 
166  //get raster
167  std::auto_ptr<te::da::DataSet> ds(m_adjLayer->getData());
168  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
169  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
170 
171  std::vector<unsigned int> vec;
172  for(size_t t = 0; t < inputRst->getNumberOfBands(); ++t)
173  {
174  vec.push_back((unsigned int)t);
175  }
176 
177  std::vector< te::gm::GTParameters::TiePoint > tiePoints;
178  m_tiePointLocatorDialog->getWidget()->getTiePoints(tiePoints);
179 
180  int srid;
181  m_tiePointLocatorDialog->getWidget()->getOutputSRID(srid);
182 
183  double resX, resY;
184  m_tiePointLocatorDialog->getWidget()->getOutputResolution(resX, resY);
185 
186  //input parameters
187  te::rp::Register::InputParameters algoInputParams;
188  algoInputParams.m_inputRasterPtr = inputRst.release();
189  algoInputParams.m_inputRasterBands = vec;
190  algoInputParams.m_tiePoints = tiePoints;
191  algoInputParams.m_outputSRID = srid;
192  algoInputParams.m_outputResolutionX = resX;
193  algoInputParams.m_outputResolutionY = resY;
194 
195  //output parameters
196  te::rp::Register::OutputParameters algoOutputParams;
197  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
198  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
199 
200  QApplication::setOverrideCursor(Qt::WaitCursor);
201 
202  try
203  {
204  te::rp::Register algorithmInstance;
205 
206  if(!algorithmInstance.initialize(algoInputParams))
207  {
208  QMessageBox::warning(this, tr("Register"), tr("Algorithm initialization error.") +
209  ( " " + te::rp::Module::getLastLogStr() ).c_str());
210 
211  QApplication::restoreOverrideCursor();
212 
213  return false;
214  }
215 
216  if(!algorithmInstance.execute(algoOutputParams))
217  {
218  QMessageBox::warning(this, tr("Register"), tr("Register Error.") +
219  ( " " + te::rp::Module::getLastLogStr() ).c_str());
220 
221  QApplication::restoreOverrideCursor();
222 
223  return false;
224  }
225  else
226  {
227  QMessageBox::warning(this, tr("Register"), tr("Register Done!"));
228 
229  algoOutputParams.reset();
230 
231  //set output layer
232  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
233  m_rasterInfoPage->getWidget()->getInfo());
234  }
235  }
236  catch(const std::exception& e)
237  {
238  QMessageBox::warning(this, tr("Register"), e.what());
239 
240  QApplication::restoreOverrideCursor();
241 
242  return false;
243  }
244  catch(...)
245  {
246  QMessageBox::warning(this, tr("Register"), tr("An exception has occurred!"));
247 
248  QApplication::restoreOverrideCursor();
249 
250  return false;
251  }
252 
253  QApplication::restoreOverrideCursor();
254 
255  return true;
256 }
257 
Register input parameters.
Definition: Register.h:56
Utility functions for the data access module.
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: Register.h:60
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
Definition: Register.cpp:149
This file has the TiePointLocatorWidget class.
This file defines the RegisterWizard class.
void setPageReference(const QString &ref)
Sets the documentation page reference.
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
double m_outputResolutionY
The output raster Y axis resolution (default:1).
Definition: Register.h:70
This file defines a class for a Raster Info Wizard page.
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
Tie-points between each raster point (te::gm::GTParameters::TiePoint::first are raster lines/columns ...
Definition: Register.h:64
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Definition: Register.cpp:333
static const std::string & getLastLogStr()
Returns the last log string generated by this module.
Definition: Module.h:53
std::vector< unsigned int > m_inputRasterBands
Bands to process from the input raster.
Definition: Register.h:62
This class is GUI used to define the raster info parameters for raster factory.
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
Definition: Register.h:108
This file has the RasterInfoWidget class.
Performs raster data registering into a SRS using a set of tie points.
Definition: Register.h:48
int m_outputSRID
The output raster SRID (default:0).
Definition: Register.h:66
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
double m_outputResolutionX
The output raster X axis resolution (default:1).
Definition: Register.h:68
Register output parameters.
Definition: Register.h:102
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Register.h:106
te::map::AbstractLayerPtr getOutputLayer()
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:432
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const std::map< std::string, std::string > &connInfo)
Definition: Utils.cpp:40
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
Definition: Register.cpp:117