27 #include "../../../dataaccess/dataset/DataSet.h" 28 #include "../../../dataaccess/utils/Utils.h" 29 #include "../../../raster/Raster.h" 30 #include "../../../maptools/RasterContrast.h" 31 #include "../../../maptools/Utils.h" 32 #include "../../../rp/Contrast.h" 33 #include "../../../rp/Functions.h" 34 #include "../../../rp/MixtureModel.h" 35 #include "../../../rp/Module.h" 36 #include "../help/HelpPushButton.h" 37 #include "../layer/search/LayerSearchWidget.h" 38 #include "../layer/search/LayerSearchWizardPage.h" 39 #include "../raster/RasterInfoWidget.h" 49 #include <QApplication> 50 #include <QMessageBox> 51 #include <QActionGroup> 61 this->setWizardStyle(QWizard::ModernStyle);
62 this->setWindowTitle(tr(
"Mixture Model"));
64 this->setOption(QWizard::HaveHelpButton,
true);
65 this->setOption(QWizard::HelpButtonOnRight,
false);
69 this->setButton(QWizard::HelpButton, helpButton);
73 connect(
this, SIGNAL(currentIdChanged(
int)), SLOT(
onPageChanged(
int)));
87 std::list<te::map::AbstractLayerPtr> list =
m_layerSearchPage->getSearchWidget()->getSelecteds();
89 if(list.empty() ==
false)
157 std::vector<unsigned int> inputRasterBands;
158 unsigned int nbands = 0;
161 std::string outputDataSetNamePath =
m_rasterInfoPage->getWidget()->getPath();
162 std::string outputDataSetNamePrefix =
m_rasterInfoPage->getWidget()->getShortName();
163 std::string outputDataSetNameExt =
m_rasterInfoPage->getWidget()->getExtension();
165 std::vector< std::map<std::string, std::string> > outputRastersInfos;
168 std::vector<std::string> outputDataSetNames;
169 std::map<std::string, std::vector<double> >::iterator it;
172 std::string name = outputDataSetNamePrefix;
175 name += outputDataSetNameExt;
177 outputDataSetNames.push_back(name);
179 std::map<std::string, std::string> rinfo;
181 std::string fileName =
182 outputDataSetNamePath
185 rinfo[
"URI"] = fileName;
187 outputRastersInfos.push_back(rinfo);
188 inputRasterBands.push_back(nbands++);
194 std::string name = outputDataSetNamePrefix;
197 name += outputDataSetNameExt;
199 outputDataSetNames.push_back(name);
200 std::map<std::string, std::string> rinfo;
202 std::string fileName =
203 outputDataSetNamePath
206 rinfo[
"URI"] = fileName;
208 outputRastersInfos.push_back(rinfo);
209 inputRasterBands.push_back(nbands++);
213 std::vector< boost::shared_ptr< te::rst::Raster > > outputRastersPtrs;
221 catch (
const std::exception& e)
223 QMessageBox::warning(
this, tr(
"Mixture Model - Decompose"), e.what());
224 QApplication::restoreOverrideCursor();
225 outputRastersPtrs.clear();
230 QMessageBox::warning(
this, tr(
"Mixture Model - Decompose"), tr(
"An exception has occurred!"));
231 QApplication::restoreOverrideCursor();
232 outputRastersPtrs.clear();
236 QApplication::restoreOverrideCursor();
241 outputRastersPtrs.clear();
244 for (std::size_t t = 0; t < outputRastersInfos.size(); ++t)
246 std::map<std::string, std::string> rinfo = outputRastersInfos[t];
258 QMessageBox::warning(
this, tr(
"Mixture Model"), tr(
"File already exists."));
264 std::list<te::map::AbstractLayerPtr> ::iterator it_l;
265 for (it_l = l.begin(); it_l != l.end(); it_l++)
276 QMessageBox::critical(
this, tr(
"Mixture Model"), tr(
"The number of components must be the same as the number of selected bands"));
281 std::map<std::string, std::string> error_rinfo;
286 std::string name_out = algoOutputParams.
m_rInfo[
"URI"];
287 std::size_t pos = name_out.find_last_of(
'.');
288 name_out.insert(pos,
"_Error");
289 error_rinfo.insert(std::pair<std::string, std::string>(
"URI", name_out));
295 std::vector<double> min;
296 std::vector<double> max;
298 QApplication::setOverrideCursor(Qt::WaitCursor);
300 if(algorithmInstance.
initialize(algoInputParams))
302 if(algorithmInstance.
execute(algoOutputParams))
304 min = algoOutputParams.
m_min;
305 max = algoOutputParams.
m_max;
306 if (error_rinfo.size())
308 for (
size_t i = 0; i < algoOutputParams.
m_minerror.size(); ++i)
310 min.push_back(algoOutputParams.
m_minerror[i]);
311 max.push_back(algoOutputParams.
m_maxerror[i]);
318 decompose(algoInputParams, algoOutputParams);
322 algoOutputParams.
reset();
325 if (error_rinfo.size())
330 QApplication::restoreOverrideCursor();
332 int addOutPutLayer = QMessageBox::question(
this, tr(
"Mixture Model"), tr(
"Would you like to add layer on active project?"),
333 QMessageBox::Yes | QMessageBox::No);
335 if (addOutPutLayer == QMessageBox::Yes)
337 std::list<te::map::AbstractLayerPtr>::iterator itl;
347 (outputlayer.get())->setRasterContrast(contrast);
350 double gain, offset1, offset2;
353 contrast->
setValues(gain, offset1, offset2, min[
b], max[b], b);
363 QApplication::restoreOverrideCursor();
365 QMessageBox::critical(
this, tr(
"Mixture Model"), tr(
"Mixture Model execution error.") +
373 QApplication::restoreOverrideCursor();
374 QMessageBox::critical(
this, tr(
"Mixture Model"), tr(
"Mixture Model initialization error." ) +
381 QApplication::restoreOverrideCursor();
const std::string & getErrorMessage() const
Return the current error message if there is any.
void reset()
Reset all variables.
std::vector< double > m_min
Minimun value calculeted in output raster.
void setValues(const double &gain, const double &offset1, const double &offset2, const double &min, const double &max, const std::size_t &band)
It set the transformation values for contranst of one band.
This file defines a class for a MixtureModel Wizard page.
Raster decomposition using mixture model.
std::map< std::string, std::string > m_rInfoError
The necessary information to create the error raster (as described in te::raster::RasterFactory).
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
static bool getGainAndOffset(const InputParameters::ContrastType &type, const double &inRangeMin, const double &inRangeMax, const double &outRangeMin, const double &outRangeMax, double &gain, double &offset1, double &offset2)
Returns gain and offset values for contrast types (when applicable).
bool DecomposeBands(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< std::map< std::string, std::string > > &outputRastersInfos, const std::string &outputDataSourceType, std::vector< boost::shared_ptr< te::rst::Raster > > &outputRastersPtrs)
Decompose a multi-band raster into a set of one-band rasters.
This file defines a class for a Raster Info Wizard page.
This class is GUI used to define the mixture model parameters for the RP constast operation...
A Qt dialog that allows users to run a mixture model operation defined by RP module.
std::map< std::string, std::string > m_rInfo
The necessary information to create the output raster (as described in te::raster::RasterFactory).
std::vector< double > m_max
Maximum value calculeted in output raster.
std::vector< double > m_minerror
Minimun value calculeted in output raster.
This class is GUI used to define the raster info parameters for raster factory.
std::vector< double > m_maxerror
Maximum value calculeted in output raster.
Utility functions for the data access module.
This class contains the parameters needed to apply dynamic contrast over a raster.
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
MixtureModel output parameters.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the mixing model using the parameters defined in inputParams and outputParams.
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
A pointer to the generated output raster, one band per component plus one error band per component (w...
bool m_createErrorRaster
A flag to indicate that output raster will include the error bands.
bool initialize(const AlgorithmInputParameters &inputParams)
Initializes model with paramters defined in inputParams.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr