27 #include "../../../common/StringUtils.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"
35 #include "ui_SegmenterWizardPageForm.h"
38 #include <QGridLayout>
39 #include <QtGui/QCheckBox>
40 #include <QtGui/QIntValidator>
41 #include <QtGui/QMessageBox>
48 : QWizardPage(parent),
49 m_ui(new Ui::SegmenterWizardPageForm),
58 QGridLayout* displayLayout =
new QGridLayout(
m_ui->m_frame);
63 displayLayout->setContentsMargins(0,0,0,0);
66 this->setTitle(tr(
"Segmenter"));
67 this->setSubTitle(tr(
"Select the type of segmenter and set their specific parameters."));
69 QIntValidator* intValRG =
new QIntValidator(
this);
70 intValRG->setBottom(0);
71 m_ui->m_minimumSegmentSizeRGLineEdit->setValidator(intValRG);
73 QIntValidator* intValB =
new QIntValidator(
this);
74 intValB->setBottom(0);
75 m_ui->m_minimumSegmentSizeRGLineEdit_2->setValidator(intValB);
79 m_ui->m_colorWeightBaatzDoubleSpinBox->setValue( regGrowStrategyParameters.
m_colorWeight );
93 int nBands = m_ui->m_bandTableWidget->rowCount();
95 for(
int i = 0; i < nBands; ++i)
97 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
99 if(checkBox->isChecked())
112 std::list<te::map::AbstractLayerPtr> list;
114 list.push_back(m_layer);
116 m_navigator->set(m_layer,
true);
131 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
133 m_inputRst.reset(ds->getRaster(rpos).release());
138 int nBands = m_ui->m_bandTableWidget->rowCount();
140 for(
int i = 0; i < nBands; ++i)
142 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
144 if(checkBox->isChecked())
150 int index = m_ui->m_strategyTypeComboBox->currentIndex();
152 std::string strategyName = m_ui->m_strategyTypeComboBox->itemData(index).toString().toStdString();
154 if(strategyName ==
"RegionGrowing")
157 strategyParameters.
m_minSegmentSize = m_ui->m_minimumSegmentSizeRGLineEdit->text().toUInt();
164 else if(strategyName ==
"Baatz")
167 strategyParameters.
m_minSegmentSize = m_ui->m_minimumSegmentSizeRGLineEdit->text().toUInt();
171 for(
int i = 0; i < nBands; ++i)
173 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
175 if(checkBox->isChecked())
177 QDoubleSpinBox* spinBox = (QDoubleSpinBox*)m_ui->m_bandTableWidget->cellWidget(i, 1);
183 strategyParameters.
m_colorWeight = m_ui->m_colorWeightBaatzDoubleSpinBox->value();
184 strategyParameters.
m_compactnessWeight = m_ui->m_compactnessWeightBaatzDoubleSpinBox->value();
190 return algoInputParams;
195 std::string strategyName = m_ui->m_strategyTypeComboBox->itemData(index).toString().toStdString();
197 if(strategyName ==
"RegionGrowing")
200 list.append(tr(
"Band"));
202 m_ui->m_bandTableWidget->setColumnCount(1);
203 m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
205 else if(strategyName ==
"Baatz")
208 list.append(tr(
"Band"));
209 list.append(tr(
"Weight"));
211 m_ui->m_bandTableWidget->setColumnCount(2);
212 m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
214 int nBands = m_ui->m_bandTableWidget->rowCount();
216 for(
int i = 0; i < nBands; ++i)
218 QDoubleSpinBox* spinBox =
new QDoubleSpinBox(m_ui->m_bandTableWidget);
219 spinBox->setMinimum(0.0);
220 spinBox->setMaximum(1.0);
221 spinBox->setSingleStep(0.1);
222 spinBox->setDecimals(4);
223 spinBox->setValue(0.3333);
225 m_ui->m_bandTableWidget->setCellWidget(i, 1, spinBox);
229 m_ui->m_bandTableWidget->resizeColumnsToContents();
230 m_ui->m_bandTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
235 QApplication::setOverrideCursor(Qt::WaitCursor);
250 std::map<std::string, std::string> rinfo;
253 rinfo[
"MEM_RASTER_DATATYPE"] = boost::lexical_cast<std::string>(inputRst->
getBandDataType(0));
254 rinfo[
"MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(inputRst->
getNumberOfBands());
256 algoOutputParams.
m_rType =
"MEM";
257 algoOutputParams.
m_rInfo = rinfo;
264 if(algorithmInstance.
initialize(algoInputParams))
266 if(algorithmInstance.
execute(algoOutputParams))
270 m_navigator->drawRaster(rst.get());
276 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Constrast error."));
279 QApplication::restoreOverrideCursor();
287 m_ui->m_strategyTypeComboBox->clear();
289 m_ui->m_strategyTypeComboBox->addItem(tr(
"Region Growing"),
"RegionGrowing");
290 m_ui->m_strategyTypeComboBox->addItem(tr(
"Baatz"),
"Baatz");
295 assert(m_layer.get());
298 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
304 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
308 for(
unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
310 m_ui->m_bandTableWidget->setRowCount(0);
313 for(
unsigned b = 0 ; b < inputRst->getNumberOfBands(); b++)
315 int newrow = m_ui->m_bandTableWidget->rowCount();
316 m_ui->m_bandTableWidget->insertRow(newrow);
318 QString bName(tr(
"Band "));
319 bName.append(QString::number(b));
321 QCheckBox* bandCheckBox =
new QCheckBox(bName,
this);
322 bandCheckBox->setChecked(
true );
324 m_ui->m_bandTableWidget->setCellWidget(newrow, 0, bandCheckBox);
void onStrategyTypeComboBoxActivated(int index)
std::auto_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
std::string m_strategyName
The segmenter strategy name see each te::rp::SegmenterStrategyFactory inherited classes documentation...
This file defines a class for a Segmenter Wizard page.
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for segmenter operation.
This file has the RasterNavigatorWidget class.
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
unsigned int getNumberOfRows() const
Returns the raster number of rows.
SegmenterWizardPage(QWidget *parent=0)
Segmenter Input Parameters.
bool m_enableBlockMerging
If true, a block merging procedure will be performed (default:true).
te::rp::Segmenter::InputParameters getInputParams()
te::rst::Raster const * m_inputRasterPtr
Input raster.
double m_compactnessWeight
The weight given to the compactness component, deafult:0.5, valid range: [0,1].
Segmenter Output Parameters.
This class is used to navigate over a DataSetLayer (having a raster representation) and given a set o...
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
double m_colorWeight
The weight given to the color component, deafult:0.5, valid range: [0,1].
bool m_enableBlockProcessing
If true, the original raster will be splitted into small blocks, each one will be segmented independe...
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
bool m_enableThreadedProcessing
If true, threaded processing will be performed (best with multi-core or multi-processor systems (defa...
virtual int getBandDataType(std::size_t i) const =0
Returns the data type in a particular band (or dimension).
The Baatz based features will be used - Reference: Baatz, M.; Schape, A. Multiresolution segmentation...
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
void fillSegmenterTypes()
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
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...
unsigned int m_minSegmentSize
A positive minimum segment size (pixels number - default: 100).
SegmentFeaturesType m_segmentFeatures
What segment features will be used on the segmentation process (default:InvalidFeaturesType).
std::auto_ptr< te::qt::widgets::RasterNavigatorWidget > m_navigator
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
double m_segmentsSimilarityThreshold
Segments similarity treshold - Segments with similarity values below this value will be merged; valid...
An abstract class for raster data strucutures.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
std::auto_ptr< Ui::SegmenterWizardPageForm > m_ui
void setSegStrategyParams(const SegmenterStrategyParameters &segStratParams)
Set specific segmenter strategy parameters.
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.
te::map::AbstractLayerPtr get()