examples/rp/Contrast.cpp
Go to the documentation of this file.
1 #include "RPExamples.h"
2 
3 // TerraLib
4 
5 #include <terralib/dataaccess.h>
6 #include <terralib/geometry.h>
7 #include <terralib/memory.h>
8 #include <terralib/raster.h>
9 #include <terralib/rp.h>
10 
11 // STL
12 #include <string>
13 #include <map>
14 #include <iostream>
15 
16 void Contrast()
17 {
18  try
19  {
20  std::cout << "Linear Contrast example using Raster Processing module." << std::endl << std::endl;
21 
22 // open input raster
23  std::map<std::string, std::string> rinfo;
24  rinfo["URI"] = TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif";
25 
27 
28  bool executeok = false;
29  bool initok = false;
30  {
31  std::cout << "Using Linear Contrast" << std::endl;
32 
33 // create output raster for linear contrast
34  std::map<std::string, std::string> orinfo;
35  orinfo["URI"] = TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop_linear_contrast.tif";
36 
37 // create contrast algorithm parameters
38  te::rp::Contrast::InputParameters contInputParameters;
39  te::rp::Contrast::OutputParameters contOutputParameters;
40 
42  contInputParameters.m_lCMinInput.resize( rin->getNumberOfBands(), 100 );
43  contInputParameters.m_lCMaxInput.resize( rin->getNumberOfBands(), 255 );
44  contInputParameters.m_inRasterPtr = rin;
45  for (unsigned b = 0; b < rin->getNumberOfBands(); b++)
46  {
47  contInputParameters.m_inRasterBands.push_back(b);
48  }
49  contOutputParameters.m_createdOutRasterInfo = orinfo;
50  contOutputParameters.m_createdOutRasterDSType = "GDAL";
51 
52 // execute the algorithm
53  te::rp::Contrast continstance;
54 
55  initok = continstance.initialize(contInputParameters );
56 
57  if (initok)
58  executeok = continstance.execute( contOutputParameters );
59 
60  if (!executeok)
61  std::cout << "Problems in linear contrast." << std::endl;
62  }
63 
64  // clean up
65  delete rin;
66 
67  if (executeok)
68  std::cout << "Done!" << std::endl << std::endl;
69  else
70  std::cout << "Problems in contrast." << std::endl;
71  }
72  catch(const std::exception& e)
73  {
74  std::cout << std::endl << "An exception has occurred in Contrast(): " << e.what() << std::endl;
75  }
76  catch(...)
77  {
78  std::cout << std::endl << "An unexpected exception has occurred in Contrast()!" << std::endl;
79  }
80 }
81 
This file contains include headers for the memory data source of TerraLib.
std::vector< double > m_lCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:106
ContrastType m_type
The contrast type to be applied.
Definition: Contrast.h:87
These routines show how to use the RP (raster processing) module.
int b
Definition: TsRtree.cpp:32
Contrast input parameters.
Definition: Contrast.h:65
An abstract class for raster data strucutures.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
void Contrast()
This file contains include headers for the TerraLib Raster Processing module.
std::vector< unsigned int > m_inRasterBands
Bands to be processed from the input raster.
Definition: Contrast.h:91
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
std::vector< double > m_lCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:108
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
std::string m_createdOutRasterDSType
Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the resul...
Definition: Contrast.h:198
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: Contrast.h:89
This file contains include headers for the Vector Geometry model of TerraLib.
This file contains include headers for the Data Access module of TerraLib.
Contrast output parameters.
Definition: Contrast.h:188
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:200
Contrast enhancement.
Definition: Contrast.h:57
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.