OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimOverviewSequencer.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Description: Sequencer for building overview files.
8 //
9 //----------------------------------------------------------------------------
10 // $Id: ossimOverviewSequencer.cpp 23377 2015-06-17 18:03:05Z okramer $
11 
13 #include <ossim/base/ossimIpt.h>
14 #include <ossim/base/ossimIrect.h>
16 #include <ossim/base/ossimNotify.h>
17 #include <ossim/base/ossimTrace.h>
23 
24 
25 #ifdef OSSIM_ID_ENABLED
26 static const char OSSIM_ID[] = "$Id: ossimOverviewSequencer.cpp 23377 2015-06-17 18:03:05Z okramer $";
27 #endif
28 
29 static ossimTrace traceDebug("ossimOverviewSequencer:debug");
30 
32  :
35  m_imageHandler(0),
36  m_maskWriter(0),
37  m_maskFilter(0),
38  m_tile(0),
39  m_areaOfInterest(),
41  m_numberOfTilesHorizontal(0),
42  m_numberOfTilesVertical(0),
43  m_currentTileNumber(0),
44  m_sourceResLevel(0),
45  m_dirtyFlag(true),
46  m_decimationFactor(2),
47  m_resampleType(ossimFilterResampler::ossimFilterResampler_BOX),
48  m_histogram(0),
49  m_histoMode(OSSIM_HISTO_MODE_UNKNOWN),
50  m_histoTileIndex(1),
51  m_scanForMinMax(false),
52  m_scanForMinMaxNull(false),
53  m_minValues(0),
54  m_maxValues(0),
55  m_nulValues(0)
56 {
58 
59  if (traceDebug())
60  {
62  << "ossimOverviewSequencer::ossimOverviewSequencer entered..."
63  << "\nmpi rank: "<< ossimMpi::instance()->getRank()
64  << std::endl;
65 #ifdef OSSIM_ID_ENABLED
66  ossimNotify(ossimNotifyLevel_DEBUG)<< "OSSIM_ID: " << OSSIM_ID
67  << std::endl;
68 #endif
69  }
70 }
71 
73 {
74  m_imageHandler = 0;
75  m_maskFilter = 0;
76  m_maskWriter = 0;
77  m_tile = 0;
78  m_histogram = 0;
79 
80  if (traceDebug())
81  {
83  << "ossimOverviewSequencer::~ossimOverviewSequencer entered..."
84  << "\nmpi rank: " << ossimMpi::instance()->getRank()
85  << std::endl;
86  }
87 }
88 
90 {
92 }
93 
95 {
97 }
98 
100 {
102 }
103 
105 {
107  {
108  rect.makeNan(); // not initialized...
109  }
110  else
111  {
114 
115  //---
116  // NOTE:
117  // This will add a sample or line if there is a remainder like:
118  // 1025 / 2 = 512 will then become 513. It will be up to the resample
119  // tile method to fill the extra sample correctly.
120  //---
122  {
123  ++width;
124  }
126  {
127  ++height;
128  }
129 
130  rect = ossimIrect(0, 0, width-1, height-1);
131  }
132 }
133 
135 {
136  m_imageHandler = input;
138  m_dirtyFlag = true;
139 
140  if (m_maskWriter.valid())
142 }
143 
145 {
146  m_sourceResLevel = level;
148  m_dirtyFlag = true;
149 }
150 
152 {
153  return m_histoMode;
154 }
155 
157 {
158  m_histoMode = mode;
159  m_dirtyFlag = true;
160 }
161 
163 {
164  if ( m_histogram.valid() && m_imageHandler.valid() )
165  {
167  }
168 }
169 
171 {
172  if ( m_histogram.valid() )
173  {
175  histo->addHistogram( m_histogram.get() );
176  ossimKeywordlist kwl;
177  histo->saveState(kwl);
178  kwl.write(file.c_str());
179  }
180 }
181 
183 {
184  if ( m_dirtyFlag == false )
185  {
186  return; // Already initialized.
187  }
188 
189  if ( !m_imageHandler )
190  {
191  return;
192  }
193 
194  ossimImageSource* imageSource = m_imageHandler.get();
195  if (m_maskFilter.valid())
196  imageSource = m_maskFilter.get();
197 
198  // Check the area of interest and set from image if needed.
199  if ( m_areaOfInterest.hasNans() )
200  {
202  }
203 
204  // Check the tile size and set from image if needed.
205  if ( m_tileSize.hasNans() )
206  {
207  m_tileSize.x = imageSource->getTileWidth();
208  m_tileSize.y = imageSource->getTileHeight();
209  }
210 
211  // Update m_numberOfTilesHorizontal and m_numberOfTilesVertical.
213 
214  // Start on first tile.
216 
217  // Use this factory constructor as it copies the min/max/nulls from the image handler.
219  create( 0, imageSource->getNumberOfOutputBands(), imageSource);
220 
221  if(m_tile.valid())
222  {
223  // Set the width and height.
224  m_tile->setWidthHeight(static_cast<ossim_uint32>(m_tileSize.x),
225  static_cast<ossim_uint32>(m_tileSize.y) );
226  // Initialize tile buffer.
227  m_tile->initialize();
228  }
229 
231  {
233 
234  m_histogram->create(imageSource);
235 
237  {
238  m_histoTileIndex = 1; // Sample every tile.
239  }
240  else
241  {
242  const ossim_float64 PIXEL_TO_SAMPLE = 100.0 * 256.0 * 256.0; // 100 256x256 tiles.
244 
245  if (traceDebug())
246  {
248  << "pixels: " << pixels << "\n"
249  << "PIXEL_TO_SAMPLE: " << PIXEL_TO_SAMPLE << "\n";
250  }
251 
252  if (pixels > PIXEL_TO_SAMPLE)
253  {
254  m_histoTileIndex = ossim::round<ossim_uint32>(pixels/PIXEL_TO_SAMPLE);
255  }
256  else
257  {
258  m_histoTileIndex = 1; // Sample every tile.
259  }
260  }
261  }
262  else
263  {
264  m_histogram = 0;
265  }
266 
267 
269  {
270  //---
271  // The methods ossimImageData::computeMinMaxNullPix and computeMinMaxPix
272  // will resize and set min to max, max to min and null to max if the arrays passed in
273  // are empty.
274  //---
276  }
277 
278  m_dirtyFlag = false;
279 
280  if (traceDebug())
281  {
283  << "aoi: " << m_areaOfInterest
284  << "\ntile size: " << m_tileSize
285  << "\ntiles wide: " << m_numberOfTilesHorizontal
286  << "\ntiles high: " << m_numberOfTilesVertical
287  << "\nsource rlevel: " << m_sourceResLevel
288  << "\ndecimation factor: " << m_decimationFactor
289  << "\nresamp type: " << m_resampleType
290  << "\nscan for min max: " << (m_scanForMinMax?"true\n":"false\n")
291  << "\nscan for min, max null: " << (m_scanForMinMaxNull?"true\n":"false\n")
292  << "\nhisto mode: " << m_histoMode << "\n";
294  {
296  << "Sampling every " << m_histoTileIndex << " tile(s) for histogram.\n";
297  }
298  }
299 }
300 
302 {
304 }
305 
307 {
308  if ( m_dirtyFlag )
309  {
311  }
312 
313  // Get the rectangle to grab from the image.
314  ossimIrect inputRect;
315  getInputTileRectangle(inputRect);
316 
317  // Get the output rectangle.
318  ossimIrect outputRect;
319  getOutputTileRectangle(outputRect);
320 
321  // Capture the output rectangle.
322  m_tile->setImageRectangle(outputRect);
323 
324  // Start with a blank tile.
325  m_tile->makeBlank();
326 
327  // Grab the input tile.
328  ossimRefPtr<ossimImageData> inputTile;
329  if (m_maskFilter.valid())
330  {
331  inputTile = m_maskFilter->getTile(inputRect, m_sourceResLevel);
332 
333  // Check for errors reading tile and set our error status for callers.
334  if ( m_maskFilter->hasError() )
335  {
336  setErrorStatus();
337  }
338  }
339  else
340  {
341  inputTile = m_imageHandler->getTile(inputRect, m_sourceResLevel);
342 
343  // Check for errors reading tile and set our error status for callers.
344  if ( m_imageHandler->hasError() )
345  {
346  setErrorStatus();
347  }
348  }
349 
350  if ( hasError() )
351  {
353  << "ossimOverviewSequencer::getNextTile ERROR:"
354  << "\nError set reading tile: " << m_currentTileNumber << std::endl;
355  if ( inputTile.valid() )
356  {
357  inputTile->makeBlank();
358  }
359  }
360  else if ( inputTile.valid() )
361  {
362  if ( m_scanForMinMaxNull )
363  {
365  }
366  else if ( m_scanForMinMax )
367  {
369  }
370 
373  {
374  if (traceDebug())
375  {
377  << "ossimOverviewSequencer::getNextTile DEBUG:"
378  << "\npopulating histogram for tile: " << m_currentTileNumber
379  << "\n";
380  }
381  inputTile->populateHistogram(m_histogram);
382  }
383 
384  if ( (inputTile->getDataObjectStatus() == OSSIM_PARTIAL) ||
385  (inputTile->getDataObjectStatus() == OSSIM_FULL ) )
386  {
387  // Resample the tile.
388  resampleTile(inputTile.get());
389  m_tile->validate();
390 
391  // Scan the resampled pixels for bogus values to be masked out (if masking enabled)
392  if (m_maskWriter.valid())
394  }
395  }
396  else
397  {
399  << "ossimOverviewSequencer::getNextTile DEBUG:"
400  << "\nRequest failed for input rect: " << inputRect
401  << "\nRes level: " << m_sourceResLevel << std::endl;
402  }
403 
404  // Increment the tile index.
406 
407  return m_tile;
408 }
409 
411 {
412 }
413 
415 {
416  return true;
417 }
418 
420 {
421  return m_tileSize;
422 }
423 
425 {
426  m_tileSize = tileSize;
428  m_dirtyFlag = true;
429 }
430 
433 {
434  m_resampleType = resampleType;
435 }
436 
438 {
439  m_scanForMinMax = flag;
440 }
441 
443 {
444  return m_scanForMinMax;
445 }
446 
448 {
449  m_scanForMinMaxNull = flag;
450 }
451 
453 {
454  return m_scanForMinMaxNull;
455 }
456 
458 {
459  m_minValues.clear();
460  m_maxValues.clear();
461  m_nulValues.clear();
462 }
463 
464 bool ossimOverviewSequencer::writeOmdFile(const std::string& file)
465 {
466  static const char M[] = "ossimOverviewSequencer::writeOmdFile";
467  if ( traceDebug() )
468  {
469  ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\nfile: " << file << endl;
470  }
471 
472  //---
473  // This method writes an omd file to disk. Typically called after sequencing trough tile that
474  // were scanned for min, max, and potentially null values.
475  // Since this can be called without a scan there is extra logic in here to initialize values
476  // if so. Also there are sanity checks for cases where there is no null value, i.e. a
477  // full tile, in which case assumptions have to be made...
478  //---
479 
480  bool result = false;
481  if ( file.size() && m_imageHandler.valid() )
482  {
485  const ossim_float64 DEFAULT_NULL = ossim::defaultNull(SCALAR);
486 
487  if ( traceDebug() )
488  {
490  << "Original array values:\n";
491  std::vector<ossim_float64>::const_iterator i = m_minValues.begin();
492  ossim_int32 band = 0;
493  while ( i < m_minValues.end() )
494  {
496  << "min[" << band++ << "]: " << *i << "\n";
497  ++i;
498  }
499  i = m_maxValues.begin();
500  band = 0;
501  while ( i < m_maxValues.end() )
502  {
504  << "max[" << band++ << "]: " << *i << "\n";
505  ++i;
506  }
507  i = m_nulValues.begin();
508  band = 0;
509  while ( i < m_nulValues.end() )
510  {
512  << "nul[" << band++ << "]: " << *i << "\n";
513  ++i;
514  }
515  }
516 
517  if ( (m_scanForMinMax == true) || (m_nulValues.size() != BANDS) )
518  {
519  // Only scanned for min and max so set the null.
520  if (m_nulValues.size() != BANDS)
521  {
522  m_nulValues.resize(BANDS);
523  }
524  for (ossim_uint32 band = 0; band < BANDS; ++band)
525  {
527  }
528  }
529  else if ( m_scanForMinMaxNull == true )
530  {
531  //---
532  // The arrays (sizes) should be set if we did the scan.
533  // Note that scanning for null only works if there IS a null in the image; hence, the
534  // extra sanity checks as if there are no null then the null gets set to the real min.
535  //
536  // This is very dangerous code as it makes assumptions (drb)...
537  //---
538  if ( (m_minValues.size() == BANDS) &&
539  (m_maxValues.size() == BANDS) &&
540  (m_nulValues.size() == BANDS) )
541  {
542  switch(SCALAR)
543  {
544  case OSSIM_UINT8:
545  case OSSIM_SINT8:
546  case OSSIM_UINT16:
547  case OSSIM_USHORT11:
548  case OSSIM_USHORT12:
549  case OSSIM_USHORT13:
550  case OSSIM_USHORT14:
551  case OSSIM_USHORT15:
552  case OSSIM_UINT32:
553  {
554  // All of these should have a null of 0.
555  for (ossim_uint32 band = 0; band < BANDS; ++band)
556  {
557  if ( m_nulValues[band] > DEFAULT_NULL )
558  {
559  if ( m_nulValues[band] < m_minValues[band] )
560  {
561  m_minValues[band] = m_nulValues[band];
562  }
563  m_nulValues[band] = DEFAULT_NULL;
564  }
565  }
566  break;
567  }
568  case OSSIM_SINT16:
569  {
570  for (ossim_uint32 band = 0; band < BANDS; ++band)
571  {
572  if ( ( m_nulValues[band] != DEFAULT_NULL ) && // -32768
573  ( m_nulValues[band] != -32767.0 ) &&
574  ( m_nulValues[band] != -32766.0 ) &&
575  ( m_nulValues[band] != -9999.0 ) )
576  {
577  if ( ( m_nulValues[band] > -9999.0 ) &&
578  ( m_nulValues[band] < m_minValues[band] ) )
579  {
580  m_minValues[band] = m_nulValues[band];
581  }
582  m_nulValues[band] = DEFAULT_NULL;
583  }
584  }
585  break;
586  }
587  case OSSIM_SINT32:
588  {
589  for (ossim_uint32 band = 0; band < BANDS; ++band)
590  {
591  if ( ( m_nulValues[band] != DEFAULT_NULL ) &&
592  ( m_nulValues[band] != -32768.0 ) && // Common null
593  ( m_nulValues[band] != -32767.0 ) && // The other common null.
594  ( m_nulValues[band] != -32766.0 ) &&
595  ( m_nulValues[band] != -9999.0 ) &&
596  ( m_nulValues[band] != -99999.0 ) )
597  {
598  if ( ( m_nulValues[band] > -9999.0 ) &&
599  ( m_nulValues[band] < m_minValues[band] ) )
600  {
601  m_minValues[band] = m_nulValues[band];
602  }
603  m_nulValues[band] = DEFAULT_NULL;
604  }
605  }
606  break;
607  }
608  case OSSIM_FLOAT32:
609  case OSSIM_FLOAT64:
610  {
611  for (ossim_uint32 band = 0; band < BANDS; ++band)
612  {
613  if ( ( m_nulValues[band] != DEFAULT_NULL ) &&
614  ( m_nulValues[band] != -32768.0 ) &&
615  ( m_nulValues[band] != -32767.0 ) &&
616  ( m_nulValues[band] != -32766.0 ) &&
617  ( m_nulValues[band] != -9999.0 ) &&
618  ( m_nulValues[band] != -99999.0 ) )
619  {
620  if ( ( m_nulValues[band] > -9999 ) &&
621  ( m_nulValues[band] < m_minValues[band] ) )
622  {
623  m_minValues[band] = m_nulValues[band];
624  }
625  m_nulValues[band] = DEFAULT_NULL;
626  }
627  }
628  break;
629  }
632  {
633  for (ossim_uint32 band = 0; band < BANDS; ++band)
634  {
635  if ( ( m_nulValues[band] != DEFAULT_NULL ) &&
636  ( m_nulValues[band] > 0.0) )
637  {
638  if ( m_nulValues[band] < m_minValues[band] )
639  {
640  m_minValues[band] = m_nulValues[band];
641  }
642  m_nulValues[band] = 0.0;
643  }
644  }
645  break;
646  }
648  default:
649  {
650  if(traceDebug())
651  {
653  << __FILE__ << ":" << __LINE__
654  << " " << M << "\nUnhandled scalar type: " << SCALAR << std::endl;
655  }
656  break;
657  }
658 
659  } // End: switch(SCALAR)
660 
661  } // Matches: if ( (m_minValues.size() == BANDS) &&...
662  else
663  {
664  // ERROR!
666  << M << "ERROR:\nMin, max and null array sizes bad! No omd file will be written."
667  << std::endl;
668  }
669 
670  } // Matches: else if ( m_scanForMinMaxNull == true )
671  else
672  {
673  // Get the values from the image handler.
674  if (m_minValues.size() != BANDS)
675  {
676  m_minValues.resize(BANDS);
677  for (ossim_uint32 band = 0; band < BANDS; ++band)
678  {
680  }
681  }
682  if (m_maxValues.size() != BANDS)
683  {
684  m_maxValues.resize(BANDS);
685  for (ossim_uint32 band = 0; band < BANDS; ++band)
686  {
688  }
689  }
690  if (m_nulValues.size() != BANDS)
691  {
692  m_nulValues.resize(BANDS);
693  for (ossim_uint32 band = 0; band < BANDS; ++band)
694  {
696  }
697  }
698  }
699 
700  // Last size check as the m_scanForMinMaxNull block could have failed.
701  if ( ( m_minValues.size() == BANDS ) &&
702  ( m_maxValues.size() == BANDS ) &&
703  ( m_nulValues.size() == BANDS ) )
704  {
705  // Write the omd file:
706  ossimKeywordlist kwl;
707  if( ossimFilename(file).exists())
708  {
709  // Pick up existing omd file.
710  kwl.addFile(file.c_str());
711  }
712  ossimImageMetaData metaData(SCALAR, BANDS);
713  for(ossim_uint32 band = 0; band < BANDS; ++band)
714  {
715  metaData.setMinPix(band, m_minValues[band]);
716  metaData.setMaxPix(band, m_maxValues[band]);
717  metaData.setNullPix(band, m_nulValues[band]);
718  }
719  // Save to keyword list.
720  metaData.saveState(kwl);
721 
722  // Write to disk.
723  result = kwl.write(file.c_str());
724  if ( result )
725  {
726  ossimNotify(ossimNotifyLevel_NOTICE) << "Wrote file: " << file << "\n";
727  }
728  else
729  {
730  ossimNotify(ossimNotifyLevel_WARN) << "ERROR writing file: " << file << "\n";
731  }
732  }
733 
734  if ( traceDebug() )
735  {
737  << "Final array values:\n";
738  std::vector<ossim_float64>::const_iterator i = m_minValues.begin();
739  ossim_int32 band = 0;
740  while ( i < m_minValues.end() )
741  {
743  << "min[" << band++ << "]: " << *i << "\n";
744  ++i;
745  }
746  i = m_maxValues.begin();
747  band = 0;
748  while ( i < m_maxValues.end() )
749  {
751  << "max[" << band++ << "]: " << *i << "\n";
752  ++i;
753  }
754  i = m_nulValues.begin();
755  band = 0;
756  while ( i < m_nulValues.end() )
757  {
759  << "nul[" << band++ << "]: " << *i << "\n";
760  ++i;
761  }
762  }
763 
764  } // Matches: if ( file && m_imageHandler.valid() )
765 
766  if ( traceDebug() )
767  {
768  ossimNotify(ossimNotifyLevel_DEBUG) << M << " exit status" << (result?"true\n":"false\n");
769  }
770 
771  return result;
772 }
773 
775 {
776  if (!m_imageHandler) return;
777 
778  getOutputTileRectangle(inputRect);
779  inputRect = inputRect * m_decimationFactor;
780 
781 #if 0
782  if (traceDebug())
783  {
785  << "ossimOverviewSequencer::getInputTileRectangle DEBUG:"
786  << "input rect: " << inputRect << std::endl;
787  }
788 #endif
789 }
790 
792  ossimIrect& outputRect) const
793 {
794  // Get the row and column.
797 
798  ossimIpt pt;
799 
800  // Set the upper left.
801  pt.y = row * m_tileSize.y;
802  pt.x = col * m_tileSize.x;
803  outputRect.set_ul(pt);
804 
805  // Set the lower right.
806  pt.y = pt.y + m_tileSize.y - 1;
807  pt.x = pt.x + m_tileSize.x - 1;
808  outputRect.set_lr(pt);
809 
810 #if 0
811  if (traceDebug())
812  {
814  << "ossimOverviewSequencer::getOutputTileRectangle DEBUG:"
815  << "output rect: " << outputRect << std::endl;
816  }
817 #endif
818 }
819 
821 {
823  {
826  m_dirtyFlag = true;
827  }
828  else
829  {
830  // Get the output rectangle.
831  ossimIrect rect;
833 
835  static_cast<ossim_uint32>( rect.width() / m_tileSize.x );
837  static_cast<ossim_uint32>( rect.height() / m_tileSize.y );
838 
839  if (rect.width() % m_tileSize.x)
840  {
842  }
843  if (rect.height() % m_tileSize.y)
844  {
846  }
847  }
848 }
849 
851 {
853  {
854  case OSSIM_UINT8:
855  {
856  resampleTile(inputTile, ossim_uint8(0));
857  break;
858  }
859 
860  case OSSIM_USHORT11:
861  case OSSIM_USHORT12:
862  case OSSIM_USHORT13:
863  case OSSIM_USHORT14:
864  case OSSIM_USHORT15:
865  case OSSIM_UINT16:
866  {
867  resampleTile(inputTile, ossim_uint16(0));
868  break;
869  }
870  case OSSIM_SINT16:
871  {
872  resampleTile(inputTile, ossim_sint16(0));
873  break;
874  }
875 
876  case OSSIM_UINT32:
877  {
878  resampleTile(inputTile, ossim_uint32(0));
879  break;
880  }
881 
882  case OSSIM_SINT32:
883  {
884  resampleTile(inputTile, ossim_sint32(0));
885  break;
886  }
887 
888  case OSSIM_FLOAT32:
889  {
890  resampleTile(inputTile, ossim_float32(0.0));
891  break;
892  }
893 
895  case OSSIM_FLOAT64:
896  {
897  resampleTile(inputTile, ossim_float64(0.0));
898  break;
899  }
900  default:
902  << "ossimOverviewSequencer::resampleTile Unknown pixel type!"
903  << std::endl;
904  return;
905 
906  } // End of "switch(m_imageHandler->getOutputScalarType())"
907 }
908 
909 template <class T>
910 void ossimOverviewSequencer::resampleTile(const ossimImageData* inputTile, T /* dummy */ )
911 {
912 #if 0
913  if (traceDebug())
914  {
916  << "ossimOverviewSequencer::resampleTile DEBUG: "
917  << "\ncurrent tile: " << m_currentTileNumber
918  << "\ninput tile:\n" << *inputTile
919  << "output tile:\n" << *(m_tile.get())
920  << endl;
921  }
922 #endif
923 
924  const ossim_uint32 BANDS = m_tile->getNumberOfBands();
925  const ossim_uint32 LINES = m_tile->getHeight();
926  const ossim_uint32 SAMPS = m_tile->getWidth();
927  const ossim_uint32 INPUT_WIDTH = m_decimationFactor*m_tileSize.x;
928 
929  T nullPixel = 0;
930  ossim_float64 weight = 0.0;
931  ossim_float64 value = 0.0;
932  ossim_uint32 sampOffset = 0;
933 
935  {
936  for (ossim_uint32 band=0; band<BANDS; ++band)
937  {
938  const T* s = static_cast<const T*>(inputTile->getBuf(band)); // source
939  T* d = static_cast<T*>(m_tile->getBuf(band)); // destination
940 
941  nullPixel = static_cast<T>(inputTile->getNullPix(band));
942  weight = 0.0;
943  value = 0.0;
944 
945  for (ossim_uint32 i=0; i<LINES; ++i)
946  {
947  for (ossim_uint32 j=0; j<SAMPS; ++j)
948  {
949  sampOffset = j*m_decimationFactor;
950 
951  weight = 1.0;
952  value = *(s + i*m_decimationFactor*INPUT_WIDTH + sampOffset);
953 
954  if(weight)
955  {
956  d[j] = static_cast<T>( value/weight );
957  }
958  else
959  {
960  d[j] = nullPixel;
961  }
962 
963  } // End of sample loop.
964 
965  d += m_tileSize.x;
966 
967  } // End of line loop.
968 
969  } // End of band loop.
970 
971  }
972  else // ossimFilterResampler::ossimFilterResampler_BOX
973  {
974  ossim_uint32 lineOffset1 = 0;
975  ossim_uint32 lineOffset2 = 0;
976  ossim_float64 ul = 0.0;
977  ossim_float64 ur = 0.0;
978  ossim_float64 ll = 0.0;
979  ossim_float64 lr = 0.0;
980 
981  for (ossim_uint32 band=0; band<BANDS; ++band)
982  {
983  const T* s = static_cast<const T*>(inputTile->getBuf(band)); // source
984  T* d = static_cast<T*>(m_tile->getBuf(band)); // destination
985 
986  nullPixel = static_cast<T>(inputTile->getNullPix(band));
987  weight = 0.0;
988  value = 0.0;
989 
990  for (ossim_uint32 i=0; i<LINES; ++i)
991  {
992  lineOffset1 = i*m_decimationFactor*INPUT_WIDTH;
993  lineOffset2 = (i*m_decimationFactor+1)*INPUT_WIDTH;
994 
995  for (ossim_uint32 j=0; j<SAMPS; ++j)
996  {
997  sampOffset = j*m_decimationFactor;
998 
999  weight = 0.0;
1000  value = 0.0;
1001 
1002  //---
1003  // Grab four pixels from the source, average, and assign
1004  // to output.
1005  //---
1006  ul = *(s + lineOffset1 + sampOffset);
1007  ur = *(s + lineOffset1 + sampOffset + 1);
1008  ll = *(s + lineOffset2 + sampOffset);
1009  lr = *(s + lineOffset2 + sampOffset + 1);
1010 
1011  if(ul != nullPixel)
1012  {
1013  ++weight;
1014  value += ul;
1015  }
1016  if(ur != nullPixel)
1017  {
1018  ++weight;
1019  value += ur;
1020  }
1021  if(ll != nullPixel)
1022  {
1023  ++weight;
1024  value += ll;
1025  }
1026  if(lr != nullPixel)
1027  {
1028  ++weight;
1029  value += lr;
1030  }
1031 
1032  if(weight)
1033  {
1034  d[j] = static_cast<T>( value/weight );
1035  }
1036  else
1037  {
1038  d[j] = nullPixel;
1039  }
1040 
1041  } // End of sample loop.
1042 
1043  d += m_tileSize.x;
1044 
1045  } // End of line loop.
1046 
1047  } // End of band loop.
1048  }
1049 }
1050 
1052  ossimMaskFilter* mask_filter)
1053 {
1054  m_maskWriter = mask_writer;
1055  m_maskFilter = mask_filter;
1056 }
16 bit unsigned integer (15 bits used)
8 bit signed integer
virtual ossim_uint32 getWidth() const
void setScanForMinMaxNull(bool flag)
Turn on/off scan for min, max, null flag.
std::vector< ossim_float64 > m_maxValues
ossim_uint32 getNumberOfTilesHorizontal() const
ossimHistogramMode
ossim_int32 m_decimationFactor
TODO make this handle any decimation.
virtual ossim_uint32 getNumberOfBands() const
64 bit floating point
virtual void setImageRectangle(const ossimIrect &rect)
16 bit unsigned integer
ossim_uint32 m_histoTileIndex
Used to determine which tiles to accumulate a histogram from.
virtual void populateHistogram(ossimRefPtr< ossimMultiBandHistogram > histo)
virtual void setWidthHeight(ossim_uint32 w, ossim_uint32 h)
Represents serializable keyword/value map.
bool addFile(const char *file)
virtual void computeMinMaxPix(std::vector< ossim_float64 > &minBands, std::vector< ossim_float64 > &maxBands) const
If the minBands and maxBands are empty or not equal to the imageData&#39;s current number of bands it wil...
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
ossimOverviewSequencer()
default constructor
bool valid() const
Definition: ossimRefPtr.h:75
ossimRefPtr< ossimImageData > m_tile
ossimReferenced allows for shared object ref counting if the reference count ever gets to 0 or less i...
float ossim_float32
ossimRefPtr< ossimImageHandler > m_imageHandler
ossim_uint32 height() const
Definition: ossimIrect.h:487
ossimRefPtr< ossimBitMaskWriter > m_maskWriter
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
std::vector< ossim_float64 > m_nulValues
virtual void getOutputImageRectangle(ossimIrect &rect) const
Gets the zero-based image rectangle for the output reduced resolution data set (rrds).
std::vector< ossim_float64 > m_minValues
Arrays o hold the min value for each band for scan min/max methods.
16 bit signed integer
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
ossim_uint32 getNumberOfTilesVertical() const
16 bit unsigned integer (14 bits used)
ossim_uint32 getNumberOfTiles() const
16 bit unsigned integer (13 bits used)
32 bit floating point
unsigned short ossim_uint16
32 bit unsigned integer
virtual bool write(const char *file, const char *comment=0) const
Methods to dump the ossimKeywordlist to a file on disk.
virtual void initialize()
Initialize the data buffer.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
Main entry point for the algorithm.
virtual ossim_uint32 getTileWidth() const
Returns the default processing tile width.
virtual void computeMinMaxNulPix(std::vector< ossim_float64 > &minBands, std::vector< ossim_float64 > &maxBands, std::vector< ossim_float64 > &nulBands) const
Scans tile for min, max, nulls.
#define OSSIM_DEFAULT_TILE_WIDTH
virtual double getMinPixelValue(ossim_uint32 band=0) const
Retuns the min pixel value.
void set_ul(const ossimIpt &pt)
Definition: ossimIrect.h:589
ossimFilterResampler::ossimFilterResamplerType m_resampleType
Currently only handles NEAREST_NEIGHBOR and BOX (default = BOX)
void setMinPix(ossim_uint32 band, double pix)
double ossim_float64
virtual void setToStartOfSequence()
Will set the internal pointers to the upperleft tile number.
bool m_dirtyFlag
Dirty flag - if true, this object is not initialized.
ossimRefPtr< ossimMaskFilter > m_maskFilter
void updateTileDimensions()
Updates theNumberOfTilesHorizontal and theNumberOfTilesVertical.
static ossimImageDataFactory * instance()
void resampleTile(const ossimImageData *inputTile)
Resamples a patch of data.
void writeHistogram()
Write histogram method.
virtual ossimDataObjectStatus validate() const
bool exists() const
void setTileSize(const ossimIpt &pt)
updated the tile size.
signed short ossim_sint16
32 bit signed integer
OSSIM_DLL double defaultNull(ossimScalarType scalarType)
bool m_scanForMinMax
Control flags for min, max, null scanning.
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
32 bit normalized floating point
ossimRefPtr< ossimMultiBandHistogram > m_histogram
signed int ossim_sint32
virtual void addHistogram(ossimMultiBandHistogram *histo)
virtual ossimRefPtr< ossimImageData > getNextTile()
Will allow you to get the next tile in the sequence.
ossim_uint32 m_sourceResLevel
This is the resolution level to build overviews from.
Class for computing a mask from an input image source and writing the mask file to disk...
virtual ossimIrect getImageRectangle(ossim_uint32 resLevel=0) const
Returns zero-based bounding rectangle of the image.
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimScalarType
void setImageHandler(ossimImageHandler *input)
Sets the input source or connection.
void generateMask(ossimRefPtr< ossimImageData > tile, ossim_uint32 rLevel)
Given a source&#39;s tile, derives the alpha mask and saves it in buffer for later writing to disk...
virtual void makeBlank()
Initializes data to null pixel values.
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
int getRank() const
Definition: ossimMpi.cpp:140
void set_lr(const ossimIpt &pt)
Definition: ossimIrect.h:623
void clearMinMaxNullArrays()
Clears out the arrays from a scan for min, max, nulls.
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
This class defines an abstract Handler which all image handlers(loaders) should derive from...
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
ossim_int32 y
Definition: ossimIpt.h:142
void makeNan()
Definition: ossimIrect.h:329
virtual const void * getBuf() const
void setScanForMinMax(bool flag)
Turn on/off scan for min max flag.
void setSourceLevel(ossim_uint32 level)
Sets the input source resolution to decimate from.
virtual void slaveProcessTiles()
This implementation does nothing.
#define OSSIM_DEFAULT_TILE_HEIGHT
virtual ~ossimOverviewSequencer()
virtual destructor
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
void getInputTileRectangle(ossimIrect &inputRect) const
Gets the image rectangle for the input tile for theCurrentTileNumber.
ossimHistogramMode m_histoMode
bool hasNans() const
Definition: ossimIrect.h:337
void setHistogramMode(ossimHistogramMode mode)
Sets the histogram accumulation mode.
ossim_int32 x
Definition: ossimIpt.h:141
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
ossimHistogramMode getHistogramMode() const
Gets the histogram accumulation mode.
8 bit unsigned integer
bool writeOmdFile(const std::string &file)
Writes an ossim metadata(omd) file with min, max, null values.
bool hasNans() const
Definition: ossimIpt.h:58
void setBitMaskObjects(ossimBitMaskWriter *mask_writer, ossimMaskFilter *mask_filter)
Enabled the generation of an alpha (bit) mask such that any full or partial null pixels will be maske...
virtual ossim_uint32 getNumberOfInputBands() const =0
void create(const ossimImageSource *input)
ossimFilename getFilenameWithThisExtension(const ossimString &ext, bool set_e0_prefix=false) const
Returns the image file with extension set using supplentary directory for dirname if set...
static ossimMpi * instance()
Definition: ossimMpi.cpp:27
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
void getOutputTileRectangle(ossimIrect &outputRect) const
Gets the image rectangle for the output tile for theCurrentTileNumber.
void setMaxPix(ossim_uint32 band, double pix)
unsigned char ossim_uint8
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void setResampleType(ossimFilterResampler::ossimFilterResamplerType resampleType)
Sets the resampling type.
virtual void initialize()
This must be called.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
void setNullPix(ossim_uint32 band, double pix)
int ossim_int32
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
16 bit unsigned integer (12 bits used)