OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimS16ImageData.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: David Burken
6 //
7 // Description:
8 //
9 // Class definition of ossimS16ImageData. Specialized image data object for
10 // signed short data.
11 //
12 //*************************************************************************
13 // $Id: ossimS16ImageData.cpp 16052 2009-12-08 22:20:40Z dburken $
14 
18 #include <ossim/base/ossimIrect.h>
21 
22 RTTI_DEF1(ossimS16ImageData, "ossimS16ImageData", ossimImageData)
23 
25 
27  :
29 {
31 }
32 
34  ossim_uint32 bands)
35  :
36  ossimImageData(source,
38  bands)
39 {
40 }
41 
43  ossim_uint32 bands,
44  ossim_uint32 width,
45  ossim_uint32 height)
46  :
47  ossimImageData(source,
49  bands,
50  width,
51  height)
52 {
53 }
54 
56  :
57  ossimImageData(rhs)
58 {
59 }
60 
62 {
63 }
64 
66 {
67  return new ossimS16ImageData(*this);
68 }
69 
71 {
72  if (getBuf() == NULL)
73  {
75  return OSSIM_NULL;
76  }
77 
78  ossim_uint32 count = 0;
79  const ossim_uint32 SIZE = getSize();
80  const ossim_uint32 BOUNDS = getSizePerBand();
81  const ossim_uint32 NUMBER_OF_BANDS = getNumberOfBands();
82 
83  for(ossim_uint32 band = 0; band < NUMBER_OF_BANDS; ++band)
84  {
86  const ossim_sint16* p = getSshortBuf(band);
87  for (ossim_uint32 i=0; i<BOUNDS; i++)
88  {
89  // check if the band is null
90  if (p[i] != np) count++;
91  }
92  }
93 
94  if (!count)
96  else if (count == SIZE)
98  else
100 
101  return getDataObjectStatus();
102 }
103 
105  ossim_uint32 bandNumber,
106  float& result)const
107 {
108  if( (getDataObjectStatus() != OSSIM_NULL) && isValidBand(bandNumber) )
109  {
110  const ossim_sint16* sourceBuf = getSshortBuf(bandNumber);
111  result =
112  static_cast<float>(m_remapTable.normFromPix(sourceBuf[offset]));
113  }
114 }
115 
117  ossim_uint32 bandNumber,
118  float inputValue)
119 {
120  if( (getDataObjectStatus() != OSSIM_NULL) && isValidBand(bandNumber) )
121  {
122  ossim_sint16* sourceBuf = getSshortBuf(bandNumber);
123  sourceBuf[offset]
124  = static_cast<ossim_sint16>(m_remapTable.pixFromNorm(inputValue));
125  }
126 }
127 
128 void
130 {
131  if(!result)
132  {
133  return;
134  }
135  // make sure that the types and width and height are
136  // good.
137  if( (result->getScalarType() != OSSIM_NORMALIZED_FLOAT) ||
138  (result->getNumberOfBands() != this->getNumberOfBands())||
139  (result->getWidth() != this->getWidth()) ||
140  (result->getHeight() != this->getHeight())||
141  (result->getDataObjectStatus() == OSSIM_NULL) ||
143  {
144  return;
145  }
146 
148 
149  if(size > 0)
150  {
151  for(ossim_uint32 bandCount = 0;
152  bandCount < m_numberOfDataComponents;
153  ++bandCount)
154  {
155  const ossim_sint16* sourceBuf = getSshortBuf(bandCount);
156  float* resultBuf = static_cast<float*>(result->getBuf(bandCount));
157  for(ossim_uint32 counter = 0; counter < size; ++counter)
158  {
159  resultBuf[counter]
160  = static_cast<float>(m_remapTable.
161  normFromPix(sourceBuf[counter]));
162  }
163  }
164  }
165 }
166 
168 {
169  if(!result)
170  {
171  return;
172  }
173 
174  // make sure that the types and width and height are
175  // good.
176  if( (result->getScalarType() != OSSIM_NORMALIZED_FLOAT) ||
177  (result->getNumberOfBands() != this->getNumberOfBands())||
178  (result->getWidth() != this->getWidth()) ||
179  (result->getHeight() != this->getHeight())||
180  (result->getDataObjectStatus() == OSSIM_NULL) ||
182  {
183  return;
184  }
185 
187 
188  if(size > 0)
189  {
190  for(ossim_uint32 bandCount = 0;
191  bandCount < m_numberOfDataComponents;
192  ++bandCount)
193  {
194  const ossim_sint16* sourceBuf = getSshortBuf(bandCount);
195  double* resultBuf = static_cast<double*>(result->getBuf(bandCount));
196  for(ossim_uint32 counter = 0; counter < size; ++counter)
197  {
198  resultBuf[counter] = m_remapTable.normFromPix(sourceBuf[counter]);
199  }
200  }
201  }
202 }
203 
205 {
206  if((normalizedInput->getScalarType() != OSSIM_NORMALIZED_FLOAT) &&
207  (normalizedInput->getScalarType() != OSSIM_NORMALIZED_DOUBLE) )
208  {
209  //ERROR
210  return;
211  }
212 
213  ossim_uint32 counter = 0;
214  ossim_uint32 bandCount = 0;
216  ossimScalarType scalarType = normalizedInput->getScalarType();
217 
218  if(size > 0)
219  {
220  if(scalarType == OSSIM_NORMALIZED_FLOAT)
221  {
222  for(bandCount = 0; bandCount < m_numberOfDataComponents; ++bandCount)
223  {
224  float* sourceBuf =
225  static_cast<float*>(normalizedInput->getBuf(bandCount));
226  ossim_sint16* resultBuf = getSshortBuf(bandCount);
227  for(counter = 0; counter < size; ++counter)
228  {
229  resultBuf[counter]
230  = static_cast<ossim_sint16>(m_remapTable.
231  pixFromNorm(sourceBuf[counter]));
232  }
233  }
234  }
235  else // Double
236  {
237  for(bandCount = 0; bandCount < m_numberOfDataComponents; ++bandCount)
238  {
239  double* sourceBuf =
240  static_cast<double*>(normalizedInput->getBuf(bandCount));
241  ossim_sint16* resultBuf = getSshortBuf(bandCount);
242  for(counter = 0; counter < size; ++counter)
243  {
244  resultBuf[counter]
245  = static_cast<ossim_sint16>(m_remapTable.
246  pixFromNorm(sourceBuf[counter]));
247  }
248  }
249  }
250  }
251 }
252 
254  ossim_uint32 bandNumber)
255 {
256  double result = -1; // invalid MSE
257  ossim_uint32 index = 0;
258  double delta = 0;
259  ossim_uint32 validPixelCount=0;
260 
261  ossim_sint16* buffer = getSshortBuf(bandNumber);
262  if(buffer)
263  {
264  ossim_uint32 bounds = getWidth()*getHeight();
265  for(index = 0; index < bounds; ++index)
266  {
267  if(!isNull(index))
268  {
269  delta = *buffer - meanValue;
270  result += (delta*delta);
271  ++validPixelCount;
272  }
273  ++buffer;
274  }
275  if(validPixelCount > 0)
276  {
277  result /= validPixelCount;
278  }
279  }
280 
281  return result;
282 }
283 
284 
286 {
287  double result = 0.0;
288  ossim_uint32 index = 0;
289  ossim_uint32 validPixelCount=0;
290 
291  ossim_sint16* buffer = getSshortBuf(bandNumber);
292  if(buffer)
293  {
294  ossim_uint32 bounds = getSizePerBand();
295  for(index = 0; index < bounds; ++index)
296  {
297  if(!isNull(index))
298  {
299  result += *buffer;
300  ++validPixelCount;
301  }
302  ++buffer;
303  }
304  if(validPixelCount > 0)
305  {
306  result /= validPixelCount;
307  }
308  }
309 
310  return result;
311 }
312 
314 {
315  if(getBuf() != NULL && isWithin(x, y))
316  {
317  //***
318  // Compute the offset into the buffer for (x,y). This should always
319  // come out positive.
320  //***
321  ossim_uint32 ux = static_cast<ossim_uint32>(x - m_origin.x);
322  ossim_uint32 uy = static_cast<ossim_uint32>(y - m_origin.y);
323 
324  ossim_uint32 offset = uy * m_spatialExtents[0] + ux;
325 
326  for(ossim_uint32 band = 0; band < m_numberOfDataComponents; band++)
327  {
328  ossim_sint16* buf = getSshortBuf(band)+offset;
329  *buf = (ossim_sint16)color;
330  }
331  }
332 }
333 
334 void ossimS16ImageData::fill(ossim_uint32 band, double value)
335 {
336  void* s = getBuf(band);
337 
338  if (s == NULL) return; // nothing to do...
339 
340  ossim_uint32 size_in_pixels = getSizePerBand();
341  ossim_sint16* p = getSshortBuf(band);
342 
343  for (ossim_uint32 i=0; i<size_in_pixels; i++) p[i] = (ossim_sint16)value;
344 
345  // Set the status to unknown since we don't know about the other bands.
347 }
348 
349 
351 {
352  for(ossim_uint32 band = 0; band < getNumberOfBands(); ++band)
353  {
354  const ossim_sint16* buf = getSshortBuf(band)+offset;
355 
356  if((*buf) != m_nullPixelValue[band])
357  {
358  return false;
359  }
360  }
361 
362  return true;
363 }
364 
366 {
367  for(ossim_uint32 band = 0; band < getNumberOfBands(); ++band)
368  {
369  ossim_sint16* buf = getSshortBuf(band)+offset;
370  *buf = static_cast<ossim_sint16>(m_nullPixelValue[band]);
371  }
372 }
373 
375 {
376  if (!buf)
377  {
380  "ossimS16ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
381  __FILE__,
382  __LINE__);
383  return;
384  }
385 
386  const ossim_uint32 SIZE = getSizePerBand();
387 
388  if(SIZE > 0)
389  {
390  for(ossim_uint32 band = 0; band < getNumberOfBands(); ++band)
391  {
392  const ossim_sint16* s = getSshortBuf(band); // source
393  double* d = buf + (band*SIZE); // destination
394 
395  for(ossim_uint32 index = 0; index < SIZE; ++index)
396  {
397  d[index] = m_remapTable.
398  normFromPix(static_cast<ossim_int32>(s[index]));
399  }
400  }
401  }
402 }
403 
405  double* buf) const
406 {
407  if (!buf)
408  {
411  "ossimS16ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
412  __FILE__,
413  __LINE__);
414  return;
415  }
416 
417  if(!getBuf(band)) return;
418 
419  const ossim_uint32 SIZE = getSizePerBand();
420 
421  if(SIZE)
422  {
423  const ossim_float64 RANGE = (getMaxPix(band)-getMinPix(band)+1);
424 
425  const ossim_sint16* s = getSshortBuf(band); // source
426  double* d = buf; // destination
427 
428  for(ossim_uint32 index = 0; index < SIZE; ++index)
429  {
430  ossim_float64 p = s[index];
431 
432  if (p == m_nullPixelValue[band])
433  {
434  d[index] = 0.0;
435  }
436  else if (p >= m_maxPixelValue[band])
437  {
438  d[index] = 1.0;
439  }
440  else
441  {
442  //---
443  // Normalize...
444  // Note that this will shift any negatives to positive prior
445  // to dividing.
446  //---
447  d[index] =
448  ((p-m_minPixelValue[band]+1) / RANGE);
449  }
450  }
451  }
452 }
453 
455 {
456  if (!buf)
457  {
460  "ossimS16ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
461  __FILE__,
462  __LINE__);
463  return;
464  }
465 
467 
468  if(size > 0)
469  {
470  for(ossim_uint32 band = 0; band < getNumberOfBands(); band++)
471  {
472  double* s = buf + (band*size); // source
473  ossim_sint16* d = getSshortBuf(band); // destination
474 
475  for(ossim_uint32 index = 0; index < size; index++)
476  {
477  d[index] = m_remapTable.pixFromNorm(s[index]);
478  }
479  }
480  }
481 }
482 
484  double* buf)
485 {
486  if (!buf)
487  {
490  "ossimS11ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
491  __FILE__,
492  __LINE__);
493  return;
494  }
495 
497 
498  if((size > 0)&&getBuf(band))
499  {
500  double* s = buf; // source
501  ossim_sint16* d = getSshortBuf(band); // destination
502 
503  for(ossim_uint32 index = 0; index < size; ++index)
504  {
505  *d = m_remapTable.pixFromNorm(*s);
506  ++d;
507  ++s;
508  }
509  }
510 }
511 
513 {
514  if (!buf)
515  {
518  "ossimS16ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
519  __FILE__,
520  __LINE__);
521  return;
522  }
523 
525 
526  if(size > 0)
527  {
528  for(ossim_uint32 band = 0; band < getNumberOfBands(); ++band)
529  {
530  const ossim_sint16* s = getSshortBuf(band); // source
531  float* d = buf + (band*size); // destination
532 
533  for(ossim_uint32 index = 0; index < size; ++index)
534  {
535  d[index] = m_remapTable.
536  normFromPix(static_cast<ossim_int32>(s[index]));
537  }
538  }
539  }
540 }
541 
543  float* buf) const
544 {
545  if (!buf)
546  {
549  "ossimS16ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
550  __FILE__,
551  __LINE__);
552  return;
553  }
554  if(!getBuf(band)) return;
555 
557 
558  if(size > 0)
559  {
560  const ossim_sint16* s = getSshortBuf(band); // source
561  float* d = buf; // destination
562 
563  for(ossim_uint32 index = 0; index < size; ++index)
564  {
565  *d = m_remapTable.normFromPix(static_cast<ossim_int32>(*s));
566  }
567  }
568 }
569 
571 {
572  if (!buf)
573  {
576  "ossimS16ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
577  __FILE__,
578  __LINE__);
579  return;
580  }
581 
583 
584  if(size > 0)
585  {
586  for(ossim_uint32 band = 0; band < getNumberOfBands(); ++band)
587  {
588  float* s = buf + (band*size); // source
589  ossim_sint16* d = getSshortBuf(band); // destination
590 
591  for(ossim_uint32 index = 0; index < size; ++index)
592  {
593  d[index] = m_remapTable.pixFromNorm(s[index]);
594  }
595  }
596  }
597 }
598 
600  float* buf)
601 {
602  if (!buf)
603  {
606  "ossimS16ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
607  __FILE__,
608  __LINE__);
609  return;
610  }
611 
613 
614  if((size > 0)&&getBuf(band))
615  {
616  float* s = buf; // source
617  ossim_sint16* d = getSshortBuf(band); // destination
618 
619  for(ossim_uint32 index = 0; index < size; ++index)
620  {
621  *d = m_remapTable.pixFromNorm(*s);
622  ++d;
623  ++s;
624  }
625  }
626 }
627 
OSSIMDLLEXPORT void ossimSetError(const char *className, ossim_int32 error, const char *fmtString=0,...)
virtual ossim_uint32 getWidth() const
ossim_uint32 x
bool isNull(ossim_uint32 offset) const
virtual void setValue(ossim_int32 x, ossim_int32 y, double color)
virtual const ossim_float64 * getMaxPix() const
void setNull(ossim_uint32 offset)
virtual ossim_uint32 getNumberOfBands() const
virtual void copyNormalizedBufferToTile(double *buf)
virtual void getNormalizedFloat(ossim_uint32 offset, ossim_uint32 bandNumber, float &result) const
ossim_uint32 y
virtual double computeMeanSquaredError(double meanValue, ossim_uint32 bandNumber=0)
virtual double computeAverageBandValue(ossim_uint32 bandNumber=0)
16 bit signed integer
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
static const ossimErrorCode OSSIM_ERROR
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
Signed 16 bit normalized remap tables to go to/from normalized value to pixel value.
virtual const ossim_sint16 * getSshortBuf() const
virtual void convertToNormalizedFloat(ossimImageData *result) const
double ossim_float64
virtual ossimDataObjectStatus validate() const
yy_size_t size
signed short ossim_sint16
virtual ossim_uint32 getSizePerBand() const
Returns the number of pixels in a single band in a tile.
std::vector< ossim_float64 > m_maxPixelValue
Max pixel value for each band.
unsigned int ossim_uint32
32 bit normalized floating point
virtual void copyTileToNormalizedBuffer(double *buf) const
std::vector< ossim_uint32 > m_spatialExtents
virtual bool isWithin(ossim_int32 x, ossim_int32 y)
std::vector< ossim_float64 > m_minPixelValue
Min pixel value for each band.
virtual ossimObject * dup() const
virtual void unnormalizeInput(ossimImageData *normalizedInput)
virtual bool isValidBand(ossim_uint32 band) const
ossimScalarType
virtual const ossim_float64 * getMinPix() const
virtual ossim_int32 pixFromNorm(ossim_float64 normPix) const
Gets pixel value from normalized value.
virtual ossimScalarType getScalarType() const
64 bit normalized floating point
std::vector< ossim_float64 > m_nullPixelValue
Null pixel value for each band.
virtual ossim_uint32 getSize() const
Returns the total number of pixels in a tile for all bands.
ossim_int32 y
Definition: ossimIpt.h:142
virtual const void * getBuf() const
virtual ossim_float64 normFromPix(ossim_int32 pix) const
Gets normalized value (between &#39;0.0&#39; and &#39;1.0&#39;) from an int which should in scalar range of a signed ...
virtual void setDataObjectStatus(ossimDataObjectStatus status) const
Full list found in ossimConstants.h.
ossim_int32 x
Definition: ossimIpt.h:141
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
ossimDataObjectStatus
Definitions for data object status.
static const ossimNormalizedS16RemapTable m_remapTable
virtual void setNormalizedFloat(ossim_uint32 offset, ossim_uint32 bandNumber, float input)
void fill(ossim_uint32 band, double value)
virtual void convertToNormalizedDouble(ossimImageData *result) const
int ossim_int32