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

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

// method: train_cc
//
// arguments:
//  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 status
//
// this method trains the images on block basis so as to develop a model file
//
logical_1 Image_analysis::train_cc(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) {
  
  // check for a histogram
  //
  if (algorithm_d == IMAGA_ALG_HISTOGRAM) {
    if (hist_train_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*)"train_cc", 
		       (char_1*)"error while computing the histogram");
      return ISIP_FALSE;
    }
  }

  // check for the edge detection
  //
  else if (algorithm_d == IMAGA_ALG_EDGEDET) {
    if (edge_train_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*)"train_cc",
		       (char_1*)"error while computing the edge detection");
      return ISIP_FALSE;
    }
  }

  // check for the factor analysis
  //
  else if (algorithm_d == IMAGA_ALG_FACTOR) {
    if (pca_train_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*)"train_cc",
		       (char_1*)"error while computing the algorithms");
      return ISIP_FALSE;
    }
  }

  // check for the sharpness
  //
  else if (algorithm_d == IMAGA_ALG_DIFF) {
    if (dent_train_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*)"train_cc",
		       (char_1*)"error while computing the diff in magnitude");
      return ISIP_FALSE;
    }
  }

  // check for the standard deviation
  //
  else if (algorithm_d == IMAGA_ALG_SD) {
    if (sd_train_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*)"train_cc",
		       (char_1*)"error while computing the deviation");
      return ISIP_FALSE;
    }
  }

  // check for the entropy
  //
  else if (algorithm_d == IMAGA_ALG_ENT) {
    if (ent_train_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*)"train_cc",
		       (char_1*)"error while computing the entropy");
      return ISIP_FALSE;
    }
  }

  // check for the run lenght coding
  //
  else if (algorithm_d == IMAGA_ALG_RLE) {
    if (rle_train_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*)"train_cc",
		       (char_1*)"error while computing the run length coding");
      return ISIP_FALSE;
    }
  }

  // check for the fractal dimension
  //
  else if (algorithm_d == IMAGA_ALG_FRACT) {
    if (fract_train_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*)"train_cc",
		       (char_1*)"error computing the fractal dimensions");
      return ISIP_FALSE;
    }
  }
  
  // else: unknown algorithm
  //
  else {
    error_handler_cc((char_1*)"train_cc",
		     (char_1*)"unknown algorithm");
    return ISIP_FALSE;
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}  
