26 #include "../raster/Band.h" 
   27 #include "../raster/BandProperty.h" 
   28 #include "../raster/Grid.h" 
   29 #include "../raster/RasterFactory.h" 
   56       const std::vector< unsigned int >& rasterBands,
 
   58       const unsigned int maskRasterBand,
 
   59       const unsigned int rasterTargetAreaLineStart,
 
   60       const unsigned int rasterTargetAreaColStart,
 
   61       const unsigned int rasterTargetAreaWidth,
 
   62       const unsigned int rasterTargetAreaHeight,
 
   63       const double desiredRescaleFactorX,
 
   64       const double desiredRescaleFactorY,
 
   66       const unsigned char maxMemPercentUsage, 
 
   67       std::vector< boost::shared_ptr< FloatsMatrix > >& loadedRasterData,
 
   69       double& achievedRescaleFactorX,
 
   70       double& achievedRescaleFactorY )
 
   74       const unsigned int rescaledNLines = (
unsigned int)(
 
   75         ((
double)rasterTargetAreaHeight) * desiredRescaleFactorY );
 
   76       const unsigned int rescaledNCols = (
unsigned int)(
 
   77         ((
double)rasterTargetAreaWidth) * desiredRescaleFactorX );
 
   79       achievedRescaleFactorX = ((double)rescaledNCols) / ((double)rasterTargetAreaWidth);
 
   80       achievedRescaleFactorY = ((double)rescaledNLines) / ((double)rasterTargetAreaHeight);
 
   83         unsigned char maxMemPercentUsagePerMatrix = 
MAX( 1u, maxMemPercentUsage / 
 
   85             ( maskRasterPtr ? 1 : 0 ) 
 
   87             ((
unsigned int)rasterBands.size()) ) 
 
   90         loadedRasterData.resize( rasterBands.size() );
 
   92         for( 
unsigned int rasterBandsIdx = 0 ; rasterBandsIdx < rasterBands.size() ;
 
   95           loadedRasterData[ rasterBandsIdx ].reset( 
new FloatsMatrix );
 
   98             maxMemPercentUsagePerMatrix ),
 
   99             "Cannot allocate image 1 matrix" );
 
  100           maxMemPercentUsagePerMatrix *= 2;
 
  106             rescaledNLines, rescaledNCols,
 
  108             "Cannot allocate image 1 mask matrix" );          
 
  117         assert( inMaskRasterBand );
 
  119         unsigned char* outMaskLinePtr = 0;
 
  120         unsigned int outLine = 0;
 
  121         unsigned int outCol = 0;
 
  122         unsigned int inLine = 0;
 
  123         unsigned int inCol = 0;
 
  126         for( outLine = 0 ; outLine < rescaledNLines ; ++outLine ) 
 
  128           inLine = (
unsigned int)( ( ( (
double)outLine ) / 
 
  129             desiredRescaleFactorY ) + ( (double)rasterTargetAreaLineStart ) );      
 
  131           outMaskLinePtr = loadedMaskRasterData[ outLine ];
 
  133           for( outCol = 0 ; outCol < rescaledNCols ; ++outCol ) 
 
  135             inCol = (
unsigned int)( ( ( (
double)outCol ) / 
 
  136                 desiredRescaleFactorX ) + ( (double)rasterTargetAreaColStart ) );        
 
  138             inMaskRasterBand->
