OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
band_average.cpp
Go to the documentation of this file.
1 
14 // iostream is used for general output
15 //
16 #include <iostream>
17 #include <iterator>
18 
19 #include "base/data_types/ossimFilename.h"
20 #include "base/data_types/ossimString.h"
21 
22 // this is for implementing progress output.
23 //
24 #include "base/common/ossimStdOutProgress.h"
25 
26 // This is the majic number factory. All loaders are registered to this factory.
27 // it will lookp through all factories to try to open the passed in image file
28 //
29 #include "imaging/factory/ossimImageHandlerRegistry.h"
30 
31 // Base pointer for the passed back object type
32 //
33 #include "imaging/formats/ossimImageHandler.h"
34 
35 // Base pointer our file writer
36 //
37 #include "imaging/formats/ossimImageFileWriter.h"
38 
39 #include "imaging/factory/ossimImageWriterFactoryRegistry.h"
40 
41 #include "imaging/tile_sources/ossimBandAverageFilter.h"
42 
43 // this is the most important class and is called as the first line of all applications.
44 // without this alll the important factories are not created.
45 //
46 #include "init/ossimInit.h"
47 
48 
49 using namespace std;
50 void usage();
51 void printOutputTypes();
52 
53 int main(int argc, char* argv[])
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 }
127 
128 
129 void usage()
130 {
131  cout << "image_copy <output_type> <input filename> <output filename>" << endl
132  << "where output types are: " << endl;
134 }
136 {
137  std::vector<ossimString> outputType;
138 
140  std::copy(outputType.begin(),
141  outputType.end(),
142  std::ostream_iterator<ossimString>(cout, "\n"));
143 }
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.
void printOutputTypes()
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...
int main(int argc, char *argv[])
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()
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const
getImageTypeList.