TsRegister.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/unittest/rp/register/TsRegister.cpp
22 
23  \brief A test suit for Register interface.
24 */
25 
26 // TerraLib
27 #include "../Config.h"
28 #include <terralib/rp.h>
29 #include <terralib/raster.h>
30 #include <terralib/geometry.h>
31 
32 // STL
33 #include <cmath>
34 
35 // Boost
36 #define BOOST_TEST_NO_MAIN
37 #include <boost/test/unit_test.hpp>
38 #include <boost/shared_ptr.hpp>
39 
40 BOOST_AUTO_TEST_SUITE (register_tests)
41 
42 #define ASSERTMAXDIST( pt1, pt2, maxDist ) \
43 { \
44  const double diffx = pt1.x - pt2.x; \
45  const double diffy = pt1.y - pt2.y; \
46  const double error = std::sqrt( ( diffx * diffx ) + ( diffy * diffy ) ); \
47  BOOST_CHECK( error <= maxDist ); \
48 }
49 
50 #define ASSERTMAXDIFF( value1, value2, maxDiff ) \
51 { \
52  BOOST_CHECK( ( std::abs( value1 - value2 ) <= maxDiff ) ); \
53 }
54 
55 BOOST_AUTO_TEST_CASE(register_test)
56 {
57  /* Openning input raster */
58 
59  std::map<std::string, std::string> auxRasterInfo;
60 
61  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
62  boost::shared_ptr< te::rst::Raster > inputRasterPtrPointer ( te::rst::RasterFactory::open(
63  auxRasterInfo ) );
64  BOOST_CHECK( inputRasterPtrPointer.get() );
65 
66  te::gm::LinearRing detailedExtent(te::gm::LineStringType, 0, 0);
68  *inputRasterPtrPointer->getGrid(), detailedExtent ),
69  "Indexed extent creation error" );
70 
71  te::gm::LinearRing indexedDetailedExtent(te::gm::LineStringType, 0, 0);
73  *inputRasterPtrPointer->getGrid(), indexedDetailedExtent ),
74  "Indexed extent creation error" );
75 
76  /* Creating the algorithm parameters */
77 
78  te::rp::Register::InputParameters algoInputParams;
79 
80  algoInputParams.m_inputRasterPtr = inputRasterPtrPointer.get();
81 
82  algoInputParams.m_inputRasterBands.push_back( 0 );
83  algoInputParams.m_inputRasterBands.push_back( 1 );
84  algoInputParams.m_inputRasterBands.push_back( 2 );
85 
87  tiePoint1.first.x = 0;
88  tiePoint1.first.y = 0;
89  inputRasterPtrPointer->getGrid()->gridToGeo( tiePoint1.first.x, tiePoint1.first.y,
90  tiePoint1.second.x, tiePoint1.second.y );
91  algoInputParams.m_tiePoints.push_back( tiePoint1 );
92 
94  tiePoint2.first.x = (double)( inputRasterPtrPointer->getNumberOfColumns() - 1.0 );
95  tiePoint2.first.y = 0;
96  inputRasterPtrPointer->getGrid()->gridToGeo( tiePoint2.first.x, tiePoint2.first.y,
97  tiePoint2.second.x, tiePoint2.second.y );
98  algoInputParams.m_tiePoints.push_back( tiePoint2 );
99 
101  tiePoint3.first.x = (double)( inputRasterPtrPointer->getNumberOfColumns() - 1.0 );
102  tiePoint3.first.y = (double)( inputRasterPtrPointer->getNumberOfRows() - 1.0 );
103  inputRasterPtrPointer->getGrid()->gridToGeo( tiePoint3.first.x, tiePoint3.first.y,
104  tiePoint3.second.x, tiePoint3.second.y );
105  algoInputParams.m_tiePoints.push_back( tiePoint3 );
106 
108  tiePoint4.first.x = 0;
109  tiePoint4.first.y = (double)( inputRasterPtrPointer->getNumberOfRows() - 1.0 );
110  inputRasterPtrPointer->getGrid()->gridToGeo( tiePoint4.first.x, tiePoint4.first.y,
111  tiePoint4.second.x, tiePoint4.second.y );
112  algoInputParams.m_tiePoints.push_back( tiePoint4 );
113 
114  algoInputParams.m_outputSRID = inputRasterPtrPointer->getSRID();
115 
116  algoInputParams.m_outputResolutionX = inputRasterPtrPointer->getResolutionX();
117  algoInputParams.m_outputResolutionY = inputRasterPtrPointer->getResolutionY();
118 
119  algoInputParams.m_interpMethod = te::rst::NearestNeighbor;
120 
121  algoInputParams.m_noDataValue = 0;
122 
123  algoInputParams.m_geomTransfName = "Affine";
124 
125  te::rp::Register::OutputParameters algoOutputParams;
126 
127  algoOutputParams.m_rInfo["URI"] =
128  "terralib_unittest_rp_Register_Test001.tif";
129  algoOutputParams.m_rType = "GDAL";
130 
131  /* Executing the algorithm */
132 
133  te::rp::Register algorithmInstance;
134 
135  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
136  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
137 
138  ASSERTMAXDIFF( inputRasterPtrPointer->getResolutionX(),
139  algoOutputParams.m_outputRasterPtr->getResolutionX(), 0.1 );
140  ASSERTMAXDIFF( inputRasterPtrPointer->getResolutionY(),
141  algoOutputParams.m_outputRasterPtr->getResolutionY(), 0.1 );
142 
143  ASSERTMAXDIST( inputRasterPtrPointer->getGrid()->getExtent()->getLowerLeft(),
144  algoOutputParams.m_outputRasterPtr->getGrid()->getExtent()->getLowerLeft(),
145  0.1 );
146  ASSERTMAXDIST( inputRasterPtrPointer->getGrid()->getExtent()->getUpperRight(),
147  algoOutputParams.m_outputRasterPtr->getGrid()->getExtent()->getUpperRight(),
148  0.1 );
149 }
150 
151 BOOST_AUTO_TEST_SUITE_END()
Register input parameters.
Definition: Register.h:56
Near neighborhood interpolation method.
#define ASSERTMAXDIFF(value1, value2, maxDiff)
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: Register.h:60
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
double m_outputResolutionY
The output raster Y axis resolution (default:1).
Definition: Register.h:70
std::pair< Coord2D, Coord2D > TiePoint
Tie point type definition.
Definition: GTParameters.h:59
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
Tie-points between each raster point (te::gm::GTParameters::TiePoint::first are raster lines/columns ...
Definition: Register.h:64
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
double m_noDataValue
The pixel value used where no raster data is avaliable (defaul:0).
Definition: Register.h:74
std::vector< unsigned int > m_inputRasterBands
Bands to process from the input raster.
Definition: Register.h:62
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
Definition: Register.h:72
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
Definition: Register.h:108
This file contains include headers for the TerraLib Raster Processing module.
bool GetDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &detailedExtent)
Create a datailed extent from the given grid.
Performs raster data registering into a SRS using a set of tie points.
Definition: Register.h:48
int m_outputSRID
The output raster SRID (default:0).
Definition: Register.h:66
double m_outputResolutionX
The output raster X axis resolution (default:1).
Definition: Register.h:68
bool GetIndexedDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &indexedDetailedExtent)
Create a indexed (lines,columns) datailed extent from the given grid.
BOOST_AUTO_TEST_CASE(encoding_test_utf8_latin1)
Register output parameters.
Definition: Register.h:102
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Register.h:106
This file contains include headers for the Vector Geometry model of TerraLib.
BOOST_AUTO_TEST_SUITE(register_tests) BOOST_AUTO_TEST_CASE(register_test)
Definition: TsRegister.cpp:40
std::string m_geomTransfName
The name of the geometric transformation used (see each te::gm::GTFactory inherited classes to find e...
Definition: Register.h:76
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
The generated output registered raster.
Definition: Register.h:110
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.
#define ASSERTMAXDIST(pt1, pt2, maxDist)