getValue( inCol, inLine, value );
 
  141               outMaskLinePtr[ outCol ] = 0;
 
  143               outMaskLinePtr[ outCol ] = 255;
 
  150         const double rasterTargetAreaLineStartDouble = (double)
 
  151           rasterTargetAreaLineStart;
 
  152         const double rasterTargetAreaColStartDouble = (double)
 
  153           rasterTargetAreaColStart;
 
  155         float* floatLinePtr = 0;
 
  156         double* doubleLinePtr = 0;
 
  157         unsigned int outLine = 0;
 
  158         unsigned int outCol = 0;
 
  161         std::complex< double > interpolatedValue;
 
  162         unsigned int bandIdx = 0;
 
  170           "Cannot allocate auxiliar matrix" );        
 
  172         for( 
unsigned int rasterBandsIdx = 0 ; rasterBandsIdx < rasterBands.size() ;
 
  175           bandIdx= rasterBands[ rasterBandsIdx ];
 
  177           bandMax = -1.0 * DBL_MAX;
 
  179           for( outLine = 0 ; outLine < rescaledNLines ; ++outLine ) 
 
  181             inLine = ( ( (double)outLine ) /  desiredRescaleFactorY ) + 
 
  182               rasterTargetAreaLineStartDouble;
 
  184             doubleLinePtr = auxBandData[ outLine ];
 
  186             for( outCol = 0 ; outCol < rescaledNCols ; ++outCol ) 
 
  188               inCol = ( ( (double)outCol ) / desiredRescaleFactorX ) + 
 
  189                 rasterTargetAreaColStartDouble;
 
  191               interpInstance.
getValue( inCol, inLine, interpolatedValue,
 
  194               doubleLinePtr[ outCol ] = interpolatedValue.real();              
 
  196               if( interpolatedValue.real() > bandMax ) bandMax = interpolatedValue.real();
 
  197               if( interpolatedValue.real() < bandMin ) bandMin = interpolatedValue.real();
 
  201           if( bandMin == bandMax )
 
  204             gain = ( 1.0 / ( bandMax - bandMin ) );
 
  206           for( outLine = 0 ; outLine < rescaledNLines ; ++outLine ) 
 
  208             doubleLinePtr = auxBandData[ outLine ];
 
  209             floatLinePtr = loadedRasterData[ rasterBandsIdx ]->operator[]( outLine  );
 
  211             for( outCol = 0 ; outCol < rescaledNCols ; ++outCol ) 
 
  213               floatLinePtr[ outCol ] = (float)( ( doubleLinePtr[ outCol ] - bandMin ) * gain );
 
  225       const std::string& tifFileName )
 
  227       std::map<std::string, std::string> rInfo;
 
  228       rInfo[
"URI"] = tifFileName + 
".tif";
 
  230       std::vector<te::rst::BandProperty*> bandsProperties;
 
  233       bandsProperties[0]->m_noDataValue = 0;
 
  242       std::auto_ptr< te::rst::Raster > outputRasterPtr(
 
  246       unsigned int line = 0;
 
  247       unsigned int col = 0;
 
  250       double rasterDataMin = DBL_MAX;
 
  251       double rasterDataMax = (-1.0) * DBL_MAX;
 
  254       for( line = 0 ; line < nLines ; ++line )
 
  255         for( col = 0 ; col < nCols ; ++col )
 
  257           value = (double)rasterData[ line ][ col ];
 
  259           if( rasterDataMin > value )
 
  260             rasterDataMin = value;
 
  261           if( rasterDataMax < value )
 
  262             rasterDataMax = value;
 
  265       if( rasterDataMax == rasterDataMin )
 
  271       for( line = 0 ; line < nLines ; ++line )
 
  272         for( col = 0 ; col < nCols ; ++col )
 
  274           value = (double)rasterData[ line ][ col ];
 
  275           value = ( value - rasterDataMin ) / ( rasterDataMax - rasterDataMin );
 
  277           value = std::max( 0.0, value );
 
  278           value = std::min( 255.0, value );
 
  280           outputRasterPtr->setValue( col, line, value, 0 );
 
  281           outputRasterPtr->setValue( col, line, value, 1 );
 
  282           outputRasterPtr->setValue( col, line, value, 2 );
 
  285       InterestPointsSetT::const_iterator itB = interestPoints.begin();
 
  286       InterestPointsSetT::const_iterator itE = interestPoints.end();
 
  290         outputRasterPtr->setValue( itB->m_x, itB->m_y, 0, 0 );
 
  291         outputRasterPtr->setValue( itB->m_x, itB->m_y, 255, 1 );
 
  292         outputRasterPtr->setValue( itB->m_x, itB->m_y, 0, 2 );
 
  300       const std::string& fileNameBeginning )
 
  302       const unsigned int tifLinesNumber = (
unsigned int)std::sqrt( (
double)
 
  306       double const* featureLinePtr = 0;
 
  308       InterestPointsSetT::const_iterator iIt = interestPoints.begin();
 
  310       for( 
unsigned int featuresIdx = 0 ; featuresIdx < features.
getLinesNumber() ;
 
  313         featureLinePtr = features[ featuresIdx ];
 
  315         std::vector<te::rst::BandProperty*> bandsProperties;
 
  318         bandsProperties[0]->m_noDataValue = 0;
 
  320         std::map<std::string, std::string> rInfo;
 
  321         rInfo[
"URI"] = fileNameBeginning + 
"_" + boost::lexical_cast< std::string >( iIt->m_x ) 
 
  322           + 
"_" + boost::lexical_cast< std::string >( iIt->m_y ) + 
".tif";        
 
  325           tifLinesNumber, 0, -1 );          
 
  327         std::auto_ptr< te::rst::Raster > outputRasterPtr(
 
  331         unsigned int line = 0;
 
  332         unsigned int col = 0;
 
  338         for( col = 0 ; col < featuresColsNumber ; ++col )
 
  340           if( min > featureLinePtr[ col ] ) min = featureLinePtr[ col ];
 
  341           if( max < featureLinePtr[ col ] ) max = featureLinePtr[ col ];
 
  344         gain = 255.0 / ( max - min );
 
  346         for( line = 0 ; line < tifLinesNumber ; ++line )
 
  347           for( col = 0 ; col < tifLinesNumber ; ++col )
 
  349             value = featureLinePtr[ ( line * tifLinesNumber ) + col ];
 
  352             value = 
MIN( 255.0, value );
 
  353             value = 
MAX( 0.0, value );
 
  355             outputRasterPtr->setValue( col, line, value, 0 );
 
  366       InterestPointsSetT::const_iterator it1 = interestPoints.begin();
 
  367       InterestPointsSetT::const_iterator it2;
 
  368       const InterestPointsSetT::const_iterator itE = interestPoints.end();
 
  377           if( ( it1->m_x == it2->m_x ) && ( it1->m_y == it2->m_y ) )
 
virtual ~TiePointsLocatorStrategy()
 
This file contains include headers for the memory data source of TerraLib. 
 
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value. 
 
A raster band description. 
 
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band. 
 
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
 
#define MIN(a, b)
Macro that returns min between two values. 
 
Red channel color interpretation. 
 
void getValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Get the interpolated value at specific band. 
 
InterpolationMethod
Allowed interpolation methods. 
 
Tie-Pointsr locator strategy. 
 
#define MAX(a, b)
Macro that returns max between two values. 
 
#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...
 
static void createTifFromMatrix(const FloatsMatrix &rasterData, const InterestPointsSetT &interestPoints, const std::string &tifFileName)
Moravec interest points locator. 
 
const TiePointsLocatorStrategy & operator=(const TiePointsLocatorStrategy &)
 
virtual void reset()=0
Clear all internal allocated resources and go back to the initial not-initialized state...
 
An abstract class for raster data strucutures. 
 
unsigned int getColumnsNumber() const 
The number of current matrix columns. 
 
std::multiset< InterestPointT > InterestPointsSetT
 
TiePointsLocatorStrategy()
 
A raster band description. 
 
static bool loadRasterData(te::rst::Raster const *rasterPtr, const std::vector< unsigned int > &rasterBands, te::rst::Raster const *maskRasterPtr, const unsigned int maskRasterBand, const unsigned int rasterTargetAreaLineStart, const unsigned int rasterTargetAreaColStart, const unsigned int rasterTargetAreaWidth, const unsigned int rasterTargetAreaHeight, const double desiredRescaleFactorX, const double desiredRescaleFactorY, const te::rst::Interpolator::Method rasterInterpMethod, const unsigned char maxMemPercentUsage, std::vector< boost::shared_ptr< FloatsMatrix > > &loadedRasterData, UCharsMatrix &loadedMaskRasterData, double &achievedRescaleFactorX, double &achievedRescaleFactorY)
Load rasters data (normalized between 0 and 1). 
 
void reset()
Reset (clear) the active instance data. 
 
Tie-points locator strategy. 
 
static void features2Tiff(const DoublesMatrix &features, const InterestPointsSetT &interestPoints, const std::string &fileNameBeginning)
Save the generated features to tif files. 
 
A generic template matrix. 
 
static Raster * make()
It creates and returns an empty raster with default raster driver. 
 
Blue channel color interpretation. 
 
A rectified grid is the spatial support for raster data. 
 
Green channel color interpretation. 
 
unsigned int getLinesNumber() const 
The number of current matrix lines. 
 
static bool checkForDuplicatedInterestPoints(const InterestPointsSetT &interestPoints, double &x, double &y)
Check for duplicated interest points. 
 
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.