39 # define MAX(x,y) ((x)>(y)?(x):(y)) 40 # define MIN(x,y) ((x)>(y)?(y):(x)) 44 static const int MEAN_FLAG = 1, SD_FLAG = 2;
48 m_statsConsistent(MEAN_FLAG | SD_FLAG),
49 m_vals(new float [1]),
50 m_counts(new float [1]),
64 m_statsConsistent(MEAN_FLAG | SD_FLAG),
65 m_vals(new float [xres]),
66 m_counts(new float [xres]),
97 fprintf(stderr,
"Histogram : Ran out of memory for arrays.\n");
108 for(i = 0; i < xres; i++)
119 m_statsConsistent(MEAN_FLAG | SD_FLAG),
129 if ( ( xres >= 2 ) && uvals && ucounts )
142 m_statsConsistent(0),
152 if ((
size == 0) || (xres == 0))
160 if ((
float)(data[i]) <
m_vmin)
161 m_vmin = (float)(data[i]);
162 else if ((
float)(data[i]) >
m_vmax)
163 m_vmax = (float)(data[i]);
188 m_statsConsistent(0),
203 const float* his_vals = his.
GetVals();
206 const float* his_counts = his.
GetCounts();
210 fprintf(stderr,
"Histogram : Ran out of memory for arrays.\n");
224 for(i=0; i<
m_num; i++)
243 m_statsConsistent(0),
259 int max_index = his->
GetRes() - 1;
260 float minvalue = his->
GetVals()[0] - del*.5f;
261 float maxvalue = his->
GetVals()[max_index] + del*.5f;
266 else if(!(width == 0.0))
267 m_num = (int)ceil((maxvalue - minvalue)/width);
274 float mean_val = (maxvalue + minvalue)/2.0f;
276 m_vmax = mean_val + half_range;
277 m_vmin = mean_val - half_range;
283 "Histogram : Ran out of memory for arrays.\n");
299 for(i = 0; i <
m_num; i++)
312 const float* his_counts = his->
GetCounts();
313 for(i=0; i<
m_num; i++)
327 float his_start = minvalue + .5f*del;
329 float c0 = his->
GetCount(his_start);
330 float c1 = his->
GetCount(his_start + del);
331 float s0 = (c1 - c0)/del;
333 for(
float x = start;
x <= (his_start + del +
m_delta);)
335 float interp = s0 * (
x - his_start) + c0;
336 if(interp < 0) interp = 0;
341 float his_end = maxvalue - .5f*del;
344 float cn_1 = his->
GetCount(his_end - del);
345 float sn = (cn_1 - cn)/del;
347 for(
float y = end;
y >= (his_end - del +
m_delta);)
349 float interp = sn * (his_end -
y) + cn;
350 if(interp < 0) interp = 0;
356 for(
float z = his_start + del; z <= (his_end - del);)
361 float deriv = (cip1 - ci_1)/(2.0f*del);
363 ((cip1 + ci_1)/2.0f - ci)/(del*del);
365 if (fine_x_index < 0)
367 if (z<
m_vmin) fine_x_index = 0;
368 else fine_x_index =
m_num-1;
370 float fine_x =
m_vals[fine_x_index];
371 for(
float xfine = fine_x; xfine < z + del;)
373 float interp = ci + deriv*(xfine -z) +
374 second_drv*(xfine - z)*(xfine - z);
376 if(interp < 0) interp = 0;
388 float his_start = minvalue + .5f*del;
389 float his_end = maxvalue - .5f*del;
390 for(
float x = his_start;
x <= his_end;)
409 xres = xres >0? xres:1;
411 m_vals =
new float [xres];
435 for(i = 0; i < xres; i++)
444 if(
m_num < 1)
return 0;
456 while((idxLeft <
m_num) && (new_counts[idxLeft] < 1))++idxLeft;
457 while((idxRight > -1) && (new_counts[idxRight] < 1))--idxRight;
458 if(idxLeft < idxRight)
461 while(idx <= idxRight)
463 if(new_counts[idx]>0)
465 pvars[0] = new_counts[idx];
473 while(idx <= idxRight)
477 new_counts[idx] = pvars[0];
510 float* new_counts = scaled_his->
GetCounts();
512 for(i=0; i <
m_num; i++)
518 float scale = scale_factor;
519 if(scale_factor > 1.0) scale = 1.0;
521 for(
float x = highvalue;
x >
m_vmin;)
527 if (trans_x<
m_vmin) index = 0;
528 else index =
m_num-1;
531 float abs_fraction = (float)fabs(fraction);
536 else x_index =
m_num-1;
541 new_counts[index] += (1.0f - abs_fraction)*
m_counts[x_index];
543 if(index < (
m_num-1))
544 new_counts[index + 1] +=
551 new_counts[index - 1] +=
576 const float* density_counts = this->
GetCounts();
580 float* cum_counts = cum_his->
GetCounts();
582 for(i=0; i < res; i++)
585 cum_counts[res-1] = density_counts[res-1];
586 for(i = res-2; i>=0; --i)
588 cum_counts[i] += (density_counts[i] + cum_counts[i+1]);
597 const float* density_counts = this->
GetCounts();
601 float* cum_counts = cum_his->
GetCounts();
603 for(i=0; i < res; i++)
606 cum_counts[0] = density_counts[0];
607 for(i = 1; i < res; i++)
609 cum_counts[i] += (density_counts[i] + cum_counts[i-1]);
633 return cnts[nbm+bin];
635 return cnts[bin-n_bins];
658 for(i = 0; i < nbins; i++)
687 int peak_location = (start_index+i-1)/2;
689 for(k = start_index; k<=(i-1); k++)
701 int init_location = (init_end-1)/2;
703 for(k = 0; k<init_end; k++)
709 int end_location = (start_index + nbm)/2;
711 for(k = start_index; k<nbins; k++)
722 int peak_location = (start_index + init_end - nbm -1)/2;
724 if(peak_location < 0)
726 peak_location += nbm;
727 for( k = 0; k< init_end; k++)
729 for( k= start_index; k <nbins; k++)
735 for( k = start_index; k< nbins; k++)
737 for( k= 0; k < init_end; k++)
744 int init_location = (init_end-1)/2;
746 for(k = start_index; k<init_end; k++)
764 if((2*radius +1)>
m_num/2)
771 int n_buckets = h_new->
GetRes();
777 for( i =0; i < n_buckets; i++)
781 for( i = 0; i< n_buckets; i++)
784 float max_count = counts_old[i];
786 for(k = -radius; k <= radius ;k++)
794 if(max_count == counts_old[i])
795 counts_new[i] = max_count;
874 return bandIdx<
GetRes()?bandIdx:-1;
891 for(i = 0; i <
m_num; i++)
956 for(i = 0; i <
m_num; i++)
1015 for (i=0; i <
m_num; i++)
1057 if (low < minval) low = minval;
1058 if (high > maxval) high = maxval;
1062 int indexlow, indexhigh;
1066 if (low<
m_vmin) indexlow = 0;
1067 else indexlow =
m_num-1;
1072 if (high<
m_vmin) indexhigh = 0;
1073 else indexhigh =
m_num-1;
1077 while (i<=indexhigh)
1109 if (val < minValue || val > maxValue)
1116 int total_buckets =
GetRes();
1118 float partial_sum = 0.0;
1119 float total_sum = 0.0;
1121 for(
int i = 0; i < total_buckets; ++i)
1124 if (i <= cutoff_bucket)
1130 return (partial_sum/total_sum);
1139 if (val < minValue || val > maxValue)
1144 int total_buckets =
GetRes();
1146 float partial_sum = 0.0;
1147 float total_sum = 0.0;
1149 for(
int i = (total_buckets-1); i >= 0; --i)
1152 if (i >= cutoff_bucket)
1158 return (partial_sum/total_sum);
1167 if(clip_fraction<0) clip_fraction=0.0;
1168 if(clip_fraction>1.0) clip_fraction=1.0;
1171 if(clip_fraction==0.0)
return this->
GetMinVal();
1172 if(clip_fraction==1.0)
return this->
GetMaxVal();
1173 float clip_area = area*clip_fraction;
1176 int res = this->
GetRes();
1196 if(clip_fraction<0) clip_fraction=0.0;
1197 if(clip_fraction>1.0) clip_fraction=1.0;
1200 if(clip_fraction==0.0)
return this->
GetMaxVal();
1201 if(clip_fraction==1.0)
return this->
GetMinVal();
1202 float clip_area = area*clip_fraction;
1205 int res = this->
GetRes();
1224 int res = this->
GetRes();
1227 for(i =0; i < res; i++)
1236 out <<
"\n MaxVal " << this->
GetMaxVal() <<
"\n";
1237 out <<
" MinVal " << this->
GetMinVal() <<
"\n";
1239 out <<
" Resolution " << this->
GetRes() <<
"\n";
1242 out <<
"------------------------------------------------\n\n";
1250 FILE *dumpfp = fopen(dumpfile,
"w");
1254 fprintf(stderr,
"Error opening histogram data file.\n");
1259 for(i = 0; i <
m_num; i++)
1271 FILE *fp = fopen(fname,
"w");
1275 fprintf(stderr,
"Error opening histogram plot file.\n");
1279 for(
int j = 0; j <
m_num; j++)
1309 bool binsCreated =
false;
1317 create(numberOfBins, 0, numberOfBins - 1);
1328 *binNumber.
c_str() !=
'.')
1335 s >> binNumber >> count;
1336 if(*binNumber.
c_str() != (char)
'.')
1339 (float)count.toDouble());
1370 if(inputLine.
find(
"File Type") != string::npos)
1372 std::string::size_type index = inputLine.
find(
":");
1373 if(index != std::string::npos)
1390 if(inputLine.
find(
"Version") != string::npos)
1392 std::string::size_type index = inputLine.
find(
":");
1393 if(index != std::string::npos)
1409 if(inputLine.
find(
"Mapper Type") != string::npos)
1411 std::string::size_type index = inputLine.
find(
":");
1412 if(index != std::string::npos)
1428 if(inputLine.
find(
"Number of Bins") != string::npos)
1430 std::string::size_type index = inputLine.
find(
":");
1431 if(index != std::string::npos)
1450 const char* prefix)
const 1472 bool firstValue =
true;
1481 binArrayList +=
",";
1491 binArrayList +=
")";
1493 kwl.
add(prefix,
"bins", binArrayList,
true);
1518 const char* number_of_bins = kwl.
find(prefix,
"number_of_bins");
1530 float maxValue = bins - 1;
1533 const char* min_value = kwl.
find(prefix,
"min_value");
1534 const char* max_value = kwl.
find(prefix,
"max_value");
1545 create((
int)bins, minValue, maxValue);
1547 memset(countsPtr,
'\0', bins*
sizeof(
float));
1551 if(!binsString.
empty())
1553 std::vector<ossimDpt> result;
1558 for(idx = 0; idx < result.size();++idx)
1563 countsPtr[binIdx] = result[idx].y;
1575 ossimKeywordlist::KeywordMap::const_iterator iter = kwlMap.begin();
1576 while(iter != kwlMap.end())
1578 ossimString numberStr(iter->first.begin() + offset,
1598 std::vector<ossim_uint32> theNumberList(numberOfBins);
1600 for(idx = 0; idx < theNumberList.size();++idx)
1604 theNumberList[idx] = numberStr.
toUInt32();
1609 memset(countsPtr,
'\0', bins*
sizeof(
float));
1610 for(idx = 0; idx < numberOfBins;++idx)
1627 if(binValues.
valid())
1630 float minValue = 0.0;
1631 float maxValue = 0.0;
1632 std::vector<float> floatValues;
1640 floatValues.
push_back(vString.toFloat32());
1648 maxValue = count - 1;
1650 if(minValueNode.
valid())
1654 if(maxValueNode.
valid())
1659 create(count, minValue, maxValue);
1662 for(idx = 0; idx < count; ++idx)
1664 countsPtr[idx] = floatValues[idx];
1676 xmlNode->
setTag(
"ossimHistogram");
1681 binValues->
setTag(
"binValues");
1687 for(idx = 0; idx <
m_num;++idx)
1691 binValues->
setText(out.str());
float GetCount(float uval) const
void setTag(const ossimString &tag)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
float GetBucketSize() const
int WritePlot(const char *fname) const
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
void setText(const ossimString &text)
Represents serializable keyword/value map.
int addPoint(const double Px, const double Py, const double *Pvars)
int GetValIndex(float val) const
std::basic_ifstream< char > ifstream
Class for char input file streams.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
const char * find(const char *key) const
float getHighFractionFromValue(float val) const
ossimHistogram * CumulativeLessThanEqual() const
double nan()
Method to return ieee floating point double precision NAN.
static ossimString toString(bool aValue)
Numeric to string methods.
ossim_uint32 toUInt32() const
std::istream & getline(std::istream &is, ossimString &str, char delim)
float GetMaxValFromIndex(ossim_uint32 idx) const
const ossimRefPtr< ossimXmlNode > & findFirstNode(const ossimString &rel_xpath) const
void push_back(char c)
Equivalent to insert(end(), c).
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
float GetValFromIndex(ossim_uint32 idx) const
const ossimString & getText() const
RTTI_DEF1(ossimHistogram, "ossimHistogram", ossimObject)
OSSIM_DLL void toVector(std::vector< ossimDpt > &result, const ossimString &stringOfPoints)
Will take a string list separated by spaces and convert to a vector of ossimDpts. ...
ossimHistogram * Scale(float scale_factor)
std::map< std::string, std::string > KeywordMap
float GetStandardDev() const
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
virtual int GetIndex(float) const
void create(int xres, float val1, float val2)
void extractKeysThatMatch(ossimKeywordlist &kwl, const ossimString ®ularExpression) const
virtual bool importHistogram(const ossimFilename &inputFile)
ossimHistogram * CumulativeGreaterThanEqual() const
virtual ~ossimHistogram()
ossim_float32 toFloat32() const
float GetMaxCount() const
void UpCount(float newval, float occurences=1)
float HighClipVal(float clip_fraction) const
ossimHistogram * fillInteriorEmptyBins(int type=HISTOGRAM_FILL_THIN_PLATE) const
int getPoint(const double Px, const double Py, double *Pvars) const
void RemoveFlatPeaks(int nbins, float *cnts, bool cyclic)
float LowClipVal(float clip_fraction) const
ossimHistogram * NonMaximumSupress(int radius=1, bool cyclic=false)
float GetMinValFromIndex(ossim_uint32 idx) const
std::vector< ossimString > getSubstringKeyList(const ossimString ®ularExpression) const
std::basic_istream< char > istream
Base class for char input streams.
const ossimKeywordlist::KeywordMap & getMap() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
float ComputeArea() const
std::string substr(std::string::size_type pos=0, std::string::size_type n=std::string::npos) const
Equivalent to basic_string(*this, pos, n).
std::basic_istringstream< char > istringstream
Class for char input memory streams.
float GetExtendedCount(int bin, int n_bins, float *cnts, bool cyclic)
void addChildNode(ossimRefPtr< ossimXmlNode > node)
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
float getLowFractionFromValue(float val) const
float SetCount(float pixelval, float count)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.