All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SequenceMosaic.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/rp/SequenceMosaic.cpp
22  \brief Create mosaics from a sequence of overlapped rasters using an automatic tie-points detection method.
23 */
24 
25 #include "SequenceMosaic.h"
26 
27 #include "RasterHandler.h"
28 #include "Macros.h"
29 #include "Functions.h"
30 #include "../raster/Grid.h"
31 #include "../raster/BandProperty.h"
32 #include "../raster/Utils.h"
33 #include "../raster/RasterFactory.h"
34 #include "../memory/CachedRaster.h"
35 #include "../memory/ExpansibleRaster.h"
36 #include "../geometry/Envelope.h"
37 #include "../geometry/GeometricTransformation.h"
38 #include "../geometry/Polygon.h"
39 #include "../geometry/LinearRing.h"
40 #include "../geometry/MultiPolygon.h"
41 #include "../geometry/MultiPoint.h"
42 #include "../geometry/Point.h"
43 #include "../common/progress/TaskProgress.h"
44 
45 #include <boost/lexical_cast.hpp>
46 
47 #include <memory>
48 
49 #define SEQUENCE_RASTER_MAX_MOSAIC_MEM_USE 10
50 
51 namespace te
52 {
53  namespace rp
54  {
55 
57  {
58  reset();
59  }
60 
62  {
63  reset();
64  operator=( other );
65  }
66 
68  {
69  reset();
70  }
71 
72  void SequenceMosaic::InputParameters::reset() throw( te::rp::Exception )
73  {
74  m_feederRasterPtr = 0;
75  m_inputRastersBands.clear();
76  m_geomTransfName = "Affine";
78  m_noDataValue = 0.0;
79  m_forceInputNoDataValue = false;
80  m_blendMethod = te::rp::Blender::NoBlendMethod;
81  m_autoEqualize = true;
82  m_useRasterCache = true;
83  m_enableMultiThread = true;
84  m_enableProgress = false;
85  m_tiePointsLocationBandIndex = 0;
86  m_outDataSetsNamePrefix.clear();
87  m_outDataSetsNameSufix.clear();
88  m_minRequiredTiePointsCoveredAreaPercent = 0.0;
89  m_locatorParams.reset();
90  }
91 
93  const SequenceMosaic::InputParameters& params )
94  {
95  reset();
96 
97  m_feederRasterPtr = params.m_feederRasterPtr;
98  m_inputRastersBands = params.m_inputRastersBands;
99  m_geomTransfName = params.m_geomTransfName;
100  m_interpMethod = params.m_interpMethod;
101  m_noDataValue = params.m_noDataValue;
102  m_forceInputNoDataValue = params.m_forceInputNoDataValue;
103  m_blendMethod = params.m_blendMethod;
104  m_autoEqualize = params.m_autoEqualize;
105  m_useRasterCache = params.m_useRasterCache;
106  m_enableMultiThread = params.m_enableMultiThread;
107  m_enableProgress = params.m_enableProgress;
108  m_tiePointsLocationBandIndex = params.m_tiePointsLocationBandIndex;
109  m_outDataSetsNamePrefix = params.m_outDataSetsNamePrefix;
110  m_outDataSetsNameSufix = params.m_outDataSetsNameSufix;
111  m_minRequiredTiePointsCoveredAreaPercent =
113  m_locatorParams = params.m_locatorParams;
114 
115  return *this;
116  }
117 
119  {
120  return new InputParameters( *this );
121  }
122 
123  // ----------------------------------------------------------------------
124 
126  {
127  reset();
128  }
129 
131  {
132  reset();
133  operator=( other );
134  }
135 
137  {
138  reset();
139  }
140 
141  void SequenceMosaic::OutputParameters::reset() throw( te::rp::Exception )
142  {
143  m_outputDSPtr = 0;
144  m_sequencesInfo.clear();
145  }
146 
148  const SequenceMosaic::OutputParameters& params )
149  {
150  reset();
151 
152  m_outputDSPtr = params.m_outputDSPtr;
153  m_sequencesInfo = params.m_sequencesInfo;
154 
155  return *this;
156  }
157 
159  {
160  return new OutputParameters( *this );
161  }
162 
163  // ----------------------------------------------------------------------
164 
166  {
167  }
168 
170  {
171  }
172 
174  {
175  m_dataSetName.clear();
176  m_rasterFeederIndexes.clear();
177  m_tiePoints.clear();
178  }
179 
180  // ----------------------------------------------------------------------
181 
183  {
184  reset();
185  }
186 
188  {
189  }
190 
192  throw( te::rp::Exception )
193  {
194  if( ! m_isInitialized ) return false;
195 
196  SequenceMosaic::OutputParameters* outParamsPtr = dynamic_cast<
197  SequenceMosaic::OutputParameters* >( &outputParams );
198  TERP_TRUE_OR_THROW( outParamsPtr, "Invalid paramters" );
199 
201  "Invalid data source" );
203  "Invalid data source" );
204 
205  outParamsPtr->m_sequencesInfo.clear();
206 
207  // progress
208 
209  std::auto_ptr< te::common::TaskProgress > progressPtr;
211  {
212  progressPtr.reset( new te::common::TaskProgress );
213 
214  progressPtr->setTotalSteps( m_inputParameters.m_feederRasterPtr->getObjsCount() );
215 
216  progressPtr->setMessage( "Mosaicking" );
217  }
218 
219  // iterating over all rasters
220 
221  const std::vector< double > dummyRasterOffsets( m_inputParameters.m_inputRastersBands[ 0 ].size(), 0.0 );
222  const std::vector< double > dummyRasterScales( m_inputParameters.m_inputRastersBands[ 0 ].size(), 1.0 );
223 
224  std::vector< unsigned int > dummyRasterBandsIndexes;
225  {
226  for( unsigned int bandIdx = 0 ; bandIdx <
227  m_inputParameters.m_inputRastersBands[ 0 ].size(); ++bandIdx )
228  dummyRasterBandsIndexes.push_back( bandIdx );
229  }
230 
231  std::auto_ptr< te::mem::ExpansibleRaster > mosaicRasterHandler;
232  std::vector< double > mosaicTargetMeans;
233  std::vector< double > mosaicTargetVariances;
234  te::gm::Polygon mosaicValidDataPol( 0, te::gm::PolygonType, 0 ); // the polygon delimiting the valid data inside the mosaic (mosaic world coods)
235  std::vector< double > mosaicBandsRangeMin;
236  std::vector< double > mosaicBandsRangeMax;
237  unsigned int lastInputRasterBBoxLLXIndexed = 0; // The last raster added to the mosaic position
238  unsigned int lastInputRasterBBoxLLYIndexed = 0; // The last raster added to the mosaic position
239  unsigned int lastInputRasterBBoxURXIndexed = 0; // The last raster added to the mosaic position
240  unsigned int lastInputRasterBBoxURYIndexed = 0; // The last raster added to the mosaic position
241  MosaicSequenceInfo currentMosaicSquenceInfo;
242 
245  {
246  const unsigned int inputRasterIdx =
248 
249  te::rst::Raster const* inputRasterPtr =
251 
252  std::auto_ptr< te::mem::CachedRaster > cachedInputRasterPtr;
254  {
255  cachedInputRasterPtr.reset( new te::mem::CachedRaster(
258  inputRasterPtr = cachedInputRasterPtr.get();
259  }
260 
261  // saving the current mosaic (debug purposes)
262 
263 // if( mosaicRasterHandler.get() )
264 // {
265 // if( ! createDiskRasterCopy( "Mosaic_" +
266 // boost::lexical_cast< std::string >( inputRasterIdx - 1 ) + ".tif",
267 // *mosaicRasterHandler ) )
268 // {
269 // return false;
270 // }
271 // }
272 
273  // Mosaicking
274 
275  if( mosaicRasterHandler.get() == 0 )
276  {
277  const double& mosaicLLX = inputRasterPtr->getGrid()->getExtent()->m_llx;
278  const double& mosaicLLY = inputRasterPtr->getGrid()->getExtent()->m_lly;
279  const double& mosaicURX = inputRasterPtr->getGrid()->getExtent()->m_urx;
280  const double& mosaicURY = inputRasterPtr->getGrid()->getExtent()->m_ury;
281 
283  auxLinearRingPtr->setPoint( 0, mosaicLLX, mosaicURY );
284  auxLinearRingPtr->setPoint( 1, mosaicURX, mosaicURY );
285  auxLinearRingPtr->setPoint( 2, mosaicURX, mosaicLLY );
286  auxLinearRingPtr->setPoint( 3, mosaicLLX, mosaicLLY );
287  auxLinearRingPtr->setPoint( 4, mosaicLLX, mosaicURY );
288  mosaicValidDataPol.clear();
289  mosaicValidDataPol.push_back( auxLinearRingPtr );
290  mosaicValidDataPol.setSRID( inputRasterPtr->getGrid()->getSRID() );
291 
292  lastInputRasterBBoxLLXIndexed = 0;
293  lastInputRasterBBoxLLYIndexed = inputRasterPtr->getNumberOfRows() - 1;
294  lastInputRasterBBoxURXIndexed = inputRasterPtr->getNumberOfColumns() - 1;
295  lastInputRasterBBoxURYIndexed = 0;
296 
297  mosaicBandsRangeMin.resize(
298  m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size(), 0 );
299  mosaicBandsRangeMax.resize(
300  m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size(), 0 );
301 
302  std::vector< te::rst::BandProperty* > bandsProperties;
303  for( std::vector< unsigned int >::size_type inputRastersBandsIdx = 0 ;
304  inputRastersBandsIdx <
305  m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size() ;
306  ++inputRastersBandsIdx )
307  {
308  te::rst::BandProperty const* const inBandPropPtr =
310  inputRasterIdx ][ inputRastersBandsIdx ] )->getProperty();
311 
312  bandsProperties.push_back( new te::rst::BandProperty( *inBandPropPtr ) );
313  bandsProperties[ inputRastersBandsIdx ]->m_colorInterp = te::rst::GrayIdxCInt;
314  bandsProperties[ inputRastersBandsIdx ]->m_noDataValue = m_inputParameters.m_noDataValue;
315  bandsProperties[ inputRastersBandsIdx ]->m_blkw = (unsigned int)
316  std::ceil( ((double)inputRasterPtr->getNumberOfColumns()) / 4.0 );
317  bandsProperties[ inputRastersBandsIdx ]->m_blkh = (unsigned int)
318  std::ceil( ((double)inputRasterPtr->getNumberOfRows()) / 4.0 );
319  bandsProperties[ inputRastersBandsIdx ]->m_nblocksx = (unsigned int)
320  std::ceil( ((double)inputRasterPtr->getNumberOfColumns()) /
321  ((double)bandsProperties[ inputRastersBandsIdx ]->m_blkw ) );
322  bandsProperties[ inputRastersBandsIdx ]->m_nblocksy = (unsigned int)
323  std::ceil( ((double)inputRasterPtr->getNumberOfRows()) /
324  ((double)bandsProperties[ inputRastersBandsIdx ]->m_blkh ) );
325 
326  te::rst::GetDataTypeRanges( bandsProperties[ inputRastersBandsIdx ]->m_type,
327  mosaicBandsRangeMin[ inputRastersBandsIdx ],
328  mosaicBandsRangeMax[ inputRastersBandsIdx ]);
329  }
330 
331  mosaicRasterHandler.reset(
333  new te::rst::Grid( *( inputRasterPtr->getGrid() ) ),
334  bandsProperties ) );
335  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler.get(),
336  "Output raster creation error" );
337 
338  const unsigned int nBands = mosaicRasterHandler->getNumberOfBands();
339 
340  mosaicTargetMeans.resize( nBands, 0.0 );
341  mosaicTargetVariances.resize( nBands, 0.0 );
342 
343  for( unsigned int inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
344  nBands ; ++inputRastersBandsIdx )
345  {
346  const unsigned int inputBandIdx =
347  m_inputParameters.m_inputRastersBands[ inputRasterIdx ][ inputRastersBandsIdx ] ;
348  const double& bandNoDataValue = m_inputParameters.m_forceInputNoDataValue ?
349  m_inputParameters.m_noDataValue : inputRasterPtr->getBand( inputBandIdx
351  const unsigned int outRowsBound = inputRasterPtr->getNumberOfRows();
352  const unsigned int outColsBound = inputRasterPtr->getNumberOfColumns();
353  te::rst::Band& outBand =
354  (*mosaicRasterHandler->getBand( inputRastersBandsIdx ));
355  const te::rst::Band& inBand =
356  (*inputRasterPtr->getBand( inputBandIdx ));
357  unsigned int validPixelsNumber = 0;
358  unsigned int outCol = 0;
359  unsigned int outRow = 0;
360  double pixelValue = 0;
361 
362  double& mean = mosaicTargetMeans[ inputRastersBandsIdx ];
363  mean = 0;
364 
365  for( outRow = 0 ; outRow < outRowsBound ; ++outRow )
366  {
367  for( outCol = 0 ; outCol < outColsBound ; ++outCol )
368  {
369  inBand.getValue( outCol, outRow, pixelValue );
370 
371  if( pixelValue != bandNoDataValue )
372  {
373  outBand.setValue( outCol, outRow, pixelValue );
374 
375  mean += pixelValue;
376  ++validPixelsNumber;
377  }
378 
379  }
380  }
381 
382  mean /= ( (double)validPixelsNumber );
383 
384  // variance calcule
385 
387  {
388  double& variance = mosaicTargetVariances[ inputRastersBandsIdx ];
389  variance = 0;
390 
391  double pixelValue = 0;
392 
393  for( outRow = 0 ; outRow < outRowsBound ; ++outRow )
394  {
395  for( outCol = 0 ; outCol < outColsBound ; ++outCol )
396  {
397  outBand.getValue( outCol, outRow, pixelValue );
398 
399  if( pixelValue != bandNoDataValue )
400  {
401  variance += ( ( pixelValue - mean ) * ( pixelValue -
402  mean ) ) / ( (double)validPixelsNumber );
403  }
404  }
405  }
406  }
407  }
408 
409  // Updating the mosaic sequence info
410 
411  currentMosaicSquenceInfo.m_rasterFeederIndexes.push_back(
412  inputRasterIdx );
413  currentMosaicSquenceInfo.m_tiePoints.push_back(
414  std::vector< te::gm::GTParameters::TiePoint >() );
415 
416  // Move to the next raster
417 
418  cachedInputRasterPtr.reset();
419 
421 
423  {
424  progressPtr->pulse();
425  if( ! progressPtr->isActive() ) return false;
426  }
427  }
428  else
429  {
430  // Locating the tie points where te::gm::GTParameters::TiePoint::first
431  // are :mosaic indexed coods and te::gm::GTParameters::TiePoint::second are
432  // indexed coords from the current raster
433 
435 
436  {
438  locatorInParams = m_inputParameters.m_locatorParams;
439 
440  locatorInParams.m_inRaster1Ptr = mosaicRasterHandler.get();
441 
442  locatorInParams.m_inMaskRaster1Ptr = 0;
443 
444  locatorInParams.m_inRaster1Bands.clear();
445  locatorInParams.m_inRaster1Bands.push_back(
447 
448  locatorInParams.m_raster1TargetAreaColStart = lastInputRasterBBoxLLXIndexed;
449  locatorInParams.m_raster1TargetAreaLineStart = lastInputRasterBBoxURYIndexed;
450  locatorInParams.m_raster1TargetAreaWidth = (unsigned int)(
451  lastInputRasterBBoxURXIndexed - lastInputRasterBBoxLLXIndexed + 1 );
452  locatorInParams.m_raster1TargetAreaHeight = (unsigned int)(
453  lastInputRasterBBoxLLYIndexed - lastInputRasterBBoxURYIndexed + 1 );
454 
455  locatorInParams.m_inRaster2Ptr = inputRasterPtr;
456 
457  locatorInParams.m_inMaskRaster2Ptr = 0;
458 
459  locatorInParams.m_inRaster2Bands.clear();
460  locatorInParams.m_inRaster2Bands.push_back(
461  m_inputParameters.m_inputRastersBands[ inputRasterIdx ][
463 
464  locatorInParams.m_raster2TargetAreaLineStart = 0;
465  locatorInParams.m_raster2TargetAreaColStart = 0;
466  locatorInParams.m_raster2TargetAreaWidth = 0;
467  locatorInParams.m_raster2TargetAreaHeight = 0;
468 
470 
471  locatorInParams.m_enableProgress = false;
472 
473  locatorInParams.m_pixelSizeXRelation = mosaicRasterHandler->getResolutionX() /
474  inputRasterPtr->getResolutionX();
475  locatorInParams.m_pixelSizeYRelation = mosaicRasterHandler->getResolutionY() /
476  inputRasterPtr->getResolutionY();
477 
479 
480  locatorInParams.m_enableGeometryFilter = true;
481 
483 
484  te::rp::TiePointsLocator locatorInstance;
485  TERP_TRUE_OR_RETURN_FALSE( locatorInstance.initialize(
486  locatorInParams ), "Tie points locator init error" );
487  TERP_TRUE_OR_RETURN_FALSE( locatorInstance.execute(
488  locatorOutParams ), "Tie points locator exec error" );
489  }
490 
491  // The matching was accomplished successfully ?
492 
493  if(
494  ( locatorOutParams.m_transformationPtr.get() == 0 )
495  ||
496  (
497  locatorOutParams.m_tiePoints.size()
498  <
499  (
500  2
501  *
502  locatorOutParams.m_transformationPtr->getMinRequiredTiePoints()
503  )
504  )
505  ||
506  (
507  (
508  getTPConvexHullArea( locatorOutParams.m_tiePoints, true )
509  /
510  (double)(
511  inputRasterPtr->getNumberOfColumns()
512  *
513  inputRasterPtr->getNumberOfRows()
514  )
515  )
516  <
517  (
519  /
520  100.0
521  )
522  )
523  )
524  {
525  // Saving the mosaic sequence info
526 
527  currentMosaicSquenceInfo.m_dataSetName = m_inputParameters.m_outDataSetsNamePrefix +
528  boost::lexical_cast< std::string >( outParamsPtr->m_sequencesInfo.size() ) +
530 
531  outParamsPtr->m_sequencesInfo.push_back( currentMosaicSquenceInfo );
532 
533  // Create the output data set
534 
535  assert( mosaicRasterHandler.get() );
537  currentMosaicSquenceInfo.m_dataSetName,
538  *( mosaicRasterHandler.get() ), outParamsPtr->m_outputDSPtr ),
539  "Data set creation error" );
540  mosaicRasterHandler.reset();
541 
542  currentMosaicSquenceInfo.clear();
543  }
544  else
545  {
546  // Generating the offset and gain info for eath band from the current raster
547 
548  std::vector< double > currentRasterBandsOffsets;
549  std::vector< double > currentRasterBandsScales;
550 
552  {
553  double currentRasterVariance = 0;
554  double currentRasterMean = 0;
555 
556  for( unsigned int inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
557  m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size() ;
558  ++inputRastersBandsIdx )
559  {
560  const unsigned int inputBandIdx = m_inputParameters.m_inputRastersBands[ inputRasterIdx ][
561  inputRastersBandsIdx ];
562 
563  calcBandStatistics( (*inputRasterPtr->getBand( inputBandIdx ) ),
566  currentRasterMean,
567  currentRasterVariance );
568 
569  currentRasterBandsScales.push_back( std::sqrt( mosaicTargetVariances[ inputRastersBandsIdx ] /
570  currentRasterVariance ) );
571  currentRasterBandsOffsets.push_back( mosaicTargetMeans[ inputRastersBandsIdx ] -
572  ( currentRasterBandsScales[ inputRastersBandsIdx ] * currentRasterMean ) );
573  }
574  }
575  else
576  {
577  currentRasterBandsOffsets = dummyRasterOffsets;
578  currentRasterBandsScales = dummyRasterScales;
579  }
580 
581  // Updating the mosaic sequence info
582 
583  currentMosaicSquenceInfo.m_tiePoints.push_back(
584  locatorOutParams.m_tiePoints );
585  currentMosaicSquenceInfo.m_rasterFeederIndexes.push_back(
586  inputRasterIdx );
587 
588  // Expanding the mosaic to fit the extent requirement allowing the
589  // merge of the current raster.
590  // Fiding the new geometric transformation between then.
591 
592  std::auto_ptr< te::gm::GeometricTransformation > geoTransPtr(
593  locatorOutParams.m_transformationPtr->clone() );
594 
595  {
596  const double oldLLYIndexed =
597  (double)( inputRasterPtr->getNumberOfRows() - 1 );
598  const double oldURXIndexed =
599  (double)( inputRasterPtr->getNumberOfColumns() - 1 );
600 
601  double mappedLLX = 0;
602  double mappedLLY = 0;
603  double mappedLRX = 0;
604  double mappedLRY = 0;
605  double mappedURX = 0;
606  double mappedURY = 0;
607  double mappedULX = 0;
608  double mappedULY = 0;
609  locatorOutParams.m_transformationPtr->inverseMap(
610  0.0,
611  oldLLYIndexed,
612  mappedLLX,
613  mappedLLY);
614  locatorOutParams.m_transformationPtr->inverseMap(
615  oldURXIndexed,
616  oldLLYIndexed,
617  mappedLRX,
618  mappedLRY);
619  locatorOutParams.m_transformationPtr->inverseMap(
620  oldURXIndexed,
621  0.0,
622  mappedURX,
623  mappedURY);
624  locatorOutParams.m_transformationPtr->inverseMap(
625  0.0,
626  0.0,
627  mappedULX,
628  mappedULY);
629 
630  const double newLLXIndexed = std::min( mappedLLX, std::min( mappedLRX, std::min( mappedURX, mappedULX ) ) );
631  const double newLLYIndexed = std::max( mappedLLY, std::max( mappedLRY, std::max( mappedURY, mappedULY ) ) );
632  const double newURXIndexed = std::max( mappedLLX, std::max( mappedLRX, std::max( mappedURX, mappedULX ) ) );
633  const double newURYIndexed = std::min( mappedLLY, std::min( mappedLRY, std::min( mappedURY, mappedULY ) ) );
634 
635  double oldMosaicReferenceX = 0;
636  double oldMosaicReferenceY = 0;
637  mosaicRasterHandler->getGrid()->gridToGeo( 0.0, 0.0, oldMosaicReferenceX,
638  oldMosaicReferenceY );
639 
640  double mosaicReferenceHasChanged = false;
641 
642 
643  if( newLLXIndexed < 0.0 )
644  {
645  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addLeftColumns(
646  (unsigned int)std::ceil( -1.0 * newLLXIndexed ) ),
647  "Mosaic expansion error" );
648  mosaicReferenceHasChanged = true;
649  }
650 
651  if( newURYIndexed < 0.0 )
652  {
653  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addTopLines(
654  (unsigned int)std::ceil( -1.0 * newURYIndexed ) ),
655  "Mosaic expansion error" );
656  mosaicReferenceHasChanged = true;
657  }
658 
659  if( newURXIndexed > ((double)(mosaicRasterHandler->getNumberOfColumns() - 1) ) )
660  {
661  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addRightColumns(
662  (unsigned int)std::ceil( newURXIndexed -
663  ((double)(mosaicRasterHandler->getNumberOfColumns() - 1)) ) ),
664  "Mosaic expansion error" );
665  }
666 
667  if( newLLYIndexed > ((double)(mosaicRasterHandler->getNumberOfRows() - 1) ) )
668  {
669  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addBottomLines(
670  (unsigned int)std::ceil( newLLYIndexed -
671  ((double)(mosaicRasterHandler->getNumberOfRows() - 1) ) ) ),
672  "Mosaic expansion error" );
673  }
674 
675  // updating the geometric transformation between both rasters
676 
677  if( mosaicReferenceHasChanged )
678  {
679  double expansionOffSetX = 0;
680  double expansionOffSetY = 0;
681  mosaicRasterHandler->getGrid()->geoToGrid( oldMosaicReferenceX,
682  oldMosaicReferenceY, expansionOffSetX, expansionOffSetY );
683 
684  te::gm::GTParameters newTransParams;
685  newTransParams.m_tiePoints =
686  geoTransPtr->getParameters().m_tiePoints;
687 
688  for( unsigned int tpIdx = 0 ; tpIdx <
689  newTransParams.m_tiePoints.size() ; ++tpIdx )
690  {
691  newTransParams.m_tiePoints[ tpIdx ].first.x += expansionOffSetX;
692  newTransParams.m_tiePoints[ tpIdx ].first.y += expansionOffSetY;
693  }
694 
695  TERP_TRUE_OR_RETURN_FALSE( geoTransPtr->initialize( newTransParams ),
696  "Geometric transformation parameters calcule error" );
697  }
698  }
699 
700  // Locating the current raster over the expanded mosaic
701 
702  double inputRasterMappedLLXIndexed = 0;
703  double inputRasterMappedLLYIndexed = 0;
704  double inputRasterMappedLRXIndexed = 0;
705  double inputRasterMappedLRYIndexed = 0;
706  double inputRasterMappedURXIndexed = 0;
707  double inputRasterMappedURYIndexed = 0;
708  double inputRasterMappedULXIndexed = 0;
709  double inputRasterMappedULYIndexed = 0;
710  {
711  const double lastRowIdx =
712  (double)( inputRasterPtr->getNumberOfRows() - 1 );
713  const double lastColIdx =
714  (double)( inputRasterPtr->getNumberOfColumns() - 1 );
715 
716  geoTransPtr->inverseMap(
717  0.0,
718  lastRowIdx,
719  inputRasterMappedLLXIndexed,
720  inputRasterMappedLLYIndexed);
721  geoTransPtr->inverseMap(
722  lastColIdx,
723  lastRowIdx,
724  inputRasterMappedLRXIndexed,
725  inputRasterMappedLRYIndexed);
726  geoTransPtr->inverseMap(
727  lastColIdx,
728  0.0,
729  inputRasterMappedURXIndexed,
730  inputRasterMappedURYIndexed);
731  geoTransPtr->inverseMap(
732  0.0,
733  0.0,
734  inputRasterMappedULXIndexed,
735  inputRasterMappedULYIndexed);
736 
737  lastInputRasterBBoxLLXIndexed = (unsigned int)
738  std::max( 0.0,
739  std::min( (double)( mosaicRasterHandler->getNumberOfColumns() - 1 ),
740  std::floor(
741  std::min( inputRasterMappedLLXIndexed,
742  std::min( inputRasterMappedLRXIndexed,
743  std::min( inputRasterMappedURXIndexed,
744  inputRasterMappedULXIndexed
745  )
746  )
747  )
748  )
749  )
750  );
751 
752  lastInputRasterBBoxLLYIndexed = (unsigned int)
753  std::max( 0.0,
754  std::min( (double)( mosaicRasterHandler->getNumberOfRows() - 1 ),
755  std::ceil(
756  std::max( inputRasterMappedLLYIndexed,
757  std::max( inputRasterMappedLRYIndexed,
758  std::max( inputRasterMappedURYIndexed,
759  inputRasterMappedULYIndexed
760  )
761  )
762  )
763  )
764  )
765  );
766 
767  lastInputRasterBBoxURXIndexed = (unsigned int)
768  std::max( 0.0,
769  std::min( (double)( mosaicRasterHandler->getNumberOfColumns() - 1 ),
770  std::ceil(
771  std::max( inputRasterMappedLLXIndexed,
772  std::max( inputRasterMappedLRXIndexed,
773  std::max( inputRasterMappedURXIndexed,
774  inputRasterMappedULXIndexed
775  )
776  )
777  )
778  )
779  )
780  );
781 
782  lastInputRasterBBoxURYIndexed = (unsigned int)
783  std::max( 0.0,
784  std::min( (double)( mosaicRasterHandler->getNumberOfRows() - 1 ),
785  std::floor(
786  std::min( inputRasterMappedLLYIndexed,
787  std::min( inputRasterMappedLRYIndexed,
788  std::min( inputRasterMappedURYIndexed,
789  inputRasterMappedULYIndexed
790  )
791  )
792  )
793  )
794  )
795  );
796 
797  assert( lastInputRasterBBoxLLXIndexed >= 0 );
798  assert( lastInputRasterBBoxLLXIndexed <=
799  ( mosaicRasterHandler->getNumberOfColumns() - 1 ) );
800  assert( lastInputRasterBBoxLLYIndexed >= 0 );
801  assert( lastInputRasterBBoxLLYIndexed <=
802  ( mosaicRasterHandler->getNumberOfRows() - 1 ) );
803  assert( lastInputRasterBBoxURXIndexed >= 0 );
804  assert( lastInputRasterBBoxURXIndexed <=
805  ( mosaicRasterHandler->getNumberOfColumns() - 1 ) );
806  assert( lastInputRasterBBoxURYIndexed >= 0 );
807  assert( lastInputRasterBBoxURYIndexed <=
808  ( mosaicRasterHandler->getNumberOfRows() - 1 ) );
809  }
810 
811  // Blending the current raster into the mosaic
812 
813  {
814  te::rp::Blender blenderInstance;
815 
816  TERP_TRUE_OR_RETURN_FALSE( blenderInstance.initialize(
817  *( mosaicRasterHandler.get() ),
818  dummyRasterBandsIndexes,
819  *inputRasterPtr,
820  m_inputParameters.m_inputRastersBands[ inputRasterIdx ],
826  dummyRasterOffsets,
827  dummyRasterScales,
828  currentRasterBandsOffsets,
829  currentRasterBandsScales,
830  &mosaicValidDataPol,
831  0,
832  *geoTransPtr ),
833  "Blender initiazing error" );
834 
835  std::vector< double > blendedValues( mosaicRasterHandler->getNumberOfBands() );
836  unsigned int outputRow = 0;
837  unsigned int outputCol = 0;
838  const unsigned int nBands = mosaicRasterHandler->getNumberOfBands();
839  unsigned int outBandIdx = 0;
840  te::rst::Raster& outputRaster = *mosaicRasterHandler;
841 
842  for( outputRow = lastInputRasterBBoxURYIndexed ; outputRow <= lastInputRasterBBoxLLYIndexed ;
843  ++outputRow )
844  {
845  for( outputCol = lastInputRasterBBoxLLXIndexed ; outputCol <= lastInputRasterBBoxURXIndexed ;
846  ++outputCol )
847  {
848  blenderInstance.getBlendedValues( (double)outputRow, (double)outputCol,
849  blendedValues );
850 
851  for( outBandIdx = 0 ; outBandIdx < nBands ; ++outBandIdx )
852  {
853  double& blendedValue = blendedValues[ outBandIdx ];
854 
855  if( blendedValue != m_inputParameters.m_noDataValue )
856  {
857  blendedValue = std::max( blendedValue ,
858  mosaicBandsRangeMin[ outBandIdx ] );
859  blendedValue = std::min( blendedValue ,
860  mosaicBandsRangeMax[ outBandIdx ] );
861 
862  outputRaster.setValue( outputCol, outputRow, blendedValue, outBandIdx );
863  }
864  }
865  }
866  }
867  }
868 
869  // updating the mosaic related polygons
870 
871  {
872 
873  double inputRasterMappedLLX = 0;
874  double inputRasterMappedLLY = 0;
875  mosaicRasterHandler->getGrid()->gridToGeo(
876  (double)inputRasterMappedLLXIndexed, (double)inputRasterMappedLLYIndexed,
877  inputRasterMappedLLX, inputRasterMappedLLY );
878 
879  double inputRasterMappedLRX = 0;
880  double inputRasterMappedLRY = 0;
881  mosaicRasterHandler->getGrid()->gridToGeo(
882  (double)inputRasterMappedLRXIndexed, (double)inputRasterMappedLRYIndexed,
883  inputRasterMappedLRX, inputRasterMappedLRY );
884 
885  double inputRasterMappedURX = 0;
886  double inputRasterMappedURY = 0;
887  mosaicRasterHandler->getGrid()->gridToGeo(
888  (double)inputRasterMappedURXIndexed, (double)inputRasterMappedURYIndexed,
889  inputRasterMappedURX, inputRasterMappedURY );
890 
891  double inputRasterMappedULX = 0;
892  double inputRasterMappedULY = 0;
893  mosaicRasterHandler->getGrid()->gridToGeo(
894  (double)inputRasterMappedULXIndexed, (double)inputRasterMappedULYIndexed,
895  inputRasterMappedULX, inputRasterMappedULY );
896 
898  auxLinearRingPtr->setPoint( 0, inputRasterMappedULX, inputRasterMappedULY );
899  auxLinearRingPtr->setPoint( 1, inputRasterMappedURX, inputRasterMappedURY );
900  auxLinearRingPtr->setPoint( 2, inputRasterMappedLRX, inputRasterMappedLRY );
901  auxLinearRingPtr->setPoint( 3, inputRasterMappedLLX, inputRasterMappedLLY );
902  auxLinearRingPtr->setPoint( 4, inputRasterMappedULX, inputRasterMappedULY );
903  te::gm::Polygon lastMosaicAddedRasterPol( 0, te::gm::PolygonType, 0 ); //the polygon of the last added raster (mosaic world coords)
904  lastMosaicAddedRasterPol.push_back( auxLinearRingPtr );
905  lastMosaicAddedRasterPol.setSRID( mosaicRasterHandler->getSRID() );
906 
907  // current mosaic area in a multi-polygon form
908  std::auto_ptr< te::gm::MultiPolygon > mosaicValidDataPolMultiPolPtr(
910  mosaicValidDataPol.getSRID(), 0 ) );
911  mosaicValidDataPolMultiPolPtr->add( (te::gm::Polygon*)mosaicValidDataPol.clone() );
912 
913  // union of the current raster box with the current mosaic valid area under the mosaic SRID
914  std::auto_ptr< te::gm::Geometry > unionMultiPolPtr;
915  unionMultiPolPtr.reset( mosaicValidDataPolMultiPolPtr->Union(
916  &lastMosaicAddedRasterPol ) );
917  TERP_TRUE_OR_THROW( unionMultiPolPtr.get(), "Invalid pointer" );
918  unionMultiPolPtr->setSRID( mosaicRasterHandler->getSRID() );
919 
920  TERP_TRUE_OR_THROW( unionMultiPolPtr->getGeomTypeId() == te::gm::PolygonType,
921  "Invalid geometry type")
922  mosaicValidDataPol = *( (te::gm::Polygon*)unionMultiPolPtr.get() );
923  }
924 
925  // Move to the next raster
926 
927  cachedInputRasterPtr.reset();
928 
930 
932  {
933  progressPtr->pulse();
934  if( ! progressPtr->isActive() ) return false;
935  }
936  }
937  }
938  }
939 
940  if( mosaicRasterHandler.get() )
941  {
942  // Saving the mosaic sequence info
943 
944  currentMosaicSquenceInfo.m_dataSetName = m_inputParameters.m_outDataSetsNamePrefix +
945  boost::lexical_cast< std::string >( outParamsPtr->m_sequencesInfo.size() ) +
947 
948  outParamsPtr->m_sequencesInfo.push_back( currentMosaicSquenceInfo );
949 
951  currentMosaicSquenceInfo.m_dataSetName,
952  *( mosaicRasterHandler.get() ), outParamsPtr->m_outputDSPtr ),
953  "Data set creation error" );
954 
955  currentMosaicSquenceInfo.clear();
956  }
957 
958  return true;
959  }
960 
961  void SequenceMosaic::reset() throw( te::rp::Exception )
962  {
964  m_isInitialized = false;
965  }
966 
968  throw( te::rp::Exception )
969  {
970  reset();
971 
972  SequenceMosaic::InputParameters const* inputParamsPtr = dynamic_cast<
973  SequenceMosaic::InputParameters const* >( &inputParams );
974  TERP_TRUE_OR_THROW( inputParamsPtr, "Invalid paramters pointer" );
975 
976  m_inputParameters = *inputParamsPtr;
977 
978  // Checking the feeder
979 
981  "Invalid m_feederRasterPtr" )
982 
985  "Invalid number of rasters" )
986 
987  // checking m_inputRastersBands
988 
990  ((unsigned int)m_inputParameters.m_inputRastersBands.size()) ==
992  "Bands mismatch" );
993 
995 
996  for( std::vector< std::vector< unsigned int > >::size_type
997  inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
998  m_inputParameters.m_inputRastersBands.size() ; ++inputRastersBandsIdx )
999  {
1001  != 0, "Invalid raster" )
1002 
1004  inputRastersBandsIdx ].size() > 0, "Invalid bands number" );
1005 
1007  inputRastersBandsIdx ].size() == m_inputParameters.m_inputRastersBands[
1008  0 ].size(), "Bands number mismatch" );
1009 
1010  for( std::vector< unsigned int >::size_type currRasterBandidx = 0 ;
1011  currRasterBandidx < m_inputParameters.m_inputRastersBands[
1012  inputRastersBandsIdx ].size() ; ++currRasterBandidx )
1013  {
1015  inputRastersBandsIdx ][ currRasterBandidx ] <
1017  "Invalid band index" );
1018 
1020  m_inputParameters.m_inputRastersBands[ inputRastersBandsIdx ].size(),
1021  "Invalid parameter m_tiePointsLocationBandIndex" );
1022  }
1023 
1025  }
1026 
1030  "Invalid parameter m_minRequiredTiePointsCoveredAreaPercent" );
1031 
1032  m_isInitialized = true;
1033 
1034  return true;
1035  }
1036 
1038  {
1039  return m_isInitialized;
1040  }
1041 
1043  const bool& forceNoDataValue,
1044  const double& noDataValue,
1045  double& mean, double& variance )
1046  {
1047  mean = 0;
1048  variance = 0;
1049 
1050  double internalNoDataValue = 0;
1051  if( forceNoDataValue )
1052  internalNoDataValue = noDataValue;
1053  else
1054  internalNoDataValue = band.getProperty()->m_noDataValue;
1055 
1056  const unsigned int nCols = band.getProperty()->m_blkw *
1057  band.getProperty()->m_nblocksx;
1058  const unsigned int nLines = band.getProperty()->m_blkh *
1059  band.getProperty()->m_nblocksy;
1060 
1061  double pixelsNumber = 0;
1062  double value = 0;
1063  unsigned int col = 0;
1064  unsigned int line = 0;
1065 
1066  for( line = 0 ; line < nLines ; ++line )
1067  for( col = 0 ; col < nCols ; ++col )
1068  {
1069  band.getValue( col, line, value );
1070 
1071  if( value != internalNoDataValue )
1072  {
1073  mean += value;
1074  ++pixelsNumber;
1075  }
1076  }
1077 
1078  if( pixelsNumber != 0.0 )
1079  {
1080  mean /= pixelsNumber;
1081 
1082  for( line = 0 ; line < nLines ; ++line )
1083  for( col = 0 ; col < nCols ; ++col )
1084  {
1085  band.getValue( col, line, value );
1086 
1087  if( value != internalNoDataValue )
1088  {
1089  variance += ( ( value - mean ) * ( value - mean ) ) / pixelsNumber;
1090  }
1091  }
1092 
1093  }
1094  }
1095 
1096  bool SequenceMosaic::createRasterDataSet( const std::string& dataSetName,
1097  const te::rst::Raster& sourceRaster, te::da::DataSource* dataSourcePtr ) const
1098  {
1099  if( dataSetName.empty() ) return false;
1100  if( ! ( sourceRaster.getAccessPolicy() & te::common::RAccess ) ) return false;
1101  if( dataSourcePtr == 0 ) return false;
1102  if( ! dataSourcePtr->isValid() ) return false;
1103 
1104  const unsigned int nRows = sourceRaster.getNumberOfRows();
1105  const unsigned int nCols = sourceRaster.getNumberOfColumns();
1106  const unsigned int nBands = sourceRaster.getNumberOfBands();
1107 
1108  std::vector< te::rst::BandProperty* > bandsProperties;
1109  unsigned int bandIdx = 0;
1110  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1111  {
1112  bandsProperties.push_back( new te::rst::BandProperty(
1113  *( sourceRaster.getBand( bandIdx )->getProperty()) ) );
1114  }
1115 
1116  te::rp::RasterHandler outRasterHandler;
1117  if( ! te::rp::CreateNewRaster( *( sourceRaster.getGrid() ),
1118  bandsProperties, dataSetName, *dataSourcePtr, outRasterHandler) )
1119  return false;
1120 
1121  unsigned int col = 0;
1122  unsigned int row = 0;
1123  double value = 0;
1124 
1125  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1126  {
1127  const te::rst::Band& inBand = *(sourceRaster.getBand( bandIdx ));
1128  te::rst::Band& outBand = *(outRasterHandler.getRasterPtr()->getBand( bandIdx ));
1129 
1130  for( row = 0 ; row < nRows ; ++row )
1131  {
1132  for( col = 0 ; col < nCols ; ++col )
1133  {
1134  inBand.getValue( col, row, value );
1135  outBand.setValue( col, row, value );
1136  }
1137  }
1138  }
1139 
1140  return true;
1141  }
1142 
1143  bool SequenceMosaic::createDiskRasterCopy( const std::string& fileName,
1144  const te::rst::Raster& sourceRaster ) const
1145  {
1146  std::map<std::string, std::string> rInfo;
1147  rInfo["URI"] = fileName;
1148 
1149  const unsigned int nBands = sourceRaster.getNumberOfBands();
1150 
1151  std::vector<te::rst::BandProperty*> bandsProperties;
1152  unsigned int bandIdx = 0;
1153  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1154  bandsProperties.push_back(new te::rst::BandProperty(
1155  *sourceRaster.getBand( bandIdx )->getProperty() ) );
1156 
1157  te::rst::Grid* newgrid = new te::rst::Grid( *sourceRaster.getGrid() );
1158 
1159  std::auto_ptr< te::rst::Raster > outputRasterPtr(
1160  te::rst::RasterFactory::make( "GDAL", newgrid, bandsProperties, rInfo, 0, 0));
1161  if( outputRasterPtr.get() == 0 ) return false;
1162 
1163  unsigned int line = 0;
1164  unsigned int col = 0;
1165  const unsigned int nLines = sourceRaster.getNumberOfRows();
1166  const unsigned int nCols = sourceRaster.getNumberOfColumns();
1167 
1168  double value = 0;
1169 
1170  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1171  {
1172  const te::rst::Band& inBand = *sourceRaster.getBand( bandIdx );
1173  te::rst::Band& outBand = *outputRasterPtr->getBand( bandIdx );
1174 
1175  for( line = 0 ; line < nLines ; ++line )
1176  for( col = 0 ; col < nCols ; ++col )
1177  {
1178  inBand.getValue( col, line, value );
1179  outBand.setValue( col, line, value );
1180  }
1181  }
1182 
1183  return true;
1184  }
1185 
1187  const std::vector< te::gm::GTParameters::TiePoint >& tiePoints,
1188  const bool useTPSecondCoordPair ) const
1189  {
1190  if( tiePoints.size() < 3 )
1191  {
1192  return 0;
1193  }
1194  else
1195  {
1197 
1198  for( unsigned int tiePointsIdx = 0 ; tiePointsIdx < tiePoints.size() ;
1199  ++tiePointsIdx )
1200  {
1201  if( useTPSecondCoordPair )
1202  points.add( new te::gm::Point( tiePoints[ tiePointsIdx ].second.x,
1203  tiePoints[ tiePointsIdx ].second.y ) );
1204  else
1205  points.add( new te::gm::Point( tiePoints[ tiePointsIdx ].first.x,
1206  tiePoints[ tiePointsIdx ].first.y ) );
1207  }
1208 
1209  std::auto_ptr< te::gm::Polygon > convexHullPolPtr(
1210  dynamic_cast< te::gm::Polygon* >( points.convexHull() ) );
1211 
1212  if( convexHullPolPtr.get() )
1213  return convexHullPolPtr->getArea();
1214  else
1215  return 0.0;
1216  }
1217  }
1218 
1219  } // end namespace rp
1220 } // end namespace te
1221 
virtual unsigned int getObjsCount() const =0
Return the total number of feeder objects.
AbstractParameters * clone() const
Create a clone copy of this instance.
std::string m_geomTransfName
The name of the geometric transformation used if tie-points are supplied (see each te::gm::GTFactory ...
int m_blkh
Block height (pixels).
Definition: BandProperty.h:144
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
bool m_useRasterCache
Enable(true) or disable the use of raster caching (default:true).
bool m_enableProgress
Enable/Disable the progress interface (default:false).
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
Definition: Geometry.h:189
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
The generated tie-pionts (te::gm::GTParameters::TiePoint::first are raster 1 line/column indexes...
const OutputParameters & operator=(const OutputParameters &params)
virtual te::rst::Raster const * getCurrentObj() const =0
Return the current sequence object.
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
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.
Definition: Raster.cpp:233
std::string m_outDataSetsNamePrefix
The raster output data sets names prefix.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
Definition: Raster.cpp:208
Tie points locator.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
ColorInterp m_colorInterp
The color interpretation.
Definition: BandProperty.h:140
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
te::rst::Raster const * m_inMaskRaster2Ptr
Optional one band input mask raster 2 (tie-points will not be generated inside mask image areas marke...
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
Definition: Raster.cpp:218
virtual unsigned int getCurrentOffset() const =0
Return the index of the current object.
Raster Processing functions.
std::vector< MosaicSequenceInfo > m_sequencesInfo
void setSRID(int srid)
It sets the Spatial Reference System ID of the geometry and all its parts if it is a GeometryCollecti...
virtual Geometry * convexHull() const
This method calculates the Convex Hull of a geometry.
Definition: Geometry.cpp:439
unsigned int m_raster2TargetAreaWidth
The raster 2 target area width (default:0 - The entire raster will be considered).
te::rp::Blender::BlendMethod m_blendMethod
The pixel blending method (default: NoBlendMethod).
std::auto_ptr< te::gm::GeometricTransformation > m_transformationPtr
The generated geometric transformation with the base mininum required tie-points set ( depending on t...
te::da::DataSource * m_outputDSPtr
The mosaic sequences info.
Grid * getGrid()
It returns the raster grid.
Definition: Raster.cpp:94
std::vector< unsigned int > m_inRaster1Bands
Bands to be used from the input raster 1.
std::vector< unsigned int > m_rasterFeederIndexes
The indexes (inside the input rasters feeder) of the rasters written to this mosaic sequence...
bool m_enableGeometryFilter
Enable/disable the geometry filter/outliers remotion (default:true).
unsigned int m_raster2TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
static Raster * make()
It creates and returns an empty raster with default raster driver.
No blending performed.
Definition: Blender.h:61
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
unsigned int m_tiePointsLocationBandIndex
The band used to locate tie-points, this is the index inside each vector of m_inputRastersBands (defa...
double m_noDataValue
The pixel value used where no raster data is avaliable (defaul:0).
int m_nblocksy
The number of blocks in y.
Definition: BandProperty.h:146
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
Blended pixel value calculation for two overlaped rasters.
Definition: Blender.h:53
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
void getBlendedValues(const double &line, const double &col, std::vector< double > &values)
Blend a pixel value using the current parameters.
Definition: Blender.h:118
double getTPConvexHullArea(const std::vector< te::gm::GTParameters::TiePoint > &tiePoints, const bool useTPSecondCoordPair) const
Returns the tie points converx hull area.
void add(Geometry *g)
It adds the geometry into the collection.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
#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...
Definition: Macros.h:183
double m_pixelSizeXRelation
The pixel resolution relation m_pixelSizeXRelation = raster1_pixel_res_x / raster2_pixel_res_x (defau...
std::string m_outDataSetsNameSufix
The raster output data sets names sufix.
Abstract parameters base interface.
std::vector< TiePoint > m_tiePoints
Tie points.
Definition: GTParameters.h:95
A raster band description.
Definition: Band.h:63
A rectified grid is the spatial support for raster data.
Definition: Grid.h:55
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
TiePointsLocator input parameters.
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
FeederConstRaster * m_feederRasterPtr
Input rasters feeder.
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
bool m_enableMultiThread
Enable/Disable the use of multi-threads (default:true).
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
Definition: Grid.cpp:276
bool m_enableProgress
Enable/Disable the progress interface (default:false).
void clear()
It deletes all the rings of the CurvePolygon and clear it.
Create mosaics from a sequence of overlapped rasters using an automatic tie-points detection method...
bool m_autoEqualize
Auto equalization will be performed using the overlaped image areas (default:true).
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
unsigned int m_raster2TargetAreaLineStart
The first line of the raster 2 target area to process (default:0 - The entire raster will be consider...
A point with x and y coordinate values.
Definition: Point.h:50
std::vector< std::vector< te::gm::GTParameters::TiePoint > > m_tiePoints
The generated tie-pionts (te::gm::GTParameters::TiePoint::first are mosaic coods, te::gm::GTParameter...
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.
Definition: Functions.cpp:67
unsigned int m_raster1TargetAreaLineStart
The first line of the raster 1 target area to process (default:0 - The entire raster will be consider...
#define SEQUENCE_RASTER_MAX_MOSAIC_MEM_USE
std::vector< std::vector< unsigned int > > m_inputRastersBands
Bands to process for each input raster.
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
unsigned int m_raster2TargetAreaHeight
The raster 2 target area height (default:0 - The entire raster will be considered).
const InputParameters & operator=(const InputParameters &params)
std::string m_geomTransfName
The name of the geometric transformation used to ensure tie-points consistency (see each te::gm::GTFa...
SequenceMosaic::InputParameters m_inputParameters
Input execution parameters.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
Definition: Raster.cpp:213
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
const Algorithm & operator=(const Algorithm &)
Definition: Algorithm.cpp:43
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:116
virtual te::dt::AbstractData * clone() const
It clones the linestring.
Definition: Polygon.cpp:52
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
Definition: LineString.cpp:313
RasterHandler.
Definition: RasterHandler.h:47
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
A raster band description.
Definition: BandProperty.h:61
std::vector< unsigned int > m_inRaster2Bands
Bands to be used from the input raster 2.
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits&lt;double&gt;::max().
Definition: BandProperty.h:136
bool createDiskRasterCopy(const std::string &fileName, const te::rst::Raster &sourceRaster) const
Create copy of the given raster into a disk file.
virtual void reset()=0
Reset the feeder to the first position (subsequent accesses will start from the first sequence obejct...
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
Definition: Macros.h:149
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
static void calcBandStatistics(const te::rst::Band &band, const bool &forceNoDataValue, const double &noDataValue, double &mean, double &variance)
Raster band statistics calcule.
double m_pixelSizeYRelation
The pixel resolution relation m_pixelSizeYRelation = raster1_pixel_res_y / raster2_pixel_res_y (defau...
A RAM cache adaptor to an external existent raster that must always be avaliable. ...
Definition: CachedRaster.h:50
std::string m_dataSetName
The generated data set name for this mosaic sequence.
te::rst::Raster const * m_inMaskRaster1Ptr
Optional one band input mask raster 1 (tie-points will not be generated inside mask image areas marke...
Raster Processing algorithm output parameters base interface.
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
int m_nblocksx
The number of blocks in x.
Definition: BandProperty.h:145
An abstract class for raster data strucutures.
Definition: Raster.h:70
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:50
BandProperty * getProperty()
Returns the band property.
Definition: Band.cpp:370
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
unsigned int m_raster1TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
te::rst::Raster * getRasterPtr()
Returns a pointer the the handled raster instance or NULL if no instance is handled.
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
Definition: Raster.cpp:223
int getSRID() const
Returns the grid spatial reference system identifier.
Definition: Grid.cpp:266
te::rp::TiePointsLocator::InputParameters m_locatorParams
The parameters used by the tie-points locator when processing each rasters pair (leave untouched to u...
void clear()
Clear the internal allocated resources.
double m_minRequiredTiePointsCoveredAreaPercent
The mininumum required tie-points covered area percent of each raster area - valid range [0...
unsigned int m_raster1TargetAreaWidth
The raster 1 target area width (default:0 - The entire raster will be considered).
2D Geometric transformation parameters.
Definition: GTParameters.h:50
bool createRasterDataSet(const std::string &dataSetName, const te::rst::Raster &sourceRaster, te::da::DataSource *dataSourcePtr) const
Create a raster data set from the given raster.
te::rst::Raster const * m_inRaster1Ptr
Input raster 1.
bool m_enableMultiThread
Enable/Disable the use of multi-threads (default:true).
Near neighborhood interpolation method.
Definition: Interpolator.h:60
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
Definition: Utils.cpp:331
bool m_isInitialized
Tells if this instance is initialized.
unsigned int m_raster1TargetAreaHeight
The raster 1 target area height (default:0 - The entire raster will be considered).
Index into a lookup table.
Definition: Enums.h:57
bool m_forceInputNoDataValue
If true, m_noDataValue will be used as the no-data value for input rasters (defalt:false).
te::rst::Raster const * m_inRaster2Ptr
Input raster 2.
void push_back(Curve *ring)
It adds the curve to the curve polygon.
Definition: CurvePolygon.h:279
bool initialize(const te::rst::Raster &raster1, const std::vector< unsigned int > &raster1Bands, const te::rst::Raster &raster2, const std::vector< unsigned int > &raster2Bands, const BlendMethod &blendMethod, const te::rst::Interpolator::Method &interpMethod1, const te::rst::Interpolator::Method &interpMethod2, const double &noDataValue, const bool forceInputNoDataValue, const std::vector< double > &pixelOffsets1, const std::vector< double > &pixelScales1, const std::vector< double > &pixelOffsets2, const std::vector< double > &pixelScales2, te::gm::Polygon const *const r1ValidDataDelimiterPtr, te::gm::Polygon const *const r2ValidDataDelimiterPtr, const te::gm::GeometricTransformation &geomTransformation)
Inititate the blender instance.
Definition: Blender.cpp:81
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
Definition: Raster.cpp:89
virtual bool moveNext()=0
Advances to the next sequence obeject.
Raster tuple.
Raster Processing algorithm input parameters base interface.
AbstractParameters * clone() const
Create a clone copy of this instance.
TiePointsLocator output parameters.
virtual bool isValid() const =0
It checks if the data source is valid (available for using).