OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRgbGridRemapEngine.cpp
Go to the documentation of this file.
1 //*****************************************************************************
2 // FILE: ossimRgbGridRemapEngine.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 // AUTHOR: Oscar Kramer
11 //
12 // DESCRIPTION: Contains implementation of class
13 //
14 // LIMITATIONS: None.
15 //
16 //*****************************************************************************
17 // $Id: ossimRgbGridRemapEngine.cpp 15833 2009-10-29 01:41:53Z eshirschorn $
18 
20 
21 RTTI_DEF1(ossimRgbGridRemapEngine, "ossimRgbGridRemapEngine",
23 
26 #include <ossim/base/ossimDpt.h>
29 
30 //***
31 // Define Trace flags for use within this file:
32 //***
33 #include <ossim/base/ossimTrace.h>
34 static ossimTrace traceExec ("ossimRgbGridRemapEngine:exec");
35 static ossimTrace traceDebug ("ossimRgbGridRemapEngine:debug");
36 
37 //*****************************************************************************
38 // METHOD: ossimRgbGridRemapEngine::dup
39 //
40 //*****************************************************************************
42 {
43  return new ossimRgbGridRemapEngine;
44 }
45 
46 //*****************************************************************************
47 // METHOD: ossimRgbGridRemapEngine::remapTile
48 //
49 //*****************************************************************************
51  ossimGridRemapSource* remapper,
53 {
54  static const char MODULE[] = "ossimRgbGridRemapEngine::remapTile";
55  if (traceExec()) CLOG << "entering..." << endl;
56 
57  //***
58  // Fetch tile size and NULL pixel value:
59  //***
60  int width = tile->getWidth();
61  int height = tile->getHeight();
62  int offset = 0;
63  double null[3];
64 
65  //***
66  // Determine null pixel values so that we can recognize a null coming in and
67  // not remap it:
68  //***
69  null[0] = tile->getNullPix(0);
70  null[1] = tile->getNullPix(1);
71  null[2] = tile->getNullPix(2);
72 
73  ossimDblGrid& gridR = *(remapper->getGrid(0));
74  ossimDblGrid& gridG = *(remapper->getGrid(1));
75  ossimDblGrid& gridB = *(remapper->getGrid(2));
76 
77  //***
78  // Remap according to pixel type:
79  //***
80  switch(tile->getScalarType())
81  {
82  case OSSIM_UCHAR:
83  {
84  ossim_uint8* red_buf = (ossim_uint8*)tile->getBuf(0);
85  ossim_uint8* grn_buf = (ossim_uint8*)tile->getBuf(1);
86  ossim_uint8* blu_buf = (ossim_uint8*)tile->getBuf(2);
87  short pixel_buffer[3];
88 
89  for (double line=origin.line; line<origin.line+height; line+=1.0)
90  {
91  for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
92  {
93  //***
94  // Scan for null pixel before adding remap delta:
95  //***
96  if ((red_buf[offset] != (ossim_uint8) null[0]) &&
97  (grn_buf[offset] != (ossim_uint8) null[1]) &&
98  (blu_buf[offset] != (ossim_uint8) null[2]))
99  {
100  //***
101  // Remap RGB pixel with spatially variant bias value:
102  //***
103  pixel_buffer[0] = red_buf[offset] + (short) gridR(samp,line);
104  pixel_buffer[1] = grn_buf[offset] + (short) gridG(samp,line);
105  pixel_buffer[2] = blu_buf[offset] + (short) gridB(samp,line);
106 
107  //***
108  // Clamp:
109  //***
110  if (pixel_buffer[0]<0) red_buf[offset] = 0;
111  else if (pixel_buffer[0]>255) red_buf[offset] = 255;
112  else red_buf[offset] = pixel_buffer[0];
113 
114 
115  if (pixel_buffer[1]<0) grn_buf[offset] = 0;
116  else if (pixel_buffer[1]>255) grn_buf[offset] = 255;
117  else grn_buf[offset] = pixel_buffer[1];
118 
119 
120  if (pixel_buffer[2]<0) blu_buf[offset] = 0;
121  else if (pixel_buffer[2]>255) blu_buf[offset] = 255;
122  else blu_buf[offset] = pixel_buffer[2];
123 
124  //***
125  // Avoid NULLS:
126  //***
127  if (red_buf[offset] == (ossim_uint8) null[0]) red_buf[offset]++;
128  if (grn_buf[offset] == (ossim_uint8) null[1]) grn_buf[offset]++;
129  if (blu_buf[offset] == (ossim_uint8) null[2]) blu_buf[offset]++;
130  }
131 
132  offset++;
133  }
134  }
135  break;
136  }
137 
138  default:
139  {
140  ossimNotify(ossimNotifyLevel_WARN) << "WARNING ossimRgbGridRemapEngine::remapTile: Scalar type not handled" << std::endl;
141  break;
142  }
143 
144  } // end switch statement
145 
146  if (traceExec()) CLOG << "returning..." << endl;
147  return;
148 };
149 
150 //*****************************************************************************
151 // METHOD: ossimRgbGridRemapEngine::assignRemapValues
152 //
153 // This engine defines the target value as an RGB vector of doubles, computed
154 // as the mean of all contributor RGB values.
155 //
156 //*****************************************************************************
158  vector<ossimAtbPointSource*>& sources_list)
159 {
160  static const char MODULE[] = "ossimRgbGridRemapEngine::assignRemapValues";
161  if (traceExec()) CLOG << "entering..." << endl;
162 
163  int i; // index to individual sources
164 
165  //***
166  // Declare a 2D array that will contain all of the contributing sources'
167  // RGB mean values. Also declare the accumulator target vector.
168  //***
169  int num_contributors = (int)sources_list.size();
170  double** contributor_pixel = new double* [num_contributors];
171  for (i=0; i<num_contributors; i++)
172  contributor_pixel[i] = new double[3];
173  double target_pixel[3] = {0.0, 0.0, 0.0};
174 
175  //***
176  // Now loop over each remaining contributor and sum in its contribution:
177  //***
178  vector<ossimAtbPointSource*>::iterator source;
179  i = 0;
180  for(source=sources_list.begin();
181  source!=sources_list.end();
182  source++)
183  {
184  (*source)->getSourceValue(contributor_pixel[i]);
185 
186  target_pixel[0] += contributor_pixel[i][0]/(double)num_contributors;
187  target_pixel[1] += contributor_pixel[i][1]/(double)num_contributors;
188  target_pixel[2] += contributor_pixel[i][2]/(double)num_contributors;
189 
190  i++;
191  }
192 
193  //***
194  // The target pixel has been established. Now need to compute the actual
195  // remap quantities that will be written to the appropriate remap grids:
196  //***
197  i = 0;
198  for(source=sources_list.begin();
199  source!=sources_list.end();
200  source++)
201  {
202  computeRemapNode(*source, contributor_pixel[i], target_pixel);
203  i++;
204  }
205 
206  //***
207  // Delete locally allocated memory:
208  //***
209  for (i=0; i<num_contributors; i++)
210  delete [] contributor_pixel[i];
211  delete [] contributor_pixel;
212 
213  if (traceExec()) CLOG << "returning..." << endl;
214  return;
215 }
216 
217 //*****************************************************************************
218 // METHOD: ossimRgbGridRemapEngine::computeSourceValue
219 //
220 //*****************************************************************************
222  ossimRefPtr<ossimImageData>& source, void* result)
223 {
224  static const char MODULE[]="ossimRgbGridRemapEngine::computeSourceValue";
225  if (traceExec()) CLOG << "entering..." << endl;
226 
227  //***
228  // This engine defines "value" as the RGB vector corresponding to the mean
229  // RGB pixel value of the source data:
230  //***
231  ((double*)result)[0] = source->computeAverageBandValue(0);
232  ((double*)result)[1] = source->computeAverageBandValue(1);
233  ((double*)result)[2] = source->computeAverageBandValue(2);
234 
235  if (traceExec()) CLOG << "returning..." << endl;
236  return;
237 }
238 
239 //*****************************************************************************
240 // METHOD: ossimRgbGridRemapEngine::computeRemapNode
241 //
242 // This engine defines the remap value as the difference between the target
243 // RGB vector and the individual point source's value vector.
244 //
245 //*****************************************************************************
247  void* source_value,
248  void* target_value)
249 {
250  static const char MODULE[] = "ossimRgbGridRemapEngine::computeRemapNode";
251  if (traceExec()) CLOG << "entering..." << endl;
252 
253  //***
254  // Compute the remap grid node value specific to this RGB implementation:
255  //***
256  double node[3];
257  node[0] = ((double*)target_value)[0] - ((double*)source_value)[0];
258  node[1] = ((double*)target_value)[1] - ((double*)source_value)[1];
259  node[2] = ((double*)target_value)[2] - ((double*)source_value)[2];
260 
261  //***
262  // Fetch a pointer to the remapper feeding this point source in order to
263  // pass it the node value:
264  //***
265  ossimGridRemapSource* remapper = ps->getRemapSource();
266  remapper->setGridNode(ps->getViewPoint(), node);
267 
268  if (traceExec()) CLOG << "returning..." << endl;
269  return;
270 }
271 
RTTI_DEF1(ossimRgbGridRemapEngine, "ossimRgbGridRemapEngine", ossimGridRemapEngine)
virtual ossim_uint32 getWidth() const
#define CLOG
Definition: ossimTrace.h:23
double samp
Definition: ossimDpt.h:164
virtual void computeRemapNode(ossimAtbPointSource *point_source, void *source_value, void *target_value)
virtual ossim_uint32 getHeight() const
const ossimDpt & getViewPoint() const
virtual void assignRemapValues(std::vector< ossimAtbPointSource *> &sources)
double line
Definition: ossimDpt.h:165
virtual void computeSourceValue(ossimRefPtr< ossimImageData > &source, void *result)
ossimGridRemapSource * getRemapSource()
virtual void remapTile(const ossimDpt &origin_point, ossimGridRemapSource *remapper, ossimRefPtr< ossimImageData > &tile)
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
virtual ossimObject * dup() const
virtual const void * getBuf() const
unsigned char ossim_uint8
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
8 bit unsigned iteger