OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimCastTileSourceFilter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 //*************************************************************************
11 // $Id: ossimCastTileSourceFilter.cpp 17195 2010-04-23 17:32:18Z dburken $
18 
20  "ossimCastTileSourceFilter",
22 
24  ossimScalarType scalarType)
25  :ossimImageSourceFilter(NULL,input),
26  theTile(NULL),
27  theOutputScalarType(scalarType)
28 {
29 }
30 
32 {
33 }
34 
36  const ossimIrect& tileRect,
37  ossim_uint32 resLevel)
38 {
40 
42  {
43  inputTile = theInputConnection->getTile(tileRect, resLevel);
44  }
45  return applyCast(inputTile);
46 }
47 
49 {
50  if(isSourceEnabled())
51  {
52  return theOutputScalarType;
53  }
54  else if(theInputConnection)
55  {
57  }
58 
59  return OSSIM_SCALAR_UNKNOWN;
60 }
61 
63 {
64  if(!isSourceEnabled())
65  {
67  {
69  }
70  }
72 }
73 
75 {
76  if(!isSourceEnabled())
77  {
79  {
81  }
82  }
83 
85  {
86  double tempMin = theInputConnection->getMinPixelValue(band);
87 
90 
91  if((tempMin >= defaultMin) && (tempMin <= defaultMax))
92  {
93  defaultMin = tempMin;
94  }
95 
96  return defaultMin;
97  }
98 
100 }
101 
103 {
104  if(!isSourceEnabled())
105  {
107  {
108  return theInputConnection->getMaxPixelValue(band);
109  }
110  }
112  {
113  double tempMax = theInputConnection->getMaxPixelValue(band);
114 
117 
118  if((tempMax >= defaultMin) && (tempMax <= defaultMax))
119  {
120  defaultMax = tempMax;
121  }
122 
123  return defaultMax;
124  }
126 }
127 
129  ossimRefPtr<ossimImageData> inputTile)
130 {
131  if(!inputTile.valid())
132  {
133  return inputTile;
134  }
135 
136  if(!theTile.valid() ||
137  (theTile->getNumberOfBands() != inputTile->getNumberOfBands()))
138  {
139  allocate(inputTile);
140  }
141  else
142  {
143  ossim_int32 tw =inputTile->getWidth();
144  ossim_int32 th =inputTile->getHeight();
147  theTile->setWidthHeight(tw, th);
148 
149  if((w*h != tw*th))
150  {
151  theTile->initialize();
152  }
153  else
154  {
155  theTile->makeBlank();
156  }
157  theTile->setOrigin(inputTile->getOrigin());
158  }
159 
160  if( (inputTile->getDataObjectStatus()==OSSIM_EMPTY) ||
161  (inputTile->getDataObjectStatus()==OSSIM_NULL))
162  {
163  return theTile;
164  }
165 
166  switch(inputTile->getScalarType())
167  {
168  case OSSIM_UINT8:
169  {
170  ossim_uint8** bands = new ossim_uint8*[inputTile->getNumberOfBands()];
171 
172  for(ossim_uint32 band = 0;
173  band < inputTile->getNumberOfBands();
174  ++band)
175  {
176  bands[band] = static_cast<ossim_uint8*>(inputTile->getBuf(band));
177  }
178  castInputToOutput(bands,
179  inputTile->getNullPix(),
180  inputTile->getDataObjectStatus()==OSSIM_PARTIAL);
181  delete [] bands;
182  break;
183  }
184  case OSSIM_SINT8:
185  {
186  ossim_sint8** bands = new ossim_sint8*[inputTile->getNumberOfBands()];
187 
188  for(ossim_uint32 band = 0;
189  band < inputTile->getNumberOfBands();
190  ++band)
191  {
192  bands[band] = static_cast<ossim_sint8*>(inputTile->getBuf(band));
193  }
194  castInputToOutput(bands,
195  inputTile->getNullPix(),
196  inputTile->getDataObjectStatus()==OSSIM_PARTIAL);
197  delete [] bands;
198  break;
199  }
200  case OSSIM_UINT16:
201  case OSSIM_USHORT11:
202  case OSSIM_USHORT12:
203  case OSSIM_USHORT13:
204  case OSSIM_USHORT14:
205  case OSSIM_USHORT15:
206  {
207  ossim_uint16** bands =
208  new ossim_uint16*[inputTile->getNumberOfBands()];
209 
210  for(ossim_uint32 band = 0;
211  band < inputTile->getNumberOfBands();
212  ++band)
213  {
214  bands[band] = static_cast<ossim_uint16*>(inputTile->getBuf(band));
215  }
216  castInputToOutput(bands,
217  inputTile->getNullPix(),
218  inputTile->getDataObjectStatus()==OSSIM_PARTIAL);
219  delete [] bands;
220  break;
221  }
222  case OSSIM_SINT16:
223  {
224  ossim_sint16** bands =
225  new ossim_sint16*[inputTile->getNumberOfBands()];
226 
227  for(ossim_uint32 band = 0;
228  band < inputTile->getNumberOfBands();
229  ++band)
230  {
231  bands[band] = static_cast<ossim_sint16*>(inputTile->getBuf(band));
232  }
233  castInputToOutput(bands,
234  inputTile->getNullPix(),
235  inputTile->getDataObjectStatus()==OSSIM_PARTIAL);
236  delete [] bands;
237  break;
238  }
239  case OSSIM_SINT32:
240  {
241  ossim_sint32** bands =
242  new ossim_sint32*[inputTile->getNumberOfBands()];
243 
244  for(ossim_uint32 band = 0;
245  band < inputTile->getNumberOfBands();
246  ++band)
247  {
248  bands[band] = static_cast<ossim_sint32*>(inputTile->getBuf(band));
249  }
250  castInputToOutput(bands,
251  inputTile->getNullPix(),
252  inputTile->getDataObjectStatus()==OSSIM_PARTIAL);
253  delete [] bands;
254  break;
255  }
256  case OSSIM_UINT32:
257  {
258  ossim_uint32** bands =
259  new ossim_uint32*[inputTile->getNumberOfBands()];
260 
261  for(ossim_uint32 band = 0;
262  band < inputTile->getNumberOfBands();
263  ++band)
264  {
265  bands[band] = static_cast<ossim_uint32*>(inputTile->getBuf(band));
266  }
267  castInputToOutput(bands,
268  inputTile->getNullPix(),
269  inputTile->getDataObjectStatus()==OSSIM_PARTIAL);
270  delete [] bands;
271  break;
272  }
273  case OSSIM_FLOAT32:
275  {
276  float** bands = new float*[inputTile->getNumberOfBands()];
277 
278  for(ossim_uint32 band = 0;
279  band < inputTile->getNumberOfBands();
280  ++band)
281  {
282  bands[band] = static_cast<float*>(inputTile->getBuf(band));
283  }
284  castInputToOutput(bands,
285  inputTile->getNullPix(),
286  inputTile->getDataObjectStatus()==OSSIM_PARTIAL);
287  delete [] bands;
288  break;
289  }
290  case OSSIM_FLOAT64:
292  {
293  double** bands = new double*[inputTile->getNumberOfBands()];
294 
295  for(ossim_uint32 band = 0;
296  band < inputTile->getNumberOfBands();
297  ++band)
298  {
299  bands[band] = static_cast<double*>(inputTile->getBuf(band));
300  }
301  castInputToOutput(bands,
302  inputTile->getNullPix(),
303  inputTile->getDataObjectStatus()==OSSIM_PARTIAL);
304  delete [] bands;
305  break;
306  }
308  default:
309  {
310  break;
311  }
312  }
313 
314 // theTile->setDataObjectStatus(inputTile->getDataObjectStatus());
315  theTile->validate();
316  return theTile;
317 }
318 
320 {
322  theOutputScalarType = scalarType;
323 
324  if ( (theOutputScalarType != old_type))
325  {
326  // must reinitialize...
327  theTile = NULL;
328  initialize();
329  }
330 }
331 
333 {
334  int scalar =
336 
337  if (scalar != ossimLookUpTable::NOT_FOUND)
338  {
339  setOutputScalarType(static_cast<ossimScalarType>(scalar));
340  }
341  else
342  {
344  << "ossimCastTileSourceFilter::setOutputScalarType WARN:"
345  << "\nUnknown scalar type: " << scalarType.c_str() << endl;
346  }
347 }
348 
350 {
352 }
353 
355 {
357 
359  {
360  // default to OSSIM_UCHAR
362  }
363 }
364 
366  const char* prefix) const
367 {
369 
370  kwl.add(prefix,
373  true);
374 
375  return true;
376 }
377 
379  const char* prefix)
380 {
382 
384  {
386  << "ossimScalarRemapper::loadState WARN:\n"
387  << " ERROR detected in keyword list! State not loaded."
388  << endl;
389  return false;
390  }
391 
392  int scalar = ossimScalarTypeLut::instance()->getEntryNumber(kwl, prefix);
393 
394  if (scalar != ossimLookUpTable::NOT_FOUND)
395  {
396  theOutputScalarType = static_cast<ossimScalarType>(scalar);
397  }
398 
399  return true;
400 }
401 
402 template<class inType>
404  const double *nullPix,
405  bool inPartialFlag)
406 {
407  switch(theTile->getScalarType())
408  {
409  case OSSIM_UINT8:
410  {
411  ossim_uint8** bands = new ossim_uint8*[theTile->getNumberOfBands()];
412 
413  for(ossim_uint32 band = 0; band < theTile->getNumberOfBands(); ++band)
414  {
415  bands[band] = static_cast<ossim_uint8*>(theTile->getBuf(band));
416  }
417 
418  castInputToOutput(inBuffer,
419  nullPix,
420  inPartialFlag,
421  bands,
422  theTile->getNullPix(),
424  delete [] bands;
425  break;
426  }
427  case OSSIM_SINT8:
428  {
429  ossim_sint8** bands = new ossim_sint8*[theTile->getNumberOfBands()];
430 
431  for(ossim_uint32 band = 0; band < theTile->getNumberOfBands(); ++band)
432  {
433  bands[band] = static_cast<ossim_sint8*>(theTile->getBuf(band));
434  }
435 
436  castInputToOutput(inBuffer,
437  nullPix,
438  inPartialFlag,
439  bands,
440  theTile->getNullPix(),
442  delete [] bands;
443  break;
444  }
445  case OSSIM_SINT16:
446  {
448 
449  for(ossim_uint32 band = 0; band < theTile->getNumberOfBands(); ++band)
450  {
451  bands[band] = static_cast<ossim_sint16*>(theTile->getBuf(band));
452  }
453 
454  castInputToOutput(inBuffer,
455  nullPix,
456  inPartialFlag,
457  bands,
458  theTile->getNullPix(),
460  delete [] bands;
461  break;
462  }
463  case OSSIM_UINT16:
464  case OSSIM_USHORT11:
465  case OSSIM_USHORT12:
466  case OSSIM_USHORT13:
467  case OSSIM_USHORT14:
468  case OSSIM_USHORT15:
469  {
471 
472  for(ossim_uint32 band = 0; band < theTile->getNumberOfBands(); ++band)
473  {
474  bands[band] = static_cast<ossim_uint16*>(theTile->getBuf(band));
475  }
476 
477  castInputToOutput(inBuffer,
478  nullPix,
479  inPartialFlag,
480  bands,
481  theTile->getNullPix(),
483  delete [] bands;
484  break;
485  }
486  case OSSIM_UINT32:
487  {
489 
490  for(ossim_uint32 band = 0; band < theTile->getNumberOfBands(); ++band)
491  {
492  bands[band] = static_cast<ossim_uint32*>(theTile->getBuf(band));
493  }
494 
495  castInputToOutput(inBuffer,
496  nullPix,
497  inPartialFlag,
498  bands,
499  theTile->getNullPix(),
501  delete [] bands;
502  break;
503  }
504  case OSSIM_SINT32:
505  {
507 
508  for(ossim_uint32 band = 0; band < theTile->getNumberOfBands(); ++band)
509  {
510  bands[band] = static_cast<ossim_sint32*>(theTile->getBuf(band));
511  }
512 
513  castInputToOutput(inBuffer,
514  nullPix,
515  inPartialFlag,
516  bands,
517  theTile->getNullPix(),
519  delete [] bands;
520  break;
521  }
522 
523  case OSSIM_FLOAT32:
525  {
526  float** bands = new float*[theTile->getNumberOfBands()];
527 
528  for(ossim_uint32 band = 0; band < theTile->getNumberOfBands(); ++band)
529  {
530  bands[band] = static_cast<float*>(theTile->getBuf(band));
531  }
532 
533  castInputToOutput(inBuffer,
534  nullPix,
535  inPartialFlag,
536  bands,
537  theTile->getNullPix(),
539  delete [] bands;
540  break;
541  }
542  case OSSIM_FLOAT64:
544  {
545  double** bands = new double*[theTile->getNumberOfBands()];
546 
547  for(ossim_uint32 band = 0; band < theTile->getNumberOfBands(); ++band)
548  {
549  bands[band] = static_cast<double*>(theTile->getBuf(band));
550  }
551 
552  castInputToOutput(inBuffer,
553  nullPix,
554  inPartialFlag,
555  bands,
556  theTile->getNullPix(),
558  delete [] bands;
559  break;
560  }
562  default:
563  {
565  << "ossimCastTileSourceFilter::castInputToOutput WARN:\n"
566  << "Scalar not set in ossimCastTileSourceFilter" << endl;
567  break;
568  }
569  }
570 }
571 
572 template<class inType, class outType>
574  const double *nullInPix,
575  bool inPartialFlag,
576  outType *outBuffer[],
577  const double *nullOutPix,
578  ossim_uint32 numberOfBands)
579 {
581  if(!inPartialFlag)
582  {
583  for(ossim_uint32 band = 0; band < numberOfBands; ++band)
584  {
585  outType outMin = static_cast<outType>(theTile->getMinPix(band));
586  outType outMax = static_cast<outType>(theTile->getMaxPix(band));
587 
588  for(ossim_uint32 offset = 0; offset < size; ++offset)
589  {
590  double temp = inBuffer[band][offset];
591  if(temp < outMin) temp = outMin;
592  if(temp > outMax) temp = outMax;
593  outBuffer[band][offset] = static_cast<outType>(temp);
594  }
595  }
596  }
597  else
598  {
599  for(ossim_uint32 band = 0; band < numberOfBands; ++band)
600  {
601  inType np = static_cast<inType>(nullInPix[band]);
602  outType outNp = static_cast<outType>(nullOutPix[band]);
603  outType outMin = static_cast<outType>(theTile->getMinPix(band));
604  outType outMax = static_cast<outType>(theTile->getMaxPix(band));
605 
606  for(ossim_uint32 offset = 0; offset < size; ++offset)
607  {
608  if(inBuffer[band][offset] != np)
609  {
610  double temp = inBuffer[band][offset];
611  if(temp < outMin) temp = outMin;
612  if(temp > outMax) temp = outMax;
613  outBuffer[band][offset] = static_cast<outType>(temp);
614  }
615  else
616  {
617  outBuffer[band][offset] = static_cast<outType>(outNp);
618 
619  }
620  }
621  }
622  }
623 }
624 
626 {
628  this,
630  inputTile->getNumberOfBands(),
631  inputTile->getWidth(),
632  inputTile->getHeight());
633  theTile->initialize();
634  theTile->setOrigin(inputTile->getOrigin());
635 }
636 
638 {
639 }
640 
642 {
643 }
644 
646 {
647  if(property->getName() == ossimKeywordNames::SCALAR_TYPE_KW)
648  {
649  int scalar = ossimScalarTypeLut::instance()->getEntryNumber(property->valueToString());
650 
651  if (scalar != ossimLookUpTable::NOT_FOUND)
652  {
653  setOutputScalarType(static_cast<ossimScalarType>(scalar));
654  }
655  }
656  else
657  {
659  }
660 }
661 
663 {
664  ossimRefPtr<ossimProperty> resultProperty;
666  {
667  ossimStringProperty* stringProperty = new ossimStringProperty(name,
669  false);
670 
671  stringProperty->addConstraint(ossimScalarTypeLut::instance()->getEntryString(OSSIM_UINT8));
672  stringProperty->addConstraint(ossimScalarTypeLut::instance()->getEntryString(OSSIM_SINT8));
673  stringProperty->addConstraint(ossimScalarTypeLut::instance()->getEntryString(OSSIM_UINT16));
674  stringProperty->addConstraint(ossimScalarTypeLut::instance()->getEntryString(OSSIM_SINT16));
675  stringProperty->addConstraint(ossimScalarTypeLut::instance()->getEntryString(OSSIM_UINT32));
676  stringProperty->addConstraint(ossimScalarTypeLut::instance()->getEntryString(OSSIM_SINT32));
677  stringProperty->addConstraint(ossimScalarTypeLut::instance()->getEntryString(OSSIM_FLOAT32));
678  stringProperty->addConstraint(ossimScalarTypeLut::instance()->getEntryString(OSSIM_FLOAT64));
679 
680  stringProperty->setCacheRefreshBit();
681  resultProperty = stringProperty;
682  }
683  else
684  {
685  resultProperty = ossimImageSourceFilter::getProperty(name);
686  }
687  return resultProperty;
688 }
689 
690 void ossimCastTileSourceFilter::getPropertyNames(std::vector<ossimString>& propertyNames)const
691 {
693 
694  propertyNames.push_back(ossimKeywordNames::SCALAR_TYPE_KW);
695 }
696 
16 bit unsigned integer (15 bits used)
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
8 bit signed integer
RTTI_DEF1(ossimCastTileSourceFilter, "ossimCastTileSourceFilter", ossimImageSourceFilter)
virtual void valueToString(ossimString &valueResult) const =0
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual const ossim_float64 * getMaxPix() const
virtual void refreshEvent(ossimRefreshEvent &event)
virtual ossim_uint32 getNumberOfBands() const
64 bit floating point
16 bit unsigned integer
virtual void setWidthHeight(ossim_uint32 w, ossim_uint32 h)
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
virtual ossimString getEntryString(ossim_int32 entry_number) const
ossimRefPtr< ossimImageData > theTile
virtual double getNullPixelValue(ossim_uint32 band) const
Sets the current resolution level.
virtual ossimString getOutputScalarTypeString() const
16 bit signed integer
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
static const ossimErrorCode OSSIM_ERROR
signed char ossim_sint8
16 bit unsigned integer (13 bits used)
void addConstraint(const ossimString &value)
32 bit floating point
unsigned short ossim_uint16
32 bit unsigned integer
ossimCastTileSourceFilter(ossimImageSource *inputSource=NULL, ossimScalarType scalarType=OSSIM_UCHAR)
virtual void initialize()
Initialize the data buffer.
virtual ossim_int32 getEntryNumber(const char *entry_string, bool case_insensitive=true) const
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
OSSIM_DLL double defaultMin(ossimScalarType scalarType)
Definition: ossimCommon.cpp:73
static ossimImageDataFactory * instance()
yy_size_t size
virtual ossimDataObjectStatus validate() const
signed short ossim_sint16
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual void propertyEvent(ossimPropertyEvent &event)
Override base class so that a disableSource event does not reinitialize the object and enable itself...
32 bit signed integer
OSSIM_DLL double defaultNull(ossimScalarType scalarType)
ossimImageSource * theInputConnection
unsigned int ossim_uint32
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
virtual const ossim_float64 * getNullPix() const
32 bit normalized floating point
virtual void setOutputScalarType(ossimScalarType scalarType)
Sets the output scalar type.
signed int ossim_sint32
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossimScalarType
virtual void setOrigin(const ossimIpt &origin)
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)
void allocate(const ossimRefPtr< ossimImageData > inputTile)
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
OSSIM_DLL double defaultMax(ossimScalarType scalarType)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual ossimErrorCode getErrorStatus() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual const void * getBuf() const
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
static const char * SCALAR_TYPE_KW
void castInputToOutput(inType **inBuffer, const double *nullPix, bool inPartialFlag)
8 bit unsigned integer
ossimRefPtr< ossimImageData > applyCast(ossimRefPtr< ossimImageData > input)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=NULL) const
Method to save the state of an object to a keyword list.
virtual const ossimIpt & getOrigin() const
unsigned char ossim_uint8
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void setCacheRefreshBit()
8 bit unsigned iteger
const ossimString & getName() const
int ossim_int32
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
16 bit unsigned integer (12 bits used)