OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageUtil.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 // File: ossimImageUtil.cpp
3 //
4 // License: MIT
5 //
6 // Author: David Burken
7 //
8 // Description: ossimImageUtil class definition
9 //
10 // Utility class for processing image recursively. This is for doing things like:
11 // building overview, histograms, compute min/max, extract vertices.
12 //
13 //----------------------------------------------------------------------------
14 // $Id$
15 
19 #include <ossim/base/ossimCommon.h>
21 #include <ossim/base/ossimDatum.h>
23 #include <ossim/base/ossimDrect.h>
29 #include <ossim/base/ossimGpt.h>
30 #include <ossim/init/ossimInit.h>
32 #include <ossim/base/ossimNotify.h>
38 #include <ossim/base/ossimString.h>
40 #include <ossim/base/ossimTrace.h>
50 #include <ossim/init/ossimInit.h>
65 
66 #include <cstdlib>
67 #include <iomanip>
68 #include <string>
69 #include <vector>
70 
71 static std::string CMM_MAX_KW = "cmm_max"; // CMM(ComputeMinMax)
72 static std::string CMM_MIN_KW = "cmm_min";
73 static std::string CMM_NULL_KW = "cmm_null";
74 static std::string COPY_ALL_FLAG_KW = "copy_all_flag";
75 static std::string CREATE_HISTOGRAM_KW = "create_histogram";
76 static std::string CREATE_HISTOGRAM_FAST_KW = "create_histogram_fast";
77 static std::string CREATE_HISTOGRAM_R0_KW = "create_histogram_r0";
78 static std::string CREATE_OVERVIEWS_KW = "create_overviews";
79 static std::string CREATE_THUMBNAILS_KW = "create_thumbnails";
80 static std::string DUMP_FILTERED_IMAGES_KW = "dump_filter_image";
81 static std::string FALSE_KW = "false";
82 static std::string FILE_KW = "file";
83 static std::string INTERNAL_OVERVIEWS_FLAG_KW = "internal_overviews_flag";
84 static std::string OUTPUT_DIRECTORY_KW = "output_directory";
85 static std::string OUTPUT_FILENAMES_KW = "output_filenames";
86 static std::string OVERRIDE_FILTERED_IMAGES_KW = "override_filtered_images";
87 static std::string OVERVIEW_STOP_DIM_KW = "overview_stop_dimension";
88 static std::string OVERVIEW_TYPE_KW = "overview_type";
89 static std::string READER_PROP_KW = "reader_prop";
90 static std::string REBUILD_HISTOGRAM_KW = "rebuild_histogram";
91 static std::string REBUILD_OVERVIEWS_KW = "rebuild_overviews";
92 static std::string SCAN_MIN_MAX_KW = "scan_for_min_max";
93 static std::string SCAN_MIN_MAX_NULL_KW = "scan_for_min_max_null";
94 static std::string THREADS_KW = "threads";
95 static std::string THUMBNAIL_SIZE_KW = "thumbnail_size";
96 static std::string THUMBNAIL_STRETCH_TYPE_KW = "thumbnail_stretch_type";
97 static std::string THUMBNAIL_TYPE_KW = "thumbnail_type";
98 static std::string TILE_SIZE_KW = "tile_size";
99 static std::string TRUE_KW = "true";
100 static std::string WRITER_PROP_KW = "writer_prop";
101 
102 // Static trace for debugging. Use -T ossimImageUtil to turn on.
103 static ossimTrace traceDebug = ossimTrace("ossimImageUtil:debug");
104 
106  :
107  ossimReferenced(),
109  m_kwl( new ossimKeywordlist() ),
110  m_fileWalker(0),
111  m_mutex(),
112  m_errorStatus(0),
113  m_filteredImages(0)
114 {
115 }
116 
118 {
119  if ( m_fileWalker )
120  {
121  delete m_fileWalker;
122  m_fileWalker = 0;
123  }
124 }
125 
127 {
128  // Set the command line options:
129  au->addCommandLineOption("-a or --include-fullres", "Copy full res dataset to overview file as well as building reduced res sets. Option only valid with tiff overview builder. Requires -o option.");
130 
131  au->addCommandLineOption("--ch or --create-histogram", "Computes full histogram alongside overview.");
132 
133  au->addCommandLineOption("--chf or --create-histogram-fast", "Computes a histogram in fast mode which samples partial tiles.");
134  au->addCommandLineOption("--ct or --create-thumbnail", "computes a thumbnail of the image");
135  au->addCommandLineOption("--tt or --thumbnail-type", "Can be of of values png or jpeg");
136  au->addCommandLineOption("--tst or --thumbnail-stretch-type", "Can be of values none,auto-minmax,auto-percentile,std-stretch-1,std-stretch-2,std-stretch-3");
137 
138  au->addCommandLineOption("--compression-quality", "Compression quality for TIFF JPEG takes values from 0 to 100, where 100 is best. For J2K plugin, numerically_lossless, visually_lossless, lossy");
139 
140  au->addCommandLineOption("--compute-min-max", "Turns on min, max scanning when reading tiles and writes a dot omd file. This option assumes the null is known.");
141 
142  au->addCommandLineOption("--compute-min-max-null", "Turns on min, max, null scanning when reading tiles and write a dot omd file. This option tries to find a null value which is useful for float data.");
143 
144  au->addCommandLineOption("--compression-type", "Compression type can be: deflate, jpeg, lzw, none or packbits");
145 
146  au->addCommandLineOption("--create-histogram-r0", "Forces create-histogram code to compute a histogram using r0 instead of the starting resolution for the overview builder. Can require a separate pass of R0 layer if the base image has built in overviews.");
147 
148  au->addCommandLineOption("-d", "<output_directory> Write overview to output directory specified.");
149 
150  au->addCommandLineOption("--dump-filtered-image-list", "Outputs list of filtered images and extensions.");
151 
152  au->addCommandLineOption("-h", "Display this information");
153 
154  au->addCommandLineOption("-i or --internal-overviews", "Builds internal overviews. Requires -o option. Option only valid with tiff input image and tiff overview builder. WARNING: Modifies source image and cannot be undone!");
155 
156  au->addCommandLineOption("--list-entries", "Lists the entries within the image");
157 
158  au->addCommandLineOption("--max","Overrides max value for compute-min-max option.");
159 
160  au->addCommandLineOption("--min","Overrides min value for compute-min-max option.");
161 
162  au->addCommandLineOption("--null", "<null_value> Overrides null value for compute-min-max option. e.g. -9999.0 for float data");
163 
164  au->addCommandLineOption("-o", "Creates overviews. (default=ossim_tiff_box)");
165 
166  au->addCommandLineOption("--of or --output-files", "Output image files we can open, exluding overviews.");
167 
168  au->addCommandLineOption("--options","<options.kwl> This can be all or part of the application options. Also used for custom prep, per file and post system commands. To get a template you can turn on trace to the ossimImageUtil class by adding \"-T ossimImageUtil\" to your command.");
169 
170  au->addCommandLineOption("--ot", "<overview_type> Overview type. see list at bottom for valid types. (default=ossim_tiff_box)");
171 
172  au->addCommandLineOption("--override-filtered-images", "Allows processing of file that is in the filtered image list.");
173 
174  au->addCommandLineOption("-r or --rebuild-overviews", "Rebuild overviews even if they are already present.");
175 
176  au->addCommandLineOption("--rebuild-histogram", "Rebuild histogram even if they are already present.");
177 
178  au->addCommandLineOption("--reader-prop", "Adds a property to send to the reader. format is name=value");
179 
180  au->addCommandLineOption("-s", "Stop dimension for overviews. This controls how \nmany layers will be built. If set to 64 then the builder will stop when height and width for current level are less than or equal to 64. Note a default can be set in the ossim preferences file by setting the keyword \"overview_stop_dimension\".");
181 
182  au->addCommandLineOption("--tile-size", "<size> Defines the tile size for overview builder. Tiff option only. Must be a multiple of 16. Size will be used in both x and y directions. Note a default can be set in your ossim preferences file by setting the key \"tile_size\".");
183 
184  au->addCommandLineOption("--threads", "<threads> The number of threads to use. (default=1) Note a default can be set in your ossim preferences file by setting the key \"ossim_threads\".");
185 
186  au->addCommandLineOption("--writer-prop", "Adds a property to send to the writer. format is name=value");
187 }
188 
190 {
191  // Set the general usage:
193  ossimString usageString = ap.getApplicationName();
194  usageString += " [options] <file-or-directory-to-walk>";
195  au->setCommandLineUsage(usageString);
196 
197  addOptions(au);
198 
199 } // void ossimImageUtil::addArguments(ossimArgumentParser& ap)
200 
202 {
203  static const char M[] = "ossimImageUtil::initialize(ossimArgumentParser&)";
204  if ( traceDebug() )
205  {
206  ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\n";
207  }
208 
209  bool result = true;
210 
211  if ( (ap.argc() == 1) || ap.read("-h") || ap.read("--help") )
212  {
213  usage(ap);
214 
215  // continue_after_init to false
216  result = false;
217  }
218  else
219  {
220  // Start with clean options keyword list.
221  m_kwl->clear();
222 
223  // Used throughout below:
224  std::string ts1;
226  std::string ts2;
228 
229  while ( 1 ) // While forever loop...
230  {
231  if( ap.read("-a") || ap.read("--include-fullres") )
232  {
233  setCopyAllFlag( true );
234  if ( ap.argc() < 2 )
235  {
236  break;
237  }
238  }
239 
240  if( ap.read("--compression-quality", sp1) )
241  {
242  if ( ts1.size() )
243  {
244  setCompressionQuality( ts1 );
245  }
246  if ( ap.argc() < 2 )
247  {
248  break;
249  }
250  }
251 
252  if( ap.read("--compression-type", sp1) )
253  {
254  if ( ts1.size() )
255  {
256  setCompressionType( ts1 );
257  }
258  if ( ap.argc() < 2 )
259  {
260  break;
261  }
262  }
263 
264  if( ap.read("--ch") || ap.read("--create-histogram") )
265  {
266  setCreateHistogramFlag( true );
267  if ( ap.argc() < 2 )
268  {
269  break;
270  }
271  }
272 
273  if( ap.read("--chf") || ap.read("--create-histogram-fast") )
274  {
276  if ( ap.argc() < 2 )
277  {
278  break;
279  }
280  }
281 
282  if( ap.read("--compute-min-max") )
283  {
284  setScanForMinMax( true );
285  if ( ap.argc() < 2 )
286  {
287  break;
288  }
289  }
290 
291  if( ap.read("--compute-min-max-null") )
292  {
293  setScanForMinMaxNull( true );
294  if ( ap.argc() < 2 )
295  {
296  break;
297  }
298  }
299 
300  if( ap.read("--create-histogram-r0") )
301  {
302  setCreateHistogramR0Flag( true );
303  if ( ap.argc() < 2 )
304  {
305  break;
306  }
307  }
308 
309  if( ap.read("-d", sp1) )
310  {
311  setOutputDirectory( ts1 );
312  if ( ap.argc() < 2 )
313  {
314  break;
315  }
316  }
317 
318  if( ap.read("--dump-filtered-image-list") )
319  {
321  if ( ap.argc() < 2 )
322  {
323  break;
324  }
325  }
326 
327  if( ap.read("-i") || ap.read("--internal-overviews") )
328  {
329  setInternalOverviewsFlag( true );
330  if ( ap.argc() < 2 )
331  {
332  break;
333  }
334  }
335 
336  if( ap.read("--max", sp1) )
337  {
338  addOption( CMM_MAX_KW, ts1 );
339  if ( ap.argc() < 2 )
340  {
341  break;
342  }
343  }
344 
345  if( ap.read("--min", sp1) )
346  {
347  addOption( CMM_MIN_KW, ts1 );
348  if ( ap.argc() < 2 )
349  {
350  break;
351  }
352  }
353 
354  if( ap.read("--null", sp1) )
355  {
356  addOption( CMM_NULL_KW, ts1 );
357  if ( ap.argc() < 2 )
358  {
359  break;
360  }
361  }
362 
363  if( ap.read("--options", sp1) )
364  {
365  ossimFilename optionsKwl = ts1;
366  if ( optionsKwl.exists() )
367  {
368  if ( m_kwl->addFile(optionsKwl) == false )
369  {
370  std::string errMsg = "ERROR could not open options keyword list file: ";
371  errMsg += optionsKwl.string();
372  throw ossimException(errMsg);
373  }
374  }
375  else
376  {
377  std::string errMsg = "ERROR options keyword list file does not exists: ";
378  errMsg += optionsKwl.string();
379  throw ossimException(errMsg);
380  }
381  }
382 
383  if( ap.read("--of") || ap.read("--output-files") )
384  {
385  setOutputFileNamesFlag( true );
386  if ( ap.argc() < 2 )
387  {
388  break;
389  }
390  }
391 
392  if (ap.read("-o"))
393  {
395  if (ap.argc() < 2)
396  {
397  break;
398  }
399  }
400  if (ap.read("--ct"))
401  {
403  if (ap.argc() < 2)
404  {
405  break;
406  }
407  }
408  if (ap.read("--tt", sp1) || ap.read("--thumbnail-type", sp1))
409  {
410  setThumbnailType(ts1);
411  if (ap.argc() < 2)
412  {
413  break;
414  }
415  }
416  if (ap.read("--tst", sp1) || ap.read("--thumbnail-stretch-type", sp1))
417  {
419  if (ap.argc() < 2)
420  {
421  break;
422  }
423  }
424 
425  if (ap.read("--ot", sp1))
426  {
427  setOverviewType( ts1 );
428  if ( ap.argc() < 2 )
429  {
430  break;
431  }
432  }
433 
434  if( ap.read("--override-filtered-images") )
435  {
437  if ( ap.argc() < 2 )
438  {
439  break;
440  }
441  }
442 
443  if( ap.read("-r") || ap.read("--rebuild-overviews") )
444  {
445  setRebuildOverviewsFlag( true );
446  if ( ap.argc() < 2 )
447  {
448  break;
449  }
450  }
451 
452  if( ap.read("--rebuild-histogram") )
453  {
454  setRebuildHistogramFlag( true );
455  if ( ap.argc() < 2 )
456  {
457  break;
458  }
459  }
460 
461  while(ap.read("--reader-prop", sp1))
462  {
463  if (ts1.size())
464  {
465  std::string key = READER_PROP_KW;
467  addOption( key, ts1 );
468  }
469  }
470  if ( ap.argc() < 2 )
471  {
472  break;
473  }
474 
475  if( ap.read("-s", sp1) )
476  {
478  if ( ap.argc() < 2 )
479  {
480  break;
481  }
482  }
483 
484  if ( ap.read("--tile-size", sp1))
485  {
486  setTileSize( ossimString(ts1).toInt32() );
487  if ( ap.argc() < 2 )
488  {
489  break;
490  }
491  }
492 
493  if( ap.read("--threads", sp1) )
494  {
495  m_kwl->addPair( THREADS_KW, ts1 );
496  if ( ap.argc() < 2 )
497  {
498  break;
499  }
500  }
501 
502  while(ap.read("--writer-prop", sp1))
503  {
504  if (ts1.size())
505  {
506  std::string key = WRITER_PROP_KW;
508  addOption( key, ts1 );
509  }
510  }
511  if ( ap.argc() < 2 )
512  {
513  break;
514  }
515 
516  // End of arg parsing.
518  if ( ap.errors() )
519  {
521  std::string errMsg = "Unknown option...";
522  throw ossimException(errMsg);
523  }
524 
525  break; // Break from while forever.
526 
527  } // End while (forever) loop.
528 
529  if(ap.argc() > 1)
530  {
531  for (ossim_int32 i = 0; i < (ap.argc()-1); ++i)
532  {
533  ossimString kw = FILE_KW;
534  kw += ossimString::toString(i);
535  std::string value = ap[i+1];
536  m_kwl->addPair(kw.string(), value, true);
537  }
538  }
539  else
540  {
541  if ( getDumpFilterImagesFlag() )
542  {
543  // Caller wants to see filtered image names:
544  if ( m_filteredImages.empty() )
545  {
547  }
548 
549  // Dump our filtered images.
551 
552  if ( !m_fileWalker )
553  {
556  }
557 
558  // Dump the file walker's filtered extensions.
560  }
561  else
562  {
563  usage(ap);
564  }
565 
566  // continue_after_init to false
567  result = false;
568 
569  }
570 
571  } // not usage
572 
573  if ( traceDebug() )
574  {
576  << "m_kwl:\n" << *(m_kwl.get()) << "\n"
577  << M << " exit result = " << (result?"true":"false")
578  << "\n";
579  }
580 
581  return result;
582 }
583 
585 {
586  static const char M[] = "ossimImageUtil::execute()";
587 
588  if ( traceDebug() )
589  {
590  ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\n";
591  }
592 
593  // Launch any prep system commands:
595 
596  // Get the number of "file*" keywords.
597  ossim_uint32 fileCount = m_kwl->numberOf("file");
598 
599  if ( fileCount )
600  {
601  if ( !m_fileWalker )
602  {
604  }
605 
607 
608  // Must set this so we can stop recursion on directory based images.
610 
611  // This links the file walker back to our "processFile" method.
613 
614  // Wrap in try catch block as excptions can be thrown under the hood.
615  try
616  {
617  // Get the list of files passed to us:
618  std::vector<ossimFilename> files;
619  ossim_uint32 processedFiles = 0;;
620  ossim_uint32 i = 0;
621  while ( processedFiles < fileCount )
622  {
623  ossimString key = FILE_KW;
624  key += ossimString::toString(i);
625  std::string lookup = m_kwl->findKey( key.string() );
626  if ( lookup.size() )
627  {
628  files.push_back( ossimFilename(lookup) );
629  ++processedFiles;
630  }
631 
632  ++i;
633  if ( i > (fileCount + 100) ) break;
634  }
635 
636  //---
637  // If the file count is one and it is not a directory, we will assume
638  // the caller wanted to process that file. So leave the filter list
639  // blank.
640  //---
641  if ( (getOverrideFilteredImagesFlag() == false) && files.size() &&
642  ( (files.size() > 1) || (files[0].isDir() == true) ) )
643  {
644  if ( m_filteredImages.empty() )
645  {
647  }
648  if ( m_fileWalker->getFilteredExtensions().empty() )
649  {
651  }
652  }
653 
654  // Process the files:
655  m_fileWalker->walk( files );
656  }
657  catch (const ossimException& e)
658  {
660  << "Caught exception: " << e.what() << endl;
662  }
663 
664  } // if ( fileCount )
665 
666  // Launch any post system commands:
668 
669  if ( traceDebug() )
670  {
672  << M << " exit status: " << m_errorStatus << std::endl;
673  }
674 
675  // Zero is good, non zero is bad.
676  return m_errorStatus;
677 }
678 
679 //---
680 // This method is called back by the ossimFileWalker::walk method for each file it finds that it
681 // deems can be processed.
682 //---
684 {
685  static const char M[] = "ossimImageUtil::processFile";
686  if(traceDebug())
687  {
689  << M << " entered...\n" << "file: " << file << "\n";
690  }
691 
692  bool processFileFlag = true;
694  {
695  processFileFlag = !isFiltered( file );
696  }
697 
698  if ( processFileFlag )
699  {
700  ossimNotify(ossimNotifyLevel_NOTICE) << "Processing file: " << file << std::endl;
701 
702  m_mutex.lock();
704  ossimImageHandlerRegistry::instance()->open(file, true, true);
705  m_mutex.unlock();
706 
707  if ( ih.valid() && !ih->hasError() )
708  {
709  // Check for output directory:
710  if ( m_kwl->hasKey( OUTPUT_DIRECTORY_KW ) )
711  {
712  ossimFilename outputDir;
713  outputDir.string() = m_kwl->findKey( OUTPUT_DIRECTORY_KW );
714 
715  if ( outputDir.exists() && outputDir.isDir() )
716  {
717  ih->setSupplementaryDirectory( outputDir );
718  }
719  }
720 
721  if ( isDirectoryBasedImage( ih.get() ) )
722  {
723  // Tell the walker not to recurse this directory.
724  m_mutex.lock();
726  m_mutex.unlock();
727  }
728 
729  // Set any reader props:
730  ossimPropertyInterface* pi = dynamic_cast<ossimPropertyInterface*>(ih.get());
731  if ( pi ) setProps(pi);
732 
733  bool consumedHistogramOptions = false;
734  bool consumedCmmOptions = false;
735 
736  if ( getOutputFileNamesFlag() )
737  {
738  // Simply output the file name of any images we can open:
740  }
741 
742  // Compute/Scan for min, max. Note the overview sequencer may have computed for us.
743  if ( ( scanForMinMax() || scanForMinMaxNull() ) && !consumedCmmOptions )
744  {
745  computeMinMax( ih );
746  }
747 
748  if ( createOverviews() )
749  {
750  // Skip shape files...
751  if ( ih->getClassName() != "ossimOgrGdalTileSource" )
752  {
753  createOverview(ih, consumedHistogramOptions, consumedCmmOptions);
754  }
755  }
756  if (createThumbnails())
757  {
758  for (ossim_uint32 idx = 0; idx < ih->getNumberOfEntries(); ++idx)
759  {
760  ih->setCurrentEntry(idx);
761  if (ih->getNumberOfDecimationLevels() <= 1)
762  {
763  ih->setState(0);
764  ih->openOverview();
765  }
766  createThumbnail(ih);
767  }
768  }
769  // Build stand alone histogram. Note the overview sequencer may have computed for us.
770  if ( hasHistogramOption() && !consumedHistogramOptions)
771  {
772  createHistogram( ih );
773  }
774 
775  // Launch any file system commands.
776  executeFileCommands( file );
777  }
778  else
779  {
780  ossimNotify(ossimNotifyLevel_WARN) << M << "\nCould not open: " << file << std::endl;
781  }
782  }
783  else // Matches: if ( processFileFlag )
784  {
786  << "Filtered file, not processing: " << file << std::endl;
787  }
788 
789  if(traceDebug())
790  {
791  // Since ossimFileWalker is threaded output the file so we know which job exited.
792  ossimNotify(ossimNotifyLevel_DEBUG) << M << "\nfile: " << file << "\nexited...\n";
793  }
794 }
795 
796 // Create overview for image:
798  bool& consumedHistogramOptions,
799  bool& consumedCmmOptions )
800 {
801  static const char M[] = "ossimImageUtil::createOverview #1";
802  if(traceDebug())
803  {
804  ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\n";
805  }
806 
807  if ( ih.valid() )
808  {
809  // Get the entry list:
810  std::vector<ossim_uint32> entryList;
811  ih->getEntryList(entryList);
812 
813  bool useEntryIndex = false;
814  if ( entryList.size() )
815  {
816  if ( (entryList.size() > 1) || (entryList[0] != 0) ) useEntryIndex = true;
817  }
818 
819  // Create the overview builder:
820  ossimString overviewType;
821  getOverviewType( overviewType.string() );
824  if ( ob.valid() )
825  {
826  // Set up any overview builder options that don't involve histograms.
827  ossimPropertyInterface* pi = dynamic_cast<ossimPropertyInterface*>( ob.get() );
828  if ( pi ) setProps(pi);
829 
830  ossim_uint32 stopDimension = getOverviewStopDimension();
831  if ( stopDimension ) ob->setOverviewStopDimension(stopDimension);
832 
833  if ( ( scanForMinMax() || scanForMinMaxNull() ) && !hasCmmOption() )
834  {
835  //---
836  // If scan is set and we don't have any min, max, null overrides let the
837  // overview builder scan for min, max.
838  //
839  // If min, max, or null option is set, scan will be performed in
840  // separate function.
841  //---
842  ob->setScanForMinMax( scanForMinMax() );
843  ob->setScanForMinMaxNull( scanForMinMaxNull() );
844  consumedCmmOptions = true;
845  }
846 
847  for(ossim_uint32 idx = 0; idx < entryList.size(); ++idx)
848  {
849  createOverview(ih, ob, entryList[idx], useEntryIndex, consumedHistogramOptions);
850  }
851  }
852  else
853  {
855  << "ERROR:\nCould not create builder for: "<< overviewType << std::endl;
857  }
858  }
859 
860  if(traceDebug())
861  {
862  ossimNotify(ossimNotifyLevel_DEBUG) << M << " exited...\n";
863  }
864 }
865 
866 // Create overview for entry:
869  ossim_uint32 entry,
870  bool useEntryIndex,
871  bool& consumedHistogramOptions)
872 {
873  static const char M[] = "ossimImageUtil::createOverview #2";
874  if(traceDebug())
875  {
876  ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\n";
877  }
878 
879  if ( ih.valid() && ob.valid() )
880  {
881  if (useEntryIndex)
882  {
883  // Set entry before deriving file name.
884  ih->setCurrentEntry(entry);
885  ossimNotify(ossimNotifyLevel_NOTICE) << "entry number: "<< entry << std::endl;
886  }
887 
888  ossimFilename outputFile =
889  ih->getFilenameWithThisExtension(ossimString(".ovr"), useEntryIndex);
890 
891  if ( rebuildOverviews() )
892  {
893  ih->closeOverview();
894  if ( outputFile.exists() )
895  {
896  outputFile.remove();
897  }
898  }
899 
900  if ( getInternalOverviewsFlag() )
901  {
902  if ( ih->getClassName() == "ossimTiffTileSource")
903  {
904  //---
905  // INTERNAL_OVERVIEWS_FLAG_KW is set to true:
906  // Tiff reader can handle internal overviews. Set the output file to
907  // input file. Do it after the above remove so that if there were
908  // external overviews they will get removed.
909  //---
910  outputFile = ih->getFilename();
911  }
912  else
913  {
915  << "Internal overviews not supported for reader type: "
916  <<ih->getClassName()
917  << "\nIgnoring option..."
918  << endl;
919  }
920  }
921 
922  if ( hasRequiredOverview( ih, ob ) == false )
923  {
924  //---
925  // Set create histogram code...
926  //
927  // Notes:
928  // 1) Must put this logic after any removal of external overview file.
929  //
930  // 2) Base file could have built in overviews, e.g. jp2 files. So the sequensor could
931  // start at R6 even if there is no external overview file.
932  //
933  // 3) If user want the histogram from R0 the overview builder can do as long as
934  // ossimImageHandler::getNumberOfDecimationLevels returns 1. If we are starting
935  // overview building at R6 then we must do the create histogram in a separate path.
936  //---
938  if ( createHistogram() ||
939  ( createHistogramR0() && ( ih->getNumberOfDecimationLevels() == 1 ) ) )
940  {
941  histoMode = OSSIM_HISTO_MODE_NORMAL;
942  }
943  else if ( createHistogramFast() )
944  {
945  histoMode = OSSIM_HISTO_MODE_FAST;
946  }
947 
948  if(traceDebug())
949  {
950  ossimNotify(ossimNotifyLevel_DEBUG) << "Histogram mode: " << histoMode << "\n";
951  }
952 
953  if ( histoMode != OSSIM_HISTO_MODE_UNKNOWN )
954  {
955  consumedHistogramOptions = true;
956  ob->setHistogramMode(histoMode);
957 
959  << "Creating overviews with histogram for file: " << ih->getFilename() << std::endl;
960  }
961  else
962  {
963  if ( histoMode != OSSIM_HISTO_MODE_UNKNOWN )
964  {
965  consumedHistogramOptions = false;
967  << "Creating overviews for file: " << ih->getFilename() << std::endl;
968  }
969  }
970 
971  //---
972  // Set properties, e.g. tile size. Must be set before the call to
973  // ob->setInputSource(...)
974  //---
975  std::vector< ossimRefPtr<ossimProperty> > propertyList(0);
976  ossimIpt tileSize;
977  if ( getTileSize( tileSize ) == true )
978  {
980  tileSize.toString()));
981  ob->setProperties(propertyList);
982  }
983 
984  ob->setOutputFile(outputFile);
985  ob->setInputSource(ih.get());
986 
987  // Create the overview for this entry in this file:
988  if ( ob->execute() == false )
989  {
992  << "Error returned creating overviews for file: " << ih->getFilename() << std::endl;
993  }
994  }
995  else
996  {
997  consumedHistogramOptions = false;
999  << "Image has required reduced resolution data sets." << std::endl;
1000  }
1001  }
1002 
1003  if(traceDebug())
1004  {
1005  ossimNotify(ossimNotifyLevel_DEBUG) << M << " exited...\n";
1006  }
1007 }
1009 {
1010  ossimKeywordlist bandsKeywordList;
1011  bandsKeywordList.add("type", "ossimBandSelector");
1012  bandsKeywordList.add(ossimKeywordNames::BANDS_KW, "default");
1014  if (!bs)
1015  return;
1016  ossimIrect cutRect;
1021  ossimDrect bounds = ih->getBoundingRect();
1022  ossim_float64 maxSize = ossim::max(bounds.width(), bounds.height());
1023  ossim_float64 thumbnailSize = getThumbnailSize();
1024  ossim_float64 scale = thumbnailSize / maxSize;
1025  ossimFilename thumbnailFilename = getThumbnailFilename(ih.get());
1027  if (scale > 1.0)
1028  {
1029  scale = 1.0;
1030  cutRect = bounds;
1031  }
1032  else
1033  {
1034  cutRect = bounds * scale;
1035  }
1036  cutFilter->setRectangle(cutRect);
1037  if ((scale < .5) && (ih->getNumberOfDecimationLevels() < 2))
1038  {
1039  return;
1040  }
1041 
1042  trans->scale(scale, scale);
1043  renderer->setImageViewTransform(trans.get());
1044  if (!bs.valid())
1045  return;
1046  bs->connectMyInputTo(ih.get());
1047  bs->initialize();
1048  ossim_uint32 bandCount = bs->getNumberOfInputBands();
1049  if ((bandCount == 2) || (bandCount > 3))
1050  {
1051  ossimBandSelector *tempBs = dynamic_cast<ossimBandSelector *>(bs.get());
1052  if (tempBs)
1053  {
1054  tempBs->setThreeBandRgb();
1055  }
1056  }
1057 
1059  stretch->setStretchMode(thumbnailStretchType);
1060  ossimFilename histogramFilename = ih->createDefaultHistogramFilename();
1061 
1062  //if (!histogramFilename.empty())
1063  //{
1064  // histogramFile = m_histogramFilename;
1065  // }
1066  stretch->connectMyInputTo(bs.get());
1067  stretch->openHistogram(histogramFilename);
1068  renderer->connectMyInputTo(stretch.get());
1069 
1070  scalarRemapper->connectMyInputTo(renderer.get());
1071  cutFilter->connectMyInputTo(scalarRemapper.get());
1072  ossimKeywordlist writerKwl;
1073  ossimString ext = thumbnailFilename.ext();
1074  ext = ext.downcase();
1075  writerKwl.add("type", "image/" + ext);
1076  writerKwl.add("filename", thumbnailFilename.c_str());
1077  writerKwl.add("create_external_geometry", "false");
1078  if (ext == "png")
1079  {
1080  writerKwl.add("add_alpha_channel", "true");
1081  }
1083 
1084  if (writer)
1085  {
1086  writer->connectMyInputTo(cutFilter.get());
1087 
1088  writer->execute();
1089 
1090  writer->disconnect();
1091  writer = 0;
1092  }
1093  scalarRemapper->disconnect();
1094  scalarRemapper = 0;
1095  cutFilter->disconnect();
1096  cutFilter = 0;
1097  renderer->disconnect();
1098  renderer = 0;
1099  stretch->disconnect();
1100  stretch = 0;
1101  bs->disconnect();
1102  bs = 0;
1103 }
1104 
1107 {
1108  bool result = false;
1109  if ( ih.valid() && ob.valid() && ( getCopyAllFlag() == false ) )
1110  {
1111  if ( ih->getClassName() == "ossimCcfTileSource" )
1112  {
1113  // CCF reader does not use external overviews.
1114  result = true;
1115  }
1116  else
1117  {
1118  // Note we always have one rset
1119  ossim_uint32 required = 1;
1120 
1121  ossim_uint32 startingResLevel = ih->getNumberOfDecimationLevels();
1122  ossim_uint32 overviewStopDimension = ob->getOverviewStopDimension();
1123 
1124  ossim_uint32 largestImageDimension =
1125  ih->getNumberOfSamples(0) >
1126  ih->getNumberOfLines(0) ?
1127  ih->getNumberOfSamples(0) :
1128  ih->getNumberOfLines(0);
1129 
1130  while(largestImageDimension > overviewStopDimension)
1131  {
1132  largestImageDimension /= 2;
1133  ++required;
1134  }
1135 
1136  if ( startingResLevel >= required )
1137  {
1138  result = true;
1139  }
1140  }
1141  }
1142  return result;
1143 }
1144 
1146 {
1147  static const char M[] = "ossimImageUtil::createHistogram #1";
1148  if(traceDebug())
1149  {
1150  ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\n";
1151  }
1152 
1153  if ( ih.valid() )
1154  {
1155  // Get the entry list:
1156  std::vector<ossim_uint32> entryList;
1157  ih->getEntryList(entryList);
1158 
1159  bool useEntryIndex = false;
1160  if ( entryList.size() )
1161  {
1162  if ( (entryList.size() > 1) || (entryList[0] != 0) ) useEntryIndex = true;
1163  }
1164 
1165  for(ossim_uint32 idx = 0; idx < entryList.size(); ++idx)
1166  {
1167  createHistogram(ih, entryList[idx], useEntryIndex);
1168  }
1169  }
1170 
1171  if(traceDebug())
1172  {
1173  ossimNotify(ossimNotifyLevel_DEBUG) << M << " exited...\n";
1174  }
1175 }
1176 
1177 // Create histogram for entry:
1179  ossim_uint32 entry,
1180  bool useEntryIndex)
1181 {
1182  static const char M[] = "ossimImageUtil::createHistogram #2";
1183  if(traceDebug())
1184  {
1185  ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\n";
1186  }
1187 
1188  if ( ih.valid() )
1189  {
1190  if (useEntryIndex)
1191  {
1192  // Set entry before deriving file name.
1193  ih->setCurrentEntry(entry);
1194  ossimNotify(ossimNotifyLevel_NOTICE) << "entry number: "<< entry << std::endl;
1195  }
1196 
1197  ossimFilename outputFile =
1198  ih->getFilenameWithThisExtension(ossimString(".his"), useEntryIndex);
1199 
1200  // Only build if needed:
1201  if ( (outputFile.exists() == false) || rebuildHistogram() )
1202  {
1204  << "Computing histogram for file: " << ih->getFilename() << std::endl;
1205 
1206  // Check handler to see if it's filtering bands.
1207  std::vector<ossim_uint32> originalBandList(0);
1208  if ( ih->isBandSelector() )
1209  {
1210  // Capture for finalize method.
1211  ih->getOutputBandList( originalBandList );
1212 
1213  // Set output list to input.
1215  }
1216 
1219 
1220  histoSource->setMaxNumberOfRLevels(1); // Currently hard coded...
1221 
1222 #if 0 /* TODO tmp drb */
1223  if( !ossim::isnan(histoMin) )
1224  {
1225  histoSource->setMinValueOverride(histoMin);
1226  }
1227 
1228  if( !ossim::isnan(histoMax) )
1229  {
1230  histoSource->setMaxValueOverride(histoMax);
1231  }
1232 
1233  if(histoBins > 0)
1234  {
1235  histoSource->setNumberOfBinsOverride(histoBins);
1236  }
1237 #endif
1238 
1239  if(traceDebug())
1240  {
1242  << "Histogram mode: " << getHistogramMode() << "\n";
1243  }
1244 
1245  // Connect histogram source to image handler.
1246  histoSource->setComputationMode( getHistogramMode() );
1247  histoSource->connectMyInputTo(0, ih.get() );
1248  histoSource->enableSource();
1249 
1250  // Connect writer to histogram source.
1251  writer->connectMyInputTo(0, histoSource.get());
1252  writer->setFilename(outputFile);
1254  writer->addListener(&theStdOutProgress);
1255 
1256  // Compute...
1257  writer->execute();
1258 
1259  writer=0;
1260 
1261  // Reset the band list.
1262  if ( ih->isBandSelector() && originalBandList.size() )
1263  {
1264  ih->setOutputBandList( originalBandList );
1265  }
1266 
1267  } // Matches: if ( (outputFile.exists() == false) || rebuildHistogram() )
1268 
1269  } // Matches: if ( ih.valid() )
1270 
1271  if(traceDebug())
1272  {
1273  ossimNotify(ossimNotifyLevel_DEBUG) << M << " exited...\n";
1274  }
1275 
1276 } // End: ossimImageUtil::createHistogram #2
1277 
1279 {
1280  static const char M[] = "ossimImageUtil::computeMinMax #1";
1281  if(traceDebug())
1282  {
1283  ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\n";
1284  }
1285 
1286  if ( ih.valid() )
1287  {
1288  // Get the entry list:
1289  std::vector<ossim_uint32> entryList;
1290  ih->getEntryList(entryList);
1291 
1292  bool useEntryIndex = false;
1293  if ( entryList.size() )
1294  {
1295  if ( (entryList.size() > 1) || (entryList[0] != 0) ) useEntryIndex = true;
1296  }
1297 
1298  for(ossim_uint32 idx = 0; idx < entryList.size(); ++idx)
1299  {
1300  computeMinMax(ih, entryList[idx], useEntryIndex);
1301  }
1302  }
1303 
1304  if(traceDebug())
1305  {
1306  ossimNotify(ossimNotifyLevel_DEBUG) << M << " exited...\n";
1307  }
1308 
1309 } // End: ossimImageUtil::computeMinMax( ih )
1310 
1312  ossim_uint32 entry,
1313  bool useEntryIndex )
1314 {
1315  static const char M[] = "ossimImageUtil::computeMinMax #2";
1316  if(traceDebug())
1317  {
1318  ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\n";
1319  }
1320 
1321  if ( ih.valid() )
1322  {
1323  // Get any min, max, null overrides;
1324  double maxValue = ossim::nan();
1325  double minValue = ossim::nan();
1326  double nullValue = ossim::nan();
1327 
1328  ossimString value = m_kwl->findKey( CMM_MAX_KW );
1329  if ( value.size() )
1330  {
1331  maxValue = value.toDouble();
1332  }
1333 
1334  value = m_kwl->findKey( CMM_MIN_KW );
1335  if ( value.size() )
1336  {
1337  minValue = value.toDouble();
1338  }
1339 
1340  bool hasNull = false;
1341  value = m_kwl->findKey( CMM_NULL_KW );
1342  if ( value.size() )
1343  {
1344  nullValue = value.toDouble();
1345  if ( !ossim::isnan(nullValue) )
1346  {
1347  hasNull = true;
1348  }
1349  }
1350 
1351  // Select the entry.
1352  ih->setCurrentEntry( entry );
1353 
1354  // Build the .omd file name.
1355  ossimFilename omd_file = ih->getFilename();;
1356 
1357  // Check for output directory:
1358  if ( m_kwl->hasKey( OUTPUT_DIRECTORY_KW ) )
1359  {
1360  ossimFilename outputDir;
1361  outputDir.string() = m_kwl->findKey( OUTPUT_DIRECTORY_KW );
1362 
1363  if ( outputDir.exists() && outputDir.isDir() )
1364  {
1365  omd_file = outputDir.dirCat( omd_file.file() );
1366  }
1367  }
1368 
1369  if ( useEntryIndex )
1370  {
1371  ossim_uint32 currentEntry = ih->getCurrentEntry();
1372  omd_file.setExtension("");
1373  omd_file += "_e";
1374  omd_file += ossimString::toString(currentEntry);
1375 
1376  //---
1377  // Note: Set extension was not used here deliberately to avoid
1378  // messing
1379  // up a MODIS file in hdf format with multiple '.'s in the file
1380  // name.
1381  //---
1382  omd_file += ".omd";
1383  }
1384  else
1385  {
1386  omd_file.setExtension("omd");
1387  }
1388 
1390 
1391  //---
1392  // Note: getImageTileWidth/Height will return zero if the image is not
1393  // intenally tiles.
1394  //---
1395  ossimIpt tileWidthHeight( ih->getImageTileWidth(), ih->getImageTileHeight() );
1396  if (!tileWidthHeight.x)
1397  {
1398  //---
1399  // Make the sequencer read entire strips from the image handler
1400  // at a time. This will speed up access time for strip images
1401  //---
1402  tileWidthHeight.x = ih->getBoundingRect().width();
1403  }
1404  if(!tileWidthHeight.y)
1405  {
1406  tileWidthHeight.y = ih->getTileHeight();
1407  }
1408 
1409  if ( traceDebug() )
1410  {
1412  << "Sequencer tile size: " << tileWidthHeight << endl;
1413  }
1414 
1415  is->setTileSize(tileWidthHeight);
1416 
1417  //---
1418  // Make arrays of doubles to hold the min/max values.
1419  // Initialize mins to default maxes and maxes to default mins to be
1420  // safe.
1421  //---
1422  ossim_uint32 i; // for numerous iterations...
1423 
1424  const ossimScalarType ST = ih->getOutputScalarType();
1425 
1426  const double DEFAULT_MIN = ossim::defaultMin(ST);
1427  const double DEFAULT_MAX = ossim::defaultMax(ST);
1428 
1429  const ossim_uint32 BANDS = ih->getNumberOfInputBands();
1430 
1431  vector<double> tmin(BANDS);
1432  vector<double> tmax(BANDS);
1433  vector<double> tnull(BANDS);
1434  for (i = 0; i < BANDS; ++i)
1435  {
1436  tmin[i] = DEFAULT_MAX;
1437  tmax[i] = DEFAULT_MIN;
1438 
1439  if ( hasNull )
1440  {
1441  // User passed in with --null option so set here.
1442  tnull[i] = nullValue;
1443  }
1444  else
1445  {
1446  tnull[i] = ih->getNullPixelValue(i);
1447  }
1448  }
1449 
1450  // Scan the image and compute the min and max.
1451  const double TOTAL_TILES = is->getNumberOfTiles();
1452  double tile_count = 0.0;
1454  << setiosflags(ios::fixed) << setprecision(0);
1455 
1456  if( (ossim::isnan(minValue) ) || (ossim::isnan(maxValue) ) )
1457  {
1459  while(id.valid())
1460  {
1461  if ( hasNull )
1462  {
1463  // Pass null to image data object so it doesn't get picked up as "min".
1464  id->setNullPix( nullValue );
1465  }
1466  id->computeMinMaxPix(tmin, tmax);
1467  id = is->getNextTile();
1468  ++tile_count;
1470  << "\r" << setw(3)
1471  << (tile_count / TOTAL_TILES * 100.0) << "%"
1472  << flush;
1473  }
1474  }
1475 
1476  if(!ossim::isnan(minValue))
1477  {
1478  std::fill(tmin.begin(), tmin.end(), minValue);
1479  }
1480  if(!ossim::isnan(maxValue))
1481  {
1482  std::fill(tmax.begin(), tmax.end(), maxValue);
1483  }
1485  << "\r100%\nFinished..." << endl;
1486 
1487  ossimKeywordlist okwl(omd_file);
1488 
1489  for(i = 0; i < BANDS; ++i)
1490  {
1491  //---
1492  // Check to see if values got assigned. If not flip to default and
1493  // issue a warning.
1494  //---
1495  if (tmin[i] == DEFAULT_MAX)
1496  {
1497  tmin[i] = DEFAULT_MIN;
1499  << "cmm scan for min failed! Using default min."
1500  << std::endl;
1501  }
1502  if (tmax[i] == DEFAULT_MIN)
1503  {
1504  tmax[i] = DEFAULT_MAX;
1506  << "cmm scan for max failed! Using default max."
1507  << std::endl;
1508  }
1509 
1510  ossimString band =
1511  ossimString("band")+ossimString::toString(i+1)+".";
1512 
1513  if (tmin[i] == DEFAULT_MAX)
1514  {
1515  tmin[i] = DEFAULT_MIN;
1516  }
1517  // if (tmax[i] == DEFAULT_MIN){}
1518 
1519  okwl.add(band + "min_value", tmin[i], true);
1520  okwl.add(band + "max_value", tmax[i], true);
1521  okwl.add(band + "null_value", tnull[i], true);
1522 
1523  if( traceDebug() )
1524  {
1526  << setiosflags(ios::fixed) << setprecision(16)
1527  << "band" << ossimString::toString(i+1) << ".min_value: "
1528  << tmin[i]
1529  << "\nband" << ossimString::toString(i+1) << ".max_value: "
1530  << tmax[i]
1531  << "\nband" << ossimString::toString(i+1) << ".null_value: "
1532  << tnull[i] << endl;
1533  }
1534 
1535  } // End of band loop.
1536 
1537  // Add missing info (number of bands, scalar type) to the .omd file
1538  okwl.add("bytes_per_pixel", ossim::scalarSizeInBytes(ST), true);
1539  okwl.add("number_bands", BANDS, true);
1540  okwl.add("scalar_type", (ossimScalarTypeLut::instance()->getEntryString(ST)), true);
1541 
1542  // Write the file to disk:
1543  okwl.write(omd_file);
1545  << "wrote file: " << omd_file << endl;
1546 
1547  ih->loadMetaData();
1548 
1549  } // Matches: if ( ih.valid() )
1550 
1551  if(traceDebug())
1552  {
1553  ossimNotify(ossimNotifyLevel_DEBUG) << M << " exited...\n";
1554  }
1555 
1556 } // End: ossimImageUtil::computeMinMax( ih, entry, ... )
1557 
1559 {
1560  // Add global usage options.
1562 
1563  // Set app name.
1565 
1566  // Add options.
1567  addArguments(ap);
1568 
1569  // Write usage.
1571 
1573 
1575  << "\nExample commands:\n"
1576 
1577  << "\n// A single image standard tiff overviews, histogram:\n"
1578  << "ossim-preproc -o --ch <file>\n"
1579 
1580  << "\n// A single image with j2k overviews(requires kakadu plugin), histogram:\n"
1581  << "ossim-preproc --ot ossim_kakadu_nitf_j2k --ch <file>\n"
1582  << "\n// j2k, histogram, 4 threads\n"
1583 
1584  << "\n// standard tiff overviews, full histogram, 4 threads:\n"
1585  << "ossim-preproc -r -o --ch --threads 4 <directory_to_walk>\n"
1586 
1587  << "\n// j2k, histogram (fast mode), 4 threads\n"
1588  << "ossim-preproc -r --ot ossim_kakadu_nitf_j2k --chf --threads 4 "
1589  << "<directory_to_walk>\n"
1590 
1591  << "\n// tiff, jpeg compression, histogram, 4 threads\n"
1592  << "ossim-preproc -r --ch --compression-quality 75 --compression-type "
1593  << "jpeg --threads 4 <directory_to_walk>\n"
1594  << "ossim-preproc -r --ch --compression-quality 75 --compression-type "
1595  << "jpeg --threads 4 <directory_to_walk>\n"
1596 
1597  << "\n// Process all the tiffs in a directory feeding \"prep\", \"file\", \"post\" system commands via the --options option which includes indexing file into the omar database via omar-data-mgr app:\n"
1598  << "ossim-preproc --options preproc-options.kwl -r -o --ch *.tif\n"
1599  << "\n// Contents of preproc-options.kwl used in above command:\n"
1600  << "prep.command0: echo start_time: %{date}\n"
1601  << "prep.command0.strf_time_format: %Y%m%d%H%M%S\n"
1602  << "prep.command1: mkdir -p %{date}\n"
1603  << "file.command0: mv %{file_no_ext}.* %{date}/.\n"
1604  << "file.command1: omar-data-mgr -u http://localhost:8080/omar add %{date}/%{basename}\n"
1605  << "post.command0: echo end_time: %{date}\n"
1606  << "post.command0.strf_time_format: %Y%m%d%H%M%S\n"
1607 
1608  << "\nNOTES:\n"
1609  << "\n --ch equals --create-histogram"
1610  << "\n --chf equals --create-histogram-fast"
1611 
1612  << "\n\nExpanded command option variables:\n\n"
1613  << "%{basename} = filename without path\n"
1614  << "%{basename_no_ext} = filename without path and without extension\n"
1615  << "%{date} = Expanded to current zulu time. Default format=yyyymmdd\n"
1616  << " output format controlled by command0.strf_time_format key.\n"
1617  << "%{dirname} = path of filename\n"
1618  << "%{file} = filename being processed\n"
1619  << "%{file_no_ext} = filename with no extension\n"
1620 
1621  << std::endl;
1622 }
1623 
1624 // Private method:
1626 {
1628  << "\nValid overview types: " << std::endl;
1629 
1630  std::vector<ossimString> outputType;
1631 
1633  std::copy(outputType.begin(),
1634  outputType.end(),
1635  std::ostream_iterator<ossimString>(ossimNotify(ossimNotifyLevel_NOTICE), "\t\n"));
1636 }
1637 
1638 // Private method:
1640 {
1641  bool result = false;
1642  if ( ih )
1643  {
1644  // Get the image handler name.
1645  ossimString imageHandlerName = ih->getClassName();
1646  if ( (imageHandlerName == "ossimAdrgTileSource") ||
1647  (imageHandlerName == "ossimCibCadrgTileSource") )
1648  {
1649  result = true;
1650  }
1651  }
1652  return result;
1653 }
1654 
1656 {
1657  addOption( CREATE_OVERVIEWS_KW, ( flag ? TRUE_KW : FALSE_KW ) );
1658 }
1659 
1661 {
1662  return keyIsTrue( CREATE_OVERVIEWS_KW );
1663 }
1665 {
1666  addOption(CREATE_THUMBNAILS_KW, (flag ? TRUE_KW : FALSE_KW));
1667 }
1668 
1670 {
1671  return keyIsTrue(CREATE_THUMBNAILS_KW);
1672 }
1673 
1675 {
1676  addOption( REBUILD_OVERVIEWS_KW, ( flag ? TRUE_KW : FALSE_KW ) );
1677  if ( flag )
1678  {
1679  setCreateOverviewsFlag( true ); // Turn on overview building.
1680  }
1681 }
1682 
1684 {
1685  return keyIsTrue( REBUILD_OVERVIEWS_KW );
1686 }
1687 
1689 {
1690  addOption( REBUILD_HISTOGRAM_KW, ( flag ? TRUE_KW : FALSE_KW ) );
1691  if ( flag )
1692  {
1693  setCreateHistogramFlag( true ); // Turn on histogram building.
1694  }
1695 }
1696 
1698 {
1699  return keyIsTrue( REBUILD_HISTOGRAM_KW );
1700 }
1701 
1703 {
1704  addOption( SCAN_MIN_MAX_KW, ( flag ? TRUE_KW : FALSE_KW ) );
1705 }
1706 
1708 {
1709  return keyIsTrue( SCAN_MIN_MAX_KW );
1710 }
1711 
1713 {
1714  addOption( SCAN_MIN_MAX_NULL_KW, ( flag ? TRUE_KW : FALSE_KW ) );
1715 }
1716 
1718 {
1719  return keyIsTrue( SCAN_MIN_MAX_NULL_KW );
1720 }
1721 
1722 void ossimImageUtil::setCompressionQuality( const std::string& quality )
1723 {
1724  if ( quality.size() )
1725  {
1726  std::string key = WRITER_PROP_KW;
1728  std::string value = ossimKeywordNames::COMPRESSION_QUALITY_KW;
1729  value += "=";
1730  value += quality;
1731  addOption( key, value );
1732  }
1733 }
1734 
1735 void ossimImageUtil::setCompressionType(const std::string& type)
1736 {
1737  if ( type.size() )
1738  {
1739  std::string key = WRITER_PROP_KW;
1741  std::string value = ossimKeywordNames::COMPRESSION_TYPE_KW;
1742  value += "=";
1743  value += type;
1744  addOption( key, value );
1745  }
1746 }
1747 
1749 {
1750  // Add this for hasRequiredOverview method.
1751  std::string key = COPY_ALL_FLAG_KW;
1752  std::string value = ( flag ? TRUE_KW : FALSE_KW );
1753  addOption( key, value );
1754 
1755  // Add as a writer prop:
1756  key = WRITER_PROP_KW;
1758  value = COPY_ALL_FLAG_KW;
1759  value += "=";
1760  value += ( flag ? TRUE_KW : FALSE_KW );
1761  addOption( key, value );
1762 }
1763 
1765 {
1766  return keyIsTrue( COPY_ALL_FLAG_KW );
1767 }
1768 
1770 {
1771  std::string key = DUMP_FILTERED_IMAGES_KW;
1772  std::string value = ( flag ? TRUE_KW : FALSE_KW );
1773  addOption( key, value );
1774 }
1775 
1777 {
1778  return keyIsTrue( DUMP_FILTERED_IMAGES_KW );
1779 }
1780 
1782 {
1783  // Add this for hasRequiredOverview method.
1784  std::string key = INTERNAL_OVERVIEWS_FLAG_KW;
1785  std::string value = ( flag ? TRUE_KW : FALSE_KW );
1786  addOption( key, value );
1787 
1788  // Add as a writer prop:
1789  key = WRITER_PROP_KW;
1791  value = INTERNAL_OVERVIEWS_FLAG_KW;
1792  value += "=";
1793  value += ( flag ? TRUE_KW : FALSE_KW );
1794  addOption( key, value );
1795 }
1796 
1798 {
1799  return keyIsTrue( INTERNAL_OVERVIEWS_FLAG_KW );
1800 }
1801 
1803 {
1804  std::string key = OUTPUT_FILENAMES_KW;
1805  std::string value = ( flag ? TRUE_KW : FALSE_KW );
1806  addOption( key, value );
1807 }
1808 
1810 {
1811  return keyIsTrue( OUTPUT_FILENAMES_KW );
1812 }
1813 
1815 {
1816  std::string key = OVERRIDE_FILTERED_IMAGES_KW;
1817  std::string value = ( flag ? TRUE_KW : FALSE_KW );
1818  addOption( key, value );
1819 }
1820 
1822 {
1823  return keyIsTrue( OVERRIDE_FILTERED_IMAGES_KW );
1824 }
1825 
1826 void ossimImageUtil::setOutputDirectory( const std::string& directory )
1827 {
1828  std::string key = OUTPUT_DIRECTORY_KW;
1829  addOption( key, directory );
1830 }
1831 
1832 void ossimImageUtil::setOverviewType( const std::string& type )
1833 {
1834  std::string key = OVERVIEW_TYPE_KW;
1835  addOption( key, type );
1836  setCreateOverviewsFlag( true ); // Assume caller wants overviews.
1837 }
1838 
1839 void ossimImageUtil::getOverviewType(std::string& type) const
1840 {
1841  std::string lookup = m_kwl->findKey(OVERVIEW_TYPE_KW);
1842  if ( lookup.size() )
1843  {
1844  type = lookup;
1845  }
1846  else
1847  {
1848  type = "ossim_tiff_box"; // default
1849  }
1850 }
1851 
1853 {
1854  if ( pi )
1855  {
1856  ossimString baseKey;
1857  if ( dynamic_cast<ossimImageHandler*>(pi) )
1858  {
1859  baseKey = READER_PROP_KW;
1860  }
1861  else
1862  {
1863  baseKey = WRITER_PROP_KW;
1864  }
1865 
1866  ossim_uint32 propCount = m_kwl->numberOf( baseKey.c_str() );
1867  if ( propCount )
1868  {
1869  ossim_uint32 foundProps = 0;
1870  ossim_uint32 index = 0;
1871 
1872  // (propCount+100) is to allow for holes like reader_prop0, reader_prop2...
1873  while ( (foundProps < propCount) && (index < (propCount+100) ) )
1874  {
1875  ossimString key = baseKey;
1876  key += ossimString::toString(index);
1877  std::string lookup = m_kwl->findKey( key.string() );
1878  if ( lookup.size() )
1879  {
1880  ossimString value = lookup;
1881  std::vector<ossimString> v = value.split("=");
1882  if (v.size() == 2)
1883  {
1884  ossimString propertyName = v[0];
1885  ossimString propertyValue = v[1];
1887  new ossimStringProperty(propertyName, propertyValue);
1888  pi->setProperty( p );
1889  }
1890  ++foundProps;
1891  }
1892  ++index;
1893  }
1894  }
1895  }
1896 }
1897 
1899 {
1900  addOption( OVERVIEW_STOP_DIM_KW, dimension );
1901 }
1902 
1903 void ossimImageUtil::setOverviewStopDimension( const std::string& dimension )
1904 {
1905  addOption( OVERVIEW_STOP_DIM_KW, dimension );
1906 }
1907 
1909 {
1910  if ((tileSize % 16) == 0)
1911  {
1912  addOption( TILE_SIZE_KW, tileSize );
1913  }
1914  else
1915  {
1917  << "ossimImageUtil::setTileSize NOTICE:"
1918  << "\nTile width must be a multiple of 16!"
1919  << std::endl;
1920  }
1921 }
1922 
1923 bool ossimImageUtil::getTileSize( ossimIpt& tileSize ) const
1924 {
1925  bool result = false;
1926  std::string lookup = m_kwl->findKey( TILE_SIZE_KW );
1927  if ( lookup.size() )
1928  {
1929  ossim_int32 i = ossimString(lookup).toInt32();
1930  if ( (i % 16) == 0 )
1931  {
1932  tileSize.x = i;
1933  tileSize.y = i;
1934  result = true;
1935  }
1936  }
1937  return result;
1938 }
1939 
1941 {
1942  ossim_uint32 result = 0;
1943  std::string lookup = m_kwl->findKey( OVERVIEW_STOP_DIM_KW );
1944  if ( lookup.size() )
1945  {
1946  result = ossimString(lookup).toUInt32();
1947  }
1948  return result;
1949 }
1950 
1952 {
1953  addOption( CREATE_HISTOGRAM_KW, ( flag ? TRUE_KW : FALSE_KW ) );
1954 }
1955 
1957 {
1958  return keyIsTrue( CREATE_HISTOGRAM_KW );
1959 }
1960 
1962 {
1963  addOption( CREATE_HISTOGRAM_FAST_KW, ( flag ? TRUE_KW : FALSE_KW ) );
1964 }
1965 
1967 {
1968  return keyIsTrue( CREATE_HISTOGRAM_FAST_KW );
1969 }
1970 
1972 {
1973  addOption( CREATE_HISTOGRAM_R0_KW, ( flag ? TRUE_KW : FALSE_KW ) );
1974 }
1975 
1977 {
1978  return keyIsTrue( CREATE_HISTOGRAM_R0_KW );
1979 }
1980 
1982 {
1983  return ( createHistogram() || createHistogramFast() || createHistogramR0() );
1984 }
1985 
1987 {
1988  return ( keyIsTrue( CMM_MAX_KW ) || keyIsTrue( CMM_MIN_KW )|| keyIsTrue( CMM_NULL_KW ) );
1989 }
1990 
1992 {
1994  if ( createHistogram() || createHistogramR0() )
1995  {
1996  result = OSSIM_HISTO_MODE_NORMAL;
1997  }
1998  else if ( createHistogramFast() )
1999  {
2000  result = OSSIM_HISTO_MODE_FAST;
2001  }
2002  return result;
2003 }
2004 
2006 {
2007  addOption( THREADS_KW, threads );
2008 }
2009 
2010 void ossimImageUtil::setNumberOfThreads( const std::string& threads )
2011 {
2012  addOption( THREADS_KW, threads );
2013 }
2014 
2016 {
2017  ossim_uint32 result;
2018  std::string lookup = m_kwl->findKey( THREADS_KW );
2019  if ( lookup.size() )
2020  {
2021  result = ossimString(lookup).toUInt32();
2022  }
2023  else
2024  {
2025  result = ossim::getNumberOfThreads();
2026  }
2027  return result;
2028 }
2029 
2031 {
2032  ossim_uint32 result = m_kwl->numberOf( WRITER_PROP_KW.c_str() );
2033  if ( result )
2034  {
2035  ossim_uint32 foundProps = 0;
2036  ossim_uint32 index = 0;
2037 
2038  //---
2039  // Loop until we find the last index used for WRITER_PROP_KW.
2040  // (result+100) is to allow for holes like writer_prop0, writer_prop2...
2041  //---
2042  while ( (foundProps < result) && (index < (result+100) ) )
2043  {
2044  ossimString key = WRITER_PROP_KW;
2045  key += ossimString::toString(index);
2046  std::string lookup = m_kwl->findKey( key.string() );
2047  if ( lookup.size() )
2048  {
2049  ++foundProps;
2050  }
2051  ++index;
2052  }
2053  result = index;
2054  }
2055  return result;
2056 }
2057 
2059 {
2060  ossim_uint32 result = m_kwl->numberOf( READER_PROP_KW.c_str() );
2061  if ( result )
2062  {
2063  ossim_uint32 foundProps = 0;
2064  ossim_uint32 index = 0;
2065 
2066  //---
2067  // Loop until we find the last index used for WRITER_PROP_KW.
2068  // (result+100) is to allow for holes like reader_prop0, reader_prop2...
2069  //---
2070  while ( (foundProps < result) && (index < (result+100) ) )
2071  {
2072  ossimString key = READER_PROP_KW;
2073  key += ossimString::toString(index);
2074  std::string lookup = m_kwl->findKey( key.string() );
2075  if ( lookup.size() )
2076  {
2077  ++foundProps;
2078  }
2079  ++index;
2080  }
2081  result = index;
2082  }
2083  return result;
2084 }
2086 {
2087  ossim_uint32 result;
2088  std::string lookup = m_kwl->findKey(THUMBNAIL_SIZE_KW);
2089  if (lookup.size())
2090  {
2091  result = ossimString(lookup).toUInt32();
2092  }
2093  else
2094  {
2095  result = 256;
2096  }
2097  return result;
2098 }
2099 void ossimImageUtil::setThumbnailStretchType(const std::string &value)
2100 {
2101  addOption(THUMBNAIL_STRETCH_TYPE_KW, value);
2102 }
2103 
2105 {
2107 
2108  ossimString typeString = m_kwl->findKey(THUMBNAIL_STRETCH_TYPE_KW);
2109 
2110  if (typeString.empty())
2111  {
2112  typeString = "auto-minmax";
2113  }
2114 
2115  typeString = typeString.downcase();
2116 
2117  if ((typeString == "auto-minmax"))
2118  {
2119  result = ossimHistogramRemapper::StretchMode::LINEAR_AUTO_MIN_MAX;
2120  }
2121  else if ((typeString == "auto-percentile"))
2122  {
2123  result = ossimHistogramRemapper::StretchMode::LINEAR_AUTO_PERCENTILE;
2124  }
2125  else if ((typeString == "std-stretch-1") || (typeString == "std-stretch 1"))
2126  {
2127  result = ossimHistogramRemapper::StretchMode::LINEAR_1STD_FROM_MEAN;
2128  }
2129  else if ((typeString == "std-stretch-2") || (typeString == "std-stretch 2"))
2130  {
2131  result = ossimHistogramRemapper::StretchMode::LINEAR_2STD_FROM_MEAN;
2132  }
2133  else if ((typeString == "std-stretch-3") || (typeString == "std-stretch 3"))
2134  {
2135  result = ossimHistogramRemapper::StretchMode::LINEAR_3STD_FROM_MEAN;
2136  }
2137  else if (typeString == "auto-minmax")
2138  {
2139  result = ossimHistogramRemapper::StretchMode::STRETCH_UNKNOWN;
2140  }
2141  return result;
2142 }
2143 
2144 void ossimImageUtil::setThumbnailType(const std::string& value)
2145 {
2146  addOption(THUMBNAIL_TYPE_KW, value);
2147 }
2148 
2150 {
2151  ossimString typeString = m_kwl->findKey(THUMBNAIL_TYPE_KW);
2152  std::string result = "jpeg";
2153 
2154  typeString = typeString.downcase();
2155 
2156  if(typeString != "png" && typeString != "jpeg")
2157  {
2158  typeString = "jpeg";
2159  }
2160 
2161  result = typeString.string();
2162 
2163  return result;
2164 }
2165 
2167 {
2168  ossimFilename thumbnailFilename = ih->getFilenameWithThisExtension("");
2169  std::string thumbnailType = getThumbnailType();
2170  if (thumbnailType == "png")
2171  {
2172  thumbnailFilename = ossimFilename(thumbnailFilename + "thumb.png");
2173  }
2174  else
2175  {
2176  thumbnailFilename = ossimFilename(thumbnailFilename + "thumb.jpg");
2177  }
2178 
2179  return thumbnailFilename.string();
2180 }
2181 
2182 void ossimImageUtil::addOption(const std::string &key, ossim_uint32 value)
2183 {
2184  addOption(key, ossimString::toString(value).string());
2185 }
2186 
2187 void ossimImageUtil::addOption( const std::string& key, const std::string& value )
2188 {
2189  m_mutex.lock();
2190  if ( m_kwl.valid() )
2191  {
2192  if ( key.size() && value.size() )
2193  {
2194  m_kwl->addPair( key, value );
2195  }
2196  }
2197  m_mutex.unlock();
2198 }
2199 
2201 {
2202  m_mutex.lock();
2204  m_mutex.unlock();
2205 }
2206 
2208 {
2209  bool result = false;
2210  if ( file.size() )
2211  {
2212  // Strip full path to base name.
2213  std::string baseName = file.file().string();
2214  if ( baseName.size() )
2215  {
2216  std::vector<std::string>::const_iterator i = m_filteredImages.begin();
2217  while ( i != m_filteredImages.end() )
2218  {
2219  if ( baseName == (*i) )
2220  {
2221  result = true;
2222  break;
2223  }
2224  ++i;
2225  }
2226  }
2227  }
2228 #if 0 /* Please leave for debug. (drb) */
2229  if(traceDebug())
2230  {
2232  << "ossimFileWalker::isFiltered file " << (result?"filtered: ":"not filtered: ")
2233  << file << "\n";
2234  }
2235 #endif
2236 
2237  return result;
2238 }
2239 
2240 bool ossimImageUtil::keyIsTrue( const std::string& key ) const
2241 {
2242  bool result = false;
2243  if ( m_kwl.valid() )
2244  {
2245  std::string value = m_kwl->findKey( key );
2246  if ( value.size() )
2247  {
2248  result = ossimString(value).toBool();
2249  }
2250  }
2251  return result;
2252 }
2253 
2254 const std::vector<std::string>& ossimImageUtil::getFilteredImages() const
2255 {
2256  return m_filteredImages;
2257 }
2258 
2259 std::vector<std::string>& ossimImageUtil::getFilteredImages()
2260 {
2261  return m_filteredImages;
2262 }
2263 
2265 {
2266  m_mutex.lock();
2267 
2268  // Common images to filter out, put most common first.
2269  m_filteredImages.push_back(std::string("icon.jpg"));
2270  m_filteredImages.push_back(std::string("logo.jpg"));
2271  m_filteredImages.push_back(std::string("preview.jpg"));
2272 
2273  m_mutex.unlock();
2274 }
2275 
2277 {
2278  ossimNotify(ossimNotifyLevel_NOTICE) << "Filtered image list:\n";
2279  std::vector<std::string>::const_iterator i = m_filteredImages.begin();
2280  while ( i != m_filteredImages.end() )
2281  {
2282  ossimNotify(ossimNotifyLevel_NOTICE) << (*i) << "\n";
2283  ++i;
2284  }
2285  ossimNotify(ossimNotifyLevel_NOTICE) << std::endl;
2286 }
2287 
2289 {
2290  std::string prefix = "prep.";
2291  ossimFilename file = "";
2292  executeCommands( prefix, file );
2293 }
2294 
2296 {
2297  std::string prefix = "file.";
2298  executeCommands( prefix, file );
2299 }
2300 
2302 {
2303  std::string prefix = "post.";
2304  ossimFilename file = "";
2305  executeCommands( prefix, file );
2306 }
2307 
2309  const std::string& prefix, const ossimFilename& file ) const
2310 {
2311  const std::string BASE_KEY = "command";
2312 
2313  // Get the number of test:
2314  const std::string REG_EXP_STR = prefix + BASE_KEY + std::string("[0-9]+");
2315  const ossim_uint32 NUM_COMMANDS = m_kwl->getNumberOfSubstringKeys(REG_EXP_STR);
2316  if ( NUM_COMMANDS )
2317  {
2318  const ossim_uint32 MAX_INDEX = NUM_COMMANDS + 1000; // for skipage...
2319  ossim_uint32 index = 0;
2320  ossim_uint32 processedIndexes = 0;
2321  std::string commandKey;
2322  ossimString command;
2323 
2324  while ( processedIndexes < MAX_INDEX )
2325  {
2326  commandKey = prefix + BASE_KEY + ossimString::toString( index++ ).string();
2327  command.string() = m_kwl->findKey( commandKey );
2328 
2329  if ( command.size() )
2330  {
2331  substituteCommandString( file, prefix, commandKey, command );
2332 
2334  << "executing_command: " << command << std::endl;
2335 
2336  // Launch the command:
2337  int status = system( command.c_str() );
2338 
2340  << "return_status: " << status << std::endl;
2341 
2342  ++processedIndexes;
2343 
2344  if ( processedIndexes == NUM_COMMANDS )
2345  {
2346  break;
2347  }
2348  }
2349  }
2350  }
2351 }
2352 
2354  const ossimFilename& file,
2355  const std::string& prefix,
2356  const std::string& commandKey,
2357  ossimString& command ) const
2358 {
2359  // Expand any environment vars, e.g. $(env_var_name):
2360  command.expandEnvironmentVariable();
2361 
2362  gsubDate( commandKey, command );
2363 
2364  if ( prefix == "file." )
2365  {
2366  substituteFileStrings( file, command );
2367  }
2368 }
2369 
2371  ossimString& command ) const
2372 {
2373  const std::string BASENAME_VARIABLE = "%{basename}";
2374  command.gsub( BASENAME_VARIABLE, file.file().string() );
2375 
2376  const std::string BASENAME_NO_EXT_VARIABLE = "%{basename_no_ext}";
2377  command.gsub( BASENAME_NO_EXT_VARIABLE, file.file().string() );
2378 
2379  const std::string DIRNAME_VARIABLE = "%{dirname}";
2380  command.gsub( DIRNAME_VARIABLE, file.path().string() );
2381 
2382  const std::string FILE_VARIABLE = "%{file}";
2383  command.gsub( FILE_VARIABLE, file.string(), true );
2384 
2385  const std::string FILE_NO_EXT_VARIABLE = "%{file_no_ext}";
2386  command.gsub( FILE_NO_EXT_VARIABLE, file.noExtension().string(), true );
2387 }
2388 
2389 void ossimImageUtil::gsubDate( const std::string& commandKey,
2390  ossimString& command ) const
2391 {
2392  // Date:
2393  const std::string DATE_VARIABLE = "%{date}";
2394  if ( command.find( DATE_VARIABLE ) )
2395  {
2396  std::string key = ".strf_time_format";
2397  std::string strfTimeFormat = m_kwl->findKey( commandKey, key );
2398  if ( strfTimeFormat.empty() )
2399  {
2400  // yyyymmdd
2401  strfTimeFormat = "%Y%m%d";
2402  }
2403 
2404  //---
2405  // Get the date as a string, e.g 20150411.
2406  // true for gmt time.
2407  //---
2408  std::string date;
2409  ossim::getFormattedTime( strfTimeFormat, true, date );
2410 
2411  if ( date.size() )
2412  {
2413  // Sustitute:
2414  command.gsub( DATE_VARIABLE, date, true );
2415  }
2416  }
2417 }
2418 
2419 
bool keyIsTrue(const std::string &key) const
void setRectangle(const ossimIrect &rect)
ossimString toString() const
Definition: ossimIpt.cpp:139
void dumpFilteredExtensionList() const
Dumps filtered image extenstions to std out.
void write(std::ostream &output, const UsageMap &um, unsigned int widthOfOutput=80)
virtual bool addListener(ossimListener *listener)
std::string getApplicationName() const
return the application name, as specified by argv[0]
bool createHistogramR0() const
bool createOverviews() const
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
void setCreateHistogramFastFlag(bool flag)
Sets create histogram flag keyword CREATE_HISTOGRAM_FAST_KW used by processFile method.
bool createHistogramFast() const
ossimFilename noExtension() const
static bool remove(const ossimFilename &pathname)
Removes pathname from filesystem if supported by platform.
ossim_uint32 getOverviewStopDimension() const
ossimHistogramMode
void setProperties(std::vector< ossimRefPtr< ossimProperty > > &propertyList)
ossim_uint32 numberOf(const char *str) const
T max(T a, T b)
Definition: ossimCommon.h:236
void setComputationMode(ossimHistogramMode mode)
ossim_uint32 getNumberOfSubstringKeys(const ossimString &regularExpression) const
ossim_float64 width() const
Definition: ossimDrect.h:522
void setFileProcessor(ossimFileProcessorInterface *fpi)
Sets ossimFileProcessorInterfacecallback method to process files.
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
void setRecurseFlag(bool flag)
Sets recurse flag.
virtual void disconnect(ossimConnectableObject *object=0)
Will disconnect the object passed in.
void setNumberOfBinsOverride(ossim_int32 numberOfBinsOverride)
void executePrepCommands() const
run prep system commands.
Represents serializable keyword/value map.
bool addFile(const char *file)
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
void setState(std::shared_ptr< ossim::ImageHandlerState > state)
static const char * OUTPUT_TILE_SIZE_KW
bool valid() const
Definition: ossimRefPtr.h:75
std::vector< std::string > m_filteredImages
Hold images we never want to process.
bool hasHistogramOption() const
void addOptions(ossimArgumentParser &parser)
Definition: ossimInit.cpp:100
ossimFilename expand() const
Method to do file name expansion.
std::string getThumbnailFilename(ossimImageHandler *ih) const
ossimReferenced allows for shared object ref counting if the reference count ever gets to 0 or less i...
bool read(const std::string &str)
search for an occurance of a string in the argument list, on sucess remove that occurance from the li...
virtual bool setInputSource(ossimImageHandler *imageSource)
Sets the input to the builder.
virtual ossim_uint32 getNumberOfLines(ossim_uint32 resLevel=0) const =0
Pure virtual, derived classes must implement.
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
bool getInternalOverviewsFlag() const
bool getOutputFileNamesFlag() const
void setCreateHistogramFlag(bool flag)
Sets create histogram flag keyword CREATE_HISTOGRAM_KW used by processFile method.
bool hasKey(const std::string &key) const
Checks for key in map.
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
bool scanForMinMax() const
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
static ossimImageWriterFactoryRegistry * instance()
static ossimString toString(bool aValue)
Numeric to string methods.
void setCopyAllFlag(bool flag)
Sets the overview builder copy all flag.
void getOverviewType(std::string &type) const
Initializes type from OVERVIEW_TYPE_KW or sets to default ossim_tiff_box if not found.
std::string getThumbnailType() const
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
void substituteCommandString(const ossimFilename &file, const std::string &prefix, const std::string &commandKey, ossimString &command) const
Expands variables in a command string.
void setOutputDirectory(const std::string &directory)
Sets the output directory.
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
const std::vector< std::string > & getFilteredExtensions() const
static const ossimErrorCode OSSIM_ERROR
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
bool rebuildOverviews() const
ossim_uint32 toUInt32() const
void setCommandLineUsage(const ossimString &explanation)
ossimFileWalker * m_fileWalker
void setThumbnailType(const std::string &value)
void setErrorStatus(ossim_int32 status)
Sets the m_errorStatus for return on execute.
OSSIM_DLL ossimStdOutProgress theStdOutProgress
bool hasRequiredOverview(ossimRefPtr< ossimImageHandler > &ih, ossimRefPtr< ossimOverviewBuilderBase > &ob)
virtual void closeOverview()
If theOverview is initialized it will be deleted and set to NULL.
void addArguments(ossimArgumentParser &ap)
Adds application arguments to the argument parser.
void setCreateHistogramR0Flag(bool flag)
Sets create histogram "R0" flag keyword CREATE_HISTOGRAM_R0_KW used by processFile method...
void usage(ossimArgumentParser &ap)
Initializes arg parser and outputs usage.
ossimApplicationUsage * getApplicationUsage()
Utility class to walk through directories and get a list of files to process.
bool isDir() const
virtual bool write(const char *file, const char *comment=0) const
Methods to dump the ossimKeywordlist to a file on disk.
bool getTileSize(ossimIpt &tileSize) const
Gets the tile size.
virtual void processFile(const ossimFilename &file)
ProcessFile method.
virtual bool openOverview()
Searches for an overview.
void setImageViewTransform(ossimImageViewTransform *transform)
OSSIM_DLL ossim_uint32 getNumberOfThreads()
Get the number threads to use from ossimPreferences or ossim::Thread.
void substituteFileStrings(const ossimFilename &file, ossimString &command) const
Expands file level variables in a command string.
virtual ossim_uint32 getNumberOfDecimationLevels() const
This returns the total number of decimation levels.
ossim_int32 toInt32() const
void setOverrideFilteredImagesFlag(bool flag)
Sets the override filtered images flag.
void reportRemainingOptionsAsUnrecognized(ossimErrorSeverity severity=OSSIM_BENIGN)
for each remaining option report it as an unrecongnized.
bool createHistogram() const
void setStretchMode(StretchMode mode, bool rebuildTableFlag=false)
Sets remap mode to mode.
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
bool scanForMinMaxNull() const
bool isFiltered(const ossimFilename &f) const
Convenience method to check file to see is if file should be processed.
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
virtual void setNullPix(ossim_float64 null_pix)
OSSIM_DLL double defaultMin(ossimScalarType scalarType)
Definition: ossimCommon.cpp:73
virtual void getOutputBandList(std::vector< ossim_uint32 > &bandList) const
Initializes bandList.
ossimImageUtil()
default constructor
void setCompressionType(const std::string &type)
Sets the compression type to use when building overviews.
ossimString expandEnvironmentVariable() const
If the variable "$(env_var_name)" is found in the string, where "env_var_name" is any system environm...
virtual ossim_uint32 getOverviewStopDimension() const
Get the overview stop dimension.
void executeFileCommands(const ossimFilename &file) const
run per file system commands.
bool errors(ossimErrorSeverity severity=OSSIM_BENIGN) const
bool exists() const
virtual const ossimFilename & getFilename() const
Returns the filename.
OSSIM_DLL void getFormattedTime(const std::string &format, bool gmtFlag, std::string &result)
Gets the current time.
virtual const char * what() const
Returns the error message.
void dumpFilteredImageList() const
Dumps filtered image list to std out.
std::string::size_type size() const
Definition: ossimString.h:405
void createOverview(ossimRefPtr< ossimImageHandler > &ih, bool &consumedHistogramOptions, bool &consumedCmmOptions)
void setTileSize(ossim_uint32 tileSize)
Sets the tile size.
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
Method to populate a list of supported types of all factories registered to this registry.
bool toBool() const
String to numeric methods.
static const char * COMPRESSION_TYPE_KW
virtual bool execute()=0
Builds the overviews.
virtual void setFlushStreamFlag(bool flag)
virtual ossim_uint32 getImageTileHeight() const =0
Returns the tile width of the image or 0 if the image is not tiled.
virtual bool setOutputToInputBandList()
If the image handler "isBandSeletor()" then the band selection of the output are set to input or iden...
unsigned int ossim_uint32
void setNumberOfThreads(ossim_uint32 nThreads)
Sets the max number of threads(jobs) to run at one time.
double toDouble() const
bool getDumpFilterImagesFlag() const
void setProps(ossimPropertyInterface *pi) const
set reader or writer properties based on cast of pi.
void addOption(const std::string &key, ossim_uint32 value)
Adds option to m_kwl with mutex lock.
void setApplicationName(const ossimString &name)
OSSIM_DLL ossim_uint32 scalarSizeInBytes(ossimScalarType scalarType)
int getThumbnailStretchType() const
void computeMinMax(ossimRefPtr< ossimImageHandler > &ih)
virtual ossim_uint32 getCurrentEntry() const
virtual void enableSource()
Definition: ossimSource.cpp:84
virtual void setOutputFile(const ossimFilename &file)=0
Sets the output file name.
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
ossim_int32 m_errorStatus
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_uint32 getNextWriterPropIndex() const
ossim_uint32 getThumbnailSize() const
bool rebuildHistogram() const
void setScanForMinMaxNull(bool flag)
Sets scan for min/max/null flag keyword SCAN_MIN_MAX_KW used by processFile method.
virtual ossim_uint32 getNumberOfEntries() const
ossim_uint32 width() const
Definition: ossimIrect.h:500
static const char * BANDS_KW
virtual void getEntryList(std::vector< ossim_uint32 > &entryList) const
std::mutex m_mutex
void initializeDefaultFilterList()
Initializes the filter list with a default set of filtered out file names.
ossim_float64 height() const
Definition: ossimDrect.h:517
virtual bool isBandSelector() const
Indicates whether or not the image handler can control output band selection via the setOutputBandLis...
void addOptions(ossimApplicationUsage *au)
ossimScalarType
void setOutputFileNamesFlag(bool flag)
Sets the output file name flag OUTPUT_FILENAMES_KW.
void setScanForMinMax(bool flag)
Sets scan for min/max flag keyword SCAN_MIN_MAX_KW used by processFile method.
void setMaxValueOverride(ossim_float32 maxValueOverride)
ossim_uint32 getNextReaderPropIndex() const
bool createThumbnails() const
return status
bool getOverrideFilteredImagesFlag() const
void executeCommands(const std::string &prefix, const ossimFilename &file) const
system commands.
virtual ossim_uint32 getImageTileWidth() const =0
Returns the tile width of the image or 0 if the image is not tiled.
virtual ~ossimImageUtil()
virtual destructor
static ossimOverviewBuilderFactoryRegistry * instance()
instance method for access to theInstance pointer.
void executePostCommands() const
run post system commands.
virtual ossimImageSource * createImageSource(const ossimString &name) const
OSSIM_DLL double defaultMax(ossimScalarType scalarType)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
ossimHistogramMode getHistogramMode() const
This class defines an abstract Handler which all image handlers(loaders) should derive from...
const std::vector< std::string > & getFilteredImages() const
ossimRefPtr< ossimKeywordlist > m_kwl
Holds all options passed into intialize except writer props.
virtual void loadMetaData()
There is an external file with an omd extension.
ossim_int32 y
Definition: ossimIpt.h:142
void setNumberOfThreads(ossim_uint32 threads)
Set number of threads to use.
virtual void setProperty(const ossimString &name, const ossimString &value)
void setDumpFilteredImageListFlag(bool flag)
Sets the dump filteredImageList flag.
virtual void setThreeBandRgb()
Will set to three bands (rgb) out.
static const char * COMPRESSION_QUALITY_KW
ossimFilename dirCat(const ossimFilename &file) const
void setCreateOverviewsFlag(bool flag)
Sets create overviews flag keyword CREATE_OVERVIEWS_KW used by processFile method.
void initializeDefaultFilterList()
Initializes the filter list with a default set of filtered out file names.
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
bool empty() const
Definition: ossimString.h:411
virtual void setSupplementaryDirectory(const ossimFilename &dir)
Sets the supplementary directory.
virtual ossimFilename createDefaultHistogramFilename() const
void outputOverviewWriterTypes() const
static ossimInit * instance()
Definition: ossimInit.cpp:89
void createThumbnail(ossimRefPtr< ossimImageHandler > &ih)
bool initialize(ossimArgumentParser &ap)
Initial method.
void setCompressionQuality(const std::string &quality)
Sets the writer property for compression quality.
ossimFilename file() const
void setRebuildOverviewsFlag(bool flag)
Sets the rebuild overview flag keyword REBUILD_OVERVIEWS_KW used by processFile method.
virtual void setMaxNumberOfRLevels(ossim_uint32 number)
ossimImageFileWriter * createWriter(const ossimFilename &filename) const
ossimString ext() const
bool isDirectoryBasedImage(const ossimImageHandler *ih) const
virtual ossim_uint32 getNumberOfSamples(ossim_uint32 resLevel=0) const =0
Pure virtual, derived classes must implement.
static ossimImageHandlerRegistry * instance()
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
Returns zero-based bounding rectangle of the image.
void setCreateThumbnailsFlag(bool flag)
Sets create thumbnails flag keyword CREATE_THUMBNAILS_KW used by processFile method.
ossim_int32 x
Definition: ossimIpt.h:141
void setOverviewType(const std::string &type)
Sets key OVERVIEW_TYPE_KW.
virtual void initialize()=0
virtual void scale(double x, double y)
ossimString & gsub(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false)
Substitutes searchKey string with replacementValue and returns a reference to *this.
void setThumbnailStretchType(const std::string &value)
void setWaitOnDirFlag(bool flag)
Sets waitOnDir flag.
void setOverviewStopDimension(ossim_uint32 dimension)
sets the overview stop dimension.
void gsubDate(const std::string &commandPrefix, ossimString &command) const
Expands date variables in a command string.
virtual ossim_uint32 getNumberOfInputBands() const =0
virtual void setFilename(const ossimFilename &filename)
void setMinValueOverride(ossim_float32 minValueOverride)
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
virtual void setTileSize(const ossimIpt &tileSize)
virtual bool setCurrentEntry(ossim_uint32 entryIdx)
ossimOverviewBuilderBase * createBuilder(const ossimString &typeName) const
Creates a builder from a string.
virtual bool setOutputBandList(const std::vector< ossim_uint32 > &band_list)
If the image handler "isBandSeletor()" then the band selection of the output chip can be controlled...
bool hasCmmOption() const
void setRebuildHistogramFlag(bool flag)
Sets the rebuild histogram flag keyword REBUILD_HISTOGRAM_KW used by processFile method.
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...
int & argc()
return the argument count.
ossim_int32 execute()
Execute method.
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
ossimFilename path() const
bool getCopyAllFlag() const
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
Definition: ossimString.h:753
static ossimImageSourceFactoryRegistry * instance()
void walk(const std::vector< ossimFilename > &files)
Takes an array of files.
void setInternalOverviewsFlag(bool flag)
Sets the overview builder internal overviews flag.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
bool openHistogram(const ossimFilename &histogram_file)
Open the histogram file.
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()
ossim_uint32 getNumberOfThreads() const
int ossim_int32
void writeErrorMessages(std::ostream &output, ossimErrorSeverity sevrity=OSSIM_BENIGN)
write out error messages at an above specified .
const std::string & string() const
Definition: ossimString.h:414
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91
void setHistogramMode(ossimHistogramMode mode)
Sets the histogram accumulation mode.