examples/rp/IHSFusion.cpp
Go to the documentation of this file.
1 #include "RPExamples.h"
2 
3 // TerraLib
4 #include <terralib/rp.h>
5 #include <terralib/raster.h>
6 
7 #include <iostream>
8 
9 void IHSFusion()
10 {
11  try
12  {
13  std::cout << "Example of how to apply the IHS Fusion using Raster Processing module." << std::endl << std::endl;
14 
15  // Openning the the input image
16 
17  std::map<std::string, std::string> auxRasterInfo1;
18  auxRasterInfo1["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
19  te::rst::Raster* inputRasterPointer1 = te::rst::RasterFactory::open(
20  auxRasterInfo1 );
21  if( inputRasterPointer1 == 0 )
22  {
23  std::cout << "Raster 1 error." << std::endl;
24  return;
25  }
26 
27  std::map<std::string, std::string> auxRasterInfo2;
28  auxRasterInfo2["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_hrc_crop.tif";
29  te::rst::Raster* inputRasterPointer2 = te::rst::RasterFactory::open(
30  auxRasterInfo2 );
31  if( inputRasterPointer2 == 0 )
32  {
33  std::cout << "Raster 2 error." << std::endl;
34  return;
35  }
36 
37  // Creating the algorithm parameters
38 
39  te::rp::IHSFusion::InputParameters algoInputParams;
40 
41  algoInputParams.m_lowResRasterPtr = inputRasterPointer1;
42  algoInputParams.m_lowResRasterRedBandIndex = 0;
43  algoInputParams.m_lowResRasterGreenBandIndex = 1;
44  algoInputParams.m_lowResRasterBlueBandIndex = 2;
45  algoInputParams.m_highResRasterPtr = inputRasterPointer2;
46  algoInputParams.m_highResRasterBand = 0;
47 
48  te::rp::IHSFusion::OutputParameters algoOutputParams;
49 
50  algoOutputParams.m_rInfo["URI"] =
51  TERRALIB_DATA_DIR "/geotiff/IHSFusionExample.tif";
52  algoOutputParams.m_rType = "GDAL";
53 
54  // Executing the algorithm
55 
56  te::rp::IHSFusion algorithmInstance;
57 
58  if( ! algorithmInstance.initialize( algoInputParams ) )
59  {
60  std::cout << "Algorithm initialization error." << std::endl;
61  return;
62  }
63 
64  if( ! algorithmInstance.execute( algoOutputParams ) )
65  {
66  std::cout << "Algorithm execution error." << std::endl;
67  return;
68  }
69  else
70  {
71  std::cout << "Algorithm execution OK." << std::endl;
72  }
73 
74  // clean up
75 
76  delete inputRasterPointer1;
77  delete inputRasterPointer2;
78  }
79  catch(const std::exception& e)
80  {
81  std::cout << std::endl << "An exception has occurred:" << e.what() << std::endl;
82  }
83  catch(...)
84  {
85  std::cout << std::endl << "An unexpected exception has occurred!" << std::endl;
86  }
87 }
88 
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
Definition: IHSFusion.h:114
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: IHSFusion.h:112
Fusion of a low-resolution multi-band image with a high resolution image using the IHS method...
Definition: IHSFusion.h:56
These routines show how to use the RP (raster processing) module.
IHSFusion output parameters.
Definition: IHSFusion.h:108
IHSFusion input parameters.
Definition: IHSFusion.h:64
unsigned int m_lowResRasterRedBandIndex
The low-resolution raster red band index (default:0).
Definition: IHSFusion.h:70
unsigned int m_highResRasterBand
Band to process from the high-resolution raster.
Definition: IHSFusion.h:78
void IHSFusion()
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
An abstract class for raster data strucutures.
This file contains include headers for the TerraLib Raster Processing module.
unsigned int m_lowResRasterBlueBandIndex
The low-resolution raster blue band index (default:2).
Definition: IHSFusion.h:74
te::rst::Raster const * m_highResRasterPtr
Input high-resolution raster.
Definition: IHSFusion.h:76
te::rst::Raster const * m_lowResRasterPtr
Input low-resolution multi-band raster.
Definition: IHSFusion.h:68
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
unsigned int m_lowResRasterGreenBandIndex
The low-resolution raster green band index (default:1).
Definition: IHSFusion.h:72
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.