OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTileMapModel.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // AUTHOR: Jordi Inglada
6 //
7 // DESCRIPTION:
8 //
9 // SOFTWARE HISTORY:
10 // 23JAN2008 Jordi Inglada, CNES
11 // Initial coding.
12 //
13 //*****************************************************************************
14 
15 #include "ossimTileMapModel.h"
16 
17 #include <stdio.h>
18 #include <cstdlib>
19 
22 
23 //***
24 // Define Trace flags for use within this file:
25 //***
26 #include <ossim/base/ossimTrace.h>
27 static ossimTrace traceExec ("ossimTileMapModel:exec");
28 static ossimTrace traceDebug ("ossimTileMapModel:debug");
29 
30 namespace ossimplugins
31 {
32 
33  RTTI_DEF1(ossimTileMapModel, "ossimTileMapModel", ossimSensorModel);
34 
35 //*****************************************************************************
36 // DEFAULT CONSTRUCTOR: ossimTileMapModel()
37 //
38 //*****************************************************************************
40  :
42  qDepth (1)
43 
44  {
45  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::ossimTileMapModel: entering..." << std::endl;
46 
47 // initAdjustableParameters();
48 
49 // std::cout << "TileMapModel constructor" << std::endl;
50 
51  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::ossimTileMapModel: returning..." << std::endl;
52  }
53 
54 
56  {
57  static const char MODULE[] = "ossimTileMapModel::open";
58 
59  ossimString os = file.beforePos(4);
60 
61  if (traceDebug())
62  {
63  CLOG << " Entered..." << std::endl
64  << " trying to open file " << file << std::endl;
65  }
66  if(os == "http" || file.ext() == "otb")
67  {
68  return true;
69  }
70 
71  return false;
72  }
73 
74 
75 //*****************************************************************************
76 // CONSTRUCTOR: ossimTileMapModel(kwl)
77 //
78 // Constructs model from keywordlist geometry file
79 //
80 //*****************************************************************************
82  :
84  qDepth (1)
85  {
86  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::ossimTileMapModel(geom_kwl): entering..." << std::endl;
87 
88 
89  //***
90  // Parse keywordlist for geometry:
91  //***
92  loadState(geom_kwl);
93 
94  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::ossimTileMapModel(geom_kwl): Exited..." << std::endl;
95  }
96 
97 //*****************************************************************************
98 // COPY CONSTRUCTOR:
99 //*****************************************************************************
101  :
102  ossimSensorModel (rhs),
103  qDepth (rhs.qDepth)
104  {
105  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::ossimTileMapModel(rhs): entering..." << std::endl;
106 
107  //initAdjustableParameters();
108 
109  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::ossimTileMapModel(rhs): returning..." << std::endl;
110  }
111 
112 //*****************************************************************************
113 // METHOD: ossimTileMapModel::lineSampleHeightToWorld()
114 //
115 // Performs the line/sample to groundpoint projection given an elevation.
116 //
117 //*****************************************************************************
119  ossimGpt& gpt) const
120  {
121  lineSampleHeightToWorld(image_point, 0.0, gpt);
122  }
124  const double& /* height */,
125  ossimGpt& gpt) const
126  {
127  if(!image_point.hasNans())
128  {
129  gpt.lon = static_cast<double>(image_point.samp)/(1 << qDepth)/256 *360.0-180.0;
130  double y = static_cast<double>(image_point.line)/(1 << qDepth)/256;
131  double ex = exp(4*M_PI*(y-0.5));
132  gpt.lat = -180.0/M_PI*asin((ex-1)/(ex+1));
133  }
134  else
135  {
136  gpt.makeNan();
137  }
138  return;
139  }
140 
142  ossimDpt& img_pt) const
143  {
144  // if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::worldToLineSample(): entering..." << std::endl;
145 
146  if(ground_point.isLatNan() || ground_point.isLonNan() )
147  {
148  img_pt.makeNan();
149  return;
150  }
151 
152  double x = (180.0 + ground_point.lon) / 360.0;
153  double y = - ground_point.lat * M_PI / 180; // convert to radians
154  y = 0.5 * log((1+sin(y)) / (1 - sin(y)));
155  y *= 1.0/(2 * M_PI); // scale factor from radians to normalized
156  y += 0.5; // and make y range from 0 - 1
157 
158  img_pt.samp = floor(x*pow(2.,static_cast<double>(qDepth))*256);
159 
160  img_pt.line = floor(y*pow(2.,static_cast<double>(qDepth))*256);
161 
162  return;
163  }
164 
165 
166 
167 //*****************************************************************************
168 // METHOD: ossimTileMapModel::print()
169 //
170 // Formatted dump of data members.
171 //
172 //*****************************************************************************
174  {
175  os << "\nDump of ossimTileMapModel object at "
176  << hex << this << ":\n"
177  << "\nTileMapModel -- Dump of all data members: "
178  << "\n theImageID: " << theImageID.chars()
179  << "\n theImageSize: " << theImageSize
180  << "\n theRefImgPt: " << theRefImgPt
181  << "\n theRefGndPt: " << theRefGndPt
182  << "\n theGSD.line: " << theGSD.line
183  << "\n theGSD.samp: " << theGSD.samp
184  << "\n qDepth: " << qDepth
185  << endl;
186 
187  return ossimSensorModel::print(os);
188  }
189 
190 //*****************************************************************************
191 // METHOD: ossimTileMapModel::saveState()
192 //
193 // Saves the model state to the KWL. This KWL also serves as a geometry file.
194 //
195 //*****************************************************************************
197  const char* prefix) const
198  {
199  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::saveState: entering..." << std::endl;
200 
201  kwl.add(prefix, ossimKeywordNames::TYPE_KW, TYPE_NAME(this));
202 
203  kwl.add(prefix, "depth", qDepth);
204 
205  //***
206  // Hand off to base class for common stuff:
207  //***
208  ossimSensorModel::saveState(kwl, prefix);
209 
210 
211  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::saveState: returning..." << std::endl;
212  return true;
213  }
214 
215 //*****************************************************************************
216 // METHOD: ossimTileMapModel::loadState()
217 //
218 // Restores the model's state from the KWL. This KWL also serves as a
219 // geometry file.
220 //
221 //*****************************************************************************
223  const char* prefix)
224  {
225  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::loadState: entering..." << std::endl;
226 
227  if (traceDebug())
228  {
229  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::loadState:"
230  << "\nInput kwl: " << kwl
231  << std::endl;
232  }
233 
234  const char* value = NULL;
235  //const char* keyword =NULL;
236  bool success;
237 
238  //***
239  // Assure this keywordlist contains correct type info:
240  //***
241  value = kwl.find(prefix, ossimKeywordNames::TYPE_KW);
242  if (!value || (strcmp(value, TYPE_NAME(this))))
243  {
244  theErrorStatus = 1;
245  return false;
246  }
247 
248  value = kwl.find(prefix, "depth");
249  qDepth = atoi(value);
250 
251  //***
252  // Pass on to the base-class for parsing first:
253  //***
254  success = ossimSensorModel::loadState(kwl, prefix);
255  if (!success)
256  {
257  theErrorStatus++;
258  return false;
259  }
260 
261 
262  updateModel();
263 
264  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::loadState: returning..." << std::endl;
265  return true;
266  }
267 
268 //*****************************************************************************
269 // STATIC METHOD: ossimTileMapModel::writeGeomTemplate
270 //
271 // Writes a sample kwl to output stream.
272 //
273 //*****************************************************************************
275  {
276  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::writeGeomTemplate: entering..." << std::endl;
277 
278  os <<
279  "//**************************************************************\n"
280  "// Template for TileMap model keywordlist\n"
281  "//**************************************************************\n"
282  << ossimKeywordNames::TYPE_KW << ": " << "ossimTileMapModel" << endl;
283 
284 
285  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::writeGeomTemplate: returning..." << std::endl;
286  return;
287  }
288 } // End: namespace ossimplugins
ossim_uint32 x
#define TYPE_NAME(p)
Definition: ossimRtti.h:326
virtual void lineSampleToWorld(const ossimDpt &image_point, ossimGpt &worldPoint) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
static void writeGeomTemplate(ostream &os)
#define CLOG
Definition: ossimTrace.h:23
RTTI_DEF1(ossimAlosPalsarModel, "ossimAlosPalsarModel", ossimGeometricSarSensorModel)
Represents serializable keyword/value map.
bool isLonNan() const
Definition: ossimGpt.h:140
ossim_uint32 y
const char * find(const char *key) const
ossimString theImageID
double samp
Definition: ossimDpt.h:164
void makeNan()
Definition: ossimGpt.h:130
bool isLatNan() const
Definition: ossimGpt.h:139
static const char * TYPE_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
double line
Definition: ossimDpt.h:165
#define M_PI
ossim_float64 lon
Definition: ossimGpt.h:266
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual std::ostream & print(std::ostream &out) const
bool hasNans() const
Definition: ossimDpt.h:67
virtual void updateModel()
bool open(const ossimFilename &file)
virtual void lineSampleHeightToWorld(const ossimDpt &image_point, const double &heightEllipsoid, ossimGpt &worldPoint) const
ossimString beforePos(std::string::size_type pos) const
ossimString ext() const
ossim_float64 lat
Definition: ossimGpt.h:265
virtual std::ostream & print(std::ostream &out) const
virtual void worldToLineSample(const ossimGpt &ground_point, ossimDpt &img_pt) const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void makeNan()
Definition: ossimDpt.h:65
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23