OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimHsvGridRemapEngine.cpp
Go to the documentation of this file.
1 //*****************************************************************************
2 // FILE: ossimHsvGridRemapEngine.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: ossimHsvGridRemapEngine.cpp 15833 2009-10-29 01:41:53Z eshirschorn $
18 
20 
21 RTTI_DEF1(ossimHsvGridRemapEngine, "ossimHsvGridRemapEngine",
23 
26 #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 ("ossimHsvGridRemapEngine:exec");
37 static ossimTrace traceDebug ("ossimHsvGridRemapEngine:debug");
38 
39 //*****************************************************************************
40 // METHOD: ossimHsvGridRemapEngine::remapTile
41 //
42 //*****************************************************************************
44 {
45  return new ossimHsvGridRemapEngine;
46 }
47 
48 //*****************************************************************************
49 // METHOD: ossimHsvGridRemapEngine::remapTile
50 //
51 //*****************************************************************************
53  ossimGridRemapSource* remapper,
55 {
56  static const char MODULE[] = "ossimHsvGridRemapEngine::remapTile";
57  if (traceExec()) CLOG << "entering..." << endl;
58 
59  //***
60  // Fetch tile size and NULL pixel value:
61  //***
62  int width = tile->getWidth();
63  int height = tile->getHeight();
64  int offset = 0;
65 
66  void* red_buf = tile->getBuf(0);
67  void* grn_buf = tile->getBuf(1);
68  void* blu_buf = tile->getBuf(2);
69 
70  ossimDblGrid& gridH = *(remapper->getGrid(0));
71  ossimDblGrid& gridS = *(remapper->getGrid(1));
72  ossimDblGrid& gridV = *(remapper->getGrid(2));
73 
74  //---
75  // Remap according to pixel type:
76  //---
77  switch(tile->getScalarType())
78  {
79  case OSSIM_UINT8:
80  {
81  for (double line=origin.line; line<origin.line+height; line+=1.0)
82  {
83  for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
84  {
85  //---
86  // Fetch pixel from the input tile band buffers and convert
87  // to HSV:
88  //---
89  ossimRgbVector rgb_pixel (((ossim_uint8*)red_buf)[offset],
90  ((ossim_uint8*)grn_buf)[offset],
91  ((ossim_uint8*)blu_buf)[offset]);
92  ossimHsvVector hsv_pixel (rgb_pixel);
93 
94  //---
95  // Remap pixel HSV with spatially variant bias value:
96  //---
97  hsv_pixel.setH(hsv_pixel.getH() + gridH(samp,line));
98  hsv_pixel.setS(hsv_pixel.getS() + gridS(samp,line));
99  hsv_pixel.setV(hsv_pixel.getV() + gridV(samp,line));
100 
101  //---
102  // Convert back to RGB and write to the tile:
103  //---
104  rgb_pixel = hsv_pixel; // auto-clamped
105  ((ossim_uint8*)red_buf)[offset] = rgb_pixel.getR();
106  ((ossim_uint8*)grn_buf)[offset] = rgb_pixel.getG();
107  ((ossim_uint8*)blu_buf)[offset] = rgb_pixel.getB();
108 
109  offset++;
110  }
111  }
112  break;
113  }
114 
115  case OSSIM_USHORT11:
116  case OSSIM_USHORT12:
117  case OSSIM_USHORT13:
118  case OSSIM_USHORT14:
119  case OSSIM_USHORT15:
120  break;
121 
122  case OSSIM_UINT16:
123  break;
124 
125  case OSSIM_SINT16:
126  break;
127 
128  case OSSIM_FLOAT64:
129  break;
130 
132  break;
133 
134  case OSSIM_FLOAT32:
135  break;
136 
138  break;
139 
141  default:
142  break;
143 
144  } // end switch statement
145 
146  if (traceExec()) CLOG << "returning..." << endl;
147  return;
148 };
149 
150 //*****************************************************************************
151 // METHOD: ossimHsvGridRemapEngine::assignRemapValues
152 //
153 // This engine defines the target value as an HSV vector of doubles, computed
154 // as the mean of all contributor HSV values.
155 //
156 //*****************************************************************************
158  vector<ossimAtbPointSource*>& sources_list)
159 {
160  static const char MODULE[] = "ossimHsvGridRemapEngine::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  // HSV 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: ossimHsvGridRemapEngine::computeSourceValue
219 //
220 //*****************************************************************************
222  ossimRefPtr<ossimImageData>& source, void* result)
223 {
224  static const char MODULE[]="ossimHsvGridRemapEngine::computeSourceValue";
225  if (traceExec()) CLOG << "entering..." << endl;
226 
227  //***
228  // This engine defines "value" as the HSV vector corresponding to the mean
229  // RGB pixel value of the source data:
230  //***
231  ossimRgbVector rgb_vector;
232  rgb_vector.setR((unsigned char) source->computeAverageBandValue(0));
233  rgb_vector.setG((unsigned char) source->computeAverageBandValue(1));
234  rgb_vector.setB((unsigned char) source->computeAverageBandValue(2));
235 
236  //***
237  // Assign the HSV components to the result vector:
238  //***
239  ossimHsvVector hsv_vector (rgb_vector);
240  ((double*)result)[0] = (double) hsv_vector.getH();
241  ((double*)result)[1] = (double) hsv_vector.getS();
242  ((double*)result)[2] = (double) hsv_vector.getV();
243 
244  if (traceExec()) CLOG << "returning..." << endl;
245  return;
246 }
247 
248 //*****************************************************************************
249 // METHOD: ossimHsvGridRemapEngine::computeRemapNode
250 //
251 // This engine defines the remap value as the difference between the target
252 // HSV vector and the individual point source's value vector.
253 //
254 //*****************************************************************************
256  void* source_value,
257  void* target_value)
258 {
259  static const char MODULE[] = "ossimHsvGridRemapEngine::computeRemapNode";
260  if (traceExec()) CLOG << "entering..." << endl;
261 
262  //***
263  // Compute the remap grid node value specific to this HSV implementation:
264  //***
265  double node[3];
266  node[0] = ((double*)target_value)[0] - ((double*)source_value)[0];
267  node[1] = ((double*)target_value)[1] - ((double*)source_value)[1];
268  node[2] = ((double*)target_value)[2] - ((double*)source_value)[2];
269 
270  //***
271  // Fetch a pointer to the remapper feeding this point source in order to
272  // pass it the node value:
273  //***
274  ossimGridRemapSource* remapper = ps->getRemapSource();
275  remapper->setGridNode(ps->getViewPoint(), node);
276 
277  if (traceExec()) CLOG << "returning..." << endl;
278  return;
279 }
280 
16 bit unsigned integer (15 bits used)
virtual ossim_uint32 getWidth() const
unsigned char getR() const
64 bit floating point
#define CLOG
Definition: ossimTrace.h:23
16 bit unsigned integer
double samp
Definition: ossimDpt.h:164
float getS() const
void setR(unsigned char R)
16 bit signed integer
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
16 bit unsigned integer (13 bits used)
32 bit floating point
virtual ossimObject * dup() const
const ossimDpt & getViewPoint() const
void setB(unsigned char B)
void setS(float S)
double line
Definition: ossimDpt.h:165
ossimGridRemapSource * getRemapSource()
32 bit normalized floating point
void setGridNode(const ossimDpt &view_pt, const double *value)
float getH() const
unsigned char getB() const
ossimDblGrid * getGrid(unsigned int index)
virtual ossim_float64 computeAverageBandValue(ossim_uint32 bandNumber=0) const
This will compute the average value for the band.
RTTI_DEF1(ossimHsvGridRemapEngine, "ossimHsvGridRemapEngine", ossimGridRemapEngine)
void setG(unsigned char G)
unsigned char getG() const
virtual ossimScalarType getScalarType() const
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
void setH(float H)
virtual void computeRemapNode(ossimAtbPointSource *point_source, void *source_value, void *target_value)
virtual void assignRemapValues(std::vector< ossimAtbPointSource *> &sources)
virtual const void * getBuf() const
virtual void computeSourceValue(ossimRefPtr< ossimImageData > &source, void *result)
virtual void remapTile(const ossimDpt &origin_point, ossimGridRemapSource *remapper, ossimRefPtr< ossimImageData > &tile)
void setV(float V)
8 bit unsigned integer
float getV() const
unsigned char ossim_uint8
16 bit unsigned integer (12 bits used)