TePDILinearFilter_test.cpp

Shows how to use this class.

00001 #define TEAGN_ENABLE_STDOUT_LOG
00002 
00003 #include <TePDIExamplesBase.hpp>
00004 
00005 #include <TePDILinearFilter.hpp>
00006 #include <TePDIFilterMask.hpp>
00007 #include <TePDIParameters.hpp>
00008 #include <TeAgnostic.h>
00009 #include <TePDIUtils.hpp>
00010 
00011 #include <TeInitRasterDecoders.h>
00012 #include <TeProgress.h>
00013 #include <TeStdIOProgress.h>
00014 
00015 void DummyMask_RGB_test()
00016 {
00017   TePDIParameters params;
00018 
00019   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00020     std::string( TEPDIEXAMPLESRESPATH "cbers_rgb342_crop1.tif" ), 'r' ) );
00021   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00022   params.SetParameter( "input_image", inRaster );
00023   
00024   TePDITypes::TePDIRasterPtrType outRaster;
00025   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00026     1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00027   params.SetParameter( "output_image", outRaster );  
00028   
00029   std::vector<int> channels;
00030   channels.push_back( 0 );
00031   channels.push_back( 1 );
00032   channels.push_back( 2 );
00033   params.SetParameter( "channels", channels );
00034 
00035   params.SetParameter( "filter_mask", TePDIFilterMask::create_Dummy() );
00036 
00037   params.SetParameter( "iterations", (int)1 );
00038 
00039   TePDILinearFilter filter;  
00040 
00041   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00042     "Invalid Parameters" );
00043 
00044   TEAGN_TRUE_OR_THROW( filter.Apply(),
00045     "Apply error" );
00046   
00047   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00048     TEPDIEXAMPLESBINPATH "TePDILinearFilter_DummyMask_RGB.tif" ), 
00049     "GeoTIF generation error" );  
00050     
00051 }
00052 
00053 
00054 void Avg3x3_test()
00055 {
00056   TePDIParameters params;
00057 
00058   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00059     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00060   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00061   params.SetParameter( "input_image", inRaster );
00062 
00063   TePDITypes::TePDIRasterPtrType outRaster;
00064   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00065     1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00066   params.SetParameter( "output_image", outRaster );
00067 
00068   std::vector<int> channels;
00069   channels.push_back( 0 );
00070   params.SetParameter( "channels", channels );
00071 
00072   params.SetParameter( "filter_mask", TePDIFilterMask::create_Avg3x3() );
00073 
00074   params.SetParameter( "iterations", (int)3 );
00075 
00076   TePDILinearFilter filter;  
00077 
00078   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00079     "Invalid Parameters" );
00080 
00081   TEAGN_TRUE_OR_THROW( filter.Apply(),
00082     "Apply error" );
00083 
00084   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00085     TEPDIEXAMPLESBINPATH "TePDILinearFilter_Avg3x3_test.tif" ), "GeoTIF generation error" );
00086 }
00087 
00088 
00089 void Avg7x7_test()
00090 {
00091   TePDIParameters params;
00092 
00093   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00094     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00095   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00096   params.SetParameter( "input_image", inRaster );
00097 
00098   TePDITypes::TePDIRasterPtrType outRaster;
00099   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00100     1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00101   params.SetParameter( "output_image", outRaster );
00102 
00103   std::vector<int> channels;
00104   channels.push_back( 0 );
00105   params.SetParameter( "channels", channels );
00106 
00107   params.SetParameter( "filter_mask", TePDIFilterMask::create_Avg7x7() );
00108 
00109   params.SetParameter( "iterations", (int)2 );
00110 
00111   TePDILinearFilter filter;
00112 
00113   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00114     "Invalid Parameters" );
00115 
00116   TEAGN_TRUE_OR_THROW( filter.Apply(),
00117     "Apply error" );
00118 
00119   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00120     TEPDIEXAMPLESBINPATH "TePDILinearFilter_Avg7x7_test.tif" ), "GeoTIF generation error" );
00121 }
00122 
00123 
00124 void NDHigh_test()
00125 {
00126   TePDIParameters params;
00127 
00128   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00129     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00130   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00131   params.SetParameter( "input_image", inRaster );
00132 
00133   TePDITypes::TePDIRasterPtrType outRaster;
00134   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00135     1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00136   params.SetParameter( "output_image", outRaster );
00137 
00138   std::vector<int> channels;
00139   channels.push_back( 0 );
00140   params.SetParameter( "channels", channels );
00141 
00142   params.SetParameter( "filter_mask", TePDIFilterMask::create_NDHigh() );
00143 
00144   params.SetParameter( "iterations", (int)1 );
00145 
00146   params.SetParameter( "level_offset", (double)20 );
00147 
00148   TePDILinearFilter filter;
00149 
00150   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00151     "Invalid Parameters" );
00152 
00153   TEAGN_TRUE_OR_THROW( filter.Apply(),
00154     "Apply error" );
00155 
00156   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00157     TEPDIEXAMPLESBINPATH "TePDILinearFilter_NDHigh_test.tif" ), "GeoTIF generation error" );
00158 }
00159 
00160 
00161 void S_test()
00162 {
00163   TePDIParameters params;
00164 
00165   TePDITypes::TePDIRasterPtrType inRaster( new TeRaster(
00166     std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
00167   TEAGN_TRUE_OR_THROW( inRaster->init(), "Unable to init inRaster" );
00168   params.SetParameter( "input_image", inRaster );
00169 
00170   TePDITypes::TePDIRasterPtrType outRaster;
00171   TEAGN_TRUE_OR_THROW( TePDIUtils::TeAllocRAMRaster( outRaster,
00172     1, 1, 1, false, TeUNSIGNEDCHAR, 0 ), "RAM Raster Alloc error" );
00173   params.SetParameter( "output_image", outRaster );
00174 
00175   std::vector<int> channels;
00176   channels.push_back( 0 );
00177   params.SetParameter( "channels", channels );
00178 
00179   params.SetParameter( "filter_mask", TePDIFilterMask::create_S() );
00180 
00181   params.SetParameter( "iterations", (int)1 );
00182 
00183   TePDILinearFilter filter;
00184 
00185   TEAGN_TRUE_OR_THROW( filter.Reset( params ),
00186     "Invalid Parameters" );
00187 
00188   TEAGN_TRUE_OR_THROW( filter.Apply(),
00189     "Apply error" );
00190 
00191   TEAGN_TRUE_OR_THROW( TePDIUtils::TeRaster2Geotiff( outRaster,
00192     TEPDIEXAMPLESBINPATH "TePDILinearFilter_S_test.tif" ), "GeoTIF generation error" );
00193 }
00194 
00195 
00196 
00197 int main()
00198 {
00199   TEAGN_LOGMSG( "Test started." );
00200 
00201   try{
00202     TeInitRasterDecoders();
00203     
00204     TeStdIOProgress pi;
00205     TeProgress::setProgressInterf( dynamic_cast< TeProgressBase* >( &pi ) );     
00206 
00207     DummyMask_RGB_test();
00208     Avg3x3_test();
00209     Avg7x7_test();
00210     NDHigh_test();
00211     S_test();
00212   }
00213   catch( const TeException& excpt ){
00214     TEAGN_LOGERR( excpt.message() )
00215     return EXIT_FAILURE;
00216   }
00217 
00218   TEAGN_LOGMSG( "Test OK." );
00219   return EXIT_SUCCESS;
00220 }

Generated on Sun Jul 29 04:01:03 2012 for TerraLib - Development Source by  doxygen 1.5.3