30 #include "../dataaccess/dataset/DataSetType.h"
31 #include "../dataaccess/datasource/DataSourceFactory.h"
32 #include "../dataaccess/utils/Utils.h"
33 #include "../datatype/Enums.h"
34 #include "../raster/BandProperty.h"
35 #include "../raster/Grid.h"
36 #include "../raster/RasterFactory.h"
37 #include "../raster/RasterProperty.h"
38 #include "../raster/RasterIterator.h"
39 #include "../raster/Utils.h"
40 #include "../geometry/Point.h"
41 #include "../common/MatrixUtils.h"
47 #include <boost/filesystem.hpp>
48 #include <boost/numeric/ublas/io.hpp>
49 #include <boost/numeric/ublas/matrix.hpp>
50 #include <boost/shared_ptr.hpp>
51 #include <boost/shared_array.hpp>
52 #include <boost/lexical_cast.hpp>
53 #include <boost/thread.hpp>
54 #include <boost/numeric/ublas/lu.hpp>
55 #include <boost/numeric/ublas/matrix.hpp>
66 #define M_PI 3.14159265358979323846
120 const std::vector< te::rst::BandProperty* >& bandsProperties,
121 const std::string& outDataSetName,
122 const std::string& dataSourceType,
127 std::auto_ptr< te::da::DataSource > dataSourcePtr(
129 if( dataSourcePtr.get() == 0 )
return false;
134 outDataSetName, *dataSourcePtr, internalRasterHandler ) )
136 std::auto_ptr< te::da::DataSource > dummyDataSourcePtr;
137 std::auto_ptr< te::da::DataSourceTransactor > transactorPtr;
138 std::auto_ptr< te::da::DataSet > dataSetPtr;
139 std::auto_ptr< te::rst::Raster > rasterPtr;
141 internalRasterHandler.
release( dummyDataSourcePtr, transactorPtr,
142 dataSetPtr, rasterPtr );
144 outRasterHandler.
reset( dataSourcePtr.release(), transactorPtr.release(),
145 dataSetPtr.release(), rasterPtr.release() );
156 const std::vector< te::rst::BandProperty* >& bandsProperties,
157 const std::string& outDataSetName,
163 std::auto_ptr< te::rst::RasterProperty > rasterPropertyPtr(
165 bandsProperties, std::map< std::string, std::string >(),
170 std::auto_ptr< te::da::DataSourceTransactor > transactorPtr(
173 if( transactorPtr.get() == 0 )
180 if( transactorPtr->dataSetExists( outDataSetName ) )
182 transactorPtr->dropDataSet( outDataSetName );
185 std::auto_ptr< te::da::DataSetType > dataSetTypePtr(
187 dataSetTypePtr->add( rasterPropertyPtr.release() );
191 transactorPtr->createDataSet( dataSetTypePtr.get(),
192 std::map< std::string, std::string >() );
199 if( ! transactorPtr->dataSetExists( outDataSetName ) )
return false;
201 std::auto_ptr< te::da::DataSet > dataSetPtr( transactorPtr->getDataSet(
204 if( dataSetPtr.get() == 0 )
211 std::auto_ptr< te::rst::Raster > rasterPtr( dataSetPtr->getRaster( 0 ) );
213 if( rasterPtr.get() )
215 outRasterHandler.
reset( transactorPtr.release(), dataSetPtr.release(), rasterPtr.release() );
225 std::vector< te::rst::BandProperty* > bandsProperties,
228 std::string dataSetName = std::string(
"createNewMemRaster" ) +
229 boost::lexical_cast< std::string >( &outRasterHandler );
232 "MEM", outRasterHandler );
236 std::vector< te::rst::BandProperty* > bandsProperties,
237 const std::string& fileName,
240 std::auto_ptr< te::rst::Raster > outRasterPtr;
243 outRasterHandler.
reset( outRasterPtr.release() );
248 outRasterHandler.
reset();
254 std::vector< te::rst::BandProperty* > bandsProperties,
255 const std::string& fileName,
256 std::auto_ptr< te::rst::Raster >& outRasterPtr )
258 outRasterPtr.reset();
260 std::map< std::string, std::string > rInfo;
261 rInfo[
"URI" ] = fileName;
271 if( outRasterPtr.get() )
282 const std::string& fileName )
292 unsigned int bandIdx =0;
293 unsigned int col = 0;
294 unsigned int row = 0;
296 std::vector< te::rst::BandProperty* > bandsProperties;
297 for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
306 fileName, outRasterHandler ) )
313 for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
318 for( row = 0 ; row < nRows ; ++row )
320 for( col = 0 ; col < nCols ; ++col )
323 outBand.
setValue( col, row, value );
332 unsigned int inputVectorSize,
double* outputVector )
334 switch( inputVectorDataType )
338 char* vPtr = (
char*)inputVector;
339 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
340 outputVector[ idx ] = (
double)vPtr[ idx ];
346 unsigned char* vPtr = (
unsigned char*)inputVector;
347 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
348 outputVector[ idx ] = (
double)vPtr[ idx ];
353 short int* vPtr = (
short int*)inputVector;
354 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
355 outputVector[ idx ] = (
double)vPtr[ idx ];
360 std::complex< short int >* vPtr = (std::complex< short int >*)
362 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
363 outputVector[ idx ] = (
double)vPtr[ idx ].real();
368 unsigned short int* vPtr = (
unsigned short int*)inputVector;
369 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
370 outputVector[ idx ] = (
double)vPtr[ idx ];
375 int* vPtr = (
int*)inputVector;
376 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
377 outputVector[ idx ] = (
double)vPtr[ idx ];
382 std::complex< int >* vPtr = (std::complex< int >*)
384 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
385 outputVector[ idx ] = (
double)vPtr[ idx ].real();
390 unsigned int* vPtr = (
unsigned int*)inputVector;
391 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
392 outputVector[ idx ] = (
double)vPtr[ idx ];
397 long int* vPtr = (
long int*)inputVector;
398 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
399 outputVector[ idx ] = (
double)vPtr[ idx ];
404 unsigned long int* vPtr = (
unsigned long int*)inputVector;
405 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
406 outputVector[ idx ] = (
double)vPtr[ idx ];
411 float* vPtr = (
float*)inputVector;
412 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
413 outputVector[ idx ] = (
double)vPtr[ idx ];
418 std::complex< float >* vPtr = (std::complex< float >*)
420 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
421 outputVector[ idx ] = (
double)vPtr[ idx ].real();
426 memcpy( outputVector, inputVector, inputVectorSize *
sizeof(
double ) );
431 std::complex< double >* vPtr = (std::complex< double >*)
433 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
434 outputVector[ idx ] = (
double)vPtr[ idx ].real();
438 throw te::rp::Exception(
"Invalid data type" );
444 unsigned int inputVectorSize,
const int outputVectorDataType,
447 switch( outputVectorDataType )
451 char* vPtr = (
char*)outputVector;
452 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
453 vPtr[ idx ] = (
char)inputVector[ idx ];
459 unsigned char* vPtr = (
unsigned char*)outputVector;
460 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
461 vPtr[ idx ] = (
unsigned char)inputVector[ idx ];
466 short int* vPtr = (
short int*)outputVector;
467 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
468 vPtr[ idx ] = (
short int)inputVector[ idx ];
473 std::complex< short int >* vPtr = (std::complex< short int >*)
475 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
476 vPtr[ idx ]= ( (
short int)inputVector[ idx ] );
481 unsigned short int* vPtr = (
unsigned short int*)outputVector;
482 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
483 vPtr[ idx ] = (
unsigned short int)inputVector[ idx ];
488 int* vPtr = (
int*)outputVector;
489 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
490 vPtr[ idx ] = (
int)inputVector[ idx ];
495 std::complex< int >* vPtr = (std::complex< int >*)
497 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
498 vPtr[ idx ] = ( (
int)inputVector[ idx ] );
503 unsigned int* vPtr = (
unsigned int*)outputVector;
504 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
505 vPtr[ idx ] = (
unsigned int)inputVector[ idx ];
510 long int* vPtr = (
long int*)outputVector;
511 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
512 vPtr[ idx ] = (
long int)inputVector[ idx ];
517 unsigned long int* vPtr = (
unsigned long int*)outputVector;
518 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
519 vPtr[ idx ] = (
unsigned long int)inputVector[ idx ];
524 float* vPtr = (
float*)outputVector;
525 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
526 vPtr[ idx ] = (
float)inputVector[ idx ];
531 std::complex< float >* vPtr = (std::complex< float >*)
533 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
534 vPtr[ idx ] = ( (
float)inputVector[ idx ] );
539 memcpy( outputVector, inputVector, inputVectorSize *
sizeof(
double ) );
544 std::complex< double >* vPtr = (std::complex< double >*)
546 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
547 vPtr[ idx ] = ( (
double)inputVector[ idx ] );
551 throw te::rp::Exception(
"Invalid data type" );
558 static std::vector<std::string> bandNames;
560 bandNames.push_back(
"CBERS2_CCD_1_BLUE");
561 bandNames.push_back(
"CBERS2_CCD_2_GREEN");
562 bandNames.push_back(
"CBERS2_CCD_3_RED");
563 bandNames.push_back(
"CBERS2_CCD_4_NIR");
564 bandNames.push_back(
"CBERS2_CCD_5_PAN");
566 bandNames.push_back(
"LANDSAT5_TM_1_BLUE");
567 bandNames.push_back(
"LANDSAT5_TM_2_GREEN");
568 bandNames.push_back(
"LANDSAT5_TM_3_RED");
569 bandNames.push_back(
"LANDSAT5_TM_4_NIR");
570 bandNames.push_back(
"LANDSAT5_TM_5_SWIR");
571 bandNames.push_back(
"LANDSAT5_TM_6_THERMAL");
572 bandNames.push_back(
"LANDSAT5_TM_7_MIR");
574 bandNames.push_back(
"LANDSAT7_ETM+_1_BLUE");
575 bandNames.push_back(
"LANDSAT7_ETM+_2_GREEN");
576 bandNames.push_back(
"LANDSAT7_ETM+_3_RED");
577 bandNames.push_back(
"LANDSAT7_ETM+_4_NIR");
578 bandNames.push_back(
"LANDSAT7_ETM+_5_SWIR");
579 bandNames.push_back(
"LANDSAT7_ETM+_6_THERMAL");
580 bandNames.push_back(
"LANDSAT7_ETM+_7_MIR");
581 bandNames.push_back(
"LANDSAT7_ETM+_8_PAN");
583 bandNames.push_back(
"WV2_MUL_1_COASTAL");
584 bandNames.push_back(
"WV2_MUL_2_BLUE");
585 bandNames.push_back(
"WV2_MUL_3_GREEN");
586 bandNames.push_back(
"WV2_MUL_4_YELLOW");
587 bandNames.push_back(
"WV2_MUL_5_RED");
588 bandNames.push_back(
"WV2_MUL_6_REDEDGE");
589 bandNames.push_back(
"WV2_MUL_7_NIR1");
590 bandNames.push_back(
"WV2_MUL_8_NIR2");
591 bandNames.push_back(
"WV2_PAN");
598 static std::map<std::string, std::pair<double, double> > BandInfo;
600 BandInfo[
"CBERS2_CCD_1_BLUE"] = std::pair<double, double> (0.45, 0.52);
601 BandInfo[
"CBERS2_CCD_2_GREEN"] = std::pair<double, double> (0.52, 0.59);
602 BandInfo[
"CBERS2_CCD_3_RED"] = std::pair<double, double> (0.63, 0.69);
603 BandInfo[
"CBERS2_CCD_4_NIR"] = std::pair<double, double> (0.77, 0.89);
604 BandInfo[
"CBERS2_CCD_5_PAN"] = std::pair<double, double> (0.51, 0.73);
606 BandInfo[
"LANDSAT5_TM_1_BLUE"] = std::pair<double, double> (0.45, 0.52);
607 BandInfo[
"LANDSAT5_TM_2_GREEN"] = std::pair<double, double> (0.52, 0.60);
608 BandInfo[
"LANDSAT5_TM_3_RED"] = std::pair<double, double> (0.63, 0.69);
609 BandInfo[
"LANDSAT5_TM_4_NIR"] = std::pair<double, double> (0.76, 0.90);
610 BandInfo[
"LANDSAT5_TM_5_SWIR"] = std::pair<double, double> (1.55, 1.75);
611 BandInfo[
"LANDSAT5_TM_6_THERMAL"] = std::pair<double, double> (10.40, 12.50);
612 BandInfo[
"LANDSAT5_TM_7_MIR"] = std::pair<double, double> (2.08, 2.35);
614 BandInfo[
"LANDSAT7_ETM+_1_BLUE"] = std::pair<double, double> (0.45, 0.515);
615 BandInfo[
"LANDSAT7_ETM+_2_GREEN"] = std::pair<double, double> (0.525, 0.605);
616 BandInfo[
"LANDSAT7_ETM+_3_RED"] = std::pair<double, double> (0.63, 0.69);
617 BandInfo[
"LANDSAT7_ETM+_4_NIR"] = std::pair<double, double> (0.75, 0.90);
618 BandInfo[
"LANDSAT7_ETM+_5_SWIR"] = std::pair<double, double> (1.55, 1.75);
619 BandInfo[
"LANDSAT7_ETM+_6_THERMAL"] = std::pair<double, double> (10.40, 12.5);
620 BandInfo[
"LANDSAT7_ETM+_7_MIR"] = std::pair<double, double> (2.09, 2.35);
621 BandInfo[
"LANDSAT7_ETM+_8_PAN"] = std::pair<double, double> (0.52, 0.90);
623 BandInfo[
"WV2_MUL_1_COASTAL"] = std::pair<double, double> (0.4, 0.45);
624 BandInfo[
"WV2_MUL_2_BLUE"] = std::pair<double, double> (0.45, 0.51);
625 BandInfo[
"WV2_MUL_3_GREEN"] = std::pair<double, double> (0.51, 0.58);
626 BandInfo[
"WV2_MUL_4_YELLOW"] = std::pair<double, double> (0.585, 0.625);
627 BandInfo[
"WV2_MUL_5_RED"] = std::pair<double, double> (0.66, 0.69);
628 BandInfo[
"WV2_MUL_6_REDEDGE"] = std::pair<double, double> (0.705, 0.745);
629 BandInfo[
"WV2_MUL_7_NIR1"] = std::pair<double, double> (0.77, 0.895);
630 BandInfo[
"WV2_MUL_8_NIR2"] = std::pair<double, double> (0.86, 0.104);
631 BandInfo[
"WV2_PAN"] = std::pair<double, double> (0.45, 0.8);
635 if (BandInfo.find(bandName) == BandInfo.end())
636 return std::pair<double, double> (0.0, 1.0);
638 return BandInfo[bandName];
653 static std::map<std::string, std::pair<double, double> > DNBandInfo;
655 DNBandInfo[
"CBERS2_CCD_1_BLUE"] = std::pair<double, double> (0.0, 255.0);
656 DNBandInfo[
"CBERS2_CCD_2_GREEN"] = std::pair<double, double> (0.0, 255.0);
657 DNBandInfo[
"CBERS2_CCD_3_RED"] = std::pair<double, double> (0.0, 255.0);
658 DNBandInfo[
"CBERS2_CCD_4_NIR"] = std::pair<double, double> (0.0, 255.0);
659 DNBandInfo[
"CBERS2_CCD_5_PAN"] = std::pair<double, double> (0.0, 255.0);
661 DNBandInfo[
"LANDSAT5_TM_1_BLUE"] = std::pair<double, double> (0.0, 255.0);
662 DNBandInfo[
"LANDSAT5_TM_2_GREEN"] = std::pair<double, double> (0.0, 255.0);
663 DNBandInfo[
"LANDSAT5_TM_3_RED"] = std::pair<double, double> (0.0, 255.0);
664 DNBandInfo[
"LANDSAT5_TM_4_NIR"] = std::pair<double, double> (0.0, 255.0);
665 DNBandInfo[
"LANDSAT5_TM_5_SWIR"] = std::pair<double, double> (0.0, 255.0);
666 DNBandInfo[
"LANDSAT5_TM_6_THERMAL"] = std::pair<double, double> (0.0, 255.0);
667 DNBandInfo[
"LANDSAT5_TM_7_MIR"] = std::pair<double, double> (0.0, 255.0);
669 DNBandInfo[
"LANDSAT7_ETM+_1_BLUE"] = std::pair<double, double> (0.0, 255.0);
670 DNBandInfo[
"LANDSAT7_ETM+_2_GREEN"] = std::pair<double, double> (0.0, 255.0);
671 DNBandInfo[
"LANDSAT7_ETM+_3_RED"] = std::pair<double, double> (0.0, 255.0);
672 DNBandInfo[
"LANDSAT7_ETM+_4_NIR"] = std::pair<double, double> (0.0, 255.0);
673 DNBandInfo[
"LANDSAT7_ETM+_5_SWIR"] = std::pair<double, double> (0.0, 255.0);
674 DNBandInfo[
"LANDSAT7_ETM+_6_THERMAL"] = std::pair<double, double> (0.0, 255.0);
675 DNBandInfo[
"LANDSAT7_ETM+_7_MIR"] = std::pair<double, double> (0.0, 255.0);
676 DNBandInfo[
"LANDSAT7_ETM+_8_PAN"] = std::pair<double, double> (0.0, 255.0);
678 DNBandInfo[
"WV2_MUL_1_COASTAL"] = std::pair<double, double> (0.0, 2048.0);
679 DNBandInfo[
"WV2_MUL_2_BLUE"] = std::pair<double, double> (0.0, 2048.0);
680 DNBandInfo[
"WV2_MUL_3_GREEN"] = std::pair<double, double> (0.0, 2048.0);
681 DNBandInfo[
"WV2_MUL_4_YELLOW"] = std::pair<double, double> (0.0, 2048.0);
682 DNBandInfo[
"WV2_MUL_5_RED"] = std::pair<double, double> (0.0, 2048.0);
683 DNBandInfo[
"WV2_MUL_6_REDEDGE"] = std::pair<double, double> (0.0, 2048.0);
684 DNBandInfo[
"WV2_MUL_7_NIR1"] = std::pair<double, double> (0.0, 2048.0);
685 DNBandInfo[
"WV2_MUL_7_NIR2"] = std::pair<double, double> (0.0, 2048.0);
686 DNBandInfo[
"WV2_PAN"] = std::pair<double, double> (0.0, 2048.0);
690 if (DNBandInfo.find(bandName) == DNBandInfo.end())
691 return std::pair<double, double> (0.0, 255.0);
693 return DNBandInfo[bandName];
707 std::vector<double> omins;
708 std::vector<double> omaxs;
709 std::vector<unsigned int> bands;
721 const double namplitude = nmax - nmin;
722 std::vector<double> oamplitude;
724 oamplitude.push_back(omaxs[b] - omins[b]);
734 value = ((*it)[b] - omins[b]) * namplitude / oamplitude[b] + nmin;
746 const unsigned int redBandIdx,
const unsigned int greenBandIdx,
747 const unsigned int blueBandIdx,
const double rgbRangeMin,
771 const double blueNoData = inputRGBRaster.
getBand(
774 unsigned int outRow = 0;
775 unsigned int outCol = 0;
780 double redNorm = 0, greenNorm = 0, blueNorm = 0;
781 double rMinusG = 0, rMinusB = 0;
784 const double twoPi = 2.0 * ((double)
M_PI);
785 const double pi2 = ((double)
M_PI) / 2.0;
786 const double rgbNormFac = ( rgbRangeMax == rgbRangeMin ) ? 0.0 :
787 ( 1.0 / ( rgbRangeMax - rgbRangeMin ) );
788 double intensity = 0;
790 double saturation = 0;
792 for( outRow = 0 ; outRow < outNRows ; ++outRow )
794 for( outCol = 0 ; outCol < outNCols ; ++outCol )
796 redBand.
getValue( outCol, outRow, red );
797 greenBand.
getValue( outCol, outRow, green );
798 blueBand.
getValue( outCol, outRow, blue );
800 if( ( red == redNoData ) || ( green == greenNoData ) ||
801 ( blue == blueNoData ) )
809 if( ( red == green ) && ( green == blue ) )
819 intensity = ( red * rgbNormFac );
823 redNorm = ( red - rgbRangeMin ) * rgbNormFac;
824 greenNorm = ( green - rgbRangeMin ) * rgbNormFac;
825 blueNorm = ( blue - rgbRangeMin ) * rgbNormFac;
827 rMinusG = redNorm - greenNorm;
828 rMinusB = redNorm - blueNorm;
830 cosValue = std::sqrt( ( rMinusG * rMinusG ) + ( rMinusB *
831 ( greenNorm - blueNorm ) ) );
833 if( cosValue == 0.0 )
839 cosValue = ( 0.5 * ( rMinusG + rMinusB ) ) /
841 teta = std::acos( cosValue );
844 assert( ( cosValue >= (-1.0) ) && ( cosValue <= (1.0) ) );
846 if( blueNorm > greenNorm )
848 hue = ( twoPi - teta );
855 rgbSum = ( redNorm + greenNorm + blueNorm );
857 saturation = ( 1.0 - ( 3 * std::min( std::min( redNorm, greenNorm ), blueNorm ) /
860 intensity = ( rgbSum / 3.0 );
864 outputIHSRaster.
setValue( outCol, outRow, intensity, 0 );
865 outputIHSRaster.
setValue( outCol, outRow, hue, 1 );
866 outputIHSRaster.
setValue( outCol, outRow, saturation, 2 );
874 const unsigned int intensityBandIdx,
const unsigned int hueBandIdx,
875 const unsigned int saturationBandIdx,
const double rgbRangeMin,
893 const double intensityNoData = inputIHSRaster.
getBand(
895 const double hueNoData = inputIHSRaster.
getBand(
897 const double saturationNoData = inputIHSRaster.
getBand(
900 const double rgbNormFac = ( rgbRangeMax == rgbRangeMin ) ? 0.0 :
901 ( rgbRangeMax - rgbRangeMin );
902 const double pi3 =
M_PI / 3.0;
903 const double twoPi3 = 2.0 *
M_PI / 3.0;
904 const double fourPi3 = 4.0 *
M_PI / 3.0;
905 unsigned int row = 0;
906 unsigned int col = 0;
920 for( row = 0 ; row < nRows ; ++row )
922 for( col = 0 ; col < nCols ; ++col )
924 intensityBand.
getValue( col, row, lig );
926 saturationBand.
getValue( col, row, sat );
928 if( ( lig == intensityNoData ) || ( hue == hueNoData ) ||
929 ( sat == saturationNoData ) )
931 red = green = blue = 0;
935 if( ( hue == 0.0 ) && ( sat == 0.0 ) )
937 red = green = blue = ( lig * rgbNormFac );
944 blue = lig * ( 1.0 - sat );
945 red = lig * ( 1.0 + ( sat * std::cos( hue ) /
946 std::cos( pi3 - hue ) ) );
947 green = ( 3.0 * lig ) - ( red + blue );
949 else if( hue < fourPi3 )
954 red = lig * ( 1.0 - sat );
955 green = lig * ( 1.0 + ( sat * std::cos( hue ) /
956 std::cos( pi3 - hue ) ) );
957 blue = ( 3.0 * lig ) - ( red + green );
964 green = lig * ( 1.0 - sat );
965 blue = lig * ( 1.0 + ( sat * std::cos( hue ) /
966 std::cos( pi3 - hue ) ) );
967 red = ( 3.0 * lig ) - ( green + blue );
970 red = ( red * rgbNormFac ) + rgbRangeMin;
971 green = ( green * rgbNormFac ) + rgbRangeMin;
972 blue = ( blue * rgbNormFac ) + rgbRangeMin;
976 red =
MIN( red, rgbRangeMax );
977 green =
MIN( green, rgbRangeMax );
978 blue =
MIN( blue, rgbRangeMax );
980 red =
MAX( red, rgbRangeMin );
981 green =
MAX( green, rgbRangeMin );
982 blue =
MAX( blue, rgbRangeMin );
985 greenBand.
setValue( col, row, green );
986 blueBand.
setValue( col, row, blue );
1003 boost::scoped_array< unsigned char > blockBuffer(
new unsigned char[ blockSizeBytes ] );
1004 boost::scoped_array< double > doubleBuffer(
new double[ blockElementsNumber ] );
1006 unsigned int elementIdx = 0;
1008 double meanElementsNumber = 0;
1031 doubleBuffer.get() );
1033 for( elementIdx = 0 ; elementIdx < blockElementsNumber ; ++elementIdx )
1035 if( noDataValue != doubleBuffer[ elementIdx ] )
1045 doubleBuffer[ elementIdx ]
1054 meanElementsNumber = meanElementsNumber + 1.0;
1087 const unsigned int maxThreads,
1096 for(
unsigned int row = 0 ; row < rasterBlocksStatus.
getLinesNumber() ;
1102 rasterBlocksStatus( row, col ) =
false;
1108 double pixelsNumber = 0.0;
1120 if( maxThreads == 1 )
1128 boost::thread_group threads;
1130 for(
unsigned int threadIdx = 0 ; threadIdx < threadsNumber ;
1154 boost::scoped_array< unsigned char > blockBuffer(
new unsigned char[ blockSizeBytes ] );
1155 boost::scoped_array< double > doubleBuffer(
new double[ blockElementsNumber ] );
1157 unsigned int elementIdx = 0;
1159 double squaresDifsSum = 0;
1160 double elementsNumber = 0;
1184 doubleBuffer.get() );
1186 for( elementIdx = 0 ; elementIdx < blockElementsNumber ; ++elementIdx )
1188 if( noDataValue != doubleBuffer[ elementIdx ] )
1190 diff = doubleBuffer[ elementIdx ] - meanValue;
1192 squaresDifsSum += diff;
1193 elementsNumber = elementsNumber + 1.0;
1212 const unsigned int maxThreads,
double const *
const meanValuePtr,
1213 double& stdDevValue )
1218 mean = (*meanValuePtr);
1234 for(
unsigned int row = 0 ; row < rasterBlocksStatus.
getLinesNumber() ;
1240 rasterBlocksStatus( row, col ) =
false;
1246 double pixelsNumber = 0.0;
1259 if( maxThreads == 1 )
1267 boost::thread_group threads;
1269 for(
unsigned int threadIdx = 0 ; threadIdx < threadsNumber ;
1279 stdDevValue = std::sqrt( stdDevValue / pixelsNumber );
1297 boost::scoped_array< unsigned char > blockBuffer1(
new unsigned char[ blockSizeBytes1 ] );
1298 boost::scoped_array< unsigned char > blockBuffer2(
new unsigned char[ blockSizeBytes2 ] );
1299 boost::scoped_array< double > doubleBuffer1(
new double[ blockElementsNumber ] );
1300 boost::scoped_array< double > doubleBuffer2(
new double[ blockElementsNumber ] );
1302 unsigned int elementIdx = 0;
1303 double covariance = 0;
1304 double elementsNumber = 0;
1330 doubleBuffer1.get() );
1332 doubleBuffer2.get() );
1334 for( elementIdx = 0 ; elementIdx < blockElementsNumber ; ++elementIdx )
1336 if( ( noDataValue1 != doubleBuffer1[ elementIdx ] ) &&
1337 ( noDataValue2 != doubleBuffer2[ elementIdx ] ) )
1339 diff1 = doubleBuffer1[ elementIdx ] - paramsPtr->
m_mean1Value;
1340 diff2 = doubleBuffer2[ elementIdx ] - paramsPtr->
m_mean2Value;
1342 covariance += ( diff1 * diff2 );
1344 elementsNumber = elementsNumber + 1.0;
1359 double const *
const mean1ValuePtr,
double const *
const mean2ValuePtr,
1360 double& covarianceValue )
1377 mean1 = (*mean1ValuePtr);
1390 mean2 = (*mean2ValuePtr);
1411 for(
unsigned int row = 0 ; row < rasterBlocksStatus.
getLinesNumber() ;
1417 rasterBlocksStatus( row, col ) =
false;
1421 covarianceValue = 0.0;
1423 double pixelsNumber = 0.0;
1438 if( maxThreads == 1 )
1446 boost::thread_group threads;
1448 for(
unsigned int threadIdx = 0 ; threadIdx < threadsNumber ;
1458 if( pixelsNumber != 0.0 )
1460 covarianceValue /= pixelsNumber;
1473 unsigned int col = 0;
1474 double pixelsNumber = 0.0;
1476 covarianceValue = 0;
1478 for(
unsigned int row = 0 ; row < nRows ; ++row )
1480 for( col = 0 ; col < nCols ; ++col )
1482 band1.
getValue( col, row, value1 );
1483 band2.
getValue( col, row, value2 );
1485 if( ( noDataValue1 != value1 ) &&
1486 ( noDataValue2 != value2 ) )
1488 covarianceValue += ( ( value1 - mean1 ) * ( value2 - mean2 ) );
1490 pixelsNumber = pixelsNumber + 1.0;
1495 if( pixelsNumber != 0.0 )
1497 covarianceValue /= pixelsNumber;
1506 const std::vector< unsigned int >& inputRasterBands,
1507 boost::numeric::ublas::matrix< double >& pcaMatrix,
1509 const std::vector< unsigned int >& pcaRasterBands,
1510 const unsigned int maxThreads )
1539 boost::numeric::ublas::matrix< double > covarianceMatrix;
1541 covarianceMatrix.resize( inputRasterBands.size(), inputRasterBands.size() );
1543 for(
unsigned int covMatrixIdx1 = 0 ; covMatrixIdx1 < inputRasterBands.size() ;
1551 for(
unsigned int covMatrixIdx2 = 0 ; covMatrixIdx2 < inputRasterBands.size() ;
1559 if( covMatrixIdx1 > covMatrixIdx2 )
1561 covarianceMatrix( covMatrixIdx1, covMatrixIdx2 ) =
1562 covarianceMatrix( covMatrixIdx2, covMatrixIdx1 );
1567 *( inputRaster.
getBand( inputRasterBands[ covMatrixIdx2 ] ) ),
1568 maxThreads, 0, 0, covarianceMatrix( covMatrixIdx1, covMatrixIdx2 ) ) )
1580 boost::numeric::ublas::matrix< double > eigenValues;
1581 boost::numeric::ublas::matrix< double > eigenVectors;
1588 pcaMatrix = boost::numeric::ublas::trans( eigenVectors );
1590 return RemapValues( inputRaster, inputRasterBands, pcaMatrix, pcaRaster,
1591 pcaRasterBands, maxThreads );
1596 const boost::numeric::ublas::matrix< double >& pcaMatrix,
1598 const std::vector< unsigned int >& outputRasterBands,
1599 const unsigned int maxThreads )
1601 boost::numeric::ublas::matrix< double > inversePcaMatrix;
1607 std::vector< unsigned int > inputRasterBands;
1612 inputRasterBands.push_back( bandIdx );
1615 return RemapValues( pcaRaster, inputRasterBands, inversePcaMatrix,
1616 outputRaster, outputRasterBands, maxThreads );
1630 const unsigned int inputRasterBandsSize = (
unsigned int)inputRasterBands.size();
1633 assert( inputRasterBandsSize == outputRasterBands.size() );
1635 unsigned int maxBlocksSizesBytes = 0;
1636 std::vector< double > inputBandsNoDataValues( inputRasterBandsSize, 0.0 );
1637 std::vector< double > outputBandsNoDataValues( inputRasterBandsSize, 0.0 );
1638 std::vector< boost::shared_array< double > > inDoubleBuffersHandlers( inputRasterBandsSize );
1639 std::vector< boost::shared_array< double > > outDoubleBuffersHandlers( inputRasterBandsSize );
1640 unsigned int inputRasterBandsIdx = 0;
1641 boost::numeric::ublas::matrix< double > remapMatrix = *( paramsPtr->
m_remapMatrixPtr );
1642 std::vector< double > outputMinValue( inputRasterBandsSize );
1643 std::vector< double > outputMaxValue( inputRasterBandsSize );
1644 boost::shared_array< double* > inDoubleBuffersPtrsHandler(
new double*[ inputRasterBandsSize ] );
1645 boost::shared_array< double* > outDoubleBuffersPtrsHandler(
new double*[ inputRasterBandsSize ] );
1646 double** inDoubleBuffers = inDoubleBuffersPtrsHandler.get();
1647 double** outDoubleBuffers = outDoubleBuffersPtrsHandler.get();
1649 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
1650 ++inputRasterBandsIdx )
1652 const unsigned int& inBandIdx = inputRasterBands[ inputRasterBandsIdx ];
1653 assert( inBandIdx < paramsPtr->m_inputRasterPtr->getNumberOfBands() );
1657 outputRasterBands[ inputRasterBandsIdx ] );
1659 maxBlocksSizesBytes = std::max( maxBlocksSizesBytes, (
unsigned int)inBandPtr->getBlockSize() );
1660 maxBlocksSizesBytes = std::max( maxBlocksSizesBytes, (
unsigned int)outBandPtr->
getBlockSize() );
1665 inDoubleBuffersHandlers[ inputRasterBandsIdx ].reset(
new double[ blockElementsNumber ] );
1666 inDoubleBuffers[ inputRasterBandsIdx ] = inDoubleBuffersHandlers[ inputRasterBandsIdx ].get();
1668 outDoubleBuffersHandlers[ inputRasterBandsIdx ].reset(
new double[ blockElementsNumber ] );
1669 outDoubleBuffers[ inputRasterBandsIdx ] = outDoubleBuffersHandlers[ inputRasterBandsIdx ].get();
1673 outputMinValue[ inputRasterBandsIdx ],
1674 outputMaxValue[ inputRasterBandsIdx ] );
1679 boost::scoped_array< unsigned char > blockBuffer(
new unsigned char[ maxBlocksSizesBytes ] );
1681 unsigned int elementIdx = 0;
1682 boost::numeric::ublas::matrix< double > pixelValues( inputRasterBandsSize, 1 );
1683 boost::numeric::ublas::matrix< double > remappedPixelValues( inputRasterBandsSize, 1 );
1684 bool elementIsValid =
false;
1704 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
1705 ++inputRasterBandsIdx )
1707 const unsigned int& inBandIdx = inputRasterBands[ inputRasterBandsIdx ];
1710 inBandPtr->
read( blkX, blkY, blockBuffer.get() );
1713 blockElementsNumber,
1714 inDoubleBuffers[ inputRasterBandsIdx ] );
1721 for( elementIdx = 0 ; elementIdx < blockElementsNumber ; ++elementIdx )
1723 elementIsValid =
true;
1725 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
1726 ++inputRasterBandsIdx )
1728 if( inDoubleBuffers[ inputRasterBandsIdx ][ elementIdx ] ==
1729 inputBandsNoDataValues[ inputRasterBandsIdx ] )
1731 elementIsValid =
false;
1736 pixelValues( inputRasterBandsIdx, 0 ) =
1737 inDoubleBuffers[ inputRasterBandsIdx ][ elementIdx ];
1741 if( elementIsValid )
1745 remappedPixelValues = boost::numeric::ublas::prod( remapMatrix, pixelValues );
1749 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
1750 ++inputRasterBandsIdx )
1752 outDoubleBuffers[ inputRasterBandsIdx ][ elementIdx ] =
1754 outputMinValue[ inputRasterBandsIdx ],
1756 outputMaxValue[ inputRasterBandsIdx ],
1757 remappedPixelValues( inputRasterBandsIdx, 0 )
1768 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
1769 ++inputRasterBandsIdx )
1772 outputRasterBands[ inputRasterBandsIdx ] );
1776 blockBuffer.get() );
1778 outBandPtr->
write( blkX, blkY, blockBuffer.get() );
1790 const std::vector< unsigned int >& inputRasterBands,
1791 const boost::numeric::ublas::matrix< double >& remapMatrix,
1793 const std::vector< unsigned int >& outputRasterBands,
1794 const unsigned int maxThreads )
1804 if( remapMatrix.size1() != inputRasterBands.size() )
1808 if( remapMatrix.size2() != inputRasterBands.size() )
1824 if( remapMatrix.size1() != outputRasterBands.size() )
1828 if( remapMatrix.size2() != outputRasterBands.size() )
1832 for(
unsigned int inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBands.size() ;
1833 ++inputRasterBandsIdx )
1835 if( inputRasterBands[ inputRasterBandsIdx ] >= inputRaster.
getNumberOfBands() )
1840 for(
unsigned int outputRasterBandsIdx = 0 ; outputRasterBandsIdx < outputRasterBands.size() ;
1841 ++outputRasterBandsIdx )
1843 if( outputRasterBands[ outputRasterBandsIdx ] >= outputRaster.
getNumberOfBands() )
1851 bool useOptimizedRemap =
true;
1854 for(
unsigned int inputRasterBandsIdx = 0 ; inputRasterBandsIdx <
1907 useOptimizedRemap =
false;
1915 if( useOptimizedRemap )
1918 if( ! rasterBlocksStatus.
reset(
1925 for(
unsigned int row = 0 ; row < rasterBlocksStatus.
getLinesNumber() ;
1931 rasterBlocksStatus( row, col ) =
false;
1947 if( maxThreads == 1 )
1955 boost::thread_group threads;
1957 for(
unsigned int threadIdx = 0 ; threadIdx < threadsNumber ;
1971 const unsigned int inputRasterBandsSize = inputRasterBands.size();
1974 boost::numeric::ublas::matrix< double > pixelValues( inputRasterBands.size(), 1 );
1975 boost::numeric::ublas::matrix< double > remappedPixelValues( inputRasterBands.size(), 1 );
1976 std::vector< double > inputNoDataValues( inputRasterBandsSize );
1977 std::vector< double > outputNoDataValues( inputRasterBandsSize );
1978 std::vector< double > outputMinValue( inputRasterBandsSize );
1979 std::vector< double > outputMaxValue( inputRasterBandsSize );
1980 unsigned int inputRasterBandsIdx = 0;
1981 unsigned int row = 0;
1982 unsigned int col = 0;
1983 bool pixelIsValid =
false;
1985 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
1986 ++inputRasterBandsIdx )
1988 if( inputRasterBands[ inputRasterBandsIdx ] >= inputRaster.
getNumberOfBands() )
1993 inputNoDataValues[ inputRasterBandsIdx ] = inputRaster.
getBand(
1996 outputNoDataValues[ inputRasterBandsIdx ] = outputRaster.
getBand(
2001 outputMinValue[ inputRasterBandsIdx ],
2002 outputMaxValue[ inputRasterBandsIdx ] );
2005 for( row = 0 ; row < nRows ; ++row )
2007 for( col = 0 ; col < nCols ; ++col )
2009 pixelIsValid =
true;
2011 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
2012 ++inputRasterBandsIdx )
2014 inputRaster.
getValue( col, row, pixelValues( inputRasterBandsIdx, 0 ),
2015 inputRasterBands[ inputRasterBandsIdx ] );
2017 if( pixelValues( inputRasterBandsIdx, 0 ) == inputNoDataValues[ inputRasterBandsIdx ] )
2019 pixelIsValid =
false;
2026 remappedPixelValues = boost::numeric::ublas::prod( remapMatrix, pixelValues );
2028 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
2029 ++inputRasterBandsIdx )
2035 outputMinValue[ inputRasterBandsIdx ]
2038 outputMaxValue[ inputRasterBandsIdx ]
2040 remappedPixelValues( inputRasterBandsIdx, 0 )
2043 outputRasterBands[ inputRasterBandsIdx ] );
2048 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
2049 ++inputRasterBandsIdx )
2051 outputRaster.
setValue( col, row, outputNoDataValues[ inputRasterBandsIdx ],
2052 outputRasterBands[ inputRasterBandsIdx ] );
2064 const std::vector< unsigned int >& inputRasterBands,
2065 const std::vector< std::map<std::string, std::string> > & outputRastersInfos,
2066 const std::string& outputDataSourceType,
2067 std::vector< boost::shared_ptr< te::rst::Raster > > & outputRastersPtrs )
2069 outputRastersPtrs.clear();
2075 if( outputRastersInfos.size() != inputRasterBands.size() )
2079 if( outputDataSourceType.empty() )
2084 outputRastersPtrs.resize( inputRasterBands.size() );
2089 for(
unsigned int inputRasterBandsIdx = 0 ; inputRasterBandsIdx <
2090 inputRasterBands.size() ; ++inputRasterBandsIdx )
2092 const unsigned int bandIdx = inputRasterBands[ inputRasterBandsIdx ];
2098 std::vector< te::rst::BandProperty* > bandsProperties;
2103 outputRastersPtrs[ inputRasterBandsIdx].reset(
2106 outputRastersInfos[ inputRasterBandsIdx ], 0, 0 ) );
2107 if( outputRastersPtrs[ inputRasterBandsIdx].
get() == 0 )
return false;
2109 unsigned int col = 0;
2110 unsigned int row = 0;
2113 te::rst::Band& outBand = *(outputRastersPtrs[ inputRasterBandsIdx]->getBand( 0 ));
2115 for( row = 0 ; row < nRows ; ++row )
2117 for( col = 0 ; col < nCols ; ++col )
2119 inBand.
getValue( col, row, value );
2120 outBand.
setValue( col, row, value );
2130 const std::vector< unsigned int >& inputRasterBands,
2132 const std::map<std::string, std::string>& outputRasterInfo,
2133 const std::string& outputDataSourceType,
2134 std::auto_ptr< te::rst::Raster >& outputRasterPtr )
2136 outputRasterPtr.reset();
2142 if( outputDataSourceType.empty() )
2151 std::auto_ptr< te::rst::Grid > outputGridPtr;
2152 std::vector< te::rst::BandProperty* > bandsProperties;
2169 *( inputRasterPtr->
getBand( inputRasterBands[
2176 outputGridPtr.release(), bandsProperties, outputRasterInfo, 0, 0 ) );
2177 if( outputRasterPtr.get() == 0 )
return false;
2188 const unsigned int inBandIdx = inputRasterBands[
2191 unsigned int outRow = 0;
2192 unsigned int outCol = 0;
2193 const unsigned int nOutRows = outputRasterPtr->getNumberOfRows();
2194 const unsigned int nOutCols = outputRasterPtr->getNumberOfColumns();
2199 double xOutCoord = 0;
2200 double yOutCoord = 0;
2201 double xInCoord = 0;
2202 double yInCoord = 0;
2205 std::complex< double > value = 0;
2209 if( inputRasterPtr->
getSRID() == outputRasterPtr->getSRID() )
2211 for( outRow = 0 ; outRow < nOutRows ; ++outRow )
2213 for( outCol = 0 ; outCol < nOutCols ; ++outCol )
2215 outGrid.
gridToGeo( (
double)outCol, (
double)outRow, xOutCoord, yOutCoord );
2216 inGrid.
geoToGrid( xOutCoord, yOutCoord, inCol, inRow );
2217 interp.
getValue( inCol, inRow, value, inBandIdx );
2218 outBand.
setValue( outCol, outRow, value );
2224 for( outRow = 0 ; outRow < nOutRows ; ++outRow )
2226 for( outCol = 0 ; outCol < nOutCols ; ++outCol )
2228 outGrid.
gridToGeo( (
double)outCol, (
double)outRow, xOutCoord, yOutCoord );
2229 conv.convert( xOutCoord, yOutCoord, xInCoord, yInCoord );
2230 inGrid.
geoToGrid( xInCoord, yInCoord, inCol, inRow );
2231 interp.
getValue( inCol, inRow, value, inBandIdx );
2232 outBand.
setValue( outCol, outRow, value );
2248 if( ( nCols == 0 ) || ( nRows == 0 ) )
2253 const unsigned int ringSize = ( 2 * ( nCols + 1 ) ) +
2254 ( 2 * ( nRows - 1 ) ) + 1;
2265 unsigned int ringIdx = 0;
2269 ring.setPoint( 0, lLX, uRY );
2271 for( col = 0 ; col < nCols ; ++col )
2273 ring.setPoint( ++ringIdx, lLX + ( ((
double)( col + 1 ) ) * resX ), uRY );
2276 for( row = 0 ; row < nRows ; ++row )
2278 ring.setPoint( ++ringIdx, uRX, uRY - ( ((
double)( row + 1 ) ) * resY ) );
2281 for( col = nCols - 1 ; col > -1 ; --col )
2283 ring.setPoint( ++ringIdx, lLX + ( ((
double)( col + 1 ) ) * resX ), lLY );
2286 for( row = nRows - 1 ; row > 0 ; --row )
2288 ring.setPoint( ++ringIdx, lLX, uRY - ( ((
double)( row + 1 ) ) * resY ) );
2291 ring.setPoint( ringSize - 1, lLX, uRY );
2293 detailedExtent = ring;
2303 if( ( nCols == 0 ) || ( nRows == 0 ) )
2308 const unsigned int ringSize = ( 2 * ( nCols + 1 ) ) +
2309 ( 2 * ( nRows - 1 ) ) + 1;
2314 const double lLY = ((double)nRows) - 0.5;
2315 const double uRX = ((double)nCols) - 0.5;
2316 unsigned int ringIdx = 0;
2322 for( col = 0 ; col < nCols ; ++col )
2324 ring.
setPoint( ++ringIdx, 0.5 + ((
double)col), (-0.5) );
2327 for( row = 0 ; row < nRows ; ++row )
2329 ring.
setPoint( ++ringIdx, uRX, 0.5 + ((
double)row) );
2332 for( col = nCols - 1 ; col > -1 ; --col )
2334 ring.
setPoint( ++ringIdx, ((
double)col) - 0.5, lLY );
2337 for( row = nRows - 1 ; row > -1 ; --row )
2339 ring.
setPoint( ++ringIdx, (-0.5), ((
double)row) - 0.5 );
2342 ring.
setPoint( ringSize - 1, -0.5, -0.5 );
2344 indexedDetailedExtent = ring;
2352 boost::numeric::ublas::matrix< double > emptyFilter;
2354 switch( filterType )
2358 boost::numeric::ublas::matrix< double > internalFilter( 5, 5 );
2359 const double weight = 256;
2361 internalFilter(0,0) = 1/weight; internalFilter(0,1) = 4/weight; internalFilter(0,2) = 6/weight; internalFilter(0,3) = 4/weight; internalFilter(0,4) = 1/weight;
2362 internalFilter(1,0) = 4/weight; internalFilter(1,1) = 16/weight; internalFilter(1,2) = 24/weight; internalFilter(1,3) = 16/weight; internalFilter(1,4) = 4/weight;
2363 internalFilter(2,0) = 6/weight; internalFilter(2,1) = 24/weight; internalFilter(2,2) = 36/weight; internalFilter(2,3) = 24/weight; internalFilter(2,4) = 6/weight;
2364 internalFilter(3,0) = 4/weight; internalFilter(3,1) = 16/weight; internalFilter(3,2) = 24/weight; internalFilter(3,3) = 16/weight; internalFilter(3,4) = 4/weight;
2365 internalFilter(4,0) = 1/weight; internalFilter(4,1) = 4/weight; internalFilter(4,2) = 6/weight; internalFilter(4,3) = 4/weight; internalFilter(4,4) = 1/weight;
2367 return internalFilter;
2373 boost::numeric::ublas::matrix< double > internalFilter( 3, 3 );
2374 const double weight = 16;
2376 internalFilter(0,0) = 1/weight; internalFilter(0,1) = 2/weight; internalFilter(0,2) = 1/weight;
2377 internalFilter(1,0) = 2/weight; internalFilter(1,1) = 4/weight; internalFilter(1,2) = 2/weight;
2378 internalFilter(2,0) = 1/weight; internalFilter(2,1) = 2/weight; internalFilter(2,2) = 1/weight;
2380 return internalFilter;
2386 throw te::rp::Exception(
"Invalid filter type" );
2396 const std::vector< unsigned int >& inputRasterBands,
2398 const unsigned int levelsNumber,
2399 const boost::numeric::ublas::matrix< double >& filter )
2405 for(
unsigned int inputRasterBandsIdx = 0 ; inputRasterBandsIdx <
2406 inputRasterBands.size() ; ++inputRasterBandsIdx )
2408 if( inputRasterBands[ inputRasterBandsIdx ] >= inputRaster.
getNumberOfBands() )
2420 ( waveletRaster.
getNumberOfBands() < ( 2 * levelsNumber * inputRasterBands.size() ) )
2425 if( levelsNumber == 0 )
2429 if( ( filter.size1() == 0 ) || ( filter.size2() == 0 ) ||
2430 ( filter.size1() != filter.size2() )
2439 const int filterWidth = filter.size1();
2440 const int offset = filterWidth / 2;
2444 for(
unsigned int inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBands.size() ;
2445 ++inputRasterBandsIdx )
2447 for(
unsigned int levelIndex = 0; levelIndex < levelsNumber; ++levelIndex)
2449 const unsigned int currentSmoothBandIdx = ( 2 * levelsNumber *
2450 inputRasterBandsIdx ) + ( 2 * levelIndex );
2453 const unsigned int currentWaveletBandIdx = currentSmoothBandIdx + 1;
2455 currentWaveletBandIdx );
2457 const unsigned int prevSmoothBandIdx = currentSmoothBandIdx - 2;
2459 if( levelIndex == 0 )
2461 prevSmoothBandPtr = inputRaster.
getBand( inputRasterBands[ inputRasterBandsIdx ] );
2465 prevSmoothBandPtr = waveletRaster.
getBand( prevSmoothBandIdx );
2469 const int filterScale = (int)std::pow(2.0, (
double)levelIndex);
2473 int convolutionCenterCol = 0;
2474 int convolutionCenterRow = 0;
2477 double valueOriginal = 0.0;
2478 double valuePrev = 0.0;
2479 double valueNew = 0.0;
2481 for (convolutionCenterRow = 0; convolutionCenterRow < nLines; convolutionCenterRow++)
2483 for (convolutionCenterCol = 0; convolutionCenterCol < nCols; convolutionCenterCol++)
2487 for (filterRow = 0; filterRow < filterWidth; filterRow++)
2489 for (filterCol = 0; filterCol < filterWidth; filterCol++)
2491 col = convolutionCenterCol+(filterCol-offset)*filterScale;
2492 row = convolutionCenterRow+(filterRow-offset)*filterScale;
2496 else if (col >= nCols)
2500 else if (row >= nLines)
2503 prevSmoothBand.
getValue( col, row, valueOriginal );
2505 valueNew += valueOriginal * filter( filterRow, filterCol );
2509 currentSmoothBand.
setValue( convolutionCenterCol, convolutionCenterRow,
2511 prevSmoothBand.
getValue( convolutionCenterCol, convolutionCenterRow,
2513 currentWaveletBand.
setValue( convolutionCenterCol, convolutionCenterRow,
2514 valueOriginal - valueNew );
2525 const unsigned int levelsNumber,
2527 const std::vector< unsigned int >& outputRasterBands )
2532 ( waveletRaster.
getNumberOfBands() < ( 2 * levelsNumber * outputRasterBands.size() ) )
2537 if( levelsNumber == 0 )
2551 for(
unsigned int outputRasterBandsIdx = 0 ; outputRasterBandsIdx <
2552 outputRasterBands.size() ; ++outputRasterBandsIdx )
2554 if( outputRasterBands[ outputRasterBandsIdx ] >= outputRaster.
getNumberOfBands() )
2560 for(
unsigned int outputRasterBandsIdx = 0 ; outputRasterBandsIdx <
2561 outputRasterBands.size() ; ++outputRasterBandsIdx )
2563 const unsigned int outputRasterBandIdx = outputRasterBands[ outputRasterBandsIdx ];
2566 const unsigned int firstSmoothBandIdx = outputRasterBandsIdx *
2568 const unsigned int firstWaveletBandIdx = firstSmoothBandIdx
2570 const unsigned int lastSmoothBandIdx = firstSmoothBandIdx
2571 + ( 2 * levelsNumber ) - 2;
2572 const unsigned int lastWaveletBandIdx = lastSmoothBandIdx + 1;
2573 unsigned int col = 0;
2574 unsigned int row = 0;
2577 unsigned int waveletRasterBand = 0;
2579 double bandAllowedMinValue = 0;
2580 double bandAllowedMaxValue = 0;
2583 bandAllowedMaxValue );
2586 for( row = 0 ; row < nRows ; ++row )
2588 for( col = 0 ; col < nCols ; ++col )
2592 for( waveletRasterBand = firstWaveletBandIdx ;
2593 waveletRasterBand <= lastWaveletBandIdx ;
2594 waveletRasterBand += 2)
2596 waveletRaster.
getValue( col, row, value, waveletRasterBand );
2600 waveletRaster.
getValue( col, row, value, lastSmoothBandIdx );
2603 sum = std::max( sum, bandAllowedMinValue );
2604 sum = std::min( sum, bandAllowedMaxValue );
2606 outputRaster.
setValue( col, row, sum, outputRasterBandIdx );
2616 const std::vector< unsigned int >& inputRasterBands,
2618 const unsigned int firstRow,
2619 const unsigned int firstColumn,
2620 const unsigned int height,
2621 const unsigned int width,
2622 const unsigned int newheight,
2623 const unsigned int newwidth,
2624 const std::map<std::string, std::string>& rinfo,
2625 const std::string& dataSourceType,
2626 std::auto_ptr< te::rst::Raster >& resampledRasterPtr )
2636 for (std::size_t inputRasterBandsIdx = 0; inputRasterBandsIdx <
2637 inputRasterBands.size(); inputRasterBandsIdx++)
2639 if( inputRasterBands[ inputRasterBandsIdx ] >= inputRaster.
getNumberOfBands() )
2646 - 0.5, ((
double)firstRow) - 0.5);
2648 + width)) - 0.5, ((
double)(firstRow + height)) - 0.5);
2651 ulc.
x, lrc.
y, lrc.
x, ulc.
y ) );
2656 newwidth, newheight, newEnvelopePtr.release(),
2659 std::vector<te::rst::BandProperty*> bands;
2661 for (std::size_t inputRasterBandsIdx = 0; inputRasterBandsIdx <
2662 inputRasterBands.size(); inputRasterBandsIdx++)
2666 bands[ inputRasterBandsIdx ]->m_blkh = 1;
2667 bands[ inputRasterBandsIdx ]->m_blkw = newwidth;
2668 bands[ inputRasterBandsIdx ]->m_nblocksx = 1;
2669 bands[ inputRasterBandsIdx ]->m_nblocksy = newheight;
2673 gridPtr.release(), bands, rinfo, 0 ) );
2674 if( resampledRasterPtr.get() == 0 )
2681 std::complex<double> interpValue;
2683 const double rowsFactor = ((double)(height-1)) / ((
double)(newheight-1));
2684 const double colsFactor = ((double)(width-1)) / ((
double)(newwidth-1));
2685 double inputRow = 0;
2686 double inputCol = 0;
2687 unsigned int outputCol = 0;
2688 unsigned int outputRow = 0;
2689 unsigned int inputBandIdx = 0;
2690 double allowedMin = 0;
2691 double allowedMax = 0;
2693 for (std::size_t inputRasterBandsIdx = 0; inputRasterBandsIdx <
2694 inputRasterBands.size(); inputRasterBandsIdx++)
2696 te::rst::Band& outputBand = *resampledRasterPtr->getBand( inputRasterBandsIdx );
2697 inputBandIdx = inputRasterBands[ inputRasterBandsIdx ];
2701 for ( outputRow = 0; outputRow < newheight; ++outputRow)
2703 inputRow = ( ((double)( outputRow ) ) * rowsFactor ) + ((double)firstRow);
2705 for ( outputCol = 0; outputCol < newwidth; ++outputCol )
2707 inputCol = ( ((double)( outputCol ) ) * colsFactor ) + ((double)firstColumn);
2709 interp.
getValue(inputCol, inputRow, interpValue, inputBandIdx);
2711 interpValue.real( std::max( allowedMin, interpValue.real() ) );
2712 interpValue.real( std::min( allowedMax, interpValue.real() ) );
2714 outputBand.
setValue(outputCol, outputRow, interpValue);
virtual unsigned int getObjsCount() const =0
Return the total number of feeder objects.
bool GetMeanValue(const te::rst::Band &band, const unsigned int maxThreads, double &meanValue)
Get the mean of band pixel values.
double GetDigitalNumberBandMax(std::string bandName)
Returns the maximum digital number of a given sensor/band.
unsigned int getNumberOfRows() const
Returns the grid number of rows.
virtual void setValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the attribute value in a band of a cell.
boost::mutex * m_mutexPtr
double * m_stdDevValuePtr
boost::mutex * m_mutexPtr
void reset()
Reset the internal state (all internal pointed objects are deleted).
te::rst::Raster * m_outputRasterPtr
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
Matrix< bool > * m_rasterBlocksStatusPtr
unsigned int getRow() const
Returns the current row in iterator.
A raster band description.
int getSRID() const
Returns the grid spatial reference system identifier.
double * m_pixelsNumberValuePtr
A class that models the description of a dataset.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
int m_nblocksx
The number of blocks in x.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
int m_nblocksy
The number of blocks in y.
This class implements and iterator to "navigate" over a raster, with a predefined number of bands...
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
virtual std::auto_ptr< DataSourceTransactor > getTransactor()=0
It returns an object that can execute transactions in the context of a data source.
bool ConvertIHS2RGB(const te::rst::Raster &inputIHSRaster, const unsigned int intensityBandIdx, const unsigned int hueBandIdx, const unsigned int saturationBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputRGBRaster)
IHS to RGB conversion.
void TERPEXPORT GetDataTypeRange(const int dataType, double &min, double &max)
Returns the real data type range (all values that can be represented by the given data type)...
bool ComposeBands(te::rp::FeederConstRaster &feeder, const std::vector< unsigned int > &inputRasterBands, const te::rst::Interpolator::Method &interpMethod, const std::map< std::string, std::string > &outputRasterInfo, const std::string &outputDataSourceType, std::auto_ptr< te::rst::Raster > &outputRasterPtr)
Compose a set of bands into one multi-band raster.
std::vector< std::string > GetBandNames()
Returns a vector os with band's names.
bool CreateNewMemRaster(const te::rst::Grid &rasterGrid, std::vector< te::rst::BandProperty * > bandsProperties, RasterHandler &outRasterHandler)
Create a new raster into a new memory datasource.
#define MIN(a, b)
Macro that returns min between two values.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
void release(std::auto_ptr< te::da::DataSource > &dataSourcePtr, std::auto_ptr< te::da::DataSourceTransactor > &transactorPtr, std::auto_ptr< te::da::DataSet > &dataSetPtr, std::auto_ptr< te::rst::Raster > &rasterPtr)
Relase the internal state and give the ownership to the given pointers.
virtual void read(int x, int y, void *buffer) const =0
It reads a data block to the specified buffer.
Matrix< bool > * m_rasterBlocksStatusPtr
boost::mutex * m_mutexPtr
An utility struct for representing 2D coordinates.
void getValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Get the interpolated value at specific band.
int m_type
The data type of the elements in the band.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits::max().
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
te::rst::Band const * m_inputBandPtr
bool DirectPrincipalComponents(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, boost::numeric::ublas::matrix< double > &pcaMatrix, te::rst::Raster &pcaRaster, const std::vector< unsigned int > &pcaRasterBands, const unsigned int maxThreads)
Generate all principal components from the given input raster.
bool DecomposeBands(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< std::map< std::string, std::string > > &outputRastersInfos, const std::string &outputDataSourceType, std::vector< boost::shared_ptr< te::rst::Raster > > &outputRastersPtrs)
Decompose a multi-band raster into a set of one-band rasters.
InterpolationMethod
Allowed interpolation methods.
double GetSpectralBandMax(std::string bandName)
Returns the maximum reflectance value of a given sensor/band.
#define MAX(a, b)
Macro that returns max between two values.
bool RemapValues(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const boost::numeric::ublas::matrix< double > &remapMatrix, te::rst::Raster &outputRaster, const std::vector< unsigned int > &outputRasterBands, const unsigned int maxThreads)
Remap pixel values using a remap function matrix.
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
Raster Processing functions.
double getResolutionY() const
Returns the grid vertical (y-axis) resolution.
bool ConvertRGB2IHS(const te::rst::Raster &inputRGBRaster, const unsigned int redBandIdx, const unsigned int greenBandIdx, const unsigned int blueBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputIHSRaster)
RGB to IHS conversion.
std::vector< unsigned int > const * m_inputRasterBandsPtr
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
boost::mutex * m_mutexPtr
bool TERPEXPORT Copy2DiskRaster(const te::rst::Raster &inputRaster, const std::string &fileName)
Create a new raster into a GDAL datasource.
A LinearRing is a LineString that is both closed and simple.
TECOMMONEXPORT unsigned int GetPhysProcNumber()
Returns the number of physical processors.
te::rst::Band const * m_inputBand1Ptr
virtual std::complex< double > getMaxValue(bool readall=false, unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the maximum occurring value in a window of the band.
bool NormalizeRaster(te::rst::Raster &inraster, double nmin, double nmax)
Normalizes one raster in a given interval.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
virtual void reset()=0
Reset the feeder to the first position (subsequent accesses will start from the first sequence obejct...
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
static RasterIterator begin(Raster *r, const std::vector< unsigned int > &bands)
Returns an iterator referring to the first value.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
unsigned int getColumnsNumber() const
The number of current matrix columns.
bool InverseWaveletAtrous(const te::rst::Raster &waveletRaster, const unsigned int levelsNumber, te::rst::Raster &outputRaster, const std::vector< unsigned int > &outputRasterBands)
Regenerate the original raster from its wavelets planes.
static std::auto_ptr< DataSource > make(const std::string &dsType)
WaveletAtrousFilterType
Wavelet Atrous Filter types.
BandProperty * getProperty()
Returns the band property.
int m_blkw
Block width (pixels).
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
std::pair< double, double > GetDigitalNumberBandInfo(std::string bandName)
Returns the maximun and minimum digital numbers of a given sensor/band.
te::rst::Raster const * m_inputRasterPtr
unsigned int getNumberOfColumns() const
Returns the grid number of columns.
bool DirectWaveletAtrous(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, te::rst::Raster &waveletRaster, const unsigned int levelsNumber, const boost::numeric::ublas::matrix< double > &filter)
Generate all wavelet planes from the given input raster.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
double getResolutionX() const
Returns the grid horizontal (x-axis) resolution.
virtual void write(int x, int y, void *buffer)=0
It writes a data block from the specified buffer.
void Convert2DoublesVector(void *inputVector, const int inputVectorDataType, unsigned int inputVectorSize, double *outputVector)
Convert vector elements.
te::rst::Band const * m_inputBand2Ptr
bool EigenVectors(const boost::numeric::ublas::matrix< T > &inputMatrix, boost::numeric::ublas::matrix< T > &eigenVectorsMatrix, boost::numeric::ublas::matrix< T > &eigenValuesMatrix)
Computes the eigenvectors of a given matrix.
void GetMeanValueThread(GetMeanValueThreadParams *paramsPtr)
A raster band description.
Matrix< bool > * m_rasterBlocksStatusPtr
bool GetDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &detailedExtent)
Create a datailed extent from the given grid.
Grid * getGrid()
It returns the raster grid.
te::rst::Band const * m_inputBandPtr
void reset()
Reset (clear) the active instance data.
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
void RemapValuesThread(RemapValuesThreadParams *paramsPtr)
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
bool CreateNewRaster(const te::rst::Grid &rasterGrid, const std::vector< te::rst::BandProperty * > &bandsProperties, const std::string &outDataSetName, const std::string &dataSourceType, RasterHandler &outRasterHandler)
Create a new raster into the givem data source.
boost::numeric::ublas::matrix< double > CreateWaveletAtrousFilter(const WaveletAtrousFilterType &filterType)
Create a Wavele Atrous Filter.
bool GetCovarianceValue(const te::rst::Band &band1, const te::rst::Band &band2, const unsigned int maxThreads, double const *const mean1ValuePtr, double const *const mean2ValuePtr, double &covarianceValue)
Get the covariance of band pixel values.
int getSRID() const
Returns the raster spatial reference system identifier.
double * m_pixelsNumberValuePtr
double GetSpectralBandMin(std::string bandName)
Returns the minimum reflectance value of a given sensor/band.
Feeder from a input rasters.
virtual std::complex< double > getMinValue(bool readall=false, unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the minimum occurring value in a window of the band.
static Raster * make()
It creates and returns an empty raster with default raster driver.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
bool GetInverseMatrix(const boost::numeric::ublas::matrix< T > &inputMatrix, boost::numeric::ublas::matrix< T > &outputMatrix)
Matrix inversion.
bool GetIndexedDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &indexedDetailedExtent)
Create a indexed (lines,columns) datailed extent from the given grid.
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
bool InversePrincipalComponents(const te::rst::Raster &pcaRaster, const boost::numeric::ublas::matrix< double > &pcaMatrix, te::rst::Raster &outputRaster, const std::vector< unsigned int > &outputRasterBands, const unsigned int maxThreads)
Regenerate the original raster from its principal components.
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
std::vector< unsigned int > const * m_outputRasterBandsPtr
static RasterIterator end(Raster *r, const std::vector< unsigned int > &bands)
Returns an iterator referring to after the end of the iterator.
te::rst::Raster * getRasterPtr()
Returns a pointer the the handled raster instance or NULL if no instance is handled.
unsigned int getColumn() const
Returns the current column in iterator.
int getType() const
It returns the data type of the elements in the band.
virtual bool moveNext()=0
Advances to the next sequence obeject.
Matrix< bool > * m_rasterBlocksStatusPtr
bool RasterResample(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const te::rst::Interpolator::Method interpMethod, const unsigned int firstRow, const unsigned int firstColumn, const unsigned int height, const unsigned int width, const unsigned int newheight, const unsigned int newwidth, const std::map< std::string, std::string > &rinfo, const std::string &dataSourceType, std::auto_ptr< te::rst::Raster > &resampledRasterPtr)
Resample a subset of the raster, given a box.
bool CreateNewGdalRaster(const te::rst::Grid &rasterGrid, std::vector< te::rst::BandProperty * > bandsProperties, const std::string &fileName, RasterHandler &outRasterHandler)
Create a new raster into a GDAL datasource.
double * m_covarianceValuePtr
int m_blkh
Block height (pixels).
std::pair< double, double > GetSpectralBandInfo(std::string bandName)
Returns the maximun and minimum reflectance values of a given sensor/band.
virtual te::rst::Raster const * getCurrentObj() const =0
Return the current sequence object.
A rectified grid is the spatial support for raster data.
boost::numeric::ublas::matrix< double > const * m_remapMatrixPtr
void GetCovarianceValueThread(GetCovarianceValueThreadParams *paramsPtr)
double * m_pixelsNumberValuePtr
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
void GetStdDevValueThread(GetStdDevValueThreadParams *paramsPtr)
unsigned int getLinesNumber() const
The number of current matrix lines.
virtual unsigned int getCurrentOffset() const =0
Return the index of the current object.
bool GetStdDevValue(const te::rst::Band &band, const unsigned int maxThreads, double const *const meanValuePtr, double &stdDevValue)
Get the standard deviation of band pixel values.
void ConvertDoublesVector(double *inputVector, unsigned int inputVectorSize, const int outputVectorDataType, void *outputVector)
Convert a doubles vector.