All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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::MultiPolygon mosaicValidAreaPols( 0, te::gm::MultiPolygonType, 0 ); // the polygons 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 
290  inputRasterPtr->getGrid()->getSRID(), 0 );
291  outPolPtr->add( auxLinearRingPtr );
292 
293  mosaicValidAreaPols.clear();
294  mosaicValidAreaPols.add( outPolPtr );
295  mosaicValidAreaPols.setSRID( inputRasterPtr->getGrid()->getSRID() );
296 
297  lastInputRasterBBoxLLXIndexed = 0;
298  lastInputRasterBBoxLLYIndexed = inputRasterPtr->getNumberOfRows() - 1;
299  lastInputRasterBBoxURXIndexed = inputRasterPtr->getNumberOfColumns() - 1;
300  lastInputRasterBBoxURYIndexed = 0;
301 
302  mosaicBandsRangeMin.resize(
303  m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size(), 0 );
304  mosaicBandsRangeMax.resize(
305  m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size(), 0 );
306 
307  std::vector< te::rst::BandProperty* > bandsProperties;
308  for( std::vector< unsigned int >::size_type inputRastersBandsIdx = 0 ;
309  inputRastersBandsIdx <
310  m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size() ;
311  ++inputRastersBandsIdx )
312  {
313  te::rst::BandProperty const* const inBandPropPtr =
315  inputRasterIdx ][ inputRastersBandsIdx ] )->getProperty();
316 
317  bandsProperties.push_back( new te::rst::BandProperty( *inBandPropPtr ) );
318  bandsProperties[ inputRastersBandsIdx ]->m_colorInterp = te::rst::GrayIdxCInt;
319  bandsProperties[ inputRastersBandsIdx ]->m_noDataValue = m_inputParameters.m_noDataValue;
320  bandsProperties[ inputRastersBandsIdx ]->m_blkw = (unsigned int)
321  std::ceil( ((double)inputRasterPtr->getNumberOfColumns()) / 4.0 );
322  bandsProperties[ inputRastersBandsIdx ]->m_blkh = (unsigned int)
323  std::ceil( ((double)inputRasterPtr->getNumberOfRows()) / 4.0 );
324  bandsProperties[ inputRastersBandsIdx ]->m_nblocksx = (unsigned int)
325  std::ceil( ((double)inputRasterPtr->getNumberOfColumns()) /
326  ((double)bandsProperties[ inputRastersBandsIdx ]->m_blkw ) );
327  bandsProperties[ inputRastersBandsIdx ]->m_nblocksy = (unsigned int)
328  std::ceil( ((double)inputRasterPtr->getNumberOfRows()) /
329  ((double)bandsProperties[ inputRastersBandsIdx ]->m_blkh ) );
330 
331  te::rst::GetDataTypeRanges( bandsProperties[ inputRastersBandsIdx ]->m_type,
332  mosaicBandsRangeMin[ inputRastersBandsIdx ],
333  mosaicBandsRangeMax[ inputRastersBandsIdx ]);
334  }
335 
336  mosaicRasterHandler.reset(
338  new te::rst::Grid( *( inputRasterPtr->getGrid() ) ),
339  bandsProperties ) );
340  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler.get(),
341  "Output raster creation error" );
342 
343  const unsigned int nBands = mosaicRasterHandler->getNumberOfBands();
344 
345  mosaicTargetMeans.resize( nBands, 0.0 );
346  mosaicTargetVariances.resize( nBands, 0.0 );
347 
348  for( unsigned int inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
349  nBands ; ++inputRastersBandsIdx )
350  {
351  const unsigned int inputBandIdx =
352  m_inputParameters.m_inputRastersBands[ inputRasterIdx ][ inputRastersBandsIdx ] ;
353  const double& bandNoDataValue = m_inputParameters.m_forceInputNoDataValue ?
354  m_inputParameters.m_noDataValue : inputRasterPtr->getBand( inputBandIdx
356  const unsigned int outRowsBound = inputRasterPtr->getNumberOfRows();
357  const unsigned int outColsBound = inputRasterPtr->getNumberOfColumns();
358  te::rst::Band& outBand =
359  (*mosaicRasterHandler->getBand( inputRastersBandsIdx ));
360  const te::rst::Band& inBand =
361  (*inputRasterPtr->getBand( inputBandIdx ));
362  unsigned int validPixelsNumber = 0;
363  unsigned int outCol = 0;
364  unsigned int outRow = 0;
365  double pixelValue = 0;
366 
367  double& mean = mosaicTargetMeans[ inputRastersBandsIdx ];
368  mean = 0;
369 
370  for( outRow = 0 ; outRow < outRowsBound ; ++outRow )
371  {
372  for( outCol = 0 ; outCol < outColsBound ; ++outCol )
373  {
374  inBand.getValue( outCol, outRow, pixelValue );
375 
376  if( pixelValue != bandNoDataValue )
377  {
378  outBand.setValue( outCol, outRow, pixelValue );
379 
380  mean += pixelValue;
381  ++validPixelsNumber;
382  }
383 
384  }
385  }
386 
387  mean /= ( (double)validPixelsNumber );
388 
389  // variance calcule
390 
392  {
393  double& variance = mosaicTargetVariances[ inputRastersBandsIdx ];
394  variance = 0;
395 
396  double pixelValue = 0;
397 
398  for( outRow = 0 ; outRow < outRowsBound ; ++outRow )
399  {
400  for( outCol = 0 ; outCol < outColsBound ; ++outCol )
401  {
402  outBand.getValue( outCol, outRow, pixelValue );
403 
404  if( pixelValue != bandNoDataValue )
405  {
406  variance += ( ( pixelValue - mean ) * ( pixelValue -
407  mean ) ) / ( (double)validPixelsNumber );
408  }
409  }
410  }
411  }
412  }
413 
414  // Updating the mosaic sequence info
415 
416  currentMosaicSquenceInfo.m_rasterFeederIndexes.push_back(
417  inputRasterIdx );
418  currentMosaicSquenceInfo.m_tiePoints.push_back(
419  std::vector< te::gm::GTParameters::TiePoint >() );
420 
421  // Move to the next raster
422 
423  cachedInputRasterPtr.reset();
424 
426 
428  {
429  progressPtr->pulse();
430  if( ! progressPtr->isActive() ) return false;
431  }
432  }
433  else
434  {
435  // Locating the tie points where te::gm::GTParameters::TiePoint::first
436  // are :mosaic indexed coods and te::gm::GTParameters::TiePoint::second are
437  // indexed coords from the current raster
438 
440 
441  {
443  locatorInParams = m_inputParameters.m_locatorParams;
444 
445  locatorInParams.m_inRaster1Ptr = mosaicRasterHandler.get();
446 
447  locatorInParams.m_inMaskRaster1Ptr = 0;
448 
449  locatorInParams.m_inRaster1Bands.clear();
450  locatorInParams.m_inRaster1Bands.push_back(
452 
453  locatorInParams.m_raster1TargetAreaColStart = lastInputRasterBBoxLLXIndexed;
454  locatorInParams.m_raster1TargetAreaLineStart = lastInputRasterBBoxURYIndexed;
455  locatorInParams.m_raster1TargetAreaWidth = (unsigned int)(
456  lastInputRasterBBoxURXIndexed - lastInputRasterBBoxLLXIndexed + 1 );
457  locatorInParams.m_raster1TargetAreaHeight = (unsigned int)(
458  lastInputRasterBBoxLLYIndexed - lastInputRasterBBoxURYIndexed + 1 );
459 
460  locatorInParams.m_inRaster2Ptr = inputRasterPtr;
461 
462  locatorInParams.m_inMaskRaster2Ptr = 0;
463 
464  locatorInParams.m_inRaster2Bands.clear();
465  locatorInParams.m_inRaster2Bands.push_back(
466  m_inputParameters.m_inputRastersBands[ inputRasterIdx ][
468 
469  locatorInParams.m_raster2TargetAreaLineStart = 0;
470  locatorInParams.m_raster2TargetAreaColStart = 0;
471  locatorInParams.m_raster2TargetAreaWidth = 0;
472  locatorInParams.m_raster2TargetAreaHeight = 0;
473 
475 
476  locatorInParams.m_enableProgress = false;
477 
478  locatorInParams.m_pixelSizeXRelation = mosaicRasterHandler->getResolutionX() /
479  inputRasterPtr->getResolutionX();
480  locatorInParams.m_pixelSizeYRelation = mosaicRasterHandler->getResolutionY() /
481  inputRasterPtr->getResolutionY();
482 
484 
485  locatorInParams.m_enableGeometryFilter = true;
486 
488 
489  te::rp::TiePointsLocator locatorInstance;
490  TERP_TRUE_OR_RETURN_FALSE( locatorInstance.initialize(
491  locatorInParams ), "Tie points locator init error" );
492  TERP_TRUE_OR_RETURN_FALSE( locatorInstance.execute(
493  locatorOutParams ), "Tie points locator exec error" );
494  }
495 
496  // The matching was accomplished successfully ?
497 
498  if(
499  ( locatorOutParams.m_transformationPtr.get() == 0 )
500  ||
501  (
502  locatorOutParams.m_tiePoints.size()
503  <
504  (
505  2
506  *
507  locatorOutParams.m_transformationPtr->getMinRequiredTiePoints()
508  )
509  )
510  ||
511  (
512  (
513  getTPConvexHullArea( locatorOutParams.m_tiePoints, true )
514  /
515  (double)(
516  inputRasterPtr->getNumberOfColumns()
517  *
518  inputRasterPtr->getNumberOfRows()
519  )
520  )
521  <
522  (
524  /
525  100.0
526  )
527  )
528  )
529  {
530  // Saving the mosaic sequence info
531 
532  currentMosaicSquenceInfo.m_dataSetName = m_inputParameters.m_outDataSetsNamePrefix +
533  boost::lexical_cast< std::string >( outParamsPtr->m_sequencesInfo.size() ) +
535 
536  outParamsPtr->m_sequencesInfo.push_back( currentMosaicSquenceInfo );
537 
538  // Create the output data set
539 
540  assert( mosaicRasterHandler.get() );
542  currentMosaicSquenceInfo.m_dataSetName,
543  *( mosaicRasterHandler.get() ), outParamsPtr->m_outputDSPtr ),
544  "Data set creation error" );
545  mosaicRasterHandler.reset();
546 
547  currentMosaicSquenceInfo.clear();
548  }
549  else
550  {
551  // Generating the offset and gain info for eath band from the current raster
552 
553  std::vector< double > currentRasterBandsOffsets;
554  std::vector< double > currentRasterBandsScales;
555 
557  {
558  double currentRasterVariance = 0;
559  double currentRasterMean = 0;
560 
561  for( unsigned int inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
562  m_inputParameters.m_inputRastersBands[ inputRasterIdx ].size() ;
563  ++inputRastersBandsIdx )
564  {
565  const unsigned int inputBandIdx = m_inputParameters.m_inputRastersBands[ inputRasterIdx ][
566  inputRastersBandsIdx ];
567 
568  calcBandStatistics( (*inputRasterPtr->getBand( inputBandIdx ) ),
571  currentRasterMean,
572  currentRasterVariance );
573 
574  currentRasterBandsScales.push_back( std::sqrt( mosaicTargetVariances[ inputRastersBandsIdx ] /
575  currentRasterVariance ) );
576  currentRasterBandsOffsets.push_back( mosaicTargetMeans[ inputRastersBandsIdx ] -
577  ( currentRasterBandsScales[ inputRastersBandsIdx ] * currentRasterMean ) );
578  }
579  }
580  else
581  {
582  currentRasterBandsOffsets = dummyRasterOffsets;
583  currentRasterBandsScales = dummyRasterScales;
584  }
585 
586  // Updating the mosaic sequence info
587 
588  currentMosaicSquenceInfo.m_tiePoints.push_back(
589  locatorOutParams.m_tiePoints );
590  currentMosaicSquenceInfo.m_rasterFeederIndexes.push_back(
591  inputRasterIdx );
592 
593  // Expanding the mosaic to fit the extent requirement allowing the
594  // merge of the current raster.
595  // Fiding the new geometric transformation between then.
596 
597  std::auto_ptr< te::gm::GeometricTransformation > geoTransPtr(
598  locatorOutParams.m_transformationPtr->clone() );
599 
600  {
601  const double oldLLYIndexed =
602  (double)( inputRasterPtr->getNumberOfRows() - 1 );
603  const double oldURXIndexed =
604  (double)( inputRasterPtr->getNumberOfColumns() - 1 );
605 
606  double mappedLLX = 0;
607  double mappedLLY = 0;
608  double mappedLRX = 0;
609  double mappedLRY = 0;
610  double mappedURX = 0;
611  double mappedURY = 0;
612  double mappedULX = 0;
613  double mappedULY = 0;
614  locatorOutParams.m_transformationPtr->inverseMap(
615  0.0,
616  oldLLYIndexed,
617  mappedLLX,
618  mappedLLY);
619  locatorOutParams.m_transformationPtr->inverseMap(
620  oldURXIndexed,
621  oldLLYIndexed,
622  mappedLRX,
623  mappedLRY);
624  locatorOutParams.m_transformationPtr->inverseMap(
625  oldURXIndexed,
626  0.0,
627  mappedURX,
628  mappedURY);
629  locatorOutParams.m_transformationPtr->inverseMap(
630  0.0,
631  0.0,
632  mappedULX,
633  mappedULY);
634 
635  const double newLLXIndexed = std::min( mappedLLX, std::min( mappedLRX, std::min( mappedURX, mappedULX ) ) );
636  const double newLLYIndexed = std::max( mappedLLY, std::max( mappedLRY, std::max( mappedURY, mappedULY ) ) );
637  const double newURXIndexed = std::max( mappedLLX, std::max( mappedLRX, std::max( mappedURX, mappedULX ) ) );
638  const double newURYIndexed = std::min( mappedLLY, std::min( mappedLRY, std::min( mappedURY, mappedULY ) ) );
639 
640  double oldMosaicReferenceX = 0;
641  double oldMosaicReferenceY = 0;
642  mosaicRasterHandler->getGrid()->gridToGeo( 0.0, 0.0, oldMosaicReferenceX,
643  oldMosaicReferenceY );
644 
645  double mosaicReferenceHasChanged = false;
646 
647 
648  if( newLLXIndexed < 0.0 )
649  {
650  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addLeftColumns(
651  (unsigned int)std::ceil( -1.0 * newLLXIndexed ) ),
652  "Mosaic expansion error" );
653  mosaicReferenceHasChanged = true;
654  }
655 
656  if( newURYIndexed < 0.0 )
657  {
658  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addTopLines(
659  (unsigned int)std::ceil( -1.0 * newURYIndexed ) ),
660  "Mosaic expansion error" );
661  mosaicReferenceHasChanged = true;
662  }
663 
664  if( newURXIndexed > ((double)(mosaicRasterHandler->getNumberOfColumns() - 1) ) )
665  {
666  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addRightColumns(
667  (unsigned int)std::ceil( newURXIndexed -
668  ((double)(mosaicRasterHandler->getNumberOfColumns() - 1)) ) ),
669  "Mosaic expansion error" );
670  }
671 
672  if( newLLYIndexed > ((double)(mosaicRasterHandler->getNumberOfRows() - 1) ) )
673  {
674  TERP_TRUE_OR_RETURN_FALSE( mosaicRasterHandler->addBottomLines(
675  (unsigned int)std::ceil( newLLYIndexed -
676  ((double)(mosaicRasterHandler->getNumberOfRows() - 1) ) ) ),
677  "Mosaic expansion error" );
678  }
679 
680  // updating the geometric transformation between both rasters
681 
682  if( mosaicReferenceHasChanged )
683  {
684  double expansionOffSetX = 0;
685  double expansionOffSetY = 0;
686  mosaicRasterHandler->getGrid()->geoToGrid( oldMosaicReferenceX,
687  oldMosaicReferenceY, expansionOffSetX, expansionOffSetY );
688 
689  te::gm::GTParameters newTransParams;
690  newTransParams.m_tiePoints =
691  geoTransPtr->getParameters().m_tiePoints;
692 
693  for( unsigned int tpIdx = 0 ; tpIdx <
694  newTransParams.m_tiePoints.size() ; ++tpIdx )
695  {
696  newTransParams.m_tiePoints[ tpIdx ].first.x += expansionOffSetX;
697  newTransParams.m_tiePoints[ tpIdx ].first.y += expansionOffSetY;
698  }
699 
700  TERP_TRUE_OR_RETURN_FALSE( geoTransPtr->initialize( newTransParams ),
701  "Geometric transformation parameters calcule error" );
702  }
703  }
704 
705  // Locating the current raster over the expanded mosaic
706 
707  double inputRasterMappedLLXIndexed = 0;
708  double inputRasterMappedLLYIndexed = 0;
709  double inputRasterMappedLRXIndexed = 0;
710  double inputRasterMappedLRYIndexed = 0;
711  double inputRasterMappedURXIndexed = 0;
712  double inputRasterMappedURYIndexed = 0;
713  double inputRasterMappedULXIndexed = 0;
714  double inputRasterMappedULYIndexed = 0;
715  {
716  const double lastRowIdx =
717  (double)( inputRasterPtr->getNumberOfRows() - 1 );
718  const double lastColIdx =
719  (double)( inputRasterPtr->getNumberOfColumns() - 1 );
720 
721  geoTransPtr->inverseMap(
722  0.0,
723  lastRowIdx,
724  inputRasterMappedLLXIndexed,
725  inputRasterMappedLLYIndexed);
726  geoTransPtr->inverseMap(
727  lastColIdx,
728  lastRowIdx,
729  inputRasterMappedLRXIndexed,
730  inputRasterMappedLRYIndexed);
731  geoTransPtr->inverseMap(
732  lastColIdx,
733  0.0,
734  inputRasterMappedURXIndexed,
735  inputRasterMappedURYIndexed);
736  geoTransPtr->inverseMap(
737  0.0,
738  0.0,
739  inputRasterMappedULXIndexed,
740  inputRasterMappedULYIndexed);
741 
742  lastInputRasterBBoxLLXIndexed = (unsigned int)
743  std::max( 0.0,
744  std::min( (double)( mosaicRasterHandler->getNumberOfColumns() - 1 ),
745  std::floor(
746  std::min( inputRasterMappedLLXIndexed,
747  std::min( inputRasterMappedLRXIndexed,
748  std::min( inputRasterMappedURXIndexed,
749  inputRasterMappedULXIndexed
750  )
751  )
752  )
753  )
754  )
755  );
756 
757  lastInputRasterBBoxLLYIndexed = (unsigned int)
758  std::max( 0.0,
759  std::min( (double)( mosaicRasterHandler->getNumberOfRows() - 1 ),
760  std::ceil(
761  std::max( inputRasterMappedLLYIndexed,
762  std::max( inputRasterMappedLRYIndexed,
763  std::max( inputRasterMappedURYIndexed,
764  inputRasterMappedULYIndexed
765  )
766  )
767  )
768  )
769  )
770  );
771 
772  lastInputRasterBBoxURXIndexed = (unsigned int)
773  std::max( 0.0,
774  std::min( (double)( mosaicRasterHandler->getNumberOfColumns() - 1 ),
775  std::ceil(
776  std::max( inputRasterMappedLLXIndexed,
777  std::max( inputRasterMappedLRXIndexed,
778  std::max( inputRasterMappedURXIndexed,
779  inputRasterMappedULXIndexed
780  )
781  )
782  )
783  )
784  )
785  );
786 
787  lastInputRasterBBoxURYIndexed = (unsigned int)
788  std::max( 0.0,
789  std::min( (double)( mosaicRasterHandler->getNumberOfRows() - 1 ),
790  std::floor(
791  std::min( inputRasterMappedLLYIndexed,
792  std::min( inputRasterMappedLRYIndexed,
793  std::min( inputRasterMappedURYIndexed,
794  inputRasterMappedULYIndexed
795  )
796  )
797  )
798  )
799  )
800  );
801 
802  assert( lastInputRasterBBoxLLXIndexed >= 0 );
803  assert( lastInputRasterBBoxLLXIndexed <=
804  ( mosaicRasterHandler->getNumberOfColumns() - 1 ) );
805  assert( lastInputRasterBBoxLLYIndexed >= 0 );
806  assert( lastInputRasterBBoxLLYIndexed <=
807  ( mosaicRasterHandler->getNumberOfRows() - 1 ) );
808  assert( lastInputRasterBBoxURXIndexed >= 0 );
809  assert( lastInputRasterBBoxURXIndexed <=
810  ( mosaicRasterHandler->getNumberOfColumns() - 1 ) );
811  assert( lastInputRasterBBoxURYIndexed >= 0 );
812  assert( lastInputRasterBBoxURYIndexed <=
813  ( mosaicRasterHandler->getNumberOfRows() - 1 ) );
814  }
815 
816  // Blending the current raster into the mosaic
817 
818  {
819  te::rp::Blender blenderInstance;
820 
821  TERP_TRUE_OR_RETURN_FALSE( blenderInstance.initialize(
822  *( mosaicRasterHandler.get() ),
823  dummyRasterBandsIndexes,
824  *inputRasterPtr,
825  m_inputParameters.m_inputRastersBands[ inputRasterIdx ],
831  dummyRasterOffsets,
832  dummyRasterScales,
833  currentRasterBandsOffsets,
834  currentRasterBandsScales,
835  &mosaicValidAreaPols,
836  0,
837  *geoTransPtr,
839  false ),
840  "Blender initiazing error" );
841 
842  TERP_TRUE_OR_RETURN_FALSE( blenderInstance.blendIntoRaster1(),
843  "Error blending images" );
844  }
845 
846  // updating the mosaic related polygons
847 
848  {
849 
850  double inputRasterMappedLLX = 0;
851  double inputRasterMappedLLY = 0;
852  mosaicRasterHandler->getGrid()->gridToGeo(
853  (double)inputRasterMappedLLXIndexed, (double)inputRasterMappedLLYIndexed,
854  inputRasterMappedLLX, inputRasterMappedLLY );
855 
856  double inputRasterMappedLRX = 0;
857  double inputRasterMappedLRY = 0;
858  mosaicRasterHandler->getGrid()->gridToGeo(
859  (double)inputRasterMappedLRXIndexed, (double)inputRasterMappedLRYIndexed,
860  inputRasterMappedLRX, inputRasterMappedLRY );
861 
862  double inputRasterMappedURX = 0;
863  double inputRasterMappedURY = 0;
864  mosaicRasterHandler->getGrid()->gridToGeo(
865  (double)inputRasterMappedURXIndexed, (double)inputRasterMappedURYIndexed,
866  inputRasterMappedURX, inputRasterMappedURY );
867 
868  double inputRasterMappedULX = 0;
869  double inputRasterMappedULY = 0;
870  mosaicRasterHandler->getGrid()->gridToGeo(
871  (double)inputRasterMappedULXIndexed, (double)inputRasterMappedULYIndexed,
872  inputRasterMappedULX, inputRasterMappedULY );
873 
875  auxLinearRingPtr->setPoint( 0, inputRasterMappedULX, inputRasterMappedULY );
876  auxLinearRingPtr->setPoint( 1, inputRasterMappedURX, inputRasterMappedURY );
877  auxLinearRingPtr->setPoint( 2, inputRasterMappedLRX, inputRasterMappedLRY );
878  auxLinearRingPtr->setPoint( 3, inputRasterMappedLLX, inputRasterMappedLLY );
879  auxLinearRingPtr->setPoint( 4, inputRasterMappedULX, inputRasterMappedULY );
880  te::gm::Polygon lastMosaicAddedRasterPol( 0, te::gm::PolygonType, 0 ); //the polygon of the last added raster (mosaic world coords)
881  lastMosaicAddedRasterPol.push_back( auxLinearRingPtr );
882  lastMosaicAddedRasterPol.setSRID( mosaicRasterHandler->getSRID() );
883 
884  // union of the current raster box with the current mosaic valid area under the mosaic SRID
885 
886  std::auto_ptr< te::gm::Geometry > unionMultiPolPtr(
887  mosaicValidAreaPols.Union( &lastMosaicAddedRasterPol ) );
888  TERP_TRUE_OR_THROW( unionMultiPolPtr.get(), "Invalid pointer" );
889  unionMultiPolPtr->setSRID( mosaicRasterHandler->getSRID() );
890 
891  if( unionMultiPolPtr->getGeomTypeId() == te::gm::MultiPolygonType )
892  {
893  mosaicValidAreaPols = *( (te::gm::MultiPolygon*)unionMultiPolPtr.get() );
894  }
895  else if( unionMultiPolPtr->getGeomTypeId() == te::gm::PolygonType )
896  {
897  mosaicValidAreaPols.clear();
898  mosaicValidAreaPols.setSRID( unionMultiPolPtr->getSRID() );
899  mosaicValidAreaPols.add( (te::gm::Polygon*)unionMultiPolPtr.release() );
900  }
901  else
902  {
903  TERP_LOG_AND_RETURN_FALSE( "Invalid union geometry type" );
904  }
905  }
906 
907  // Move to the next raster
908 
909  cachedInputRasterPtr.reset();
910 
912 
914  {
915  progressPtr->pulse();
916  if( ! progressPtr->isActive() ) return false;
917  }
918  }
919  }
920  }
921 
922  if( mosaicRasterHandler.get() )
923  {
924  // Saving the mosaic sequence info
925 
926  currentMosaicSquenceInfo.m_dataSetName = m_inputParameters.m_outDataSetsNamePrefix +
927  boost::lexical_cast< std::string >( outParamsPtr->m_sequencesInfo.size() ) +
929 
930  outParamsPtr->m_sequencesInfo.push_back( currentMosaicSquenceInfo );
931 
933  currentMosaicSquenceInfo.m_dataSetName,
934  *( mosaicRasterHandler.get() ), outParamsPtr->m_outputDSPtr ),
935  "Data set creation error" );
936 
937  currentMosaicSquenceInfo.clear();
938  }
939 
940  return true;
941  }
942 
943  void SequenceMosaic::reset() throw( te::rp::Exception )
944  {
946  m_isInitialized = false;
947  }
948 
950  throw( te::rp::Exception )
951  {
952  reset();
953 
954  SequenceMosaic::InputParameters const* inputParamsPtr = dynamic_cast<
955  SequenceMosaic::InputParameters const* >( &inputParams );
956  TERP_TRUE_OR_THROW( inputParamsPtr, "Invalid paramters pointer" );
957 
958  m_inputParameters = *inputParamsPtr;
959 
960  // Checking the feeder
961 
963  "Invalid m_feederRasterPtr" )
964 
967  "Invalid number of rasters" )
968 
969  // checking m_inputRastersBands
970 
972  ((unsigned int)m_inputParameters.m_inputRastersBands.size()) ==
974  "Bands mismatch" );
975 
977 
978  for( std::vector< std::vector< unsigned int > >::size_type
979  inputRastersBandsIdx = 0 ; inputRastersBandsIdx <
980  m_inputParameters.m_inputRastersBands.size() ; ++inputRastersBandsIdx )
981  {
983  != 0, "Invalid raster" )
984 
986  inputRastersBandsIdx ].size() > 0, "Invalid bands number" );
987 
989  inputRastersBandsIdx ].size() == m_inputParameters.m_inputRastersBands[
990  0 ].size(), "Bands number mismatch" );
991 
992  for( std::vector< unsigned int >::size_type currRasterBandidx = 0 ;
993  currRasterBandidx < m_inputParameters.m_inputRastersBands[
994  inputRastersBandsIdx ].size() ; ++currRasterBandidx )
995  {
997  inputRastersBandsIdx ][ currRasterBandidx ] <
999  "Invalid band index" );
1000 
1002  m_inputParameters.m_inputRastersBands[ inputRastersBandsIdx ].size(),
1003  "Invalid parameter m_tiePointsLocationBandIndex" );
1004  }
1005 
1007  }
1008 
1012  "Invalid parameter m_minRequiredTiePointsCoveredAreaPercent" );
1013 
1014  m_isInitialized = true;
1015 
1016  return true;
1017  }
1018 
1020  {
1021  return m_isInitialized;
1022  }
1023 
1025  const bool& forceNoDataValue,
1026  const double& noDataValue,
1027  double& mean, double& variance )
1028  {
1029  mean = 0;
1030  variance = 0;
1031 
1032  double internalNoDataValue = 0;
1033  if( forceNoDataValue )
1034  internalNoDataValue = noDataValue;
1035  else
1036  internalNoDataValue = band.getProperty()->m_noDataValue;
1037 
1038  const unsigned int nCols = band.getProperty()->m_blkw *
1039  band.getProperty()->m_nblocksx;
1040  const unsigned int nLines = band.getProperty()->m_blkh *
1041  band.getProperty()->m_nblocksy;
1042 
1043  double pixelsNumber = 0;
1044  double value = 0;
1045  unsigned int col = 0;
1046  unsigned int line = 0;
1047 
1048  for( line = 0 ; line < nLines ; ++line )
1049  for( col = 0 ; col < nCols ; ++col )
1050  {
1051  band.getValue( col, line, value );
1052 
1053  if( value != internalNoDataValue )
1054  {
1055  mean += value;
1056  ++pixelsNumber;
1057  }
1058  }
1059 
1060  if( pixelsNumber != 0.0 )
1061  {
1062  mean /= pixelsNumber;
1063 
1064  for( line = 0 ; line < nLines ; ++line )
1065  for( col = 0 ; col < nCols ; ++col )
1066  {
1067  band.getValue( col, line, value );
1068 
1069  if( value != internalNoDataValue )
1070  {
1071  variance += ( ( value - mean ) * ( value - mean ) ) / pixelsNumber;
1072  }
1073  }
1074 
1075  }
1076  }
1077 
1078  bool SequenceMosaic::createRasterDataSet( const std::string& dataSetName,
1079  const te::rst::Raster& sourceRaster, te::da::DataSource* dataSourcePtr ) const
1080  {
1081  if( dataSetName.empty() ) return false;
1082  if( ! ( sourceRaster.getAccessPolicy() & te::common::RAccess ) ) return false;
1083  if( dataSourcePtr == 0 ) return false;
1084  if( ! dataSourcePtr->isValid() ) return false;
1085 
1086  const unsigned int nRows = sourceRaster.getNumberOfRows();
1087  const unsigned int nCols = sourceRaster.getNumberOfColumns();
1088  const unsigned int nBands = sourceRaster.getNumberOfBands();
1089 
1090  std::vector< te::rst::BandProperty* > bandsProperties;
1091  unsigned int bandIdx = 0;
1092  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1093  {
1094  bandsProperties.push_back( new te::rst::BandProperty(
1095  *( sourceRaster.getBand( bandIdx )->getProperty()) ) );
1096  }
1097 
1098  te::rp::RasterHandler outRasterHandler;
1099  if( ! te::rp::CreateNewRaster( *( sourceRaster.getGrid() ),
1100  bandsProperties, dataSetName, *dataSourcePtr, outRasterHandler) )
1101  return false;
1102 
1103  unsigned int col = 0;
1104  unsigned int row = 0;
1105  double value = 0;
1106 
1107  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1108  {
1109  const te::rst::Band& inBand = *(sourceRaster.getBand( bandIdx ));
1110  te::rst::Band& outBand = *(outRasterHandler.getRasterPtr()->getBand( bandIdx ));
1111 
1112  for( row = 0 ; row < nRows ; ++row )
1113  {
1114  for( col = 0 ; col < nCols ; ++col )
1115  {
1116  inBand.getValue( col, row, value );
1117  outBand.setValue( col, row, value );
1118  }
1119  }
1120  }
1121 
1122  return true;
1123  }
1124 
1125  bool SequenceMosaic::createDiskRasterCopy( const std::string& fileName,
1126  const te::rst::Raster& sourceRaster ) const
1127  {
1128  std::map<std::string, std::string> rInfo;
1129  rInfo["URI"] = fileName;
1130 
1131  const unsigned int nBands = sourceRaster.getNumberOfBands();
1132 
1133  std::vector<te::rst::BandProperty*> bandsProperties;
1134  unsigned int bandIdx = 0;
1135  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1136  bandsProperties.push_back(new te::rst::BandProperty(
1137  *sourceRaster.getBand( bandIdx )->getProperty() ) );
1138 
1139  te::rst::Grid* newgrid = new te::rst::Grid( *sourceRaster.getGrid() );
1140 
1141  std::auto_ptr< te::rst::Raster > outputRasterPtr(
1142  te::rst::RasterFactory::make( "GDAL", newgrid, bandsProperties, rInfo, 0, 0));
1143  if( outputRasterPtr.get() == 0 ) return false;
1144 
1145  unsigned int line = 0;
1146  unsigned int col = 0;
1147  const unsigned int nLines = sourceRaster.getNumberOfRows();
1148  const unsigned int nCols = sourceRaster.getNumberOfColumns();
1149 
1150  double value = 0;
1151 
1152  for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
1153  {
1154  const te::rst::Band& inBand = *sourceRaster.getBand( bandIdx );
1155  te::rst::Band& outBand = *outputRasterPtr->getBand( bandIdx );
1156 
1157  for( line = 0 ; line < nLines ; ++line )
1158  for( col = 0 ; col < nCols ; ++col )
1159  {
1160  inBand.getValue( col, line, value );
1161  outBand.setValue( col, line, value );
1162  }
1163  }
1164 
1165  return true;
1166  }
1167 
1169  const std::vector< te::gm::GTParameters::TiePoint >& tiePoints,
1170  const bool useTPSecondCoordPair ) const
1171  {
1172  if( tiePoints.size() < 3 )
1173  {
1174  return 0;
1175  }
1176  else
1177  {
1179 
1180  for( unsigned int tiePointsIdx = 0 ; tiePointsIdx < tiePoints.size() ;
1181  ++tiePointsIdx )
1182  {
1183  if( useTPSecondCoordPair )
1184  points.add( new te::gm::Point( tiePoints[ tiePointsIdx ].second.x,
1185  tiePoints[ tiePointsIdx ].second.y ) );
1186  else
1187  points.add( new te::gm::Point( tiePoints[ tiePointsIdx ].first.x,
1188  tiePoints[ tiePointsIdx ].first.y ) );
1189  }
1190 
1191  std::auto_ptr< te::gm::Geometry > convexHullPolPtr( points.convexHull() );
1192 
1193  if( dynamic_cast< te::gm::Surface* >( convexHullPolPtr.get() ) )
1194  {
1195  return dynamic_cast< te::gm::Surface* >( convexHullPolPtr.get() )->getArea();
1196  }
1197  else
1198  {
1199  return 0.0;
1200  }
1201  }
1202  }
1203 
1204  } // end namespace rp
1205 } // end namespace te
1206 
virtual unsigned int getObjsCount() const =0
Return the total number of feeder objects.
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
void add(Curve *ring)
It adds the ring to the curve polygon.
Definition: CurvePolygon.h:267
void push_back(Curve *ring)
It adds the curve to the curve polygon.
Definition: CurvePolygon.h:279
bool createDiskRasterCopy(const std::string &fileName, const te::rst::Raster &sourceRaster) const
Create copy of the given raster into a disk file.
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
virtual bool isValid() const =0
It checks if the data source is valid (available for using).
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
The generated tie-pionts (te::gm::GTParameters::TiePoint::first are raster 1 line/column indexes...
bool m_useRasterCache
Enable(true) or disable the use of raster caching (default:true).
bool m_enableGeometryFilter
Enable/disable the geometry filter/outliers remotion (default:true).
std::vector< TiePoint > m_tiePoints
Tie points.
Definition: GTParameters.h:95
bool m_enableProgress
Enable/Disable the progress interface (default:false).
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
Definition: Utils.cpp:331
Index into a lookup table.
Definition: Enums.h:57
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
void setSRID(int srid)
It sets the Spatial Reference System ID of the geometry and all its parts if it is a GeometryCollecti...
double m_pixelSizeXRelation
The pixel resolution relation m_pixelSizeXRelation = raster1_pixel_res_x / raster2_pixel_res_x (defau...
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
A raster band description.
Definition: BandProperty.h:61
Blended pixel value calculation for two overlaped rasters.
Definition: Blender.h:56
int getSRID() const
Returns the grid spatial reference system identifier.
Definition: Grid.cpp:265
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
Definition: Raster.cpp:213
int m_nblocksx
The number of blocks in x.
Definition: BandProperty.h:145
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
static void calcBandStatistics(const te::rst::Band &band, const bool &forceNoDataValue, const double &noDataValue, double &mean, double &variance)
Raster band statistics calcule.
int m_nblocksy
The number of blocks in y.
Definition: BandProperty.h:146
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...
te::rp::TiePointsLocator::InputParameters m_locatorParams
The parameters used by the tie-points locator when processing each rasters pair (leave untouched to u...
te::rst::Raster const * m_inRaster2Ptr
Input raster 2.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
bool m_enableMultiThread
Enable/Disable the use of multi-threads (default:true).
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
TiePointsLocator input parameters.
Raster Processing algorithm output parameters base interface.
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
unsigned int m_raster1TargetAreaLineStart
The first line of the raster 1 target area to process (default:0 - The entire raster will be consider...
te::rp::Blender::BlendMethod m_blendMethod
The pixel blending method (default: NoBlendMethod).
std::string m_outDataSetsNamePrefix
The raster output data sets names prefix.
double m_noDataValue
The pixel value used where no raster data is avaliable (defaul:0).
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits::max().
Definition: BandProperty.h:136
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
std::vector< MosaicSequenceInfo > m_sequencesInfo
No blending performed.
Definition: Blender.h:64
unsigned int m_raster2TargetAreaWidth
The raster 2 target area width (default:0 - The entire raster will be considered).
std::vector< std::vector< unsigned int > > m_inputRastersBands
Bands to process for each input raster.
bool blendIntoRaster1()
Execute blending of the given input rasters and write the result into raster1.
Definition: Blender.cpp:942
Raster Processing functions.
unsigned int m_raster2TargetAreaLineStart
The first line of the raster 2 target area to process (default:0 - The entire raster will be consider...
#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
const Algorithm & operator=(const Algorithm &)
Definition: Algorithm.cpp:43
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
Definition: Raster.cpp:89
const InputParameters & operator=(const InputParameters &params)
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
std::vector< unsigned int > m_inRaster2Bands
Bands to be used from the input raster 2.
te::rst::Raster const * m_inRaster1Ptr
Input raster 1.
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:50
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
A point with x and y coordinate values.
Definition: Point.h:50
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
Definition: LineString.cpp:352
virtual void reset()=0
Reset the feeder to the first position (subsequent accesses will start from the first sequence obejct...
std::auto_ptr< te::gm::GeometricTransformation > m_transformationPtr
The generated geometric transformation with the base mininum required tie-points set ( depending on t...
An abstract class for raster data strucutures.
Definition: Raster.h:71
void clear()
It deletes all the elements of the collection.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
Definition: Raster.cpp:208
BandProperty * getProperty()
Returns the band property.
Definition: Band.cpp:370
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
SequenceMosaic::InputParameters m_inputParameters
Input execution parameters.
const OutputParameters & operator=(const OutputParameters &params)
std::string m_geomTransfName
The name of the geometric transformation used to ensure tie-points consistency (see each te::gm::GTFa...
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).
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
Definition: Raster.cpp:218
Raster tuple.
double m_minRequiredTiePointsCoveredAreaPercent
The mininumum required tie-points covered area percent of each raster area - valid range [0...
A RAM cache adaptor to an external existent raster that must always be avaliable. ...
Definition: CachedRaster.h:50
RasterHandler.
Definition: RasterHandler.h:47
std::string m_outDataSetsNameSufix
The raster output data sets names sufix.
std::vector< unsigned int > m_rasterFeederIndexes
The indexes (inside the input rasters feeder) of the rasters written to this mosaic sequence...
A raster band description.
Definition: Band.h:63
unsigned int m_raster1TargetAreaWidth
The raster 1 target area width (default:0 - The entire raster will be considered).
Grid * getGrid()
It returns the raster grid.
Definition: Raster.cpp:94
#define SEQUENCE_RASTER_MAX_MOSAIC_MEM_USE
TiePointsLocator output parameters.
unsigned int m_raster1TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
double m_pixelSizeYRelation
The pixel resolution relation m_pixelSizeYRelation = raster1_pixel_res_y / raster2_pixel_res_y (defau...
unsigned int m_raster2TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
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:120
bool m_forceInputNoDataValue
If true, m_noDataValue will be used as the no-data value for input rasters (defalt:false).
double getTPConvexHullArea(const std::vector< te::gm::GTParameters::TiePoint > &tiePoints, const bool useTPSecondCoordPair) const
Returns the tie points converx hull area.
Tie points locator.
Abstract parameters base interface.
#define TERP_LOG_AND_RETURN_FALSE(message)
Logs a warning message will and return false.
Definition: Macros.h:236
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
void setSRID(int srid)
It sets the Spatial Reference System ID of the geometry collection and all its parts.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
std::string m_dataSetName
The generated data set name for this mosaic sequence.
void add(Geometry *g)
It adds the geometry into the collection.
bool m_isInitialized
Tells if this instance is initialized.
static Raster * make()
It creates and returns an empty raster with default raster driver.
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
Definition: Grid.cpp:275
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
Definition: Raster.cpp:223
virtual Geometry * convexHull() const
This method calculates the Convex Hull of a geometry.
Definition: Geometry.cpp:439
Raster Processing algorithm input parameters base interface.
te::rst::Raster const * m_inMaskRaster2Ptr
Optional one band input mask raster 2 (tie-points will not be generated inside mask image areas marke...
te::rst::Raster * getRasterPtr()
Returns a pointer the the handled raster instance or NULL if no instance is handled.
2D Geometric transformation parameters.
Definition: GTParameters.h:50
virtual bool moveNext()=0
Advances to the next sequence obeject.
AbstractParameters * clone() const
Create a clone copy of this instance.
int m_blkh
Block height (pixels).
Definition: BandProperty.h:144
Near neighborhood interpolation method.
Definition: Interpolator.h:63
virtual Geometry * Union(const Geometry *const rhs) const
It returns a geometric object that represents the point set union with another geometry.
Definition: Geometry.cpp:473
bool m_enableMultiThread
Enable/Disable the use of multi-threads (default:true).
virtual te::rst::Raster const * getCurrentObj() const =0
Return the current sequence object.
std::string m_geomTransfName
The name of the geometric transformation used if tie-points are supplied (see each te::gm::GTFactory ...
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68
ColorInterp m_colorInterp
The color interpretation.
Definition: BandProperty.h:140
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
std::vector< unsigned int > m_inRaster1Bands
Bands to be used from the input raster 1.
FeederConstRaster * m_feederRasterPtr
Input rasters feeder.
unsigned int m_raster1TargetAreaHeight
The raster 1 target area height (default:0 - The entire raster will be considered).
void clear()
Clear the internal allocated resources.
unsigned int m_raster2TargetAreaHeight
The raster 2 target area height (default:0 - The entire raster will be considered).
virtual unsigned int getCurrentOffset() const =0
Return the index of the current object.
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
Definition: Macros.h:149
bool initialize(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::MultiPolygon const *const r1ValidDataDelimiterPtr, te::gm::MultiPolygon const *const r2ValidDataDelimiterPtr, const te::gm::GeometricTransformation &geomTransformation, const unsigned int threadsNumber, const bool enableProgressInterface)
Inititate the blender instance.
Definition: Blender.cpp:169
te::rst::Raster const * m_inMaskRaster1Ptr
Optional one band input mask raster 1 (tie-points will not be generated inside mask image areas marke...
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
AbstractParameters * clone() const
Create a clone copy of this instance.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
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.
Surface is an abstract class that represents a 2-dimensional geometric objects.
Definition: Surface.h:54
unsigned int m_tiePointsLocationBandIndex
The band used to locate tie-points, this is the index inside each vector of m_inputRastersBands (defa...
te::da::DataSource * m_outputDSPtr
The mosaic sequences info.