OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimAtCorrGridRemapper.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts <gpotts@imagelinks.com>
6 //
7 // Description:
8 //*******************************************************************
9 // $Id: ossimAtCorrGridRemapper.cpp 21631 2012-09-06 18:10:55Z dburken $
12 
13 RTTI_DEF1(ossimAtCorrGridRemapper, "ossimAtCorrGridRemapper", ossimAtCorrRemapper);
14 
16  ossimImageSource* inputSource,
17  const ossimString& sensorType)
18  :ossimAtCorrRemapper(owner, inputSource, sensorType)
19 {
21 }
22 
24 {
25 }
26 
28  int band,
29  double& a,
30  double& b,
31  double& c)const
32 {
34  {
35  double x = (((double)(pt.x - theUlGridBound.x))/theGridBounds.width())*(theGridSize.x-1);
36  double y = (((double)(pt.y - theUlGridBound.y))/theGridBounds.height())*(theGridSize.y-1);
37 
38  int xidx = (int)x;
39  int yidx = (int)y;
40 
41  double xt = x - xidx;
42  double yt = y - yidx;
43 
44  double va00 = theAGrid[band][yidx][xidx];
45  double va01 = theAGrid[band][yidx][xidx+1];
46  double va11 = theAGrid[band][yidx+1][xidx+1];
47  double va10 = theAGrid[band][yidx+1][xidx];
48  double vb00 = theBGrid[band][yidx][xidx];
49  double vb01 = theBGrid[band][yidx][xidx+1];
50  double vb11 = theBGrid[band][yidx+1][xidx+1];
51  double vb10 = theBGrid[band][yidx+1][xidx];
52  double vc00 = theCGrid[band][yidx][xidx];
53  double vc01 = theCGrid[band][yidx][xidx+1];
54  double vc11 = theCGrid[band][yidx+1][xidx+1];
55  double vc10 = theCGrid[band][yidx+1][xidx];
56 
57  double vaInterpH1 = va00 + (va01-va00)*xt;
58  double vaInterpH2 = va10 + (va11-va10)*xt;
59  double vbInterpH1 = vb00 + (vb01-vb00)*xt;
60  double vbInterpH2 = vb10 + (vb11-vb10)*xt;
61  double vcInterpH1 = vc00 + (vc01-vc00)*xt;
62  double vcInterpH2 = vc10 + (vc11-vc10)*xt;
63 
64  a = vaInterpH1 + (vaInterpH2-vaInterpH1)*yt;
65  b = vbInterpH1 + (vbInterpH2-vbInterpH1)*yt;
66  c = vcInterpH1 + (vcInterpH2-vcInterpH1)*yt;
67  }
68  else
69  {
71  band,
72  a,
73  b,
74  c);
75  }
76 }
77 
79 {
81 
83  {
86  }
87  else
88  {
90  }
91 
92  if(!theAGrid.size()||
93  !theBGrid.size()||
94  !theCGrid.size())
95  {
97  }
99 }
100 
101 void ossimAtCorrGridRemapper::setGridSize(ossim_uint32 numberOfBands, const ossimIpt& gridSize)
102 {
103 
104  if((theGridSize!=gridSize)||(numberOfBands != theAGrid.size()))
105  {
106  theAGrid.resize(numberOfBands);
107  theBGrid.resize(numberOfBands);
108  theCGrid.resize(numberOfBands);
109 
110  for(ossim_uint32 b = 0; b < numberOfBands;++b)
111  {
112  theAGrid[b].resize(gridSize.y);
113  theBGrid[b].resize(gridSize.y);
114  theCGrid[b].resize(gridSize.y);
115  for(int r = 0; r < gridSize.y; ++r)
116  {
117  theAGrid[b][r].resize(gridSize.x);
118  theBGrid[b][r].resize(gridSize.x);
119  theCGrid[b][r].resize(gridSize.x);
120  }
121 
122  }
123  theGridSize = gridSize;
124  }
125 
126 }
127 
128 
130 {
131  ossim_uint32 idxBand;
132  vector<double> xaAverage(theAGrid.size());
133  vector<double> xcAverage(theBGrid.size());
134  vector<double> xbAverage(theCGrid.size());
135  // double aAverage=0.0, bAverage=0.0, cAverag=0.0;
136 
137 
138  if((theAGrid.size() != theBGrid.size())||
139  (theAGrid.size() != theCGrid.size())||
140  (theAGrid.size() == 0))
141  {
142  return;
143  }
144 
145  for(idxBand = 0; idxBand < theAGrid.size(); ++idxBand)
146  {
147  ossim_uint32 idxRow = 0;
148  xaAverage[idxBand] = 0.0;
149  xbAverage[idxBand] = 0.0;
150  xcAverage[idxBand] = 0.0;
151  for(idxRow = 0; idxRow < theAGrid[idxBand].size();++idxRow)
152  {
153  ossim_uint32 idxCol = 0;
154  for(idxCol = 0; idxCol < theAGrid[idxBand][idxRow].size();++idxCol)
155  {
156  xaAverage[idxBand] += theAGrid[idxBand][idxRow][idxCol];
157 
158  }
159  }
160  for(idxRow = 0; idxRow < theBGrid[idxBand].size();++idxRow)
161  {
162  ossim_uint32 idxCol = 0;
163  for(idxCol = 0; idxCol < theBGrid[idxBand][idxRow].size();++idxCol)
164  {
165  xbAverage[idxBand] += theBGrid[idxBand][idxRow][idxCol];
166  }
167  }
168  for(idxRow = 0; idxRow < theCGrid[idxBand].size();++idxRow)
169  {
170  ossim_uint32 idxCol = 0;
171  for(idxCol = 0; idxCol < theCGrid[idxBand][idxRow].size();++idxCol)
172  {
173  xaAverage[idxBand] += theCGrid[idxBand][idxRow][idxCol];
174  xbAverage[idxBand] += theCGrid[idxBand][idxRow][idxCol];
175  xcAverage[idxBand] += theCGrid[idxBand][idxRow][idxCol];
176 
177  }
178  }
179  }
180 
181  for(idxBand = 0; idxBand < theAGrid.size(); ++idxBand)
182  {
183  xaAverage[idxBand] /=(double)(theGridSize.x*theGridSize.y);
184  xbAverage[idxBand] /=(double)(theGridSize.x*theGridSize.y);
185  xcAverage[idxBand] /=(double)(theGridSize.x*theGridSize.y);
186  }
187 
188  theXaArray = xaAverage;
189  theXbArray = xbAverage;
190  theXcArray = xcAverage;
191 }
192 
198  const char* prefix)
199 {
200  const char* MODULE = "ossimAtCorrGridRemapper::loadState";
201  theAGrid.clear();
202  theBGrid.clear();
203  theCGrid.clear();
204 
206  {
207  cerr << MODULE << " ERROR:"
208  << "Not initialized..." << endl;
209  return false;
210  }
213 
214  theAGrid.resize(bands);
215  theBGrid.resize(bands);
216  theCGrid.resize(bands);
217 
218 
219  const char* rowsLookup = NULL;
220  const char* colsLookup = NULL;
221  for(ossim_uint32 band = 0; band < bands; ++band)
222  {
223  ossim_uint32 r = 0;
224  ossim_uint32 c = 0;
225  ossimString gridString = "band";
226  gridString += ossimString::toString(band+1);
227  gridString += ".grid";
228 
229  rowsLookup = kwl.find(prefix,
230  gridString + ".rows");
231 
232  colsLookup = kwl.find(prefix,
233  gridString + ".cols");
234  if(rowsLookup&&colsLookup)
235  {
236  cout << "both keywords needed: " << (gridString+".rows") << endl
237  << (gridString+".cols") << endl;
238 
240  return false;
241  }
242 
243  ossim_uint32 rows = ossimString(rowsLookup).toULong();
244  ossim_uint32 cols = ossimString(colsLookup).toULong();
245 
246  if(cols&&rows)
247  {
248  cout << "value for cols and rows keyword have 0" << endl;
250  return false;
251  }
252 
253  theAGrid[band].resize(rows);
254  theBGrid[band].resize(rows);
255  theCGrid[band].resize(rows);
256  for(r = 0; r < rows; ++r)
257  {
258  theAGrid[band][r].resize(cols);
259  theBGrid[band][r].resize(cols);
260  theCGrid[band][r].resize(cols);
261  }
262 
263  ossim_uint32 idx = 1;
264  const char* aLookup;
265  const char* bLookup;
266  const char* cLookup;
267  for(r = 0; r < rows; ++r)
268  {
269  for(c = 0; c < cols; ++c)
270  {
271  aLookup = kwl.find(prefix, gridString+".a"+ossimString::toString(idx));
272  bLookup = kwl.find(prefix, gridString+".b"+ossimString::toString(idx));
273  cLookup = kwl.find(prefix, gridString+".c"+ossimString::toString(idx));
274  theAGrid[band][r][c] = ossimString(aLookup).toDouble();
275  theBGrid[band][r][c] = ossimString(bLookup).toDouble();
276  theCGrid[band][r][c] = ossimString(cLookup).toDouble();
277 
278  ++idx;
279  }
280  }
281 
282  theGridSize.x = cols;
283  theGridSize.y = rows;
285  }
286 
287  return true;
288 }
289 
291  const char* prefix)const
292 {
293 
294  ossim_uint32 bands = (ossim_uint32)theAGrid.size();
295 
296  for(ossim_uint32 band = 0; band < bands; ++band)
297  {
298  int idx = 1;
299  int r = 0;
300  int c = 0;
301  ossimString gridString = "band";
302  gridString += ossimString::toString(band+1);
303  gridString += ".grid";
304 
305  ossim_uint32 rows = (ossim_uint32)theAGrid[band].size();
306  kwl.add(prefix,
307  gridString+".rows",
308  rows,
309  true);
310  ossim_uint32 cols = (ossim_uint32)theAGrid[band][0].size();
311  kwl.add(prefix,
312  gridString+".cols",
313  cols,
314  true);
315  for(r = 0; r < theGridSize.y; ++r)
316  {
317  for(c = 0; c < theGridSize.x; ++c)
318  {
319  kwl.add(prefix,
320  gridString+".a"+ossimString::toString(idx),
321  theAGrid[band][r][c],
322  true);
323  kwl.add(prefix,
324  gridString+".b"+ossimString::toString(idx),
325  theAGrid[band][r][c],
326  true);
327  kwl.add(prefix,
328  gridString+".c"+ossimString::toString(idx),
329  theAGrid[band][r][c],
330  true);
331 
332  ++idx;
333  }
334  }
335  }
336 
337  return ossimAtCorrRemapper::saveState(kwl, prefix);
338 }
ossim_uint32 x
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual ossim_uint32 getNumberOfBands() const
vector< double > theXcArray
std::vector< std::vector< std::vector< double > > > theCGrid
void setGridSize(ossim_uint32 numberOfBands, const ossimIpt &gridSize)
Represents serializable keyword/value map.
ossim_uint32 y
const char * find(const char *key) const
double y
Definition: ossimDpt.h:165
ossim_uint32 height() const
Definition: ossimIrect.h:487
static ossimString toString(bool aValue)
Numeric to string methods.
RTTI_DEF1(ossimAtCorrGridRemapper, "ossimAtCorrGridRemapper", ossimAtCorrRemapper)
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossimAtCorrGridRemapper(ossimObject *owner=NULL, ossimImageSource *inputSource=NULL, const ossimString &sensorType="")
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
std::vector< std::vector< std::vector< double > > > theBGrid
yy_size_t size
ossimImageSource * theInputConnection
unsigned int ossim_uint32
virtual void interpolate(const ossimDpt &pt, int band, double &a, double &b, double &c) const
double toDouble() const
unsigned long toULong() const
vector< double > theXaArray
ossim_uint32 width() const
Definition: ossimIrect.h:500
vector< double > theXbArray
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossimRefPtr< ossimImageData > theTile
ossim_int32 y
Definition: ossimIpt.h:142
void makeNan()
Definition: ossimIrect.h:329
double x
Definition: ossimDpt.h:164
ossim_int32 x
Definition: ossimIpt.h:141
std::vector< std::vector< std::vector< double > > > theAGrid
virtual void interpolate(const ossimDpt &pt, int band, double &a, double &b, double &c) const
bool pointWithin(const ossimIpt &pt) const
Definition: ossimIrect.h:729