// file: $USFS/class/image_analysis/v6.0/imaga_proc_6.cc
//

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

// method: train_cc
//
// arguments:
//  char_1* image_fname: (input) image file name
//  char_1* seg_fname: (input) segmentation data file name
//
// return:
//  a logical_1 value indicating status
//
// this method trains the images so as to develop a model file
// this is the segmentation-based version
//
logical_1 Image_analysis::train_cc(char_1* image_fname_a,
				   char_1* seg_fname_a) {
  
  // check for a histogram
  //
  if (algorithm_d == IMAGA_ALG_HISTOGRAM) {
    if (hist_train_cc(image_fname_a, seg_fname_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(image_fname_a, seg_fname_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(image_fname_a, seg_fname_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(image_fname_a, seg_fname_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(image_fname_a, seg_fname_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(image_fname_a, seg_fname_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(image_fname_a, seg_fname_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(image_fname_a, seg_fname_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;  
}  
