OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimHistogram.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: MIT
4 //
5 // Author: Ken Melero (kmelero@imagelinks.com)
6 // Orginally developed by:
7 // Copyright (c) 1997 TargetJr Consortium
8 // GE Corporate Research and Development (GE CRD)
9 // 1 Research Circle
10 // Niskayuna, NY 12309
11 // Adapted from: IUE v4.1.2
12 // Description:
13 // A ossimHistogram contains an array of "buckets", which represent finite
14 // segments of some value axis, along with a corresponding array of
15 // frequency m_counts for each of these buckets.
16 //
17 //********************************************************************
18 // $Id$
19 
20 #include <ossim/base/ossimCommon.h>
24 #include <ossim/base/ossimDpt.h>
25 #include <cmath>
26 #include <cstdio>
27 #include <fstream>
28 #include <iostream>
29 #include <iomanip>
30 #include <sstream>
31 using namespace std;
32 
33 
34 
35 // nonstandard versions that use operator>, so they behave differently
36 // than std:::min/max and ossim::min/max. kept here for now for that
37 // reason.
38 #ifndef MAX
39 # define MAX(x,y) ((x)>(y)?(x):(y))
40 # define MIN(x,y) ((x)>(y)?(y):(x))
41 #endif
42 
43 
44 static const int MEAN_FLAG = 1, SD_FLAG = 2;
45 RTTI_DEF1(ossimHistogram, "ossimHistogram", ossimObject);
47  :
48  m_statsConsistent(MEAN_FLAG | SD_FLAG),
49  m_vals(new float [1]),
50  m_counts(new float [1]),
51  m_num(0),
52  m_delta(0.0),
53  m_vmin(0),
54  m_vmax(0),
55  m_mean(0.0),
56  m_standardDev(0.0)
57 {
58  m_vals[0] = 0.0;
59  m_counts[0] = 0.0;
60 }
61 
62 ossimHistogram::ossimHistogram(int xres, float val1, float val2)
63  :
64  m_statsConsistent(MEAN_FLAG | SD_FLAG),
65  m_vals(new float [xres]),
66  m_counts(new float [xres]),
67  m_num(xres),
68  m_delta(0.0),
69  m_vmin(0),
70  m_vmax(0),
71  m_mean(0.0),
72  m_standardDev(0.0)
73 {
74  m_vmax = MAX(val1, val2);
75  m_vmin = MIN(val1, val2);
76 
77  //---
78  // Set the delta which is used to index the bins.
79  // Note: that using "(m_vmax - m_vmin) / xres" was dropping the
80  // last bin on integer data.
81  //---
82  if ( (m_vmax - m_vmin + 1) == xres )
83  {
84  m_delta = 1.0;
85  }
86  else
87  {
88  m_delta = (m_vmax - m_vmin) / xres;
89  }
90 
91  m_mean = (float)((m_vmax + m_vmin)/2.0);
92  m_standardDev = (float)((m_vmax - m_vmin)/(2.0*sqrt(3.0)));
93  int i = 0;
94 
95  if (m_vals == NULL || m_counts == NULL)
96  {
97  fprintf(stderr, "Histogram : Ran out of memory for arrays.\n");
98  m_vals = NULL;
99  m_counts = NULL;
100  m_num = 0;
101  m_vmin = 0;
102  m_vmax = 0;
103  m_delta = 0.0;
104  }
105  else
106  {
107  //std::cout << std::setprecision(15) << m_vmin << ", " << m_vmax << ", " <<m_delta <<", "<< xres << std::endl;
108  for(i = 0; i < xres; i++)
109  {
110  m_vals[i] = m_vmin + m_delta * (float)(i + 0.5);
111  //std::cout << m_vals[i] << std::endl;
112  m_counts[i] = 0.0;
113  }
114  }
115 }
116 
117 ossimHistogram::ossimHistogram(float* uvals, float* ucounts, int xres)
118  :
119  m_statsConsistent(MEAN_FLAG | SD_FLAG),
120  m_vals(uvals),
121  m_counts(ucounts),
122  m_num(xres),
123  m_delta(0.0),
124  m_vmin(0),
125  m_vmax(0),
126  m_mean(0.0),
127  m_standardDev(0.0)
128 {
129  if ( ( xres >= 2 ) && uvals && ucounts )
130  {
131  m_delta = m_vals[1] - m_vals[0]; // Changed this from delta = 1.0
132  // m_vmax = GetMaxVal();
133  // m_vmin = GetMinVal(); JAF version
134  m_vmin = uvals[0] - .5f*m_delta;
135  m_vmax = uvals[m_num-1] + .5f*m_delta;
136  m_mean = GetMean();
138  }
139 }
141  :
142  m_statsConsistent(0),
143  m_vals(0),
144  m_counts(0),
145  m_num((int)xres),
146  m_delta(0.0),
147  m_vmin(0),
148  m_vmax(0),
149  m_mean(0.0),
150  m_standardDev(0.0)
151 {
152  if ((size == 0) || (xres == 0))
153  return;
154 
155  // scan the dataset for min/max:
156  m_vmin=(float)(data[0]);
157  m_vmax=(float)(data[0]);
158  for (ossim_uint32 i=1; i<size; ++i)
159  {
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]);
164  }
165 
166  // Allocate histogram:
167  m_delta = (m_vmax - m_vmin) / m_num;
168  m_vals = new float [m_num];
169  m_counts = new float [m_num];
170  for (ossim_int32 i=0; i<m_num; ++i)
171  {
172  m_vals[i] = m_vmin + m_delta * (i + 0.5);
173  m_counts[i] = 0.0;
174  }
175 
176  // compute histogram:
177  for (ossim_uint32 i=0; i<size; i++)
178  UpCount((float)(data[i]));
179 
180  GetMean();
181  GetStandardDev();
182 }
183 
184 //-----------------------------------------------------------
185 // -- Copy constructor
187 :
188 m_statsConsistent(0),
189 m_vals(0),
190 m_counts(0),
191 m_num(0),
192 m_delta(0.0),
193 m_vmin(0),
194 m_vmax(0),
195 m_mean(0.0),
196 m_standardDev(0.0)
197 {
198 
199  int i = 0;
200  m_num = his.GetRes();
201 
202  m_vals = new float[m_num];
203  const float* his_vals = his.GetVals();
204 
205  m_counts = new float[m_num];
206  const float* his_counts = his.GetCounts();
207 
208  if (m_vals == NULL || m_counts == NULL)
209  {
210  fprintf(stderr, "Histogram : Ran out of memory for arrays.\n");
211  m_vals = NULL;
212  m_counts = NULL;
213  m_num = 0;
214  m_vmin = 0;
215  m_vmax = 0;
216  m_delta = 0.0;
217  m_statsConsistent = 0;
218  return;
219  }
220 
221  m_mean = his.GetMean();
223 
224  for(i=0; i<m_num; i++)
225  {
226  m_vals[i] = his_vals[i];
227  m_counts[i] = his_counts[i];
228  }
229  m_vmax = his.GetMaxVal();
230  m_vmin = his.GetMinVal();
231  m_delta = his.GetBucketSize();
232 
233  m_statsConsistent = 0;
234  m_statsConsistent |= (MEAN_FLAG | SD_FLAG);
235 }
236 
237 
238 //---------------------------------------
239 // -- Resample a histogram
240 
242 :
243 m_statsConsistent(0),
244 m_vals(0),
245 m_counts(0),
246 m_num(0),
247 m_delta(0.0),
248 m_vmin(0),
249 m_vmax(0),
250 m_mean(0.0),
251 m_standardDev(0.0)
252 {
253 
255 
256 // Attributes of original histogram
257 
258  float del = his->GetBucketSize();
259  int max_index = his->GetRes() - 1;
260  float minvalue = his->GetVals()[0] - del*.5f;
261  float maxvalue = his->GetVals()[max_index] + del*.5f;
262 
263 
264 // Intialize a new histogram
265  if(width == del) m_num = his->GetRes();
266  else if(!(width == 0.0))
267  m_num = (int)ceil((maxvalue - minvalue)/width);
268  else
269  m_num = 1; // This shouldn't happen anyway.
270 
271  m_vals = new float [m_num];
272  m_counts = new float [m_num];
273  m_delta = width;
274  float mean_val = (maxvalue + minvalue)/2.0f;
275  float half_range = (m_num * m_delta)/2.0f;
276  m_vmax = mean_val + half_range;
277  m_vmin = mean_val - half_range;
278  int i = 0;
279 
280  if (m_vals == NULL || m_counts == NULL)
281  {
282  fprintf(stderr,
283  "Histogram : Ran out of memory for arrays.\n");
284  m_vals = NULL;
285  m_counts = NULL;
286  m_num = 0;
287  m_vmin = 0;
288  m_vmax = 0;
289  m_delta = 0.0;
290  m_mean = 0.0;
291  m_standardDev = 0.0;
292  m_statsConsistent |= (MEAN_FLAG | SD_FLAG);
293  return;
294 
295  }
296 
297  else
298  {
299  for(i = 0; i < m_num; i++)
300  {
301  m_vals[i] = m_vmin + m_delta * (i + 0.5f);
302  m_counts[i] = 0.0;
303  }
304  }
305 
306 
307 // Cases:
308 
309 
310  if(width == del) // Then just copy his
311  {
312  const float* his_counts = his->GetCounts();
313  for(i=0; i<m_num; i++)
314  m_counts[i] = his_counts[i];
315  m_mean = GetMean();
317  m_statsConsistent |= (MEAN_FLAG | SD_FLAG);
318  return;
319  }
320 
321 
322  if(del > width) // Then interpolate his m_counts.
323  {
324 
325 // Boundary conditions:
326 // Start
327  float his_start = minvalue + .5f*del;
328  float start = m_vmin + .5f*m_delta;
329  float c0 = his->GetCount(his_start);
330  float c1 = his->GetCount(his_start + del);
331  float s0 = (c1 - c0)/del;
332 
333  for(float x = start; x <= (his_start + del + m_delta);)
334  {
335  float interp = s0 * (x - his_start) + c0;
336  if(interp < 0) interp = 0; //Can be negative
337  SetCount(x,interp);
338  x += width;
339  }
340 // End
341  float his_end = maxvalue - .5f*del;
342  float end = m_vmax - .5f*m_delta;
343  float cn = his->GetCount(his_end);
344  float cn_1 = his->GetCount(his_end - del);
345  float sn = (cn_1 - cn)/del;
346 
347  for(float y = end; y >= (his_end - del + m_delta);)
348  {
349  float interp = sn * (his_end - y) + cn;
350  if(interp < 0) interp = 0; //Can be negative
351  SetCount(y, interp);
352  y -= m_delta;
353  }
354 // Interior Loop
355 
356  for(float z = his_start + del; z <= (his_end - del);)
357  {
358  float ci = his->GetCount(z);
359  float ci_1 = his->GetCount(z-del);
360  float cip1 = his->GetCount(z+del);
361  float deriv = (cip1 - ci_1)/(2.0f*del);
362  float second_drv =
363  ((cip1 + ci_1)/2.0f - ci)/(del*del);
364  int fine_x_index = GetIndex(z);
365  if (fine_x_index < 0)
366  {
367  if (z<m_vmin) fine_x_index = 0;
368  else fine_x_index = m_num-1;
369  }
370  float fine_x = m_vals[fine_x_index];
371  for(float xfine = fine_x; xfine < z + del;)
372  {
373  float interp = ci + deriv*(xfine -z) +
374  second_drv*(xfine - z)*(xfine - z);
375 
376  if(interp < 0) interp = 0; //Can be negative
377  SetCount(xfine, interp);
378  xfine += width;
379  }
380  z += del;
381  }
382  }
383 
384 
385  if(del < width) //Just accumulate samples from his into larger bins
386  {
387  if( del != 0.0){
388  float his_start = minvalue + .5f*del;
389  float his_end = maxvalue - .5f*del;
390  for(float x = his_start; x <= his_end;)
391  {
392  SetCount(x, (GetCount(x) + his->GetCount(x)));
393  x += del;
394  }
395  }
396  }
397  m_mean = GetMean();
400  m_statsConsistent |= (MEAN_FLAG | SD_FLAG);
401 }
402 
403 void ossimHistogram::create(int xres, float val1, float val2)
404 {
405  // clear all the data
406  deleteAll();
407 
408  // now set it up and initialize;
409  xres = xres >0? xres:1;
410 
411  m_vals = new float [xres];
412  m_counts = new float [xres];
413  m_num = xres;
414  m_vmax = MAX(val1, val2);
415  m_vmin = MIN(val1, val2);
416 
417  m_delta = (m_vmax - m_vmin) / xres;
418  m_mean = (float)((m_vmax + m_vmin)/2.0);
419  m_standardDev = (float)((m_vmax - m_vmin)/(2.0*sqrt(3.0)));
420  m_statsConsistent = 0;
421  m_statsConsistent |= (MEAN_FLAG | SD_FLAG);
422  int i = 0;
423  if (m_vals == NULL || m_counts == NULL)
424  {
425  ossimNotify(ossimNotifyLevel_FATAL) << "Histogram : Ran out of memory for arrays.\n";
426  m_vals = NULL;
427  m_counts = NULL;
428  m_num = 0;
429  m_vmin = 0;
430  m_vmax = 0;
431  m_delta = 0.0;
432  }
433  else
434  {
435  for(i = 0; i < xres; i++)
436  {
437  m_vals[i] = m_vmin + m_delta * (float)(i + 0.5);
438  m_counts[i] = 0.0;
439  }
440  }
441 }
443 {
444  if(m_num < 1) return 0;
445  ossimHistogram* result = new ossimHistogram(*this);
446  switch(type)
447  {
450  {
451  ossimThinPlateSpline spline(1);
452  double pvars[1];
453  float* new_counts = result->GetCounts();
454  ossim_int32 idxLeft = 0;
455  ossim_int32 idxRight = m_num-1;
456  while((idxLeft < m_num) && (new_counts[idxLeft] < 1))++idxLeft;
457  while((idxRight > -1) && (new_counts[idxRight] < 1))--idxRight;
458  if(idxLeft < idxRight)
459  {
460  ossim_int32 idx = idxLeft;
461  while(idx <= idxRight)
462  {
463  if(new_counts[idx]>0)
464  {
465  pvars[0] = new_counts[idx];
466  spline.addPoint(idx, 0, pvars);
467  }
468  ++idx;
469  }
470  if(spline.solve())
471  {
472  idx = idxLeft;
473  while(idx <= idxRight)
474  {
475  if(spline.getPoint(idx, 0, pvars))
476  {
477  new_counts[idx] = pvars[0];
478  }
479  ++idx;
480  }
481  m_statsConsistent = 0;
482  }
483  else
484  {
485  }
486  }
487 
488  break;
489  }
490  }
491 
492  return result;
493 }
494 //--------------------------------------------------
495 // -- Transform the value axis of a histogram by a
496 // translation, transl, and a scale factor, scale.
497 // The new histogram has the same resolution as his.
498 
500 {
501 
502 // Extract attributes of self
503 
504 // float lowvalue = m_vals[0];
505  float highvalue = m_vals[m_num-1];
506 
507 // Construct a new histogram
508 
509  ossimHistogram* scaled_his = new ossimHistogram(this, m_delta);
510  float* new_counts = scaled_his->GetCounts();
511  int i = 0;
512  for(i=0; i < m_num; i++) // Initialize
513  new_counts[i] = 0.0;
514 
515 // Compute scaled values
516 // We assume that the new histogram is to be scaled down from his
517 
518  float scale = scale_factor;
519  if(scale_factor > 1.0) scale = 1.0;
520 
521  for(float x = highvalue; x > m_vmin;)
522  {
523  float trans_x = (x-m_vmin)*scale + m_vmin; // Scaled x.
524  int index = GetIndex(trans_x);
525  if (index < 0)
526  {
527  if (trans_x<m_vmin) index = 0;
528  else index = m_num-1;
529  }
530  float fraction = (trans_x - m_vals[index])/m_delta;
531  float abs_fraction = (float)fabs(fraction);
532  int x_index = GetIndex(x);
533  if (x_index < 0)
534  {
535  if (x<m_vmin) x_index = 0;
536  else x_index = m_num-1;
537  }
538 
539 // Distribute the m_counts in proportion
540 
541  new_counts[index] += (1.0f - abs_fraction)*m_counts[x_index];
542  if(fraction > 0)
543  if(index < (m_num-1))
544  new_counts[index + 1] +=
545  abs_fraction*m_counts[x_index];
546  else
547  new_counts[index] +=
548  abs_fraction*m_counts[x_index];
549  else
550  if(index > 0)
551  new_counts[index - 1] +=
552  abs_fraction*m_counts[x_index];
553  else
554  new_counts[index] +=
555  abs_fraction*m_counts[x_index];
556  x -= m_delta;
557  }
558 
559 // Compute new Histogram attributes
560 
561  m_mean = scaled_his->GetMean();
562  m_standardDev = scaled_his->GetStandardDev();
563  return scaled_his;
564 }
565 
566 //---------------------------------------------------------------------
567 // -- Assuming that "this" is a histogram of population density,
568 // construct a new histogram which is the cumulative distribution.
569 // Each bin, xi, in his is assumed to represent a density, i.e.,
570 // {x | (xi - .5*m_delta) < x <= (xi + .5*m_delta)}
571 // Each bin, xi, in the result represents a cumulative distribution, i.e.,
572 // {x | x <= (xi + .5*m_delta)}
574 {
575  ossimHistogram* cum_his = new ossimHistogram(*this);
576  const float* density_counts = this->GetCounts();
577  int res = this->GetRes();
578 
579  // Intitialize cumulative m_counts
580  float* cum_counts = cum_his->GetCounts();
581  int i = 0;
582  for(i=0; i < res; i++)
583  cum_counts[i] = 0;
584 
585  cum_counts[res-1] = density_counts[res-1];
586  for(i = res-2; i>=0; --i)
587  {
588  cum_counts[i] += (density_counts[i] + cum_counts[i+1]);
589  }
590 
591  return cum_his;
592 }
593 
595 {
596  ossimHistogram* cum_his = new ossimHistogram(*this);
597  const float* density_counts = this->GetCounts();
598  int res = this->GetRes();
599 
600  // Intitialize cumulative m_counts
601  float* cum_counts = cum_his->GetCounts();
602  int i = 0;
603  for(i=0; i < res; i++)
604  cum_counts[i] = 0;
605 
606  cum_counts[0] = density_counts[0];
607  for(i = 1; i < res; i++)
608  {
609  cum_counts[i] += (density_counts[i] + cum_counts[i-1]);
610  }
611 
612  return cum_his;
613 }
614 
615 //Provides the correct values for histogram m_counts when the bin index
616 //extends outside the valid range of the m_counts array. This function
617 //permits easy array access logic for the NonMaximumSuppression algorithm.
618 //The cyclic flag indicates that the m_counts array index is circular, i.e,
619 //cnts[0] equivalent to cnts[n_bins-1]
620 inline float GetExtendedCount(int bin, int n_bins, float* cnts, bool cyclic)
621 {
622  int nbm = n_bins-1;
623  if(!cyclic)
624  {
625  if(bin < 0)
626  return cnts[0];
627  if(bin >= n_bins)
628  return cnts[nbm];
629  }
630  else
631  {
632  if(bin<0)
633  return cnts[nbm+bin];
634  if(bin >= n_bins)
635  return cnts[bin-n_bins];
636  }
637  return cnts[bin];
638 }
639 //Prune any sequences of more than one maxium value
640 //That is, it is possible to have a "flat" top peak with an arbitarily
641 //long sequence of equal, but maximum values. The cyclic flag indictates
642 //that the sequence wraps around, i.e. cnts[0] equivalent to cnts[nbins-1]
643 inline void RemoveFlatPeaks(int nbins, float* cnts, bool cyclic)
644 {
645  int nbm = nbins-1;
646 
647  //Here we define a small state machine - parsing for runs of peaks
648  //init is the state corresponding to an initial run (starting at i ==0)
649  bool init=(GetExtendedCount(0, nbins, cnts, cyclic) !=0 ) ? true : false;
650  int init_end =0;
651 
652  //start is the state corresponding to any other run of peaks
653  bool start=false;
654  int start_index=0;
655  int i = 0;
656 
657  //The scan of the state machine
658  for(i = 0; i < nbins; i++)
659  {
660  float v = GetExtendedCount(i, nbins, cnts, cyclic);
661 
662  //State init: a string of non-zeroes at the begining.
663  if(init&&v!=0)
664  continue;
665 
666  if(init&&v==0)
667  {
668  init_end = i;
669  init = false;
670  continue;
671  }
672 
673  //State !init&&!start: a string of "0s"
674  if(!start&&v==0)
675  continue;
676 
677  //State !init&&start: the first non-zero value
678  if(!start&&v!=0)
679  {
680  start_index = i;
681  start = true;
682  continue;
683  }
684  //State ending flat peak: encountered a subsequent zero after starting
685  if(start&&v==0)
686  {
687  int peak_location = (start_index+i-1)/2;//The middle of the run
688  int k = 0;
689  for(k = start_index; k<=(i-1); k++)
690  if(k!=peak_location)
691  cnts[k] = 0;
692  start = false;
693  }
694  }
695  //Now handle the boundary conditions
696  //The non-cyclic case
697  if(!cyclic)
698  {
699  if(init_end!=0) //Was there an initial run of peaks?
700  {
701  int init_location = (init_end-1)/2;
702  int k = 0;
703  for(k = 0; k<init_end; k++)
704  if(k!=init_location)
705  cnts[k] = 0;
706  }
707  if(start) // Did we reach the end of the array in a run of pks?
708  {
709  int end_location = (start_index + nbm)/2;
710  int k = 0;
711  for(k = start_index; k<nbins; k++)
712  if(k!=end_location)
713  cnts[k] = 0;
714  }
715  }
716  else //The cyclic case
717  {
718  if(init_end!=0) //Is there a run which crosses the cyclic cut?
719  {
720  if(start)
721  { //Yes, so define the peak location accordingly
722  int peak_location = (start_index + init_end - nbm -1)/2;
723  int k;
724  if(peak_location < 0) //Is the peak to the left of the cut?
725  {// Yes, to the left
726  peak_location += nbm;
727  for( k = 0; k< init_end; k++)
728  cnts[k]=0;
729  for( k= start_index; k <nbins; k++)
730  if(k!=peak_location)
731  cnts[k] = 0;
732  }
733  else
734  {//No, on the right.
735  for( k = start_index; k< nbins; k++)
736  cnts[k]=0;
737  for( k= 0; k < init_end; k++)
738  if(k!=peak_location)
739  cnts[k] = 0;
740  }
741  }
742  else
743  {//There wasn't a final run so just clean up the initial run
744  int init_location = (init_end-1)/2;
745  int k = 0;
746  for(k = start_index; k<init_end; k++)
747  if(k!=init_location)
748  cnts[k] = 0;
749  }
750  }
751  }
752 }
753 
754 //----------------------------------------------------------
755 // -- Suppress values in the Histogram which are not locally
756 // a maxium. The neighborhood for computing the local maximum
757 // is [radius X radius], e.g. for radius =1 the neighborhood
758 // is [-X-], for radius = 2, the neighborhood is [--X--], etc.
759 // If the cyclic flag is true then the index space is assumed to
760 // be equivalent to a circle. That is, elements "0" and (n_buckets-1)
761 // are in correspondence.
763 {
764  if((2*radius +1)> m_num/2)
765  {
766  ossimNotify(ossimNotifyLevel_WARN)<<"ossimHistogram::NonMaximumSupress the radius is too large \n";
767  return NULL;
768  }
769  //Get the m_counts array of "this"
770  ossimHistogram* h_new = new ossimHistogram(*this);
771  int n_buckets = h_new->GetRes();
772  float* counts_old = this->GetCounts();
773 
774  //Make a new Histogram for the suppressed version
775  float* counts_new = h_new->GetCounts();
776  int i;
777  for( i =0; i < n_buckets; i++)
778  counts_new[i] = 0;
779 
780  //Find local maxima
781  for( i = 0; i< n_buckets; i++)
782  {
783  //find the maxium value in the current kernel
784  float max_count = counts_old[i];
785  int k = 0;
786  for(k = -radius; k <= radius ;k++)
787  {
788  int index = i+k;
789  float c = GetExtendedCount(index, n_buckets, counts_old, cyclic);
790  if( c > max_count)
791  max_count = c;
792  }
793  //Is position i a local maxium?
794  if(max_count == counts_old[i])
795  counts_new[i] = max_count;//Yes. So set the m_counts to the max value
796  }
797  RemoveFlatPeaks(n_buckets, counts_new, cyclic);
798  return h_new;
799 }
800 //----------------------------------------------------------
801 // -- Compute the m_mean of the histogram population
803 {
804  float xsum = 0.0;
805 
806  if(MEAN_FLAG&m_statsConsistent)
807  return m_mean;
808  else
809  {
810  if( this->GetBucketSize() > 0.0){
811  for(float x=this->GetMinVal(); x<= this->GetMaxVal(); x +=this->GetBucketSize())
812  xsum += x*GetCount(x);
813  }
814 
815  float area = ComputeArea(m_vmin, m_vmax);
816  if(area <= 0.0)
817  {
818  // fprintf(stderr, "Histogram : Area <= 0.0\n");
819  return 0.0;
820  }
821  else
822  {
823  m_statsConsistent |=1;
824  m_mean = xsum/area;
825  return m_mean;
826  }
827  }
828 }
829 
830 
831 
833 {
834  float sum = 0.0;
835 
836  if(SD_FLAG&m_statsConsistent)
837  return m_standardDev;
838  else
839  {
840  float xm = this -> GetMean(); // Force an Update of m_mean
841 
842  if( this->GetBucketSize() > 0.0){
843  for(float x=this->GetMinVal();
844  x<= this->GetMaxVal();
845  x +=this->GetBucketSize())
846 
847  sum += (x-xm)*(x-xm)*GetCount(x);
848  }
849 
850  float area = ComputeArea(m_vmin, m_vmax);
851  if(area <= 0.0)
852  {
853  // fprintf(stderr, "Histogram : Area <= 0.0\n");
854  return 0.0;
855  }
856  else
857  {
858  m_statsConsistent |= 2;
859  m_standardDev = (float)sqrt(sum/area);
860  return m_standardDev;
861  }
862  }
863 }
864 
865 int ossimHistogram::GetIndex(float pixelval)const
866 {
867 #if 1
868  if ((pixelval > m_vmax) || (pixelval < m_vmin) || (m_num==0) )
869  {
870  return -1;
871  }
872 // ossim_float32 d = m_vmax-m_vmin;
873  int bandIdx = (ossim_int32)((pixelval-m_vmin)/m_delta);
874  return bandIdx<GetRes()?bandIdx:-1;
875 // if(bandIdx == m_num)
876 // {
877 // return m_num-1;
878 // }
879 // else if(bandIdx < m_num)
880 // {
881 // return bandIdx;
882 // }
883 // return -1;
884 #else
885  if ((pixelval > m_vmax) || (pixelval < m_vmin))
886  return -1;
887 
888  int idx = 0;
889  int i = 0;
890 
891  for(i = 0; i < m_num; i++)
892  {
893  //std::cout << std::setprecision(15) << m_vals[i] << std::endl;
894  // RWMC: This is very dangerous - might get an intermediate
895  // value which is between m_vals[i]+0.5*m_delta and
896  // m_vals[i+1]-0.5*m_delta, which would then return index of 0.
897  // Changed to check range one-sided, which is safe because of
898  // previous check on range.
899  // if ((pixelval > (m_vals[i] - 0.5 * m_delta)) &&
900  // (pixelval <= (m_vals[i] + 0.5 * m_delta)))
901  if (pixelval <= (m_vals[i] + 0.5 * m_delta))
902  {
903  idx = i;
904  break;
905  }
906  }
907 //std::cout << idx << std::endl;
908  return idx;
909 #endif
910 }
912 {
913  float result = 0.0;
914 
915  if((int)idx < m_num)
916  {
917  result = (m_vals[idx]-(0.5 * m_delta));
918  if(result < m_vmin) result = m_vmin;
919  }
920 
921  return result;
922 }
923 
925 {
926  float result = 0.0;
927 
928  if((int)idx < m_num)
929  {
930  result = (m_vals[idx]+(0.5 * m_delta));
931  if(result > m_vmax) result = m_vmax;
932  }
933 
934  return result;
935 }
936 
938 {
939  float result = 0.0;
940  if((int)idx < m_num)
941  {
942  result = m_vals[idx];
943  }
944 
945  return result;
946 }
947 
948 int ossimHistogram::GetValIndex(float pixelval)const
949 {
950  if ((pixelval > m_vmax) || (pixelval < m_vmin))
951  return -1;
952 
953  int idx = 0;
954  int i = 0;
955 
956  for(i = 0; i < m_num; i++)
957  {
958  if ((pixelval > (m_vals[i] - 0.5 * m_delta)) &&
959  (pixelval <= (m_vals[i] + 0.5 * m_delta)))
960  {
961  idx = i;
962  break;
963  }
964  }
965 
966  return idx;
967 }
968 
969 
970 
971 float ossimHistogram::GetCount(float pixelval)const
972 {
973  int index = GetIndex(pixelval);
974 
975  if (index < 0)
976  return -1;
977  else
978  return m_counts[index];
979 }
980 
981 
982 
984 {
985  int i=0;
986 
987  while (i<m_num-1 && !m_counts[i])
988  i++;
989 
990  return m_vals[i];
991 }
992 
993 
994 
995 
997 {
998  int i=m_num-1;
999 
1000  while (i>0 && !m_counts[i])
1001  i--;
1002 
1003  if (i < 0)
1004  return 0.0;
1005 
1006  return m_vals[i];
1007 }
1008 
1009 
1011 {
1012  int i=0;
1013  float max;
1014  max = 0.0;
1015  for (i=0; i < m_num; i++)
1016  if (m_counts[i] > max)
1017  max = m_counts[i];
1018  return max;
1019 }
1020 
1021 
1022 
1023 
1024 float ossimHistogram::SetCount(float pixelval, float count)
1025 {
1026  m_statsConsistent = 0;
1027 
1028  int index = GetIndex(pixelval);
1029 
1030  if (index < 0)
1031  return -1;
1032  else
1033  {
1034  m_counts[index] = count;
1035  return count;
1036  }
1037 }
1038 
1039 
1040 void ossimHistogram::UpCount(float pixelval, float occurences)
1041 {
1042 
1043  m_statsConsistent = 0;
1044  int idx = GetIndex(pixelval);
1045  if (idx >= 0) // Originally (index > 0)
1046  {
1047  m_counts[idx] += occurences;
1048  }
1049 }
1050 
1051 float ossimHistogram::ComputeArea(float low, float high)const
1052 {
1053  float sum = 0.0;
1054  float maxval = GetMaxVal();
1055  float minval = GetMinVal();
1056 
1057  if (low < minval) low = minval;
1058  if (high > maxval) high = maxval;
1059 
1060  if (low <= high)
1061  {
1062  int indexlow, indexhigh;
1063  indexlow = (int) GetIndex(low);
1064  if (indexlow < 0)
1065  {
1066  if (low<m_vmin) indexlow = 0;
1067  else indexlow = m_num-1;
1068  }
1069  indexhigh = (int) GetIndex(high);
1070  if (indexhigh < 0)
1071  {
1072  if (high<m_vmin) indexhigh = 0;
1073  else indexhigh = m_num-1;
1074  }
1075  int i=indexlow;
1076 
1077  while (i<=indexhigh)
1078  {
1079  sum+= m_counts[i];
1080  i++;
1081  }
1082  }
1083 
1084  return sum;
1085 }
1086 //----------------------------------------------------------------------
1087 // --Compute the total area under the histogram
1088 //
1090 {
1091  float m_vmin = this->GetMinVal();
1092  float m_vmax = this->GetMaxVal();
1093  if(m_vmin>m_vmax)
1094  {
1095  float temp = m_vmin;
1096  m_vmin = m_vmax;
1097  m_vmax = temp;
1098  }
1099  return this->ComputeArea(m_vmin, m_vmax);
1100 }
1101 
1103 {
1104  // std::cout << "ossimHistogram::getLowFractionFromValue(float val)\n";
1105 // float minValue = floor(GetMinVal());
1106 // float maxValue = ceil(GetMaxVal());
1107  float minValue = GetMinVal();
1108  float maxValue = GetMaxVal();
1109  if (val < minValue || val > maxValue)
1110  {
1111  return ossim::nan();
1112  }
1113 // std::cout << "VAL: " << val << "\n"
1114 // << "MIN: " << minValue << "\n"
1115 // << "MAX: " << maxValue << "\n";
1116  int total_buckets = GetRes();
1117  int cutoff_bucket = GetValIndex(val);
1118  float partial_sum = 0.0;
1119  float total_sum = 0.0;
1120  // std::cout << "CUTOFF BUCKET ===" << cutoff_bucket << "\n";
1121  for(int i = 0; i < total_buckets; ++i)
1122  {
1123  total_sum += m_counts[i];
1124  if (i <= cutoff_bucket)
1125  {
1126  partial_sum += m_counts[i];
1127  }
1128  }
1129  // std::cout << "FRACTION ==== " << (partial_sum/total_sum) << "\n";
1130  return (partial_sum/total_sum);
1131 }
1132 
1134 {
1135 // float min = floor(GetMinVal());
1136 // float max = ceil(GetMaxVal());
1137  float minValue = GetMinVal();
1138  float maxValue = GetMaxVal();
1139  if (val < minValue || val > maxValue)
1140  {
1141  return ossim::nan();
1142  }
1143 
1144  int total_buckets = GetRes();
1145  int cutoff_bucket = GetValIndex(val);
1146  float partial_sum = 0.0;
1147  float total_sum = 0.0;
1148 
1149  for(int i = (total_buckets-1); i >= 0; --i)
1150  {
1151  total_sum += m_counts[i];
1152  if (i >= cutoff_bucket)
1153  {
1154  partial_sum += m_counts[i];
1155  }
1156  }
1157 
1158  return (partial_sum/total_sum);
1159 }
1160 
1161 //----------------------------------------------------------------------
1162 // -- Finds the lower bound value which elminates a given fraction of
1163 // histogram area.
1164 //
1165 float ossimHistogram::LowClipVal(float clip_fraction)const
1166 {
1167  if(clip_fraction<0) clip_fraction=0.0;
1168  if(clip_fraction>1.0) clip_fraction=1.0;
1169  float area = this->ComputeArea();
1170  if(area==0.0) return this->GetMinVal();
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;
1174  const float* m_counts = this->GetCounts();
1175  const float* m_vals = this->GetVals();
1176  int res = this->GetRes();
1177  float sum = 0;
1178  int i=0;
1179 
1180  for(; i<res; i++)
1181  {
1182  sum+=m_counts[i];
1183  if(sum>=clip_area)
1184  break;
1185  }
1186 
1187  return m_vals[i];
1188 }
1189 
1190 //----------------------------------------------------------------------
1191 // -- Finds the lower bound value which elminates a given fraction of
1192 // histogram area.
1193 //
1194 float ossimHistogram::HighClipVal(float clip_fraction)const
1195 {
1196  if(clip_fraction<0) clip_fraction=0.0;
1197  if(clip_fraction>1.0) clip_fraction=1.0;
1198  float area = this->ComputeArea();
1199  if(area==0.0) return this->GetMaxVal();
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;
1203  const float* m_counts = this->GetCounts();
1204  const float* m_vals = this->GetVals();
1205  int res = this->GetRes();
1206  float sum = 0;
1207  int i = (res-1);
1208  for(; i>=0; i--)
1209  {
1210  sum+=m_counts[i];
1211  if(sum>=clip_area)
1212  break;
1213  }
1214  return m_vals[i];
1215 }
1216 
1217 //--------------------------------------------------------------------------
1218 // -- Prints histogram m_counts onto cout
1220 {
1222  const float* m_vals = this->GetVals();
1223  const float* m_counts = this->GetCounts();
1224  int res = this->GetRes();
1225  int width = 0;
1226  int i = 0;
1227  for(i =0; i < res; i++)
1228  {
1229  if(width++ > 5)
1230  {
1231  width = 0;
1232  out << "\n";
1233  }
1234  out << m_vals[i] << " " << m_counts[i] << " | " ;
1235  }
1236  out << "\n MaxVal " << this->GetMaxVal() << "\n";
1237  out << " MinVal " << this->GetMinVal() << "\n";
1238  out << " BucketSize " << this->GetBucketSize() << "\n";
1239  out << " Resolution " << this->GetRes() << "\n";
1240  out << " Area "
1241  << this->ComputeArea(this->GetMinVal(),this->GetMaxVal()) << "\n";
1242  out << "------------------------------------------------\n\n";
1243 }
1244 
1245 //---------------------------------------------------------------------------
1246 // --- dumps histogram values to file.
1247 
1248 void ossimHistogram::Dump(char *dumpfile)const
1249 {
1250  FILE *dumpfp = fopen(dumpfile, "w");
1251 
1252  if (!dumpfp)
1253  {
1254  fprintf(stderr, "Error opening histogram data file.\n");
1255  return;
1256  }
1257  int i = 0;
1258 
1259  for(i = 0; i < m_num; i++)
1260  fprintf(dumpfp, "%f %f\n", m_vals[i], m_counts[i]);
1261 
1262  fclose(dumpfp);
1263  return;
1264 }
1265 
1266 //---------------------------------------------------------------------------
1267 // -- Writes histogram in format suitable for plotting tools like Gnuplot.
1268 
1269 int ossimHistogram::WritePlot(const char *fname)const
1270 {
1271  FILE *fp = fopen(fname, "w");
1272 
1273  if (!fp)
1274  {
1275  fprintf(stderr, "Error opening histogram plot file.\n");
1276  return 0;
1277  }
1278 
1279  for(int j = 0; j < m_num; j++)
1280  fprintf(fp, "%f %f\n", m_vals[j], m_counts[j]);
1281 
1282  fclose(fp);
1283  return 1;
1284 }
1285 
1287 {
1288  if (m_vals)
1289  {
1290  delete []m_vals;
1291  m_vals = NULL;
1292  }
1293  if (m_counts)
1294  {
1295  delete []m_counts;
1296  m_counts = NULL;
1297  }
1298 }
1299 
1301 {
1302  deleteAll();
1303 }
1304 
1305 
1307 {
1309  bool binsCreated = false;
1310 
1311  if(header.parseStream(in))
1312  {
1313  long numberOfBins = header.getNumberOfBins();
1314 
1315  if(numberOfBins)
1316  {
1317  create(numberOfBins, 0, numberOfBins - 1);
1318  binsCreated = true;
1319 
1320  if(binsCreated)
1321  {
1322  ossimString buffer;
1323  ossimString binNumber;
1324  ossimString count;
1325 
1326  while(in.good() &&
1327  !in.eof() &&
1328  *binNumber.c_str() != '.')
1329  {
1330 
1331  getline(in, buffer);
1332 
1333  istringstream s(buffer);
1334 
1335  s >> binNumber >> count;
1336  if(*binNumber.c_str() != (char)'.')
1337  {
1338  SetCount((float)binNumber.toDouble(),
1339  (float)count.toDouble());
1340  }
1341  }
1342  }
1343  }
1344  else
1345  {
1346  return false;
1347  }
1348  }
1349  return true;
1350 }
1351 
1353 {
1354  if(inputFile.exists())
1355  {
1356  ifstream input(inputFile.c_str());
1357 
1358  return importHistogram(input);
1359  }
1360 
1361  return false;
1362 }
1363 
1364 
1366 {
1367  ossimString inputLine;
1368 
1369  getline(in, inputLine);
1370  if(inputLine.find("File Type") != string::npos)
1371  {
1372  std::string::size_type index = inputLine.find(":");
1373  if(index != std::string::npos)
1374  {
1375  m_fileType = inputLine.substr(index+1);
1377  }
1378  else
1379  {
1380  return false;
1381  }
1382 
1383  }
1384  else
1385  {
1386  return false;
1387  }
1388 
1389  getline(in, inputLine);
1390  if(inputLine.find("Version") != string::npos)
1391  {
1392  std::string::size_type index = inputLine.find(":");
1393  if(index != std::string::npos)
1394  {
1395  m_version = inputLine.substr(index+1);
1396  m_version = m_version.trim();
1397  }
1398  else
1399  {
1400  return false;
1401  }
1402  }
1403  else
1404  {
1405  return false;
1406  }
1407 
1408  getline(in, inputLine);
1409  if(inputLine.find("Mapper Type") != string::npos)
1410  {
1411  std::string::size_type index = inputLine.find(":");
1412  if(index != std::string::npos)
1413  {
1414  m_mapperType = inputLine.substr(index+1);
1416  }
1417  else
1418  {
1419  return false;
1420  }
1421  }
1422  else
1423  {
1424  return false;
1425  }
1426 
1427  getline(in, inputLine);
1428  if(inputLine.find("Number of Bins") != string::npos)
1429  {
1430  std::string::size_type index = inputLine.find(":");
1431  if(index != std::string::npos)
1432  {
1433  m_numberOfBins = inputLine.substr(index+1);
1435  }
1436  else
1437  {
1438  return false;
1439  }
1440  }
1441  else
1442  {
1443  return false;
1444  }
1445 
1446  return true;
1447 }
1448 
1450  const char* prefix)const
1451 {
1452  kwl.add(prefix,
1453  "type",
1454  "ossimHistogram",
1455  true);
1456  kwl.add(prefix,
1457  "number_of_bins",
1458  m_num,
1459  true);
1460  kwl.add(prefix,
1461  "min_value",
1462  m_vmin,
1463  true);
1464  kwl.add(prefix,
1465  "max_value",
1466  m_vmax,
1467  true);
1468 
1469 
1470 
1471  ossimString binArrayList = "(";
1472  bool firstValue = true;
1473 
1474  for(ossim_int32 index = 0; index < m_num; ++index)
1475  {
1476  if(fabs(m_counts[index]) > FLT_EPSILON)
1477  {
1478 
1479  if(!firstValue)
1480  {
1481  binArrayList += ",";
1482  }
1483  else
1484  {
1485  firstValue = false;
1486  }
1487  binArrayList += "("+ossimString::toString(index)+","+ossimString::toString(m_counts[index])+")";
1488  }
1489  }
1490 
1491  binArrayList += ")";
1492 
1493  kwl.add(prefix, "bins", binArrayList, true);
1494 #if 0
1495  ossimString binValue = "";
1496  for(ossim_int32 index = 0; index < m_num; ++index)
1497  {
1498  if(fabs(m_counts[index]) > FLT_EPSILON)
1499  {
1500  // binValue = prefix;
1501  binValue = "bin";
1502  binValue += ossimString::toString(index);
1503 
1504  kwl.add(prefix,
1505  binValue.c_str(),
1506  m_counts[index],
1507  true);
1508  }
1509  }
1510 #endif
1511  return true;
1512 }
1513 
1515  const char* prefix)
1516 {
1517 // std::cout << "ossimHistogram::loadState!!!!\n";
1518  const char* number_of_bins = kwl.find(prefix, "number_of_bins");
1519 
1520 // std::cout << "NBINS = " << number_of_bins << std::endl;
1521  if(number_of_bins)
1522  {
1523  ossim_uint32 bins = ossimString(number_of_bins).toUInt32();
1524 
1525 // std::cout << "BINS ======== " << bins << std::endl;
1526  if(bins > 0)
1527  {
1528  // setup some defaults
1529  float minValue = 0;
1530  float maxValue = bins - 1;
1531 
1532  // see if there is a range set for the data
1533  const char* min_value = kwl.find(prefix, "min_value");
1534  const char* max_value = kwl.find(prefix, "max_value");
1535 
1536  if(min_value)
1537  {
1538  minValue = (ossim_float32)ossimString(min_value).toDouble();
1539  }
1540  if(max_value)
1541  {
1542  maxValue = (ossim_float32)ossimString(max_value).toDouble();
1543  }
1544 
1545  create((int)bins, minValue, maxValue);
1546  float* countsPtr = GetCounts();
1547  memset(countsPtr, '\0', bins*sizeof(float));
1548  // this is new style histogram creation
1549  //
1550  ossimString binsString = kwl.find(prefix, "bins");
1551  if(!binsString.empty())
1552  {
1553  std::vector<ossimDpt> result;
1554  ossim::toVector(result, binsString);
1555  if(!result.empty())
1556  {
1557  ossim_uint32 idx = 0;
1558  for(idx = 0; idx < result.size();++idx)
1559  {
1560  ossim_uint32 binIdx = static_cast<ossim_uint32>(result[idx].x);
1561  if(binIdx < bins)
1562  {
1563  countsPtr[binIdx] = result[idx].y;
1564  }
1565  }
1566  }
1567  }
1568  else
1569  {
1570  ossimKeywordlist binsKwl;
1571  ossim_uint32 offset = (ossim_uint32)(ossimString(prefix)+"bin").size();
1572  ossimString regExpression = ossimString("^(") + ossimString(prefix) + "bin[0-9]+)";
1573  kwl.extractKeysThatMatch(binsKwl,regExpression);
1574  const ossimKeywordlist::KeywordMap& kwlMap = binsKwl.getMap();
1575  ossimKeywordlist::KeywordMap::const_iterator iter = kwlMap.begin();
1576  while(iter != kwlMap.end())
1577  {
1578  ossimString numberStr(iter->first.begin() + offset,
1579  iter->first.end());
1580  countsPtr[numberStr.toUInt32()] = ossimString(iter->second).toDouble();
1581  ++iter;
1582  }
1583  }
1584 
1585 // ossimKeywordlist kwl;
1586 // this->saveState(kwl);
1587 // std::cout << kwl << std::endl;
1588 
1589  return true;
1590 #if 0
1591  // create the bins
1592  ossimString binNumber = "";
1593  ossimString regExpression = ossimString("^(") + ossimString(prefix) + "bin[0-9]+)";
1594  vector<ossimString> keys = kwl.getSubstringKeyList( regExpression );
1595  ossim_uint32 numberOfBins = (ossim_uint32)keys.size();
1596  ossim_uint32 offset = (ossim_uint32)(ossimString(prefix)+"bin").size();
1597 
1598  std::vector<ossim_uint32> theNumberList(numberOfBins);
1599  ossim_uint32 idx = 0;
1600  for(idx = 0; idx < theNumberList.size();++idx)
1601  {
1602  ossimString numberStr(keys[idx].begin() + offset,
1603  keys[idx].end());
1604  theNumberList[idx] = numberStr.toUInt32();
1605 
1606  }
1607 
1608  float* countsPtr = GetCounts();
1609  memset(countsPtr, '\0', bins*sizeof(float));
1610  for(idx = 0; idx < numberOfBins;++idx)
1611  {
1612  const char* binCount = kwl.find(prefix, ossimString("bin") + ossimString::toString(theNumberList[idx]));
1613  countsPtr[theNumberList[idx]] = (float)ossimString(binCount).toDouble();
1614  }
1615 #endif
1616  }
1617  }
1618  return true;
1619 }
1620 
1622 {
1623  ossimRefPtr<ossimXmlNode> binValues = xmlNode->findFirstNode("binValues");
1624  ossimRefPtr<ossimXmlNode> minValueNode = xmlNode->findFirstNode("minValue");
1625  ossimRefPtr<ossimXmlNode> maxValueNode = xmlNode->findFirstNode("maxValue");
1626 
1627  if(binValues.valid())
1628  {
1629  ossim_uint32 count = 0;
1630  float minValue = 0.0;
1631  float maxValue = 0.0;
1632  std::vector<float> floatValues;
1633  std::istringstream in(binValues->getText());
1634  ossimString vString;
1635  while(!in.fail())
1636  {
1637  in>>vString;
1638  if(!in.fail())
1639  {
1640  floatValues.push_back(vString.toFloat32());
1641  }
1642  }
1643  count = (ossim_uint32)floatValues.size();
1644 
1645  if(count)
1646  {
1647  minValue = 0;
1648  maxValue = count - 1;
1649 
1650  if(minValueNode.valid())
1651  {
1652  minValue = minValueNode->getText().toFloat32();
1653  }
1654  if(maxValueNode.valid())
1655  {
1656  maxValue = maxValueNode->getText().toFloat32();
1657  }
1658 
1659  create(count, minValue, maxValue);
1660  float* countsPtr = GetCounts();
1661  ossim_uint32 idx = 0;
1662  for(idx = 0; idx < count; ++idx)
1663  {
1664  countsPtr[idx] = floatValues[idx];
1665  }
1666  return true;
1667  }
1668  }
1669 
1670  return false;
1671 }
1672 
1674 {
1675  ossimRefPtr<ossimXmlNode> binValues = new ossimXmlNode;
1676  xmlNode->setTag("ossimHistogram");
1677  xmlNode->addChildNode("minValue", ossimString::toString(m_vmin));
1678  xmlNode->addChildNode("maxValue", ossimString::toString(m_vmax));
1679  xmlNode->addChildNode("standardDeviation", ossimString::toString(m_standardDev));
1680  xmlNode->addChildNode("m_mean", ossimString::toString(m_mean));
1681  binValues->setTag("binValues");
1682  std::ostringstream out;
1683 
1684  ossim_int32 idx = 0;
1685  if(m_num > 0)
1686  {
1687  for(idx = 0; idx < m_num;++idx)
1688  {
1689  out << ossimString::toString(m_counts[idx], 8) << " ";
1690  }
1691  binValues->setText(out.str());
1692  }
1693  xmlNode->addChildNode(binValues.get());
1694 
1695  return true;
1696 }
ossim_uint32 x
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.
Definition: ossimIosFwd.h:35
virtual void deleteAll()
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
ossim_uint32 y
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
bool valid() const
Definition: ossimRefPtr.h:75
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
const char * find(const char *key) const
#define MAX(x, y)
float getHighFractionFromValue(float val) const
ossimHistogram * CumulativeLessThanEqual() const
float ossim_float32
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
static ossimString toString(bool aValue)
Numeric to string methods.
ossim_uint32 toUInt32() const
std::istream & getline(std::istream &is, ossimString &str, char delim)
Definition: ossimString.h:916
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).
Definition: ossimString.h:905
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
int GetRes() const
float GetValFromIndex(ossim_uint32 idx) const
const ossimString & getText() const
Definition: ossimXmlNode.h:92
float GetMean() 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. ...
yy_size_t size
ossimHistogram * Scale(float scale_factor)
bool exists() const
std::map< std::string, std::string > KeywordMap
float GetStandardDev() const
#define FLT_EPSILON
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)
double toDouble() const
void extractKeysThatMatch(ossimKeywordlist &kwl, const ossimString &regularExpression) const
virtual bool importHistogram(const ossimFilename &inputFile)
ossimHistogram * CumulativeGreaterThanEqual() const
virtual ~ossimHistogram()
void Print() const
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 &regularExpression) const
float GetMinVal() const
#define MIN(x, y)
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
const ossimKeywordlist::KeywordMap & getMap() const
#define max(a, b)
Definition: auxiliary.h:76
float * GetCounts()
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
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).
Definition: ossimString.h:910
float * GetVals()
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
float GetExtendedCount(int bin, int n_bins, float *cnts, bool cyclic)
float GetMaxVal() const
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.
Definition: ossimString.h:753
void Dump(char *) const
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.
Definition: ossimIosFwd.h:23
int ossim_int32