27 #include "../../../common/progress/ProgressManager.h"
28 #include "../../../common/StringUtils.h"
29 #include "../../../dataaccess/dataset/DataSet.h"
30 #include "../../../dataaccess/utils/Utils.h"
31 #include "../../../raster/Raster.h"
32 #include "../../../rp/Segmenter.h"
33 #include "../../../rp/SegmenterRegionGrowingStrategy.h"
34 #include "../progress/ProgressViewerDialog.h"
37 #include "ui_SegmenterWizardPageForm.h"
40 #include <QGridLayout>
42 #include <QIntValidator>
43 #include <QMessageBox>
50 : QWizardPage(parent),
51 m_ui(new Ui::SegmenterWizardPageForm),
60 QGridLayout* displayLayout =
new QGridLayout(
m_ui->m_frame);
65 displayLayout->setContentsMargins(0,0,0,0);
68 this->setTitle(tr(
"Segmenter"));
69 this->setSubTitle(tr(
"Select the type of segmenter and set their specific parameters."));
71 QIntValidator* intValRG =
new QIntValidator(
this);
72 intValRG->setBottom(0);
73 m_ui->m_minimumSegmentSizeRGLineEdit->setValidator(intValRG);
75 QIntValidator* intValB =
new QIntValidator(
this);
76 intValB->setBottom(0);
77 m_ui->m_minimumSegmentSizeRGLineEdit_2->setValidator(intValB);
79 m_ui->m_noDataValueLineEdit->setValidator(
new QDoubleValidator(
this));
82 m_ui->m_minimumSegmentSizeRGLineEdit->setText( QString::number( regGrowStrategyParameters.
m_minSegmentSize ) );
83 m_ui->m_minimumSegmentSizeRGLineEdit_2->setText( QString::number( regGrowStrategyParameters.
m_minSegmentSize ) );
86 m_ui->m_colorWeightBaatzDoubleSpinBox->setValue( regGrowStrategyParameters.
m_colorWeight );
100 int nBands = m_ui->m_bandTableWidget->rowCount();
102 for(
int i = 0; i < nBands; ++i)
104 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
106 if(checkBox->isChecked())
119 std::list<te::map::AbstractLayerPtr> list;
121 list.push_back(m_layer);
123 m_navigator->set(m_layer,
true);
138 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
140 m_inputRst.reset(ds->getRaster(rpos).release());
145 int nBands = m_ui->m_bandTableWidget->rowCount();
147 for(
int i = 0; i < nBands; ++i)
149 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
151 if(checkBox->isChecked())
155 if(m_ui->m_noDataValueCheckBox->isChecked() && !m_ui->m_noDataValueLineEdit->text().isEmpty())
162 int index = m_ui->m_strategyTypeComboBox->currentIndex();
164 std::string strategyName = m_ui->m_strategyTypeComboBox->itemData(index).toString().toStdString();
166 if(strategyName ==
"RegionGrowing")
169 strategyParameters.
m_minSegmentSize = m_ui->m_minimumSegmentSizeRGLineEdit->text().toUInt();
178 else if(strategyName ==
"Baatz")
181 strategyParameters.
m_minSegmentSize = m_ui->m_minimumSegmentSizeRGLineEdit->text().toUInt();
187 for(
int i = 0; i < nBands; ++i)
189 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
191 if(checkBox->isChecked())
193 QDoubleSpinBox* spinBox = (QDoubleSpinBox*)m_ui->m_bandTableWidget->cellWidget(i, 1);
199 strategyParameters.
m_colorWeight = m_ui->m_colorWeightBaatzDoubleSpinBox->value();
200 strategyParameters.
m_compactnessWeight = m_ui->m_compactnessWeightBaatzDoubleSpinBox->value();
206 return algoInputParams;
211 std::string strategyName = m_ui->m_strategyTypeComboBox->itemData(index).toString().toStdString();
213 if(strategyName ==
"RegionGrowing")
216 list.append(tr(
"Band"));
218 m_ui->m_bandTableWidget->setColumnCount(1);
219 m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
221 else if(strategyName ==
"Baatz")
224 list.append(tr(
"Band"));
225 list.append(tr(
"Weight"));
227 m_ui->m_bandTableWidget->setColumnCount(2);
228 m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
230 int nBands = m_ui->m_bandTableWidget->rowCount();
232 for(
int i = 0; i < nBands; ++i)
234 QDoubleSpinBox* spinBox =
new QDoubleSpinBox(m_ui->m_bandTableWidget);
235 spinBox->setMinimum(0.0);
236 spinBox->setMaximum(1.0);
237 spinBox->setSingleStep(0.1);
238 spinBox->setDecimals(4);
239 spinBox->setValue(0.3333);
241 m_ui->m_bandTableWidget->setCellWidget(i, 1, spinBox);
245 m_ui->m_bandTableWidget->resizeColumnsToContents();
247 #if (QT_VERSION >= 0x050000)
248 m_ui->m_bandTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
250 m_ui->m_bandTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
256 QApplication::setOverrideCursor(Qt::WaitCursor);
270 std::map<std::string, std::string> rinfo;
271 rinfo[
"MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(inputRst->
getNumberOfRows());
272 rinfo[
"MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(inputRst->
getNumberOfColumns());
273 rinfo[
"MEM_RASTER_DATATYPE"] = boost::lexical_cast<std::string>(inputRst->
getBandDataType(0));
274 rinfo[
"MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(inputRst->
getNumberOfBands());
276 algoOutputParams.
m_rType =
"MEM";
277 algoOutputParams.
m_rInfo = rinfo;
288 if(algorithmInstance.
initialize(algoInputParams))
290 if(algorithmInstance.
execute(algoOutputParams))
294 m_navigator->drawRaster(rst.get());
300 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Constrast error."));
305 QApplication::restoreOverrideCursor();
313 m_ui->m_strategyTypeComboBox->clear();
315 m_ui->m_strategyTypeComboBox->addItem(tr(
"Region Growing"),
"RegionGrowing");
316 m_ui->m_strategyTypeComboBox->addItem(tr(
"Baatz"),
"Baatz");
321 assert(m_layer.get());
324 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
330 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
334 for(
unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
336 m_ui->m_bandTableWidget->setRowCount(0);
339 for(
unsigned b = 0 ; b < inputRst->getNumberOfBands(); b++)
341 int newrow = m_ui->m_bandTableWidget->rowCount();
342 m_ui->m_bandTableWidget->insertRow(newrow);
344 QString bName(tr(
"Band "));
345 bName.append(QString::number(b));
347 QCheckBox* bandCheckBox =
new QCheckBox(bName,
this);
348 bandCheckBox->setChecked(
true );
350 m_ui->m_bandTableWidget->setCellWidget(newrow, 0, bandCheckBox);
void fillSegmenterTypes()
The Baatz based features will be used - Reference: Baatz, M.; Schape, A. Multiresolution segmentation...
Segmenter Output Parameters.
std::auto_ptr< te::qt::widgets::RasterNavigatorWidget > m_navigator
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
bool m_enableSameIterationMerges
If enabled, a merged segment could be merged with another within the same iteration (default:false)...
std::auto_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
SegmenterWizardPage(QWidget *parent=0)
std::vector< double > m_bandsWeights
The weight given to each band, when applicable (note: the bands weights sum must always be 1) or an e...
void removeViewer(int viewerId)
Dettach a progress viewer.
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
The mean of segments pixel values will be used - Reference: S. A. Bins, L. M. G. Fonseca, G. J. Erthal e F. M. Ii, "Satellite Imagery segmentation: a region growing approach", VIII Simposio Brasileiro de Sensoriamento Remoto, Salvador, BA, 14-19 abril 1996.
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
SegmentFeaturesType m_segmentFeatures
What segment features will be used on the segmentation process (default:InvalidFeaturesType).
std::auto_ptr< Ui::SegmenterWizardPageForm > m_ui
unsigned int m_minSegmentSize
A positive minimum segment size (pixels number - default: 100).
double m_segmentsSimilarityThreshold
Segments similarity treshold - Use lower values to merge only those segments that are more similar - ...
void onStrategyTypeComboBoxActivated(int index)
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
te::rp::Segmenter::InputParameters getInputParams()
te::map::AbstractLayerPtr get()
double m_colorWeight
The weight given to the color component, deafult:0.9, valid range: [0,1].
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for segmenter operation.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
double m_compactnessWeight
The weight given to the compactness component, deafult:0.5, valid range: [0,1].
This file defines a class for a Segmenter Wizard page.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
bool m_enableLocalMutualBestFitting
If enabled, a merge only occurs between two segments if the minimum dissimilarity criteria is best fu...
virtual int getBandDataType(std::size_t i) const =0
Returns the data type in a particular band (or dimension).