OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimBandMergeSource.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: ossimBandMergeSource.cpp 23611 2015-11-06 19:37:12Z gpotts $
15 #include <ossim/base/ossimIrect.h>
16 
17 RTTI_DEF1(ossimBandMergeSource, "ossimBandMergeSource", ossimImageCombiner)
18 
21  theNumberOfOutputBands(0),
22  theTile(NULL)
23 {
24 }
25 
27  :ossimImageCombiner(inputSources),
28  theNumberOfOutputBands(0),
29  theTile(NULL)
30 {
31  initialize();
32 }
33 
35 {
37 }
38 
40  ossim_uint32 resLevel)
41 {
42  ossim_uint32 layerIdx = 0;
43  if( ( getNumberOfInputs() == 1) || !isSourceEnabled() )
44  {
45  return getNextTile(layerIdx, 0, tileRect, resLevel);
46  }
47 
48  // test if initialized
49  if(!theTile.get())
50  {
51  allocate();
52  }
53 
54  if(!theTile.get())
55  {
56  return getNextTile(layerIdx, 0, tileRect, resLevel);
57  }
58 
59  long w = tileRect.width();
60  long h = tileRect.height();
61  long tileW = theTile->getWidth();
62  long tileH = theTile->getHeight();
63  if ((w != tileW) || (h != tileH))
64  {
65  theTile->setWidth(w);
66  theTile->setHeight(h);
67  if((w*h)!=(tileW*tileH))
68  {
70  }
71  else
72  {
73  theTile->makeBlank();
74  }
75  }
76  else
77  {
78  theTile->makeBlank();
79  }
80 
81  theTile->setOrigin(tileRect.ul());
82  getTile(theTile.get(), resLevel);
83 
84  return theTile;
85 }
86 
88 {
89  if (!tile)
90  return false;
91 
92  ossim_uint32 layerIdx = 0;
93  if( ( getNumberOfInputs() == 1) || !isSourceEnabled() )
94  {
95  return getNextTile(layerIdx, 0, tile, resLevel);
96  }
97 
98  tile->makeBlank();
99  ossim_uint32 currentBand = 0;
100  ossim_uint32 maxBands = tile->getNumberOfBands();
101  ossim_uint32 inputIdx = 0;
102  ossimRefPtr<ossimImageData> currentTile;
103  for(inputIdx = 0; inputIdx < getNumberOfInputs(); ++inputIdx)
104  {
105  ossimImageSource* input = PTR_CAST(ossimImageSource, getInput(inputIdx));
106  ossim_uint32 maxInputBands = 1;
107 
108  if(input)
109  {
110  currentTile = input->getTile(tile->getImageRectangle(), resLevel);
111  if(currentTile.valid())
112  {
113  maxInputBands = currentTile->getNumberOfBands();
114  //std::cout << "MAX INPUT BANDS === " << maxInputBands << "\n";
115  if (maxInputBands == 0)
116  maxInputBands = 1;
117  }
118  }
119  else
120  {
121  currentTile = 0;
122  }
123 
124  if(currentTile.valid()&&(currentTile->getBuf()))
125  {
126  for(ossim_uint32 band = 0; (band < maxInputBands) && (currentBand < maxBands); ++band)
127  {
128  //std::cout << "Actual Band, BAND == " << currentBand << ", " << band << "\n";
129  // clear the band with the actual NULL
130  tile->fill(currentBand, tile->getNullPix(band));
131 
132  if(currentTile.valid())
133  {
134  if((currentTile->getDataObjectStatus() != OSSIM_NULL) &&
135  (currentTile->getDataObjectStatus() != OSSIM_EMPTY))
136  {
137  memmove(tile->getBuf(currentBand),
138  currentTile->getBuf(band),
139  currentTile->getSizePerBandInBytes());
140  }
141  }
142  ++currentBand;
143  }
144  }
145  }
146  tile->validate();
147  return true;
148 }
149 
151 {
152  ossim_uint32 currentBandCount = 0;
153  ossim_uint32 idx = 0;
154 
156  if(!maxBands) return 0.0;
157 
158  while((currentBandCount < maxBands)&&
159  (idx < getNumberOfInputs()))
160  {
162  if(temp)
163  {
164  ossim_uint32 previousCount = currentBandCount;
165  currentBandCount += temp->getNumberOfOutputBands();
166 
167  if(band < currentBandCount)
168  {
169  return temp->getNullPixelValue(band - previousCount);
170  }
171  }
172  ++idx;
173  }
174 
175  return ossim::nan();
176 }
177 
179 {
180  ossim_uint32 currentBandCount = 0;
181  ossim_uint32 idx = 0;
182 
184  if(!maxBands) return 0.0;
185 
186  while((currentBandCount < maxBands)&&
187  (idx < getNumberOfInputs()))
188  {
190  if(temp)
191  {
192  ossim_uint32 previousCount = currentBandCount;
193  currentBandCount += temp->getNumberOfOutputBands();
194 
195  if(band < currentBandCount)
196  {
197  return temp->getMinPixelValue(band - previousCount);
198  }
199  }
200  ++idx;
201  }
202 
203  return 0.0;
204 }
205 
207 {
208  ossim_uint32 currentBandCount = 0;
209  ossim_uint32 idx = 0;
210 
212  if(!maxBands) return 0.0;
213 
214  while((currentBandCount < maxBands)&&
215  (idx < getNumberOfInputs()))
216  {
218  if(temp)
219  {
220  ossim_uint32 previousCount = currentBandCount;
221  currentBandCount += temp->getNumberOfOutputBands();
222 
223  if(band < currentBandCount)
224  {
225  return temp->getMaxPixelValue(band - previousCount);
226  }
227  }
228  ++idx;
229  }
230 
231  return ossim::nan();
232 }
233 
235 {
237 
238  if(theTile.get())
239  {
240  theTile = NULL;
241  }
242 
244 }
245 
247 {
249  {
251  this);
252  theTile->initialize();
253  }
254 }
255 
257 {
258  ossim_uint32 result = 0;
260  for(ossim_uint32 index = 0; index < size; ++index)
261  {
263  if(temp)
264  {
265  if(temp->getNumberOfOutputBands() == 0)
266  {
267  ++result;
268  }
269  else
270  {
271  result += temp->getNumberOfOutputBands();
272  }
273  }
274  }
275  return result;
276 }
277 
279 {
281  {
282  return computeNumberOfInputBands();
283  }
284 
285  return theNumberOfOutputBands;
286 }
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
void fill(ossim_uint32 band, ossim_float64 value)
will fill the entire band with the value.
virtual ossim_uint32 getNumberOfBands() const
This will be a base for all combiners.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
bool valid() const
Definition: ossimRefPtr.h:75
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
ossim_uint32 height() const
Definition: ossimIrect.h:487
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual void initialize()
Initialize the data buffer.
ossim_uint32 theNumberOfOutputBands
void allocate()
Performs allocation of "theTile".
virtual ossim_uint32 getSizePerBandInBytes() const
Returns the number of bytes in single band of the tile.
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
virtual void setHeight(ossim_uint32 height)
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 &returnedIdx, const ossim_uint32 startIdx, const ossimIrect &tileRect, ossim_uint32 resLevel=0)
std::vector< ossimRefPtr< ossimConnectableObject > > ConnectableObjectList
static ossimImageDataFactory * instance()
yy_size_t size
virtual ossimDataObjectStatus validate() const
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
ossimRefPtr< ossimImageData > theTile
virtual void setWidth(ossim_uint32 width)
virtual ossimIrect getImageRectangle() const
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
ossim_uint32 width() const
Definition: ossimIrect.h:500
virtual void setOrigin(const ossimIpt &origin)
ossim_uint32 computeNumberOfInputBands() const
virtual void makeBlank()
Initializes data to null pixel values.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual const void * getBuf() const
virtual ossim_uint32 getNumberOfInputs() const
Returns the number of input objects.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
This will merge all the bands from the input source list into one contiguous ossimImageData object...
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)