OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Functions
band_average.cpp File Reference
#include <iostream>
#include <iterator>
#include "base/data_types/ossimFilename.h"
#include "base/data_types/ossimString.h"
#include "base/common/ossimStdOutProgress.h"
#include "imaging/factory/ossimImageHandlerRegistry.h"
#include "imaging/formats/ossimImageHandler.h"
#include "imaging/formats/ossimImageFileWriter.h"
#include "imaging/factory/ossimImageWriterFactoryRegistry.h"
#include "imaging/tile_sources/ossimBandAverageFilter.h"
#include "init/ossimInit.h"

Go to the source code of this file.

Functions

void usage ()
 
void printOutputTypes ()
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 53 of file band_average.cpp.

References ossimImageFileWriter::addListener(), ossimConnectableObject::connectMyInputTo(), ossimImageWriterFactoryRegistry::createWriter(), ossimImageFileWriter::execute(), ossimInit::initialize(), ossimImageWriterFactoryRegistry::instance(), ossimInit::instance(), ossimImageHandlerRegistry::instance(), ossimImageHandlerRegistry::open(), ossimImageFileWriter::removeListener(), ossimImageFileWriter::setFilename(), and usage().

54 {
55  ossimInit::instance()->initialize(argc, argv);
56  if(argc!=4)
57  {
58  usage();
59  }
60  else
61  {
62  // try to open up the passed in image
63  //
65 
66  // try to create a writer for the output image type.
67  //
69 
70  if(!handler)
71  {
72  cout << "Unable to open input image: "<< argv[2] << endl;
73  return 1;
74  }
75  if(!writer)
76  {
77  cout << "Unable to create writer of type: " << argv[1] << endl;
78  delete handler;
79  return 1;
80  }
81 
82  ossimBandAverageFilter *bandAverageFilter = new ossimBandAverageFilter;
83  bandAverageFilter->connectMyInputTo(handler);
84 
85  // specify the output file name
86  writer->setFilename(ossimFilename(argv[3]));
87 
88  // within OSSIM we have a concept of inputs that can be connected together
89  // writer have only 1 input and we index them starting from 0. If we only
90  // supplied the second argument it would find the first available input and connect
91  // it to that slot. Here, we explicitly say connect the handler to slot 0 of the
92  // writer.
93  //
94  writer->connectMyInputTo(0, bandAverageFilter);
95 
96  // Optionally we can add listeners to listen for certain events.
97  //
98  // all writers should execute event processing and generate a progress event.
99  // we have a default event listener that listens for this event and can be used
100  // to output the progress of the exected process.
101  //
102  // the first argument is to specify the precision of the percent complete
103  // output, here we default to 0 for whole number outputs. The second argument
104  // specifies to flush the stream on each print If you don't want progress
105  // output then don't add this listener
106  //
107  // the defalut standard out listener is found in base/common/ossimStdOutProgress.h"
108  //
109  ossimStdOutProgress progress(0, true);
110  writer->addListener(&progress);
111 
112  // execute the writer. Writer will start sequencing through
113  // all the tiles from the input and output it to disk.
114  //
115  writer->execute();
116 
117  // now to be on the safe side we will remove any added listeners.
118  writer->removeListener(&progress);
119 
120  delete bandAverageFilter;
121  delete writer;
122  delete handler;
123  }
124 
125  return 0;
126 }
void usage()
void initialize(int &argc, char **argv)
Definition: ossimInit.cpp:119
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
This filter outputs a single band that is the weighted average of all the input bands retrieved from ...
virtual bool addListener(ossimListener *listener)
Overrides base "addListener" this will capture the pointer and then call the base class "addListener"...
static ossimImageWriterFactoryRegistry * instance()
Pure virtual base class for image file writers.
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual void setFilename(const ossimFilename &file)
This class defines an abstract Handler which all image handlers(loaders) should derive from...
static ossimInit * instance()
Definition: ossimInit.cpp:89
ossimImageFileWriter * createWriter(const ossimFilename &filename) const
static ossimImageHandlerRegistry * instance()
virtual bool removeListener(ossimListener *listener)
Overrides base "removeListener".
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()

◆ printOutputTypes()

void printOutputTypes ( )

Definition at line 135 of file band_average.cpp.

References ossimImageWriterFactoryRegistry::getImageTypeList(), and ossimImageWriterFactoryRegistry::instance().

Referenced by usage().

136 {
137  std::vector<ossimString> outputType;
138 
140  std::copy(outputType.begin(),
141  outputType.end(),
142  std::ostream_iterator<ossimString>(cout, "\n"));
143 }
static ossimImageWriterFactoryRegistry * instance()
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const
getImageTypeList.

◆ usage()

void usage ( )

Definition at line 129 of file band_average.cpp.

References printOutputTypes().

Referenced by main(), and ossimArgumentParser::setApplicationUsage().

130 {
131  cout << "image_copy <output_type> <input filename> <output filename>" << endl
132  << "where output types are: " << endl;
134 }
void printOutputTypes()