34 #include "../common/SystemApplicationSettings.h" 35 #include "../common/Version.h" 36 #include "../core/utils/Platform.h" 37 #include "../dataaccess/dataset/DataSetType.h" 38 #include "../dataaccess/datasource/DataSourceFactory.h" 39 #include "../dataaccess/utils/Utils.h" 40 #include "../datatype/Enums.h" 41 #include "../raster/BandProperty.h" 42 #include "../raster/Grid.h" 43 #include "../raster/RasterFactory.h" 44 #include "../raster/RasterProperty.h" 45 #include "../raster/RasterSummaryManager.h" 46 #include "../raster/RasterIterator.h" 47 #include "../raster/Utils.h" 48 #include "../geometry/Point.h" 49 #include "../common/MatrixUtils.h" 50 #include "../common/progress/TaskProgress.h" 57 #include <boost/filesystem.hpp> 58 #include <boost/numeric/ublas/io.hpp> 59 #include <boost/numeric/ublas/matrix.hpp> 60 #include <boost/property_tree/ptree.hpp> 61 #include <boost/property_tree/json_parser.hpp> 62 #include <boost/shared_ptr.hpp> 63 #include <boost/shared_array.hpp> 64 #include <boost/lexical_cast.hpp> 65 #include <boost/thread.hpp> 66 #include <boost/numeric/ublas/lu.hpp> 67 #include <boost/numeric/ublas/matrix.hpp> 78 #define M_PI 3.14159265358979323846 132 const std::vector< te::rst::BandProperty* >& bandsProperties,
133 const std::string& outDataSetName,
134 const std::string& dataSourceType,
139 std::unique_ptr< te::da::DataSource > dataSourcePtr(
141 if( dataSourcePtr.get() == nullptr )
return false;
146 outDataSetName, *dataSourcePtr, internalRasterHandler ) )
148 std::unique_ptr< te::da::DataSource > dummyDataSourcePtr;
149 std::unique_ptr< te::da::DataSourceTransactor > transactorPtr;
150 std::unique_ptr< te::da::DataSet > dataSetPtr;
151 std::unique_ptr< te::rst::Raster > rasterPtr;
153 internalRasterHandler.
release( dummyDataSourcePtr, transactorPtr,
154 dataSetPtr, rasterPtr );
156 outRasterHandler.
reset( dataSourcePtr.release(), transactorPtr.release(),
157 dataSetPtr.release(), rasterPtr.release() );
168 const std::vector< te::rst::BandProperty* >& bandsProperties,
169 const std::string& outDataSetName,
175 std::unique_ptr< te::rst::RasterProperty > rasterPropertyPtr(
177 bandsProperties, std::map< std::string, std::string >(),
178 false, 0,
nullptr ) );
182 std::unique_ptr< te::da::DataSourceTransactor > transactorPtr(
185 if( transactorPtr.get() == nullptr )
192 if( transactorPtr->dataSetExists( outDataSetName ) )
194 transactorPtr->dropDataSet( outDataSetName );
197 std::unique_ptr< te::da::DataSetType > dataSetTypePtr(
199 dataSetTypePtr->add( rasterPropertyPtr.release() );
203 transactorPtr->createDataSet( dataSetTypePtr.get(),
204 std::map< std::string, std::string >() );
211 if( ! transactorPtr->dataSetExists( outDataSetName ) )
return false;
213 std::unique_ptr< te::da::DataSet > dataSetPtr( transactorPtr->getDataSet(
216 if( dataSetPtr.get() == nullptr )
223 std::unique_ptr< te::rst::Raster > rasterPtr( dataSetPtr->getRaster( 0 ) );
225 if( rasterPtr.get() )
227 outRasterHandler.
reset( transactorPtr.release(), dataSetPtr.release(), rasterPtr.release() );
237 const std::vector< te::rst::BandProperty* >& bandsProperties,
238 const std::map< std::string, std::string>& rasterInfo,
239 const std::string& rasterType,
240 std::unique_ptr< te::rst::Raster >& outRasterPtr )
245 new te::rst::Grid( rasterGrid ), bandsProperties, rasterInfo,
nullptr,
nullptr ) );
252 if( outRasterPtr.get() == nullptr )
261 std::vector< te::rst::BandProperty* > bandsProperties,
264 std::string dataSetName = std::string(
"createNewMemRaster" ) +
265 boost::lexical_cast< std::string >( &outRasterHandler );
268 "MEM", outRasterHandler );
272 std::vector< te::rst::BandProperty* > bandsProperties,
273 const std::string& fileName,
276 std::unique_ptr< te::rst::Raster > outRasterPtr;
279 outRasterHandler.
reset( outRasterPtr.release() );
284 outRasterHandler.
reset();
290 std::vector< te::rst::BandProperty* > bandsProperties,
291 const std::string& fileName,
292 std::unique_ptr< te::rst::Raster >& outRasterPtr )
294 outRasterPtr.reset();
296 std::map< std::string, std::string > rInfo;
297 rInfo[
"URI" ] = fileName;
307 if( outRasterPtr.get() )
318 const std::string& fileName )
325 const unsigned int nBands =
static_cast<unsigned int>(inputRaster.
getNumberOfBands());
328 unsigned int bandIdx =0;
329 unsigned int col = 0;
330 unsigned int row = 0;
332 std::vector< te::rst::BandProperty* > bandsProperties;
333 for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
342 fileName, outRasterHandler ) )
349 for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
354 for( row = 0 ; row < nRows ; ++row )
356 for( col = 0 ; col <
nCols ; ++
col )
359 outBand.
setValue( col, row, value );
368 unsigned int inputVectorSize,
double* outputVector )
370 switch( inputVectorDataType )
374 char* vPtr =
static_cast<char*
>(inputVector);
375 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
376 outputVector[ idx ] = static_cast<double>(vPtr[ idx ]);
382 unsigned char* vPtr =
static_cast<unsigned char*
>(inputVector);
383 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
384 outputVector[ idx ] = static_cast<double>(vPtr[ idx ]);
389 short int* vPtr =
static_cast<short int*
>(inputVector);
390 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
391 outputVector[ idx ] = static_cast<double>(vPtr[ idx ]);
396 std::complex< short int >* vPtr =
static_cast<std::complex< short int >*
>(inputVector);
397 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
398 outputVector[ idx ] = static_cast<double>(vPtr[ idx ].real());
403 unsigned short int* vPtr =
static_cast<unsigned short int*
>(inputVector);
404 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
405 outputVector[ idx ] = static_cast<double>(vPtr[ idx ]);
410 int* vPtr =
static_cast<int*
>(inputVector);
411 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
412 outputVector[ idx ] = static_cast<double>(vPtr[ idx ]);
417 std::complex< int >* vPtr =
static_cast<std::complex< int >*
>(inputVector);
418 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
419 outputVector[ idx ] = static_cast<double>(vPtr[ idx ].real());
424 unsigned int* vPtr =
static_cast<unsigned int*
>(inputVector);
425 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
426 outputVector[ idx ] = static_cast<double>(vPtr[ idx ]);
431 long int* vPtr =
static_cast<long int*
>(inputVector);
432 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
433 outputVector[ idx ] = static_cast<double>(vPtr[ idx ]);
438 unsigned long int* vPtr =
static_cast<unsigned long int*
>(inputVector);
439 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
440 outputVector[ idx ] = static_cast<double>(vPtr[ idx ]);
445 float* vPtr =
static_cast<float*
>(inputVector);
446 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
447 outputVector[ idx ] = static_cast<double>(vPtr[ idx ]);
452 std::complex< float >* vPtr =
static_cast<std::complex< float >*
>(inputVector);
453 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
454 outputVector[ idx ] = static_cast<double>(vPtr[ idx ].real());
459 memcpy( outputVector, inputVector, inputVectorSize *
sizeof(
double ) );
464 std::complex< double >* vPtr =
static_cast<std::complex< double >*
>(inputVector);
465 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
466 outputVector[ idx ] = static_cast<double>(vPtr[ idx ].real());
470 throw te::rp::Exception(
"Invalid data type" );
475 unsigned int inputVectorSize,
const int outputVectorDataType,
478 switch( outputVectorDataType )
482 char* vPtr =
static_cast<char*
>(outputVector);
483 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
484 vPtr[ idx ] = static_cast<char>(inputVector[ idx ]);
490 unsigned char* vPtr =
static_cast<unsigned char*
>(outputVector);
491 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
492 vPtr[ idx ] = static_cast<unsigned char>(inputVector[ idx ]);
497 short int* vPtr =
static_cast<short int*
>(outputVector);
498 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
499 vPtr[ idx ] = static_cast<short int>(inputVector[ idx ]);
504 std::complex< short int >* vPtr =
static_cast<std::complex< short int >*
>(outputVector);
505 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
506 vPtr[ idx ]= ( static_cast<short int>(inputVector[ idx ]) );
511 unsigned short int* vPtr =
static_cast<unsigned short int*
>(outputVector);
512 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
513 vPtr[ idx ] = static_cast<unsigned short int>(inputVector[ idx ]);
518 int* vPtr =
static_cast<int*
>(outputVector);
519 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
520 vPtr[ idx ] = static_cast<int>(inputVector[ idx ]);
525 std::complex< int >* vPtr =
static_cast<std::complex< int >*
>(outputVector);
526 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
527 vPtr[ idx ] = ( static_cast<int>(inputVector[ idx ]) );
532 unsigned int* vPtr =
static_cast<unsigned int*
>(outputVector);
533 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
534 vPtr[ idx ] = static_cast<unsigned int>(inputVector[ idx ]);
539 long int* vPtr =
static_cast<long int*
>(outputVector);
540 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
541 vPtr[ idx ] = static_cast<long int>(inputVector[ idx ]);
546 unsigned long int* vPtr =
static_cast<unsigned long int*
>(outputVector);
547 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
548 vPtr[ idx ] = static_cast<unsigned long int>(inputVector[ idx ]);
553 float* vPtr =
static_cast<float*
>(outputVector);
554 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
555 vPtr[ idx ] = static_cast<float>(inputVector[ idx ]);
560 std::complex< float >* vPtr =
static_cast<std::complex< float >*
>(outputVector);
561 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
562 vPtr[ idx ] = ( static_cast<float>(inputVector[ idx ]) );
567 memcpy( outputVector, inputVector, inputVectorSize *
sizeof(
double ) );
572 std::complex< double >* vPtr =
static_cast<std::complex< double >*
>(outputVector);
573 for(
unsigned int idx = 0 ; idx < inputVectorSize ; ++idx )
574 vPtr[ idx ] = ( static_cast<double>(inputVector[ idx ]) );
578 throw te::rp::Exception(
"Invalid data type" );
589 static std::string sens_file = datalocalPath +
"/" + Organization +
"/" + app +
"-" + vers +
"/SpectralSensor.json";
596 static std::vector<std::string> bandNames;
599 bandNames.push_back(
"CBERS2_CCD_1_BLUE");
600 bandNames.push_back(
"CBERS2_CCD_2_GREEN");
601 bandNames.push_back(
"CBERS2_CCD_3_RED");
602 bandNames.push_back(
"CBERS2_CCD_4_NIR");
603 bandNames.push_back(
"CBERS2_CCD_5_PAN");
605 bandNames.push_back(
"LANDSAT5_TM_1_BLUE");
606 bandNames.push_back(
"LANDSAT5_TM_2_GREEN");
607 bandNames.push_back(
"LANDSAT5_TM_3_RED");
608 bandNames.push_back(
"LANDSAT5_TM_4_NIR");
609 bandNames.push_back(
"LANDSAT5_TM_5_SWIR");
610 bandNames.push_back(
"LANDSAT5_TM_6_THERMAL");
611 bandNames.push_back(
"LANDSAT5_TM_7_MIR");
613 bandNames.push_back(
"LANDSAT7_ETM+_1_BLUE");
614 bandNames.push_back(
"LANDSAT7_ETM+_2_GREEN");
615 bandNames.push_back(
"LANDSAT7_ETM+_3_RED");
616 bandNames.push_back(
"LANDSAT7_ETM+_4_NIR");
617 bandNames.push_back(
"LANDSAT7_ETM+_5_SWIR");
618 bandNames.push_back(
"LANDSAT7_ETM+_6_THERMAL");
619 bandNames.push_back(
"LANDSAT7_ETM+_7_MIR");
620 bandNames.push_back(
"LANDSAT7_ETM+_8_PAN");
622 bandNames.push_back(
"WV2_MUL_1_COASTAL");
623 bandNames.push_back(
"WV2_MUL_2_BLUE");
624 bandNames.push_back(
"WV2_MUL_3_GREEN");
625 bandNames.push_back(
"WV2_MUL_4_YELLOW");
626 bandNames.push_back(
"WV2_MUL_5_RED");
627 bandNames.push_back(
"WV2_MUL_6_REDEDGE");
628 bandNames.push_back(
"WV2_MUL_7_NIR1");
629 bandNames.push_back(
"WV2_MUL_8_NIR2");
630 bandNames.push_back(
"WV2_PAN");
632 bandNames.push_back(
"AWIFS_RED");
633 bandNames.push_back(
"AWIFS_GREEN");
634 bandNames.push_back(
"AWIFS_NIR");
635 bandNames.push_back(
"AWIFS_MIR");
637 bandNames.push_back(
"RAPID_EYE_BLUE");
638 bandNames.push_back(
"RAPID_EYE_GREEN");
639 bandNames.push_back(
"RAPID_EYE_RED");
640 bandNames.push_back(
"RAPID_EYE_REDEDGE");
641 bandNames.push_back(
"RAPID_EYE_NIR");
643 bandNames.push_back(
"LISS3_GREEN");
644 bandNames.push_back(
"LISS3_RED");
645 bandNames.push_back(
"LISS3_NEAR_INFRARED");
646 bandNames.push_back(
"LISS3_SHORTWAVE_INFRARED");
648 bandNames.push_back(
"DMC_NIR");
649 bandNames.push_back(
"DMC_RED");
650 bandNames.push_back(
"DMC_GREEN");
652 bandNames.push_back(
"LANDSAT8-OLI1_COASTAL_AEROSOL");
653 bandNames.push_back(
"LANDSAT8-OLI2_BLUE");
654 bandNames.push_back(
"LANDSAT8-OLI3_GREEN");
655 bandNames.push_back(
"LANDSAT8-OLI4_RED");
656 bandNames.push_back(
"LANDSAT8-OLI5_NIR");
657 bandNames.push_back(
"LANDSAT8-OLI6_SWIR1");
658 bandNames.push_back(
"LANDSAT8-OLI7_SWIR2");
659 bandNames.push_back(
"LANDSAT8-OLI8_PAN");
660 bandNames.push_back(
"LANDSAT8-OLI9_CIRRUS");
662 bandNames.push_back(
"LANDSAT8-TIRS1");
663 bandNames.push_back(
"LANDSAT8-TIRS2");
665 bandNames.push_back(
"CBERS4_PAN_PAN");
666 bandNames.push_back(
"CBERS4_PAN_GREEN");
667 bandNames.push_back(
"CBERS4_PAN_RED");
668 bandNames.push_back(
"CBERS4_PAN_NIR");
670 bandNames.push_back(
"CBERS4_MUX_BLUE");
671 bandNames.push_back(
"CBERS4_MUX_GREEN");
672 bandNames.push_back(
"CBERS4_MUX_RED");
673 bandNames.push_back(
"CBERS4_MUX_NIR");
675 bandNames.push_back(
"CBERS4_IRS_PAN");
676 bandNames.push_back(
"CBERS4_IRS_SWIR_B10");
677 bandNames.push_back(
"CBERS4_IRS_SWIR_B11");
678 bandNames.push_back(
"CBERS4_IRS_TH");
680 bandNames.push_back(
"CBERS4_WFI_BLUE");
681 bandNames.push_back(
"CBERS4_WFI_GREEN");
682 bandNames.push_back(
"CBERS4_WFI_RED");
683 bandNames.push_back(
"CBERS4_WFI_NIR");
692 static std::map<std::string, SpectralSensorParams > SensorParams;
693 SensorParams.clear();
695 if (!boost::filesystem::exists(sens_file))
698 for (
size_t i = 0; i < bn.size(); i++)
703 boost::property_tree::ptree pt;
704 boost::property_tree::json_parser::read_json(sens_file, pt);
706 for(boost::property_tree::ptree::value_type &v: pt.get_child(
"Spectral Sensors"))
708 std::string name = v.second.get<std::string>(
"name");
709 std::string
band = v.second.get<std::string>(
"band");
710 std::string lower = v.second.get<std::string>(
"lower");
711 std::string upper = v.second.get<std::string>(
"upper");
712 std::string min = v.second.get<std::string>(
"min");
713 std::string max = v.second.get<std::string>(
"max");
714 SensorParams[name] =
SpectralSensorParams(std::atoi(band.c_str()), std::atof(lower.c_str()), std::atof(upper.c_str()), std::atof(min.c_str()), std::atof(max.c_str()));
725 boost::property_tree::ptree pt;
726 boost::property_tree::ptree sensors;
728 for (std::map<std::string, te::rp::SpectralSensorParams > ::iterator it = params.begin(); it != params.end(); ++it)
730 boost::property_tree::ptree sensor;
732 sensor.put(
"name", it->first);
733 sensor.put(
"band", it->second.m_band);
734 sensor.put(
"lower", it->second.m_lower);
735 sensor.put(
"upper", it->second.m_upper);
736 sensor.put(
"min", it->second.m_min);
737 sensor.put(
"max", it->second.m_max);
739 sensors.push_back(std::make_pair(
"Spectral Sensor", sensor));
742 pt.add_child(
"Spectral Sensors", sensors);
744 boost::property_tree::json_parser::write_json(filename, pt);
750 static std::map<std::string, struct SpectralSensorParams > BandInfo;
841 if (BandInfo.find(bandName) == BandInfo.end())
844 return BandInfo[bandName];
849 std::map<std::string, SpectralSensorParams > params =
getSensorParams();
850 std::map<std::string, SpectralSensorParams > ::iterator it = params.find(bandName);
851 if (it == params.end())
852 return std::pair<double, double>(0.0, 255.0);
854 return std::pair<double, double>(it->second.m_min, it->second.m_max);
873 std::vector<double> omins;
874 std::vector<double> omaxs;
875 std::vector<unsigned int>
bands;
876 std::vector<double> dummy;
882 const std::complex<double>* cmin = rsMin->at(
b).m_minVal;
883 const std::complex<double>* cmax = rsMax->at(
b).m_maxVal;
885 omins.push_back(cmin->real());
886 omaxs.push_back(cmax->real());
894 const double namplitude = nmax - nmin;
895 std::vector<double> oamplitude;
897 oamplitude.push_back(omaxs[
b] - omins[
b]);
908 if (value != dummy[b])
909 value = ((*it)[
b] - omins[
b]) * namplitude / oamplitude[b] + nmin;
926 std::vector<double> omins;
927 std::vector<double> omaxs;
928 std::vector<unsigned int>
bands;
929 std::vector<double> dummy;
935 const std::complex<double>* cmin = rsMin->at(
b).m_minVal;
936 const std::complex<double>* cmax = rsMax->at(
b).m_maxVal;
938 omins.push_back(cmin->real());
939 omaxs.push_back(cmax->real());
947 const double namplitude = nmax - nmin;
948 std::vector<double> oamplitude;
950 oamplitude.push_back(omaxs[
b] - omins[
b]);
956 std::vector<te::rst::BandProperty*> bandsProperties;
963 bandsProperties.push_back(bprop);
966 std::map< std::string, std::string > rInfo;
975 if (value != dummy[b])
976 value = ((*it)[
b] - omins[
b]) * namplitude / oamplitude[b] + nmin;
992 inputRaster->
getValue(c, r, rasterValue, b);
995 rasterValue = 255 * (rasterValue - omins[b]) / (omaxs[
b] - omins[
b]);
997 outputRaster->
setValue(c, r, rasterValue, b);
1002 return outputRaster;
1006 const unsigned int redBandIdx,
const unsigned int greenBandIdx,
1007 const unsigned int blueBandIdx,
const double rgbRangeMin,
1035 const double blueNoData = inputRGBRaster.
getBand(
1041 unsigned int outRow = 0;
1042 unsigned int outCol = 0;
1047 double redNorm = 0, greenNorm = 0, blueNorm = 0;
1048 double rMinusG = 0, rMinusB = 0;
1050 double cosValue = 0;
1051 const double twoPi = 2.0 * (
static_cast<double>(
M_PI));
1052 const double pi2 = (
static_cast<double>(
M_PI)) / 2.0;
1053 const double rgbNormFac = ( rgbRangeMax == rgbRangeMin ) ? 0.0 :
1054 ( 1.0 / ( rgbRangeMax - rgbRangeMin ) );
1055 double intensity = 0;
1057 double saturation = 0;
1059 for( outRow = 0 ; outRow < outNRows ; ++outRow )
1061 for( outCol = 0 ; outCol < outNCols ; ++outCol )
1063 redBand.
getValue( outCol, outRow, red );
1064 greenBand.
getValue( outCol, outRow, green );
1065 blueBand.
getValue( outCol, outRow, blue );
1067 if( ( red == redNoData ) || ( green == greenNoData ) ||
1068 ( blue == blueNoData ) )
1070 iBand.
setValue( outCol, outRow, iNoData );
1071 hBand.
setValue( outCol, outRow, hNoData );
1072 sBand.
setValue( outCol, outRow, sNoData );
1076 if( ( red == green ) && ( green == blue ) )
1086 intensity = ( red * rgbNormFac );
1090 redNorm = ( red - rgbRangeMin ) * rgbNormFac;
1091 greenNorm = ( green - rgbRangeMin ) * rgbNormFac;
1092 blueNorm = ( blue - rgbRangeMin ) * rgbNormFac;
1094 rMinusG = redNorm - greenNorm;
1095 rMinusB = redNorm - blueNorm;
1097 cosValue = std::sqrt( ( rMinusG * rMinusG ) + ( rMinusB *
1098 ( greenNorm - blueNorm ) ) );
1100 if( cosValue == 0.0 )
1106 cosValue = ( 0.5 * ( rMinusG + rMinusB ) ) /
1108 teta = std::acos( cosValue );
1111 assert( ( cosValue >= (-1.0) ) && ( cosValue <= (1.0) ) );
1113 if( blueNorm > greenNorm )
1115 hue = ( twoPi - teta );
1122 rgbSum = ( redNorm + greenNorm + blueNorm );
1124 saturation = ( 1.0 - ( 3 * std::min( std::min( redNorm, greenNorm ), blueNorm ) /
1127 intensity = ( rgbSum / 3.0 );
1130 iBand.
setValue( outCol, outRow, intensity );
1131 hBand.
setValue( outCol, outRow, hue );
1132 sBand.
setValue( outCol, outRow, saturation );
1141 const te::rst::Raster& inputGreenRaster,
const unsigned int greenBandIdx,
1142 const te::rst::Raster& inputBlueRaster,
const unsigned int blueBandIdx,
1143 const double rgbRangeMin,
const double rgbRangeMax,
te::rst::Raster& outputIHSRaster)
1183 unsigned int outRow = 0;
1184 unsigned int outCol = 0;
1189 double redNorm = 0, greenNorm = 0, blueNorm = 0;
1190 double rMinusG = 0, rMinusB = 0;
1192 double cosValue = 0;
1193 const double twoPi = 2.0 * (
static_cast<double>(
M_PI));
1194 const double pi2 = (
static_cast<double>(
M_PI)) / 2.0;
1195 const double rgbNormFac = (rgbRangeMax == rgbRangeMin) ? 0.0 :
1196 (1.0 / (rgbRangeMax - rgbRangeMin));
1197 double intensity = 0;
1199 double saturation = 0;
1201 for (outRow = 0; outRow < outNRows; ++outRow)
1203 for (outCol = 0; outCol < outNCols; ++outCol)
1205 redBand.
getValue(outCol, outRow, red);
1206 greenBand.
getValue(outCol, outRow, green);
1207 blueBand.
getValue(outCol, outRow, blue);
1209 if ((red == redNoData) || (green == greenNoData) ||
1210 (blue == blueNoData))
1212 iBand.
setValue(outCol, outRow, iNoData);
1213 hBand.
setValue(outCol, outRow, hNoData);
1214 sBand.
setValue(outCol, outRow, sNoData);
1218 if ((red == green) && (green == blue))
1228 intensity = (red * rgbNormFac);
1232 redNorm = (red - rgbRangeMin) * rgbNormFac;
1233 greenNorm = (green - rgbRangeMin) * rgbNormFac;
1234 blueNorm = (blue - rgbRangeMin) * rgbNormFac;
1236 rMinusG = redNorm - greenNorm;
1237 rMinusB = redNorm - blueNorm;
1239 cosValue = std::sqrt((rMinusG * rMinusG) + (rMinusB *
1240 (greenNorm - blueNorm)));
1242 if (cosValue == 0.0)
1248 cosValue = (0.5 * (rMinusG + rMinusB)) /
1250 teta = std::acos(cosValue);
1253 assert((cosValue >= (-1.0)) && (cosValue <= (1.0)));
1255 if (blueNorm > greenNorm)
1257 hue = (twoPi - teta);
1264 rgbSum = (redNorm + greenNorm + blueNorm);
1266 saturation = (1.0 - (3 * std::min(std::min(redNorm, greenNorm), blueNorm) /
1269 intensity = (rgbSum / 3.0);
1272 iBand.
setValue(outCol, outRow, intensity);
1273 hBand.
setValue(outCol, outRow, hue);
1274 sBand.
setValue(outCol, outRow, saturation);
1283 const unsigned int intensityBandIdx,
const unsigned int hueBandIdx,
1284 const unsigned int saturationBandIdx,
const double rgbRangeMin,
1318 const double rgbNormFac = ( rgbRangeMax == rgbRangeMin ) ? 0.0 :
1319 ( rgbRangeMax - rgbRangeMin );
1320 const double pi3 =
M_PI / 3.0;
1321 const double twoPi3 = 2.0 *
M_PI / 3.0;
1322 const double fourPi3 = 4.0 *
M_PI / 3.0;
1323 unsigned int row = 0;
1324 unsigned int col = 0;
1333 for( row = 0 ; row < nRows ; ++row )
1335 for( col = 0 ; col <
nCols ; ++
col )
1337 intensityBand.
getValue( col, row, lig );
1339 saturationBand.
getValue( col, row, sat );
1341 if( ( lig == intensityNoData ) || ( hue == hueNoData ) ||
1342 ( sat == saturationNoData ) )
1344 redBand.
setValue( col, row, rNoData );
1345 greenBand.
setValue( col, row, gNoData );
1346 blueBand.
setValue( col, row, bNoData );
1350 if( ( hue == 0.0 ) && ( sat == 0.0 ) )
1352 red = green = blue = ( lig * rgbNormFac );
1359 blue = lig * ( 1.0 - sat );
1360 red = lig * ( 1.0 + ( sat * std::cos( hue ) /
1361 std::cos( pi3 - hue ) ) );
1362 green = ( 3.0 * lig ) - ( red + blue );
1364 else if( hue < fourPi3 )
1369 red = lig * ( 1.0 - sat );
1370 green = lig * ( 1.0 + ( sat * std::cos( hue ) /
1371 std::cos( pi3 - hue ) ) );
1372 blue = ( 3.0 * lig ) - ( red + green );
1379 green = lig * ( 1.0 - sat );
1380 blue = lig * ( 1.0 + ( sat * std::cos( hue ) /
1381 std::cos( pi3 - hue ) ) );
1382 red = ( 3.0 * lig ) - ( green + blue );
1385 red = ( red * rgbNormFac ) + rgbRangeMin;
1386 green = ( green * rgbNormFac ) + rgbRangeMin;
1387 blue = ( blue * rgbNormFac ) + rgbRangeMin;
1390 red =
MIN( red, rgbRangeMax );
1391 green =
MIN( green, rgbRangeMax );
1392 blue =
MIN( blue, rgbRangeMax );
1394 red =
MAX( red, rgbRangeMin );
1395 green =
MAX( green, rgbRangeMin );
1396 blue =
MAX( blue, rgbRangeMin );
1399 greenBand.
setValue( col, row, green );
1400 blueBand.
setValue( col, row, blue );
1410 const te::rst::Raster& inputSRaster,
const unsigned int saturationBandIdx,
1411 const double rgbRangeMin,
const double rgbRangeMax,
te::rst::Raster& outputRGBRaster)
1452 const double rgbNormFac = (rgbRangeMax == rgbRangeMin) ? 0.0 :
1453 (rgbRangeMax - rgbRangeMin);
1454 const double pi3 =
M_PI / 3.0;
1455 const double twoPi3 = 2.0 *
M_PI / 3.0;
1456 const double fourPi3 = 4.0 *
M_PI / 3.0;
1457 unsigned int row = 0;
1458 unsigned int col = 0;
1467 for (row = 0; row < nRows; ++row)
1471 intensityBand.
getValue(col, row, lig);
1473 saturationBand.
getValue(col, row, sat);
1475 if ((lig == intensityNoData) || (hue == hueNoData) ||
1476 (sat == saturationNoData))
1478 redBand.
setValue(col, row, rNoData);
1479 greenBand.
setValue(col, row, gNoData);
1480 blueBand.
setValue(col, row, bNoData);
1484 if ((hue == 0.0) && (sat == 0.0))
1486 red = green = blue = (lig * rgbNormFac);
1493 blue = lig * (1.0 - sat);
1494 red = lig * (1.0 + (sat * std::cos(hue) /
1495 std::cos(pi3 - hue)));
1496 green = (3.0 * lig) - (red + blue);
1498 else if (hue < fourPi3)
1503 red = lig * (1.0 - sat);
1504 green = lig * (1.0 + (sat * std::cos(hue) /
1505 std::cos(pi3 - hue)));
1506 blue = (3.0 * lig) - (red + green);
1513 green = lig * (1.0 - sat);
1514 blue = lig * (1.0 + (sat * std::cos(hue) /
1515 std::cos(pi3 - hue)));
1516 red = (3.0 * lig) - (green + blue);
1519 red = (red * rgbNormFac) + rgbRangeMin;
1520 green = (green * rgbNormFac) + rgbRangeMin;
1521 blue = (blue * rgbNormFac) + rgbRangeMin;
1524 red =
MIN(red, rgbRangeMax);
1525 green =
MIN(green, rgbRangeMax);
1526 blue =
MIN(blue, rgbRangeMax);
1528 red =
MAX(red, rgbRangeMin);
1529 green =
MAX(green, rgbRangeMin);
1530 blue =
MAX(blue, rgbRangeMin);
1533 greenBand.
setValue(col, row, green);
1543 const unsigned int redBandIdx,
const unsigned int greenBandIdx,
1544 const unsigned int blueBandIdx,
const double ,
1571 unsigned int outRow = 0;
1572 unsigned int outCol = 0;
1578 double saturation = 0;
1580 for (outRow = 0; outRow < outNRows; ++outRow)
1582 for (outCol = 0; outCol < outNCols; ++outCol)
1584 redBand.
getValue(outCol, outRow, red);
1585 greenBand.
getValue(outCol, outRow, green);
1586 blueBand.
getValue(outCol, outRow, blue);
1589 green /= rgbRangeMax;
1590 blue /= rgbRangeMax;
1592 double vmax =
MAX(red, green);
1593 vmax =
MAX(vmax, blue);
1595 double vmin =
MIN(red, green);
1596 vmin =
MIN(vmin, blue);
1598 hue = (vmax + vmin) / 2.;
1599 saturation = (vmax + vmin) / 2.;
1600 light = (vmax + vmin) / 2.;
1609 double diff = vmax - vmin;
1611 saturation = light > 0.5 ? diff / (2. - vmax - vmin) : diff / (vmax + vmin);
1615 hue = (green - blue) / diff + (green < blue ? 6. : 0.);
1617 else if (vmax == green)
1619 hue = (blue - red) / diff + 2.;
1621 else if (vmax == blue)
1623 hue = (red - green) / diff + 4.;
1629 hBand.
setValue(outCol, outRow, hue);
1630 lBand.
setValue(outCol, outRow, light);
1631 sBand.
setValue(outCol, outRow, saturation);
1639 const te::rst::Raster& inputGreenRaster,
const unsigned int greenBandIdx,
1640 const te::rst::Raster& inputBlueRaster,
const unsigned int blueBandIdx,
1641 const double ,
const double rgbRangeMax,
te::rst::Raster& outputHLSRaster)
1672 unsigned int outRow = 0;
1673 unsigned int outCol = 0;
1679 double saturation = 0;
1681 for (outRow = 0; outRow < outNRows; ++outRow)
1683 for (outCol = 0; outCol < outNCols; ++outCol)
1685 redBand.
getValue(outCol, outRow, red);
1686 greenBand.
getValue(outCol, outRow, green);
1687 blueBand.
getValue(outCol, outRow, blue);
1690 green /= rgbRangeMax;
1691 blue /= rgbRangeMax;
1693 double vmax =
MAX(red, green);
1694 vmax =
MAX(vmax, blue);
1696 double vmin =
MIN(red, green);
1697 vmin =
MIN(vmin, blue);
1699 hue = (vmax + vmin) / 2.;
1700 saturation = (vmax + vmin) / 2.;
1701 light = (vmax + vmin) / 2.;
1710 double diff = vmax - vmin;
1712 saturation = light > 0.5 ? diff / (2. - vmax - vmin) : diff / (vmax + vmin);
1716 hue = (green - blue) / diff + (green < blue ? 6. : 0.);
1718 else if (vmax == green)
1720 hue = (blue - red) / diff + 2.;
1722 else if (vmax == blue)
1724 hue = (red - green) / diff + 4.;
1730 hBand.
setValue(outCol, outRow, hue);
1731 lBand.
setValue(outCol, outRow, light);
1732 sBand.
setValue(outCol, outRow, saturation);
1740 const unsigned int hueBandIdx,
const unsigned int lightBandIdx,
1741 const unsigned int saturationBandIdx,
const double ,
1775 unsigned int row = 0;
1776 unsigned int col = 0;
1779 double saturation = 0;
1781 for (row = 0; row < nRows; ++row)
1786 lightBand.
getValue(col, row, light);
1787 saturationBand.
getValue(col, row, saturation);
1789 if ((hue == hueNoData) || (light == lightNoData) ||
1790 (saturation == saturationNoData))
1792 redBand.
setValue(col, row, rNoData);
1793 greenBand.
setValue(col, row, gNoData);
1794 blueBand.
setValue(col, row, bNoData);
1798 std::vector< double > rgb;
1801 if (saturation == 0)
1803 rgb.push_back(light * rgbRangeMax);
1804 rgb.push_back(light * rgbRangeMax);
1805 rgb.push_back(light * rgbRangeMax);
1809 for (
unsigned int i = 0; i < 3; ++i)
1811 double q = light < 0.5 ? light * (1. + saturation) : light + saturation - light * saturation;
1812 double p = 2. * light - q;
1846 p = (p + (q -
p) * 6. * t);
1848 else if (t < (1. / 2.))
1852 else if (t < (2. / 3.))
1854 p = (p + (q -
p) * (2. / 3. - t) * 6.);
1861 redBand.
setValue(col, row, rgb[0]);
1862 greenBand.
setValue(col, row, rgb[1]);
1863 blueBand.
setValue(col, row, rgb[2]);
1873 const te::rst::Raster& inputSRaster,
const unsigned int saturationBandIdx,
1874 const double ,
const double rgbRangeMax,
te::rst::Raster& outputRGBRaster)
1915 unsigned int row = 0;
1916 unsigned int col = 0;
1919 double saturation = 0;
1921 for (row = 0; row < nRows; ++row)
1926 lightBand.
getValue(col, row, light);
1927 saturationBand.
getValue(col, row, saturation);
1929 if ((hue == hueNoData) || (light == lightNoData) ||
1930 (saturation == saturationNoData))
1932 redBand.
setValue(col, row, rNoData);
1933 greenBand.
setValue(col, row, gNoData);
1934 blueBand.
setValue(col, row, bNoData);
1938 std::vector< double > rgb;
1941 if (saturation == 0)
1943 rgb.push_back(light * rgbRangeMax);
1944 rgb.push_back(light * rgbRangeMax);
1945 rgb.push_back(light * rgbRangeMax);
1949 for (
unsigned int i = 0; i < 3; ++i)
1951 double q = light < 0.5 ? light * (1. + saturation) : light + saturation - light * saturation;
1952 double p = 2. * light - q;
1986 p = (p + (q -
p) * 6. * t);
1988 else if (t < (1. / 2.))
1992 else if (t < (2. / 3.))
1994 p = (p + (q -
p) * (2. / 3. - t) * 6.);
2001 redBand.
setValue(col, row, rgb[0]);
2002 greenBand.
setValue(col, row, rgb[1]);
2003 blueBand.
setValue(col, row, rgb[2]);
2021 boost::scoped_array< unsigned char > blockBuffer(
new unsigned char[ blockSizeBytes ] );
2022 boost::scoped_array< double > doubleBuffer(
new double[ blockElementsNumber ] );
2024 unsigned int elementIdx = 0;
2026 double meanElementsNumber = 0;
2044 paramsPtr->
m_inputBandPtr->
read( static_cast<int>(blkX), static_cast<int>(blkY), blockBuffer.get() );
2049 doubleBuffer.get() );
2051 for( elementIdx = 0 ; elementIdx < blockElementsNumber ; ++elementIdx )
2053 if( noDataValue != doubleBuffer[ elementIdx ] )
2063 doubleBuffer[ elementIdx ]
2072 meanElementsNumber = meanElementsNumber + 1.0;
2105 const unsigned int maxThreads,
2114 for(
unsigned int row = 0 ; row < rasterBlocksStatus.
getLinesNumber() ;
2120 rasterBlocksStatus( row,
col ) =
false;
2126 double pixelsNumber = 0.0;
2138 if( maxThreads == 1 )
2146 boost::thread_group threads;
2148 for(
unsigned int threadIdx = 0 ; threadIdx < threadsNumber ;
2172 boost::scoped_array< unsigned char > blockBuffer(
new unsigned char[ blockSizeBytes ] );
2173 boost::scoped_array< double > doubleBuffer(
new double[ blockElementsNumber ] );
2175 unsigned int elementIdx = 0;
2177 double squaresDifsSum = 0;
2178 double elementsNumber = 0;
2197 paramsPtr->
m_inputBandPtr->
read( static_cast<int>(blkX), static_cast<int>(blkY), blockBuffer.get() );
2202 doubleBuffer.get() );
2204 for( elementIdx = 0 ; elementIdx < blockElementsNumber ; ++elementIdx )
2206 if( noDataValue != doubleBuffer[ elementIdx ] )
2208 diff = doubleBuffer[ elementIdx ] - meanValue;
2210 squaresDifsSum += diff;
2211 elementsNumber = elementsNumber + 1.0;
2230 const unsigned int maxThreads,
double const *
const meanValuePtr,
2231 double& stdDevValue )
2236 mean = (*meanValuePtr);
2252 for(
unsigned int row = 0 ; row < rasterBlocksStatus.
getLinesNumber() ;
2258 rasterBlocksStatus( row,
col ) =
false;
2264 double pixelsNumber = 0.0;
2277 if( maxThreads == 1 )
2285 boost::thread_group threads;
2287 for(
unsigned int threadIdx = 0 ; threadIdx < threadsNumber ;
2297 stdDevValue = std::sqrt( stdDevValue / pixelsNumber );
2315 boost::scoped_array< unsigned char > blockBuffer1(
new unsigned char[ blockSizeBytes1 ] );
2316 boost::scoped_array< unsigned char > blockBuffer2(
new unsigned char[ blockSizeBytes2 ] );
2317 boost::scoped_array< double > doubleBuffer1(
new double[ blockElementsNumber ] );
2318 boost::scoped_array< double > doubleBuffer2(
new double[ blockElementsNumber ] );
2320 unsigned int elementIdx = 0;
2321 double covariance = 0;
2322 double elementsNumber = 0;
2342 paramsPtr->
m_inputBand1Ptr->
read( static_cast<int>(blkX), static_cast<int>(blkY), blockBuffer1.get() );
2343 paramsPtr->
m_inputBand2Ptr->
read( static_cast<int>(blkX), static_cast<int>(blkY), blockBuffer2.get() );
2348 doubleBuffer1.get() );
2350 doubleBuffer2.get() );
2352 for( elementIdx = 0 ; elementIdx < blockElementsNumber ; ++elementIdx )
2354 if( ( noDataValue1 != doubleBuffer1[ elementIdx ] ) &&
2355 ( noDataValue2 != doubleBuffer2[ elementIdx ] ) )
2357 diff1 = doubleBuffer1[ elementIdx ] - paramsPtr->
m_mean1Value;
2358 diff2 = doubleBuffer2[ elementIdx ] - paramsPtr->
m_mean2Value;
2360 covariance += ( diff1 * diff2 );
2362 elementsNumber = elementsNumber + 1.0;
2377 double const *
const mean1ValuePtr,
double const *
const mean2ValuePtr,
2378 double& covarianceValue )
2395 mean1 = (*mean1ValuePtr);
2408 mean2 = (*mean2ValuePtr);
2429 for(
unsigned int row = 0 ; row < rasterBlocksStatus.
getLinesNumber() ;
2435 rasterBlocksStatus( row,
col ) =
false;
2439 covarianceValue = 0.0;
2441 double pixelsNumber = 0.0;
2456 if( maxThreads == 1 )
2464 boost::thread_group threads;
2466 for(
unsigned int threadIdx = 0 ; threadIdx < threadsNumber ;
2476 if( pixelsNumber != 0.0 )
2478 covarianceValue /= pixelsNumber;
2491 unsigned int col = 0;
2492 double pixelsNumber = 0.0;
2494 covarianceValue = 0;
2496 for(
unsigned int row = 0 ; row < nRows ; ++row )
2498 for( col = 0 ; col <
nCols ; ++
col )
2500 band1.
getValue( col, row, value1 );
2501 band2.
getValue( col, row, value2 );
2503 if( ( noDataValue1 != value1 ) &&
2504 ( noDataValue2 != value2 ) )
2506 covarianceValue += ( ( value1 - mean1 ) * ( value2 - mean2 ) );
2508 pixelsNumber = pixelsNumber + 1.0;
2513 if( pixelsNumber != 0.0 )
2515 covarianceValue /= pixelsNumber;
2524 const std::vector< unsigned int >& inputRasterBands,
2525 boost::numeric::ublas::matrix< double >& pcaMatrix,
2527 const std::vector< unsigned int >& pcaRasterBands,
2528 const unsigned int maxThreads )
2557 boost::numeric::ublas::matrix< double > covarianceMatrix;
2559 covarianceMatrix.resize( inputRasterBands.size(), inputRasterBands.size() );
2561 for(
unsigned int covMatrixIdx1 = 0 ; covMatrixIdx1 < inputRasterBands.size() ;
2569 for(
unsigned int covMatrixIdx2 = 0 ; covMatrixIdx2 < inputRasterBands.size() ;
2577 if( covMatrixIdx1 > covMatrixIdx2 )
2579 covarianceMatrix( covMatrixIdx1, covMatrixIdx2 ) =
2580 covarianceMatrix( covMatrixIdx2, covMatrixIdx1 );
2585 *( inputRaster.
getBand( inputRasterBands[ covMatrixIdx2 ] ) ),
2586 maxThreads,
nullptr,
nullptr, covarianceMatrix( covMatrixIdx1, covMatrixIdx2 ) ) )
2598 boost::numeric::ublas::matrix< double > eigenValues;
2599 boost::numeric::ublas::matrix< double > eigenVectors;
2606 pcaMatrix = boost::numeric::ublas::trans( eigenVectors );
2608 return RemapValues( inputRaster, inputRasterBands, pcaMatrix, pcaRaster,
2609 pcaRasterBands, maxThreads );
2614 const boost::numeric::ublas::matrix< double >& pcaMatrix,
2616 const std::vector< unsigned int >& outputRasterBands,
2617 const unsigned int maxThreads )
2619 boost::numeric::ublas::matrix< double > inversePcaMatrix;
2625 std::vector< unsigned int > inputRasterBands;
2630 inputRasterBands.push_back( bandIdx );
2633 return RemapValues( pcaRaster, inputRasterBands, inversePcaMatrix,
2634 outputRaster, outputRasterBands, maxThreads );
2648 const unsigned int inputRasterBandsSize =
static_cast<unsigned int>(inputRasterBands.size());
2651 assert( inputRasterBandsSize == outputRasterBands.size() );
2653 unsigned int maxBlocksSizesBytes = 0;
2654 std::vector< double > inputBandsNoDataValues( inputRasterBandsSize, 0.0 );
2655 std::vector< double > outputBandsNoDataValues( inputRasterBandsSize, 0.0 );
2656 std::vector< boost::shared_array< double > > inDoubleBuffersHandlers( inputRasterBandsSize );
2657 std::vector< boost::shared_array< double > > outDoubleBuffersHandlers( inputRasterBandsSize );
2658 unsigned int inputRasterBandsIdx = 0;
2659 boost::numeric::ublas::matrix< double > remapMatrix = *( paramsPtr->
m_remapMatrixPtr );
2660 std::vector< double > outputMinValue( inputRasterBandsSize );
2661 std::vector< double > outputMaxValue( inputRasterBandsSize );
2662 boost::shared_array< double* > inDoubleBuffersPtrsHandler(
new double*[ inputRasterBandsSize ] );
2663 boost::shared_array< double* > outDoubleBuffersPtrsHandler(
new double*[ inputRasterBandsSize ] );
2664 double** inDoubleBuffers = inDoubleBuffersPtrsHandler.get();
2665 double** outDoubleBuffers = outDoubleBuffersPtrsHandler.get();
2667 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
2668 ++inputRasterBandsIdx )
2670 const unsigned int& inBandIdx = inputRasterBands[ inputRasterBandsIdx ];
2671 assert( inBandIdx < paramsPtr->m_inputRasterPtr->getNumberOfBands() );
2675 outputRasterBands[ inputRasterBandsIdx ] );
2677 maxBlocksSizesBytes = std::max( maxBlocksSizesBytes, static_cast<unsigned int>(inBandPtr->getBlockSize()) );
2678 maxBlocksSizesBytes = std::max( maxBlocksSizesBytes, static_cast<unsigned int>(outBandPtr->
getBlockSize()) );
2680 inputBandsNoDataValues[ inputRasterBandsIdx ] = inBandPtr->getProperty()->m_noDataValue;
2683 inDoubleBuffersHandlers[ inputRasterBandsIdx ].reset(
new double[ blockElementsNumber ] );
2684 inDoubleBuffers[ inputRasterBandsIdx ] = inDoubleBuffersHandlers[ inputRasterBandsIdx ].get();
2686 outDoubleBuffersHandlers[ inputRasterBandsIdx ].reset(
new double[ blockElementsNumber ] );
2687 outDoubleBuffers[ inputRasterBandsIdx ] = outDoubleBuffersHandlers[ inputRasterBandsIdx ].get();
2691 outputMinValue[ inputRasterBandsIdx ],
2692 outputMaxValue[ inputRasterBandsIdx ] );
2697 boost::scoped_array< unsigned char > blockBuffer(
new unsigned char[ maxBlocksSizesBytes ] );
2699 unsigned int elementIdx = 0;
2700 boost::numeric::ublas::matrix< double > pixelValues( inputRasterBandsSize, 1 );
2701 boost::numeric::ublas::matrix< double > remappedPixelValues( inputRasterBandsSize, 1 );
2702 bool elementIsValid =
false;
2722 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
2723 ++inputRasterBandsIdx )
2725 const unsigned int& inBandIdx = inputRasterBands[ inputRasterBandsIdx ];
2728 inBandPtr->
read( static_cast<int>(blkX), static_cast<int>(blkY), blockBuffer.get() );
2731 blockElementsNumber,
2732 inDoubleBuffers[ inputRasterBandsIdx ] );
2739 for( elementIdx = 0 ; elementIdx < blockElementsNumber ; ++elementIdx )
2741 elementIsValid =
true;
2743 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
2744 ++inputRasterBandsIdx )
2746 if( inDoubleBuffers[ inputRasterBandsIdx ][ elementIdx ] ==
2747 inputBandsNoDataValues[ inputRasterBandsIdx ] )
2749 elementIsValid =
false;
2754 pixelValues( inputRasterBandsIdx, 0 ) =
2755 inDoubleBuffers[ inputRasterBandsIdx ][ elementIdx ];
2759 if( elementIsValid )
2763 remappedPixelValues = boost::numeric::ublas::prod( remapMatrix, pixelValues );
2767 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
2768 ++inputRasterBandsIdx )
2770 outDoubleBuffers[ inputRasterBandsIdx ][ elementIdx ] =
2772 outputMinValue[ inputRasterBandsIdx ],
2774 outputMaxValue[ inputRasterBandsIdx ],
2775 remappedPixelValues( inputRasterBandsIdx, 0 )
2782 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
2783 ++inputRasterBandsIdx )
2785 outDoubleBuffers[ inputRasterBandsIdx ][ elementIdx ] =
2786 outputBandsNoDataValues[ inputRasterBandsIdx ] ;
2795 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
2796 ++inputRasterBandsIdx )
2799 outputRasterBands[ inputRasterBandsIdx ] );
2803 blockBuffer.get() );
2805 outBandPtr->
write( static_cast<int>(blkX), static_cast<int>(blkY), blockBuffer.get() );
2817 const std::vector< unsigned int >& inputRasterBands,
2818 const boost::numeric::ublas::matrix< double >& remapMatrix,
2820 const std::vector< unsigned int >& outputRasterBands,
2821 const unsigned int maxThreads )
2831 if( remapMatrix.size1() != inputRasterBands.size() )
2835 if( remapMatrix.size2() != inputRasterBands.size() )
2851 if( remapMatrix.size1() != outputRasterBands.size() )
2855 if( remapMatrix.size2() != outputRasterBands.size() )
2859 for(
unsigned int inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBands.size() ;
2860 ++inputRasterBandsIdx )
2862 if( inputRasterBands[ inputRasterBandsIdx ] >= inputRaster.
getNumberOfBands() )
2867 for(
unsigned int outputRasterBandsIdx = 0 ; outputRasterBandsIdx < outputRasterBands.size() ;
2868 ++outputRasterBandsIdx )
2870 if( outputRasterBands[ outputRasterBandsIdx ] >= outputRaster.
getNumberOfBands() )
2878 bool useOptimizedRemap =
true;
2881 for(
unsigned int inputRasterBandsIdx = 0 ; inputRasterBandsIdx <
2934 useOptimizedRemap =
false;
2942 if( useOptimizedRemap )
2945 if( ! rasterBlocksStatus.
reset(
2952 for(
unsigned int row = 0 ; row < rasterBlocksStatus.
getLinesNumber() ;
2958 rasterBlocksStatus( row,
col ) =
false;
2974 if( maxThreads == 1 )
2982 boost::thread_group threads;
2984 for(
unsigned int threadIdx = 0 ; threadIdx < threadsNumber ;
2998 const unsigned int inputRasterBandsSize =
static_cast<unsigned int>(inputRasterBands.size());
3001 boost::numeric::ublas::matrix< double > pixelValues( inputRasterBands.size(), 1 );
3002 boost::numeric::ublas::matrix< double > remappedPixelValues( inputRasterBands.size(), 1 );
3003 std::vector< double > inputNoDataValues( inputRasterBandsSize );
3004 std::vector< double > outputNoDataValues( inputRasterBandsSize );
3005 std::vector< double > outputMinValue( inputRasterBandsSize );
3006 std::vector< double > outputMaxValue( inputRasterBandsSize );
3007 unsigned int inputRasterBandsIdx = 0;
3008 unsigned int row = 0;
3009 unsigned int col = 0;
3010 bool pixelIsValid =
false;
3012 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
3013 ++inputRasterBandsIdx )
3015 if( inputRasterBands[ inputRasterBandsIdx ] >= inputRaster.
getNumberOfBands() )
3020 inputNoDataValues[ inputRasterBandsIdx ] = inputRaster.
getBand(
3023 outputNoDataValues[ inputRasterBandsIdx ] = outputRaster.
getBand(
3028 outputMinValue[ inputRasterBandsIdx ],
3029 outputMaxValue[ inputRasterBandsIdx ] );
3032 for( row = 0 ; row < nRows ; ++row )
3034 for( col = 0 ; col <
nCols ; ++
col )
3036 pixelIsValid =
true;
3038 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
3039 ++inputRasterBandsIdx )
3041 inputRaster.
getValue( col, row, pixelValues( inputRasterBandsIdx, 0 ),
3042 inputRasterBands[ inputRasterBandsIdx ] );
3044 if( pixelValues( inputRasterBandsIdx, 0 ) == inputNoDataValues[ inputRasterBandsIdx ] )
3046 pixelIsValid =
false;
3053 remappedPixelValues = boost::numeric::ublas::prod( remapMatrix, pixelValues );
3055 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
3056 ++inputRasterBandsIdx )
3062 outputMinValue[ inputRasterBandsIdx ]
3065 outputMaxValue[ inputRasterBandsIdx ]
3067 remappedPixelValues( inputRasterBandsIdx, 0 )
3070 outputRasterBands[ inputRasterBandsIdx ] );
3075 for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBandsSize ;
3076 ++inputRasterBandsIdx )
3078 outputRaster.
setValue( col, row, outputNoDataValues[ inputRasterBandsIdx ],
3079 outputRasterBands[ inputRasterBandsIdx ] );
3091 const std::vector< unsigned int >& inputRasterBands,
3092 const std::vector< std::map<std::string, std::string> > & outputRastersInfos,
3093 const std::string& outputDataSourceType,
3094 std::vector< boost::shared_ptr< te::rst::Raster > > & outputRastersPtrs )
3096 outputRastersPtrs.clear();
3102 if( outputRastersInfos.size() != inputRasterBands.size() )
3106 if( outputDataSourceType.empty() )
3111 outputRastersPtrs.resize( inputRasterBands.size() );
3116 for(
unsigned int inputRasterBandsIdx = 0 ; inputRasterBandsIdx <
3117 inputRasterBands.size() ; ++inputRasterBandsIdx )
3119 const unsigned int bandIdx = inputRasterBands[ inputRasterBandsIdx ];
3125 std::vector< te::rst::BandProperty* > bandsProperties;
3130 outputRastersPtrs[ inputRasterBandsIdx].reset(
3133 outputRastersInfos[ inputRasterBandsIdx ],
nullptr,
nullptr ) );
3134 if( outputRastersPtrs[ inputRasterBandsIdx].
get() == nullptr )
return false;
3136 unsigned int col = 0;
3137 unsigned int row = 0;
3140 te::rst::Band& outBand = *(outputRastersPtrs[ inputRasterBandsIdx]->getBand( 0 ));
3142 for( row = 0 ; row < nRows ; ++row )
3144 for( col = 0 ; col <
nCols ; ++
col )
3146 inBand.
getValue( col, row, value );
3147 outBand.
setValue( col, row, value );
3157 const std::vector< unsigned int >& inputRasterBands,
3159 const std::map<std::string, std::string>& outputRasterInfo,
3160 const std::string& outputDataSourceType,
3161 std::unique_ptr< te::rst::Raster >& outputRasterPtr )
3163 outputRasterPtr.reset();
3169 if( outputDataSourceType.empty() )
3178 std::unique_ptr< te::rst::Grid > outputGridPtr;
3179 std::vector< te::rst::BandProperty* > bandsProperties;
3196 *( inputRasterPtr->
getBand( inputRasterBands[
3203 outputGridPtr.release(), bandsProperties, outputRasterInfo,
nullptr, nullptr ) );
3204 if( outputRasterPtr.get() == nullptr )
return false;
3215 const unsigned int inBandIdx = inputRasterBands[
3218 unsigned int outRow = 0;
3219 unsigned int outCol = 0;
3220 const unsigned int nOutRows = outputRasterPtr->getNumberOfRows();
3221 const unsigned int nOutCols = outputRasterPtr->getNumberOfColumns();
3226 double xOutCoord = 0;
3227 double yOutCoord = 0;
3228 double xInCoord = 0;
3229 double yInCoord = 0;
3232 std::complex< double > value = 0;
3236 if( inputRasterPtr->
getSRID() == outputRasterPtr->getSRID() )
3238 for( outRow = 0 ; outRow < nOutRows ; ++outRow )
3240 for( outCol = 0 ; outCol < nOutCols ; ++outCol )
3242 outGrid.
gridToGeo( (
double)outCol, (
double)outRow, xOutCoord, yOutCoord );
3243 inGrid.
geoToGrid( xOutCoord, yOutCoord, inCol, inRow );
3244 interp.
getValue( inCol, inRow, value, inBandIdx );
3245 outBand.
setValue( outCol, outRow, value );
3251 for( outRow = 0 ; outRow < nOutRows ; ++outRow )
3253 for( outCol = 0 ; outCol < nOutCols ; ++outCol )
3255 outGrid.
gridToGeo( (
double)outCol, (
double)outRow, xOutCoord, yOutCoord );
3256 conv.convert( xOutCoord, yOutCoord, xInCoord, yInCoord );
3257 inGrid.
geoToGrid( xInCoord, yInCoord, inCol, inRow );
3258 interp.
getValue( inCol, inRow, value, inBandIdx );
3259 outBand.
setValue( outCol, outRow, value );
3275 if( ( nCols == 0 ) || ( nRows == 0 ) )
3280 const unsigned int ringSize = ( 2 * ( nCols + 1 ) ) +
3281 ( 2 * ( nRows - 1 ) ) + 1;
3292 unsigned int ringIdx = 0;
3293 unsigned int row = 0;
3294 unsigned int col = 0;
3296 ring.setPoint( 0, lLX, uRY );
3298 for( col = 1 ; col <=
nCols ; ++
col )
3300 ring.setPoint( ++ringIdx, lLX + ( (static_cast<double>( col ) ) * resX ), uRY );
3303 for( row = 1 ; row <= nRows ; ++row )
3305 ring.setPoint( ++ringIdx, uRX, uRY - ( (static_cast<double>( row ) ) * resY ) );
3308 for( col = 1 ; col <=
nCols ; ++
col )
3310 ring.setPoint( ++ringIdx, uRX - ( (static_cast<double>( col ) ) * resX ), lLY );
3313 for( row = 1 ; row <= nRows ; ++row )
3315 ring.setPoint( ++ringIdx, lLX, lLY + ( (static_cast<double>( row ) ) * resY ) );
3319 ring.setPoint( ringSize - 1, lLX, uRY );
3321 detailedExtent = ring;
3331 if( ( nCols == 0 ) || ( nRows == 0 ) )
3336 const unsigned int ringSize = ( 2 * ( nCols + 1 ) ) +
3337 ( 2 * ( nRows - 1 ) ) + 1;
3342 const double lLY = (
static_cast<double>(nRows)) - 0.5;
3343 const double uRX = (
static_cast<double>(
nCols)) - 0.5;
3344 unsigned int ringIdx = 0;
3345 unsigned int row = 0;
3346 unsigned int col = 0;
3350 for( col = 0 ; col <
nCols ; ++
col )
3352 ring.
setPoint( ++ringIdx, 0.5 + (static_cast<double>(col)), (-0.5) );
3355 for( row = 0 ; row < nRows ; ++row )
3357 ring.
setPoint( ++ringIdx, uRX, 0.5 + (static_cast<double>(row)) );
3360 for( col = 1; col <=
nCols ; ++
col )
3362 ring.
setPoint( ++ringIdx, uRX - (static_cast<double>(col)), lLY );
3365 for( row = 1 ; row <= nRows ; ++row )
3367 ring.
setPoint( ++ringIdx, (-0.5), lLY - (static_cast<double>(row)) );
3371 ring.
setPoint( ringSize - 1, -0.5, -0.5 );
3373 indexedDetailedExtent = ring;
3381 boost::numeric::ublas::matrix< double > emptyFilter;
3383 switch( filterType )
3387 boost::numeric::ublas::matrix< double > internalFilter( 5, 5 );
3388 const double weight = 256;
3390 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;
3391 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;
3392 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;
3393 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;
3394 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;
3396 return internalFilter;
3400 boost::numeric::ublas::matrix< double > internalFilter( 3, 3 );
3401 const double weight = 16;
3403 internalFilter(0,0) = 1/weight; internalFilter(0,1) = 2/weight; internalFilter(0,2) = 1/weight;
3404 internalFilter(1,0) = 2/weight; internalFilter(1,1) = 4/weight; internalFilter(1,2) = 2/weight;
3405 internalFilter(2,0) = 1/weight; internalFilter(2,1) = 2/weight; internalFilter(2,2) = 1/weight;
3407 return internalFilter;
3411 throw te::rp::Exception(
"Invalid filter type" );
3420 const std::vector< unsigned int >& inputRasterBands,
3422 const unsigned int levelsNumber,
3423 const boost::numeric::ublas::matrix< double >& filter )
3429 for(
unsigned int inputRasterBandsIdx = 0 ; inputRasterBandsIdx <
3430 inputRasterBands.size() ; ++inputRasterBandsIdx )
3432 if( inputRasterBands[ inputRasterBandsIdx ] >= inputRaster.
getNumberOfBands() )
3444 ( waveletRaster.
getNumberOfBands() < ( 2 * levelsNumber * inputRasterBands.size() ) )
3449 if( levelsNumber == 0 )
3453 if( ( filter.size1() == 0 ) || ( filter.size2() == 0 ) ||
3454 ( filter.size1() != filter.size2() )
3463 const int filterWidth =
static_cast<int>(filter.size1());
3464 const int offset = filterWidth / 2;
3468 for(
unsigned int inputRasterBandsIdx = 0 ; inputRasterBandsIdx < inputRasterBands.size() ;
3469 ++inputRasterBandsIdx )
3471 for(
unsigned int levelIndex = 0; levelIndex < levelsNumber; ++levelIndex)
3473 const unsigned int currentSmoothBandIdx = ( 2 * levelsNumber *
3474 inputRasterBandsIdx ) + ( 2 * levelIndex );
3477 const unsigned int currentWaveletBandIdx = currentSmoothBandIdx + 1;
3479 currentWaveletBandIdx );
3481 const unsigned int prevSmoothBandIdx = currentSmoothBandIdx - 2;
3483 if( levelIndex == 0 )
3485 prevSmoothBandPtr = inputRaster.
getBand( inputRasterBands[ inputRasterBandsIdx ] );
3489 prevSmoothBandPtr = waveletRaster.
getBand( prevSmoothBandIdx );
3493 const int filterScale =
static_cast<int>(std::pow(2.0, static_cast<double>(levelIndex)));
3497 int convolutionCenterCol = 0;
3498 int convolutionCenterRow = 0;
3501 double valueOriginal = 0.0;
3502 double valueNew = 0.0;
3504 for (convolutionCenterRow = 0; convolutionCenterRow <
nLines; convolutionCenterRow++)
3506 for (convolutionCenterCol = 0; convolutionCenterCol <
nCols; convolutionCenterCol++)
3510 for (filterRow = 0; filterRow < filterWidth; filterRow++)
3512 for (filterCol = 0; filterCol < filterWidth; filterCol++)
3514 col = convolutionCenterCol+(filterCol-offset)*filterScale;
3515 row = convolutionCenterRow+(filterRow-offset)*filterScale;
3519 else if (col >= nCols)
3523 else if (row >= nLines)
3526 prevSmoothBand.
getValue( static_cast<unsigned int>(col), static_cast<unsigned int>(row), valueOriginal );
3528 valueNew += valueOriginal * filter( static_cast<size_t>(filterRow), static_cast<size_t>(filterCol) );
3532 currentSmoothBand.
setValue( static_cast<unsigned int>(convolutionCenterCol), static_cast<unsigned int>(convolutionCenterRow),
3534 prevSmoothBand.
getValue( static_cast<unsigned int>(convolutionCenterCol), static_cast<unsigned int>(convolutionCenterRow),
3536 currentWaveletBand.
setValue( static_cast<unsigned int>(convolutionCenterCol), static_cast<unsigned int>(convolutionCenterRow),
3537 valueOriginal - valueNew );
3548 const unsigned int levelsNumber,
3550 const std::vector< unsigned int >& outputRasterBands )
3555 ( waveletRaster.
getNumberOfBands() < ( 2 * levelsNumber * outputRasterBands.size() ) )
3560 if( levelsNumber == 0 )
3574 for(
unsigned int outputRasterBandsIdx = 0 ; outputRasterBandsIdx <
3575 outputRasterBands.size() ; ++outputRasterBandsIdx )
3577 if( outputRasterBands[ outputRasterBandsIdx ] >= outputRaster.
getNumberOfBands() )
3583 for(
unsigned int outputRasterBandsIdx = 0 ; outputRasterBandsIdx <
3584 outputRasterBands.size() ; ++outputRasterBandsIdx )
3586 const unsigned int outputRasterBandIdx = outputRasterBands[ outputRasterBandsIdx ];
3589 const unsigned int firstSmoothBandIdx = outputRasterBandsIdx *
3591 const unsigned int firstWaveletBandIdx = firstSmoothBandIdx
3593 const unsigned int lastSmoothBandIdx = firstSmoothBandIdx
3594 + ( 2 * levelsNumber ) - 2;
3595 const unsigned int lastWaveletBandIdx = lastSmoothBandIdx + 1;
3596 unsigned int col = 0;
3597 unsigned int row = 0;
3600 unsigned int waveletRasterBand = 0;
3602 double bandAllowedMinValue = 0;
3603 double bandAllowedMaxValue = 0;
3606 bandAllowedMaxValue );
3609 for( row = 0 ; row < nRows ; ++row )
3611 for( col = 0 ; col <
nCols ; ++
col )
3615 for( waveletRasterBand = firstWaveletBandIdx ;
3616 waveletRasterBand <= lastWaveletBandIdx ;
3617 waveletRasterBand += 2)
3619 waveletRaster.
getValue( col, row, value, waveletRasterBand );
3623 waveletRaster.
getValue( col, row, value, lastSmoothBandIdx );
3626 sum = std::max( sum, bandAllowedMinValue );
3627 sum = std::min( sum, bandAllowedMaxValue );
3629 outputRaster.
setValue( col, row, sum, outputRasterBandIdx );
3639 const std::vector< unsigned int >& inputRasterBands,
3641 const unsigned int firstRow,
3642 const unsigned int firstColumn,
3643 const unsigned int height,
3644 const unsigned int width,
3645 const unsigned int newheight,
3646 const unsigned int newwidth,
3647 const std::map<std::string, std::string>& rinfo,
3648 const std::string& dataSourceType,
3649 std::unique_ptr< te::rst::Raster >& resampledRasterPtr )
3659 for (std::size_t inputRasterBandsIdx = 0; inputRasterBandsIdx <
3660 inputRasterBands.size(); inputRasterBandsIdx++)
3662 if( inputRasterBands[ inputRasterBandsIdx ] >= inputRaster.
getNumberOfBands() )
3669 - 0.5, (static_cast<double>(firstRow)) - 0.5);
3671 + width)) - 0.5, (static_cast<double>(firstRow + height)) - 0.5);
3674 ulc.
x, lrc.
y, lrc.
x, ulc.
y ) );
3678 std::unique_ptr< te::rst::Grid > gridPtr(
new te::rst::Grid(
3679 newwidth, newheight, newEnvelopePtr.release(),
3682 std::vector<te::rst::BandProperty*>
bands;
3684 for (std::size_t inputRasterBandsIdx = 0; inputRasterBandsIdx <
3685 inputRasterBands.size(); inputRasterBandsIdx++)
3689 bands[ inputRasterBandsIdx ]->m_blkh = 1;
3690 bands[ inputRasterBandsIdx ]->m_blkw =
static_cast<int>(newwidth);
3691 bands[ inputRasterBandsIdx ]->m_nblocksx = 1;
3692 bands[ inputRasterBandsIdx ]->m_nblocksy =
static_cast<int>(newheight);
3696 gridPtr.release(),
bands, rinfo, nullptr ) );
3697 if( resampledRasterPtr.get() == nullptr )
3704 std::complex<double> interpValue;
3706 const double rowsFactor = (
static_cast<double>(height-1)) / (
static_cast<double>(newheight-1));
3707 const double colsFactor = (
static_cast<double>(width-1)) / (
static_cast<double>(newwidth-1));
3708 double inputRow = 0;
3709 double inputCol = 0;
3710 unsigned int outputCol = 0;
3711 unsigned int outputRow = 0;
3712 unsigned int inputBandIdx = 0;
3713 double allowedMin = 0;
3714 double allowedMax = 0;
3716 for (std::size_t inputRasterBandsIdx = 0; inputRasterBandsIdx <
3717 inputRasterBands.size(); inputRasterBandsIdx++)
3719 te::rst::Band& outputBand = *resampledRasterPtr->getBand( inputRasterBandsIdx );
3720 inputBandIdx = inputRasterBands[ inputRasterBandsIdx ];
3724 for ( outputRow = 0; outputRow < newheight; ++outputRow)
3726 inputRow = ( (
static_cast<double>( outputRow ) ) * rowsFactor ) + (static_cast<double>(firstRow));
3728 for ( outputCol = 0; outputCol < newwidth; ++outputCol )
3730 inputCol = ( (
static_cast<double>( outputCol ) ) * colsFactor ) + (static_cast<double>(firstColumn));
3732 interp.
getValue(inputCol, inputRow, interpValue, inputBandIdx);
3734 interpValue.real( std::max( allowedMin, interpValue.real() ) );
3735 interpValue.real( std::min( allowedMax, interpValue.real() ) );
3737 outputBand.
setValue(outputCol, outputRow, interpValue);
3746 const unsigned int paletteSize,
const bool randomize,
3747 std::vector< te::rst::BandProperty::ColorEntry >& palette )
3749 palette.resize( paletteSize );
3750 if( paletteSize == 0 )
return;
3752 const short int step =
static_cast<short int>( 256.0 /
3753 std::cbrt( static_cast<double>(paletteSize) ) );
3754 short int green = 0;
3756 unsigned int paletteIdx = 0;
3758 for(
short int red = 0 ; red < 256 ; red += step )
3760 for( green = 0 ; green < 256 ; green += step )
3762 for( blue = 0 ; blue < 256 ; blue += step )
3764 if( paletteIdx >= paletteSize )
3771 palette[ paletteIdx ].c1 = red;
3772 palette[ paletteIdx ].c2 = green;
3773 palette[ paletteIdx ].c3 = blue;
3774 palette[ paletteIdx ].c4 = 255;
3783 std::random_shuffle( palette.begin(), palette.end() );
3789 const unsigned int inputRasterBand,
3790 const bool createPaletteRaster,
3791 const unsigned int slicesNumber,
3792 const bool eqHistogram,
3793 const std::map< std::string, std::string >& rasterInfo,
3794 const std::string& rasterType,
3795 const bool enableProgress,
3796 std::vector< te::rst::BandProperty::ColorEntry >
const *
const palettePtr,
3797 std::unique_ptr< te::rst::Raster >& outRasterPtr ,
3798 std::map< double, double > limits)
3801 "Invalid raster band index" );
3804 unsigned int internalInRasterBand = inputRasterBand;
3805 std::unique_ptr< te::rst::Raster > eqRasterPtr;
3815 contInputPars.m_inRasterPtr = &inputRaster;
3816 contInputPars.m_inRasterBands.push_back( inputRasterBand );
3817 contInputPars.m_hECMaxInput.push_back( max );
3818 contInputPars.m_enableProgress = enableProgress;
3822 "Contrast init error" );
3827 "Contrast exec error" );
3829 eqRasterPtr.reset( contOutPars.m_createdOutRasterPtr.release() );
3830 internalInRasterPtr = eqRasterPtr.get();
3831 internalInRasterBand = 0;
3834 std::vector< te::rst::BandProperty::ColorEntry >
const * internalPalettePtr =
3836 std::vector< te::rst::BandProperty::ColorEntry > internalPalette;
3837 if( palettePtr ==
nullptr )
3840 internalPalettePtr = &internalPalette;
3843 std::unique_ptr< te::common::TaskProgress > progressPtr;
3844 if( enableProgress )
3847 progressPtr->setMessage(
"Slicing" );
3848 progressPtr->setTotalSteps( static_cast<int>(2 * internalInRasterPtr->getNumberOfRows()) );
3851 if( createPaletteRaster )
3853 std::vector< te::rst::BandProperty* > bandsProperties;
3855 * internalInRasterPtr->getBand( internalInRasterBand )->getProperty() ) );
3858 bandsProperties[ 0 ]->m_palette = (*internalPalettePtr);
3859 bandsProperties[ 0 ]->m_noDataValue =
static_cast<double>(internalPalettePtr->size());
3860 if( internalPalettePtr->size() <= std::numeric_limits< unsigned char >::max() )
3864 else if( internalPalettePtr->size() <= std::numeric_limits< unsigned short int >::max() )
3868 else if( internalPalettePtr->size() <= std::numeric_limits< unsigned int >::max() )
3878 bandsProperties, rasterInfo, rasterType, outRasterPtr ),
3879 "Output raster creation error" );
3881 const te::rst::Band& inBand = (*internalInRasterPtr->getBand( internalInRasterBand ));
3883 const unsigned int nRows = internalInRasterPtr->getNumberOfRows();
3884 const unsigned int nCols = internalInRasterPtr->getNumberOfColumns();
3887 unsigned int col = 0;
3890 for(
unsigned int row = 0 ; row < nRows ; ++row )
3892 for( col = 0 ; col <
nCols ; ++
col )
3894 inBand.
getValue( col, row, value );
3896 if( value == inputNoDataValue )
3898 outBand.
setValue( col, row, outputNoDataValue );
3903 for (std::map<double, double>::iterator it = limits.begin(); it != limits.end(); ++it, ++index)
3905 if (value >= (*it).first && value < (*it).second)
3907 outBand.
setValue(col, row, (
double)index);
3911 if (index == limits.size())
3912 outBand.
setValue(col, row, outputNoDataValue);
3916 if( enableProgress )
3918 progressPtr->pulse();
3919 if( ! progressPtr->isActive() )
return false;
3925 short internalPaletteMaxValue = 0;
3926 for(
unsigned int internalPaletteIdx = 0 ; internalPaletteIdx <
3927 internalPalettePtr->size() ; ++internalPaletteIdx )
3929 if( internalPalettePtr->operator[]( internalPaletteIdx ).c1 >
3930 internalPaletteMaxValue )
3932 internalPaletteMaxValue = internalPalettePtr->operator[]( internalPaletteIdx ).c1;
3934 if( internalPalettePtr->operator[]( internalPaletteIdx ).c2 >
3935 internalPaletteMaxValue )
3937 internalPaletteMaxValue = internalPalettePtr->operator[]( internalPaletteIdx ).c2;
3939 if( internalPalettePtr->operator[]( internalPaletteIdx ).c3 >
3940 internalPaletteMaxValue )
3942 internalPaletteMaxValue = internalPalettePtr->operator[]( internalPaletteIdx ).c3;
3944 if( internalPalettePtr->operator[]( internalPaletteIdx ).c4 >
3945 internalPaletteMaxValue )
3947 internalPaletteMaxValue = internalPalettePtr->operator[]( internalPaletteIdx ).c4;
3951 int outDataType = 0;
3952 if( internalPaletteMaxValue < ( std::numeric_limits< unsigned char >::max() ) )
3956 else if( internalPaletteMaxValue < ( std::numeric_limits< unsigned short int >::max() ) )
3965 std::vector< te::rst::BandProperty* > bandsProperties;
3967 * internalInRasterPtr->getBand( internalInRasterBand )->getProperty() ) );
3969 * internalInRasterPtr->getBand( internalInRasterBand )->getProperty() ) );
3971 * internalInRasterPtr->getBand( internalInRasterBand )->getProperty() ) );
3975 bandsProperties[ 0 ]->m_type = outDataType;
3976 bandsProperties[ 1 ]->m_type = outDataType;
3977 bandsProperties[ 2 ]->m_type = outDataType;
3978 bandsProperties[ 0 ]->m_noDataValue = internalPaletteMaxValue + 1;
3979 bandsProperties[ 1 ]->m_noDataValue = internalPaletteMaxValue + 1;
3980 bandsProperties[ 2 ]->m_noDataValue = internalPaletteMaxValue + 1;
3983 bandsProperties, rasterInfo, rasterType, outRasterPtr ),
3984 "Output raster creation error" );
3986 const te::rst::Band& inBand = (*internalInRasterPtr->getBand( internalInRasterBand ));
3988 te::rst::Band& outBandGreen = (*outRasterPtr->getBand( 1 ));
3993 const unsigned int nRows = internalInRasterPtr->getNumberOfRows();
3994 const unsigned int nCols = internalInRasterPtr->getNumberOfColumns();
3996 unsigned int col = 0;
3999 for(
unsigned int row = 0 ; row < nRows ; ++row )
4001 for( col = 0 ; col <
nCols ; ++
col )
4003 inBand.
getValue( col, row, value );
4005 if( value == inputNoDataValue )
4007 outBandRed.
setValue( col, row, rBandNoDataValue );
4008 outBandGreen.
setValue( col, row, gBandNoDataValue );
4009 outBandBlue.
setValue( col, row, bBandNoDataValue );
4014 for (std::map<double, double>::iterator it = limits.begin(); it != limits.end(); ++it, ++index)
4016 if (value >= (*it).first && value < (*it).second)
4020 if (index < limits.size())
4030 outBandRed.
setValue(col, row, rBandNoDataValue);
4031 outBandGreen.
setValue(col, row, gBandNoDataValue);
4032 outBandBlue.
setValue(col, row, bBandNoDataValue);
4037 if( enableProgress )
4039 progressPtr->pulse();
4040 if( ! progressPtr->isActive() )
return false;
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
Palette indexes color interpretation.
double * m_stdDevValuePtr
void push_back(Curve *ring)
It adds the curve to the curve polygon.
boost::mutex * m_mutexPtr
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
void release(std::unique_ptr< te::da::DataSource > &dataSourcePtr, std::unique_ptr< te::da::DataSourceTransactor > &transactorPtr, std::unique_ptr< te::da::DataSet > &dataSetPtr, std::unique_ptr< te::rst::Raster > &rasterPtr)
Relase the internal state and give the ownership to the given pointers.
void reset()
Reset the internal state (all internal pointed objects are deleted).
virtual std::unique_ptr< DataSourceTransactor > getTransactor()=0
It returns the set of parameters used to set up the access channel to the underlying repository...
te::rst::Raster * m_outputRasterPtr
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
Matrix< bool > * m_rasterBlocksStatusPtr
unsigned int getRow() const
Returns the current row in iterator.
A raster band description.
RGB indexed palette interpretation.
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.
void SaveSensorParams(std::map< std::string, SpectralSensorParams > ¶ms)
Saves in SpectralSensor.json file the spectral sensors parameters.
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...
bool RasterSlicing(const te::rst::Raster &inputRaster, const unsigned int inputRasterBand, const bool createPaletteRaster, const unsigned int slicesNumber, const bool eqHistogram, const std::map< std::string, std::string > &rasterInfo, const std::string &rasterType, const bool enableProgress, std::vector< te::rst::BandProperty::ColorEntry > const *const palettePtr, std::unique_ptr< te::rst::Raster > &outRasterPtr, std::map< double, double > limits)
Generate all wavelet planes from the given input raster.
static std::string asString()
std::map< std::string, SpectralSensorParams > getSensorParams()
Returns a map with spectral sensors parameters defined in SpectralSensor.json file.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
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)...
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.
This class can be used to inform the progress of a task.
#define MIN(a, b)
Macro that returns min between two values.
Red channel color interpretation.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
Matrix< bool > * m_rasterBlocksStatusPtr
boost::mutex * m_mutexPtr
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
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 ( See te::dt namespace basic data types for reference )...
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::unique_ptr< te::rst::Raster > &outputRasterPtr)
Compose a set of bands into one multi-band raster.
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<double>::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
virtual te::rst::Raster const * getCurrentObj() const =0
Return the current sequence object.
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.
double GetDigitalNumberBandMin(std::string bandName)
Returns the minimum digital number of a given sensor/band.
InterpolationMethod
Allowed interpolation methods.
#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.
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.
#define TERP_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged and a return of context wi...
bool ConvertHLS2RGB(const te::rst::Raster &inputHLSRaster, const unsigned int hueBandIdx, const unsigned int lightBandIdx, const unsigned int saturationBandIdx, const double, const double rgbRangeMax, te::rst::Raster &outputRGBRaster)
HLS to RGB conversion.
std::vector< unsigned int > const * m_inputRasterBandsPtr
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
unsigned int unsigned int nCols
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
static T & getInstance()
It returns a reference to the singleton instance.
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.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
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.
WaveletAtrousFilterType
Wavelet Atrous Filter types.
BandProperty * getProperty()
Returns the band property.
int m_blkw
Block width (pixels).
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.
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.
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
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
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
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.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
te::rst::Band const * m_inputBandPtr
bool ConvertRGB2HLS(const te::rst::Raster &inputRGBRaster, const unsigned int redBandIdx, const unsigned int greenBandIdx, const unsigned int blueBandIdx, const double, const double rgbRangeMax, te::rst::Raster &outputHLSRaster)
RGB to HLS conversion.
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.
virtual void read(int x, int y, void *buffer) const =0
It reads a data block to the specified buffer.
int getSRID() const
Returns the raster spatial reference system identifier.
short c1
gray, red, cyan or hue.
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::unique_ptr< te::rst::Raster > &resampledRasterPtr)
Resample a subset of the raster, given a box.
#define TERP_LOG_AND_RETURN_FALSE(message)
Logs a warning message will and return false.
double * m_pixelsNumberValuePtr
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
SpectralSensorParams GetSpectralBandInfo(std::string bandName)
Returns the maximun and minimum reflectance values of a given sensor/band.
Feeder from a input rasters.
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 execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
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.
short c3
blue, yellow, or saturation.
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
TECOREEXPORT std::string GetAppLocalDataLocation()
It returns the writable folder location to store per user data.
void CreateFixedStepPalette(const unsigned int paletteSize, const bool randomize, std::vector< te::rst::BandProperty::ColorEntry > &palette)
Create a fixed step sequential color palette.
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.
std::string m_createdOutRasterDSType
Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the resul...
An structure to represent a color tuple.
Raster Processing functions.
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 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).
Blue channel color interpretation.
A rectified grid is the spatial support for raster data.
boost::numeric::ublas::matrix< double > const * m_remapMatrixPtr
Green channel color interpretation.
Contrast output parameters.
void GetCovarianceValueThread(GetCovarianceValueThreadParams *paramsPtr)
double * m_pixelsNumberValuePtr
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
std::string GetSensorFilename()
Returns a json filename with spectral sensors parameters.
void GetStdDevValueThread(GetStdDevValueThreadParams *paramsPtr)
unsigned int getLinesNumber() const
The number of current matrix lines.
short c2
green, magenta, or lightness.
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.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
virtual unsigned int getCurrentOffset() const =0
Return the index of the current object.
virtual unsigned int getObjsCount() const =0
Return the total number of feeder objects.
void ConvertDoublesVector(double *inputVector, unsigned int inputVectorSize, const int outputVectorDataType, void *outputVector)
Convert a doubles vector.