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 "../../../maptools/Utils.h"
32 #include "../help/HelpPushButton.h"
33 #include "../layer/search/LayerSearchWidget.h"
34 #include "../layer/search/LayerSearchWizardPage.h"
35 #include "../progress/ProgressViewerDialog.h"
36 #include "MosaicWizard.h"
37 #include "MosaicWizardPage.h"
38 #include "../raster/RasterInfoWidget.h"
39 #include "RasterInfoWizardPage.h"
40 #include "Utils.h"
41 
42 // STL
43 #include <cassert>
44 
45 // Qt
46 #include <QMessageBox>
47 #include <QApplication>
48 
49 
51  : QWizard(parent)
52 {
53  //configure the wizard
54  this->setWizardStyle(QWizard::ModernStyle);
55  this->setWindowTitle(tr("Mosaic"));
56  //this->setFixedSize(640, 480);
57 
58  this->setOption(QWizard::HaveHelpButton, true);
59  this->setOption(QWizard::HelpButtonOnRight, false);
60 
62 
63  this->setButton(QWizard::HelpButton, helpButton);
64 
65  helpButton->setPageReference("plugins/rp/rp_mosaic.html");
66 
67  connect(this, SIGNAL(currentIdChanged(int)), SLOT(onPageChanged(int)));
68 
69  addPages();
70 }
71 
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 {
113 
114  addPage(m_layerSearchPage.get());
115  addPage(m_mosaicPage.get());
116  addPage(m_rasterInfoPage.get());
117 }
118 
120 {
121  if(m_rasterInfoPage->getWidget()->fileExists())
122  {
123  QMessageBox::warning(this, tr("Mosaic"), tr("File already exists."));
124  return false;
125  }
126 
127  if(m_layerSearchPage->getSearchWidget()->getSelecteds().size() == 1)
128  {
129  QMessageBox::warning(this, tr("Mosaic"), tr("Invalid number of layers."));
130  return false;
131  }
132 
133  if(m_mosaicPage->isGeoMosaic())
134  return executeGeoMosaic();
135  else if(m_mosaicPage->isTiePointMosaic())
136  return executeTiePointMosaic();
137  else if(m_mosaicPage->isSequenceMosaic())
138  return executeSequenceMosaic();
139 
140  return false;
141 }
142 
144 {
145 //run Geo Mosaic
146  te::rp::GeoMosaic algorithmInstance;
147 
148  te::rp::GeoMosaic::InputParameters algoInputParams = m_mosaicPage->getInputGeoParams();
149 
150  //get rasters
151  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
152 
153  std::list<te::map::AbstractLayerPtr>::iterator it = list.begin();
154  std::vector<std::size_t> bands;
155 
156  std::vector<const te::rst::Raster*> rasters;
157 
158  while(it != list.end())
159  {
161 
163 
164  rasters.push_back(rst);
165 
166  std::vector<unsigned int> bands;
167 
168  for(unsigned int i = 0; i < rst->getNumberOfBands(); ++i)
169  bands.push_back(i);
170 
171  algoInputParams.m_inputRastersBands.push_back( bands );
172 
173  ++it;
174  }
175 
176  te::rp::FeederConstRasterVector feeder(rasters);
177  algoInputParams.m_feederRasterPtr = &feeder;
178  algoInputParams.m_enableProgress = true;
179 
180  te::rp::GeoMosaic::OutputParameters algoOutputParams = m_mosaicPage->getOutputGeoParams();
181  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
182  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
183 
184  //progress
186 
187  QApplication::setOverrideCursor(Qt::WaitCursor);
188 
189  try
190  {
191  if(algorithmInstance.initialize(algoInputParams))
192  {
193  if(algorithmInstance.execute(algoOutputParams))
194  {
195  algoOutputParams.reset();
196 
197  //set output layer
198  te::map::AbstractLayerPtr outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
199  m_rasterInfoPage->getWidget()->getInfo());
200 
201  m_outputLayerList.push_back(outputLayer);
202 
203  te::qt::widgets::applyRasterMultiResolution(tr("Mosaic"), te::map::GetRaster(outputLayer.get()));
204 
205  QMessageBox::information(this, tr("Mosaic"), tr("Mosaic ended sucessfully"));
206  }
207  else
208  {
209  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic execution error.") +
210  ( " " + algorithmInstance.getErrorMessage() ).c_str());
211 
212  QApplication::restoreOverrideCursor();
213 
214  te::common::FreeContents(rasters);
215 
216  return false;
217  }
218  }
219  else
220  {
221  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic initialization error.") +
222  ( " " + algorithmInstance.getErrorMessage() ).c_str() );
223 
224  QApplication::restoreOverrideCursor();
225 
226  te::common::FreeContents(rasters);
227 
228  return false;
229  }
230  }
231  catch(const std::exception& e)
232  {
233  QMessageBox::warning(this, tr("Mosaic"), e.what());
234 
235  QApplication::restoreOverrideCursor();
236 
237  te::common::FreeContents(rasters);
238 
239  return false;
240  }
241  catch(...)
242  {
243  QMessageBox::warning(this, tr("Mosaic"), tr("An exception has occurred!"));
244 
245  QApplication::restoreOverrideCursor();
246 
247  te::common::FreeContents(rasters);
248 
249  return false;
250  }
251 
252  QApplication::restoreOverrideCursor();
253 
254  te::common::FreeContents(rasters);
255 
256  return true;
257 }
258 
260 {
261 //run Tie Point Mosaic
262  te::rp::TiePointsMosaic algorithmInstance;
263 
264  te::rp::TiePointsMosaic::InputParameters algoInputParams = m_mosaicPage->getInputTPParams();
265  algoInputParams.m_enableProgress = true;
266 
267 //get rasters
268  std::list<te::map::AbstractLayerPtr> list;
269  list.push_back(m_mosaicPage->getTiePointMosaicLayerA());
270  list.push_back(m_mosaicPage->getTiePointMosaicLayerB());
271 
272  std::list<te::map::AbstractLayerPtr>::iterator it = list.begin();
273  std::vector<std::size_t> bands;
274 
275  std::vector<const te::rst::Raster*> rasters;
276 
277  while(it != list.end())
278  {
280 
282 
283  rasters.push_back(rst);
284 
285  std::vector<unsigned int> bands;
286 
287  for(unsigned int i = 0; i < rst->getNumberOfBands(); ++i)
288  bands.push_back(i);
289 
290  algoInputParams.m_inputRastersBands.push_back( bands );
291 
292  ++it;
293  }
294 
295  te::rp::FeederConstRasterVector feeder(rasters);
296  algoInputParams.m_feederRasterPtr = &feeder;
297 
298  te::rp::TiePointsMosaic::OutputParameters algoOutputParams = m_mosaicPage->getOutputTPParams();
299  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
300  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
301 
302  //progress
304 
305  QApplication::setOverrideCursor(Qt::WaitCursor);
306 
307  try
308  {
309  if(algorithmInstance.initialize(algoInputParams))
310  {
311  if(algorithmInstance.execute(algoOutputParams))
312  {
313  algoOutputParams.reset();
314 
315  //set output layer
316  te::map::AbstractLayerPtr outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
317  m_rasterInfoPage->getWidget()->getInfo());
318 
319  m_outputLayerList.push_back(outputLayer);
320 
321  te::qt::widgets::applyRasterMultiResolution(tr("Mosaic"), te::map::GetRaster(outputLayer.get()));
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  ( " " + algorithmInstance.getErrorMessage() ).c_str());
329 
330  QApplication::restoreOverrideCursor();
331 
332  return false;
333  }
334  }
335  else
336  {
337  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic initialization error.") +
338  ( " " + algorithmInstance.getErrorMessage() ).c_str() );
339 
340  QApplication::restoreOverrideCursor();
341 
342  return false;
343  }
344  }
345  catch(const std::exception& e)
346  {
347  QMessageBox::warning(this, tr("Mosaic"), e.what());
348 
349  QApplication::restoreOverrideCursor();
350 
351  return false;
352  }
353  catch(...)
354  {
355  QMessageBox::warning(this, tr("Mosaic"), tr("An exception has occurred!"));
356 
357  QApplication::restoreOverrideCursor();
358 
359  return false;
360  }
361 
362  QApplication::restoreOverrideCursor();
363 
364  return true;
365 }
366 
368 {
369 //run Sequence Mosaic
370  te::rp::SequenceMosaic algorithmInstance;
371 
372  te::rp::SequenceMosaic::InputParameters algoInputParams = m_mosaicPage->getInputSeqParams();
373 
374  //get rasters
375  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
376 
377  std::list<te::map::AbstractLayerPtr>::iterator it = list.begin();
378  std::vector<std::size_t> bands;
379 
380  std::vector<const te::rst::Raster*> rasters;
381 
382  while(it != list.end())
383  {
385 
387 
388  rasters.push_back(rst);
389 
390  std::vector<unsigned int> bands;
391 
392  for(unsigned int i = 0; i < rst->getNumberOfBands(); ++i)
393  bands.push_back(i);
394 
395  algoInputParams.m_inputRastersBands.push_back( bands );
396 
397  ++it;
398  }
399 
400  te::rp::FeederConstRasterVector feeder(rasters);
401  algoInputParams.m_feederRasterPtr = &feeder;
402 
403  algoInputParams.m_outDataSetsNamePrefix = m_rasterInfoPage->getWidget()->getShortName();
404  algoInputParams.m_outDataSetsNameSufix = m_rasterInfoPage->getWidget()->getExtension();
405 
406  std::unique_ptr<te::da::DataSource> ds = m_rasterInfoPage->getWidget()->getDataSource();
407 
408  te::rp::SequenceMosaic::OutputParameters algoOutputParams = m_mosaicPage->getOutputSeqParams();
409  algoOutputParams.m_outputDSPtr = ds.get();
410  //algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
411  //algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
412 
413  //progress
415 
416  QApplication::setOverrideCursor(Qt::WaitCursor);
417 
418  try
419  {
420  if(algorithmInstance.initialize(algoInputParams))
421  {
422  if(algorithmInstance.execute(algoOutputParams))
423  {
424  for(std::size_t t = 0; t < algoOutputParams.m_sequencesInfo.size(); ++t)
425  {
426  std::string name = algoOutputParams.m_sequencesInfo[t].m_dataSetName;
427  std::string path = m_rasterInfoPage->getWidget()->getPath();
428 
429  std::map<std::string, std::string> rinfo;
430  rinfo["URI"] = path + name;
431 
432  te::map::AbstractLayerPtr outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(), rinfo);
433 
434  m_outputLayerList.push_back(outputLayer);
435 
436  te::qt::widgets::applyRasterMultiResolution(tr("Mosaic"), te::map::GetRaster(outputLayer.get()));
437  }
438 
439  algoOutputParams.reset();
440 
441  QMessageBox::information(this, tr("Mosaic"), tr("Mosaic ended sucessfully"));
442  }
443  else
444  {
445  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic execution error.") +
446  ( " " + algorithmInstance.getErrorMessage() ).c_str());
447 
448  QApplication::restoreOverrideCursor();
449 
450  te::common::FreeContents(rasters);
451 
452  return false;
453  }
454  }
455  else
456  {
457  QMessageBox::critical(this, tr("Mosaic"), tr("Mosaic initialization error.") +
458  ( " " + algorithmInstance.getErrorMessage() ).c_str() );
459 
460  QApplication::restoreOverrideCursor();
461 
462  te::common::FreeContents(rasters);
463 
464  return false;
465  }
466  }
467  catch(const std::exception& e)
468  {
469  QMessageBox::warning(this, tr("Mosaic"), e.what());
470 
471  QApplication::restoreOverrideCursor();
472 
473  te::common::FreeContents(rasters);
474 
475  return false;
476  }
477  catch(...)
478  {
479  QMessageBox::warning(this, tr("Mosaic"), tr("An exception has occurred!"));
480 
481  QApplication::restoreOverrideCursor();
482 
483  te::common::FreeContents(rasters);
484 
485  return false;
486  }
487 
488  QApplication::restoreOverrideCursor();
489 
490  te::common::FreeContents(rasters);
491 
492  return true;
493 }
494 
496 {
497  this->adjustSize();
498 }
const std::string & getErrorMessage() const
Return the current error message if there is any.
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).
A feeder from a input rasters vector;.
Definition: FeedersRaster.h:69
std::unique_ptr< te::qt::widgets::MosaicWizardPage > m_mosaicPage
Definition: MosaicWizard.h:90
std::list< te::map::AbstractLayerPtr > getOutputLayers()
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
std::unique_ptr< te::qt::widgets::RasterInfoWizardPage > m_rasterInfoPage
Definition: MosaicWizard.h:92
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
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.
static te::dt::Date ds(2010, 01, 01)
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
bool execute(AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
Executes the algorithm using the supplied parameters.
Definition: GeoMosaic.cpp:163
std::vector< std::vector< unsigned int > > m_inputRastersBands
Bands to process for each input raster.
FeederConstRaster * m_feederRasterPtr
Input rasters feeder.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
An abstract class for raster data strucutures.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
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()
list bands
Definition: compose.py:2
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 ).
Utility functions for the data access module.
std::list< te::map::AbstractLayerPtr > m_outputLayerList
Definition: MosaicWizard.h:94
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.
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
std::unique_ptr< te::qt::widgets::LayerSearchWizardPage > m_layerSearchPage
Definition: MosaicWizard.h:91
bool initialize(const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
Initialize the algorithm instance making it ready for execution.
Definition: GeoMosaic.cpp:760
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.
GeoMosaic output parameters.
Definition: GeoMosaic.h:100
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
std::vector< std::vector< unsigned int > > m_inputRastersBands
Bands to process for each input raster.
Definition: GeoMosaic.h:62
list rasters
Definition: compose.py:3
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 void applyRasterMultiResolution(const QString &toolName, te::rst::Raster *raster)
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
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated resources and reset the parameters instance to its initial state...
Definition: GeoMosaic.cpp:132
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.