1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
#define TEAGN_ENABLE_STDOUT_LOG
#include <TePDIExamplesBase.hpp>
#include <TePDIArithmetic.hpp>
#include <TePDIUtils.hpp>
#include <TeProgress.h>
#include <TeStdIOProgress.h>
#include <TeAgnostic.h>
#include <string>
void TePDIArithmetic_operator_test1( const std::string& operatorToken,
const std::string& tifFileNameToken )
{
TePDITypes::TePDIRasterPtrType inputRasterPointer( new TeRaster(
std::string( TEPDIEXAMPLESRESPATH "cbers2b_rgb342_crop.tif" ), 'r' ) );
TEAGN_TRUE_OR_THROW( inputRasterPointer->init(), "Unable to init inRaster1" );
TePDITypes::TePDIRasterVectorType input_rasters;
input_rasters.push_back( inputRasterPointer );
std::string arithmetic_string(
"( R0:0 " + operatorToken + " R0:1 ) " + operatorToken + " R0:2" );
TEAGN_WATCH( arithmetic_string );
TePDITypes::TePDIRasterPtrType output_raster;
TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( output_raster,
1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
// Creating algorithm parameters
TePDIParameters params;
params.SetParameter( "input_rasters", input_rasters );
params.SetParameter( "arithmetic_string", arithmetic_string );
params.SetParameter( "output_raster", output_raster );
params.SetParameter( "normalize_output", (int)1 );
// Running the algorithm
TePDIArithmetic algoInstance;
TEAGN_TRUE_OR_THROW( algoInstance.Apply( params ), "Apply error" );
TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( output_raster,
TEPDIEXAMPLESBINPATH "TePDIArithmetic_operator_test1_" + tifFileNameToken +
"_.tif" ), "GeoTIF generation error" );
}
void TePDIArithmetic_precedence_test()
{
TePDITypes::TePDIRasterPtrType inputRasterPointer( new TeRaster(
std::string( TEPDIEXAMPLESRESPATH "cbers2b_rgb342_crop.tif" ), 'r' ) );
TEAGN_TRUE_OR_THROW( inputRasterPointer->init(), "Unable to init inRaster1" );
TePDITypes::TePDIRasterVectorType input_rasters;
input_rasters.push_back( inputRasterPointer );
input_rasters.push_back( inputRasterPointer );
input_rasters.push_back( inputRasterPointer );
std::string arithmetic_string( "R0:0 + R0:1 * R0:2" );
TEAGN_WATCH( arithmetic_string );
TePDITypes::TePDIRasterPtrType output_raster;
TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( output_raster,
1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
// Creating algorithm parameters
TePDIParameters params;
params.SetParameter( "input_rasters", input_rasters );
params.SetParameter( "arithmetic_string", arithmetic_string );
params.SetParameter( "output_raster", output_raster );
params.SetParameter( "normalize_output", (int)1 );
// Running the algorithm
TePDIArithmetic algoInstance;
TEAGN_TRUE_OR_THROW( algoInstance.Apply( params ), "Apply error" );
TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( output_raster,
TEPDIEXAMPLESBINPATH "TePDIArithmetic_precedence_test.tif" ),
"GeoTIF generation error" );
}
void TePDIArithmetic_real_number_test( const std::string& operatorToken,
const std::string& tifFileNameToken )
{
TePDITypes::TePDIRasterPtrType inputRasterPointer( new TeRaster(
std::string( TEPDIEXAMPLESRESPATH "cbers2b_rgb342_crop.tif" ), 'r' ) );
TEAGN_TRUE_OR_THROW( inputRasterPointer->init(), "Unable to init inRaster1" );
TePDITypes::TePDIRasterVectorType input_rasters;
input_rasters.push_back( inputRasterPointer );
input_rasters.push_back( inputRasterPointer );
input_rasters.push_back( inputRasterPointer );
std::string arithmetic_string( "( R0:0 " + operatorToken + " 1.0 ) " +
operatorToken + " ( 1.0 " + operatorToken + " R0:1 )" );
TEAGN_WATCH( arithmetic_string );
TePDITypes::TePDIRasterPtrType output_raster;
TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( output_raster,
1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
// Creating algorithm parameters
TePDIParameters params;
params.SetParameter( "input_rasters", input_rasters );
params.SetParameter( "arithmetic_string", arithmetic_string );
params.SetParameter( "output_raster", output_raster );
params.SetParameter( "normalize_output", (int)1 );
// Running the algorithm
TePDIArithmetic algoInstance;
TEAGN_TRUE_OR_THROW( algoInstance.Apply( params ), "Apply error" );
TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( output_raster,
TEPDIEXAMPLESBINPATH "TePDIArithmetic_real_number_test_" + tifFileNameToken +
"_.tif" ), "GeoTIF generation error" );
}
int main()
{
TEAGN_LOGMSG( "Test started." );
TeStdIOProgress pi;
TeProgress::setProgressInterf( dynamic_cast< TeProgressBase* >( &pi ) );
TePDIArithmetic_operator_test1( "+", "plus" );
TePDIArithmetic_operator_test1( "-", "minus" );
TePDIArithmetic_operator_test1( "*", "multi" );
TePDIArithmetic_operator_test1( "/", "division" );
TePDIArithmetic_precedence_test();
TePDIArithmetic_real_number_test( "+", "plus" );
TePDIArithmetic_real_number_test( "-", "minus" );
TePDIArithmetic_real_number_test( "*", "multi" );
TePDIArithmetic_real_number_test( "/", "division" );
TEAGN_LOGMSG( "Test OK." );
return EXIT_SUCCESS;
}
|