examples/qt/rp/main.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 main.cpp
22 
23  \brief A list of examples for the TerraLib Widgets.
24  */
25 
26 // TerraLib
27 #include "../../Config.h"
28 #include "Config.h"
29 #include "LoadModules.h"
30 #include <terralib/common.h>
31 #include <terralib/core/plugin.h>
32 #include <terralib/dataaccess.h>
34 #include <terralib/gdal/Utils.h>
35 #include <terralib/geometry.h>
36 //#include <terralib/maptools/RasterLayerRenderer.h> // * Under revision *
37 
44 
45 // QT
46 #include <QApplication>
47 
48 // STL
49 #include <exception>
50 #include <iostream>
51 
52 void TiePointsLocatorDialogExample( int argc, char** argv )
53 {
54  // * Under revision *
55 
56  // open the input rasters
57 
58  //const std::string dataSet1Name( "cbers2b_rgb342_crop.tif" );
59  //std::map<std::string, std::string> rinfo1;
60  //rinfo1["URI"] = TE_DATA_EXAMPLE_DIR "/rasters";
61  //std::unique_ptr< te::da::DataSource > ds1( te::da::DataSourceFactory::make("GDAL") );
62  //ds1->open(rinfo1);
63  //if( ! ds1->isOpened() )
64  //{
65  // std::cout << std::endl << "Data source openning error";
66  // return;
67  //}
68  //std::unique_ptr< te::map::RasterLayer > raster1Layer(
69  // new te::map::RasterLayer(dataSet1Name, dataSet1Name) );
70  //raster1Layer->setDataSource(ds1.get());
71  //raster1Layer->setDataSetName(dataSet1Name);
72  //if( ! raster1Layer->isValid() )
73  //{
74  // std::cout << std::endl << "Invalid layer";
75  // return;
76  //}
77  //te::map::RasterLayerRenderer* renderer1 = new te::map::RasterLayerRenderer();
78  //raster1Layer->setRenderer( renderer1 );
79  //raster1Layer->setVisibility(te::map::VISIBLE);
80 
81  //const std::string dataSet2Name( "cbers2b_rgb342_crop.tif" );
82  //std::map<std::string, std::string> rinfo2;
83  //rinfo2["URI"] = TE_DATA_EXAMPLE_DIR "/rasters";
84  //std::unique_ptr< te::da::DataSource > ds2( te::da::DataSourceFactory::make("GDAL") );
85  //ds2->open(rinfo2);
86  //if( ! ds2->isOpened() )
87  //{
88  // std::cout << std::endl << "Data source openning error";
89  // return;
90  //}
91  //std::unique_ptr< te::map::RasterLayer > raster2Layer(
92  // new te::map::RasterLayer(dataSet2Name, dataSet2Name) );
93  //raster2Layer->setDataSource(ds2.get());
94  //raster2Layer->setDataSetName(dataSet2Name);
95  //if( ! raster2Layer->isValid() )
96  //{
97  // std::cout << std::endl << "Invalid layer";
98  // return;
99  //}
100  //te::map::RasterLayerRenderer* renderer2 = new te::map::RasterLayerRenderer();
101  //raster2Layer->setRenderer( renderer2 );
102  //raster2Layer->setVisibility(te::map::VISIBLE);
103 
104  //// Executing the dialog
105 
106  //QApplication app(argc, argv);
107 
108  //te::qt::widgets::TiePointsLocatorDialog dialogInstance( raster1Layer.get(),
109  // raster2Layer.get(), 0, 0 );
110 
111  //dialogInstance.exec();
112 
113  //dialogInstance.hide();
114 
115  //// Getting the result
116 
117  //std::vector< te::gm::GTParameters::TiePoint > tiePoints;
118  //dialogInstance.getTiePoints( tiePoints );
119 }
120 
121 void SegmenterDialogExample( int argc, char** argv )
122 {
123  // open the input raster
124 
125  std::string data_dir = TERRALIB_DATA_DIR;
126 
127  std::map<std::string, std::string> rinfo;
128  rinfo["URI"] = data_dir + "/geotiff/cbers2b_rgb342_crop.tif";
129 
130  std::unique_ptr< te::rst::Raster > inputRasterPointer( te::rst::RasterFactory::open(rinfo) );
131 
132  // Defining the output raster info
133 
134  std::map<std::string, std::string> outputRasterInfo;
135  outputRasterInfo["URI"] = data_dir + "/geotiff/terralib_example_qt_rp_SegmenterDialog.tif";
136 
137  // Executing the dialog
138 
139  QApplication app(argc, argv);
140 
141  te::qt::widgets::SegmenterDialog dialogInstance( inputRasterPointer.get(),
142  "GDAL", outputRasterInfo, 0, 0 );
143 
144  dialogInstance.exec();
145 
146  dialogInstance.hide();
147 
148  // Getting the result
149 
150  boost::shared_ptr< te::rst::Raster > outputRasterPtr;
151  dialogInstance.getOutputRaster( outputRasterPtr );
152 }
153 
154 void ContrastDialogExample( int argc, char** argv )
155 {
156  // open the input raster
157 
158  std::string data_dir = TERRALIB_DATA_DIR;
159 
160  std::map<std::string, std::string> rinfo;
161  rinfo["URI"] = data_dir + "/geotiff/cbers2b_rgb342_crop.tif";
162 
163  std::unique_ptr< te::rst::Raster > inputRasterPointer( te::rst::RasterFactory::open(rinfo) );
164 
165  // Defining the output raster info
166 
167  std::map<std::string, std::string> outputRasterInfo;
168  outputRasterInfo["URI"] = data_dir + "/geotiff/terralib_example_qt_rp_ContrastDialog.tif";
169 
170  // Executing the dialog
171 
172  QApplication app(argc, argv);
173 
174  te::qt::widgets::ContrastDialog dialogInstance( inputRasterPointer.get(),
175  "GDAL", outputRasterInfo, 0, 0 );
176 
177  dialogInstance.exec();
178 
179  dialogInstance.hide();
180 
181  // Getting the result
182 
183  boost::shared_ptr< te::rst::Raster > outputRasterPtr;
184  dialogInstance.getOutputRaster( outputRasterPtr );
185 }
186 
187 void ClassifierDialogExample(int argc, char** argv)
188 {
189 // open the input raster
190  std::string data_dir = TERRALIB_DATA_DIR;
191 
192  std::map<std::string, std::string> rinfo;
193  rinfo["URI"] = data_dir + "/geotiff/cbers2b_rgb342_crop.tif";
194 
195  std::unique_ptr<te::rst::Raster> inputRasterPointer(te::rst::RasterFactory::open(rinfo));
196 
197 // define the output raster info
198  std::map<std::string, std::string> outputRasterInfo;
199  outputRasterInfo["URI"] = data_dir + "/geotiff/terralib_example_qt_rp_ClassifierDialog.tif";
200 
201 // execute the dialog
202  QApplication app(argc, argv);
203 
204 // open a previously segmentation (from SegmenterDialogExample)
205  std::map<std::string, std::string> segmentedinfo;
206  segmentedinfo["URI"] = data_dir + "/geotiff/terralib_example_qt_rp_SegmenterDialog.tif";
207  std::unique_ptr<te::rst::Raster> segmentedraster(te::rst::RasterFactory::open(segmentedinfo));
208 
209 // vectorize the segmentation
210  std::vector<te::gm::Geometry*> geometries;
211  te::gdal::Vectorize(((te::gdal::Raster*) segmentedraster.get())->getGDALDataset()->GetRasterBand(1), geometries);
212  std::vector<te::gm::Polygon*> inputPolygons;
213  for (unsigned i = 0; i < geometries.size(); i++)
214  inputPolygons.push_back(static_cast<te::gm::Polygon*> (geometries[i]));
215 
216 // create GUI dialog
217  te::qt::widgets::ClassifierDialog dialogInstance(inputRasterPointer.get(), inputPolygons, "GDAL", outputRasterInfo, 0, 0);
218 
219  dialogInstance.exec();
220 
221  dialogInstance.hide();
222 
223 // get the result
224  boost::shared_ptr< te::rst::Raster > outputRasterPtr;
225 
226  dialogInstance.getOutputRaster(outputRasterPtr);
227 }
228 
229 void MixtureModelDialogExample(int argc, char** argv)
230 {
231 // open the input raster
232  std::string data_dir = TERRALIB_DATA_DIR;
233 
234  const std::string dsname("cbers2b_rgb342_crop.tif");
235  std::string rinfo ("file://");
236  rinfo += data_dir + "/geotiff/cbers2b_rgb342_crop.tif";
237  std::unique_ptr<te::da::DataSource> ds = te::da::DataSourceFactory::make("GDAL", rinfo);
238 
239  ds->open();
240  if(!ds->isOpened())
241  {
242  std::cout << std::endl << "Data source openning error";
243  return;
244  }
245 
246 // define the output raster info
247  std::map<std::string, std::string> outputRasterInfo;
248  outputRasterInfo["URI"] = data_dir + "/geotiff/terralib_example_qt_rp_MixtureModelDialog.tif";
249 
250 // execute the dialog
251  QApplication app(argc, argv);
252 
253 // get the result
254  boost::shared_ptr< te::rst::Raster > outputRasterPtr;
255 }
256 
257 int main(int argc, char** argv)
258 {
259  try
260  {
261  // initialize Terralib support
263 
264  LoadModules();
265 
266  TiePointsLocatorDialogExample( argc, argv );
267  SegmenterDialogExample( argc, argv );
268  ContrastDialogExample( argc, argv );
269  ClassifierDialogExample( argc, argv );
270  MixtureModelDialogExample( argc, argv );
271  }
272  catch(const std::exception& e)
273  {
274  std::cout << std::endl << "An exception has occurred: " << e.what() << std::endl;
275 
276  return EXIT_FAILURE;
277  }
278  catch(...)
279  {
280  std::cout << std::endl << "An unexpected exception has occurred!" << std::endl;
281 
282  return EXIT_FAILURE;
283  }
284 
286 
287 
288 // finalize Terralib support
290 
291  return EXIT_SUCCESS;
292 }
TEGDALEXPORT void Vectorize(GDALRasterBand *band, std::vector< te::gm::Geometry * > &geometries)
Vectorizes a given raster band, using GDALPolygonize function.
void MixtureModelDialogExample(int argc, char **argv)
A dialog used to execute image classification.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
Include files for Core Plugin Library.
A dialog used to execute image classification.
bool getOutputRaster(boost::shared_ptr< te::rst::Raster > &outputRasterPtr)
Returns the output result raster.
This class represents Raster data.
int main(int argc, char **argv)
static te::dt::Date ds(2010, 01, 01)
void ContrastDialogExample(int argc, char **argv)
void SegmenterDialogExample(int argc, char **argv)
void ClassifierDialogExample(int argc, char **argv)
Proxy file for the real global configuration of TerraLib examples.
bool getOutputRaster(boost::shared_ptr< te::rst::Raster > &outputRasterPtr)
Returns the output result raster.
A dialog used to execute image segmentation.
This is the abstract factory for Rasters.
static PluginManager & instance()
Access the singleton.
void finalize()
It finalizes the TerraLib Platform.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
A dialog used to execute mixture model decomposition.
A factory for data sources.
bool getOutputRaster(boost::shared_ptr< te::rst::Raster > &outputRasterPtr)
Returns the output result raster.
void initialize()
It initializes the TerraLib Platform.
void TiePointsLocatorDialogExample(int argc, char **argv)
This file contains include headers for the TerraLib Common Runtime module.
A dialog used to execute image segmentation.
This file contains include headers for the Vector Geometry model of TerraLib.
void clear()
Stop and unload all plugins, then clear the internal list of plugins.
A dialog used to execute image contrast enhencement.
A dialog used to execute image contrast enhencement.
This file contains include headers for the Data Access module of TerraLib.
A dialog used to execute tie points location.
void LoadModules()
Load terralib modules.
Utilitary functions to access GDAL and match some of its concepts to TerraLib concepts.
static Raster * open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
It opens a raster with the given parameters and default raster driver.