OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimEnviCgModel.cpp
Go to the documentation of this file.
1 //*****************************************************************************
2 // FILE: ossimCoarseGridModel.cc
3 //
4 // License: See LICENSE.txt file in the top level directory.
5 //
6 // AUTHOR: Oscar Kramer
7 //
8 // DESCRIPTION:
9 // Contains implementation of class ossimCoarseGridModel. This is an
10 // implementation of an interpolation sensor model.
11 //
12 // IMPORTANT: The lat/lon grid is for ground points on the ellipsoid.
13 // The dLat/dHgt and dLon/dHgt partials therefore are used against
14 // elevations relative to the ellipsoid.
15 //
16 //*****************************************************************************
17 // $Id: ossimCoarseGridModel.cpp 22825 2014-07-07 23:14:52Z dburken $
18 
20 
21 RTTI_DEF1(ossimEnviCgModel, "ossimEnviCgModel", ossimCoarseGridModel);
22 
28 
29 static const char* MODEL_TYPE = "ossimEnviCgModel";
30 
31 //*****************************************************************************
34 {}
35 
36 //*****************************************************************************
39 {
40  loadEnviGeocFile(geoc_file);
41 }
42 
43 
44 //*****************************************************************************
46 {
47  theHeightEnabledFlag = false;
49 
50  ossimFilename geoc_hdr (geoc_file + ".hdr");
51 
52  ifstream geocHdrStream (geoc_hdr.c_str());
53  if (geocHdrStream.fail())
54  {
55  cout << "ossimEnviCgModel:loadEnviGeocFile() Error encountered opening GEOC header file <"<<geoc_hdr<<">"<<endl;
56  return false;
57  }
58 
59  char line[1024];
61  geocHdrStream.getline(line, 1024);
62  ossimString oline(line);
63  int bigEndian=0;
64  if (!oline.contains("ENVI"))
65  {
66  cout << "ossimEnviCgModel:loadEnviGeocFile() Error: GEOC header file <"<<geoc_hdr
67  <<"> missing \"ENVI\" magic number."<<endl;
68  return false;
69  }
70  while (!geocHdrStream.eof())
71  {
72  geocHdrStream.getline(line, 1024);
73  oline = line;
74  vector<ossimString> strSplit;
75  if (oline.contains("samples"))
76  imageSize.x = oline.after("=").trim().toInt();
77  else if (oline.contains("lines"))
78  imageSize.y = oline.after("=").trim().toInt();
79  else if (oline.contains("byte order"))
80  bigEndian = oline.after("=").trim().toInt();
81  }
82 
83  ossimDpt gridOrigin(0,0);
84 
85  ifstream geocStream (geoc_file.c_str(), ios_base::binary|ios_base::in);
86  if (geocStream.fail())
87  {
88  cout << "ossimEnviCgModel:Ctor Error encountered opening GEOC file <"<<geoc_file<<">"<<endl;
89  return false;
90  }
91 
92  ossimDpt spacing (1,1);
93  theLatGrid.initialize(imageSize, gridOrigin, spacing);
94  theLonGrid.initialize(imageSize, gridOrigin, spacing);
95  theDlatDhGrid.initialize(imageSize, gridOrigin, spacing);
96  theDlonDhGrid.initialize(imageSize, gridOrigin, spacing);
97 
98  double value;
99  for (int y=0; (y<imageSize.y) && !geocStream.eof() ; ++y)
100  {
101  for (int x=0; (x<imageSize.x) && !geocStream.eof() ; ++x)
102  {
103  value = readValue(geocStream, (bool) bigEndian);
104  theLonGrid.setNode(x, y, value);
105  }
106  }
107  for (int y=0; (y<imageSize.y) && !geocStream.eof() ; ++y)
108  {
109  for (int x=0; (x<imageSize.x) && !geocStream.eof() ; ++x)
110  {
111  value = readValue(geocStream, (bool) bigEndian);
112  theLatGrid.setNode(x, y, value);
113  }
114  }
115 
116  theDlatDhGrid.fill(0.0);
117  theDlonDhGrid.fill(0.0);
120 
121  ossimIrect imageBounds(0, 0, imageSize.x-1, imageSize.y-1);
122  initializeModelParams(imageBounds);
123 
124  return true;
125 }
126 
127 bool ossimEnviCgModel::saveState(ossimKeywordlist& kwl, const char* prefix) const
128 {
129  bool status = ossimCoarseGridModel::saveState(kwl, prefix);
130  if (status)
131  kwl.add(prefix, "type", "ossimCoarseGridModel");
132  return status;
133 }
134 
135 double ossimEnviCgModel::readValue(ifstream& s, bool bigEndian) const
136 {
137  double value;
138  s.read( reinterpret_cast<char*>(&value) , sizeof(double) );
139  if (bigEndian)
140  {
141  char * pc = reinterpret_cast<char *>(&value);
142  std::swap(pc[0], pc[7]);
143  std::swap(pc[1], pc[6]);
144  std::swap(pc[2], pc[5]);
145  std::swap(pc[3], pc[4]);
146  cout<<endl;
147  }
148  return value;
149 }
ossim_uint32 x
Represents serializable keyword/value map.
ossim_uint32 y
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
double readValue(ifstream &s, bool bigEndian) const
double y
Definition: ossimDpt.h:165
bool contains(char aChar) const
Definition: ossimString.h:58
bool loadEnviGeocFile(const ossimFilename &geoc_file)
void setDomainType(DomainType dt)
Definition: ossimDblGrid.h:156
void initialize(const ossimIpt &size, const ossimDpt &origin, const ossimDpt &spacing, double null_value=OSSIM_DEFAULT_NULL_PIX_DOUBLE)
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Fulfills ossimObject base-class pure virtuals.
ossimDpt imageSize() const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
return status
RTTI_DEF1(ossimEnviCgModel, "ossimEnviCgModel", ossimCoarseGridModel)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Fulfills ossimObject base-class pure virtuals.
double x
Definition: ossimDpt.h:164
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
void initializeModelParams(ossimIrect irect)
Initializes base class data members after grids have been assigned.
void fill(double fill_value)
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
int toInt() const
void setNode(const ossimIpt &p, const double &value)
Definition: ossimDblGrid.h:107