OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageSourceSequencer.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: MIT
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 // Description:
11 //
12 //*******************************************************************
13 // $Id$
14 
17 #include <ossim/base/ossimDrect.h>
18 #include <ossim/base/ossimIrect.h>
19 #include <ossim/base/ossimTrace.h>
24 
25 RTTI_DEF2(ossimImageSourceSequencer, "ossimImageSourceSequencer",
27 
28 static ossimTrace traceDebug("ossimImageSourceSequencer:debug");
29 
31  ossimObject* owner)
32 :ossimImageSource(owner,
33  1,
34  1,
35  true,
36  false),
37  theBlankTile(NULL),
38  theAreaOfInterest(0,0,0,0),
40  theNumberOfTilesHorizontal(0),
41  theNumberOfTilesVertical(0),
42  theCurrentTileNumber(0),
43  theCreateHistogram(false)
44 {
47  theInputConnection = inputSource;
48  if(inputSource)
49  {
50  connectMyInputTo(0, inputSource);
51  initialize(); // Derived class depends on this initialization to happen now. DO NOT MOVE.
52  }
54 }
55 
57 {
59 }
60 
62 {
64 }
65 
66 
68 {
70 }
71 
73 {
75 }
76 
78 {
80  {
82  }
83 
84  return OSSIM_SCALAR_UNKNOWN;
85 }
86 
88 {
89  return theTileSize;
90 }
91 
93 {
94  theTileSize = tileSize;
96 // initialize();
97 }
98 
100 {
101  setTileSize(ossimIpt(width, height));
102 }
103 
105 {
106  bool status = false;
108  {
110  ossim_float64 aoiHeight = theAreaOfInterest.height();
111  ossim_float64 tileWidth = theTileSize.x;
112  ossim_float64 tileHeight = theTileSize.y;
113 
114  if ( (aoiWidth > 0.0) && (aoiHeight > 0.0) &&
115  (tileWidth > 0.0) && (tileHeight > 0.0) )
116  {
118  = static_cast<ossim_int64>(std::ceil(aoiWidth/tileWidth));
120  = static_cast<ossim_int64>(std::ceil(aoiHeight/tileHeight));
121  status = true;
122  }
123  }
124 
125  if ( !status )
126  {
129  }
130 }
131 
133 {
135 
137  {
138  if(theTileSize.hasNans())
139  {
142  }
143 
145  if(rect.hasNans())
146  {
148  }
149  else
150  {
151  rect.stretchOut();
152  setAreaOfInterest(rect);
153  }
155 
157  this);
158  if(theBlankTile.valid())
159  {
161  }
162  }
163 }
164 
166  const ossimConnectableObject* object)const
167 {
168  return (object&& PTR_CAST(ossimImageSource, object));
169 }
170 
172 {
173  initialize();
174 }
175 
177 {
179 }
180 
182 {
183  ossimDrect temp;
184  temp.makeNan();
185 
186  if(!theInputConnection) return temp;
187 
189  {
190  return theInputConnection->getBoundingRect(resLevel);
191  }
192 
193  return theAreaOfInterest;
194 }
195 
197  ossimDpt& result) const
198 {
200  {
201  theInputConnection->getDecimationFactor(resLevel, result);
202  }
203  result.makeNan();
204 }
205 
206 void ossimImageSourceSequencer::getDecimationFactors(vector<ossimDpt>& decimations) const
207 {
209  {
211  }
212 }
213 
215 {
216  ossim_uint32 result = 0;
218  {
220  }
221  return result;
222 }
223 
225 {
226  if(areaOfInterest.hasNans())
227  {
231  }
232 
233  // let's round it to the nearest pixel value before setting it.
234  theAreaOfInterest = areaOfInterest;
236 }
237 
239 {
240  return theAreaOfInterest;
241 }
242 
244 {
246 }
247 
249  const ossimIrect& rect, ossim_uint32 /* resLevel */ )
250 {
252  {
253  /*
254  ossimRefPtr<ossimImageData> tile =
255  theInputConnection->getTile(rect, resLevel);
256  if (tile.valid()&&tile->getBuf())
257  {
258  return tile;
259  }
260  else
261  {
262  // We should return a valid tile for the writers.
263  theBlankTile->setImageRectangle(rect);
264  return theBlankTile;
265  }
266  */
267  // For Use with multithreaded sequencer
269  tile->setImageRectangle(rect);
270  tile->initialize();
271  tile->makeBlank();
273  ossim_uint32 num_tiles = getNumberOfTiles();
274  // bool hasHistoOutput = true;
275  ossim_uint32 numberOfBands = 1;
276  ossim_uint32 numberOfBins = 0;
277  ossim_float64 minValue = 0;
278  ossim_float64 maxValue = 0;
279  ossimScalarType stype;
281 
282  if (theCreateHistogram)
283  {
284  stype = tile->getScalarType();
285  histogram = new ossimMultiResLevelHistogram;
286  histogram->create(1);
287  numberOfBands = tile->getNumberOfBands();
288 
289  getBinInformation(numberOfBins, minValue, maxValue, stype);
290  histogram->getMultiBandHistogram(0)->create(numberOfBands, numberOfBins, minValue, maxValue);
291 
292  }
293  for (ossim_uint32 tile_idx=0; tile_idx<num_tiles; ++tile_idx)
294  {
296  //tile->setDataObjectStatus(imagedata->getDataObjectStatus());
297  if(imagedata->getBuf() && (imagedata->getDataObjectStatus()!=OSSIM_EMPTY))
298  {
299  tile->loadTile(imagedata.get());
300  if (theCreateHistogram)
301  {
302  imagedata->populateHistogram(histogram->getMultiBandHistogram(0));
303  }
304  }
305  if (traceDebug())
306  {
307  ossimNotify(ossimNotifyLevel_WARN)<< "BASE SEQUENCER TILE " << tile_idx << " RECT: " << rect << std::endl;;
308  }
309  }
310  tile->validate();
311  if (theCreateHistogram) tile->setHistogram(histogram);
312  return tile;
313  }
314 
315  return 0;
316 }
317 
319 {
320  ossimRefPtr<ossimImageData> result = 0;
321  if ( theInputConnection )
322  {
323  ossimIrect tileRect;
324  if ( getTileRect( theCurrentTileNumber, tileRect ) )
325  {
327  result = theInputConnection->getTile(tileRect, resLevel);
328  if( !result.valid() || !result->getBuf() )
329  {
330  theBlankTile->setImageRectangle(tileRect);
331  result = theBlankTile;
332  }
333  }
334  }
335  return result;
336 }
337 
339 {
340  return false;
341 }
342 
344  ossim_int64 id, ossim_uint32 resLevel)
345 {
346  static const char* MODULE= "ossimImageSourceSequencer::getTile(id, resLevel)";
347  if(traceDebug())
348  {
349  CLOG << "entering.."<<endl;
350  }
351 
352  ossimRefPtr<ossimImageData> result = 0;
353 
355  {
356  // if we have no tiles try to initialize.
357  if(getNumberOfTiles() == 0)
358  {
359  initialize();
360  }
361 
362  ossimIrect tileRect;
363  if ( getTileRect( id, tileRect ) )
364  {
365  result = theInputConnection->getTile(tileRect, resLevel);
366  if( !result.valid() || !result->getBuf() )
367  {
368  theBlankTile->setImageRectangle(tileRect);
369  result = theBlankTile;
370  }
371  }
372  else // getTileRect failed...
373  {
374  if(traceDebug())
375  {
376  CLOG << "was not able to get an origin for id = " << id << endl;
377  }
378  }
379  }
380  else // no connection...
381  {
382  if(traceDebug())
383  {
384  CLOG << "No input connection so returing NULL" << endl;
385  }
386  }
387  if(traceDebug())
388  {
389  CLOG << "leaving.."<<endl;
390  }
391 
392  return result;
393 }
394 
396 {
397  bool result = false;
398  if( id >= 0 )
399  {
401  {
405  {
409  ossim_int64 ty = theTileSize.y;
410  x = ulx + x * tx;
411  y = uly + y * ty;
412 
413  //---
414  // ossimIpt currently signed 32 bit so make sure we didn't bust the
415  // bounds.
416  //---
418  {
419  origin.x = (ossim_int32)x;
420  origin.y = (ossim_int32)y;
421  result = true;
422  }
423  }
424  }
425  }
426  return result;
427 }
428 
430 {
431  // Fetch tile origin for this tile:
432  ossimIpt origin;
433  bool result = getTileOrigin(tile_id, origin);
434  if ( result )
435  {
436  // Establish the tile rect of interest for this tile:
437  tileRect.set_ul (origin);
438  tileRect.set_lrx(origin.x + theTileSize.x - 1);
439  tileRect.set_lry(origin.y + theTileSize.y - 1);
440  }
441  return result;
442 }
443 
445 {
446  if (theInputConnection)
447  {
449  }
450 
452 }
453 
455 {
456  if (theInputConnection)
457  {
458  return theInputConnection->getMinPixelValue(band);
459  }
460 
462 }
463 
465 {
466  if (theInputConnection)
467  {
468  return theInputConnection->getMaxPixelValue(band);
469  }
470 
472 }
473 
475 {
477  {
479  }
480 
481  return 0;
482 }
483 
485 {
486  return theTileSize.x;
487 }
488 
490 {
491  return theTileSize.y;
492 }
493 
495 {
496 }
497 
499 {
500  return true;
501 }
502 
504  ossim_float64& minValue,
505  ossim_float64& maxValue,
506  ossimScalarType stype)const
507 {
508  numberOfBins = 0;
509  minValue = 0;
510  maxValue = 0;
511 
512  switch(stype)
513  {
514  case OSSIM_UINT8:
515  {
516  minValue = 0;
517  maxValue = OSSIM_DEFAULT_MAX_PIX_UCHAR;
518  numberOfBins = 256;
519 
520  break;
521  }
522  case OSSIM_USHORT11:
523  {
524  minValue = 0;
525  maxValue = OSSIM_DEFAULT_MAX_PIX_UINT11;
526  numberOfBins = OSSIM_DEFAULT_MAX_PIX_UINT11 + 1;
527 
528  break;
529  }
530  case OSSIM_USHORT12:
531  {
532  minValue = 0;
533  maxValue = OSSIM_DEFAULT_MAX_PIX_UINT12;
534  numberOfBins = OSSIM_DEFAULT_MAX_PIX_UINT12 + 1;
535 
536  break;
537  }
538  case OSSIM_USHORT13:
539  {
540  minValue = 0;
541  maxValue = OSSIM_DEFAULT_MAX_PIX_UINT13;
542  numberOfBins = OSSIM_DEFAULT_MAX_PIX_UINT13 + 1;
543 
544  break;
545  }
546  case OSSIM_USHORT14:
547  {
548  minValue = 0;
549  maxValue = OSSIM_DEFAULT_MAX_PIX_UINT14;
550  numberOfBins = OSSIM_DEFAULT_MAX_PIX_UINT14 + 1;
551 
552  break;
553  }
554  case OSSIM_USHORT15:
555  {
556  minValue = 0;
557  maxValue = OSSIM_DEFAULT_MAX_PIX_UINT15;
558  numberOfBins = OSSIM_DEFAULT_MAX_PIX_UINT15 + 1;
559 
560  break;
561  }
562  case OSSIM_UINT16:
563  case OSSIM_UINT32:
564  {
565  minValue = 0;
566  maxValue = OSSIM_DEFAULT_MAX_PIX_UINT16;
567  numberOfBins = OSSIM_DEFAULT_MAX_PIX_UINT16 + 1;
568 
569  break;
570  }
571  case OSSIM_SINT16:
572  case OSSIM_SINT32:
573  case OSSIM_FLOAT32:
574  case OSSIM_FLOAT64:
575  {
576  minValue = OSSIM_DEFAULT_MIN_PIX_SINT16;
577  maxValue = OSSIM_DEFAULT_MAX_PIX_SINT16;
579 
580  break;
581  }
584  {
585  minValue = 0;
586  maxValue = 1.0;
587  numberOfBins = OSSIM_DEFAULT_MAX_PIX_UINT16+1;
588  break;
589  }
590  default:
591  {
592  if(traceDebug())
593  {
595  << "Unsupported scalar type in ossimImageHistogramSource::computeHistogram()" << endl;
596  }
597  return;
598  }
599  }
600 
601 }
602 
603 bool ossimImageSourceSequencer::loadState(const ossimKeywordlist& kwl, const char* prefix)
604 {
605  const char* lookup;
606  lookup = kwl.find(prefix, "create_histogram");
607  if(lookup)
608  {
609  bool create_histogram = ossimString(lookup).toBool();
610  setCreateHistogram(create_histogram);
611  }
612  bool status = ossimImageSource::loadState(kwl, prefix);
613 
614  return status;
615 }
616 
618 {
619  theCreateHistogram = create_histogram;
620 }
621 
16 bit unsigned integer (15 bits used)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
#define OSSIM_DEFAULT_MAX_PIX_UINT16
void makeNan()
Definition: ossimDrect.h:388
ossim_uint32 x
virtual bool addListener(ossimListener *listener)
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual ossim_uint32 getNumberOfBands() const
64 bit floating point
#define CLOG
Definition: ossimTrace.h:23
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual void setImageRectangle(const ossimIrect &rect)
16 bit unsigned integer
virtual void getDecimationFactor(ossim_uint32 resLevel, ossimDpt &result) const
Will return the decimation factor for the given resolution level.
virtual ossim_uint32 getTileWidth() const
Returns the default processing tile width.
virtual void populateHistogram(ossimRefPtr< ossimMultiBandHistogram > histo)
Represents serializable keyword/value map.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
#define OSSIM_DEFAULT_MAX_PIX_UCHAR
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
const char * find(const char *key) const
void getBinInformation(ossim_uint32 &numberOfBins, ossim_float64 &minValue, ossim_float64 &maxValue, ossimScalarType stype) const
ossim_uint32 height() const
Definition: ossimIrect.h:487
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
bool getTileRect(ossim_int64 tile_id, ossimIrect &rect) const
Establishes a tile rect given tile ID.
OSSIM_DLL void defaultTileSize(ossimIpt &tileSize)
16 bit signed integer
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimDataObjectStatus getDataObjectStatus() const
16 bit unsigned integer (14 bits used)
void create(ossim_uint32 numberOfResLevels)
16 bit unsigned integer (13 bits used)
virtual ossim_uint32 getNumberOfDecimationLevels() const
Will return the number of resolution levels.
32 bit floating point
32 bit unsigned integer
virtual ossim_uint32 getNumberOfInputBands() const
virtual void initialize()
Initialize the data buffer.
virtual ossim_uint32 getTileWidth() const
Returns the default processing tile width.
#define OSSIM_DEFAULT_TILE_WIDTH
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
void set_ul(const ossimIpt &pt)
Definition: ossimIrect.h:589
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
double ossim_float64
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
static ossimImageDataFactory * instance()
virtual void setAreaOfInterest(const ossimIrect &areaOfInterest)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
#define OSSIM_DEFAULT_MAX_PIX_UINT12
#define OSSIM_DEFAULT_MIN_PIX_SINT16
virtual void connectInputEvent(ossimConnectionEvent &event)
void setCreateHistogram(bool create_histogram)
virtual ossimDataObjectStatus validate() const
RTTI_DEF2(ossimImageSourceSequencer, "ossimImageSourceSequencer", ossimImageSource, ossimConnectableObjectListener)
virtual bool getTileOrigin(ossim_int64 id, ossimIpt &origin) const
32 bit signed integer
bool toBool() const
String to numeric methods.
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
#define OSSIM_DEFAULT_MAX_PIX_UINT15
unsigned int ossim_uint32
32 bit normalized floating point
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
#define OSSIM_DEFAULT_MAX_PIX_UINT13
ossimImageSourceSequencer(ossimImageSource *inputSource=NULL, ossimObject *owner=NULL)
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
bool hasNans() const
Definition: ossimDrect.h:396
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossim_uint32 width() const
Definition: ossimIrect.h:500
#define OSSIM_DEFAULT_MAX_PIX_SINT16
bool loadState(const ossimKeywordlist &kwl, const char *prefix)
Method to the load (recreate) the state of an object from a keyword list.
ossimScalarType
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual void disconnectInputEvent(ossimConnectionEvent &event)
void set_lrx(ossim_int32 x)
Definition: ossimIrect.h:693
return status
virtual bool getNextTileStream(std::ostream &bos)
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)
ossim_int64 getNumberOfTilesHorizontal() const
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
void set_lry(ossim_int32 y)
Definition: ossimIrect.h:702
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
#define OSSIM_DEFAULT_MAX_PIX_UINT14
ossim_int32 y
Definition: ossimIpt.h:142
void makeNan()
Definition: ossimIrect.h:329
virtual const void * getBuf() const
virtual ossim_uint32 getNumberOfDecimationLevels() const
Will return the number of resolution levels.
#define OSSIM_DEFAULT_MAX_PIX_UINT11
#define OSSIM_DEFAULT_TILE_HEIGHT
long long ossim_int64
#define OSSIM_DEFAULT_MAX_PIX_SINT32
virtual ossimIpt getTileSize() const
bool hasNans() const
Definition: ossimIrect.h:337
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
const ossimIrect & getAreaOfInterest() const
ossim_int32 x
Definition: ossimIpt.h:141
8 bit unsigned integer
bool hasNans() const
Definition: ossimIpt.h:58
virtual void setTileSize(const ossimIpt &tileSize)
ossimRefPtr< ossimImageData > theBlankTile
ossimRefPtr< ossimMultiBandHistogram > getMultiBandHistogram(ossim_uint32 resLevel) const
virtual void getDecimationFactor(ossim_uint32 resLevel, ossimDpt &result) const
Will return the decimation factor for the given resolution level.
virtual bool canConnectMyInputTo(ossim_int32 inputIndex, const ossimConnectableObject *object) const
required to be overriden by derived classes
void create(const ossimImageSource *input)
virtual void getDecimationFactors(vector< ossimDpt > &decimations) const
void stretchOut()
Definition: ossimDrect.cpp:379
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)
ossim_int64 getNumberOfTilesVertical() const
void makeNan()
Definition: ossimDpt.h:65
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
virtual void getDecimationFactors(std::vector< ossimDpt > &decimations) const
Will return an array of all decimations for each resolution level.
int ossim_int32
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
16 bit unsigned integer (12 bits used)
virtual void setHistogram(ossimRefPtr< ossimMultiResLevelHistogram > histo)
virtual bool removeListener(ossimListener *listener)