All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SegmenterWizard.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/SegmenterWizard.cpp
22 
23  \brief A Qt dialog that allows users to run a segmenter operation defined by RP module.
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/Raster.h"
31 #include "../../../rp/Segmenter.h"
32 #include "../../../rp/SegmenterRegionGrowingStrategy.h"
33 #include "../../../rp/Module.h"
34 #include "../../widgets/help/HelpPushButton.h"
35 #include "../../widgets/progress/ProgressViewerDialog.h"
36 #include "SegmenterWizard.h"
38 #include "SegmenterWizardPage.h"
39 #include "LayerSearchWidget.h"
40 #include "LayerSearchWizardPage.h"
41 #include "RasterInfoWidget.h"
42 #include "RasterInfoWizardPage.h"
43 #include "ui_SegmenterAdvancedOptionsWizardPageForm.h"
44 #include "Utils.h"
45 
46 // STL
47 #include <cassert>
48 
49 // Qt
50 #include <QtGui/QMessageBox>
51 
52 
54  : QWizard(parent)
55 {
56  //configure the wizard
57  this->setWizardStyle(QWizard::ModernStyle);
58  this->setWindowTitle(tr("Segmenter"));
59  //this->setFixedSize(640, 580);
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_segmenter.html");
69 
70  addPages();
71 }
72 
74 {
75 
76 }
77 
79 {
80  if(currentPage() == m_layerSearchPage.get())
81  {
82  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
83 
84  if(list.empty() == false)
85  {
86  te::map::AbstractLayerPtr l = *list.begin();
87 
88  m_segmenterPage->set(l);
89  }
90 
91  return m_layerSearchPage->isComplete();
92  }
93  else if(currentPage() == m_segmenterPage.get())
94  {
95  bool res = m_segmenterPage->isComplete();
96 
97  if(!res)
98  QMessageBox::warning(this, tr("Warning"), tr("Select at least one band."));
99 
100  return res;
101  }
102  else if(currentPage() == m_rasterInfoPage.get())
103  {
104  return execute();
105  }
106 
107  return true;
108 }
109 
110 void te::qt::widgets::SegmenterWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
111 {
112  m_layerSearchPage->getSearchWidget()->setList(layerList);
113  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
114 }
115 
117 {
118  removePage(m_layerSearchId);
119 
120  m_segmenterPage->set(layer);
121 }
122 
124 {
125  return m_outputLayer;
126 }
127 
129 {
130  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
131  m_segmenterPage.reset(new te::qt::widgets::SegmenterWizardPage(this));
132  m_segmenterAdvOptPage.reset(new te::qt::widgets::SegmenterAdvancedOptionsWizardPage(this));
133  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
134 
135  m_layerSearchId = addPage(m_layerSearchPage.get());
136  addPage(m_segmenterPage.get());
137  addPage(m_segmenterAdvOptPage.get());
138  addPage(m_rasterInfoPage.get());
139 
140  //for contrast only one layer can be selected
141  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
142 }
143 
145 {
146  if(m_rasterInfoPage->getWidget()->fileExists())
147  {
148  QMessageBox::warning(this, tr("Segmenter"), tr("File already exists."));
149  return false;
150  }
151 
152  //get layer
153  te::map::AbstractLayerPtr l = m_segmenterPage->get();
154  std::auto_ptr<te::da::DataSet> ds(l->getData());
155 
156  //run contrast
157  te::rp::Segmenter algorithmInstance;
158 
159  te::rp::Segmenter::InputParameters algoInputParams = m_segmenterPage->getInputParams();
160 
161  algoInputParams.m_enableProgress = true;
162  algoInputParams.m_enableThreadedProcessing = m_segmenterAdvOptPage->getForm()->m_enableThreadedProcessingcheckBox->isChecked();
163  algoInputParams.m_maxSegThreads = m_segmenterAdvOptPage->getForm()->m_maximumThreadsNumberLineEdit->text().toUInt();
164  algoInputParams.m_enableBlockProcessing = m_segmenterAdvOptPage->getForm()->m_enableBlockProcessingcheckBox->isChecked();
165  algoInputParams.m_enableBlockMerging = m_segmenterAdvOptPage->getForm()->m_enableBlockMergingCheckBox->isChecked();
166  algoInputParams.m_maxBlockSize = m_segmenterAdvOptPage->getForm()->m_maximumBlockSizeLineEdit->text().toUInt();
167 
168  te::rp::Segmenter::OutputParameters algoOutputParams;
169  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
170  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
171 
172  //progress
174  int id = te::common::ProgressManager::getInstance().addViewer(&v);
175 
176  QApplication::setOverrideCursor(Qt::WaitCursor);
177 
178  try
179  {
180  if(algorithmInstance.initialize(algoInputParams))
181  {
182  if(algorithmInstance.execute(algoOutputParams))
183  {
184  algoOutputParams.reset();
185 
186  //set output layer
187  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
188  m_rasterInfoPage->getWidget()->getInfo());
189 
190  QMessageBox::information(this, tr("Segmenter"), tr("Segmenter ended sucessfully"));
191  }
192  else
193  {
194  QMessageBox::critical(this, tr("Segmenter"), tr("Segmenter execution error"));
195 
196  te::common::ProgressManager::getInstance().removeViewer(id);
197 
198  QApplication::restoreOverrideCursor();
199 
200  return false;
201  }
202  }
203  else
204  {
205  QMessageBox::critical(this, tr("Segmenter"), tr("Segmenter initialization error") +
206  ( " " + te::rp::Module::getLastLogStr() ).c_str());
207 
208  te::common::ProgressManager::getInstance().removeViewer(id);
209 
210  QApplication::restoreOverrideCursor();
211 
212  return false;
213  }
214  }
215  catch(const std::exception& e)
216  {
217  QMessageBox::warning(this, tr("Register"), e.what());
218 
219  te::common::ProgressManager::getInstance().removeViewer(id);
220 
221  QApplication::restoreOverrideCursor();
222 
223  return false;
224  }
225  catch(...)
226  {
227  QMessageBox::warning(this, tr("Register"), tr("An exception has occuried!"));
228 
229  te::common::ProgressManager::getInstance().removeViewer(id);
230 
231  QApplication::restoreOverrideCursor();
232 
233  return false;
234  }
235 
236  te::common::ProgressManager::getInstance().removeViewer(id);
237 
238  QApplication::restoreOverrideCursor();
239 
240  return true;
241 }
242 
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: Segmenter.h:100
This file defines a class for a Segmenter Wizard page.
This class is GUI used to define the segmenter advanced options parameters for the RP constast operat...
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Definition: Segmenter.h:150
static const std::string & getLastLogStr()
Returns the last log string generated by this module.
Definition: Module.h:53
This file defines a class for a Raster Info Wizard page.
Segmenter Input Parameters.
Definition: Segmenter.h:80
bool m_enableBlockMerging
If true, a block merging procedure will be performed (default:true).
Definition: Segmenter.h:94
This file has the RasterInfoWidget class.
Segmenter Output Parameters.
Definition: Segmenter.h:144
unsigned int m_maxSegThreads
The maximum number of concurrent segmenter threads (default:0 - automatically found).
Definition: Segmenter.h:90
void setLayer(te::map::AbstractLayerPtr layer)
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
te::map::AbstractLayerPtr getOutputLayer()
bool m_enableBlockProcessing
If true, the original raster will be splitted into small blocks, each one will be segmented independe...
Definition: Segmenter.h:92
This file defines the LayerSearchWizardPage class.
This file defines the LayerSearchWidget class.
bool m_enableThreadedProcessing
If true, threaded processing will be performed (best with multi-core or multi-processor systems (defa...
Definition: Segmenter.h:88
Utility functions for the data access module.
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const std::map< std::string, std::string > &connInfo)
Definition: Utils.cpp:40
void setPageReference(const QString &ref)
Sets the documentation page reference.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
Definition: Segmenter.cpp:151
This class is GUI used to define the raster info parameters for raster factory.
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
A Qt dialog that allows users to run a segmenter operation defined by RP module.
Raster segmentation.
Definition: Segmenter.h:72
This class is GUI used to define the segmenter parameters for the RP constast operation.
This file defines a class for a Segmenter Advanced Options Wizard page.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
static T & getInstance()
It returns a reference to the singleton instance.
Definition: Singleton.h:120
unsigned int m_maxBlockSize
The input image will be split into blocks with this width for processing, this parameter tells the ma...
Definition: Segmenter.h:96
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Segmenter.h:148