OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimEnviTileSource.cpp
Go to the documentation of this file.
1 //---
2 //
3 // License: MIT
4 //
5 // Author: David Burken
6 //
7 // Description:
8 //
9 // Image handler class for a raster files with an ENVI header file.
10 //
11 //---
12 // $Id$
13 
17 #include <ossim/base/ossimTrace.h>
23 
24 
26  "ossimEnviTileSource",
28 
29 static ossimTrace traceDebug("ossimEnviTileSource:debug");
30 
32  :
34  m_enviHdr()
35 {
36 }
37 
39 {
40 }
41 
43 {
44  static const char MODULE[] = "ossimEnviTileSource::open";
45  if ( traceDebug() )
46  {
48  << MODULE << " entered..."
49  << "\nimage file: " << theImageFile << std::endl;
50  }
51 
52  bool result = false;
53 
54  if(isOpen())
55  {
56  close();
57  }
58 
59  // Look for a header file:
60  ossimFilename hdr = theImageFile;
61  hdr.setExtension("hdr"); // image.hdr
62  if ( !hdr.exists() )
63  {
64  hdr = theImageFile;
65  hdr.string() += ".hdr"; // image.ras.hdr
66  }
67 
68  if ( hdr.exists() )
69  {
70  if ( traceDebug() )
71  {
72  ossimNotify(ossimNotifyLevel_DEBUG) << "header file: " << hdr << std::endl;
73  }
74 
75  if ( m_enviHdr.open( hdr ) )
76  {
77  if ( m_rasterInfo.initializeFromEnviHdr( m_enviHdr ) )
78  {
79  // Set image file for initializeHandler method.
80  m_rasterInfo.setImageFile( theImageFile );
81 
82  // Look for an omd file:
83  ossimFilename omd = theImageFile;
84  omd.setExtension("omd"); // image.omd
85  if ( !omd.exists() )
86  {
87  omd.setExtension("kwl"); // image.kwl
88  }
89 
90  if ( omd.exists() )
91  {
92  if ( traceDebug() )
93  {
94  ossimNotify(ossimNotifyLevel_DEBUG) << "omd file: " << omd << std::endl;
95  }
96 
97  // Pick up adjusted min / max values if present.
98  ossimKeywordlist kwl( omd );
99  m_rasterInfo.getImageMetaData().updateMetaData( kwl, std::string("") );
100  }
101 
102  theMetaData = m_rasterInfo.getImageMetaData();
103 
104  result = initializeHandler();
105  if ( result )
106  {
107  completeOpen();
108 
109  //---
110  // This will set default output band list if we are a band selector and
111  // "default bands" key is found in the envi header. If "default bands"
112  // is not found it will set to identity(input = output).
113  //---
114  setDefaultBandList();
115  }
116  }
117  }
118  }
119 
120  if ( traceDebug() )
121  {
123  << MODULE << " Exit status: " << (result?"true":"false") << std::endl;
124  }
125 
126  return result;
127 }
128 
129 //************************************************************************************************
132 //************************************************************************************************
134 {
135  if ( !theGeometry )
136  {
137  // Check for external geom:
138  theGeometry = getExternalImageGeometry();
139 
140  if ( !theGeometry )
141  {
142  // Check the internal geometry first to avoid a factory call.
143  theGeometry = getInternalImageGeometry();
144 
145  // At this point it is assured theGeometry is set.
146 
147  //---
148  // WARNING:
149  // Must create/set theGeometry at this point or the next call to
150  // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
151  // as it does a recursive call back to ossimImageHandler::getImageGeometry().
152  //---
153 
154  // Check for set projection.
155  if ( theGeometry.valid()&&!theGeometry->getProjection() )
156  {
157  // Try factories for projection.
159  }
160  }
161 
162  // Set image things the geometry object should know about.
163  initImageParameters( theGeometry.get() );
164  }
165 
166  return theGeometry;
167 }
168 
170 {
171  static const char MODULE[] = "ossimEnviTileSource::getInternalImageGeometry";
172  if (traceDebug())
173  {
174  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
175  }
177 
178 // debugging to turn off model load
179 // return geom;
180 
181  geom = new ossimImageGeometry();
182 
184  if ( supData->readSupportFiles( m_enviHdr ) )
185  {
186  if (supData->isHSI())
187  {
189  if ( sensor->initialize( *(supData.get()) ) )
190  {
191  geom->setProjection( sensor.get() );
192  }
193  }
194  else
195  {
197  if ( sensor->initialize( *(supData.get()) ) )
198  {
199  geom->setProjection( sensor.get() );
200  }
201  }
202 
203  } // Matches: if ( supData->readSupportFiles( m_enviHdr ) )
204  else
205  {
206  geom = 0;
207  }
208 
209  return geom;
210 }
211 
213  const char* prefix)const
214 {
215  return ossimGeneralRasterTileSource::saveState(kwl,prefix);
216 }
217 
219  const char* prefix)
220 {
221  return ossimGeneralRasterTileSource::loadState(kwl, prefix);
222 }
223 
225  const ossimString& name)const
226 {
227  if(name == "file_type")
228  {
229  return new ossimStringProperty(name, getShortName());
230  }
231 
232  return ossimImageHandler::getProperty(name);
233 }
234 
236  std::vector<ossimString>& propertyNames)const
237 {
239  propertyNames.push_back("file_type");
240 }
241 
243 {
244  return ossimString("ENVI");
245 }
246 
248 {
249  return ossimString("ENVI reader");
250 }
251 
252 bool ossimEnviTileSource::getRgbBandList(std::vector<ossim_uint32>& bandList) const
253 {
254  bool result = false;
255 
256  bandList.clear();
257 
258  // Look in ENVI header for "default bands":
259  result = m_enviHdr.getDefaultBands( bandList );
260 
261  if ( !result && ( getNumberOfInputBands() > 2 ) )
262  {
263  // Try to derive RGB from wavelengths if found in ENVI header.
264  ossimWavelength wl;
265  if ( wl.initialize( m_enviHdr ) )
266  {
267  result = wl.getRgbBands( bandList );
268  }
269  }
270 
271  if ( bandList.size() != 3 )
272  {
273  result = false;
274  }
275 
276  return result;
277 }
278 
280 {
281  if ( isBandSelector() )
282  {
283  std::vector<ossim_uint32> bandList;
284  if ( getRgbBandList( bandList ) )
285  {
286  if ( bandList.size() )
287  {
288  ossimImageHandler::setOutputBandList(bandList, m_outputBandList);
289  }
290  }
291  }
292 
293  if ( m_outputBandList.empty() )
294  {
295  // Initialized to identity (input = output):
296  ossimImageSource::getOutputBandList( m_outputBandList );
297  }
298 }
virtual bool readSupportFiles(const ossimFilename &hdrFile)
static ossimImageGeometryRegistry * instance()
void setProjection(ossimProjection *projection)
Sets the projection to be used for local-to-world coordinate transformation.
virtual ossimString getLongName() const
Represents serializable keyword/value map.
void setDefaultBandList()
Sets default output band list if we are a band selector and "default bands" is found in the header fi...
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Adds property names to array.
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual bool extendGeometry(ossimImageHandler *handler) const
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
Gets a property.
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual void getOutputBandList(std::vector< ossim_uint32 > &bandList) const
Initializes bandList.
bool getRgbBands(std::vector< ossim_uint32 > &bands) const
Gets rgb bands if "wavelength" keyword is present.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
bool exists() const
ossimEnviTileSource()
default constructor
virtual bool open()
open method.
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
virtual bool initialize(const ossimAlphaSensorSupportData &supData)
Initializes model from support data and calls update Model on success.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual ~ossimEnviTileSource()
Hidden from use destructor.
ossimRefPtr< ossimImageGeometry > getInternalImageGeometry() const
Creates geometry from known support data, i.e.
virtual ossimString getShortName() const
virtual bool initialize(const ossimAlphaSensorSupportData &supData)
Initializes model from support data and calls update Model on success.
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
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...
virtual bool getRgbBandList(std::vector< ossim_uint32 > &bandList) const
Get the zero based rgb output band list from envi header.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
const std::string & string() const
Definition: ossimString.h:414
bool initialize(const ossimEnviHeader &hdr)
Initializes map from ENVI header class.