// file: $USFS/class/image_analysis/v1.0/imaga_hist_06.cc
//

// isip include files
//
#include "image_analysis.h"

// method: hist_compute_index_cc
//
// arguments:
//  float_8 val_a: (input) value to be processed
//  float_8 min_a: (input) minimum allowed value
//  float_8 max_a: (input) maximum allowed value
//  float_8 scale_a: (input) scale factor
//
// return: an int_4 value representing the histogram bin number
//
// this method assigns a data point to a bin in a histogram.
// note that the histogram is assumed to extend from:
//
//   [min - bin_width/2] to [max + bin_width/2]
//
// this can be replaced with the following computation:
//
//   index = (int) [val - min] * scale;
//
// points outside this range are assigned to the end bins.
//
int_4 Image_analysis::hist_compute_index_cc(float_8 val_a,
					    float_8 min_a, float_8 max_a,
					    float_8 scale_a) {
  
  // limit the value
  //
  if (val_a < min_a) {
    val_a = min_a;
  }
  else if (val_a > max_a) {
    val_a = max_a;
  }

  // return the index
  //
  return (int_4)((val_a - min_a) * scale_a);
}
