OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimShiftFilter.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 // License: LGPL
3 //
4 // See LICENSE.txt file in the top level directory for more details.
5 //
6 // Author: David Burken
7 //
8 // Description:
9 //
10 // Filter for shifting input to an output range.
11 //
12 //----------------------------------------------------------------------------
13 // $Id$
14 
17 #include <ossim/base/ossimCommon.h>
19 #include <ossim/base/ossimNotify.h>
20 #include <ossim/base/ossimTrace.h>
21 
23 
24 static ossimTrace traceDebug("ossimShiftFilter:debug");
25 
27  :
28  ossimImageSourceFilter(), // base class
29  m_tile(0),
30  m_min(ossim::nan()),
31  m_max(ossim::nan()),
32  m_null(ossim::nan())
33 {
34  if (traceDebug())
35  {
37  << "ossimShiftFilter::ossimShiftFilter entered...\n";
38  }
39 }
40 
42 {
43 }
44 
46 {
47  if (traceDebug())
48  {
50  << "ossimShiftFilter::initialize entered..." << endl;
51  }
52 
53  //---
54  // Call the base class initialize.
55  // Note: This will reset "theInputConnection" if it changed...
56  //---
58 
59  if (traceDebug())
60  {
62  << "ossimShiftFilter::initialize exited..." << endl;
63  }
64 }
65 
67  const ossimIrect& tileRect,
68  ossim_uint32 resLevel)
69 {
70  ossimRefPtr<ossimImageData> result = 0;
71 
72  if ( theInputConnection )
73  {
74  ossimRefPtr<ossimImageData> inputTile = theInputConnection->getTile( tileRect, resLevel );
75 
76  if ( inputTile.get() && isSourceEnabled() &&
78  {
79  // Get its status of the input tile.
80  ossimDataObjectStatus tile_status = inputTile->getDataObjectStatus();
81 
82  if ( tile_status != OSSIM_NULL )
83  {
84  if ( !m_tile )
85  {
86  allocate(); // First time through.
87  }
88 
89  if ( tile_status != OSSIM_EMPTY )
90  {
91  // Set the origin,bands of the output tile.
92  m_tile->setImageRectangle(tileRect);
93 
94  switch(inputTile->getScalarType())
95  {
96  case OSSIM_UINT8:
97  {
98  fillTile( ossim_uint8(0), inputTile.get(), m_tile.get() );
99  break;
100  }
101  case OSSIM_SINT8:
102  {
103  fillTile( ossim_sint8(0), inputTile.get(), m_tile.get() );
104  break;
105  }
106  case OSSIM_UINT16:
107  case OSSIM_USHORT11:
108  case OSSIM_USHORT12:
109  case OSSIM_USHORT13:
110  case OSSIM_USHORT14:
111  case OSSIM_USHORT15:
112  {
113  fillTile( ossim_uint16(0), inputTile.get(), m_tile.get() );
114  break;
115  }
116  case OSSIM_SINT16:
117  {
118  fillTile( ossim_sint16(0), inputTile.get(), m_tile.get() );
119  break;
120  }
121  case OSSIM_SINT32:
122  {
123  fillTile( ossim_sint32(0), inputTile.get(), m_tile.get() );
124  break;
125  }
126  case OSSIM_UINT32:
127  {
128  fillTile( ossim_uint32(0), inputTile.get(), m_tile.get() );
129  break;
130  }
131  case OSSIM_FLOAT32:
133  {
134  fillTile( ossim_float32(0), inputTile.get(), m_tile.get() );
135  break;
136  }
137  case OSSIM_FLOAT64:
139  {
140  fillTile( ossim_float64(0), inputTile.get(), m_tile.get() );
141  break;
142  }
144  default:
145  {
147  << "ossimShiftFilter::getTile ERROR Unhandled scalar!" << endl;
148  break;
149  }
150 
151  } // Matches: switch(inputTile->getScalarType())
152 
153  m_tile->validate();
154  }
155  else
156  {
157  m_tile->makeBlank();
158  }
159 
160  result = m_tile;
161 
162  } // Matches: if ( tile_status != OSSIM_NULL )
163 
164  } // Matches: if ( inputTile.get() ... )
165 
166  if ( !result && inputTile.get() )
167  {
168  result = inputTile;
169  }
170 
171  } // Matches: if ( theInputConnection )
172 
173  return result;
174 }
175 
176 template <class T> void ossimShiftFilter::fillTile(T /* dummy */,
177  const ossimImageData* inputTile,
178  ossimImageData* outputTile) const
179 {
180  const double BANDS = inputTile->getNumberOfBands();
181  const ossim_uint32 SPB = inputTile->getSizePerBand();
182  std::vector<double> inNull(BANDS);
183  std::vector<double> inMin(BANDS);
184  std::vector<double> inMax(BANDS);
185  std::vector<double> coef(BANDS);
186  ossim_uint32 band = 0;
187 
188  for( ; band < BANDS; ++band )
189  {
190  inNull[band] = inputTile->getNullPix(band);
191  inMin[band] = inputTile->getMinPix(band);
192  inMax[band] = inputTile->getMaxPix(band);
193  coef[band] = (m_max-m_min)/(inMax[band]-inMin[band]);
194  }
195 
196  double pix = 0;
197  for( band = 0; band < BANDS; ++band )
198  {
199  const T* inBuf = static_cast<const T*>(inputTile->getBuf(band));
200  T* outBuf = static_cast<T*>(outputTile->getBuf(band));
201 
202  for ( ossim_uint32 i = 0; i < SPB; ++i )
203  {
204  pix = inBuf[i];
205  if ( pix == inNull[band] )
206  {
207  pix = m_null;
208  }
209  else
210  {
211  // Shift and multiply:
212  pix = m_min + (pix - inMin[band]) * coef[band];
213 
214  // Range check:
215  pix = pix <= m_max ? (pix >= m_min ? pix : m_min) : m_max;
216  }
217 
218  outBuf[i] = static_cast<T>(pix);
219  }
220  }
221 
222  outputTile->validate();
223 }
224 
226 {
227  return ossimString("ossimShiftFilter");
228 }
229 
231 {
232  return ossimString("OSSIM shift filter");
233 }
234 
236 {
237  return ossimString("shift filter");
238 }
239 
241 {
242  double result = 0;;
243  if ( theEnableFlag && !ossim::isnan(m_null) )
244  {
245  result = m_null;
246  }
247  else
248  {
250  }
251  return result;
252 }
253 
255 {
256  double result = 0;;
257  if ( theEnableFlag && !ossim::isnan(m_min) )
258  {
259  result = m_min;
260  }
261  else
262  {
264  }
265  return result;
266 }
267 
269 {
270  double result = 0;;
271  if ( theEnableFlag && !ossim::isnan(m_max) )
272  {
273  result = m_max;
274  }
275  else
276  {
278  }
279  return result;
280 }
281 
283 {
284  m_null = null;
285 }
286 
288 {
289  m_min = min;
290 }
291 
293 {
294  m_max = max;
295 }
296 
298 {
300  m_tile->initialize();
301 }
302 
303 // Private to disallow use...
305 : m_min(0),m_max(0),m_null(0)
306 {
307 }
308 
309 // Private to disallow use...
311 {
312  return *this;
313 }
314 
315 
16 bit unsigned integer (15 bits used)
8 bit signed integer
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual const ossim_float64 * getMaxPix() const
virtual ossim_uint32 getNumberOfBands() const
64 bit floating point
virtual ossimString getShortName() const
virtual void setImageRectangle(const ossimIrect &rect)
virtual double getMinPixelValue(ossim_uint32 band) const
16 bit unsigned integer
bool theEnableFlag
Definition: ossimSource.h:62
float ossim_float32
ossimShiftFilter & operator=(const ossimShiftFilter &)
Private to disallow use...
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
void setNullPixelValue(double null)
Set the null output pixel.
16 bit signed integer
virtual ossimDataObjectStatus getDataObjectStatus() const
16 bit unsigned integer (14 bits used)
signed char ossim_sint8
16 bit unsigned integer (13 bits used)
32 bit floating point
unsigned short ossim_uint16
32 bit unsigned integer
Class to shift/stretch input values to given min/max.
virtual void initialize()
Initialize the data buffer.
virtual ~ossimShiftFilter()
virtual protected destructor
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
double ossim_float64
virtual double getNullPixelValue(ossim_uint32 band) const
static ossimImageDataFactory * instance()
virtual ossimString getClassName() const
ossimRefPtr< ossimImageData > m_tile
virtual ossimDataObjectStatus validate() const
signed short ossim_sint16
32 bit signed integer
virtual ossim_uint32 getSizePerBand() const
Returns the number of pixels in a single band in a tile.
void setMaxPixelValue(double max)
Set the max output pixel.
ossimImageSource * theInputConnection
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
32 bit normalized floating point
signed int ossim_sint32
void allocate()
Allocates the tile.
virtual double getMaxPixelValue(ossim_uint32 band) const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
void setMinPixelValue(double min)
Set the min output pixel.
virtual const ossim_float64 * getMinPix() const
virtual ossimScalarType getScalarType() const
virtual void makeBlank()
Initializes data to null pixel values.
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
#define max(a, b)
Definition: auxiliary.h:76
virtual const void * getBuf() const
virtual void initialize()
virtual ossimString getLongName() const
ossimShiftFilter()
default constructor
8 bit unsigned integer
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
ossimDataObjectStatus
Definitions for data object status.
void fillTile(T dummy, const ossimImageData *inputTile, ossimImageData *outputTile) const
Template to fill the tile.
unsigned char ossim_uint8
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
#define min(a, b)
Definition: auxiliary.h:75
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
16 bit unsigned integer (12 bits used)
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91