OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimWarpProjection.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // AUTHOR: Oscar Kramer
6 //
7 // DESCRIPTION:
8 // Contains implementation of class ossimWarpModel. This is an
9 // implementation of a warping interpolation model.
10 //
11 //*****************************************************************************
12 // $Id: ossimWarpProjection.cpp 21214 2012-07-03 16:20:11Z dburken $
13 
15 RTTI_DEF1(ossimWarpProjection, "ossimWarpProjection", ossimProjection);
16 
21 
22 static const char* AFFINE_PREFIX = "affine.";
23 static const char* QUADWARP_PREFIX = "quadwarp.";
24 static const char* PROJECTION_PREFIX = "projection.";
25 
26 //***
27 // Define Trace flags for use within this file:
28 //***
29 #include <ossim/base/ossimTrace.h>
30 static ossimTrace traceExec ("ossimWarpProjection:exec");
31 static ossimTrace traceDebug ("ossimWarpProjection:debug");
32 
33 //*****************************************************************************
34 // CONSTRUCTOR: Default
35 //
36 //*****************************************************************************
38  :
40  theClientProjection (0),
41  theWarpTransform (0),
42  theAffineTransform (0)
43 {
46 }
47 
48 
49 //*****************************************************************************
50 // CONSTRUCTOR: Primary constructor accepting pointer to the underlying
51 // client projection
52 //
53 //*****************************************************************************
55  :
57  theClientProjection (client),
58  theWarpTransform (0),
59  theAffineTransform (0)
60 {
63 }
64 
65 //*****************************************************************************
66 // CONSTRUCTOR: Accepts geom keywordlist
67 //*****************************************************************************
69  const char* prefix)
70  :
72  theClientProjection (0),
73  theWarpTransform (0),
74  theAffineTransform (0)
75 {
77  createProjection(geom_kwl, prefix);
78 
80  bool rtn_stat = theWarpTransform->loadState(geom_kwl, prefix);
81 
83  rtn_stat &= theAffineTransform->loadState(geom_kwl, prefix);
84 
85  if ((!theClientProjection) ||
87  (!rtn_stat))
89 }
90 
91 //*****************************************************************************
92 // DESTRUCTOR
93 //*****************************************************************************
95 {
97  theWarpTransform = 0;
99 }
100 
101 //*****************************************************************************
102 // METHOD: ossimWarpProjection::worldToLineSample()
103 //*****************************************************************************
105  ossimDpt& lineSampPt) const
106 {
107  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimWarpProjection::worldToLineSample: Entering..." << std::endl;
108 
110  {
111  theClientProjection->worldToLineSample(worldPoint, lineSampPt);
112  theAffineTransform->inverse(lineSampPt);
113  theWarpTransform->inverse(lineSampPt);
114  }
115  else
116  {
117  lineSampPt.makeNan();
118  }
119 
120  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimWarpProjection::worldToLineSample: Returning..." << std::endl;
121 }
122 
123 //*****************************************************************************
124 // METHOD: ossimWarpProjection::lineSampleToWorld()
125 //*****************************************************************************
127  ossimGpt& worldPt) const
128 {
129  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimWarpProjection::lineSampleToWorld: Entering..." << std::endl;
130 
132  {
133  ossimDpt adjustedPt;
134  theWarpTransform->forward(adjustedPt);
135  theAffineTransform->forward(lineSampPt, adjustedPt);
136  theClientProjection->lineSampleToWorld(adjustedPt, worldPt);
137  }
138  else
139  {
140  worldPt.makeNan();
141  }
142 
143  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimWarpProjection::lineSampleToWorld: Returning..." << std::endl;
144 }
145 
146 //*****************************************************************************
147 // METHOD: ossimWarpProjection::lineSampleToWorld()
148 //*****************************************************************************
150  const double& hgt,
151  ossimGpt& worldPt) const
152 {
153  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimWarpProjection::lineSampleHeightToWorld: Entering..." << std::endl;
154 
156  {
157  ossimDpt adjustedPt;
158  theAffineTransform->forward(lineSampPt, adjustedPt);
159  theWarpTransform->forward(adjustedPt);
160  theClientProjection->lineSampleHeightToWorld(adjustedPt, hgt, worldPt);
161  }
162  else
163  {
164  worldPt.makeNan();
165  }
166 
167  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimWarpProjection::lineSampleHeightToWorld: Returning..." << std::endl;
168 }
169 
170 //*****************************************************************************
171 // METHOD: ossimWarpProjection::print()
172 //*****************************************************************************
174 {
176  {
177  out <<
178  "ossimWarpProjection:\n"
179  << " Member theClientProjection: ";
181 
182  out << " Member theAffineTransform: " << *theAffineTransform << "\n"
183  << " Member theWarpTransform: " << *theWarpTransform << std::endl;
184  }
185  else
186  {
187  out << "ossimWarpProjection -- Not inititialized." << std::endl;
188  }
189  return out;
190 }
191 
193 {
194  return m.print(os);
195 }
196 
197 //*****************************************************************************
198 // METHOD: ossimWarpProjection::saveState()
199 //*****************************************************************************
201  const char* prefix) const
202 {
203  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimWarpProjection::saveState: entering..." << std::endl;
204 
205  ossimString projPrefix = ossimString(prefix) + PROJECTION_PREFIX;
206  ossimString affinePrefix = ossimString(prefix) + AFFINE_PREFIX;
207  ossimString quadwarpPrefix = ossimString(prefix) + QUADWARP_PREFIX;
208 
210  {
211  theClientProjection->saveState(kwl, projPrefix.c_str());
212  theAffineTransform->saveState(kwl, affinePrefix.c_str());
213  theWarpTransform->saveState(kwl, quadwarpPrefix.c_str());
214  }
215 
216  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimWarpProjection::saveState: returning..." << std::endl;
217  return ossimProjection::saveState(kwl, prefix);
218 }
219 
220 //*****************************************************************************
221 // METHOD: ossimWarpProjection::loadState()
222 //*****************************************************************************
224  const char* prefix)
225 {
226  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimWarpProjection::loadState: entering..." << std::endl;
227 
228 // bool good_load;
229 // int err_stat;
230  // bool result = true;
231 
232  ossimString projPrefix = ossimString(prefix) + PROJECTION_PREFIX;
233  ossimString affinePrefix = ossimString(prefix) + AFFINE_PREFIX;
234  ossimString quadwarpPrefix = ossimString(prefix) + QUADWARP_PREFIX;
235 
237 
238  if (!theWarpTransform)
240 
241  if (!theAffineTransform)
243 
245 
246  if ( theClientProjection.valid() )
247  {
248  theWarpTransform->loadState(kwl, quadwarpPrefix.c_str());
249  theAffineTransform->loadState(kwl, affinePrefix.c_str());
250  }
251 
252 #if 0 /* set but not used warning... */
254  {
255  result = false;
256  }
257  else
258  {
259  theWarpTransform->loadState(kwl, quadwarpPrefix.c_str());
260  theAffineTransform->loadState(kwl, affinePrefix.c_str());
261  }
262 #endif
263 
264  return ossimProjection::loadState(kwl, prefix);
265 }
266 
267 //*****************************************************************************
268 // METHOD: ossimWarpProjection::dup()
269 //*****************************************************************************
271 {
272  ossimKeywordlist kwl;
273  saveState(kwl);
274  return new ossimWarpProjection(kwl);
275 }
276 
277 //*****************************************************************************
278 // METHOD:
279 //*****************************************************************************
281 {
283  return theClientProjection->origin();
284  return ossimGpt(0.0, 0.0, 0.0);
285 }
286 
287 //*****************************************************************************
288 // METHOD:
289 //*****************************************************************************
291 {
294  return ossimDpt(ossim::nan(), ossim::nan());
295 }
296 
297 
299 {
300  if(warp)
301  {
302  theWarpTransform = warp;
303  }
304 }
305 
307 {
308  if(affine)
309  {
310  theAffineTransform = affine;
311  }
312 }
virtual ossimDpt getMetersPerPixel() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual void forward(const ossimDpt &input, ossimDpt &output) const =0
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual void lineSampleHeightToWorld(const ossimDpt &lineSampPt, const double &hgtEllipsoid, ossimGpt &worldPt) const
virtual std::ostream & print(std::ostream &out) const
Outputs theErrorStatus as an ossimErrorCode and an ossimString.
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
void makeNan()
Definition: ossimGpt.h:130
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
static const ossimErrorCode OSSIM_ERROR
virtual void setNewAffineTransform(ossim2dTo2dTransform *affine)
ossimRefPtr< ossim2dTo2dTransform > theWarpTransform
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimProjection * createProjection(const ossimFilename &filename, ossim_uint32 entryIdx) const
virtual void inverse(const ossimDpt &input, ossimDpt &output) const
virtual ossimDpt getMetersPerPixel() const =0
virtual void lineSampleHeightToWorld(const ossimDpt &lineSampPt, const double &heightAboveEllipsoid, ossimGpt &worldPt) const =0
RTTI_DEF1(ossimWarpProjection, "ossimWarpProjection", ossimProjection)
virtual void setNewWarpTransform(ossim2dTo2dTransform *warp)
virtual std::ostream & print(std::ostream &out) const
virtual ossimObject * dup() const
std::ostream & operator<<(std::ostream &os, const ossimWarpProjection &m)
static ossimProjectionFactoryRegistry * instance()
virtual ossimGpt origin() const
virtual ossimErrorCode getErrorStatus() const
virtual ossimGpt origin() const =0
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
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual void lineSampleToWorld(const ossimDpt &lineSampPt, ossimGpt &worldPt) const =0
ossimRefPtr< ossim2dTo2dTransform > theAffineTransform
virtual void worldToLineSample(const ossimGpt &worldPoint, ossimDpt &lineSampPt) const
ossimRefPtr< ossimProjection > theClientProjection
virtual void worldToLineSample(const ossimGpt &worldPoint, ossimDpt &lineSampPt) const =0
virtual void lineSampleToWorld(const ossimDpt &lineSampPt, ossimGpt &worldPt) 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