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);
80 m_ui->m_minimumSegmentSizeRGLineEdit->setText( QString::number( regGrowStrategyParameters.
m_minSegmentSize ) );
81 m_ui->m_minimumSegmentSizeRGLineEdit_2->setText( QString::number( regGrowStrategyParameters.
m_minSegmentSize ) );
84 m_ui->m_colorWeightBaatzDoubleSpinBox->setValue( regGrowStrategyParameters.
m_colorWeight );
98 int nBands = m_ui->m_bandTableWidget->rowCount();
100 for(
int i = 0; i < nBands; ++i)
102 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
104 if(checkBox->isChecked())
117 std::list<te::map::AbstractLayerPtr> list;
119 list.push_back(m_layer);
121 m_navigator->set(m_layer,
true);
136 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
138 m_inputRst.reset(ds->getRaster(rpos).release());
143 int nBands = m_ui->m_bandTableWidget->rowCount();
145 for(
int i = 0; i < nBands; ++i)
147 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
149 if(checkBox->isChecked())
155 int index = m_ui->m_strategyTypeComboBox->currentIndex();
157 std::string strategyName = m_ui->m_strategyTypeComboBox->itemData(index).toString().toStdString();
159 if(strategyName ==
"RegionGrowing")
162 strategyParameters.
m_minSegmentSize = m_ui->m_minimumSegmentSizeRGLineEdit->text().toUInt();
169 else if(strategyName ==
"Baatz")
172 strategyParameters.
m_minSegmentSize = m_ui->m_minimumSegmentSizeRGLineEdit->text().toUInt();
176 for(
int i = 0; i < nBands; ++i)
178 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
180 if(checkBox->isChecked())
182 QDoubleSpinBox* spinBox = (QDoubleSpinBox*)m_ui->m_bandTableWidget->cellWidget(i, 1);
188 strategyParameters.
m_colorWeight = m_ui->m_colorWeightBaatzDoubleSpinBox->value();
189 strategyParameters.
m_compactnessWeight = m_ui->m_compactnessWeightBaatzDoubleSpinBox->value();
195 return algoInputParams;
200 std::string strategyName = m_ui->m_strategyTypeComboBox->itemData(index).toString().toStdString();
202 if(strategyName ==
"RegionGrowing")
205 list.append(tr(
"Band"));
207 m_ui->m_bandTableWidget->setColumnCount(1);
208 m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
210 else if(strategyName ==
"Baatz")
213 list.append(tr(
"Band"));
214 list.append(tr(
"Weight"));
216 m_ui->m_bandTableWidget->setColumnCount(2);
217 m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
219 int nBands = m_ui->m_bandTableWidget->rowCount();
221 for(
int i = 0; i < nBands; ++i)
223 QDoubleSpinBox* spinBox =
new QDoubleSpinBox(m_ui->m_bandTableWidget);
224 spinBox->setMinimum(0.0);
225 spinBox->setMaximum(1.0);
226 spinBox->setSingleStep(0.1);
227 spinBox->setDecimals(4);
228 spinBox->setValue(0.3333);
230 m_ui->m_bandTableWidget->setCellWidget(i, 1, spinBox);
234 m_ui->m_bandTableWidget->resizeColumnsToContents();
236 #if (QT_VERSION >= 0x050000)
237 m_ui->m_bandTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
239 m_ui->m_bandTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
245 QApplication::setOverrideCursor(Qt::WaitCursor);
260 std::map<std::string, std::string> rinfo;
261 rinfo[
"MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(inputRst->
getNumberOfRows());
262 rinfo[
"MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(inputRst->
getNumberOfColumns());
263 rinfo[
"MEM_RASTER_DATATYPE"] = boost::lexical_cast<std::string>(inputRst->
getBandDataType(0));
264 rinfo[
"MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(inputRst->
getNumberOfBands());
266 algoOutputParams.
m_rType =
"MEM";
267 algoOutputParams.
m_rInfo = rinfo;
278 if(algorithmInstance.
initialize(algoInputParams))
280 if(algorithmInstance.
execute(algoOutputParams))
284 m_navigator->drawRaster(rst.get());
290 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Constrast error."));
295 QApplication::restoreOverrideCursor();
303 m_ui->m_strategyTypeComboBox->clear();
305 m_ui->m_strategyTypeComboBox->addItem(tr(
"Region Growing"),
"RegionGrowing");
306 m_ui->m_strategyTypeComboBox->addItem(tr(
"Baatz"),
"Baatz");
311 assert(m_layer.get());
314 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
320 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
324 for(
unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
326 m_ui->m_bandTableWidget->setRowCount(0);
329 for(
unsigned b = 0 ; b < inputRst->getNumberOfBands(); b++)
331 int newrow = m_ui->m_bandTableWidget->rowCount();
332 m_ui->m_bandTableWidget->insertRow(newrow);
334 QString bName(tr(
"Band "));
335 bName.append(QString::number(b));
337 QCheckBox* bandCheckBox =
new QCheckBox(bName,
this);
338 bandCheckBox->setChecked(
true );
340 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.
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.75, 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
virtual int getBandDataType(std::size_t i) const =0
Returns the data type in a particular band (or dimension).