All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MosaicWizard.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/MosaicWizard.cpp
22 
23  \brief A Qt dialog that allows users to run a mosaic operation defined by RP module.
24 */
25 
26 // TerraLib
27 #include "../../../common/progress/ProgressManager.h"
28 #include "../../../common/STLUtils.h"
29 #include "../../../dataaccess/dataset/DataSet.h"
30 #include "../../../dataaccess/utils/Utils.h"
31 #include "../help/HelpPushButton.h"
32 #include "../layer/search/LayerSearchWidget.h"
33 #include "../layer/search/LayerSearchWizardPage.h"
34 #include "../progress/ProgressViewerDialog.h"
35 #include "MosaicWizard.h"
36 #include "MosaicWizardPage.h"
37 #include "RasterInfoWidget.h"
38 #include "RasterInfoWizardPage.h"
39 #include "Utils.h"
40 
41 // STL
42 #include <cassert>
43 
44 // Qt
45 #include <QMessageBox>
46 #include <QApplication>
47 
48 
50  : QWizard(parent)
51 {
52  //configure the wizard
53  this->setWizardStyle(QWizard::ModernStyle);
54  this->setWindowTitle(tr("Mosaic"));
55  //this->setFixedSize(640, 480);
56 
57  this->setOption(QWizard::HaveHelpButton, true);
58  this->setOption(QWizard::HelpButtonOnRight, false);
59 
61 
62  this->setButton(QWizard::HelpButton, helpButton);
63 
64  helpButton->setPageReference("plugins/rp/rp_mosaic.html");
65 
66  addPages();
67 }
68 
70 {
71 
72 }
73 
75 {
76  if(currentPage() == m_layerSearchPage.get())
77  {
78  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
79 
80  m_mosaicPage->setList(list);
81 
82  return m_layerSearchPage->isComplete();
83  }
84  else if(currentPage() == m_mosaicPage.get())
85  {
86  return m_mosaicPage->isComplete();
87  }
88  else if(currentPage() == m_rasterInfoPage.get())
89  {
90  return execute();
91  }
92 
93  return true;
94 }
95 
96 void te::qt::widgets::MosaicWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
97 {
98  m_layerSearchPage->getSearchWidget()->setList(layerList);
99  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
100  m_layerSearchPage->getSearchWidget()->enableMultiSelection(true);
101 }
102 
103 std::list<te::map::AbstractLayerPtr> te::qt::widgets::MosaicWizard::getOutputLayers()
104 {
105  return m_outputLayerList;
106 }
107 
109 {
110  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
111  m_mosaicPage.reset(new te::qt::widgets::MosaicWizardPage(this));
112  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
113 
114  addPage(m_layerSearchPage.get());
115  addPage(m_mosaicPage.get());
116  addPage(m_rasterInfoPage.get());
117 }
118 
120 {
121  if(m_mosaicPage->isGeoMosaic())
122  return executeGeoMosaic();
123  else if(m_mosaicPage->isTiePointMosaic())
124  return executeTiePointMosaic();
125  else if(m_mosaicPage->isSequenceMosaic())
126  return executeSequenceMosaic();
127 
128  return false;
129 }
130 
132 {
133 //run Geo Mosaic
134  te::rp::GeoMosaic algorithmInstance;
135 
136  te::rp::GeoMosaic::InputParameters algoInputParams = m_mosaicPage->getInputGeoParams();
137 
138  //get rasters
139  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
140 
141  std::list<te::map::AbstractLayerPtr>::iterator it = list.begin();
142  std::vector<std::size_t> bands;
143 
144  std::vector<const te::rst::Raster*> rasters;
145 
146  while(it != list.end())
147  {
149 
150  std::auto_ptr<te::da::DataSet> ds = l->getData();
151  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
152  te::rst::Raster* rst = ds->getRaster(rpos).release();
153 
154  rasters.push_back(rst);
155 
156  std::vector<unsigned int> bands;
157 
158  for(unsigned int i = 0; i < rst->getNumberOfBands(); ++i)
159  bands.push_back(i);
160 
161  algoInputParams.m_inputRastersBands.push_back( bands );
162 
163  ++it;
164  }
165 
166  te::rp::FeederConstRasterVector feeder(rasters);
167  algoInputParams.m_feederRasterPtr = &feeder;
168  algoInputParams.m_enableProgress = true;
169 
170  te::rp::GeoMosaic::OutputParameters algoOutputParams = m_mosaicPage->getOutputGeoParams();
171  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
172  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
173 
174  //progress
177 
178  QApplication::setOverrideCursor(Qt::WaitCursor);
179 
180  try
181  {
182  if(algorithmInstance.initialize(algoInputParams))
183  {
184  if(algorithmInstance.execute(algoOutputParams))
185  {
186  algoOutputParams.reset();
187 
188  //set output layer
189  te::map::AbstractLayerPtr outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
190  m_rasterInfoPage->getWidget()->getInfo());
191 
192  m_outputLayerList.push_back(outputLayer);
193 
194  QMessageBox::information(this, tr("Mosaic"), tr("Mosaic ended sucessfully"));
195  }
196  else
197  {
198  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic execution error.") +
199  ( " " + te::rp::Module::getLastLogStr() ).c_str());
200 
202 
203  QApplication::restoreOverrideCursor();
204 
205  te::common::FreeContents(rasters);
206 
207  return false;
208  }
209  }
210  else
211  {
212  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic initialization error.") +
213  ( " " + te::rp::Module::getLastLogStr() ).c_str() );
214 
216 
217  QApplication::restoreOverrideCursor();
218 
219  te::common::FreeContents(rasters);
220 
221  return false;
222  }
223  }
224  catch(const std::exception& e)
225  {
226  QMessageBox::warning(this, tr("Mosaic"), e.what());
227 
229 
230  QApplication::restoreOverrideCursor();
231 
232  te::common::FreeContents(rasters);
233 
234  return false;
235  }
236  catch(...)
237  {
238  QMessageBox::warning(this, tr("Mosaic"), tr("An exception has occurred!"));
239 
241 
242  QApplication::restoreOverrideCursor();
243 
244  te::common::FreeContents(rasters);
245 
246  return false;
247  }
248 
250 
251  QApplication::restoreOverrideCursor();
252 
253  te::common::FreeContents(rasters);
254 
255  return true;
256 }
257 
259 {
260 //run Tie Point Mosaic
261  te::rp::TiePointsMosaic algorithmInstance;
262 
263  te::rp::TiePointsMosaic::InputParameters algoInputParams = m_mosaicPage->getInputTPParams();
264  algoInputParams.m_enableProgress = true;
265 
266 //get rasters
267  std::list<te::map::AbstractLayerPtr> list;
268  list.push_back(m_mosaicPage->getTiePointMosaicLayerA());
269  list.push_back(m_mosaicPage->getTiePointMosaicLayerB());
270 
271  std::list<te::map::AbstractLayerPtr>::iterator it = list.begin();
272  std::vector<std::size_t> bands;
273 
274  std::vector<const te::rst::Raster*> rasters;
275 
276  while(it != list.end())
277  {
279 
280  std::auto_ptr<te::da::DataSet> ds = l->getData();
281  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
282  te::rst::Raster* rst = ds->getRaster(rpos).release();
283 
284  rasters.push_back(rst);
285 
286  std::vector<unsigned int> bands;
287 
288  for(unsigned int i = 0; i < rst->getNumberOfBands(); ++i)
289  bands.push_back(i);
290 
291  algoInputParams.m_inputRastersBands.push_back( bands );
292 
293  ++it;
294  }
295 
296  te::rp::FeederConstRasterVector feeder(rasters);
297  algoInputParams.m_feederRasterPtr = &feeder;
298 
299  te::rp::TiePointsMosaic::OutputParameters algoOutputParams = m_mosaicPage->getOutputTPParams();
300  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
301  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
302 
303  //progress
306 
307  QApplication::setOverrideCursor(Qt::WaitCursor);
308 
309  try
310  {
311  if(algorithmInstance.initialize(algoInputParams))
312  {
313  if(algorithmInstance.execute(algoOutputParams))
314  {
315  algoOutputParams.reset();
316 
317  //set output layer
318  te::map::AbstractLayerPtr outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
319  m_rasterInfoPage->getWidget()->getInfo());
320 
321  m_outputLayerList.push_back(outputLayer);
322 
323  QMessageBox::information(this, tr("Mosaic"), tr("Mosaic ended sucessfully"));
324  }
325  else
326  {
327  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic execution error.") +
328  ( " " + te::rp::Module::getLastLogStr() ).c_str());
329 
331 
332  QApplication::restoreOverrideCursor();
333 
334  return false;
335  }
336  }
337  else
338  {
339  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic initialization error.") +
340  ( " " + te::rp::Module::getLastLogStr() ).c_str() );
341 
343 
344  QApplication::restoreOverrideCursor();
345 
346  return false;
347  }
348  }
349  catch(const std::exception& e)
350  {
351  QMessageBox::warning(this, tr("Mosaic"), e.what());
352 
354 
355  QApplication::restoreOverrideCursor();
356 
357  return false;
358  }
359  catch(...)
360  {
361  QMessageBox::warning(this, tr("Mosaic"), tr("An exception has occurred!"));
362 
364 
365  QApplication::restoreOverrideCursor();
366 
367  return false;
368  }
369 
371 
372  QApplication::restoreOverrideCursor();
373 
374  return true;
375 }
376 
378 {
379 //run Sequence Mosaic
380  te::rp::SequenceMosaic algorithmInstance;
381 
382  te::rp::SequenceMosaic::InputParameters algoInputParams = m_mosaicPage->getInputSeqParams();
383 
384  //get rasters
385  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
386 
387  std::list<te::map::AbstractLayerPtr>::iterator it = list.begin();
388  std::vector<std::size_t> bands;
389 
390  std::vector<const te::rst::Raster*> rasters;
391 
392  while(it != list.end())
393  {
395 
396  std::auto_ptr<te::da::DataSet> ds = l->getData();
397  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
398  te::rst::Raster* rst = ds->getRaster(rpos).release();
399 
400  rasters.push_back(rst);
401 
402  std::vector<unsigned int> bands;
403 
404  for(unsigned int i = 0; i < rst->getNumberOfBands(); ++i)
405  bands.push_back(i);
406 
407  algoInputParams.m_inputRastersBands.push_back( bands );
408 
409  ++it;
410  }
411 
412  te::rp::FeederConstRasterVector feeder(rasters);
413  algoInputParams.m_feederRasterPtr = &feeder;
414 
415  algoInputParams.m_outDataSetsNamePrefix = m_rasterInfoPage->getWidget()->getShortName();
416  algoInputParams.m_outDataSetsNameSufix = m_rasterInfoPage->getWidget()->getExtension();
417 
418  std::auto_ptr<te::da::DataSource> ds = m_rasterInfoPage->getWidget()->getDataSource();
419 
420  te::rp::SequenceMosaic::OutputParameters algoOutputParams = m_mosaicPage->getOutputSeqParams();
421  algoOutputParams.m_outputDSPtr = ds.get();
422  //algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
423  //algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
424 
425  //progress
428 
429  QApplication::setOverrideCursor(Qt::WaitCursor);
430 
431  try
432  {
433  if(algorithmInstance.initialize(algoInputParams))
434  {
435  if(algorithmInstance.execute(algoOutputParams))
436  {
437  for(std::size_t t = 0; t < algoOutputParams.m_sequencesInfo.size(); ++t)
438  {
439  std::string name = algoOutputParams.m_sequencesInfo[t].m_dataSetName;
440  std::string path = m_rasterInfoPage->getWidget()->getPath();
441 
442  std::map<std::string, std::string> rinfo;
443  rinfo["URI"] = path + name;
444 
445  te::map::AbstractLayerPtr outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(), rinfo);
446 
447  m_outputLayerList.push_back(outputLayer);
448  }
449 
450  algoOutputParams.reset();
451 
452  QMessageBox::information(this, tr("Mosaic"), tr("Mosaic ended sucessfully"));
453  }
454  else
455  {
456  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic execution error.") +
457  ( " " + te::rp::Module::getLastLogStr() ).c_str());
458 
460 
461  QApplication::restoreOverrideCursor();
462 
463  te::common::FreeContents(rasters);
464 
465  return false;
466  }
467  }
468  else
469  {
470  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic initialization error.") +
471  ( " " + te::rp::Module::getLastLogStr() ).c_str() );
472 
474 
475  QApplication::restoreOverrideCursor();
476 
477  te::common::FreeContents(rasters);
478 
479  return false;
480  }
481  }
482  catch(const std::exception& e)
483  {
484  QMessageBox::warning(this, tr("Mosaic"), e.what());
485 
487 
488  QApplication::restoreOverrideCursor();
489 
490  te::common::FreeContents(rasters);
491 
492  return false;
493  }
494  catch(...)
495  {
496  QMessageBox::warning(this, tr("Mosaic"), tr("An exception has occurred!"));
497 
499 
500  QApplication::restoreOverrideCursor();
501 
502  te::common::FreeContents(rasters);
503 
504  return false;
505  }
506 
508 
509  QApplication::restoreOverrideCursor();
510 
511  te::common::FreeContents(rasters);
512 
513  return true;
514 }
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
Definition: GeoMosaic.cpp:130
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Definition: GeoMosaic.cpp:749
A Qt dialog that allows users to run a mosaic operation defined by RP module.
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
Utility functions for the data access module.
A feeder from a input rasters vector;.
Definition: FeedersRaster.h:69
std::list< te::map::AbstractLayerPtr > getOutputLayers()
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
Definition: GeoMosaic.cpp:163
GeoMosaic input parameters.
Definition: GeoMosaic.h:56
void setPageReference(const QString &ref)
Sets the documentation page reference.
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
Create a mosaic from a set of geo-referenced rasters.
Definition: GeoMosaic.h:48
std::string m_outDataSetsNamePrefix
The raster output data sets names prefix.
std::vector< MosaicSequenceInfo > m_sequencesInfo
This file defines a class for a Raster Info Wizard page.
std::vector< std::vector< unsigned int > > m_inputRastersBands
Bands to process for each input raster.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: GeoMosaic.h:104
std::vector< std::vector< unsigned int > > m_inputRastersBands
Bands to process for each input raster.
FeederConstRaster * m_feederRasterPtr
Input rasters feeder.
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.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
An abstract class for raster data strucutures.
Definition: Raster.h:71
This class is GUI used to define the raster info parameters for raster factory.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: GeoMosaic.h:76
virtual bool validateCurrentPage()
This file has the RasterInfoWidget class.
Create a mosaic from a set of rasters using tie-points.
std::string m_outDataSetsNameSufix
The raster output data sets names sufix.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
This file defines a class for a Mosaic Wizard page.
This class is GUI used to define the mosaic parameters for the RP mosaic operation.
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
GeoMosaic output parameters.
Definition: GeoMosaic.h:100
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
std::vector< std::vector< unsigned int > > m_inputRastersBands
Bands to process for each input raster.
Definition: GeoMosaic.h:62
Create mosaics from a sequence of overlapped rasters using an automatic tie-points detection method...
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
FeederConstRaster * m_feederRasterPtr
Input rasters feeder.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
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...
FeederConstRaster * m_feederRasterPtr
Input rasters feeder.
Definition: GeoMosaic.h:60
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
Definition: GeoMosaic.h:106
te::da::DataSource * m_outputDSPtr
The mosaic sequences info.