All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ContrastDialog.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/rp/widgets/se/ContrastDialog.cpp
22 
23  \brief A dialog used to execute image contrast enhencement
24 */
25 
26 
27 #include "ContrastDialog.h"
28 
29 #include "../../../rp/Contrast.h"
30 #include <ui_ContrastForm.h>
31 
32 #include <QMessageBox>
33 #include <QListWidgetItem>
34 
35 // TerraLib
36 
38  te::rst::Raster const* inputRasterPtr, const std::string& outpuRasterDSType,
39  const std::map< std::string, std::string >& outpuRasterInfo,
40  QWidget* parent, Qt::WindowFlags f)
41  : QDialog( parent, f ),
42  m_inputRasterPtr( inputRasterPtr ),
43  m_outputRasterIsInputRaster( false ),
44  m_outpuRasterDSType( outpuRasterDSType ),
45  m_outpuRasterInfo( outpuRasterInfo )
46 {
47  m_uiPtr = new Ui::ContrastForm;
48  m_uiPtr->setupUi(this);
49 
50  // Signals & slots
51  connect(m_uiPtr->m_okPushButton, SIGNAL(clicked()), SLOT(on_okPushButton_clicked()));
52 
53  // initializing the input raster bands combo
54 
55  for( unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
56  inputRasterPtr->getNumberOfBands() ; ++inRasterBandsIdx )
57  {
58  m_uiPtr->m_inputRasterBandsListWidget->addItem(
59  QString::number( inRasterBandsIdx ) );
60  }
61 }
62 
64  te::rst::Raster const* inputRasterPtr, QWidget* parent, Qt::WindowFlags f)
65  : QDialog( parent, f ),
66  m_inputRasterPtr( inputRasterPtr ),
67  m_outputRasterIsInputRaster( true )
68 {
69  m_uiPtr = new Ui::ContrastForm;
70  m_uiPtr->setupUi(this);
71 
72  // Signals & slots
73  connect(m_uiPtr->m_okPushButton, SIGNAL(clicked()), SLOT(on_okPushButton_clicked()));
74 
75  // initializing the input raster bands combo
76 
77  for( unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
78  inputRasterPtr->getNumberOfBands() ; ++inRasterBandsIdx )
79  {
80  m_uiPtr->m_inputRasterBandsListWidget->addItem(
81  QString::number( inRasterBandsIdx ) );
82  }
83 }
84 
86 {
87  delete m_uiPtr;
88 }
89 
91  boost::shared_ptr< te::rst::Raster >& outputRasterPtr )
92 {
93  if( m_outputRasterPtr.get() )
94  {
95  outputRasterPtr = m_outputRasterPtr;
96  return true;
97  }
98  else
99  {
100  return false;
101  }
102 }
103 
105 {
106  m_outputRasterPtr.reset();
107 
108  if( m_inputRasterPtr )
109  {
110  // Creating the algorithm parameters
111 
112  te::rp::Contrast::InputParameters algoInputParams;
113  te::rp::Contrast::OutputParameters algoOutputParams;
114 
115  algoInputParams.m_inRasterPtr = m_inputRasterPtr;
116 
117  QList<QListWidgetItem *> selectedBands =
118  m_uiPtr->m_inputRasterBandsListWidget->selectedItems();
119 
120  if( selectedBands.size() > 0 )
121  {
122  QList<QListWidgetItem *>::const_iterator itBegin = selectedBands.begin();
123  QList<QListWidgetItem *>::const_iterator itEnd = selectedBands.end();
124  while( itBegin != itEnd )
125  {
126  algoInputParams.m_inRasterBands.push_back( (*itBegin)->text().toUInt() );
127  algoOutputParams.m_outRasterBands.push_back( (*itBegin)->text().toUInt() );
128  ++itBegin;
129  }
130 
131  if( m_uiPtr->m_contrastTypeComboBox->currentText() ==
132  tr( "Histogram Equalization" ) )
133  {
134  algoInputParams.m_type =
136  algoInputParams.m_hECMaxInput.resize( selectedBands.size(),
137  m_uiPtr->m_hECMaxInputLineEdit->text().toDouble() );
138  }
139  else if( m_uiPtr->m_contrastTypeComboBox->currentText() ==
140  tr( "Linear" ) )
141  {
142  algoInputParams.m_type =
144  algoInputParams.m_lCMinInput.resize( selectedBands.size(),
145  m_uiPtr->m_lCMinInputLineEdit->text().toDouble() );
146  algoInputParams.m_lCMaxInput.resize( selectedBands.size(),
147  m_uiPtr->m_lCMaxInputLineEdit->text().toDouble() );
148  }
149  else if( m_uiPtr->m_contrastTypeComboBox->currentText() ==
150  tr( "Mean and standard deviation" ) )
151  {
152  algoInputParams.m_type =
154  algoInputParams.m_sMASCMeanInput.resize( selectedBands.size(),
155  m_uiPtr->m_sMASCMeanInputLineEdit->text().toDouble() );
156  algoInputParams.m_sMASCStdInput.resize( selectedBands.size(),
157  m_uiPtr->m_sMASCStdInputLineEdit->text().toDouble() );
158  }
159 
160  if( m_outputRasterIsInputRaster )
161  {
162  algoOutputParams.m_outRasterPtr = (te::rst::Raster*)m_inputRasterPtr;
163  }
164  else
165  {
166  algoOutputParams.m_createdOutRasterDSType = m_outpuRasterDSType;
167  algoOutputParams.m_createdOutRasterInfo = m_outpuRasterInfo;
168  }
169 
170  // Executing the algorithm
171 
172  te::rp::Contrast algorithmInstance;
173 
174  if( algorithmInstance.initialize( algoInputParams ) )
175  {
176  if( algorithmInstance.execute( algoOutputParams ) )
177  {
178  if( ! m_outputRasterIsInputRaster )
179  {
180  m_outputRasterPtr = algoOutputParams.m_createdOutRasterPtr;
181  }
182 
183  QMessageBox::information(this, "", tr("Contrast enhencement ended sucessfully"));
184  }
185  else
186  {
187  QMessageBox::critical(this, "", tr("Contrast enhencement execution error"));
188  }
189  }
190  else
191  {
192  QMessageBox::critical(this, "", tr("Contrast enhencement initialization error"));
193  }
194  }
195  else
196  {
197  QMessageBox::critical(this, "", tr("Invalid number of bands"));
198  }
199  }
200  else
201  {
202  QMessageBox::critical(this, "", tr("Invalid input raster"));
203  }
204 }
std::vector< double > m_lCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:102
te::rst::Raster * m_outRasterPtr
A pointer to a valid initiated raster instance where the result must be written, leave NULL to create...
Definition: Contrast.h:188
bool getOutputRaster(boost::shared_ptr< te::rst::Raster > &outputRasterPtr)
Returns the output result raster.
ContrastType m_type
The contrast type to be applied.
Definition: Contrast.h:87
Contrast input parameters.
Definition: Contrast.h:65
An abstract class for raster data strucutures.
Definition: Raster.h:71
std::vector< unsigned int > m_outRasterBands
Bands to be processed from the output raster.
Definition: Contrast.h:192
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
std::vector< unsigned int > m_inRasterBands
Bands to be processed from the input raster.
Definition: Contrast.h:91
std::vector< double > m_hECMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:113
std::vector< double > m_sMASCStdInput
The standard deviation to be applied in each band.
Definition: Contrast.h:157
std::auto_ptr< te::rst::Raster > m_createdOutRasterPtr
A pointer to the created output raster instance, or an empty pointer empty if the result must be writ...
Definition: Contrast.h:190
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Definition: Contrast.cpp:299
std::vector< double > m_lCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:104
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
Definition: Contrast.cpp:178
std::vector< double > m_sMASCMeanInput
The mean greyscale to be applied in each band.
Definition: Contrast.h:155
std::string m_createdOutRasterDSType
Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the resul...
Definition: Contrast.h:194
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: Contrast.h:89
ContrastDialog(te::rst::Raster const *inputRasterPtr, const std::string &outpuRasterDSType, const std::map< std::string, std::string > &outpuRasterInfo, QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic dialog which is a child of parent, with widget flags set to f. ...
A dialog used to execute image contrast enhencement.
Contrast output parameters.
Definition: Contrast.h:184
std::map< std::string, std::string > m_createdOutRasterInfo
The necessary information to create the raster (as described in te::raster::RasterFactory), leave empty if the result must be written to the raster pointed m_outRasterPtr.
Definition: Contrast.h:196
Contrast enhancement.
Definition: Contrast.h:57