00001 #define TEAGN_ENABLE_STDOUT_LOG
00002
00003 #include <TePDIExamplesBase.hpp>
00004
00005 #include <TePDIBDFilter.hpp>
00006 #include <TePDIParameters.hpp>
00007 #include <TeAgnostic.h>
00008 #include <TePDIUtils.hpp>
00009
00010 #include <TeInitRasterDecoders.h>
00011
00012 #include <TeProgress.h>
00013 #include <TeStdIOProgress.h>
00014
00015
00016 void Sobel_test()
00017 {
00018 TePDIParameters params;
00019
00020 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00021 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00022 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00023 params.SetParameter( "input_image", inRaster );
00024
00025 TePDITypes::TePDIRasterPtrType outRaster;
00026 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00027 1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00028 params.SetParameter( "output_image", outRaster );
00029
00030 std::vector<int> channels;
00031 channels.push_back( 0 );
00032 channels.push_back( 1 );
00033 channels.push_back( 2 );
00034 params.SetParameter( "channels", channels );
00035
00036 params.SetParameter( "filter_type", TePDIBDFilter::TePDISobel );
00037
00038 params.SetParameter( "iterations", (int)2 );
00039
00040 TePDIBDFilter filter;
00041
00042 TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00043 "Invalid Parameters" );
00044
00045 TEAGN_TRUE_OR_THROW( filter.Apply(),
00046 "Apply error" );
00047
00048 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00049 TEPDIEXAMPLESBINPATH "Sobel_test.tif" ), "GeoTIF generation error" );
00050 }
00051
00052
00053 void Roberts_test()
00054 {
00055 TePDIParameters params;
00056
00057 TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00058 std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00059 TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00060 params.SetParameter( "input_image", inRaster );
00061
00062 TePDITypes::TePDIRasterPtrType outRaster;
00063 TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00064 1, 1, 1, false, TeDOUBLE, 0 ), "RAM Raster Alloc error" );
00065 params.SetParameter( "output_image", outRaster );
00066
00067 std::vector<int> channels;
00068 channels.push_back( 0 );
00069 channels.push_back( 1 );
00070 channels.push_back( 2 );
00071 params.SetParameter( "channels", channels );
00072
00073 params.SetParameter( "filter_type", TePDIBDFilter::TePDIRoberts );
00074
00075 params.SetParameter( "iterations", (int)1 );
00076
00077 TePDIBDFilter filter;
00078
00079 TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00080 "Invalid Parameters" );
00081
00082 TEAGN_TRUE_OR_THROW( filter.Apply(),
00083 "Apply error" );
00084
00085 TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00086 TEPDIEXAMPLESBINPATH "Roberts_test.tif" ), "GeoTIF generation error" );
00087 }
00088
00089
00090 int main()
00091 {
00092 TEAGN_LOGMSG( "Test started." );
00093
00094 try{
00095 TeStdIOProgress pi;
00096 TeProgress::setProgressInterf( dynamic_cast< TeProgressBase* >( &pi ) );
00097
00098 TeInitRasterDecoders();
00099
00100 Sobel_test();
00101 Roberts_test();
00102 }
00103 catch( const TeException& excpt ){
00104 TEAGN_LOGERR( excpt.message() )
00105 return EXIT_FAILURE;
00106 }
00107
00108 TEAGN_LOGMSG( "Test OK." );
00109 return EXIT_SUCCESS;
00110 }