27 #include "../dataaccess/dataset/DataSetType.h"
28 #include "../dataaccess/datasource/DataSourceFactory.h"
29 #include "../dataaccess/utils/Utils.h"
30 #include "../datatype/Enums.h"
31 #include "../raster/BandProperty.h"
32 #include "../raster/Grid.h"
33 #include "../raster/RasterFactory.h"
34 #include "../raster/RasterProperty.h"
35 #include "../raster/RasterIterator.h"
36 #include "../geometry/Point.h"
43 #include <boost/filesystem.hpp>
44 #include <boost/numeric/ublas/io.hpp>
45 #include <boost/numeric/ublas/matrix.hpp>
46 #include <boost/shared_ptr.hpp>
47 #include <boost/random.hpp>
48 #include <boost/random/uniform_int_distribution.hpp>
49 #include <boost/lexical_cast.hpp>
60 #define M_PI 3.14159265358979323846
68 const std::vector< te::rst::BandProperty* >& bandsProperties,
69 const std::string& outDataSetName,
70 const std::string& dataSourceType,
75 std::auto_ptr< te::da::DataSource > dataSourcePtr(
77 if( dataSourcePtr.get() == 0 )
return false;
82 outDataSetName, *dataSourcePtr, internalRasterHandler ) )
84 std::auto_ptr< te::da::DataSource > dummyDataSourcePtr;
85 std::auto_ptr< te::da::DataSourceTransactor > transactorPtr;
86 std::auto_ptr< te::da::DataSet > dataSetPtr;
87 std::auto_ptr< te::rst::Raster > rasterPtr;
89 internalRasterHandler.
release( dummyDataSourcePtr, transactorPtr,
90 dataSetPtr, rasterPtr );
92 outRasterHandler.
reset( dataSourcePtr.release(), transactorPtr.release(),
93 dataSetPtr.release(), rasterPtr.release() );
104 const std::vector< te::rst::BandProperty* >& bandsProperties,
105 const std::string& outDataSetName,
111 std::auto_ptr< te::rst::RasterProperty > rasterPropertyPtr(
113 bandsProperties, std::map< std::string, std::string >(),
118 std::auto_ptr< te::da::DataSourceTransactor > transactorPtr(
121 if( transactorPtr.get() == 0 )
128 if( transactorPtr->dataSetExists( outDataSetName ) )
130 transactorPtr->dropDataSet( outDataSetName );
133 std::auto_ptr< te::da::DataSetType > dataSetTypePtr(
135 dataSetTypePtr->add( rasterPropertyPtr.release() );
139 transactorPtr->createDataSet( dataSetTypePtr.get(),
140 std::map< std::string, std::string >() );
147 if( ! transactorPtr->dataSetExists( outDataSetName ) )
return false;
149 std::auto_ptr< te::da::DataSet > dataSetPtr( transactorPtr->getDataSet(
152 if( dataSetPtr.get() == 0 )
159 std::auto_ptr< te::rst::Raster > rasterPtr( dataSetPtr->getRaster( 0 ) );
161 if( rasterPtr.get() )
163 outRasterHandler.
reset( transactorPtr.release(), dataSetPtr.release(), rasterPtr.release() );
173 std::vector< te::rst::BandProperty* > bandsProperties,
176 std::string dataSetName = std::string(
"createNewMemRaster" ) +
177 boost::lexical_cast< std::string >( &outRasterHandler );
180 "MEM", outRasterHandler );
184 std::vector< te::rst::BandProperty* > bandsProperties,
185 const std::string& fileName,
189 boost::filesystem::path pathInfo( fileName );
193 std::auto_ptr< te::da::DataSource > dataSourcePtr(
195 if( dataSourcePtr.get() == 0 )
return false;
197 std::map<std::string, std::string> outputRasterInfo;
198 outputRasterInfo[
"SOURCE"] = pathInfo.parent_path().string();
200 dataSourcePtr->setConnectionInfo(outputRasterInfo);
201 dataSourcePtr->open();
202 if( ! dataSourcePtr->isOpened() )
return false;
207 pathInfo.filename().string(), *dataSourcePtr, internalRasterHandler ) )
209 std::auto_ptr< te::da::DataSource > dummyDataSourcePtr;
210 std::auto_ptr< te::da::DataSourceTransactor > transactorPtr;
211 std::auto_ptr< te::da::DataSet > dataSetPtr;
212 std::auto_ptr< te::rst::Raster > rasterPtr;
214 internalRasterHandler.
release( dummyDataSourcePtr, transactorPtr,
215 dataSetPtr, rasterPtr );
217 outRasterHandler.
reset( dataSourcePtr.release(), transactorPtr.release(),
218 dataSetPtr.release(), rasterPtr.release() );
246 min = -1.0 * (double)std::numeric_limits<short int>::max();
247 max = (double)std::numeric_limits<short int>::max();
251 max = (double)std::numeric_limits<unsigned short int>::max();
255 min = -1.0 * (double)std::numeric_limits<int>::max();
256 max = (double)std::numeric_limits<int>::max();
260 max = (double)std::numeric_limits<unsigned int>::max();
263 min = -1.0 * (double)std::numeric_limits<long int>::max();
264 max = (double)std::numeric_limits<long int>::max();
268 max = (double)std::numeric_limits<unsigned long int>::max();
272 min = -1.0 * (double)std::numeric_limits<float>::max();
273 max = (double)std::numeric_limits<float>::max();
277 min = -1.0 * (double)std::numeric_limits<double>::max();
278 max = (double)std::numeric_limits<double>::max();
281 throw te::rp::Exception(
"Invalid data type" );
287 unsigned int inputVectorSize,
double* outputVector )
289 switch( inputVectorDataType )
293 char* vPtr = (
char*)inputVector;
294 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
295 outputVector[ idx ] = (
double)vPtr[ idx ];
301 unsigned char* vPtr = (
unsigned char*)inputVector;
302 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
303 outputVector[ idx ] = (
double)vPtr[ idx ];
308 short int* vPtr = (
short int*)inputVector;
309 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
310 outputVector[ idx ] = (
double)vPtr[ idx ];
315 std::complex< short int >* vPtr = (std::complex< short int >*)
317 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
318 outputVector[ idx ] = (
double)vPtr[ idx ].real();
323 unsigned short int* vPtr = (
unsigned short int*)inputVector;
324 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
325 outputVector[ idx ] = (
double)vPtr[ idx ];
330 int* vPtr = (
int*)inputVector;
331 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
332 outputVector[ idx ] = (
double)vPtr[ idx ];
337 std::complex< int >* vPtr = (std::complex< int >*)
339 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
340 outputVector[ idx ] = (
double)vPtr[ idx ].real();
345 unsigned int* vPtr = (
unsigned int*)inputVector;
346 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
347 outputVector[ idx ] = (
double)vPtr[ idx ];
352 long int* vPtr = (
long int*)inputVector;
353 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
354 outputVector[ idx ] = (
double)vPtr[ idx ];
359 unsigned long int* vPtr = (
unsigned long int*)inputVector;
360 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
361 outputVector[ idx ] = (
double)vPtr[ idx ];
366 float* vPtr = (
float*)inputVector;
367 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
368 outputVector[ idx ] = (
double)vPtr[ idx ];
373 std::complex< float >* vPtr = (std::complex< float >*)
375 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
376 outputVector[ idx ] = (
double)vPtr[ idx ].real();
381 memcpy( outputVector, inputVector, inputVectorSize *
sizeof(
double ) );
386 std::complex< double >* vPtr = (std::complex< double >*)
388 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
389 outputVector[ idx ] = (
double)vPtr[ idx ].real();
393 throw te::rp::Exception(
"Invalid data type" );
399 unsigned int inputVectorSize,
const int outputVectorDataType,
402 switch( outputVectorDataType )
406 char* vPtr = (
char*)outputVector;
407 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
408 vPtr[ idx ] = (
char)inputVector[ idx ];
414 unsigned char* vPtr = (
unsigned char*)outputVector;
415 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
416 vPtr[ idx ] = (
unsigned char)inputVector[ idx ];
421 short int* vPtr = (
short int*)outputVector;
422 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
423 vPtr[ idx ] = (
short int)inputVector[ idx ];
428 std::complex< short int >* vPtr = (std::complex< short int >*)
430 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
431 vPtr[ idx ]= ( (
short int)inputVector[ idx ] );
436 unsigned short int* vPtr = (
unsigned short int*)outputVector;
437 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
438 vPtr[ idx ] = (
unsigned short int)inputVector[ idx ];
443 int* vPtr = (
int*)outputVector;
444 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
445 vPtr[ idx ] = (
int)inputVector[ idx ];
450 std::complex< int >* vPtr = (std::complex< int >*)
452 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
453 vPtr[ idx ] = ( (
int)inputVector[ idx ] );
458 unsigned int* vPtr = (
unsigned int*)outputVector;
459 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
460 vPtr[ idx ] = (
unsigned int)inputVector[ idx ];
465 long int* vPtr = (
long int*)outputVector;
466 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
467 vPtr[ idx ] = (
long int)inputVector[ idx ];
472 unsigned long int* vPtr = (
unsigned long int*)outputVector;
473 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
474 vPtr[ idx ] = (
unsigned long int)inputVector[ idx ];
479 float* vPtr = (
float*)outputVector;
480 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
481 vPtr[ idx ] = (
float)inputVector[ idx ];
486 std::complex< float >* vPtr = (std::complex< float >*)
488 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
489 vPtr[ idx ] = ( (
float)inputVector[ idx ] );
494 memcpy( outputVector, outputVector, inputVectorSize *
sizeof(
double ) );
499 std::complex< double >* vPtr = (std::complex< double >*)
501 for(
register unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
502 vPtr[ idx ] = ( (
double)inputVector[ idx ] );
506 throw te::rp::Exception(
"Invalid data type" );
513 static std::vector<std::string> bandNames;
515 bandNames.push_back(
"CBERS2_CCD_1_BLUE");
516 bandNames.push_back(
"CBERS2_CCD_2_GREEN");
517 bandNames.push_back(
"CBERS2_CCD_3_RED");
518 bandNames.push_back(
"CBERS2_CCD_4_NIR");
519 bandNames.push_back(
"CBERS2_CCD_5_PAN");
521 bandNames.push_back(
"LANDSAT5_TM_1_BLUE");
522 bandNames.push_back(
"LANDSAT5_TM_2_GREEN");
523 bandNames.push_back(
"LANDSAT5_TM_3_RED");
524 bandNames.push_back(
"LANDSAT5_TM_4_NIR");
525 bandNames.push_back(
"LANDSAT5_TM_5_SWIR");
526 bandNames.push_back(
"LANDSAT5_TM_6_THERMAL");
527 bandNames.push_back(
"LANDSAT5_TM_7_MIR");
529 bandNames.push_back(
"LANDSAT7_ETM+_1_BLUE");
530 bandNames.push_back(
"LANDSAT7_ETM+_2_GREEN");
531 bandNames.push_back(
"LANDSAT7_ETM+_3_RED");
532 bandNames.push_back(
"LANDSAT7_ETM+_4_NIR");
533 bandNames.push_back(
"LANDSAT7_ETM+_5_SWIR");
534 bandNames.push_back(
"LANDSAT7_ETM+_6_THERMAL");
535 bandNames.push_back(
"LANDSAT7_ETM+_7_MIR");
536 bandNames.push_back(
"LANDSAT7_ETM+_8_PAN");
538 bandNames.push_back(
"WV2_MUL_1_COASTAL");
539 bandNames.push_back(
"WV2_MUL_2_BLUE");
540 bandNames.push_back(
"WV2_MUL_3_GREEN");
541 bandNames.push_back(
"WV2_MUL_4_YELLOW");
542 bandNames.push_back(
"WV2_MUL_5_RED");
543 bandNames.push_back(
"WV2_MUL_6_REDEDGE");
544 bandNames.push_back(
"WV2_MUL_7_NIR1");
545 bandNames.push_back(
"WV2_MUL_8_NIR2");
546 bandNames.push_back(
"WV2_PAN");
553 static std::map<std::string, std::pair<double, double> > BandInfo;
555 BandInfo[
"CBERS2_CCD_1_BLUE"] = std::pair<double, double> (0.45, 0.52);
556 BandInfo[
"CBERS2_CCD_2_GREEN"] = std::pair<double, double> (0.52, 0.59);
557 BandInfo[
"CBERS2_CCD_3_RED"] = std::pair<double, double> (0.63, 0.69);
558 BandInfo[
"CBERS2_CCD_4_NIR"] = std::pair<double, double> (0.77, 0.89);
559 BandInfo[
"CBERS2_CCD_5_PAN"] = std::pair<double, double> (0.51, 0.73);
561 BandInfo[
"LANDSAT5_TM_1_BLUE"] = std::pair<double, double> (0.45, 0.52);
562 BandInfo[
"LANDSAT5_TM_2_GREEN"] = std::pair<double, double> (0.52, 0.60);
563 BandInfo[
"LANDSAT5_TM_3_RED"] = std::pair<double, double> (0.63, 0.69);
564 BandInfo[
"LANDSAT5_TM_4_NIR"] = std::pair<double, double> (0.76, 0.90);
565 BandInfo[
"LANDSAT5_TM_5_SWIR"] = std::pair<double, double> (1.55, 1.75);
566 BandInfo[
"LANDSAT5_TM_6_THERMAL"] = std::pair<double, double> (10.40, 12.50);
567 BandInfo[
"LANDSAT5_TM_7_MIR"] = std::pair<double, double> (2.08, 2.35);
569 BandInfo[
"LANDSAT7_ETM+_1_BLUE"] = std::pair<double, double> (0.45, 0.515);
570 BandInfo[
"LANDSAT7_ETM+_2_GREEN"] = std::pair<double, double> (0.525, 0.605);
571 BandInfo[
"LANDSAT7_ETM+_3_RED"] = std::pair<double, double> (0.63, 0.69);
572 BandInfo[
"LANDSAT7_ETM+_4_NIR"] = std::pair<double, double> (0.75, 0.90);
573 BandInfo[
"LANDSAT7_ETM+_5_SWIR"] = std::pair<double, double> (1.55, 1.75);
574 BandInfo[
"LANDSAT7_ETM+_6_THERMAL"] = std::pair<double, double> (10.40, 12.5);
575 BandInfo[
"LANDSAT7_ETM+_7_MIR"] = std::pair<double, double> (2.09, 2.35);
576 BandInfo[
"LANDSAT7_ETM+_8_PAN"] = std::pair<double, double> (0.52, 0.90);
578 BandInfo[
"WV2_MUL_1_COASTAL"] = std::pair<double, double> (0.4, 0.45);
579 BandInfo[
"WV2_MUL_2_BLUE"] = std::pair<double, double> (0.45, 0.51);
580 BandInfo[
"WV2_MUL_3_GREEN"] = std::pair<double, double> (0.51, 0.58);
581 BandInfo[
"WV2_MUL_4_YELLOW"] = std::pair<double, double> (0.585, 0.625);
582 BandInfo[
"WV2_MUL_5_RED"] = std::pair<double, double> (0.66, 0.69);
583 BandInfo[
"WV2_MUL_6_REDEDGE"] = std::pair<double, double> (0.705, 0.745);
584 BandInfo[
"WV2_MUL_7_NIR1"] = std::pair<double, double> (0.77, 0.895);
585 BandInfo[
"WV2_MUL_8_NIR2"] = std::pair<double, double> (0.86, 0.104);
586 BandInfo[
"WV2_PAN"] = std::pair<double, double> (0.45, 0.8);
590 if (BandInfo.find(bandName) == BandInfo.end())
591 return std::pair<double, double> (0.0, 1.0);
593 return BandInfo[bandName];
608 static std::map<std::string, std::pair<double, double> > DNBandInfo;
610 DNBandInfo[
"CBERS2_CCD_1_BLUE"] = std::pair<double, double> (0.0, 255.0);
611 DNBandInfo[
"CBERS2_CCD_2_GREEN"] = std::pair<double, double> (0.0, 255.0);
612 DNBandInfo[
"CBERS2_CCD_3_RED"] = std::pair<double, double> (0.0, 255.0);
613 DNBandInfo[
"CBERS2_CCD_4_NIR"] = std::pair<double, double> (0.0, 255.0);
614 DNBandInfo[
"CBERS2_CCD_5_PAN"] = std::pair<double, double> (0.0, 255.0);
616 DNBandInfo[
"LANDSAT5_TM_1_BLUE"] = std::pair<double, double> (0.0, 255.0);
617 DNBandInfo[
"LANDSAT5_TM_2_GREEN"] = std::pair<double, double> (0.0, 255.0);
618 DNBandInfo[
"LANDSAT5_TM_3_RED"] = std::pair<double, double> (0.0, 255.0);
619 DNBandInfo[
"LANDSAT5_TM_4_NIR"] = std::pair<double, double> (0.0, 255.0);
620 DNBandInfo[
"LANDSAT5_TM_5_SWIR"] = std::pair<double, double> (0.0, 255.0);
621 DNBandInfo[
"LANDSAT5_TM_6_THERMAL"] = std::pair<double, double> (0.0, 255.0);
622 DNBandInfo[
"LANDSAT5_TM_7_MIR"] = std::pair<double, double> (0.0, 255.0);
624 DNBandInfo[
"LANDSAT7_ETM+_1_BLUE"] = std::pair<double, double> (0.0, 255.0);
625 DNBandInfo[
"LANDSAT7_ETM+_2_GREEN"] = std::pair<double, double> (0.0, 255.0);
626 DNBandInfo[
"LANDSAT7_ETM+_3_RED"] = std::pair<double, double> (0.0, 255.0);
627 DNBandInfo[
"LANDSAT7_ETM+_4_NIR"] = std::pair<double, double> (0.0, 255.0);
628 DNBandInfo[
"LANDSAT7_ETM+_5_SWIR"] = std::pair<double, double> (0.0, 255.0);
629 DNBandInfo[
"LANDSAT7_ETM+_6_THERMAL"] = std::pair<double, double> (0.0, 255.0);
630 DNBandInfo[
"LANDSAT7_ETM+_7_MIR"] = std::pair<double, double> (0.0, 255.0);
631 DNBandInfo[
"LANDSAT7_ETM+_8_PAN"] = std::pair<double, double> (0.0, 255.0);
633 DNBandInfo[
"WV2_MUL_1_COASTAL"] = std::pair<double, double> (0.0, 2048.0);
634 DNBandInfo[
"WV2_MUL_2_BLUE"] = std::pair<double, double> (0.0, 2048.0);
635 DNBandInfo[
"WV2_MUL_3_GREEN"] = std::pair<double, double> (0.0, 2048.0);
636 DNBandInfo[
"WV2_MUL_4_YELLOW"] = std::pair<double, double> (0.0, 2048.0);
637 DNBandInfo[
"WV2_MUL_5_RED"] = std::pair<double, double> (0.0, 2048.0);
638 DNBandInfo[
"WV2_MUL_6_REDEDGE"] = std::pair<double, double> (0.0, 2048.0);
639 DNBandInfo[
"WV2_MUL_7_NIR1"] = std::pair<double, double> (0.0, 2048.0);
640 DNBandInfo[
"WV2_MUL_7_NIR2"] = std::pair<double, double> (0.0, 2048.0);
641 DNBandInfo[
"WV2_PAN"] = std::pair<double, double> (0.0, 2048.0);
645 if (DNBandInfo.find(bandName) == DNBandInfo.end())
646 return std::pair<double, double> (0.0, 255.0);
648 return DNBandInfo[bandName];
662 std::vector<double> omins;
663 std::vector<double> omaxs;
664 std::vector<unsigned int> bands;
676 const double namplitude = nmax - nmin;
677 std::vector<double> oamplitude;
679 oamplitude.push_back(omaxs[b] - omins[b]);
689 value = ((*it)[b] - omins[b]) * namplitude / oamplitude[b] + nmin;
702 std::vector<te::gm::Point*> randomPoints;
706 boost::random::mt19937 generator((boost::random::mt19937::result_type) time(0));
707 boost::random::uniform_int_distribution<> random_rows(0, inputRaster.
getNumberOfRows() - 1);
708 boost::random::uniform_int_distribution<> random_columns(0, inputRaster.
getNumberOfColumns() - 1);
710 for (
unsigned int p = 0; p < numberOfPoints; p++)
712 inputRaster.
getGrid()->
gridToGeo(random_columns(generator), random_rows(generator), randX, randY);
720 const unsigned int redBandIdx,
const unsigned int greenBandIdx,
721 const unsigned int blueBandIdx,
const double rgbRangeMin,
745 const double blueNoData = inputRGBRaster.
getBand(
748 unsigned int outRow = 0;
749 unsigned int outCol = 0;
754 double redNorm = 0, greenNorm = 0, blueNorm = 0;
755 double rMinusG = 0, rMinusB = 0;
758 const double twoPi = 2.0 * ((double)
M_PI);
759 const double pi2 = ((double)
M_PI) / 2.0;
760 const double rgbNormFac = ( rgbRangeMax == rgbRangeMin ) ? 0.0 :
761 ( 1.0 / ( rgbRangeMax - rgbRangeMin ) );
762 double intensity = 0;
764 double saturation = 0;
766 for( outRow = 0 ; outRow < outNRows ; ++outRow )
768 for( outCol = 0 ; outCol < outNCols ; ++outCol )
770 redBand.
getValue( outCol, outRow, red );
771 greenBand.
getValue( outCol, outRow, green );
772 blueBand.
getValue( outCol, outRow, blue );
774 if( ( red == redNoData ) || ( green == greenNoData ) ||
775 ( blue == blueNoData ) )
783 if( ( red == green ) && ( green == blue ) )
793 intensity = ( red * rgbNormFac );
797 redNorm = ( red - rgbRangeMin ) * rgbNormFac;
798 greenNorm = ( green - rgbRangeMin ) * rgbNormFac;
799 blueNorm = ( blue - rgbRangeMin ) * rgbNormFac;
801 rMinusG = redNorm - greenNorm;
802 rMinusB = redNorm - blueNorm;
804 cosValue = std::sqrt( ( rMinusG * rMinusG ) + ( rMinusB *
805 ( greenNorm - blueNorm ) ) );
807 if( cosValue == 0.0 )
813 cosValue = ( 0.5 * ( rMinusG + rMinusB ) ) /
815 teta = std::acos( cosValue );
818 assert( ( cosValue >= (-1.0) ) && ( cosValue <= (1.0) ) );
820 if( blueNorm > greenNorm )
822 hue = ( twoPi - teta );
829 rgbSum = ( redNorm + greenNorm + blueNorm );
831 saturation = ( 1.0 - ( 3 * std::min( std::min( redNorm, greenNorm ), blueNorm ) /
834 intensity = ( rgbSum / 3.0 );
838 outputIHSRaster.
setValue( outCol, outRow, intensity, 0 );
839 outputIHSRaster.
setValue( outCol, outRow, hue, 1 );
840 outputIHSRaster.
setValue( outCol, outRow, saturation, 2 );
848 const unsigned int intensityBandIdx,
const unsigned int hueBandIdx,
849 const unsigned int saturationBandIdx,
const double rgbRangeMin,
867 const double intensityNoData = inputIHSRaster.
getBand(
869 const double hueNoData = inputIHSRaster.
getBand(
871 const double saturationNoData = inputIHSRaster.
getBand(
874 const double rgbNormFac = ( rgbRangeMax == rgbRangeMin ) ? 0.0 :
875 ( rgbRangeMax - rgbRangeMin );
876 const double pi3 =
M_PI / 3.0;
877 const double twoPi3 = 2.0 *
M_PI / 3.0;
878 const double fourPi3 = 4.0 *
M_PI / 3.0;
879 unsigned int row = 0;
880 unsigned int col = 0;
894 for( row = 0 ; row < nRows ; ++row )
896 for( col = 0 ; col < nCols ; ++col )
898 intensityBand.
getValue( col, row, lig );
900 saturationBand.
getValue( col, row, sat );
902 if( ( lig == intensityNoData ) || ( hue == hueNoData ) ||
903 ( sat == saturationNoData ) )
905 red = green = blue = 0;
909 if( ( hue == 0.0 ) && ( sat == 0.0 ) )
911 red = green = blue = ( lig * rgbNormFac );
918 blue = lig * ( 1.0 - sat );
919 red = lig * ( 1.0 + ( sat * std::cos( hue ) /
920 std::cos( pi3 - hue ) ) );
921 green = ( 3.0 * lig ) - ( red + blue );
923 else if( hue < fourPi3 )
928 red = lig * ( 1.0 - sat );
929 green = lig * ( 1.0 + ( sat * std::cos( hue ) /
930 std::cos( pi3 - hue ) ) );
931 blue = ( 3.0 * lig ) - ( red + green );
938 green = lig * ( 1.0 - sat );
939 blue = lig * ( 1.0 + ( sat * std::cos( hue ) /
940 std::cos( pi3 - hue ) ) );
941 red = ( 3.0 * lig ) - ( green + blue );
944 red = ( red * rgbNormFac ) + rgbRangeMin;
945 green = ( green * rgbNormFac ) + rgbRangeMin;
946 blue = ( blue * rgbNormFac ) + rgbRangeMin;
950 red =
MIN( red, rgbRangeMax );
951 green =
MIN( green, rgbRangeMax );
952 blue =
MIN( blue, rgbRangeMax );
954 red =
MAX( red, rgbRangeMin );
955 green =
MAX( green, rgbRangeMin );
956 blue =
MAX( blue, rgbRangeMin );
959 greenBand.
setValue( col, row, green );
960 blueBand.
setValue( col, row, blue );
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.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
std::vector< te::gm::Point * > GetRandomPointsInRaster(const te::rst::Raster &inputRaster, unsigned int numberOfPoints)
Creates a vector of random positions (points) inside the raster.
Raster Processing functions.
bool NormalizeRaster(te::rst::Raster &inraster, double nmin, double nmax)
Normalizes one raster in a given interval.
This class implements and iterator to "navigate" over a raster, with a predefined number of bands...
double GetSpectralBandMax(std::string bandName)
Returns the maximum reflectance value of a given sensor/band.
Grid * getGrid()
It returns the raster grid.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
virtual std::auto_ptr< DataSourceTransactor > getTransactor()=0
It returns an object that can execute transactions in the context of a data source.
static std::auto_ptr< DataSource > make(const std::string &dsType)
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 std::complex< double > getMinValue(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.
double GetDigitalNumberBandMax(std::string bandName)
Returns the maximum digital number of a given sensor/band.
bool ConvertRBG2IHS(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.
void Convert2DoublesVector(void *inputVector, const int inputVectorDataType, unsigned int inputVectorSize, double *outputVector)
Convert vector elements.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
unsigned int getRow() const
Returns the current row in iterator.
double GetSpectralBandMin(std::string bandName)
Returns the minimum reflectance value of a given sensor/band.
A raster band description.
A rectified grid is the spatial support for raster data.
int getSRID() const
Returns the raster spatial reference system identifier.
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
std::pair< double, double > GetSpectralBandInfo(std::string bandName)
Returns the maximun and minimum reflectance values of a given sensor/band.
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.
std::vector< std::string > GetBandNames()
Returns a vector os with band's names.
A point with x and y coordinate values.
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.
bool CreateNewMemRaster(const te::rst::Grid &rasterGrid, std::vector< te::rst::BandProperty * > bandsProperties, RasterHandler &outRasterHandler)
Create a new raster into a new memory datasource.
void reset()
Reset the internal state (all internal pointed objects are deleted).
std::pair< double, double > GetDigitalNumberBandInfo(std::string bandName)
Returns the maximun and minimum digital numbers of a given sensor/band.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
A class that models the description of a dataset.
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
#define MIN(a, b)
Macro that returns min between two values.
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
static RasterIterator end(Raster *r, const std::vector< unsigned int > &bands)
Returns an iterator referring to after the end of the iterator.
void 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)...
An abstract class for raster data strucutures.
BandProperty * getProperty()
Returns the band property.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
void ConvertDoublesVector(double *inputVector, unsigned int inputVectorSize, const int outputVectorDataType, void *outputVector)
Convert a doubles vector.
unsigned int getColumn() const
Returns the current column in iterator.
#define MAX(a, b)
Macro that returns max between two values.
virtual std::complex< double > getMaxValue(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.
static RasterIterator begin(Raster *r, const std::vector< unsigned int > &bands)
Returns an iterator referring to the first value.
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.
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.