OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimElevRemapper.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: RP
6 //
7 // Description:
8 //
9 //
10 //*******************************************************************
11 // $Id$
15 #include <ossim/base/ossimTrace.h>
16 
18 static ossimTrace traceDebug("ossimElevRemapper::debug");
19 
20 const char ossimElevRemapper::REMAP_MODE_KW[] = "remap_mode";
21 
23 :m_replacementType(ReplacementType_ELLIPSOID)
24 {
25 }
26 
28 {
29  m_imageGeometry = 0;
30 }
31 
33 {
35  {
37  }
38 }
39 
41  ossim_uint32 resLevel)
42 {
43  if (traceDebug())
44  {
46  << "ossimElevRemapper::getTile entered..." << endl;
47  }
48 
50  if(!isSourceEnabled()||!result.valid())
51  {
52  return result.get();
53  }
55 
56  if(status == OSSIM_NULL)
57  {
58  return result.get();
59  }
60  // Call the appropriate load method.
61  switch (result->getScalarType())
62  {
63  case OSSIM_UCHAR:
64  {
65  elevRemap(ossim_uint8(0), result.get(), resLevel);
66  break;
67  }
68 
69  case OSSIM_UINT16:
70  case OSSIM_USHORT11:
71  case OSSIM_USHORT12:
72  case OSSIM_USHORT13:
73  case OSSIM_USHORT14:
74  case OSSIM_USHORT15:
75  {
76  elevRemap(ossim_uint16(0), result.get(), resLevel);
77  break;
78  }
79 
80  case OSSIM_SSHORT16:
81  {
82  elevRemap(ossim_sint16(0), result.get(), resLevel);
83  break;
84  }
85  case OSSIM_UINT32:
86  {
87  elevRemap(ossim_uint32(0), result.get(), resLevel);
88  break;
89  }
90  case OSSIM_SINT32:
91  {
92  elevRemap(ossim_sint32(0), result.get(), resLevel);
93  break;
94  }
95  case OSSIM_FLOAT32:
97  {
98  elevRemap(ossim_float32(0), result.get(), resLevel);
99  break; } case OSSIM_NORMALIZED_DOUBLE: case OSSIM_FLOAT64:
100  {
101  elevRemap(ossim_float64(0), result.get(), resLevel);
102  break;
103  }
104 
106  default:
107  {
109  << "ossimElevRemapper::getTile Unsupported scalar type!" << endl;
110  break;
111  }
112  }
113  if (traceDebug())
114  {
116  << "ossimElevRemapper::getTile leaving..." << endl;
117  }
118 
119  return result;
120 }
121 
122 template <class T>
123 void ossimElevRemapper::elevRemap(T /* dummy */,
124  ossimImageData* inputTile,
125  ossim_uint32 resLevel)
126 {
127  if (!inputTile) return;
128  ossimIrect rect = inputTile->getImageRectangle();
129  ossimIrect imageBounds = getBoundingRect(resLevel);
130  ossimIrect clipRect;
131  if(!rect.intersects(imageBounds))
132  {
133  return;
134  }
135  clipRect = rect.clipToRect(imageBounds);
136 
138  {
139  ossimGpt ul, ll, lr, ur;
140  ossim_float32 hul, hll, hlr, hur;
141  ossim_float32 height = 0.0, xpercent, ypercent, uppery, lowery;
142 
143  m_imageGeometry->rnToWorld(clipRect.ul(), resLevel, ul);
144  m_imageGeometry->rnToWorld(clipRect.ur(), resLevel, ur);
145  m_imageGeometry->rnToWorld(clipRect.ll(), resLevel, ll);
146  m_imageGeometry->rnToWorld(clipRect.lr(), resLevel, lr);
147 
148  //std::cout << "UL: " << clipRect.ul() << " RES: " << ossimString::toString(resLevel) << " ULGROUND: " << ul << "\n";
149 
154 
155 // std::cout << "HUL: " << ossimString::toString(hul) << " HUR: " << ossimString::toString(hur) << " HLR: " << ossimString::toString(hlr) << " HUR: " << ossimString::toString(hur) << "\n";
156 
157  if(!rect.completely_within(imageBounds))
158  {
159  ossim_uint32 bands = inputTile->getNumberOfBands();
160  ossimIpt origin = clipRect.ul() - rect.ul();
161  ossim_uint32 bandIdx = 0;
162  ossim_uint32 inputW = inputTile->getWidth();
163  ossim_uint32 originOffset = origin.y*inputW + origin.x;
164  ossim_uint32 w = clipRect.width();
165  ossim_uint32 h = clipRect.height();
166  ossim_uint32 x = 0;
167  ossim_uint32 y = 0;
168  ossim_float32 height = 0.0, xpercent, ypercent, uppery, lowery;
169  for(bandIdx = 0; bandIdx < bands; ++bandIdx)
170  {
171  T* bandPtr = static_cast<T*>(inputTile->getBuf(bandIdx)) + originOffset;
172  for(y = 0; y < h; ++y)
173  {
174  for(x = 0; x < w; ++x)
175  {
176  xpercent = x / clipRect.width();
177  ypercent = y / clipRect.height();
178  uppery = hul + xpercent * ( hur - hul);
179  lowery = hll + xpercent * ( hlr - hll);
180  height = uppery + ypercent * ( lowery - uppery );
181  if (m_replacementType==ReplacementType_GEOID) height*=-1.0;
182 
183  bandPtr[x] += height;
184  }
185  bandPtr += inputW;
186  }
187  }
188  }
189  else
190  {
191  ossim_uint32 bands = inputTile->getNumberOfBands();
192  ossim_uint32 bandIdx = 0;
193  ossim_uint32 size = inputTile->getWidth()*inputTile->getHeight();
194  ossim_float32 height = 0.0;
195  for(bandIdx = 0; bandIdx < bands; ++bandIdx)
196  {
197  T* bandPtr = static_cast<T*>(inputTile->getBuf(bandIdx));
198 
199  ossim_uint32 idx = 0;
200  for(idx = 0; idx < size;++idx)
201  {
202  ossim_uint32 y = idx / rect.width();
203  ossim_uint32 x = idx % rect.width();
204  xpercent = x / clipRect.width();
205  ypercent = y / clipRect.height();
206  uppery = hul + xpercent * ( hur - hul);
207  lowery = hll + xpercent * ( hlr - hll);
208  height = uppery + ypercent * ( lowery - uppery );
209  if (m_replacementType==ReplacementType_GEOID) height*=-1.0;
210 
211  (*bandPtr) += height;
212  ++bandPtr;
213  }
214  }
215  }
216  }
217 }
218 
220  const char* prefix)const
221 {
222  bool result = ossimImageSourceFilter::saveState(kwl, prefix);
223  ossimString remapMode = "";
224  switch(m_replacementType)
225  {
227  remapMode = "ellipsoid";
228  break;
230  remapMode = "geoid";
231  break;
232  default:
233  remapMode = "ellipsoid";
234  break;
235  }
236  kwl.add(prefix, REMAP_MODE_KW, remapMode.c_str());
237 
238  ossimString imagePrefix = ossimString(prefix)+"image_geometry.";
239 
240  if(m_imageGeometry.valid())
241  {
242  m_imageGeometry->saveState(kwl, imagePrefix.c_str());
243  }
244  //std::cout << kwl << " SAVESTATE\n";
245  return result;
246 }
247 
249  const char* prefix)
250 {
251  //std::cout << kwl << " LOADSTATE\n";
252  if (traceDebug())
253  {
255  << "ossimElevRemapper::loadState entered..." << endl;
256  }
257  bool result = ossimImageSourceFilter::loadState(kwl, prefix);
258 
259  const char* lookup;
260  lookup = kwl.find(prefix, REMAP_MODE_KW);
261  if(lookup)
262  {
263  ossimString mode = lookup;
264  mode.upcase();
265  if (mode == "ELLIPSOID")
266  {
268  }
269  else if (mode == "GEOID")
270  {
272  }
273  }
274 
275  ossimString imagePrefix = ossimString(prefix)+"image_geometry.";
276  if(kwl.numberOf(imagePrefix.c_str())>0)
277  {
279  m_imageGeometry->loadState(kwl, imagePrefix.c_str());
280  //setImageGeometry(m_igeometry.get());
281  }
282 
283  return result;
284 }
16 bit unsigned integer (15 bits used)
virtual ossim_uint32 getWidth() const
ossim_uint32 x
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
bool loadState(const ossimKeywordlist &kwl, const char *prefix)
Method to the load (recreate) the state of an object from a keyword list.
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
ossim_uint32 numberOf(const char *str) const
virtual ossim_uint32 getNumberOfBands() const
64 bit floating point
static const char REMAP_MODE_KW[]
16 bit unsigned integer
void elevRemap(T dummy, ossimImageData *inpuTile, ossim_uint32 resLevel)
Represents serializable keyword/value map.
bool saveState(ossimKeywordlist &kwl, const char *prefix) const
Method to save the state of an object to a keyword list.
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Attempts to initialize a transform and a projection given the KWL.
const char * find(const char *key) const
float ossim_float32
ossim_uint32 height() const
Definition: ossimIrect.h:487
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
16 bit unsigned integer (13 bits used)
32 bit floating point
bool intersects(const ossimIrect &rect) const
Definition: ossimIrect.cpp:183
unsigned short ossim_uint16
const ossimIpt & ll() const
Definition: ossimIrect.h:277
32 bit unsigned integer
bool completely_within(const ossimIrect &rect) const
Definition: ossimIrect.cpp:425
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
yy_size_t size
signed short ossim_sint16
32 bit signed integer
virtual void initialize()
ossimImageSource * theInputConnection
unsigned int ossim_uint32
32 bit normalized floating point
static ossimGeoidManager * instance()
Implements singelton pattern:
signed int ossim_sint32
virtual ossimIrect getImageRectangle() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
const ossimIpt & lr() const
Definition: ossimIrect.h:276
void rnToWorld(const ossimDpt &rnPt, ossim_uint32 resolutionLevel, ossimGpt &wpt) const
rnToWorld is a utility method that takes a rn resolution image point and maps it to the world point...
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimIrect clipToRect(const ossimIrect &rect) const
Definition: ossimIrect.cpp:501
ReplacementType m_replacementType
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
const ossimIpt & ur() const
Definition: ossimIrect.h:275
ossimRefPtr< ossimImageGeometry > m_imageGeometry
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
return status
virtual ossimScalarType getScalarType() const
64 bit normalized floating point
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
16 bit unsigned integer (11 bits used)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossim_int32 y
Definition: ossimIpt.h:142
virtual const void * getBuf() const
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
Saves the transform (if any) and projection (if any) states to the KWL.
ossim_int32 x
Definition: ossimIpt.h:141
ossimDataObjectStatus
Definitions for data object status.
virtual double offsetFromEllipsoid(const ossimGpt &gpt)
16 bit signed integer
unsigned char ossim_uint8
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tile_rect, ossim_uint32 resLevel=0)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
RTTI_DEF1(ossimElevRemapper, "ossimElevRemapper", ossimImageSourceFilter)
8 bit unsigned iteger
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
16 bit unsigned integer (12 bits used)