OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageStatisticsSource.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 //
9 //*************************************************************************
14 
16  :ossimSource(0,
17  1,
18  0,
19  true,
20  false)
21 {
22 }
23 
25 {
26 
27 }
28 
30 {
32  getInput());
33 
34  if(anInterface&&isSourceEnabled())
35  {
37  ossimScalarType outputScalarType = anInterface->getOutputScalarType();
38 
39  switch(outputScalarType)
40  {
41  case OSSIM_UCHAR:
42  {
44  break;
45  }
46  case OSSIM_USHORT16:
47  case OSSIM_USHORT11:
48  case OSSIM_USHORT12:
49  case OSSIM_USHORT13:
50  case OSSIM_USHORT14:
51  case OSSIM_USHORT15:
52  {
54  break;
55  }
56  case OSSIM_SSHORT16:
57  {
59  break;
60  }
61  case OSSIM_DOUBLE:
63  {
65  break;
66  }
67  case OSSIM_FLOAT:
69  {
71  break;
72  }
73  default :
74  {
75  break;
76  }
77  }
78  }
79 }
80 
82  const ossimConnectableObject* object)const
83 {
84  return (PTR_CAST(ossimImageSource, object)&&(inputIndex < 1));
85 }
86 
87 template <class T>
89 {
91 
92  sequencer->connectMyInputTo(getInput());
93  sequencer->setToStartOfSequence();
94  ossim_uint32 bands = sequencer->getNumberOfOutputBands();
95 
96  if(bands)
97  {
98  setStatsSize(bands);
99  ossimRefPtr<ossimImageData> dataObject;
100 
101  while( (dataObject=sequencer->getNextTile()).valid() )
102  {
103  ossim_uint32 bandIdx = 0;
104  bands = dataObject->getNumberOfBands();
106  if((status != OSSIM_EMPTY)&&
107  (dataObject->getBuf()))
108  {
109  ossim_uint32 offsetMax = dataObject->getWidth()*dataObject->getHeight();
110  for(bandIdx = 0; bandIdx < bands; ++bandIdx)
111  {
112  ossim_float64 pixelCount = 0.0;
113  ossim_uint32 offset = 0;
114  T* dataPtr = static_cast<T*>(dataObject->getBuf(bandIdx));
115  T nullPixel = static_cast<T>(dataObject->getNullPix(bandIdx));
116  for(offset = 0; offset < offsetMax; ++offset)
117  {
118  if((*dataPtr) != nullPixel)
119  {
120  theMean[bandIdx] += *dataPtr;
121  if((*dataPtr) < theMin[bandIdx])
122  {
123  theMin[bandIdx] = (*dataPtr);
124  }
125  if((*dataPtr) > theMax[bandIdx])
126  {
127  theMax[bandIdx] = (*dataPtr);
128  }
129  ++pixelCount;
130  }
131  ++dataPtr;
132  }
133  if(pixelCount > 0)
134  {
135  theMean[bandIdx] /= pixelCount;
136  }
137  }
138  }
139  }
140  }
141 
142  sequencer->disconnect();
143  sequencer = 0;
144 }
145 
146 const std::vector<ossim_float64>& ossimImageStatisticsSource::getMean()const
147 {
148  return theMean;
149 }
150 
151 const std::vector<ossim_float64>& ossimImageStatisticsSource::getMin()const
152 {
153  return theMin;
154 }
155 
156 const std::vector<ossim_float64>& ossimImageStatisticsSource::getMax()const
157 {
158  return theMax;
159 }
160 
162 {
163  theMean.clear();
164  theMin.clear();
165  theMax.clear();
166 }
167 
169 {
170  theMean.resize(size);
171  theMin.resize(size);
172  theMax.resize(size);
173 
174  std::fill(theMean.begin(),
175  theMean.end(),
176  (ossim_float64)0.0);
177  std::fill(theMin.begin(),
178  theMin.end(),
180  std::fill(theMax.begin(),
181  theMax.end(),
183 }
16 bit unsigned integer (15 bits used)
virtual ossim_uint32 getWidth() const
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
const std::vector< ossim_float64 > & getMax() const
virtual ossim_uint32 getNumberOfBands() const
virtual void disconnect(ossimConnectableObject *object=0)
Will disconnect the object passed in.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
#define OSSIM_DEFAULT_MAX_PIX_DOUBLE
float ossim_float32
const std::vector< ossim_float64 > & getMin() const
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
virtual bool canConnectMyInputTo(ossim_int32 inputIndex, const ossimConnectableObject *object) const
required to be overriden by derived classes
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossim_uint32 getHeight() const
16 bit unsigned integer (14 bits used)
16 bit unsigned integer (13 bits used)
unsigned short ossim_uint16
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
double ossim_float64
const std::vector< ossim_float64 > & getMean() const
#define OSSIM_DEFAULT_MIN_PIX_DOUBLE
yy_size_t size
signed short ossim_sint16
std::vector< ossim_float64 > theMean
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
32 bit normalized floating point
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
std::vector< ossim_float64 > theMax
ossimScalarType
return status
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual const void * getBuf() const
std::vector< ossim_float64 > theMin
ossimDataObjectStatus
Definitions for data object status.
32 bit floating point
16 bit unsigned iteger
64 bit floating point
16 bit signed integer
unsigned char ossim_uint8
8 bit unsigned iteger
void computeStatisticsTemplate(T dummyVariable)
int ossim_int32
16 bit unsigned integer (12 bits used)