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

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

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

// method: edge_gauss_cc
//
// arguments:
//  float_4* edge_gauss: (output) gaussian matrix
//
// return: a logical_1 value indicating status
//
// this method generates the coefficients for the gaussian filter
//
logical_1 Image_analysis::edge_gauss_cc(float_4* edge_gauss) {
  
  // declare local variables
  //
  float_8 variance = 0.0;
  float_8 coeff = 0.0;
  float_8 x = 0.0;
  float_8 y = 0.0;
  
  // compute the constants
  //
  coeff = 1.0 / ((sqrt(2 * PI)) * edge_r_sigma_d);
  variance = -2.0 * edge_r_sigma_d * edge_r_sigma_d;
  
  float_8 scale = 1.0 / variance;
  
  // computing the constants of the mask
  // 
  for (int_4 i=0; i<edge_r_msize_d; i++) {
    for (int_4 j=0; j<edge_r_msize_d; j++) {
      
      // calculating the filter coefficients
      //
      x = (float_4)i - edge_r_xmean_d;
      y = (float_4)j - edge_r_ymean_d;
      
      edge_gauss[i*edge_r_msize_d + j] = coeff * exp((x*x + y*y) * (scale));
    }
  }

  // providing debugging information
  //
  if (debug_level_d > ISIP_DEBUG_NONE) {
    
    fprintf(stdout, "<%s> %s: %f\n%s: %f\n", "Image_analysis:edge_gauss_cc",
	    "edge_r_xmean_d", edge_r_xmean_d, "edge_r_ymean_d", edge_r_ymean_d);
    fprintf(stdout, "<%s> %s: %f\n", "Image_analysis:edge_gauss_cc",
	    "edge_r_sigma_d", edge_r_sigma_d);
    
    for (int_4 i=0; i < edge_r_msize_d; i++) {
      for (int_4 j=0; j < edge_r_msize_d; j++) {
	fprintf(stdout, "edge_gauss[%ld][%ld] =  %f\n",i, j,
		edge_gauss[i*edge_r_msize_d + j]);
      }
    }
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
      
















