OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimMonoGridRemapEngine.cpp
Go to the documentation of this file.
1 //*****************************************************************************
2 // FILE: ossimMonoGridRemapEngine.cc
3 //
4 // Copyright (C) 2001 ImageLinks, Inc.
5 //
6 // License: LGPL
7 //
8 // See LICENSE.txt file in the top level directory for more details.
9 //
10 // See the GPL in the COPYING.GPL file for more details.
11 //
12 // AUTHOR: Oscar Kramer
13 //
14 // DESCRIPTION: Contains implementation of class
15 //
16 // LIMITATIONS: None.
17 //
18 //*****************************************************************************
19 // $Id: ossimMonoGridRemapEngine.cpp 15833 2009-10-29 01:41:53Z eshirschorn $
20 
22 
23 RTTI_DEF1(ossimMonoGridRemapEngine, "ossimMonoGridRemapEngine",
25 
28 #include <ossim/base/ossimDpt.h>
31 
32 //***
33 // Define Trace flags for use within this file:
34 //***
35 #include <ossim/base/ossimTrace.h>
36 static ossimTrace traceExec ("ossimMonoGridRemapEngine:exec");
37 static ossimTrace traceDebug ("ossimMonoGridRemapEngine:debug");
38 static bool TRACE_FLAG = true;
39 
40 //*****************************************************************************
41 // METHOD: ossimMonoGridRemapEngine::dup
42 //
43 //*****************************************************************************
45 {
46  return new ossimMonoGridRemapEngine;
47 }
48 
49 //*****************************************************************************
50 // METHOD: ossimMonoGridRemapEngine::remapTile
51 //
52 //*****************************************************************************
54  ossimGridRemapSource* remapper,
56 {
57  static const char MODULE[] = "ossimMonoGridRemapEngine::remapTile";
58  if (traceExec()) CLOG << "entering..." << endl;
59 
60  //***
61  // Fetch tile size and NULL pixel value:
62  //***
63  int width = tile->getWidth();
64  int height = tile->getHeight();
65  int offset = 0;
66  double null;
67 
68  //***
69  // Determine null pixel values so that we can recognize a null coming in and
70  // not remap it:
71  //***
72  null = tile->getNullPix(0);
73  ossimDblGrid& grid = *(remapper->getGrid(0));
74 
75  //***
76  // Remap according to pixel type:
77  //***
78  switch(tile->getScalarType())
79  {
80  case OSSIM_UCHAR:
81  {
82  ossim_uint8* tile_buf = (ossim_uint8*)tile->getBuf(0);
83  short pixel;
84 
85  for (double line=origin.line; line<origin.line+height; line+=1.0)
86  {
87  for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
88  {
89  //***
90  // Scan for null pixel before adding remap delta:
91  //***
92  if (tile_buf[offset] != (ossim_uint8) null)
93  {
94  //***
95  // Remap MONO pixel with spatially variant bias value:
96  //***
97  pixel = tile_buf[offset] + (short) grid(samp,line);
98 
99  //***
100  // Clamp:
101  //***
102  if (pixel<0) tile_buf[offset] = 0;
103  else if (pixel>255) tile_buf[offset] = 255;
104  else tile_buf[offset] = pixel;
105 
106  //***
107  // Avoid NULLS:
108  //***
109  if (tile_buf[offset] == (ossim_uint8) null) tile_buf[offset]++;
110  }
111 
112  offset++;
113  }
114  }
115  break;
116  }
117 
118  case OSSIM_USHORT11:
119  {
120  ossim_uint16* tile_buf = (ossim_uint16*)tile->getBuf(0);
121  int pixel;
122 
123  for (double line=origin.line; line<origin.line+height; line+=1.0)
124  {
125  for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
126  {
127  //***
128  // Scan for null pixel before adding remap delta:
129  //***
130  if (tile_buf[offset] != (ossim_uint16) null)
131  {
132  //***
133  // Remap MONO pixel with spatially variant bias value:
134  //***
135  pixel = tile_buf[offset] + (int) grid(samp,line);
136 
137  //***
138  // Clamp:
139  //***
140  if (pixel<0) tile_buf[offset] = 0;
141  else if (pixel>2047) tile_buf[offset] = 2047;
142  else tile_buf[offset] = pixel;
143 
144  //***
145  // Avoid NULLS:
146  //***
147  if (tile_buf[offset] == (ossim_uint16) null) tile_buf[offset]++;
148  }
149 
150  offset++;
151  }
152  }
153  break;
154  }
155 
156  case OSSIM_USHORT12:
157  {
158  ossim_uint16* tile_buf = (ossim_uint16*)tile->getBuf(0);
159  int pixel;
160 
161  for (double line=origin.line; line<origin.line+height; line+=1.0)
162  {
163  for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
164  {
165  //***
166  // Scan for null pixel before adding remap delta:
167  //***
168  if (tile_buf[offset] != (ossim_uint16) null)
169  {
170  //***
171  // Remap MONO pixel with spatially variant bias value:
172  //***
173  pixel = tile_buf[offset] + (int) grid(samp,line);
174 
175  //***
176  // Clamp:
177  //***
178  if (pixel<0) tile_buf[offset] = 0;
179  else if (pixel>4095) tile_buf[offset] = 4095;
180  else tile_buf[offset] = pixel;
181 
182  //***
183  // Avoid NULLS:
184  //***
185  if (tile_buf[offset] == (ossim_uint16) null) tile_buf[offset]++;
186  }
187 
188  offset++;
189  }
190  }
191  break;
192  }
193 
194  case OSSIM_USHORT13:
195  {
196  ossim_uint16* tile_buf = (ossim_uint16*)tile->getBuf(0);
197  int pixel;
198 
199  for (double line=origin.line; line<origin.line+height; line+=1.0)
200  {
201  for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
202  {
203  //***
204  // Scan for null pixel before adding remap delta:
205  //***
206  if (tile_buf[offset] != (ossim_uint16) null)
207  {
208  //***
209  // Remap MONO pixel with spatially variant bias value:
210  //***
211  pixel = tile_buf[offset] + (int) grid(samp,line);
212 
213  //***
214  // Clamp:
215  //***
216  if (pixel<0) tile_buf[offset] = 0;
217  else if (pixel>8191) tile_buf[offset] = 8191;
218  else tile_buf[offset] = pixel;
219 
220  //***
221  // Avoid NULLS:
222  //***
223  if (tile_buf[offset] == (ossim_uint16) null) tile_buf[offset]++;
224  }
225 
226  offset++;
227  }
228  }
229  break;
230  }
231 
232  case OSSIM_USHORT14:
233  {
234  ossim_uint16* tile_buf = (ossim_uint16*)tile->getBuf(0);
235  int pixel;
236 
237  for (double line=origin.line; line<origin.line+height; line+=1.0)
238  {
239  for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
240  {
241  //***
242  // Scan for null pixel before adding remap delta:
243  //***
244  if (tile_buf[offset] != (ossim_uint16) null)
245  {
246  //***
247  // Remap MONO pixel with spatially variant bias value:
248  //***
249  pixel = tile_buf[offset] + (int) grid(samp,line);
250 
251  //***
252  // Clamp:
253  //***
254  if (pixel<0) tile_buf[offset] = 0;
255  else if (pixel>16383) tile_buf[offset] = 16383;
256  else tile_buf[offset] = pixel;
257 
258  //***
259  // Avoid NULLS:
260  //***
261  if (tile_buf[offset] == (ossim_uint16) null) tile_buf[offset]++;
262  }
263 
264  offset++;
265  }
266  }
267  break;
268  }
269 
270  case OSSIM_USHORT15:
271  {
272  ossim_uint16* tile_buf = (ossim_uint16*)tile->getBuf(0);
273  int pixel;
274 
275  for (double line=origin.line; line<origin.line+height; line+=1.0)
276  {
277  for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
278  {
279  //***
280  // Scan for null pixel before adding remap delta:
281  //***
282  if (tile_buf[offset] != (ossim_uint16) null)
283  {
284  //***
285  // Remap MONO pixel with spatially variant bias value:
286  //***
287  pixel = tile_buf[offset] + (int) grid(samp,line);
288 
289  //***
290  // Clamp:
291  //***
292  if (pixel<0) tile_buf[offset] = 0;
293  else if (pixel>32767) tile_buf[offset] = 32767;
294  else tile_buf[offset] = pixel;
295 
296  //***
297  // Avoid NULLS:
298  //***
299  if (tile_buf[offset] == (ossim_uint16) null) tile_buf[offset]++;
300  }
301 
302  offset++;
303  }
304  }
305  break;
306  }
307 
308  case OSSIM_USHORT16:
309  {
310  ossim_uint16* tile_buf = (ossim_uint16*)tile->getBuf(0);
311  int pixel;
312 
313  for (double line=origin.line; line<origin.line+height; line+=1.0)
314  {
315  for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
316  {
317  //***
318  // Scan for null pixel before adding remap delta:
319  //***
320  if (tile_buf[offset] != (ossim_uint16) null)
321  {
322  //***
323  // Remap MONO pixel with spatially variant bias value:
324  //***
325  pixel = tile_buf[offset] + (int) grid(samp,line);
326 
327  //***
328  // Clamp:
329  //***
330  if (pixel<0) tile_buf[offset] = 0;
331  else if (pixel>65535) tile_buf[offset] = 65535;
332  else tile_buf[offset] = pixel;
333 
334  //***
335  // Avoid NULLS:
336  //***
337  if (tile_buf[offset] == (ossim_uint16) null) tile_buf[offset]++;
338  }
339 
340  offset++;
341  }
342  }
343  break;
344  }
345 
346  case OSSIM_SSHORT16:
347  {
348  short* tile_buf = (short*)tile->getBuf(0);
349  int pixel;
350 
351  for (double line=origin.line; line<origin.line+height; line+=1.0)
352  {
353  for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
354  {
355  //***
356  // Scan for null pixel before adding remap delta:
357  //***
358  if (tile_buf[offset] != (short) null)
359  {
360  //***
361  // Remap MONO pixel with spatially variant bias value:
362  //***
363  pixel = tile_buf[offset] + (short) grid(samp,line);
364 
365  //***
366  // Clamp:
367  //***
368  if (pixel<-32766) tile_buf[offset] = -32766;
369  else if (pixel> 32767) tile_buf[offset] = 32767;
370  else tile_buf[offset] = pixel;
371 
372  //***
373  // Avoid NULLS:
374  //***
375  if (tile_buf[offset] == (short) null) tile_buf[offset]++;
376  }
377 
378  offset++;
379  }
380  }
381  break;
382  }
383  default:
384  {
385  ossimNotify(ossimNotifyLevel_WARN) << "WARNING ossimMonoGridRemapEngine::remapTile: Scalar type not handled" << std::endl;
386  break;
387  }
388 
389  } // end switch statement
390 
391  if (traceExec()) CLOG << "returning..." << endl;
392  return;
393 };
394 
395 //*****************************************************************************
396 // METHOD: ossimMonoGridRemapEngine::assignRemapValues
397 //
398 // This engine defines the target value as an MONO vector of doubles, computed
399 // as the mean of all contributor MONO values.
400 //
401 //*****************************************************************************
403  vector<ossimAtbPointSource*>& sources_list)
404 {
405  static const char MODULE[] = "ossimMonoGridRemapEngine::assignRemapValues";
406  if (traceExec()) CLOG << "entering..." << endl;
407 
408  int i; // index to individual sources
409 
410  //***
411  // Declare a 2D array that will contain all of the contributing sources'
412  // MONO mean values. Also declare the accumulator target vector.
413  //***
414  int num_contributors = (int)sources_list.size();
415  double** contributor_pixel = new double* [num_contributors];
416  for (i=0; i<num_contributors; i++)
417  contributor_pixel[i] = new double[1];
418  double target_pixel = 0.0;
419 
420  //***
421  // Now loop over each remaining contributor and sum in its contribution:
422  //***
423  vector<ossimAtbPointSource*>::iterator source;
424  i = 0;
425  for(source=sources_list.begin();
426  source!=sources_list.end();
427  source++)
428  {
429  (*source)->getSourceValue(contributor_pixel[i]);
430  target_pixel += contributor_pixel[i][0]/(double)num_contributors;
431  ++i;
432  }
433 
434  //***
435  // The target pixel has been established. Now need to compute the actual
436  // remap quantities that will be written to the appropriate remap grids:
437  //***
438  i = 0;
439  for(source=sources_list.begin();
440  source!=sources_list.end();
441  source++)
442  {
443  computeRemapNode(*source, contributor_pixel[i], &target_pixel);
444  ++i;
445  }
446 
447  // ***
448  // Delete locally allocated memory:
449  // ***
450  for (i=0; i<num_contributors; ++i)
451  {
452  delete [] contributor_pixel[i];
453  }
454  delete [] contributor_pixel;
455 
456  if (traceExec()) CLOG << "returning..." << endl;
457  return;
458 }
459 
460 //*****************************************************************************
461 // METHOD: ossimMonoGridRemapEngine::computeSourceValue
462 //
463 //*****************************************************************************
465  ossimRefPtr<ossimImageData>& source, void* result)
466 {
467  static const char MODULE[]="ossimMonoGridRemapEngine::computeSourceValue";
468  if (traceExec()) CLOG << "entering..." << endl;
469 
470  //***
471  // This engine defines "value" as the MONO vector corresponding to the mean
472  // MONO pixel value of the source data:
473  //***
474  ((double*)result)[0] = source->computeAverageBandValue(0);
475 
476  if (traceExec()) CLOG << "returning..." << endl;
477  return;
478 }
479 
480 //*****************************************************************************
481 // METHOD: ossimMonoGridRemapEngine::computeRemapNode
482 //
483 // This engine defines the remap value as the difference between the target
484 // MONO vector and the individual point source's value vector.
485 //
486 //*****************************************************************************
488  void* source_value,
489  void* target_value)
490 {
491  static const char MODULE[] = "ossimMonoGridRemapEngine::computeRemapNode";
492  if (traceExec()) CLOG << "entering..." << endl;
493 
494  //***
495  // Compute the remap grid node value specific to this MONO implementation:
496  //***
497  double node;
498  node = ((double*)target_value)[0] - ((double*)source_value)[0];
499 
500  //***
501  // Fetch a pointer to the remapper feeding this point source in order to
502  // pass it the node value:
503  //***
504  ossimGridRemapSource* remapper = ps->getRemapSource();
505  remapper->setGridNode(ps->getViewPoint(), &node);
506 
507  if (traceDebug() || TRACE_FLAG)
508  {
509  CLOG << "DEBUG -- "
510  << "\n\t ps->getViewPoint() = "<<ps->getViewPoint()
511  << "\n\t source_value = "<<((double*)source_value)[0]
512  << "\n\t target_value = "<<((double*)target_value)[0]
513  << "\n\t node = "<<node
514  << "\n\t remapper at "<<remapper<<endl;
515  }
516 
517  if (traceExec()) CLOG << "returning..." << endl;
518  return;
519 }
520 
16 bit unsigned integer (15 bits used)
virtual ossim_uint32 getWidth() const
virtual void remapTile(const ossimDpt &origin_point, ossimGridRemapSource *remapper, ossimRefPtr< ossimImageData > &tile)
#define CLOG
Definition: ossimTrace.h:23
double samp
Definition: ossimDpt.h:164
virtual void assignRemapValues(std::vector< ossimAtbPointSource *> &sources)
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
16 bit unsigned integer (13 bits used)
unsigned short ossim_uint16
virtual ossimObject * dup() const
const ossimDpt & getViewPoint() const
double line
Definition: ossimDpt.h:165
ossimGridRemapSource * getRemapSource()
virtual void computeRemapNode(ossimAtbPointSource *point_source, void *source_value, void *target_value)
virtual const ossim_float64 * getNullPix() const
void setGridNode(const ossimDpt &view_pt, const double *value)
ossimDblGrid * getGrid(unsigned int index)
virtual ossim_float64 computeAverageBandValue(ossim_uint32 bandNumber=0) const
This will compute the average value for the band.
virtual ossimScalarType getScalarType() const
16 bit unsigned integer (11 bits used)
virtual const void * getBuf() const
virtual void computeSourceValue(ossimRefPtr< ossimImageData > &source, void *result)
RTTI_DEF1(ossimMonoGridRemapEngine, "ossimMonoGridRemapEngine", ossimGridRemapEngine)
16 bit unsigned iteger
16 bit signed integer
unsigned char ossim_uint8
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
8 bit unsigned iteger
16 bit unsigned integer (12 bits used)