OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTwoColorView.cpp
Go to the documentation of this file.
1 //-------------------------------------------------------------------
2 // License: LGPL. See top level LICENSE.txt file.
3 //
4 // Author: Garrett Potts
5 //
6 //-------------------------------------------------------------------
7 // $Id$
8 
11 
13  "ossimTwoColorView" ,
15 
17  :
18  ossimImageCombiner(0, 2, 0, true, false) ,
19  m_byPassFlag(true),
20  m_nativeFlag(false),
21  m_newInput(0),
22  m_oldInput(0),
23  m_newInputBandIndex(0),
24  m_oldInputBandIndex(0),
25  m_redSource(ossimTwoColorView::OLD),
26  m_grnSource(ossimTwoColorView::NEW),
27  m_bluSource(ossimTwoColorView::NEW)
28 {
29 }
30 
32 {
34  {
36  }
37  return 3;
38 }
39 
41 {
43  {
45  }
46  return OSSIM_UINT8;
47 }
48 
50  ossim_uint32 oldInputBandIndex,
51  ossim_uint32 newInputBandIndex,
52  ossimTwoColorMultiViewOutputSource redOutputSource,
53  ossimTwoColorMultiViewOutputSource grnOutputSource,
54  ossimTwoColorMultiViewOutputSource bluOutputSource)
55 {
56  m_oldInputBandIndex = oldInputBandIndex;
57  m_newInputBandIndex = newInputBandIndex;
58  m_redSource = redOutputSource;
59  m_grnSource = grnOutputSource;
60  m_bluSource = bluOutputSource;
61 }
62 
64 {
66  {
68  }
69  return 0;
70 }
71 
73 {
75  {
77  }
78  return 1;
79 }
80 
82 {
84  {
86  }
87  return 256;
88 }
89 
91  ossim_uint32 resLevel)
92 {
93  ossim_uint32 tileIdx = 0;
95  {
96  return getNextTile(tileIdx, 0, rect, resLevel);
97  }
98  if(!m_twoColorTile.valid())
99  {
100  allocate();
101  }
102  if(!m_twoColorTile.valid())
103  {
104  return m_twoColorTile;
105  }
108 
109  ossimRefPtr<ossimImageData> newData = m_newInput->getTile(rect, resLevel);
110  ossimRefPtr<ossimImageData> oldData = m_oldInput->getTile(rect, resLevel);
111 
112  runAlgorithm(newData.get(), oldData.get());
113 
115 
116  return m_twoColorTile;
117 }
119 {
120  if(m_nativeFlag)
121  {
122  runNative8(newData, oldData);
123  }
124  else
125  {
126  runNorm(newData, oldData);
127  }
128 }
129 
131 {
132  if ( newData && oldData && m_twoColorTile.valid() &&
133  ( m_twoColorTile->getNumberOfBands() == 3 ) )
134  {
135  // old, new, red, green, blue buffers...
136  ossim_uint8* o = static_cast<ossim_uint8*>( oldData->getBuf(m_oldInputBandIndex) );
137  ossim_uint8* n = static_cast<ossim_uint8*>( newData->getBuf(m_newInputBandIndex) );
138  ossim_uint8* r = static_cast<ossim_uint8*>( m_twoColorTile->getBuf(0) );
139  ossim_uint8* g = static_cast<ossim_uint8*>( m_twoColorTile->getBuf(1) );
140  ossim_uint8* b = static_cast<ossim_uint8*>( m_twoColorTile->getBuf(2) );
141 
142  if ( o && n && r && g && b )
143  {
144  // Assuming null pix of 0 for 8 bit.
145  const ossim_uint8 MP = 1;
146  const ossim_uint8 NP = 0;
147 
148  ossim_uint8 newPix = 0;
149  ossim_uint8 oldPix = 0;
150 
151  const ossim_uint32 MAX_IDX = m_twoColorTile->getSizePerBand();
152 
153  for(ossim_uint32 idx = 0; idx < MAX_IDX; ++idx)
154  {
155  if( ( *n == NP ) && ( *o == NP ) )
156  {
157  // Both inputs null, set all outputs null.
158  *r = NP;
159  *b = NP;
160  *g = NP;
161  }
162  else
163  {
164  // At least one input is not null.
165  newPix = (*n != NP) ? *n : MP;
166  oldPix = (*o != NP) ? *o : MP;
167 
168  // Set red, OLD is default so check first:
170  {
171  *r = oldPix;
172  }
173  else if ( m_redSource == ossimTwoColorView::NEW )
174  {
175  *r = newPix;
176  }
177  else
178  {
179  *r = MP;
180  }
181 
182  // Set green, NEW is default so check first:
184  {
185  *g = newPix;
186  }
187  else if ( m_grnSource == ossimTwoColorView::OLD )
188  {
189  *g = oldPix;
190  }
191  else
192  {
193  *g = MP;
194  }
195 
196  // Set blue, NEW is default so check first:
198  {
199  *b = newPix;
200  }
201  else if ( m_grnSource == ossimTwoColorView::OLD )
202  {
203  *b = oldPix;
204  }
205  else
206  {
207  *b = MP;
208  }
209  }
210 
211  // Next pixel:
212  ++n;
213  ++o;
214  ++r;
215  ++g;
216  ++b;
217  }
218  }
219  }
220 }
221 
223 {
224  if ( newData && oldData && m_twoColorTile.valid() &&
225  ( m_twoColorTile->getNumberOfBands() == 3 ) )
226  {
227  const ossim_uint32 MAX_IDX = m_twoColorTile->getSizePerBand();
228 
229  // Buffers for normalized oldData and newData tiles.
230  std::vector<ossim_float32> oldDataBuffer(MAX_IDX);
231  std::vector<ossim_float32> newDataBuffer(MAX_IDX);
232 
233  // old and new input buffers.
234  ossim_float32* o = &oldDataBuffer.front();
235  ossim_float32* n = &newDataBuffer.front();
236 
237  // Normalize/copy to buffers.
240 
241  // Get the output buffers.
242  ossim_uint8* r = static_cast<ossim_uint8*>( m_twoColorTile->getBuf(0) );
243  ossim_uint8* g = static_cast<ossim_uint8*>( m_twoColorTile->getBuf(1) );
244  ossim_uint8* b = static_cast<ossim_uint8*>( m_twoColorTile->getBuf(2) );
245 
246  if ( o && n && r && g && b )
247  {
248  // Assuming null pix of 0 for 8 bit.
249  const ossim_uint8 MP = 1;
250  const ossim_uint8 NP = 0;
251 
252  ossim_uint8 newPix = 0;
253  ossim_uint8 oldPix = 0;
254  ossim_float32 tmpPix = 0.0;
255 
256  const ossim_uint32 MAX_IDX = m_twoColorTile->getSizePerBand();
257 
258  for(ossim_uint32 idx = 0; idx < MAX_IDX; ++idx)
259  {
260  if( ( *n == NP ) && ( *o == NP ) )
261  {
262  // Both inputs null, set all outputs null.
263  *r = NP;
264  *b = NP;
265  *g = NP;
266  }
267  else
268  {
269  // At least one input is not null.
270 
271  // Set the newPix:
272  if ( *n != NP )
273  {
274  // Un-normalize:
275  tmpPix = (*n) * 255.0;
276 
277  // Clamp to min/max.
278  tmpPix = (tmpPix <= 255.0) ? ( (tmpPix >= 1.0) ? tmpPix : 1.0) : 255.0;
279 
280  // Copy
281  newPix = static_cast<ossim_uint8>( tmpPix );
282  }
283  else
284  {
285  newPix = MP;
286  }
287 
288  // Set the oldPix:
289  if ( *o != NP )
290  {
291  // Un-normalize:
292  tmpPix = (*o) * 255.0;
293 
294  // Clamp to min/max.
295  tmpPix = (tmpPix <= 255.0) ? ( (tmpPix >= 1.0) ? tmpPix : 1.0) : 255.0;
296 
297  // Copy
298  oldPix = static_cast<ossim_uint8>( tmpPix );
299  }
300  else
301  {
302  oldPix = MP;
303  }
304 
305  // Set red, OLD is default so check first:
307  {
308  *r = oldPix;
309  }
310  else if ( m_redSource == ossimTwoColorView::NEW )
311  {
312  *r = newPix;
313  }
314  else
315  {
316  *r = MP;
317  }
318 
319  // Set green, NEW is default so check first:
321  {
322  *g = newPix;
323  }
324  else if ( m_grnSource == ossimTwoColorView::OLD )
325  {
326  *g = oldPix;
327  }
328  else
329  {
330  *g = MP;
331  }
332 
333  // Set blue, NEW is default so check first:
335  {
336  *b = newPix;
337  }
338  else if ( m_grnSource == ossimTwoColorView::OLD )
339  {
340  *b = oldPix;
341  }
342  else
343  {
344  *b = MP;
345  }
346  }
347 
348  // Next pixel:
349  ++n;
350  ++o;
351  ++r;
352  ++g;
353  ++b;
354  }
355  }
356  }
357 }
358 
360 {
362  if(m_twoColorTile.valid())
363  {
365  }
366 }
367 
368 
370 {
372  m_newInput = 0;
373  m_oldInput = 0;
374  m_twoColorTile = 0;
375  m_nativeFlag = false;
376  m_byPassFlag = false;
377 
378  if(getNumberOfInputs() < 2)
379  {
380  m_byPassFlag = true;
381  }
382  else
383  {
384  m_oldInput = dynamic_cast<ossimImageSource*>( getInput(0) );
385  m_newInput = dynamic_cast<ossimImageSource*>( getInput(1) );
386 
387  //---
388  // Range check band selection. This can be set from setBandIndexMapping method which
389  // does no error checking because inputs may not be set.
390  //----
391  if ( m_oldInput.valid() )
392  {
394  {
396  }
397  }
398 
399  if ( m_newInput.valid() )
400  {
402  {
404  }
405  }
406 
407  if(!m_newInput||!m_oldInput)
408  {
409  m_byPassFlag = true;
410  }
411  else
412  {
415  {
416  m_nativeFlag = true;
417  }
418  }
419  }
420 }
ossimRefPtr< ossimImageSource > m_oldInput
ossimTwoColorMultiViewOutputSource m_grnSource
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual void initialize()
virtual ossim_uint32 getNumberOfBands() const
This is a 2 color view of the input.
virtual void setImageRectangle(const ossimIrect &rect)
void runAlgorithm(ossimImageData *newData, ossimImageData *oldData)
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
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
float ossim_float32
virtual void copyTileBandToNormalizedBuffer(ossim_uint32 band, ossim_float64 *buf) const
Will copy this tiles specified band number to the normalized buffer.
double getMinPixelValue(ossim_uint32 band) const
Returns the min pixel of the band.
double getMaxPixelValue(ossim_uint32 band) const
Returns the max pixel of the band.
void setBandIndexMapping(ossim_uint32 oldInputBandIndex, ossim_uint32 newInputBandIndex, ossimTwoColorMultiViewOutputSource redOutputSource, ossimTwoColorMultiViewOutputSource grnOutputSource, ossimTwoColorMultiViewOutputSource bluOutputSource)
Sets which bands to use from inputs, and which inputs to use for output red, green and blue channels...
ossimTwoColorMultiViewOutputSource m_bluSource
virtual void initialize()
Initialize the data buffer.
void runNorm(ossimImageData *newData, ossimImageData *oldData)
ossim_uint32 m_oldInputBandIndex
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
RTTI_DEF1(ossimTwoColorView, "ossimTwoColorView", ossimImageCombiner)
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 &returnedIdx, const ossim_uint32 startIdx, const ossimIrect &tileRect, ossim_uint32 resLevel=0)
static ossimImageDataFactory * instance()
ossim_uint32 m_newInputBandIndex
virtual ossimDataObjectStatus validate() const
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
os2<< "> n<< " > nendobj n
ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual ossim_uint32 getSizePerBand() const
Returns the number of pixels in a single band in a tile.
ossimTwoColorMultiViewOutputSource m_redSource
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
unsigned int ossim_uint32
ossimRefPtr< ossimImageData > m_twoColorTile
double getNullPixelValue(ossim_uint32 band) const
Each band has a null pixel associated with it.
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossimScalarType
ossimRefPtr< ossimImageSource > m_newInput
virtual void makeBlank()
Initializes data to null pixel values.
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
virtual const void * getBuf() const
virtual ossim_uint32 getNumberOfInputs() const
Returns the number of input objects.
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
8 bit unsigned integer
void runNative8(ossimImageData *newData, ossimImageData *oldData)
ossimTwoColorMultiViewOutputSource
Enumerations for mapping inputs to red, green and blue output channels.
unsigned char ossim_uint8
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)