// file: $USFS/class/image_analysis/v3.0/imaga_edge_14.cc
//

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

#include "image_analysis_constants.h"
#include <integral_constants.h>

// method: edge_assign_cc
//
// arguments:
// int_4* pixel_num_a: a logical_1 value indicating the status
//
// this method assigns the data points to bins in the edge detection
// note that the edge detection is assigned in the range
//
//  [min_val - bin_width/2] to [max_val + bin_width/2]
//
// points outside this range are assigned to the end bins
//
logical_1 Image_analysis::edge_assign_cc(int_4 pixel_num_a) {
  
  // compute the quantization constants
  //
  float_8 bin_width = (IMAGA_EDGE_LMAX - IMAGA_EDGE_LMIN) / (float_8)edge_r_nbins_d;
  float_8 min_val = IMAGA_EDGE_LMIN - 0.5 * bin_width;
  float_8 max_val = IMAGA_EDGE_LMAX + 0.5 * bin_width;
  float_8 range = max_val - min_val;
  float_8 scale = (float_8)edge_r_nbins_d / range;
  
  // loop over all the data
  //
  int_4 index;
  
  // limit the value
  //
  if (pixel_num_a < min_val) {
    pixel_num_a = (int_4)min_val;
  }
  else if (pixel_num_a > max_val) {
    pixel_num_a = (int_4)max_val;
  }
  
  // compute the bin in which the line falls
  //
  index = (int_4)(((float_8)pixel_num_a - min_val) * scale);

  // increment the corresponding bin
  //
  edge_t_lpdf_d[index] += (float_8)1.0;

  // exit gracefully
  //
  return ISIP_TRUE;
}



