// file: $USFS/class/image_analysis/v6.1/imaga_edge_22.cc
//

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

// method: edge_test_cc
//
// arguments:
//  float_8& distance: (output) the distance from the test feature vector to
//                     the feature vector in the model
//  uint_1* blk_r: (input) buffer for red color
//  uint_1* blk_g: (input) buffer for green color
//  uint_1* blk_b: (input) buffer for blue color
//  int_4 offset_w: (input) offset in width for the image block
//  int_4 offset_h: (input) offset in height for the image block
//  int_4 width: (input) width of the image block
//  int_4 height: (input) height of the image block
//
// return:
//  a logical_1 value indicating the status
//
// this method performs the edge detection on an image block
//
logical_1 Image_analysis::edge_test_cc(float_8& distance_a, uint_1* blk_r_a,
				       uint_1* blk_g_a, uint_1* blk_b_a,
				       int_4 offset_w_a, int_4 offset_h_a,
				       int_4 width_a, int_4 height_a) {

  // initialize the private data
  //
  if (edge_init_cc() == ISIP_FALSE) {
    error_handler_cc((char_1*)"edge_test_cc",
		     (char_1*)"error while initializing the edge detection");
    return ISIP_FALSE;
  }
  
  // perform the edge detection
  //
  if (edge_compute_cc(blk_r_a, blk_g_a, blk_b_a, offset_w_a, offset_h_a,
		      width_a, height_a) == ISIP_FALSE) {
    error_handler_cc((char_1*)"edge_test_cc",
		     (char_1*)"error while computing the edges");
    return ISIP_FALSE;
  }
  
  // perform the normalization
  //
  if (edge_normalize_cc() == ISIP_FALSE) {
    error_handler_cc((char_1*)"edge_test_cc",
		     (char_1*)"error while normalizing the data");
    return ISIP_FALSE;
  }

  for (int_4 i=0; i < edge_r_nbins_d; i++) {
    fprintf(stdout, " %f\t", edge_t_lpdf_d[i]);
  }
  
  // provide some debugging information
  //
  if (debug_level_d > ISIP_DEBUG_BRIEF) {
    fprintf(stdout, "<%s> %s = %ld\n", "Image_analysis::edge_test_cc",
	    "edge_t_nlines", edge_t_tlines_d);
    fprintf(stdout, "<%s> %s = %ld\n", "Image_analysis::edge_test_cc",
	    "edge_t_nblks_d", edge_t_nblks_d);

    // display the distribution of lines
    //
    fprintf(stdout, "lines pdf:\n");
    for (int_4 i=0; i<edge_r_nbins_d; i++) {
      fprintf(stdout, "%ld: %f\n", i, edge_t_lpdf_d[i]);
    }
  }
  
  // compute the distance
  //
  if (edge_compare_cc(distance_a) == ISIP_FALSE) {
    error_handler_cc((char_1*)"edge_test_cc",
		     (char_1*)"error while computing the distance");
    return ISIP_FALSE;
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
