RegisterWizard.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 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 "../../../common/progress/ProgressManager.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../raster/Grid.h"
31 #include "../../../raster/Raster.h"
32 #include "../../../rp/Register.h"
33 #include "../../../rp/Module.h"
34 #include "../../../maptools/Utils.h"
35 #include "../help/HelpPushButton.h"
36 #include "../layer/search/LayerSearchWidget.h"
37 #include "../layer/search/LayerSearchWizardPage.h"
38 #include "../progress/ProgressViewerDialog.h"
39 #include "../raster/RasterInfoWidget.h"
40 #include "RasterInfoWizardPage.h"
41 #include "RegisterWizard.h"
42 #include "TiePointLocatorDialog.h"
43 #include "TiePointLocatorWidget.h"
44 #include "Utils.h"
45 
46 
47 // STL
48 #include <cassert>
49 #include <memory>
50 
51 // Qt
52 #include <QApplication>
53 #include <QMessageBox>
54 
55 
57  : QWizard(parent)
58 {
59  //configure the wizard
60  this->setWizardStyle(QWizard::ModernStyle);
61  this->setWindowTitle(tr("Register"));
62  //this->setFixedSize(640, 480);
63 
64  this->setOption(QWizard::HaveHelpButton, true);
65  this->setOption(QWizard::HelpButtonOnRight, false);
66 
68 
69  this->setButton(QWizard::HelpButton, helpButton);
70 
71  helpButton->setPageReference("plugins/rp/rp_register.html");
72 
73  connect(this, SIGNAL(currentIdChanged(int)), SLOT(onPageChanged(int)));
74 
75  addPages();
76 }
77 
79 
81 {
82  if(currentPage() == m_layerAdjPage.get())
83  {
84  std::list<te::map::AbstractLayerPtr> list = m_layerAdjPage->getSearchWidget()->getSelecteds();
85 
86  if(list.empty() == false)
87  {
88  m_adjLayer = *list.begin();
89 
90  m_tiePointLocatorDialog->setAdjustLayer(m_adjLayer);
91  }
92 
93  return m_layerAdjPage->isComplete();
94  }
95  else if(currentPage() == m_layerRefPage.get())
96  {
97  std::list<te::map::AbstractLayerPtr> list = m_layerRefPage->getSearchWidget()->getSelecteds();
98 
99  if(list.empty() == false)
100  m_refLayer = *list.begin();
101  else
102  m_refLayer = 0;
103 
104  m_tiePointLocatorDialog->setReferenceLayer(m_refLayer);
105 
106  m_tiePointLocatorDialog->exec();
107 
108  return true;
109  }
110  else if(currentPage() == m_rasterInfoPage.get())
111  {
112  std::vector< te::gm::GTParameters::TiePoint > tiePoints;
113 
114  m_tiePointLocatorDialog->getWidget()->getTiePoints(tiePoints);
115 
116  if(tiePoints.empty())
117  {
118  QMessageBox::warning(this, tr("Register"), tr("Tie Points not aquired."));
119  return false;
120  }
121 
122  return execute();
123  }
124 
125  return true;
126 }
127 
128 void te::qt::widgets::RegisterWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
129 {
130  m_layerRefPage->getSearchWidget()->setList(layerList);
131  m_layerAdjPage->getSearchWidget()->setList(layerList);
132 
133  m_layerRefPage->getSearchWidget()->filterOnlyByRaster();
134  m_layerAdjPage->getSearchWidget()->filterOnlyByRaster();
135 }
136 
138 {
139  return m_outputLayer;
140 }
141 
143 {
148 
149  addPage(m_layerAdjPage.get());
150  addPage(m_layerRefPage.get());
151  addPage(m_rasterInfoPage.get());
152 
153  //for register only one layer can be selected
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  m_layerRefPage->setSubTitle(tr("Allows selection of layers using filters for selection. Select the layer to be used as REFERENCE."));
157  m_layerRefPage->getSearchWidget()->enableMultiSelection(false);
158  m_layerRefPage->useSkipButton(true);
159 }
160 
162 {
163  if(m_rasterInfoPage->getWidget()->fileExists())
164  {
165  QMessageBox::warning(this, tr("Register"), tr("File already exists."));
166  return false;
167  }
168 
169  //get raster
170  std::unique_ptr<te::da::DataSet> ds(m_adjLayer->getData());
171  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
172  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
173 
174  std::vector<unsigned int> vec;
175  for(size_t t = 0; t < inputRst->getNumberOfBands(); ++t)
176  {
177  vec.push_back((unsigned int)t);
178  }
179 
180  std::vector< te::gm::GTParameters::TiePoint > tiePoints;
181  m_tiePointLocatorDialog->getWidget()->getTiePoints(tiePoints);
182 
183  int srid;
184  m_tiePointLocatorDialog->getWidget()->getOutputSRID(srid);
185 
186  double resX = 0;
187  double resY = 0;
188  m_tiePointLocatorDialog->getWidget()->getOutputResolution(resX, resY);
189 
190  //input parameters
191  te::rp::Register::InputParameters algoInputParams;
192  algoInputParams.m_inputRasterPtr = inputRst.get();
193  algoInputParams.m_inputRasterBands = vec;
194  algoInputParams.m_tiePoints = tiePoints;
195  algoInputParams.m_outputSRID = srid;
196  algoInputParams.m_outputResolutionX = resX;
197  algoInputParams.m_outputResolutionY = resY;
198  algoInputParams.m_geomTransfName = m_tiePointLocatorDialog->getWidget()->getTransformationName();
199  algoInputParams.m_interpMethod = m_tiePointLocatorDialog->getWidget()->getInterpolatorMethod();
200 
201  //output parameters
202  te::rp::Register::OutputParameters algoOutputParams;
203  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
204  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
205 
206 
207  //progress
209 
210  QApplication::setOverrideCursor(Qt::WaitCursor);
211 
212  try
213  {
214  te::rp::Register algorithmInstance;
215 
216  if(!algorithmInstance.initialize(algoInputParams))
217  {
218  QApplication::restoreOverrideCursor();
219  QMessageBox::warning(this, tr("Register"), tr("Algorithm initialization error.") +
220  ( " " + te::rp::Module::getLastLogStr() ).c_str());
221 
222  return false;
223  }
224 
225  if(!algorithmInstance.execute(algoOutputParams))
226  {
227  QApplication::restoreOverrideCursor();
228  QMessageBox::warning(this, tr("Register"), tr("Register Error.") +
229  ( " " + te::rp::Module::getLastLogStr() ).c_str());
230 
231  return false;
232  }
233  else
234  {
235  QApplication::restoreOverrideCursor();
236  QMessageBox::warning(this, tr("Register"), tr("Register Done!"));
237 
238  algoOutputParams.reset();
239 
240  //set output layer
242  m_rasterInfoPage->getWidget()->getInfo());
243  }
244  }
245  catch(const std::exception& e)
246  {
247  QApplication::restoreOverrideCursor();
248  QMessageBox::warning(this, tr("Register"), e.what());
249  return false;
250  }
251  catch(...)
252  {
253 
254  QApplication::restoreOverrideCursor();
255  QMessageBox::warning(this, tr("Register"), tr("An exception has occurred!"));
256  return false;
257  }
258 
260 
261  return true;
262 }
263 
265 {
266  this->adjustSize();
267 }
Register input parameters.
Definition: Register.h:56
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: Register.h:60
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
This file has the TiePointLocatorWidget class.
This file defines the RegisterWizard class.
void setPageReference(const QString &ref)
Sets the documentation page reference.
std::unique_ptr< te::qt::widgets::TiePointLocatorDialog > m_tiePointLocatorDialog
std::unique_ptr< te::qt::widgets::LayerSearchWizardPage > m_layerRefPage
te::map::AbstractLayerPtr m_adjLayer
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
static te::dt::Date ds(2010, 01, 01)
double m_outputResolutionY
The output raster Y axis resolution (default:1).
Definition: Register.h:70
static const std::string getLastLogStr()
Returns the last log string generated by this module.
std::unique_ptr< te::qt::widgets::RasterInfoWizardPage > m_rasterInfoPage
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.
te::map::AbstractLayerPtr m_outputLayer
std::vector< unsigned int > m_inputRasterBands
Bands to process from the input raster.
Definition: Register.h:62
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
Definition: Register.h:72
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
Utility functions for the data access module.
std::unique_ptr< te::qt::widgets::LayerSearchWizardPage > m_layerAdjPage
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
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
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const te::core::URI &connInfo)
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)
std::string m_geomTransfName
The name of the geometric transformation used (see each te::gm::GTFactory inherited classes to find e...
Definition: Register.h:76
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
TEQTWIDGETSEXPORT void applyRasterMultiResolution(const QString &toolName, te::rst::Raster *raster)
te::map::AbstractLayerPtr m_refLayer