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 "../../../maptools/Utils.h" 33 #include "../../../rp/Segmenter.h" 34 #include "../../../rp/SegmenterRegionGrowingBaatzStrategy.h" 35 #include "../../../rp/SegmenterRegionGrowingMeanStrategy.h" 36 #include "../progress/ProgressViewerDialog.h" 39 #include "ui_SegmenterWizardPageForm.h" 42 #include <QGridLayout> 44 #include <QIntValidator> 45 #include <QMessageBox> 53 m_ui(new
Ui::SegmenterWizardPageForm),
62 QGridLayout* displayLayout =
new QGridLayout(
m_ui->m_frame);
67 displayLayout->setContentsMargins(0,0,0,0);
70 this->setTitle(tr(
"Segmenter"));
71 this->setSubTitle(tr(
"Select the type of segmenter and set their specific parameters."));
73 QIntValidator* intValRG =
new QIntValidator(
this);
74 intValRG->setBottom(0);
75 m_ui->m_minimumSegmentSizeRGLineEdit->setValidator(intValRG);
77 QIntValidator* intValB =
new QIntValidator(
this);
78 intValB->setBottom(0);
79 m_ui->m_minimumSegmentSizeRGLineEdit_2->setValidator(intValB);
81 m_ui->m_noDataValueLineEdit->setValidator(
new QDoubleValidator(
this));
84 m_ui->m_minimumSegmentSizeRGLineEdit->setText( QString::number( regGrowStrategyParameters.
m_minSegmentSize ) );
85 m_ui->m_minimumSegmentSizeRGLineEdit_2->setText( QString::number( regGrowStrategyParameters.
m_minSegmentSize ) );
88 m_ui->m_colorWeightBaatzDoubleSpinBox->setValue( regGrowStrategyParameters.
m_colorWeight );
103 int nBands =
m_ui->m_bandTableWidget->rowCount();
105 for(
int i = 0; i < nBands; ++i)
107 QCheckBox* checkBox = (QCheckBox*)
m_ui->m_bandTableWidget->cellWidget(i, 0);
109 if(checkBox->isChecked())
122 std::list<te::map::AbstractLayerPtr> list;
147 int nBands =
m_ui->m_bandTableWidget->rowCount();
149 for(
int i = 0; i < nBands; ++i)
151 QCheckBox* checkBox = (QCheckBox*)
m_ui->m_bandTableWidget->cellWidget(i, 0);
153 if(checkBox->isChecked())
157 if(
m_ui->m_noDataValueCheckBox->isChecked() && !
m_ui->m_noDataValueLineEdit->text().isEmpty())
164 int index =
m_ui->m_strategyTypeComboBox->currentIndex();
166 std::string strategyName =
m_ui->m_strategyTypeComboBox->itemData(index).toString().toUtf8().data();
168 if(strategyName ==
"RegionGrowingMean")
179 else if(strategyName ==
"RegionGrowingBaatz")
187 double weightsSum = 0.0;
188 for(
int i = 0; i < nBands; ++i)
190 QCheckBox* checkBox = (QCheckBox*)
m_ui->m_bandTableWidget->cellWidget(i, 0);
192 if(checkBox->isChecked())
194 QDoubleSpinBox* spinBox = (QDoubleSpinBox*)
m_ui->m_bandTableWidget->cellWidget(i, 1);
205 strategyParameters.
m_bandsWeights[ nBands - 1 ] += ( 1.0 - weightsSum );
208 strategyParameters.
m_colorWeight =
m_ui->m_colorWeightBaatzDoubleSpinBox->value();
215 return algoInputParams;
220 std::string strategyName =
m_ui->m_strategyTypeComboBox->itemData(index).toString().toUtf8().data();
222 if(strategyName ==
"RegionGrowingMean")
225 list.append(tr(
"Band"));
227 m_ui->m_bandTableWidget->setColumnCount(1);
228 m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
230 else if(strategyName ==
"RegionGrowingBaatz")
233 list.append(tr(
"Band"));
234 list.append(tr(
"Weight"));
236 m_ui->m_bandTableWidget->setColumnCount(2);
237 m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
239 int nBands =
m_ui->m_bandTableWidget->rowCount();
241 for(
int i = 0; i < nBands; ++i)
243 QDoubleSpinBox* spinBox =
new QDoubleSpinBox(
m_ui->m_bandTableWidget);
244 spinBox->setMinimum(0.0);
245 spinBox->setMaximum(1.0);
246 spinBox->setSingleStep(0.1);
247 spinBox->setDecimals(4);
248 spinBox->setValue( 1.0 / ((
double)nBands) );
250 m_ui->m_bandTableWidget->setCellWidget(i, 1, spinBox);
254 m_ui->m_bandTableWidget->resizeColumnsToContents();
256 #if (QT_VERSION >= 0x050000) 257 m_ui->m_bandTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
259 m_ui->m_bandTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
265 QApplication::setOverrideCursor(Qt::WaitCursor);
279 std::map<std::string, std::string> rinfo;
280 rinfo[
"MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(inputRst->
getNumberOfRows());
281 rinfo[
"MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(inputRst->
getNumberOfColumns());
282 rinfo[
"MEM_RASTER_DATATYPE"] = boost::lexical_cast<std::string>(inputRst->
getBandDataType(0));
283 rinfo[
"MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(inputRst->
getNumberOfBands());
285 algoOutputParams.
m_rType =
"MEM";
286 algoOutputParams.
m_rInfo = rinfo;
296 if(algorithmInstance.
initialize(algoInputParams))
298 if(algorithmInstance.
execute(algoOutputParams))
308 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Segmenter error."));
311 QApplication::restoreOverrideCursor();
319 m_ui->m_strategyTypeComboBox->clear();
321 m_ui->m_strategyTypeComboBox->addItem(tr(
"Region Growing"),
"RegionGrowingMean");
322 m_ui->m_strategyTypeComboBox->addItem(tr(
"Region Growing Baatz"),
"RegionGrowingBaatz");
330 std::unique_ptr<te::da::DataSet>
ds =
m_layer->getData();
336 std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
340 for(
unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
342 m_ui->m_bandTableWidget->setRowCount(0);
345 for(
unsigned b = 0 ;
b < inputRst->getNumberOfBands();
b++)
347 int newrow =
m_ui->m_bandTableWidget->rowCount();
348 m_ui->m_bandTableWidget->insertRow(newrow);
350 QString bName(tr(
"Band "));
351 bName.append(QString::number(
b));
353 QCheckBox* bandCheckBox =
new QCheckBox(bName,
this);
354 bandCheckBox->setChecked(
true );
356 m_ui->m_bandTableWidget->setCellWidget(newrow, 0, bandCheckBox);
void fillSegmenterTypes()
Segmenter Output Parameters.
double m_segmentsSimilarityThreshold
Segments similarity treshold - Use lower values to merge only those segments that are more similar - ...
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
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...
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
double m_compactnessWeight
The weight given to the compactness component, deafult:0.5, valid range: [0,1].
double m_colorWeight
The weight given to the color component, deafult:0.9, valid range: [0,1].
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
bool m_enableSameIterationMerges
If enabled, a merged segment could be merged with another within the same iteration (default:false)...
std::unique_ptr< te::rst::Raster > m_inputRst
unsigned int m_minSegmentSize
A positive minimum segment size (pixels number - default: 100).
static te::dt::Date ds(2010, 01, 01)
SegmenterWizardPage(QWidget *parent=0)
bool m_enableLocalMutualBestFitting
If enabled, a merge only occurs between two segments if the minimum dissimilarity criteria is best fu...
bool m_enableSameIterationMerges
If enabled, a merged segment could be merged with another within the same iteration (default:false)...
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.
virtual int getBandDataType(std::size_t i) const =0
Returns the data type in a particular band (or dimension).
std::unique_ptr< te::qt::widgets::RasterNavigatorWidget > m_navigator
double m_segmentsSimilarityThreshold
Segments similarity treshold - Use lower values to merge only those segments that are more similar - ...
unsigned int m_minSegmentSize
A positive minimum segment size (pixels number - default: 100).
void onStrategyTypeComboBoxActivated(int index)
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
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()
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.
te::map::AbstractLayerPtr m_layer
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
bool m_enableLocalMutualBestFitting
If enabled, a merge only occurs between two segments if the minimum dissimilarity criteria is best fu...
This file defines a class for a Segmenter Wizard page.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::unique_ptr< Ui::SegmenterWizardPageForm > m_ui