OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
reproject.cpp
Go to the documentation of this file.
1 
13 // iostream is used for general output
14 //
15 #include <iostream>
16 #include <iterator>
17 
18 #include "base/data_types/ossimFilename.h"
19 #include "base/data_types/ossimString.h"
20 #include "imaging/factory/ossimImageHandlerRegistry.h"
21 #include "imaging/formats/ossimImageHandler.h"
22 #include "imaging/formats/ossimImageFileWriter.h"
23 #include "imaging/factory/ossimImageWriterFactoryRegistry.h"
24 
25 // this is an ossim ground point and has a lat, lon, and datum
26 // associated with it.
27 #include "base/data_types/ossimGpt.h"
28 
29 // Base class for accessing projection parameters.
30 #include "projections/ossimProjection.h"
31 
32 // the projection used in the reprojection
33 #include "projections/map_projections/ossimUtmProjection.h"
34 
35 // used to instantiate a projector
36 #include "projections/factory/ossimProjectionFactoryRegistry.h"
37 
38 
39 // The heart of the OSSIM resampling process for reprojecting imagery
40 #include "imaging/tile_sources/ossimImageRenderer.h"
41 
42 // this is the most important class and is called as the first line of all applications.
43 // without this alll the important factories are not created.
44 #include "init/ossimInit.h"
45 
46 using namespace std;
47 
48 void usage();
49 void printOutputTypes();
50 ossimProjection* newUtmView(const ossimGpt& centerGround,
51  const ossimDpt& metersPerPixel);
52 
53 int main(int argc, char* argv[])
54 {
55  ossimInit::instance()->initialize(argc, argv);
56 
57  if(argc!=4)
58  {
59  usage();
60  }
61  else
62  {
63  // try to open up the passed in image
64  //
66 
67  // try to create a writer for the output image type.
68  //
70 
71 
72  if(!handler)
73  {
74  cout << "Unable to open input image: "<< argv[2] << endl;
75  return 1;
76  }
77  if(!writer)
78  {
79  cout << "Unable to create writer of type: " << argv[1] << endl;
80  delete handler;
81  return 1;
82  }
83 
84  ossimKeywordlist geom;
85  handler->getImageGeometry(geom);
86 
87  // grab a projection if it exists
88  //
90 
91  if (!inputProjection)
92  {
93  cout << "the input image has no input projection and can't be reprojected" << endl;
94  delete handler;
95  delete writer;
96  return 1;
97  }
98 
99  // --------------------- SETUP The Resampleing process -------------
100  //
101  // the renderer is the resampler that fits into the chain.
102  // we will set it to a UTM view. We first get the inputs geometry and
103  // then get the scale from its projector.
104  //
105  // now lets set up the renderer
106  ossimImageRenderer* renderer = new ossimImageRenderer;
107 
108  //
109  // get the center ground by running the center pixel
110  // through the handler's projection object
111  ossimIrect bounds = handler->getBoundingRect();
112  ossimGpt centerGround;
113  inputProjection->lineSampleToWorld(bounds.midPoint(), centerGround);
114 
115  // now set the view to a new UTM view.
116  // I pass true in to tell the renderer that it owns the
117  // projection and will be responsible for deleting
118  //
119  renderer->setView(newUtmView(centerGround,
120  inputProjection->getMetersPerPixel()),
121  true);
122 
123  // connect the renderer to the handler
124  renderer->connectMyInputTo(handler);
125 
126  // specify the output file name
127  writer->setFilename(ossimFilename(argv[3]));
128 
129  // now connect the writer to the renderer
130  writer->connectMyInputTo(0, renderer);
131 
132  // execute the reprojection process.
133  writer->execute();
134 
135  delete writer;
136  delete handler;
137  }
138 
139  return 0;
140 }
141 
142 
143 void usage()
144 {
145  cout << "repoject <output_type> <input filename> <output filename>" << endl
146  << "where output types are: " << endl;
148 }
149 
151 {
152  std::vector<ossimString> outputType;
153 
155  std::copy(outputType.begin(),
156  outputType.end(),
157  std::ostream_iterator<ossimString>(std::cout, "\n"));
158 }
159 
160 ossimProjection* newUtmView(const ossimGpt& centerGround,
161  const ossimDpt& metersPerPixel)
162 {
164 
165  // we will make it a square pixel in meters
166  double averageGsd = (metersPerPixel.x + metersPerPixel.y)*.5;
167  utm->setZone(centerGround);
168  utm->setMetersPerPixel(ossimDpt(metersPerPixel));
169 
170 
171  return utm;
172 }
void printOutputTypes()
Definition: reproject.cpp:150
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.
Represents serializable keyword/value map.
double y
Definition: ossimDpt.h:165
static ossimImageWriterFactoryRegistry * instance()
Pure virtual base class for image file writers.
virtual void setMetersPerPixel(const ossimDpt &gsd)
ossimProjection * newUtmView(const ossimGpt &centerGround, const ossimDpt &metersPerPixel)
Definition: reproject.cpp:160
ossimProjection * createProjection(const ossimFilename &filename, ossim_uint32 entryIdx) const
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
ossimIpt midPoint() const
Definition: ossimIrect.h:750
void usage()
Definition: reproject.cpp:143
virtual ossimDpt getMetersPerPixel() const =0
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
void setZone(const ossimGpt &ground)
static ossimProjectionFactoryRegistry * instance()
virtual void setFilename(const ossimFilename &file)
This class defines an abstract Handler which all image handlers(loaders) should derive from...
double x
Definition: ossimDpt.h:164
static ossimInit * instance()
Definition: ossimInit.cpp:89
ossimImageFileWriter * createWriter(const ossimFilename &filename) const
static ossimImageHandlerRegistry * instance()
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
Returns zero-based bounding rectangle of the image.
virtual void lineSampleToWorld(const ossimDpt &lineSampPt, ossimGpt &worldPt) const =0
virtual bool setView(ossimObject *baseObject)
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()
int main(int argc, char *argv[])
Definition: reproject.cpp:53
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const
getImageTypeList.