All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Blender.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/Blender.cpp
22  \brief Blended pixel value calculation for two overlaped rasters.
23 */
24 
25 #include "Blender.h"
26 
27 #include "Macros.h"
28 #include "../geometry/LinearRing.h"
29 #include "../geometry/MultiPoint.h"
30 #include "../geometry/MultiLineString.h"
31 #include "../geometry/Point.h"
32 #include "../geometry/Envelope.h"
33 #include "../geometry/Enums.h"
34 #include "../raster/Raster.h"
35 #include "../raster/Grid.h"
36 #include "../raster/Band.h"
37 #include "../raster/BandProperty.h"
38 
39 #include <complex>
40 #include <limits>
41 #include <algorithm>
42 
43 // Get the perpendicular distance from a point P(pX,pY) from a line defined
44 // by the points A(lineAX,lineAY) and B(lineBX,lineBY)
45 // Requires two previously declared variables aux1 and aux2
46 #define getPerpendicularDistance( pX, pY, lineAX, lineAY, lineBX, lineBY, aux1, aux2, perpDist ) \
47  aux1 = lineAX - lineBX; \
48  aux2 = lineAY - lineBY; \
49  if( aux1 == 0.0 ) \
50  { \
51  perpDist = std::abs( pX - lineAX ); \
52  } \
53  else if( aux2 == 0.0 ) \
54  { \
55  perpDist = std::abs( pY - lineAY ); \
56  } \
57  else \
58  { \
59  perpDist = \
60  std::abs( \
61  ( aux2 * pX ) - ( aux1 * pY ) + ( lineAX * lineBY ) - ( lineBX * lineAY ) \
62  ) \
63  / \
64  std::sqrt( ( aux1 * aux1 ) + ( aux2 * aux2 ) ); \
65  }
66 
67 namespace te
68 {
69  namespace rp
70  {
72  {
73  initState();
74  };
75 
77  {
78  clear();
79  }
80 
81  bool Blender::initialize( const te::rst::Raster& raster1,
82  const std::vector< unsigned int >& raster1Bands,
83  const te::rst::Raster& raster2,
84  const std::vector< unsigned int >& raster2Bands,
85  const BlendMethod& blendMethod,
86  const te::rst::Interpolator::Method& interpMethod1,
87  const te::rst::Interpolator::Method& interpMethod2,
88  const double& noDataValue,
89  const bool forceInputNoDataValue,
90  const std::vector< double >& pixelOffsets1,
91  const std::vector< double >& pixelScales1,
92  const std::vector< double >& pixelOffsets2,
93  const std::vector< double >& pixelScales2,
94  te::gm::Polygon const * const r1ValidDataDelimiterPtr,
95  te::gm::Polygon const * const r2ValidDataDelimiterPtr,
96  const te::gm::GeometricTransformation& geomTransformation )
97  {
100  "Invalid raster 1" );
103  "Invalid raster 2" );
104  TERP_TRUE_OR_RETURN_FALSE( raster1Bands.size() ==
105  raster2Bands.size(), "Invalid raster bands vector" );
106  TERP_TRUE_OR_RETURN_FALSE( pixelOffsets1.size() ==
107  raster1Bands.size(), "Invalid pixel offsets" );
108  TERP_TRUE_OR_RETURN_FALSE( pixelScales1.size() ==
109  raster1Bands.size(), "Invalid pixel scales" );
110  TERP_TRUE_OR_RETURN_FALSE( pixelOffsets2.size() ==
111  raster2Bands.size(), "Invalid pixel offsets" );
112  TERP_TRUE_OR_RETURN_FALSE( pixelScales2.size() ==
113  raster2Bands.size(), "Invalid pixel scales" );
114  TERP_TRUE_OR_RETURN_FALSE( ( r1ValidDataDelimiterPtr ?
115  ( r1ValidDataDelimiterPtr->getNPoints() > 1 ) : true ),
116  "Invalid polygon 1" )
117  TERP_TRUE_OR_RETURN_FALSE( ( r2ValidDataDelimiterPtr ?
118  ( r2ValidDataDelimiterPtr->getNPoints() > 1 ) : true ),
119  "Invalid polygon 2" )
120  TERP_TRUE_OR_RETURN_FALSE( geomTransformation.isValid(),
121  "Invalid transformation" );
122 
123  clear();
124 
125  // defining the input rasters
126 
127  m_raster1Ptr = &raster1;
128  m_raster2Ptr = &raster2;
129 
130  // Generating the valid data area points
131 
132  std::auto_ptr< te::gm::Polygon > indexedDelimiter1Ptr; // indexed under raster 1 lines/cols
133 
134  if( r1ValidDataDelimiterPtr )
135  {
136  const std::size_t nRings = r1ValidDataDelimiterPtr->getNumRings();
137  const te::rst::Grid& grid = (*raster1.getGrid());
138 
139  indexedDelimiter1Ptr.reset( new te::gm::Polygon( 0, te::gm::PolygonType, 0, 0 ) );
140 
141  for( std::size_t ringIdx = 0 ; ringIdx < nRings ; ++ringIdx )
142  {
143  te::gm::LinearRing const* inRingPtr = dynamic_cast< te::gm::LinearRing const* >(
144  r1ValidDataDelimiterPtr->getRingN( ringIdx ) );
145  assert( inRingPtr );
146 
147  const std::size_t nPoints = inRingPtr->getNPoints();
148  te::gm::Coord2D const * inCoordsPtr = inRingPtr->getCoordinates();
149  te::gm::Coord2D auxCoord;
150 
151  te::gm::LinearRing* outRingPtr = new te::gm::LinearRing( nPoints,
152  te::gm::LineStringType, 0, 0 );
153 
154  for( std::size_t pIdx = 0 ; pIdx < nPoints ; ++pIdx )
155  {
156  grid.geoToGrid( inCoordsPtr[ pIdx ].x, inCoordsPtr[ pIdx ].y,
157  auxCoord.x, auxCoord.y );
158  outRingPtr->setPoint( pIdx, auxCoord.x, auxCoord.y );
159  }
160 
161  indexedDelimiter1Ptr->add( outRingPtr );
162  }
163  }
164  else
165  {
166  indexedDelimiter1Ptr.reset( new te::gm::Polygon( 0, te::gm::PolygonType, 0, 0 ) );
167 
168  te::gm::LinearRing* outRingPtr = new te::gm::LinearRing( 5,
169  te::gm::LineStringType, 0, 0 );
170 
171  outRingPtr->setPoint( 0,
172  -0.5,
173  -0.5 );
174  outRingPtr->setPoint( 1,
175  ((double)raster1.getNumberOfColumns()) - 0.5,
176  -0.5 );
177  outRingPtr->setPoint( 2,
178  ((double)raster1.getNumberOfColumns()) - 0.5,
179  ((double)raster1.getNumberOfRows()) - 0.5 );
180  outRingPtr->setPoint( 3,
181  -0.5,
182  ((double)raster1.getNumberOfRows()) - 0.5 );
183  outRingPtr->setPoint( 4,
184  -0.5,
185  -0.5 );
186 
187  indexedDelimiter1Ptr->add( outRingPtr );
188  }
189 
190  std::auto_ptr< te::gm::Polygon > indexedDelimiter2Ptr; // indexed under raster 1 lines/cols
191 
192  if( r2ValidDataDelimiterPtr )
193  {
194  const std::size_t nRings = r2ValidDataDelimiterPtr->getNumRings();
195  const te::rst::Grid& grid = (*raster2.getGrid());
196 
197  indexedDelimiter2Ptr.reset( new te::gm::Polygon( 0, te::gm::PolygonType, 0, 0 ) );
198 
199  for( std::size_t ringIdx = 0 ; ringIdx < nRings ; ++ringIdx )
200  {
201  te::gm::LinearRing const* inRingPtr = dynamic_cast< te::gm::LinearRing const* >(
202  r2ValidDataDelimiterPtr->getRingN( ringIdx ) );
203  assert( inRingPtr );
204 
205  const std::size_t nPoints = inRingPtr->getNPoints();
206  te::gm::Coord2D const * inCoordsPtr = inRingPtr->getCoordinates();
207  te::gm::Coord2D auxCoord;
208  te::gm::Coord2D auxCoord2;
209 
210  te::gm::LinearRing* outRingPtr = new te::gm::LinearRing( nPoints,
211  te::gm::LineStringType, 0, 0 );
212 
213  for( std::size_t pIdx = 0 ; pIdx < nPoints ; ++pIdx )
214  {
215  grid.geoToGrid( inCoordsPtr[ pIdx ].x, inCoordsPtr[ pIdx ].y,
216  auxCoord.x, auxCoord.y );
217  geomTransformation.inverseMap( auxCoord.x, auxCoord.y, auxCoord2.x, auxCoord2.y );
218  outRingPtr->setPoint( pIdx, auxCoord2.x, auxCoord2.y );
219  }
220 
221  indexedDelimiter2Ptr->add( outRingPtr );
222  }
223  }
224  else
225  {
226  indexedDelimiter2Ptr.reset( new te::gm::Polygon( 0, te::gm::PolygonType, 0, 0 ) );
227 
228  te::gm::LinearRing* outRingPtr = new te::gm::LinearRing( 5,
229  te::gm::LineStringType, 0, 0 );
230 
231  te::gm::Coord2D auxCoord;
232 
233  geomTransformation.inverseMap(
234  -0.5,
235  -0.5,
236  auxCoord.x, auxCoord.y );
237  outRingPtr->setPoint( 0, auxCoord.x, auxCoord.y );
238  outRingPtr->setPoint( 4, auxCoord.x, auxCoord.y );
239 
240  geomTransformation.inverseMap(
241  ((double)raster2.getNumberOfColumns()) - 0.5,
242  -0.5,
243  auxCoord.x, auxCoord.y );
244  outRingPtr->setPoint( 1, auxCoord.x, auxCoord.y );
245 
246  geomTransformation.inverseMap(
247  ((double)raster2.getNumberOfColumns()) - 0.5,
248  ((double)raster2.getNumberOfRows()) - 0.5,
249  auxCoord.x, auxCoord.y );
250  outRingPtr->setPoint( 2, auxCoord.x, auxCoord.y );
251 
252  geomTransformation.inverseMap(
253  -0.5,
254  ((double)raster2.getNumberOfRows()) - 0.5,
255  auxCoord.x, auxCoord.y );
256  outRingPtr->setPoint( 3, auxCoord.x, auxCoord.y );
257 
258  indexedDelimiter2Ptr->add( outRingPtr );
259  }
260 
261  // Calculating the intersection
262 
263  {
264  std::auto_ptr< te::gm::Geometry > geomIntersectionPtr(
265  indexedDelimiter2Ptr->intersection( indexedDelimiter1Ptr.get() ) );
266 
267  if( geomIntersectionPtr.get() )
268  {
269  if( geomIntersectionPtr->getGeomTypeId() == te::gm::PolygonType )
270  {
271  std::auto_ptr< te::gm::MultiPolygon > multiPolIntersectionPtr(
273  multiPolIntersectionPtr->add( geomIntersectionPtr.release() );
274 
275  m_intersectionPtr.reset( multiPolIntersectionPtr.release() );
276  }
277  else if( geomIntersectionPtr->getGeomTypeId() == te::gm::MultiPolygonType )
278  {
279  m_intersectionPtr.reset( (te::gm::MultiPolygon*)geomIntersectionPtr.release() );
280  }
281  }
282  }
283 
284  // Extracting the intersection segments points
285 
286  if( m_intersectionPtr.get() )
287  {
288  std::size_t ringIdx = 0;
289 
290  for( ringIdx = 0 ; ringIdx < indexedDelimiter2Ptr->getNumRings() ;
291  ++ringIdx )
292  {
293  std::auto_ptr< te::gm::Geometry > ringIntersectionPtr;
294  ringIntersectionPtr.reset( indexedDelimiter1Ptr->intersection( indexedDelimiter2Ptr->getRingN( ringIdx ) ) );
295 
296  if( ringIntersectionPtr.get() != 0 )
297  {
298  if( ringIntersectionPtr->getGeomTypeId() == te::gm::MultiLineStringType )
299  {
300  te::gm::MultiLineString const* ringIntersectionNPtr = dynamic_cast< te::gm::MultiLineString const * >(
301  ringIntersectionPtr.get() );
302  assert( ringIntersectionNPtr );
303 
304  std::size_t numGeoms = ringIntersectionNPtr->getNumGeometries();
305 
306  for( std::size_t gIdx = 0 ; gIdx < numGeoms ; ++gIdx )
307  {
308  te::gm::LineString const* segIndexedNPtr = dynamic_cast< te::gm::LineString const * >(
309  ringIntersectionNPtr->getGeometryN( gIdx ) );
310  assert( segIndexedNPtr );
311 
312  std::size_t nPoints = segIndexedNPtr->size();
313  te::gm::Coord2D const* coodsPtr = segIndexedNPtr->getCoordinates();
314 
315  for( std::size_t pIdx = 1 ; pIdx < nPoints ; ++pIdx )
316  {
317  m_r2IntersectionSegmentsPoints.push_back( std::pair< te::gm::Coord2D, te::gm::Coord2D >(
318  coodsPtr[ pIdx - 1 ], coodsPtr[ pIdx ] ) );
319  }
320  }
321  }
322  else if( ringIntersectionPtr->getGeomTypeId() == te::gm::LineStringType )
323  {
324  te::gm::LineString const* segIndexedNPtr = dynamic_cast< te::gm::LineString const * >(
325  ringIntersectionPtr.get() );
326  assert( segIndexedNPtr );
327 
328  std::size_t nPoints = segIndexedNPtr->size();
329  te::gm::Coord2D const* coodsPtr = segIndexedNPtr->getCoordinates();
330 
331  for( std::size_t pIdx = 1 ; pIdx < nPoints ; ++pIdx )
332  {
333  m_r2IntersectionSegmentsPoints.push_back( std::pair< te::gm::Coord2D, te::gm::Coord2D >(
334  coodsPtr[ pIdx - 1 ], coodsPtr[ pIdx ] ) );
335  }
336  }
337  }
338  }
339 
340  for( ringIdx = 0 ; ringIdx < indexedDelimiter1Ptr->getNumRings() ;
341  ++ringIdx )
342  {
343  std::auto_ptr< te::gm::Geometry > ringIntersectionPtr;
344  ringIntersectionPtr.reset( indexedDelimiter2Ptr->intersection( indexedDelimiter1Ptr->getRingN( ringIdx ) ) );
345 
346  if( ringIntersectionPtr.get() != 0 )
347  {
348  if( ringIntersectionPtr->getGeomTypeId() == te::gm::MultiLineStringType )
349  {
350  te::gm::MultiLineString const* ringIntersectionNPtr = dynamic_cast< te::gm::MultiLineString const * >(
351  ringIntersectionPtr.get() );
352  assert( ringIntersectionNPtr );
353 
354  std::size_t numGeoms = ringIntersectionNPtr->getNumGeometries();
355 
356  for( std::size_t gIdx = 0 ; gIdx < numGeoms ; ++gIdx )
357  {
358  te::gm::LineString const* segIndexedNPtr = dynamic_cast< te::gm::LineString const * >(
359  ringIntersectionNPtr->getGeometryN( gIdx ) );
360  assert( segIndexedNPtr );
361 
362  std::size_t nPoints = segIndexedNPtr->size();
363  te::gm::Coord2D const* coodsPtr = segIndexedNPtr->getCoordinates();
364 
365  for( std::size_t pIdx = 1 ; pIdx < nPoints ; ++pIdx )
366  {
367  m_r1IntersectionSegmentsPoints.push_back( std::pair< te::gm::Coord2D, te::gm::Coord2D >(
368  coodsPtr[ pIdx - 1 ], coodsPtr[ pIdx ] ) );
369  }
370  }
371  }
372  else if( ringIntersectionPtr->getGeomTypeId() == te::gm::LineStringType )
373  {
374  te::gm::LineString const* segIndexedNPtr = dynamic_cast< te::gm::LineString const * >(
375  ringIntersectionPtr.get() );
376  assert( segIndexedNPtr );
377 
378  std::size_t nPoints = segIndexedNPtr->size();
379  te::gm::Coord2D const* coodsPtr = segIndexedNPtr->getCoordinates();
380 
381  for( std::size_t pIdx = 1 ; pIdx < nPoints ; ++pIdx )
382  {
383  m_r1IntersectionSegmentsPoints.push_back( std::pair< te::gm::Coord2D, te::gm::Coord2D >(
384  coodsPtr[ pIdx - 1 ], coodsPtr[ pIdx ] ) );
385  }
386  }
387  }
388  }
389 
390 /* std::cout << std::endl;
391  for( unsigned int idx = 0 ; idx < m_r1IntersectionSegmentsPoints.size() ; ++idx )
392  {
393  std::cout << std::endl << "m_r1IntersectionSegmentsPoints[" << idx << "]="
394  << m_r1IntersectionSegmentsPoints[ idx ].first.x
395  << " " << m_r1IntersectionSegmentsPoints[ idx ].first.y
396  << " " << m_r1IntersectionSegmentsPoints[ idx ].second.x
397  << " " << m_r1IntersectionSegmentsPoints[ idx ].second.y;
398  }
399  for( unsigned int idx = 0 ; idx < m_r2IntersectionSegmentsPoints.size() ; ++idx )
400  {
401  std::cout << std::endl << "m_r2IntersectionSegmentsPoints[" << idx << "]="
402  << m_r2IntersectionSegmentsPoints[ idx ].first.x
403  << " " << m_r2IntersectionSegmentsPoints[ idx ].first.y
404  << " " << m_r2IntersectionSegmentsPoints[ idx ].second.x
405  << " " << m_r2IntersectionSegmentsPoints[ idx ].second.y;
406  }
407  std::cout << std::endl; */
408 
411  }
412 
413  // defining the blending function
414 
415  m_blendMethod = blendMethod;
416 
417  switch( blendMethod )
418  {
419  case NoBlendMethod :
420  {
422  break;
423  }
425  {
426  if( ( m_intersectionPtr.get() != 0 ) &&
429  {
431  }
432  else
433  {
435  }
436  break;
437  }
438  default :
439  {
440  return false;
441  break;
442  }
443  }
444 
445  // defining the geometric transformation
446 
447  m_geomTransformationPtr = geomTransformation.clone();
448 
449  // defining the interpolators
450 
451  m_interp1 = new te::rst::Interpolator( &raster1, interpMethod1 );
452  m_interp2 = new te::rst::Interpolator( &raster2, interpMethod2 );
453 
454  m_interpMethod1 = interpMethod1;
455  m_interpMethod2 = interpMethod2;
456 
457  // defining dummy values
458 
459  for( std::vector< unsigned int >::size_type rasterBandsIdx = 0 ;
460  rasterBandsIdx < raster1Bands.size() ; ++rasterBandsIdx )
461  {
462  TERP_TRUE_OR_RETURN_FALSE( raster1Bands[ rasterBandsIdx ] <
463  raster1.getNumberOfBands(), "Invalid band" );
464  TERP_TRUE_OR_RETURN_FALSE( raster2Bands[ rasterBandsIdx ] <
465  raster2.getNumberOfBands(), "Invalid band" );
466 
467 
468  if( forceInputNoDataValue )
469  {
470  m_raster1NoDataValues.push_back( noDataValue );
471  m_raster2NoDataValues.push_back( noDataValue );
472  }
473  else
474  {
475  m_raster1NoDataValues.push_back( raster1.getBand( raster1Bands[
476  rasterBandsIdx ] )->getProperty()->m_noDataValue );
477  m_raster2NoDataValues.push_back( raster2.getBand( raster2Bands[
478  rasterBandsIdx ] )->getProperty()->m_noDataValue );
479  }
480  }
481 
482  m_outputNoDataValue = noDataValue;
483 
484  // defining raster bands
485 
486  m_raster1Bands = raster1Bands;
487  m_raster2Bands = raster2Bands;
488 
489  // defining pixel offsets
490 
491  m_pixelOffsets1 = pixelOffsets1;
492  m_pixelScales1 = pixelScales1;
493 
494  m_pixelOffsets2 = pixelOffsets2;
495  m_pixelScales2 = pixelScales2;
496 
497  return true;
498  }
499 
501  {
503  m_blendFuncPtr = 0;
504  m_raster1Ptr = 0;
505  m_raster2Ptr = 0;
512  m_interp1 = 0;
513  m_interp2 = 0;
514  };
515 
517  {
518  m_intersectionPtr.reset();
522  if( m_interp1 ) delete m_interp1;
523  if( m_interp2 ) delete m_interp2;
524  m_raster1Bands.clear();
525  m_raster2Bands.clear();
526  m_pixelOffsets1.clear();
527  m_pixelScales1.clear();
528  m_pixelOffsets2.clear();
529  m_pixelScales2.clear();
530  m_raster1NoDataValues.clear();
531  m_raster2NoDataValues.clear();
532 
533  initState();
534  }
535 
536  void Blender::noBlendMethodImp( const double& line, const double& col,
537  std::vector< double >& values )
538  {
539  TERP_DEBUG_TRUE_OR_THROW( values.size() == m_raster1Bands.size(), "Invalid values vector size" );
540 
541  // Finding the point over the second raster
542 
545 
546  // Blending values
547 
550  {
554 
555  if( m_noBlendMethodImp_Value == m_raster1NoDataValues[ m_noBlendMethodImp_BandIdx ] )
556  {
559  m_raster2Bands[ m_noBlendMethodImp_BandIdx ] );
561 
562  if( m_noBlendMethodImp_Value == m_raster2NoDataValues[ m_noBlendMethodImp_BandIdx ] )
563  {
565  }
566  else
567  {
571  }
572  }
573  else
574  {
578  }
579  }
580  }
581 
582  void Blender::euclideanDistanceMethodImp( const double& line, const double& col,
583  std::vector< double >& values )
584  {
585  TERP_DEBUG_TRUE_OR_THROW( values.size() == m_raster1Bands.size(), "Invalid values vector size" );
586  TERP_DEBUG_TRUE_OR_THROW( m_intersectionPtr.get(), "Invalid intersection pointer" );
587  TERP_DEBUG_TRUE_OR_THROW( m_r1IntersectionSegmentsPointsSize > 1, "Invalid intersection points" );
588  TERP_DEBUG_TRUE_OR_THROW( m_r2IntersectionSegmentsPointsSize > 1, "Invalid intersection points" );
589 
590  // Checking if it is inside the intersection
591 
594 
596  {
597  // Finding distances to both rasters valid area delimiters
598 
599  m_euclideanDistanceMethodImp_dist1 = std::numeric_limits<double>::max();
603  {
604 
606  col,
607  line,
609  m_r1IntersectionSegmentsPoints[ m_euclideanDistanceMethodImp_vecIdx ].first.y,
610  m_r1IntersectionSegmentsPoints[ m_euclideanDistanceMethodImp_vecIdx ].second.x,
611  m_r1IntersectionSegmentsPoints[ m_euclideanDistanceMethodImp_vecIdx ].second.y,
615 
617  {
619  }
620  }
621 
622  m_euclideanDistanceMethodImp_dist2 = std::numeric_limits<double>::max();
626  {
627 
629  col,
630  line,
632  m_r2IntersectionSegmentsPoints[ m_euclideanDistanceMethodImp_vecIdx ].first.y,
633  m_r2IntersectionSegmentsPoints[ m_euclideanDistanceMethodImp_vecIdx ].second.x,
634  m_r2IntersectionSegmentsPoints[ m_euclideanDistanceMethodImp_vecIdx ].second.y,
638 
640  {
642  }
643  }
644 
645  // Finding the point over the second raster
646 
649 
650  // Blending values
651 
654  {
659  m_raster2Bands[ m_euclideanDistanceMethodImp_BandIdx ] );
660 
662  {
664  {
666  }
667  else
668  {
672  m_pixelOffsets2[ m_euclideanDistanceMethodImp_BandIdx ];
673  }
674  }
675  else
676  {
678  {
682  m_pixelOffsets1[ m_euclideanDistanceMethodImp_BandIdx ];
683  }
684  else
685  {
687  {
691  m_pixelOffsets1[ m_euclideanDistanceMethodImp_BandIdx ];
692  }
693  else if( m_euclideanDistanceMethodImp_dist1 == 0.0 )
694  {
698  m_pixelOffsets2[ m_euclideanDistanceMethodImp_BandIdx ];
699  }
700  else
701  {
703  (
704  (
705  (
706  (
708  *
710  )
711  +
712  m_pixelOffsets1[ m_euclideanDistanceMethodImp_BandIdx ]
713  )
714  *
716  )
717  +
718  (
719  (
720  (
722  *
724  )
725  +
726  m_pixelOffsets2[ m_euclideanDistanceMethodImp_BandIdx ]
727  )
728  *
730  )
731  )
732  /
733  (
735  +
737  );
738  }
739  }
740  }
741  }
742  }
743  else
744  {
745  noBlendMethodImp( line, col, values );
746  }
747  }
748 
749  } // end namespace rp
750 } // end namespace te
751 
MultiLineString is a MultiCurve whose elements are LineStrings.
std::vector< unsigned int > m_raster1Bands
Input raster 1 band indexes to use.
Definition: Blender.h:151
te::rst::Interpolator * m_interp1
Raster 1 interpolator instance pointer.
Definition: Blender.h:149
void setX(const double &x)
It sets the Point x-coordinate value.
Definition: Point.h:143
#define TERP_DEBUG_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
Definition: Macros.h:356
std::vector< double > m_pixelOffsets2
The values offset to be applied to raster 2 pixel values before the blended value calcule (one elemen...
Definition: Blender.h:155
std::vector< std::pair< te::gm::Coord2D, te::gm::Coord2D > > m_r1IntersectionSegmentsPoints
A sub-set of the intersection polygon wich is part of raster 1 valid data polygon ( raster 1 indexed ...
Definition: Blender.h:141
std::vector< unsigned int > m_raster2Bands
Input raster 2 band indexes to use.
Definition: Blender.h:152
void clear()
Clear all internal allocated resources.
Definition: Blender.cpp:516
void noBlendMethodImp(const double &line1, const double &col1, std::vector< double > &values)
Implementation for NoBlendMethod.
Definition: Blender.cpp:536
double m_euclideanDistanceMethodImp_aux1
Definition: Blender.h:182
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
Definition: LineString.h:193
unsigned int getNumberOfRows() const
Returns the raster number of rows.
Definition: Raster.cpp:208
Euclidean distance method.
Definition: Blender.h:62
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
std::size_t m_euclideanDistanceMethodImp_vecIdx
Definition: Blender.h:181
std::vector< double > m_pixelScales2
The values scale to be applied to raster 2 pixel values before the blended value calcule (one element...
Definition: Blender.h:156
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
Definition: CurvePolygon.h:153
void setY(const double &y)
It sets the Point y-coordinate value.
Definition: Point.h:157
double y
y-coordinate.
Definition: Coord2D.h:87
Grid * getGrid()
It returns the raster grid.
Definition: Raster.cpp:94
std::complex< double > m_euclideanDistanceMethodImp_cValue2
Definition: Blender.h:176
std::size_t size() const
It returns the number of points (vertexes) in the geometry.
Definition: LineString.h:262
te::rst::Interpolator * m_interp2
Raster 2 interpolator instance pointer.
Definition: Blender.h:150
No blending performed.
Definition: Blender.h:61
te::rst::Interpolator::Method m_interpMethod1
The interpolation method to use when reading raster 1 data.
Definition: Blender.h:146
virtual bool within(const Geometry *const rhs) const
It returns true if the geometry object is spatially within rhs geometry.
Definition: Geometry.cpp:285
void getValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Get the interpolated value at specific band.
Definition: Interpolator.h:84
#define getPerpendicularDistance(pX, pY, lineAX, lineAY, lineBX, lineBY, aux1, aux2, perpDist)
Definition: Blender.cpp:46
double m_noBlendMethodImp_Point2Col
Definition: Blender.h:166
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
Definition: Interpolator.h:51
te::gm::GeometricTransformation * m_geomTransformationPtr
A transformation mapping raster 1 pixels ( te::gm::GTParameters::TiePoint::first ) to raster 2 ( te::...
Definition: Blender.h:145
BlendMethod m_blendMethod
The blend method to apply.
Definition: Blender.h:136
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
Method
Allowed interpolation methods.
Definition: Interpolator.h:58
#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
void initState()
Reset the instance to its initial default state.
Definition: Blender.cpp:500
std::complex< double > m_euclideanDistanceMethodImp_cValue1
Definition: Blender.h:175
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
te::rst::Raster const * m_raster1Ptr
Input raster 1.
Definition: Blender.h:138
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
virtual GeometricTransformation * clone() const =0
Creat a clone copy of this instance.
double m_euclideanDistanceMethodImp_Point2Line
Definition: Blender.h:173
unsigned int m_euclideanDistanceMethodImp_BandIdx
Definition: Blender.h:177
virtual bool isValid(const GTParameters &params) const =0
Verifies if the supplied parameters already has a valid transformation.
std::vector< double > m_raster1NoDataValues
Definition: Blender.h:157
te::rst::Raster const * m_raster2Ptr
Input raster 2.
Definition: Blender.h:139
Coord2D * getCoordinates() const
It returns a pointer to the internal array of coordinates.
Definition: LineString.h:456
double m_euclideanDistanceMethodImp_Point2Col
Definition: Blender.h:174
std::size_t m_r2IntersectionSegmentsPointsSize
Size of m_r2IntersectionSegmentsPoints;.
Definition: Blender.h:144
void euclideanDistanceMethodImp(const double &line1, const double &col1, std::vector< double > &values)
Implementation for EuclideanDistanceMethod.
Definition: Blender.cpp:582
std::auto_ptr< te::gm::MultiPolygon > m_intersectionPtr
The Intersection geometry ( Multipolygon geometry - raster 1 indexed coods).
Definition: Blender.h:140
double m_outputNoDataValue
The output raster no-data value.
Definition: Blender.h:148
std::vector< double > m_raster2NoDataValues
Raster 1 no-data values (on value per band).
Definition: Blender.h:158
te::gm::Point m_euclideanDistanceMethodImp_auxPoint
Definition: Blender.h:172
std::size_t m_r1IntersectionSegmentsPointsSize
Size of m_r1IntersectionSegmentsPoints;.
Definition: Blender.h:142
double m_euclideanDistanceMethodImp_currDist
Definition: Blender.h:178
double m_noBlendMethodImp_Value
Definition: Blender.h:168
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
Definition: Raster.cpp:213
double m_euclideanDistanceMethodImp_aux2
Definition: Blender.h:183
unsigned int m_noBlendMethodImp_BandIdx
Definition: Blender.h:169
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
Definition: LineString.cpp:313
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
2D Geometric transformation base class.
te::rst::Interpolator::Method m_interpMethod2
The interpolation method to use when reading raster 2 data.
Definition: Blender.h:147
std::vector< std::pair< te::gm::Coord2D, te::gm::Coord2D > > m_r2IntersectionSegmentsPoints
A sub-set of the intersection polygon wich is part of raster 2 valid data polygon ( raster 1 indexed ...
Definition: Blender.h:143
std::vector< double > m_pixelOffsets1
The values offset to be applied to raster 1 pixel values before the blended value calcule (one elemen...
Definition: Blender.h:153
An abstract class for raster data strucutures.
Definition: Raster.h:70
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.
double m_euclideanDistanceMethodImp_dist2
Definition: Blender.h:180
std::size_t getNPoints() const
it returns the number of points (vertexes) in the geometry.
Invalid blending method.
Definition: Blender.h:60
Blended pixel value calculation for two overlaped rasters.
double x
x-coordinate.
Definition: Coord2D.h:86
std::vector< double > m_pixelScales1
The values scale to be applied to raster 1 pixel values before the blended value calcule (one element...
Definition: Blender.h:154
Near neighborhood interpolation method.
Definition: Interpolator.h:60
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
Definition: Grid.cpp:308
double m_noBlendMethodImp_Point2Line
Definition: Blender.h:165
virtual void directMap(const GTParameters &params, const double &pt1X, const double &pt1Y, double &pt2X, double &pt2Y) const =0
Direct mapping (from pt1 space into pt2 space).
BlendFunctPtr m_blendFuncPtr
The current blend function.
Definition: Blender.h:137
Curve * getRingN(std::size_t i) const
It returns the n-th ring for this curve polygon as a curve.
Definition: CurvePolygon.h:193
std::complex< double > m_noBlendMethodImp_cValue
Definition: Blender.h:167
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 void inverseMap(const GTParameters &params, const double &pt2X, const double &pt2Y, double &pt1X, double &pt1Y) const =0
Inverse mapping (from pt2 space into pt1 space).
double m_euclideanDistanceMethodImp_dist1
Definition: Blender.h:179