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) 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 "../help/HelpPushButton.h"
35 #include "../layer/search/LayerSearchWidget.h"
36 #include "../layer/search/LayerSearchWizardPage.h"
37 #include "../progress/ProgressViewerDialog.h"
38 #include "RasterInfoWidget.h"
39 #include "RasterInfoWizardPage.h"
40 #include "RegisterWizard.h"
41 #include "TiePointLocatorDialog.h"
42 #include "TiePointLocatorWidget.h"
43 #include "Utils.h"
44 
45 
46 // STL
47 #include <cassert>
48 #include <memory>
49 
50 // Qt
51 #include <QApplication>
52 #include <QMessageBox>
53 
54 
56  : QWizard(parent)
57 {
58  //configure the wizard
59  this->setWizardStyle(QWizard::ModernStyle);
60  this->setWindowTitle(tr("Register"));
61  //this->setFixedSize(640, 480);
62 
63  this->setOption(QWizard::HaveHelpButton, true);
64  this->setOption(QWizard::HelpButtonOnRight, false);
65 
67 
68  this->setButton(QWizard::HelpButton, helpButton);
69 
70  helpButton->setPageReference("plugins/rp/rp_register.html");
71 
72  addPages();
73 }
74 
76 {
77 
78 }
79 
81 {
82  if(currentPage() == m_layerRefPage.get())
83  {
84  std::list<te::map::AbstractLayerPtr> list = m_layerRefPage->getSearchWidget()->getSelecteds();
85 
86  if(list.empty() == false)
87  {
88  m_refLayer = *list.begin();
89 
90  m_tiePointLocatorDialog->setReferenceLayer(m_refLayer);
91  }
92 
93  return m_layerRefPage->isComplete();
94  }
95  else if(currentPage() == m_layerAdjPage.get())
96  {
97  std::list<te::map::AbstractLayerPtr> list = m_layerAdjPage->getSearchWidget()->getSelecteds();
98 
99  if(list.empty() == false)
100  {
101  m_adjLayer = *list.begin();
102 
103  m_tiePointLocatorDialog->setAdjustLayer(m_adjLayer);
104  }
105 
106  m_tiePointLocatorDialog->showMaximized();
107 
108  return m_layerAdjPage->isComplete();
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 {
144  m_layerRefPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
145  m_layerAdjPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
146  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
147  m_tiePointLocatorDialog.reset(new te::qt::widgets::TiePointLocatorDialog(this));
148 
149  addPage(m_layerRefPage.get());
150  addPage(m_layerAdjPage.get());
151  addPage(m_rasterInfoPage.get());
152 
153  //for register only one layer can be selected
154  m_layerRefPage->setSubTitle(tr("Allows selection of layers using filters for selection. Select the layer to be used as REFERENCE."));
155  m_layerRefPage->getSearchWidget()->enableMultiSelection(false);
156  m_layerAdjPage->setSubTitle(tr("Allows selection of layers using filters for selection. Select the layer to be used as ADJUST."));
157  m_layerAdjPage->getSearchWidget()->enableMultiSelection(false);
158 }
159 
161 {
162  if(m_rasterInfoPage->getWidget()->fileExists())
163  {
164  QMessageBox::warning(this, tr("Register"), tr("File already exists."));
165  return false;
166  }
167 
168  //get raster
169  std::auto_ptr<te::da::DataSet> ds(m_adjLayer->getData());
170  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
171  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
172 
173  std::vector<unsigned int> vec;
174  for(size_t t = 0; t < inputRst->getNumberOfBands(); ++t)
175  {
176  vec.push_back((unsigned int)t);
177  }
178 
179  std::vector< te::gm::GTParameters::TiePoint > tiePoints;
180  m_tiePointLocatorDialog->getWidget()->getTiePoints(tiePoints);
181 
182  int srid;
183  m_tiePointLocatorDialog->getWidget()->getOutputSRID(srid);
184 
185  double resX, resY;
186  m_tiePointLocatorDialog->getWidget()->getOutputResolution(resX, resY);
187 
188  //input parameters
189  te::rp::Register::InputParameters algoInputParams;
190  algoInputParams.m_inputRasterPtr = inputRst.release();
191  algoInputParams.m_inputRasterBands = vec;
192  algoInputParams.m_tiePoints = tiePoints;
193  algoInputParams.m_outputSRID = srid;
194  algoInputParams.m_outputResolutionX = resX;
195  algoInputParams.m_outputResolutionY = resY;
196 
197  //output parameters
198  te::rp::Register::OutputParameters algoOutputParams;
199  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
200  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
201 
202 
203  //progress
206 
207  QApplication::setOverrideCursor(Qt::WaitCursor);
208 
209  try
210  {
211  te::rp::Register algorithmInstance;
212 
213  if(!algorithmInstance.initialize(algoInputParams))
214  {
215  QMessageBox::warning(this, tr("Register"), tr("Algorithm initialization error.") +
216  ( " " + te::rp::Module::getLastLogStr() ).c_str());
217 
219 
220  QApplication::restoreOverrideCursor();
221 
222  return false;
223  }
224 
225  if(!algorithmInstance.execute(algoOutputParams))
226  {
227  QMessageBox::warning(this, tr("Register"), tr("Register Error.") +
228  ( " " + te::rp::Module::getLastLogStr() ).c_str());
229 
231 
232  QApplication::restoreOverrideCursor();
233 
234  return false;
235  }
236  else
237  {
238  QMessageBox::warning(this, tr("Register"), tr("Register Done!"));
239 
240  algoOutputParams.reset();
241 
242  //set output layer
243  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
244  m_rasterInfoPage->getWidget()->getInfo());
245  }
246  }
247  catch(const std::exception& e)
248  {
249  QMessageBox::warning(this, tr("Register"), e.what());
250 
252 
253  QApplication::restoreOverrideCursor();
254 
255  return false;
256  }
257  catch(...)
258  {
259  QMessageBox::warning(this, tr("Register"), tr("An exception has occurred!"));
260 
262 
263  QApplication::restoreOverrideCursor();
264 
265  return false;
266  }
267 
269 
270  QApplication::restoreOverrideCursor();
271 
272  return true;
273 }
274 
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:150
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:319
static const std::string & getLastLogStr()
Returns the last log string generated by this module.
Definition: Module.h:53
void removeViewer(int viewerId)
Dettach a progress viewer.
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
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.
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
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:481
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:118