9 #include "ControlMeasure.h"
10 #include "ControlNet.h"
11 #include "ControlPoint.h"
12 #include "LineManager.h"
14 #include "SpecialPixel.h"
33 Histogram::Histogram(
double minimum,
double maximum,
int nbins) {
35 SetValidRange(minimum, maximum);
53 string msg =
"The number of Histogram Bins must be greater than 0";
54 throw IException(IException::Programmer, msg, _FILEINFO_);
59 rangesFromNet(net,statFunc);
61 addMeasureDataFromNet(net, statFunc);
79 string msg =
"The width of Histogram Bins must be greater than 0";
80 throw IException(IException::Programmer, msg, _FILEINFO_);
84 rangesFromNet(net,statFunc);
91 int nBins = int ( ceil(domain/binWidth) ) - 1;
94 addMeasureDataFromNet(net, statFunc);
110 for (
int i=0; i<nObjPts; i++) {
112 if (point->IsIgnored() )
continue;
115 int nObs = point->GetNumMeasures();
116 for (
int j=0; j<nObs; j++) {
120 if (measure->IsIgnored())
continue;
121 this->AddData((measure->*statFunc)());
142 for (
int i=0; i<nObjPts; i++) {
145 if (point->IsIgnored())
continue;
148 int nObs = point->GetNumMeasures();
150 for (
int j=0; j<nObs; j++) {
153 if (measure->IsIgnored())
continue;
155 temp = (measure->*statFunc)();
156 if ( !
IsSpecial(temp) && temp > max ) max = temp;
157 if ( !
IsSpecial(temp) && temp < min ) min = temp;
163 string msg =
"The net file appears to have 1 or fewer measures with residual data, "
164 "thus no histogram for this net file can be created;";
165 throw IException(IException::User, msg, _FILEINFO_);
170 SetValidRange(min, max);
175 Histogram::~Histogram() {
192 void Histogram::SetValidRange(
double binStart,
double binEnd) {
193 if (binEnd < binStart) {
194 string msg =
"The binning range start [" +
IString(binStart) +
"]"
195 " must be less than the end [" +
IString(binEnd) +
"].";
196 throw IException(IException::Programmer, msg, _FILEINFO_);
203 Isis::Statistics::SetValidRange(binStart,binEnd);
204 p_binRangeStart = binStart;
205 p_binRangeEnd = binEnd;
210 void Histogram::Reset() {
212 for (
int i = 0; i < (int)p_bins.size(); i++) {
219 void Histogram::SetBins(
const int nbins) {
220 p_bins.resize(nbins);
232 void Histogram::AddData(
const double *data,
233 const unsigned int count) {
234 Statistics::AddData(data, count);
236 int nbins = p_bins.size();
238 for (
unsigned int i = 0; i < count; i++) {
240 if (BinRangeStart() == BinRangeEnd() ) {
244 index = (int) floor( ((
double) nbins / (BinRangeEnd() - BinRangeStart())) *
245 (data[i] - BinRangeStart()) );
247 if (index < 0) index = 0;
248 if (index >= nbins) index = nbins - 1;
262 void Histogram::AddData(
const double data) {
263 Statistics::AddData(data);
265 int nbins = p_bins.size();
268 if (BinRangeStart() == BinRangeEnd() ) {
272 index = (int) floor( ((
double) nbins / (BinRangeEnd() - BinRangeStart())) *
273 (data - BinRangeStart()) );
275 if (index < 0) index = 0;
276 if (index >= nbins) index = nbins - 1;
291 void Histogram::RemoveData(
const double *data,
292 const unsigned int count) {
293 Statistics::RemoveData(data, count);
295 int nbins = p_bins.size();
297 for (
unsigned int i = 0; i < count; i++) {
300 if (BinRangeStart() == BinRangeEnd() ) {
304 index = (int) floor( ((
double) nbins / (BinRangeEnd() - BinRangeStart())) *
305 (data[i] - BinRangeStart()) );
307 if (index < 0) index = 0;
308 if (index >= nbins) index = nbins - 1;
319 double Histogram::Median()
const {
320 return Percent(50.0);
328 double Histogram::Mode()
const {
330 for (
int i = 0; i < (int)p_bins.size(); i++) {
332 if (p_bins[i] > p_bins[mode]) mode = i;
335 if (p_bins[mode] < 1)
return NULL8;
337 return BinMiddle(mode);
351 double Histogram::Percent(
double percent)
const {
352 if ( (percent < 0.0) || (percent > 100.0) ) {
353 string m =
"Argument percent outside of the range 0 to 100 in";
354 m +=
" [Histogram::Percent]";
355 throw IException(IException::Programmer, m, _FILEINFO_);
358 if (ValidPixels() < 1)
return NULL8;
361 double currentPercent;
363 for (
int i = 0; i < (int)p_bins.size(); i++) {
365 currentPixels += p_bins[i];
366 currentPercent = (double) currentPixels / (
double) ValidPixels() * 100.0;
368 if (currentPercent >= percent) {
373 return BinMiddle( (
int) p_bins.size() - 1);
384 double Histogram::Skew()
const {
386 if (ValidPixels() < 1)
return NULL8;
388 double sdev = StandardDeviation();
390 if (sdev == 0.0)
return 0.0;
392 return 3.0 * (
Average() - Median()) / sdev;
403 BigInt Histogram::BinCount(
const int index)
const {
405 if ( (index < 0) || (index >= (
int)p_bins.size() ) ) {
407 QString message = Message::ArraySubscriptNotInRange(index);
409 throw IException(IException::Programmer, message, _FILEINFO_);
412 return p_bins[index];
427 void Histogram::BinRange(
const int index,
428 double &low,
double &high)
const {
429 if ( (index < 0) || (index >= (
int)p_bins.size() ) ) {
431 QString message = Message::ArraySubscriptNotInRange(index);
432 throw IException(IException::Programmer, message, _FILEINFO_);
435 double binSize = (BinRangeEnd() - BinRangeStart()) / (
double) p_bins.size();
436 low = BinRangeStart() + binSize * (double) index;
437 high = low + binSize;
449 double Histogram::BinMiddle(
const int index)
const {
450 if ( (index < 0) || (index >= (
int)p_bins.size() ) ) {
452 QString message = Message::ArraySubscriptNotInRange(index);
454 throw IException(IException::Programmer, message, _FILEINFO_);
458 BinRange(index, low, high);
459 return (low + high) / 2.0;
470 double Histogram::BinSize()
const {
473 BinRange(0, low, high);
483 int Histogram::Bins()
const {
484 return (
int)p_bins.size();
496 for (
int i = 0; i < (int)p_bins.size(); i++) {
497 if (p_bins[i] > maxBinCount) maxBinCount = p_bins[i];