OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
image_copy_b1.cpp
Go to the documentation of this file.
1 
14 // iostream is used for general output
15 //
16 #include <iostream>
17 #include <iterator>
18 #include "base/data_types/ossimFilename.h"
19 #include "base/data_types/ossimString.h"
20 
21 // This is the majic number factory. All loaders are registered to this factory.
22 // it will lookp through all factories to try to open the passed in image file
23 //
24 #include "imaging/factory/ossimImageHandlerRegistry.h"
25 
26 // Base pointer for the passed back object type
27 //
28 #include "imaging/formats/ossimImageHandler.h"
29 
30 // Base pointer our file writer
31 //
32 #include "imaging/formats/ossimImageFileWriter.h"
33 
34 #include "imaging/factory/ossimImageWriterFactoryRegistry.h"
35 
36 #include "imaging/tile_sources/ossimBandSelector.h"
37 
38 // this is the most important class and is called as the first line of all applications.
39 // without this alll the important factories are not created.
40 //
41 #include "init/ossimInit.h"
42 
43 using namespace std;
44 
45 void usage();
46 void printOutputTypes();
47 
48 int main(int argc, char* argv[])
49 {
50  ossimInit::instance()->initialize(argc, argv);
51 
52  if(argc!=4)
53  {
54  usage();
55  }
56  else
57  {
58  // try to open up the passed in image
59  //
61 
62  // try to create a writer for the output image type.
63  //
65 
66 
67  if(!handler)
68  {
69  cout << "Unable to open input image: "<< argv[2] << endl;
70  return 1;
71  }
72  if(!writer)
73  {
74  cout << "Unable to create writer of type: " << argv[1] << endl;
75  return 1;
76  }
77  ossimBandSelector* selector = new ossimBandSelector;
78 
79  // specify a lookup table that maps
80  // output band list to each input band
81  // the first output band is mapped to
82  // the first input band 0.
83  //
84  vector<ossim_uint32> outputBandList(1);
85 
86  outputBandList[0] = 0;
87  selector->setOutputBandList(outputBandList);
88 
89  selector->connectMyInputTo(0, handler);
90 
91  // specify the output file name
92  writer->setFilename(ossimFilename(argv[3]));
93  writer->connectMyInputTo(0, selector);
94  writer->execute();
95 
96  delete writer;
97  delete handler;
98  }
99 
100  return 0;
101 }
102 
103 
104 void usage()
105 {
106  cout << "image_copy <output_type> <input filename> <output filename>" << endl
107  << "where output types are: " << endl;
109 }
110 
112 {
113  std::vector<ossimString> outputType;
114 
116  std::copy(outputType.begin(),
117  outputType.end(),
118  ostream_iterator<ossimString>(cout, "\n"));
119 }
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.
void printOutputTypes()
static ossimImageWriterFactoryRegistry * instance()
void usage()
Pure virtual base class for image file writers.
int main(int argc, char *argv[])
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...
virtual void setOutputBandList(const vector< ossim_uint32 > &outputBandList, bool disablePassThru=false)
Sets the output band list.
static ossimInit * instance()
Definition: ossimInit.cpp:89
ossimImageFileWriter * createWriter(const ossimFilename &filename) const
static ossimImageHandlerRegistry * instance()
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const
getImageTypeList.